瀏覽代碼

调整生产运营会议,设置动态字段至少填一种,然后获取动态字段失败不在提示信息

Zimo 3 天之前
父節點
當前提交
64ead6d4b3

+ 2 - 1
src/api/pms/meeting/index.ts

@@ -40,7 +40,8 @@ export const OperationMeetingApi = {
 
   getCurrentCompanyExtProperties: async () => {
     return await request.get({
-      url: `/pms/iot-operation-meeting/currentCompanyExtProperties`
+      url: `/pms/iot-operation-meeting/currentCompanyExtProperties`,
+      hideErrorNotification: true
     })
   },
 

+ 4 - 1
src/config/axios/service.ts

@@ -28,6 +28,9 @@ let isRefreshToken = false
 // 请求白名单,无须token的接口
 const whiteList: string[] = ['/login', '/refresh-token']
 
+const shouldHideErrorNotification = (config?: InternalAxiosRequestConfig | AxiosError['config']) =>
+  Boolean((config as Record<string, unknown> | undefined)?.hideErrorNotification)
+
 // 创建axios实例
 const service: AxiosInstance = axios.create({
   baseURL: base_url, // api 的 base_url
@@ -185,7 +188,7 @@ service.interceptors.response.use(
         // hard coding:忽略这个提示,直接登出
         console.log(msg)
         return handleAuthorized()
-      } else {
+      } else if (!shouldHideErrorNotification(config)) {
         ElNotification.error({ title: msg })
       }
       return Promise.reject('error')

+ 81 - 8
src/views/pms/operation-meeting/components/meeting-detail-drawer.vue

@@ -285,6 +285,65 @@ const isRequiredExtProperty = (item: ExtPropertyItem) =>
 
 const isDoubleExtProperty = (item: ExtPropertyItem) => item.dataType === 'double'
 
+const hasExtPropertyActualValue = (item: ExtPropertyItem) => {
+  const value = item.actualValue
+
+  return typeof value === 'string' ? value.trim() !== '' : value !== undefined && value !== null
+}
+
+const getExtPropertyScope = (item: ExtPropertyItem) =>
+  item.defaultValue === 'next' ? 'next' : 'current'
+
+const getExtPropertyAlternativeGroupKey = (item: ExtPropertyItem) => {
+  const value = String(item.maxValue ?? '').trim()
+
+  if (!value || parseNumberValue(value) !== undefined) return ''
+
+  return value
+}
+
+const getExtPropertyAlternativeGroups = (scope: string) => {
+  const groups = new Map<string, ExtPropertyItem[]>()
+
+  detailForm.value.extProperty.forEach((property) => {
+    if (!isRequiredExtProperty(property) || getExtPropertyScope(property) !== scope) return
+
+    const groupKey = getExtPropertyAlternativeGroupKey(property)
+    if (!groupKey) return
+
+    groups.set(groupKey, [...(groups.get(groupKey) || []), property])
+  })
+
+  return groups
+}
+
+const hasCompleteExtPropertyAlternativeGroup = (scope: string) =>
+  Array.from(getExtPropertyAlternativeGroups(scope).values()).some((items) =>
+    items.every(hasExtPropertyActualValue)
+  )
+
+const isAlternativeExtProperty = (item: ExtPropertyItem) => {
+  if (!getExtPropertyAlternativeGroupKey(item)) return false
+
+  return getExtPropertyAlternativeGroups(getExtPropertyScope(item)).size > 1
+}
+
+const getExtPropertyAlternativeProps = (item: ExtPropertyItem) =>
+  Array.from(getExtPropertyAlternativeGroups(getExtPropertyScope(item)).values())
+    .flat()
+    .map((property) => getExtPropertyProp(property))
+
+const handleExtPropertyValueChange = (item: ExtPropertyItem) => {
+  if (
+    !isAlternativeExtProperty(item) ||
+    !hasCompleteExtPropertyAlternativeGroup(getExtPropertyScope(item))
+  ) {
+    return
+  }
+
+  nextTick(() => detailFormRef.value?.clearValidate(getExtPropertyAlternativeProps(item)))
+}
+
 const getExtPropertyLabel = (item: ExtPropertyItem) =>
   item.unit ? `${item.name}(${item.unit})` : item.name
 
@@ -299,13 +358,27 @@ const getExtPropertyProp = (item: ExtPropertyItem) => {
 const getExtPropertyRules = (item: ExtPropertyItem) => {
   if (!isRequiredExtProperty(item)) return []
 
+  if (isAlternativeExtProperty(item)) {
+    return [
+      {
+        validator: (_rule, _value, callback) => {
+          if (hasCompleteExtPropertyAlternativeGroup(getExtPropertyScope(item))) {
+            callback()
+            return
+          }
+
+          callback(new Error('请至少完整填写一种工作量'))
+        },
+        trigger: ['blur', 'change']
+      }
+    ]
+  }
+
   return isDoubleExtProperty(item)
     ? requiredNumberRule(`请输入${item.name}`)
     : requiredTextRule(`请输入${item.name}`)
 }
 
-const getExtPropertyNumberBoundary = (value: unknown) => parseNumberValue(value)
-
 const queryProjectNameSearch = (
   queryString: string,
   cb: (results: ProjectNameSuggestion[]) => void
@@ -525,14 +598,14 @@ onMounted(() => {
                 class="w-full!"
                 :controls="false"
                 :precision="2"
-                :min="getExtPropertyNumberBoundary(item.minValue)"
-                :max="getExtPropertyNumberBoundary(item.maxValue)" />
+                @change="handleExtPropertyValueChange(item)" />
               <el-input
                 v-else
                 v-model="item.actualValue"
                 type="textarea"
                 :rows="3"
-                :placeholder="`请输入${item.name}`" />
+                :placeholder="`请输入${item.name}`"
+                @input="handleExtPropertyValueChange(item)" />
             </el-form-item>
           </template>
           <template v-else>
@@ -617,14 +690,14 @@ onMounted(() => {
               class="w-full!"
               :controls="false"
               :precision="2"
-              :min="getExtPropertyNumberBoundary(item.minValue)"
-              :max="getExtPropertyNumberBoundary(item.maxValue)" />
+              @change="handleExtPropertyValueChange(item)" />
             <el-input
               v-else
               v-model="item.actualValue"
               type="textarea"
               :rows="4"
-              :placeholder="`请输入${item.name}`" />
+              :placeholder="`请输入${item.name}`"
+              @input="handleExtPropertyValueChange(item)" />
           </el-form-item>
         </div>
       </section>