Преглед на файлове

[Mod 0000] 加强矿端选择器校验规则

houzekong преди 6 дни
родител
ревизия
59cfd68fe3

+ 3 - 2
src/views/analysis/warningAnalysis/windPointManage/goafManage/goafManage.data.ts

@@ -1,7 +1,7 @@
 import type { BasicColumn } from '/@/components/Table';
 import type { FormSchema } from '/@/components/Table';
 import { h } from 'vue';
-import { renderMineNameByFax } from '../windPointManage.data';
+import { renderMineNameByFax, mineLeafDynamicRules } from '../windPointManage.data';
 
 /** 供风区域(采空区/Goaf)管理表格列 */
 export const goafColumns: BasicColumn[] = [
@@ -36,7 +36,8 @@ export const goafFormSchema: FormSchema[] = [
     label: '煤矿编号',
     field: 'mineCode',
     component: 'MineCascader',
-    required: true,
+    // 必选到矿井(叶子):必填与 isLeaf 校验由 mineLeafDynamicRules 单条规则承担
+    dynamicRules: mineLeafDynamicRules,
     // 编辑态(已有 id)禁用矿编码,避免误改归属矿井;新增态保持可选
     dynamicDisabled: ({ values }) => !!values.id,
     componentProps: {

+ 7 - 14
src/views/analysis/warningAnalysis/windPointManage/windPointManage.api.ts

@@ -20,25 +20,17 @@ enum Api {
 }
 
 /** 获取 MineArea 列表 */
-export const getPointList = (params?: any) => {
-  const p = { ...params };
-  // 搜索表单 MineCascader 提交的是部门 id,需换算为 API 查询条件要求的矿编码(fax)
-  // if (p.deptId) {
-  //   const mine = useMineDepartmentStore().findDepartById(p.deptId);
-  //   if (mine?.fax) p.mineCode = mine.fax;
-  //   delete p.deptId;
-  // }
-  return defHttp.post({ url: Api.getPointList, params: p }, { joinParamsToUrl: true });
-};
+export const getPointList = (params?: any) => defHttp.post({ url: Api.getPointList, params }, { joinParamsToUrl: true });
 
 /** 新增或编辑 MineArea(根据是否有 id 自动切换) */
 export const savePoint = (params?: any) => {
   const url = params?.id ? Api.updateMineArea : Api.addMineArea;
   const payload = { ...params };
-  // 表单 mineCode 为 MineCascader 的部门 id,需换算为 API 需要的矿编码(fax)
+  // 表单 mineCode 为 MineCascader 选中矿井的部门 id,换算为 API 需要的矿编码(fax);
+  // 表单校验(mineLeafDynamicRules)已保证必选到叶子矿井,故无需再判断 mine?.fax
   if (payload.mineCode) {
     const mine = useMineDepartmentStore().findDepartById(payload.mineCode);
-    if (mine?.fax) payload.mineCode = mine.fax;
+    if (mine) payload.mineCode = mine.fax;
   }
   // 供风区域:多选 id 数组 → 后端约定的对象数组 [{ id }]
   if (payload.goafList) {
@@ -57,10 +49,11 @@ export const getGoafList = (params?: any) => defHttp.post({ url: Api.getGoafList
 export const saveGoaf = (params?: any) => {
   const url = params?.id ? Api.updateGoaf : Api.addGoaf;
   const payload = { ...params };
-  // 表单 mineCode 为 MineCascader 的部门 id,需换算为 API 需要的矿编码(fax)
+  // 表单 mineCode 为 MineCascader 选中矿井的部门 id,换算为 API 需要的矿编码(fax);
+  // 表单校验(mineLeafDynamicRules)已保证必选到叶子矿井,故无需再判断 mine?.fax
   if (payload.mineCode) {
     const mine = useMineDepartmentStore().findDepartById(payload.mineCode);
-    if (mine?.fax) payload.mineCode = mine.fax;
+    if (mine) payload.mineCode = mine.fax;
   }
   return defHttp.post({ url, params: payload });
 };

+ 22 - 4
src/views/analysis/warningAnalysis/windPointManage/windPointManage.data.ts

@@ -12,7 +12,24 @@ export function renderMineNameByFax(mineCode: string): string {
   return mine?.departName || mineCode;
 }
 
-/** 注册测风点位管理表格列 */
+/** 煤矿编号(MineCascader)提交校验:必须选到矿井(叶子节点 isLeaf=true)。
+ *  单条自包含规则承担必填与叶子校验,不再叠加 schema 级 required(避免 FormItem 额外前置必填规则);
+ *  空值时按 required 的 message 提示,非空但非叶子时提示选择具体矿井。 */
+export function mineLeafDynamicRules() {
+  return [
+    {
+      required: true,
+      message: '请选择煤矿',
+      validator: (_: any, value?: string) => {
+        const dept = useMineDepartmentStore().findDepartById(value);
+        if (dept && !dept.isLeaf) return Promise.reject('请选择具体矿井');
+        return Promise.resolve();
+      },
+    },
+  ];
+}
+
+/** 注册测风地点管理表格列 */
 export const pointColumns: BasicColumn[] = [
   {
     title: '煤矿编号',
@@ -45,7 +62,7 @@ export const pointColumns: BasicColumn[] = [
     },
   },
   {
-    title: '需风量(m³/min)',
+    title: '需风量', // (m³/min)
     dataIndex: 'airVolume',
     width: 100,
   },
@@ -80,7 +97,7 @@ export const pointColumns: BasicColumn[] = [
   // },
 ];
 
-/** 上传数据布点表格列(Windrect) */
+/** 上传测风装置表格列(Windrect) */
 export const windrectColumns: BasicColumn[] = [
   // {
   //   title: '设备编码',
@@ -128,7 +145,8 @@ export const formSchema: FormSchema[] = [
     label: '煤矿编号',
     field: 'mineCode',
     component: 'MineCascader',
-    required: true,
+    // 必选到矿井(叶子):必填与 isLeaf 校验由 mineLeafDynamicRules 单条规则承担
+    dynamicRules: mineLeafDynamicRules,
     // 编辑态(已有 id)禁用矿编码,避免误改归属矿井;新增态保持可选
     dynamicDisabled: ({ values }) => !!values.id,
     // 切换煤矿时清空已选测风设备,避免绑定到其他矿的设备