index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. <!-- eslint-disable vue/multi-word-component-names -->
  2. <template>
  3. <!-- Tab标签页 -->
  4. <Tabs v-model:activeKey="activeKey" class="common-page-tabs" type="line" @change="handleTabChange">
  5. <TabPane key="unresolved" tab="未解决">
  6. <BasicTable style="padding: 0" @register="registerUnresolvedTable">
  7. <template #resetBefore>
  8. <a-button type="primary" class="ml-8px" preIcon="mdi:page-next-outline" @click="handleOpenModal({}, 'add')"> 新增问题 </a-button>
  9. <a-button type="default" class="ml-8px" preIcon="mdi:download" @click="handleOpenExportModal('unresolved')"> 导出 </a-button>
  10. </template>
  11. <template #queJson="{ record }">
  12. <div style="display: flex; align-items: center; gap: 8px; width: 100%; justify-content: space-between">
  13. <span style="white-space: pre-line; word-wrap: break-word; line-height: 1.6; display: block; text-align: left; padding: 2px 4px">
  14. {{ record?.queJson ? formatQueJson(record.queJson) : '' }}
  15. </span>
  16. <button @click="record && handleOpenModal(record, 'view')" class="action-btn" title="查看问题详情">
  17. <SvgIcon name="view" />
  18. </button>
  19. </div>
  20. </template>
  21. <template #action="{ record }">
  22. <button @click="handleOpenModal(record, 'edit')" class="action-btn" title="编辑该问题">
  23. <SvgIcon name="edit" />
  24. </button>
  25. <!-- 删除按钮 -->
  26. <Popconfirm
  27. title="删除确认"
  28. description="是否确认删除?"
  29. okText="确认"
  30. cancelText="取消"
  31. @confirm="handleDeleteRecord(record)"
  32. @cancel="handleCancel"
  33. placement="top"
  34. >
  35. <button class="action-btn" title="删除该问题">
  36. <SvgIcon name="delete" />
  37. </button>
  38. </Popconfirm>
  39. <Popconfirm
  40. title="标记已解决确认"
  41. :description="getResolveDesc(record)"
  42. okText="确认"
  43. cancelText="取消"
  44. @confirm="handleOKRecord(record)"
  45. @cancel="handleCancel"
  46. placement="top"
  47. >
  48. <button class="action-btn" title="标记该问题为已解决">
  49. <SvgIcon name="solved" />
  50. </button>
  51. </Popconfirm>
  52. <button @click="handleGoToPage(record)" class="action-btn" title="监测详情">
  53. <SvgIcon name="database" />
  54. </button>
  55. </template>
  56. </BasicTable>
  57. </TabPane>
  58. <TabPane key="resolved" tab="已解决">
  59. <BasicTable style="padding: 0" @register="registerResolvedTable">
  60. <template #resetBefore>
  61. <a-button type="default" class="ml-8px" preIcon="mdi:download" @click="handleOpenExportModal('resolved')"> 导出 </a-button>
  62. </template>
  63. <template #queJson="{ record }">
  64. <div style="display: flex; align-items: center; gap: 8px; width: 100%">
  65. <span style="flex: 1; text-align: center">
  66. {{ record?.queJson ? formatQueJson(record.queJson) : '' }}
  67. </span>
  68. <button @click="record && handleOpenModal(record, 'view')" class="action-btn" title="查看问题详情">
  69. <SvgIcon name="view" />
  70. </button>
  71. </div>
  72. </template>
  73. <template #action="{ record }">
  74. <button @click="handleOpenModal(record, 'view')" class="action-btn" title="问题详情">
  75. <SvgIcon name="details" />
  76. </button>
  77. </template>
  78. </BasicTable>
  79. </TabPane>
  80. </Tabs>
  81. <!-- 处理弹框 -->
  82. <DataQualityModal @register="registerModal" @success="handleModalSuccess" />
  83. <!-- 导出时间选择Modal-->
  84. <Modal
  85. v-model:open="exportModalVisible"
  86. title="选择导出时间范围"
  87. :width="600"
  88. @ok="handleExportConfirm"
  89. @cancel="handleExportCancel"
  90. okText="确认导出"
  91. cancelText="取消"
  92. centered
  93. :confirm-loading="exportConfirmLoading"
  94. destroyOnClose
  95. :bodyStyle="{ padding: '20px' }"
  96. >
  97. <a-form
  98. ref="exportFormRef"
  99. :model="exportFormData"
  100. :rules="exportFormRules"
  101. layout="horizontal"
  102. :label-col="{ span: 6 }"
  103. :wrapper-col="{ span: 18 }"
  104. >
  105. <a-form-item v-for="schema in exportFormSchema" :key="schema.field" :name="schema.field" :label="schema.label" :rules="schema.rules">
  106. <component
  107. :is="getExportFormComponent(schema.component)"
  108. v-model:value="exportFormData[schema.field]"
  109. v-bind="schema.componentProps"
  110. :placeholder="`请选择${schema.label}`"
  111. style="width: 100%"
  112. />
  113. </a-form-item>
  114. </a-form>
  115. </Modal>
  116. </template>
  117. <script setup lang="ts">
  118. import { ref, nextTick, computed, onMounted, reactive } from 'vue';
  119. import { BasicTable } from '/@/components/Table';
  120. import { useModal } from '/@/components/Modal';
  121. import { Tabs, TabPane, Popconfirm, message, Modal, DatePicker } from 'ant-design-vue';
  122. import type { FormInstance } from 'ant-design-vue/es/form';
  123. import DataQualityModal from './components/DataQualityModal.vue';
  124. import { SvgIcon } from '/@/components/Icon';
  125. import { columns, searchFormSchema, exportFormSchema } from './dataQuality.data';
  126. import { getDataQuaQueList, addDataQuaQue, deleteDataQuaQue, editDataQuaQue } from '../basicInfo.api';
  127. import { findNode } from '/@/utils/helper/treeHelper';
  128. import { useMineDepartmentStore } from '/@/store/modules/mine';
  129. // import { getDictItemsByCode } from '/@/utils/dict';
  130. import dayjs, { Dayjs } from 'dayjs';
  131. import { useListPage } from '/@/hooks/system/useListPage';
  132. import { advancedRoutePush } from '/@/utils/index.js';
  133. // 实例化矿井Store
  134. const mineStore = useMineDepartmentStore();
  135. // 响应式数据
  136. const activeKey = ref('unresolved'); // 激活的Tab键
  137. const pageMode = ref('add');
  138. // 导出Modal相关状态
  139. const exportModalVisible = ref(false);
  140. const exportFormRef = ref<FormInstance>();
  141. const exportConfirmLoading = ref(false);
  142. const exportType = ref<'resolved' | 'unresolved'>('unresolved'); // 记录当前导出类型
  143. const exportConfig = ref({
  144. url: '/province/dataQuaQue/exportDataQuaQueList',
  145. name: '数据质量问题反馈',
  146. params: {
  147. isOk: 0,
  148. startTime: '',
  149. endTime: '',
  150. },
  151. });
  152. // 导出表单数据和规则(参考DataQualityModal写法)
  153. const exportFormData = reactive({
  154. startTime: null as Dayjs | null,
  155. endTime: null as Dayjs | null,
  156. });
  157. // 提取导出表单规则(从exportFormSchema)
  158. const exportFormRules = reactive({
  159. startTime: exportFormSchema.find((item) => item.field === 'startTime')?.rules || [],
  160. endTime: exportFormSchema.find((item) => item.field === 'endTime')?.rules || [],
  161. });
  162. // 导出表单组件映射
  163. const exportFormComponentMap = {
  164. DatePicker,
  165. };
  166. // 获取导出表单组件
  167. const getExportFormComponent = (componentName: string) => {
  168. return exportFormComponentMap[componentName as keyof typeof exportFormComponentMap];
  169. };
  170. // 未解决表格注册
  171. const { tableContext: tableContextA, onExportXls: onExportXlsA } = useListPage({
  172. tableProps: {
  173. api: async (params: any) => {
  174. return await getDataQuaQueList({ ...params, isOk: false });
  175. },
  176. columns: columns, // 绑定动态列
  177. formConfig: {
  178. labelWidth: 120,
  179. schemas: searchFormSchema,
  180. showAdvancedButton: false,
  181. schemaGroupNames: ['常规查询'],
  182. actionColOptions: { span: 6 },
  183. },
  184. useSearchForm: true,
  185. pagination: true,
  186. showIndexColumn: false,
  187. indexColumnProps: {
  188. title: '序号',
  189. },
  190. actionColumn: {
  191. width: 200,
  192. title: '操作',
  193. dataIndex: 'action',
  194. slots: { customRender: 'action' },
  195. },
  196. immediate: false, // 先不立即加载,等状态数据获取后再加载
  197. },
  198. exportConfig: exportConfig.value,
  199. });
  200. const [registerUnresolvedTable, { reload: reloadUnresolved }] = tableContextA;
  201. // 已解决表格注册
  202. const { tableContext: tableContextB, onExportXls: onExportXlsB } = useListPage({
  203. tableProps: {
  204. api: async (params: any) => {
  205. return await getDataQuaQueList({ ...params, isOk: true });
  206. },
  207. columns: columns,
  208. formConfig: {
  209. labelWidth: 120,
  210. schemas: searchFormSchema,
  211. showAdvancedButton: false,
  212. schemaGroupNames: ['常规查询'],
  213. },
  214. useSearchForm: true,
  215. pagination: true,
  216. striped: true,
  217. showIndexColumn: false,
  218. indexColumnProps: {
  219. title: '序号',
  220. },
  221. showActionColumn: false,
  222. // actionColumn: {
  223. // width: 60,
  224. // title: '操作',
  225. // dataIndex: 'action',
  226. // slots: { customRender: 'action' },
  227. // },
  228. immediate: false, // 先不立即加载
  229. },
  230. exportConfig: exportConfig.value,
  231. });
  232. const [registerResolvedTable, { reload: reloadResolved }] = tableContextB;
  233. // 弹框注册
  234. const [registerModal, { openModal }] = useModal();
  235. /**
  236. * 打开导出时间选择Modal
  237. * @param type 导出类型:resolved 或 unresolved
  238. */
  239. function handleOpenExportModal(type: 'resolved' | 'unresolved') {
  240. exportType.value = type;
  241. exportModalVisible.value = true;
  242. // 打开Modal时重置表单
  243. nextTick(() => {
  244. exportFormRef.value?.resetFields();
  245. exportFormData.startTime = null;
  246. exportFormData.endTime = null;
  247. });
  248. }
  249. /**
  250. * 导出Modal确认处理
  251. */
  252. async function handleExportConfirm() {
  253. try {
  254. exportConfirmLoading.value = true;
  255. // 表单校验(参考DataQualityModal的校验方式)
  256. if (!exportFormRef.value) return;
  257. const validateResult = await exportFormRef.value.validate();
  258. if (!validateResult) return;
  259. // 格式化时间
  260. const startTime = exportFormData.startTime?.format('YYYY-MM-DD HH:mm:ss') || '';
  261. const endTime = exportFormData.endTime?.format('YYYY-MM-DD HH:mm:ss') || '';
  262. // 校验时间逻辑(结束时间不能早于开始时间)
  263. if (exportFormData.startTime && exportFormData.endTime && dayjs(endTime).isBefore(dayjs(startTime))) {
  264. message.error('结束时间不能早于开始时间');
  265. return;
  266. }
  267. // 根据类型选择对应的exportConfig和导出方法
  268. exportConfig.value.params = {
  269. isOk: exportType.value === 'resolved' ? 1 : 0,
  270. startTime,
  271. endTime,
  272. };
  273. if (exportType.value === 'unresolved') {
  274. await onExportXlsA();
  275. } else {
  276. await onExportXlsB();
  277. }
  278. // 关闭Modal
  279. exportModalVisible.value = false;
  280. // message.success('导出请求已发送,请注意查收文件');
  281. } catch (error: any) {
  282. console.error('导出失败:', error);
  283. message.error(error.message || '导出失败,请检查表单填写是否正确');
  284. } finally {
  285. exportConfirmLoading.value = false;
  286. }
  287. }
  288. /**
  289. * 导出Modal取消处理
  290. */
  291. function handleExportCancel() {
  292. exportModalVisible.value = false;
  293. // 取消时重置表单
  294. exportFormRef.value?.resetFields();
  295. exportFormData.startTime = null;
  296. exportFormData.endTime = null;
  297. }
  298. // 解析queJson并拼接orderNum+queCon的辅助函数
  299. function formatQueJson(queJsonStr: string) {
  300. // 空值处理
  301. if (!queJsonStr) return '无质量问题';
  302. try {
  303. const queList = JSON.parse(queJsonStr);
  304. // 非数组格式处理
  305. if (!Array.isArray(queList)) return '问题格式异常';
  306. // 空数组处理
  307. if (queList.length === 0) return '无质量问题';
  308. return queList
  309. .map((item) => {
  310. const goafName = item.goafName;
  311. const queCon = item.queCon || '无描述';
  312. return `<${goafName}工作面老空区永久密闭监测>存在的问题:${queCon}`;
  313. })
  314. .join('\n'); // 多个问题分行显示
  315. } catch (error) {
  316. console.error('解析质量问题JSON失败:', error);
  317. return '问题数据解析失败';
  318. }
  319. }
  320. // 安全重载当前激活的表格
  321. async function safeReloadActiveTable() {
  322. await nextTick();
  323. if (activeKey.value === 'unresolved') {
  324. try {
  325. await reloadUnresolved();
  326. } catch (e) {
  327. console.warn('未解决表格重载失败:', e);
  328. }
  329. } else {
  330. try {
  331. await reloadResolved();
  332. } catch (e) {
  333. console.warn('已解决表格重载失败:', e);
  334. }
  335. }
  336. }
  337. // 按需重载双表格(先注释掉)
  338. // async function reloadBothTableSafely() {
  339. // await nextTick();
  340. // // 未解决表格:await + try/catch 捕获异步错误
  341. // try {
  342. // await reloadUnresolved();
  343. // } catch (e) {
  344. // console.warn('未解决表格暂未就绪,跳过重载:', e);
  345. // }
  346. // // 已解决表格:同理,一个报错不影响另一个
  347. // try {
  348. // await reloadResolved();
  349. // } catch (e) {
  350. // console.warn('已解决表格暂未就绪,跳过重载:', e);
  351. // }
  352. // }
  353. // tabs切换事件
  354. async function handleTabChange(key: string) {
  355. activeKey.value = key;
  356. await safeReloadActiveTable();
  357. }
  358. /**
  359. * 打开弹框函数
  360. * @param result 弹框数据
  361. */
  362. function handleOpenModal(record: any, mode: 'view' | 'edit' | 'add' = 'view') {
  363. pageMode.value = mode;
  364. openModal(true, { record, mode });
  365. }
  366. /**
  367. * 弹框结果处理函数
  368. * @param result 弹框数据
  369. */
  370. async function handleModalSuccess(result: any) {
  371. try {
  372. if (pageMode.value === 'add') {
  373. await addDataQuaQue(result);
  374. } else if (pageMode.value === 'edit') {
  375. await editDataQuaQue(result);
  376. }
  377. await safeReloadActiveTable();
  378. } catch (error) {
  379. console.error('操作失败:', error);
  380. }
  381. }
  382. /**
  383. * 通用页面跳转方法
  384. * @param record 当前行数据
  385. * @param path 目标路径(树形结构所在页面的路由地址)
  386. */
  387. async function handleGoToPage(record: any) {
  388. try {
  389. const mineCode = record.mineCode;
  390. const targetNode = findNode(mineStore.getDepartTree, (item) => item.fax === mineCode, { id: 'id', pid: 'parentId', children: 'childDepart' });
  391. let minePath = '';
  392. if (targetNode) {
  393. minePath = targetNode.parentId;
  394. } else {
  395. message.warning(`未找到矿码【${mineCode}】对应的矿井节点`);
  396. return;
  397. }
  398. // 跳转页面(可携带拼接后的矿名/路径等参数)
  399. advancedRoutePush({ path: `/sealed/${minePath}`, query: { deptId: targetNode.id } });
  400. } catch (error) {
  401. console.error('矿节点定位失败:', error);
  402. message.error('矿节点定位失败,请稍后重试');
  403. }
  404. }
  405. /**
  406. * 气泡取消按钮通用回调
  407. */
  408. function handleCancel() {
  409. // 取消操作,无逻辑(仅关闭气泡)
  410. }
  411. /**
  412. * 生成已解决气泡提示文案:XX矿井XX问题是否解决了吗?
  413. */
  414. const getResolveDesc = computed(() => (record: any) => {
  415. const mineName = record.mineName || '该';
  416. return `是否确认${mineName}矿井问题已解决?`;
  417. });
  418. /**
  419. * 删除记录方法
  420. * @param record 当前行数据
  421. */
  422. async function handleDeleteRecord(record: any) {
  423. try {
  424. await deleteDataQuaQue({ id: record.id });
  425. await nextTick();
  426. await safeReloadActiveTable();
  427. } catch (error) {
  428. console.error('删除失败:', error);
  429. }
  430. }
  431. /**
  432. * 将记录改为已处理
  433. * @param record 当前行数据
  434. */
  435. async function handleOKRecord(record: any) {
  436. const copyRecord = {
  437. ...record,
  438. isOk: true,
  439. updateTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
  440. };
  441. try {
  442. await editDataQuaQue(copyRecord);
  443. await safeReloadActiveTable();
  444. message.success('标记为已解决成功');
  445. } catch (error) {
  446. console.error('操作失败:', error);
  447. message.error('操作失败,请稍后重试');
  448. }
  449. }
  450. // ========== 初始化:先获取状态数据,再加载表格 ==========
  451. onMounted(async () => {
  452. await safeReloadActiveTable();
  453. });
  454. </script>
  455. <style scoped lang="less">
  456. .form-part {
  457. padding: 12px 10px 6px 10px;
  458. margin-bottom: 8px;
  459. background-color: @white;
  460. border-radius: 2px;
  461. }
  462. .add-button {
  463. margin-bottom: 10px;
  464. }
  465. .action-btn {
  466. height: 30px;
  467. cursor: pointer;
  468. margin-right: 10px;
  469. &:last-child {
  470. margin-right: 0;
  471. }
  472. }
  473. </style>