index.vue 11 KB

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