index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <div class="registration-query flex flex-col h-full">
  3. <div class="flex-1 page-wrap">
  4. <div class="btn-group">
  5. <t-button theme="success" @click="handleAdd">新增</t-button>
  6. </div>
  7. <t-table
  8. size="small"
  9. row-key="id"
  10. :columns="columns"
  11. :data="tableData"
  12. bordered
  13. :pagination="{
  14. defaultCurrent: 1,
  15. defaultPageSize: 10,
  16. onChange,
  17. total: pagination.total,
  18. }"
  19. v-loading="tableLoading"
  20. >
  21. <template #buy-time="{ col, row }">
  22. {{ timestampFilter(row[col.colKey]) }}
  23. </template>
  24. <template #status="{ col, row }">
  25. {{ runningStatusFilter(row[col.colKey]) }}
  26. </template>
  27. </t-table>
  28. </div>
  29. <edit-device-dialog
  30. v-model:visible="showEditDeviceDialog"
  31. :curRow="curRow"
  32. @success="fetchData"
  33. ></edit-device-dialog>
  34. </div>
  35. </template>
  36. <script setup lang="jsx" name="DeviceManage">
  37. import { ref } from 'vue';
  38. import { DialogPlugin, MessagePlugin } from 'tdesign-vue-next';
  39. import useFetchTable from '@/hooks/useFetchTable';
  40. import EditDeviceDialog from './edit-device-dialog.vue';
  41. import { deviceQueryApi, deviceDestroyApi } from '@/api/system';
  42. import { runningStatusFilter, timestampFilter } from '@/utils/filter';
  43. const showEditDeviceDialog = ref(false);
  44. const curRow = ref(null);
  45. const columns = [
  46. { colKey: 'name', title: '设备编号' },
  47. { colKey: 'serialNo', title: '序列号' },
  48. { colKey: 'brand', title: '品牌' },
  49. { colKey: 'buyTime', title: '购买时间', cell: 'buy-time', width: 170 },
  50. { colKey: 'supplier', title: '供应商' },
  51. { colKey: 'status', title: '运行状态', cell: 'status', width: 80 },
  52. { colKey: 'location', title: '当前所在地' },
  53. { colKey: 'scanCount', title: '总扫描量', width: 80 },
  54. {
  55. title: '操作',
  56. colKey: 'operate',
  57. fixed: 'right',
  58. width: 120,
  59. align: 'center',
  60. cell: (h, { row }) => {
  61. return (
  62. <div class="table-operations">
  63. <t-link
  64. theme="primary"
  65. hover="color"
  66. onClick={(e) => {
  67. e.stopPropagation();
  68. handleEdit(row);
  69. }}
  70. >
  71. 修改
  72. </t-link>
  73. <t-link
  74. theme="danger"
  75. hover="color"
  76. onClick={(e) => {
  77. e.stopPropagation();
  78. handleDistroy(row);
  79. }}
  80. >
  81. 作废
  82. </t-link>
  83. </div>
  84. );
  85. },
  86. },
  87. ];
  88. const {
  89. loading: tableLoading,
  90. pagination,
  91. tableData,
  92. fetchData,
  93. onChange,
  94. } = useFetchTable(deviceQueryApi);
  95. const handleAdd = () => {
  96. curRow.value = null;
  97. showEditDeviceDialog.value = true;
  98. };
  99. const handleDistroy = (row) => {
  100. const confirmDia = DialogPlugin({
  101. header: '操作提示',
  102. body: `确定要作废选中的记录吗`,
  103. confirmBtn: '确定',
  104. cancelBtn: '取消',
  105. onConfirm: async () => {
  106. confirmDia.hide();
  107. const res = await deviceDestroyApi(row.id).catch(() => {});
  108. if (!res) return;
  109. MessagePlugin.success('删除成功');
  110. fetchData();
  111. },
  112. });
  113. };
  114. const handleEdit = (row) => {
  115. curRow.value = row;
  116. showEditDeviceDialog.value = true;
  117. };
  118. </script>