index.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <template>
  2. <div class="tools p-4">
  3. <div class="tools-body">
  4. <BasicTable @register="registerTable">
  5. <template #toolbar>
  6. <Button type="primary" @click="handleAdd">
  7. 新增工具
  8. </Button>
  9. <Button type="primary" danger :disabled="hasSelected" @click="handleBatchDelete">
  10. 批量删除
  11. </Button>
  12. </template>
  13. <template #func="{ record }">
  14. <TableAction :actions="[
  15. {
  16. label: '查看',
  17. tooltip: '查看',
  18. icon: 'ant-design:search-outlined',
  19. onClick: handleEdit.bind(null, record),
  20. },
  21. {
  22. label: '编辑',
  23. tooltip: '编辑',
  24. icon: 'clarity:note-edit-line',
  25. onClick: handleEdit.bind(null, record),
  26. },
  27. {
  28. label: '显隐',
  29. tooltip: '显隐',
  30. icon: 'ant-design:delete-outlined',
  31. color: 'error',
  32. onClick: handleShow.bind(null, record)
  33. },
  34. {
  35. label: '删除',
  36. tooltip: '删除',
  37. icon: 'ant-design:delete-outlined',
  38. color: 'error',
  39. onClick: handleDelete.bind(null, record)
  40. },
  41. ]" />
  42. </template>
  43. </BasicTable>
  44. </div>
  45. <ToolsDrawer v-if="ifShowDialog" @closeDialog="ifShowDialog = false" @onSubmit="onSubmit">
  46. </ToolsDrawer>
  47. </div>
  48. </template>
  49. <script>
  50. import { defineComponent, onMounted, watch, ref, reactive, toRefs, computed, createVNode } from 'vue';
  51. // 导入表格组件,表格事件
  52. import { BasicTable, useTable, TableAction } from '/@/components/Table';
  53. import { Button } from 'ant-design-vue';
  54. import ToolsDrawer from './ToolsDrawer.vue';
  55. import { message, Modal } from 'ant-design-vue';
  56. import moment from 'moment'
  57. import { session } from '/@/utils/Memory';
  58. import { getAllTools, addTools, delTools, showTools } from '/@/api/sys/mapTools';
  59. import { useSyncConfirm } from '/@/hooks/component/useSyncConfirm';
  60. import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
  61. import { useI18n } from '/@/hooks/web/useI18n';
  62. import { h } from 'vue';
  63. import { Tag } from 'ant-design-vue';
  64. export default defineComponent({
  65. components: { BasicTable, TableAction, Button, ToolsDrawer, ExclamationCircleOutlined },
  66. name: "tools",
  67. setup() {
  68. const { t } = useI18n(); //加载国际化
  69. const columns = [
  70. {
  71. title: '分组名称',
  72. dataIndex: 'group',
  73. key: 'group',
  74. align: 'center'
  75. },
  76. // {
  77. // title: 'id',
  78. // dataIndex: 'id',
  79. // key: 'id',
  80. // align: 'center'
  81. // },
  82. {
  83. title: '显示名称',
  84. dataIndex: 'label',
  85. key: 'label',
  86. align: 'center'
  87. },
  88. {
  89. title: '提示文字',
  90. dataIndex: 'tip',
  91. key: 'tip',
  92. align: 'center'
  93. },
  94. {
  95. title: '图标',
  96. dataIndex: 'icon',
  97. key: 'icon',
  98. align: 'center'
  99. },
  100. {
  101. title: '状态',
  102. dataIndex: 'show',
  103. width: 80,
  104. customRender: ({ record }) => {
  105. const status = !record.show;
  106. const enable = ~~status === 0;
  107. const color = enable ? 'green' : 'red';
  108. const enableText = t('routes.common.system.tableTitleSystemEnable'); //国际化处理--启用
  109. const stopText = t('routes.common.system.tableTitleSystemStop'); //国际化处理--停用
  110. const text = enable ? enableText : stopText;
  111. return h(Tag, { color: color }, () => text);
  112. },
  113. },
  114. {
  115. title: '功能',
  116. dataIndex: 'action',
  117. key: 'action',
  118. align: 'center'
  119. }
  120. ]
  121. const handleEdit = () => {
  122. }
  123. const handleDelete = (record) => {
  124. Modal.confirm({
  125. title: '删除提示',
  126. icon: createVNode(ExclamationCircleOutlined),
  127. content: '确定删除该工具?',
  128. centered: true,
  129. okText: '确定',
  130. okType: 'danger',
  131. cancelText: '取消',
  132. onOk: (() => {
  133. let param = {
  134. id: record.id
  135. }
  136. delTools(param).then(res => {
  137. message.success('操作成功');
  138. reload();
  139. })
  140. })
  141. });
  142. }
  143. const handleShow = (record) => {
  144. Modal.confirm({
  145. title: '隐藏提示',
  146. icon: createVNode(ExclamationCircleOutlined),
  147. content: '确定隐藏该工具?',
  148. centered: true,
  149. okText: '确定',
  150. okType: 'danger',
  151. cancelText: '取消',
  152. onOk: (() => {
  153. showTools(record).then(res => {
  154. message.success('操作成功');
  155. reload();
  156. })
  157. })
  158. });
  159. }
  160. const ifShowDialog = ref(false)
  161. const handleAdd = () => {
  162. ifShowDialog.value = true
  163. }
  164. const onSubmit = () => {
  165. reload();
  166. }
  167. const { createSyncConfirm } = useSyncConfirm();
  168. const handleBatchDelete = async () => {
  169. const rowKeys = getSelectRowKeys();
  170. try {
  171. await createSyncConfirm({
  172. iconType: 'warning',
  173. content: '确认后所有选中的菜单将被删除',
  174. });
  175. await handleDelete({ id: rowKeys });
  176. setSelectedRowKeys([]);
  177. reload();
  178. } catch (error) { }
  179. };
  180. const getAllData = () => {
  181. return new Promise((resolve) => {
  182. getAllTools().then(res => {
  183. if (res.code === 200 && res.data.length) {
  184. resolve(res.data)
  185. } else {
  186. message.error('暂无工具数据')
  187. }
  188. })
  189. })
  190. }
  191. //判断是否选中数据
  192. const hasSelected = computed(() => {
  193. const rowSelection = getRowSelection();
  194. return !rowSelection.selectedRowKeys?.length;
  195. });
  196. //注册tag表格
  197. const [
  198. registerTable,
  199. { reload, getRowSelection, getSelectRowKeys, setSelectedRowKeys }
  200. ] = useTable({
  201. title: '工具列表', //'菜单列表'
  202. api: getAllData, //加载数据
  203. // dataSource: toolsData,
  204. columns: columns,
  205. useSearchForm: false, //开启搜索区域
  206. bordered: true,
  207. showTableSetting: true, // 显示表格设置
  208. tableSetting: {
  209. redo: true,
  210. size: true,
  211. setting: false,
  212. fullScreen: false
  213. },
  214. showIndexColumn: true,
  215. pagination: {
  216. // pageSize: 10,
  217. hideOnSinglePage: false
  218. },
  219. rowKey: (record) => record.id,
  220. actionColumn: {
  221. width: 200,
  222. title: '操作',
  223. dataIndex: 'func',
  224. slots: { customRender: 'func' },
  225. },
  226. rowSelection: {
  227. type: 'checkbox',
  228. },
  229. });
  230. return {
  231. handleShow,
  232. hasSelected,
  233. ifShowDialog,
  234. registerTable,
  235. reload,
  236. getRowSelection,
  237. getSelectRowKeys,
  238. setSelectedRowKeys,
  239. handleEdit,
  240. handleDelete,
  241. handleBatchDelete,
  242. handleAdd,
  243. onSubmit
  244. }
  245. }
  246. })
  247. </script>
  248. <style lang="less" scoped>
  249. .tools {
  250. .tools-body {
  251. width: 100%;
  252. height: 100%;
  253. padding: 0 20px;
  254. background-color: #fff;
  255. }
  256. }
  257. </style>