index.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <template>
  2. <div>
  3. <BasicTable @register="registerTable" @resizeColumn="resizeColumn">
  4. <template #bodyCell="{ column, record }">
  5. <template v-if="column.key === 'disable'">
  6. <Tag :color="record.disable ? 'error' : 'success'">
  7. {{ commonDict(record.disable, 1) }}
  8. </Tag>
  9. </template>
  10. <template v-if="column.key === 'sysInner'">
  11. <Tag :color="record.sysInner ? 'success' : 'error'">
  12. {{ commonDict(record.sysInner, 1) }}
  13. </Tag>
  14. </template>
  15. <template v-if="column.key === 'action'">
  16. <TableAction
  17. :actions="[
  18. {
  19. icon: 'icon-edit|iconfont',
  20. tooltip: '编辑',
  21. onClick: handleEdit.bind(null, record),
  22. },
  23. {
  24. icon: 'icon-delete|iconfont',
  25. tooltip: '删除',
  26. color: 'error',
  27. popConfirm: {
  28. title: '是否确认删除',
  29. placement: 'left',
  30. confirm: handleDelete.bind(null, record),
  31. },
  32. },
  33. ]"
  34. />
  35. </template>
  36. </template>
  37. <template #search="{ onSearch }">
  38. <div class="search">
  39. <a-input-search
  40. class="table-search-item"
  41. v-model:value="tableSearch.value1"
  42. placeholder="请输入姓名"
  43. @search="onSearch"
  44. />
  45. <a-select
  46. ref="select"
  47. placeholder="选择病区"
  48. v-model:value="tableSearch.value2"
  49. style="width: 120px"
  50. @change="onSearch"
  51. class="table-search-item"
  52. >
  53. <a-select-option value="1"> <span class="mr-1">病区</span>全部 </a-select-option>
  54. <a-select-option value="jack"> <span class="mr-1">病区</span>Jack </a-select-option>
  55. <a-select-option value="lucy"><span class="mr-1">病区</span>Lucy</a-select-option>
  56. <a-select-option value="Yiminghe"
  57. ><span class="mr-1">病区</span>yiminghe</a-select-option
  58. >
  59. </a-select>
  60. <a-select
  61. ref="select"
  62. placeholder="选择设备"
  63. v-model:value="tableSearch.value3"
  64. style="width: 120px"
  65. @change="onSearch"
  66. class="table-search-item"
  67. >
  68. <a-select-option value="1"> <span class="mr-1">设备</span>全部 </a-select-option>
  69. <a-select-option value="jack"> <span class="mr-1">设备</span>111 </a-select-option>
  70. <a-select-option value="lucy"><span class="mr-1">设备</span>222</a-select-option>
  71. <a-select-option value="Yiminghe"><span class="mr-1">设备</span>333</a-select-option>
  72. </a-select>
  73. </div>
  74. </template>
  75. <template #toolbar>
  76. <a-button
  77. v-auth="['system:sysConfig:add']"
  78. preIcon="icon-plus|iconfont"
  79. type="primary"
  80. @click="handleCreate"
  81. >新增
  82. </a-button>
  83. <!-- <a-button
  84. v-auth="['system:sysConfig:export']"
  85. color="warning"
  86. preIcon="ant-design:download-outlined"
  87. @click="handleExport"
  88. >导出
  89. </a-button> -->
  90. <a-button
  91. v-auth="['system:sysConfig:refresh']"
  92. color="success"
  93. preIcon="icon-redo|iconfont"
  94. @click="handleRefresh"
  95. >刷新缓存
  96. </a-button>
  97. </template>
  98. </BasicTable>
  99. <FormModal @register="registerModal" @success="handleSuccess" />
  100. </div>
  101. </template>
  102. <script lang="ts" setup>
  103. import { ref, onBeforeMount, reactive } from 'vue';
  104. import { Tag } from 'ant-design-vue';
  105. import { BasicTable, TableAction, useTable } from '/@/components/Table';
  106. import { useModal } from '/@/components/Modal';
  107. import { useMessage } from '/@/hooks/web/useMessage';
  108. import FormModal from './FormModal.vue';
  109. import { columns, searchBasicFormSchema, searchFormSchema } from './data';
  110. // import { exportList, fetchList, refresh, removeObj } from '/@/api/modules/system/sysConfigApi';
  111. import { sysConfigQueryList, sysConfigRemove } from '/@/api/sys/sysConfigApi';
  112. // import { downloadFile, listDictModel } from '/@/api/common';
  113. // import { listDictModel } from '/@/api/common';
  114. import { commonDict } from '/@/utils';
  115. import { templateRef } from '@vueuse/core';
  116. import { useDebounceFn } from '@vueuse/shared';
  117. defineOptions({
  118. name: 'sysConfig',
  119. });
  120. // const sysStatusOptions = ref([]);
  121. onBeforeMount(async () => {
  122. // sysStatusOptions.value = await listDictModel({ dictCode: 'sys_status' });
  123. });
  124. const tableSearch = reactive({
  125. value1: '',
  126. value2: '1',
  127. value3: '1',
  128. });
  129. const { createMessage, createConfirm } = useMessage();
  130. const [registerTable, { reload, getCacheColumns, setColumns }] = useTable({
  131. // 存储需要设置 id 和 storage
  132. id: 'sys_config',
  133. storage: true,
  134. title: '参数列表',
  135. api: sysConfigQueryList,
  136. rowKey: 'id',
  137. columns,
  138. formConfig: {
  139. formId: 'sys_config',
  140. labelWidth: 100,
  141. schemas: searchFormSchema,
  142. actionColOptions: {
  143. xs: 24,
  144. sm: 12,
  145. md: 12,
  146. lg: 8,
  147. },
  148. autoSubmitOnEnter: true,
  149. baseColProps: { xs: 24, sm: 12, md: 12, lg: 8 },
  150. resetButtonOptions: {
  151. preIcon: 'icon-delete|iconfont',
  152. },
  153. submitButtonOptions: {
  154. preIcon: 'icon-search|iconfont',
  155. },
  156. },
  157. basicSearch: {
  158. schemas: searchBasicFormSchema,
  159. fields: tableSearch,
  160. },
  161. showIndexColumn: true,
  162. useSearchForm: true,
  163. showTableSetting: true,
  164. bordered: true,
  165. actionColumn: {
  166. auth: ['system:sysConfig:edit', 'system:sysConfig:remove'],
  167. width: 80,
  168. title: '操作',
  169. dataIndex: 'action',
  170. },
  171. });
  172. const [registerModal, { openModal }] = useModal();
  173. // 新增按钮事件
  174. function handleCreate() {
  175. openModal(true, {
  176. isUpdate: false,
  177. });
  178. }
  179. // 编辑按钮事件
  180. function handleEdit(record: Recordable) {
  181. console.log(record);
  182. openModal(true, {
  183. record,
  184. isUpdate: true,
  185. });
  186. }
  187. // 删除按钮事件
  188. async function handleDelete(record: Recordable) {
  189. console.log(record);
  190. await sysConfigRemove([record.id]);
  191. createMessage.success('删除成功!');
  192. await reload();
  193. }
  194. // 导出按钮事件
  195. // async function handleExport() {
  196. // createConfirm({
  197. // iconType: 'warning',
  198. // title: '提示',
  199. // content: '确认导出?',
  200. // onOk: async () => {
  201. // const params = getForm().getFieldsValue();
  202. // const filepath = await exportList(params);
  203. // downloadFile(filepath);
  204. // },
  205. // });
  206. // }
  207. // 刷新缓存按钮事件
  208. async function handleRefresh() {
  209. createConfirm({
  210. iconType: 'warning',
  211. title: '提示',
  212. content: '确认刷新所有参数缓存?',
  213. onOk: async () => {
  214. await sysConfigQueryList({});
  215. createMessage.success('刷新成功!');
  216. },
  217. });
  218. }
  219. // 弹窗回调事件
  220. async function handleSuccess({ isUpdate, values }) {
  221. console.log(isUpdate);
  222. console.log(values);
  223. await reload();
  224. }
  225. const debounceFn = useDebounceFn(async (w, col) => {
  226. const cacheColumns = await getCacheColumns();
  227. const columns = cacheColumns.map(ele => {
  228. if (ele.dataIndex == col.dataIndex) {
  229. ele.width = w;
  230. }
  231. return ele;
  232. }) as any;
  233. setColumns(columns);
  234. }, 1000 * 3);
  235. // 动态设置宽度
  236. async function resizeColumn(w, col) {
  237. col.width = w;
  238. debounceFn(w, col);
  239. }
  240. </script>
  241. <sytle scoped lang="less">
  242. .table-search {
  243. display: flex;
  244. justify-content: space-between;
  245. align-items: center;
  246. &-item {
  247. margin-right: 10px;
  248. max-width: 180px;
  249. }
  250. }
  251. </sytle>