index.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <template>
  2. <div class="procedure-map">
  3. <div class="option-area">
  4. <label style="color: var(--vent-font-color)">设备类型:</label>
  5. <Select
  6. @change="handleChange"
  7. :options="deviceKindOption"
  8. :fieldNames="{ label: 'label', value: 'value' }"
  9. v-model:value="deviceKind"
  10. style="width: 200px; color: black"
  11. placeholder="请选择设备类型"
  12. :allowClear="true"
  13. />
  14. <a-button type="primary" preIcon="ant-design:search-outlined" style="margin: 0 15px" @click="getSearch">查询</a-button>
  15. <a-button preIcon="ant-design:sync-outlined" @click="onReset" style="margin-right: 15px">重置</a-button>
  16. <a-button type="primary" preIcon="ant-design:plus-outlined" @click="handleAdd">新增</a-button>
  17. <a-button type="primary" @click="handleLink" style="margin-left: 15px">自动关联</a-button>
  18. </div>
  19. <a-table size="small" :dataSource="dataSource" :columns="columnsMap" :scroll="{ y: 620 }" :pagination="pagination" @change="pageChange">
  20. <template #action="{ record }">
  21. <a class="table-action-link" @click="handleEdit(record)">编辑</a>
  22. <!-- <a class="table-action-link" @click="handleDel(record)">删除</a> -->
  23. <a-popconfirm title="确定删除?" @confirm="handleDel(record)">
  24. <a class="table-action-link">删除</a>
  25. </a-popconfirm>
  26. </template>
  27. </a-table>
  28. <!-- 添加/编辑弹窗 -->
  29. <a-modal v-model:visible="visibleMap" width="1000px" :footer="null" :title="titleMap" centered destroyOnClose>
  30. <proceduresModal :isToggle="isToggle" :formState="formState" @close="handleClose" />
  31. </a-modal>
  32. </div>
  33. </template>
  34. <script setup lang="ts">
  35. import { Select, message } from 'ant-design-vue';
  36. import { ref, reactive, onMounted } from 'vue';
  37. import { BasicColumn } from '/@/components/Table';
  38. import { getDictItemsByCode } from '/@/utils/dict';
  39. import { deleteById, getList, autoLinkReg } from './internalManager.api';
  40. // import { columnsMap } from './internalManager.data';
  41. import proceduresModal from './procedures-modal.vue';
  42. const dataSource = ref<any[]>([]);
  43. const deviceKind = ref<string>('');
  44. const deviceKindOption = ref([]);
  45. const regTypeOption = ref([]);
  46. //分页参数配置
  47. const pagination = reactive({
  48. current: 1, // 当前页码
  49. pageSize: 10, // 每页显示条数
  50. total: 0, // 总条目数,后端返回
  51. // showTotal: (total, range) => `${range[0]}-${range[1]} 条,总共 ${total} 条`, // 分页右下角显示信息
  52. showSizeChanger: true, // 是否可改变每页显示条数
  53. pageSizeOptions: ['10', '20', '50'], // 可选的每页显示条数
  54. });
  55. const visibleMap = ref(false);
  56. const titleMap = ref('');
  57. const isToggle = ref('');
  58. const formState = reactive({
  59. id: '',
  60. regName: '',
  61. regType: '',
  62. deviceKind: '',
  63. dataId: '',
  64. monitorDataName: '',
  65. regRoute: '',
  66. });
  67. const columnsMap: BasicColumn[] = [
  68. {
  69. title: '序号',
  70. width: 60,
  71. align: 'center',
  72. customRender: ({ index }: { index: number }) => `${index + 1}`,
  73. },
  74. {
  75. title: '规程名称',
  76. dataIndex: 'regName',
  77. align: 'center',
  78. },
  79. {
  80. title: '规程类型',
  81. dataIndex: 'regType',
  82. align: 'center',
  83. // 新增:通过规程类型字典映射中文
  84. customRender: ({ text }) => {
  85. // 从规程类型字典中找到匹配的中文label
  86. const matchItem = regTypeOption.value.find((item) => item.value === text);
  87. return matchItem ? matchItem.label : text; // 未匹配到则显示原字段
  88. },
  89. },
  90. {
  91. title: '设备种类',
  92. dataIndex: 'deviceKind',
  93. align: 'center',
  94. // 新增:通过设备种类字典映射中文
  95. customRender: ({ text }) => {
  96. // 从设备种类字典中找到匹配的中文label
  97. const matchItem = deviceKindOption.value.find((item) => item.value === text);
  98. return matchItem ? matchItem.label : text; // 未匹配到则显示原字段
  99. },
  100. },
  101. {
  102. title: '关联监测数据名称',
  103. dataIndex: 'monitorDataName',
  104. align: 'center',
  105. },
  106. {
  107. title: '规则路由',
  108. dataIndex: 'regRoute',
  109. align: 'center',
  110. },
  111. {
  112. title: '操作',
  113. dataIndex: 'action',
  114. width: 200,
  115. align: 'center',
  116. slots: { customRender: 'action' },
  117. },
  118. ];
  119. //关闭弹窗
  120. function handleClose() {
  121. visibleMap.value = false;
  122. getListMap();
  123. }
  124. //添加
  125. function handleAdd() {
  126. titleMap.value = '新增规程关联表';
  127. visibleMap.value = true;
  128. isToggle.value = 'add';
  129. Object.assign(formState, {
  130. id: '',
  131. regName: '',
  132. regType: '',
  133. deviceKind: '',
  134. dataId: '',
  135. monitorDataName: '',
  136. regRoute: '',
  137. });
  138. }
  139. //编辑
  140. function handleEdit(record) {
  141. titleMap.value = '编辑规程关联表';
  142. visibleMap.value = true;
  143. isToggle.value = 'edit';
  144. Object.assign(formState, {
  145. id: record.id,
  146. regName: record.regName,
  147. regType: record.regType,
  148. deviceKind: record.deviceKind,
  149. dataId: record.dataId,
  150. monitorDataName: record.monitorDataName,
  151. regRoute: record.regRoute,
  152. });
  153. }
  154. //删除
  155. async function handleDel(record) {
  156. await deleteById({ id: record.id });
  157. pagination.current = 1;
  158. getListMap();
  159. }
  160. //分页切换
  161. function pageChange(val) {
  162. pagination.current = val.current;
  163. pagination.pageSize = val.pageSize;
  164. getListMap();
  165. }
  166. //获取数据列表
  167. async function getListMap() {
  168. let res = await getList({ deviceKind: deviceKind.value, pageNo: pagination.current, pageSize: pagination.pageSize });
  169. if (res.records && res.records.length != 0) {
  170. dataSource.value = res.records;
  171. pagination.total = res.total;
  172. } else {
  173. dataSource.value = res.records;
  174. }
  175. }
  176. //查询
  177. function getSearch() {
  178. pagination.current = 1;
  179. getListMap();
  180. }
  181. //重置
  182. function onReset() {
  183. pagination.current = 1;
  184. getListMap();
  185. }
  186. // 设备类型切换
  187. function handleChange(type) {
  188. deviceKind.value = type;
  189. getListMap();
  190. }
  191. function handleLink() {
  192. if (deviceKind.value) {
  193. autoLinkReg({ Devicetype: deviceKind.value });
  194. console.log('自动关联设备类型:', deviceKind.value);
  195. } else {
  196. message.error('请选择设备类型进行自动关联');
  197. return;
  198. }
  199. }
  200. onMounted(() => {
  201. const deviceKindRes = getDictItemsByCode('devicekind');
  202. deviceKindOption.value = deviceKindRes;
  203. console.log('deviceKindOption', deviceKindOption.value);
  204. const regTypeRes = getDictItemsByCode('regType');
  205. regTypeOption.value = regTypeRes;
  206. console.log('regTypeOption', regTypeOption.value);
  207. getListMap();
  208. });
  209. </script>
  210. <style lang="less" scoped>
  211. @import '/@/design/theme.less';
  212. .procedure-map {
  213. position: relative;
  214. width: 100%;
  215. height: 100%;
  216. padding: 10px;
  217. box-sizing: border-box;
  218. .option-area {
  219. display: flex;
  220. height: 60px;
  221. align-items: center;
  222. }
  223. }
  224. :deep(.zxm-select-selector) {
  225. width: 100%;
  226. border: 1px solid var(--vent-form-item-border) !important;
  227. background-color: #ffffff00 !important;
  228. }
  229. :deep(.zxm-select-selection-item) {
  230. color: #fff !important;
  231. }
  232. </style>