index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <!-- eslint-disable vue/multi-word-component-names -->
  2. <template>
  3. <Flex class="algorithm-model h-full">
  4. <!-- <EnfMineTree class="flex-grow-1" @select="onTreeSelect" /> -->
  5. <!--引用表格-->
  6. <BasicTable class="flex-grow-1" :expandedRowKeys="expandedRowKeys" :ellipsis="true" @register="registerTable">
  7. <!-- <template #formTitle>
  8. <a-button type="primary" @click="handleEdit({}, 'coal')">
  9. <PlusOutlined />
  10. 新增
  11. </a-button>
  12. 矿区CODE级联选择器占位符
  13. </template> -->
  14. <template #expandedRowRender>
  15. <BasicTable @register="registerInnerTable">
  16. <template #action="{ record }">
  17. <button @click="handleEdit({ goafId: record.id, mineCode: last(expandedRowKeys) }, 'goaf')" class="action-btn" title="编辑">
  18. <SvgIcon name="edit" />
  19. </button>
  20. <!-- <button @click="handleAdd({ goafId: record.id, mineCode: last(expandedRowKeys) }, 'goaf')" class="action-btn ml-1">
  21. <PlusOutlined />
  22. </button> -->
  23. <a-popconfirm title="确认删除?" @confirm="handleDelete(record, 'coal')">
  24. <button @click="handleDelete(record, 'goaf')" class="action-btn ml-1" title="删除">
  25. <SvgIcon name="delete" />
  26. </button>
  27. </a-popconfirm>
  28. </template>
  29. </BasicTable>
  30. </template>
  31. <template #action="{ record }">
  32. <button @click="handleEdit({ coalSeamId: record.id, mineCode: record.mineCode }, 'coal')" class="action-btn" title="编辑">
  33. <SvgIcon name="edit" />
  34. </button>
  35. <!-- <button @click="handleAdd({ coalSeamId: record.id, mineCode: record.mineCode }, 'coal')" class="action-btn ml-1">
  36. <PlusOutlined />
  37. </button> -->
  38. <a-popconfirm title="确认删除?" @confirm="handleDelete(record, 'coal')">
  39. <button class="action-btn ml-1" title="删除">
  40. <SvgIcon name="delete" />
  41. </button>
  42. </a-popconfirm>
  43. </template>
  44. </BasicTable>
  45. </Flex>
  46. <BasicModal width="60%" :height="600" @register="registerModal" @ok="handleSubmit" title="预警参数设置">
  47. <BasicForm @register="registerForm">
  48. <template #InputRangeNumber="{ model, field, schema }">
  49. <a-form-item>
  50. <a-input-group>
  51. <a-input-number v-model:value="model[`${field}Start`]" style="width: calc(50% - 100px)" placeholder="-" />
  52. <a-input style="width: 200px; border-left: 0; pointer-events: none; color: inherit" :value="schema.groupName" disabled />
  53. <a-input-number v-model:value="model[`${field}End`]" style="width: calc(50% - 100px); border-left: 0" placeholder="-" />
  54. </a-input-group>
  55. </a-form-item>
  56. </template>
  57. <template #InputGreaterNumber="{ model, field, schema }">
  58. <a-form-item>
  59. <a-input-group>
  60. <a-input-number style="width: calc(50% - 100px)" placeholder="-" disabled />
  61. <a-input style="width: 200px; border-left: 0; pointer-events: none; color: inherit" :value="schema.groupName" disabled />
  62. <a-input-number v-model:value="model[field]" style="width: calc(50% - 100px); border-left: 0" placeholder="-" />
  63. </a-input-group>
  64. </a-form-item>
  65. </template>
  66. <template #InputLowerNumber="{ model, field, schema }">
  67. <a-form-item>
  68. <a-input-group>
  69. <a-input-number v-model:value="model[field]" style="width: calc(50% - 100px)" placeholder="-" />
  70. <a-input style="width: 200px; border-left: 0; pointer-events: none; color: inherit" :value="schema.groupName" disabled />
  71. <a-input-number style="width: calc(50% - 100px); border-left: 0" placeholder="-" disabled />
  72. </a-input-group>
  73. </a-form-item>
  74. </template>
  75. <template #InputRangeGoaf="{ model, field, schema }">
  76. <a-form-item v-if="model[field]">
  77. <a-input-group>
  78. <a-input-number v-model:value="model[field][`lowerLimit`]" style="width: calc(50% - 100px)" placeholder="-" />
  79. <a-input style="width: 200px; border-left: 0; pointer-events: none; color: inherit" :value="schema.groupName" disabled />
  80. <a-input-number v-model:value="model[field][`upperLimit`]" style="width: calc(50% - 100px); border-left: 0" placeholder="-" />
  81. </a-input-group>
  82. </a-form-item>
  83. </template>
  84. </BasicForm>
  85. </BasicModal>
  86. </template>
  87. <script lang="ts" setup>
  88. import { nextTick, provide, ref } from 'vue';
  89. import { useDesign } from '/@/hooks/web/useDesign';
  90. // import EnfMineTree from './components/EnfMineTree.vue';
  91. import { useModal, BasicModal, ModalProps } from '/@/components/Modal';
  92. import { useForm, BasicForm } from '/@/components/Form';
  93. import { BasicTable, useTable } from '/@/components/Table';
  94. import { useListPage } from '/@/hooks/system/useListPage';
  95. import { columnsCoalAlarm, columnsGoafLimit, schemasCoalAlarm, schemasGoafLimit, searchFormSchema, goafAlarmModel } from './algorithm.data';
  96. import {
  97. addCoalSeamAlarmRule,
  98. deleteCoalSeamAlarmRule,
  99. deleteGoafDataLimit,
  100. getCoalSeam,
  101. getGoafList,
  102. updateCoalSeamAlarmRule,
  103. getCoalSeamAlarmRule,
  104. getGoafDataLimit,
  105. patchGoafDataLimit,
  106. } from './algorithm.api';
  107. import { Flex } from 'ant-design-vue';
  108. // import { PlusOutlined } from '@ant-design/icons-vue';
  109. import { forEach, last, isString } from 'lodash-es';
  110. import { message } from 'ant-design-vue';
  111. import { SvgIcon } from '/@/components/Icon';
  112. const { prefixCls } = useDesign('algorithm-list');
  113. provide('prefixCls', prefixCls);
  114. // 为了更好的控制展开逻辑
  115. const expandedRowKeys = ref<string[]>([]);
  116. // 列表页面公共参数、方法
  117. const { tableContext } = useListPage({
  118. tableProps: {
  119. api: getCoalSeam,
  120. columns: columnsCoalAlarm,
  121. rowKey: 'id',
  122. showIndexColumn: true,
  123. formConfig: {
  124. // showResetButton: false,
  125. schemas: searchFormSchema,
  126. schemaGroupNames: ['常规查询'],
  127. },
  128. onExpand(expanded, record) {
  129. // 展开最多一行
  130. if (expanded) {
  131. expandedRowKeys.value = [record.id];
  132. nextTick(reloadInner);
  133. } else {
  134. expandedRowKeys.value = [];
  135. }
  136. },
  137. },
  138. });
  139. //注册table数据
  140. const [registerTable] = tableContext;
  141. const [registerInnerTable, { reload: reloadInner }] = useTable({
  142. api: getGoafList,
  143. columns: columnsGoafLimit,
  144. rowKey: 'id',
  145. pagination: false,
  146. showActionColumn: true,
  147. actionColumn: {
  148. title: '操作',
  149. dataIndex: 'action',
  150. slots: { customRender: 'action' },
  151. },
  152. immediate: false,
  153. beforeFetch(p) {
  154. p.coalSeamId = expandedRowKeys.value[0];
  155. },
  156. });
  157. const formPropsMap = new Map([
  158. [
  159. 'coal',
  160. {
  161. schemas: schemasCoalAlarm,
  162. submitFunc: (res) => (res.id ? updateCoalSeamAlarmRule(res) : addCoalSeamAlarmRule(res)),
  163. fetchRecord: (params) => getCoalSeamAlarmRule(params).then((r) => last(r)),
  164. },
  165. ],
  166. [
  167. 'goaf',
  168. {
  169. schemas: schemasGoafLimit,
  170. submitFunc: (res) => patchGoafDataLimit(res),
  171. fetchRecord: (params) =>
  172. getGoafDataLimit(params).then((r) => {
  173. const result: any = {};
  174. forEach(goafAlarmModel, (item, key) => {
  175. result[key] = { ...params, ...item };
  176. });
  177. forEach(r, (item) => {
  178. result[item.alarmField] = item;
  179. });
  180. return result;
  181. }),
  182. },
  183. ],
  184. ]);
  185. const modalPropsMap = new Map<string, Partial<ModalProps>>([
  186. ['coal', { title: '预警参数设置', visible: true, loading: true }],
  187. ['goaf', { title: '超限预警设置', visible: true, loading: true }],
  188. ]);
  189. const submitResolver = ref<(res: any) => Promise<unknown>>();
  190. // 点击编辑后,获取对应的表单和弹窗配置
  191. async function handleEdit(record, sign: string) {
  192. if (!modalPropsMap.has(sign)) return;
  193. if (!formPropsMap.has(sign)) return;
  194. setModalProps(modalPropsMap.get(sign) as ModalProps);
  195. const { schemas, fetchRecord, submitFunc } = formPropsMap.get(sign)!;
  196. const res = await fetchRecord(record);
  197. await resetSchema(schemas);
  198. await nextTick();
  199. await setFieldsValue(res);
  200. await nextTick();
  201. // 不要使用setFormProps因为它会错误的触发submit方法
  202. // await setFormProps({ submitFunc });
  203. submitResolver.value = (res) => submitFunc(Object.assign(res, record));
  204. setModalProps({ loading: false });
  205. }
  206. // async function handleAdd(record, sign: string) {
  207. // if (!modalPropsMap.has(sign)) return;
  208. // if (!formPropsMap.has(sign)) return;
  209. // setModalProps(modalPropsMap.get(sign) as ModalProps);
  210. // const { schemas, submitFunc } = formPropsMap.get(sign)!;
  211. // await nextTick();
  212. // await resetSchema(schemas);
  213. // await nextTick();
  214. // await resetFields();
  215. // await nextTick();
  216. // // 不要使用setFormProps因为它会错误的触发submit方法
  217. // // await setFormProps({ submitFunc });
  218. // submitResolver.value = (res) => submitFunc(Object.assign(res, record));
  219. // setModalProps({ loading: false });
  220. // }
  221. const deletionPropsMap = new Map<string, { api: (id: string) => Promise<void> }>([
  222. ['coal', { api: (id) => deleteCoalSeamAlarmRule({ id }) }],
  223. ['goaf', { api: (id) => deleteGoafDataLimit({ id }) }],
  224. ]);
  225. function handleDelete(record, sign: string) {
  226. if (!deletionPropsMap.has(sign)) return;
  227. deletionPropsMap.get(sign)?.api(record.id);
  228. }
  229. const [registerModal, { setModalProps }] = useModal();
  230. const [registerForm, { setFieldsValue, validate, resetSchema }] = useForm({
  231. model: {},
  232. schemas: schemasCoalAlarm,
  233. showResetButton: false,
  234. showSubmitButton: false,
  235. colon: false,
  236. compact: true,
  237. });
  238. function handleSubmit() {
  239. return validate().then((res) => {
  240. submitResolver.value &&
  241. submitResolver
  242. .value(res)
  243. .then(() => {
  244. message.success('操作成功');
  245. setModalProps({ visible: false });
  246. })
  247. .catch((e) => {
  248. message.error(isString(e) ? e : '操作失败');
  249. });
  250. });
  251. }
  252. </script>
  253. <style lang="less">
  254. @import './index.less';
  255. .ant-input-group {
  256. display: flex;
  257. text-align: center;
  258. .ant-input-number {
  259. min-width: 100px;
  260. &:first-child {
  261. border-top-right-radius: 0;
  262. border-bottom-right-radius: 0;
  263. }
  264. &:last-child {
  265. border-top-left-radius: 0;
  266. border-bottom-left-radius: 0;
  267. }
  268. }
  269. }
  270. </style>