Просмотр исходного кода

修复: 恢复级联班主任输入筛选

1. 为 SsCcp 恢复 inp=true 输入框、模糊查询、空值查全部及上级学校条件传递。

2. 未配置 inp=true 的级联继续保持原有禁用选择模式,并保留班主任值回显与选择后的隐藏字段更新。

3. 验证:node --check 与 git diff --check 通过;已备份并部署至正式 worker1,重启 tomcat-pms 后新 Pod 容器哈希与本地最终文件一致。
“gaohp” 3 месяцев назад
Родитель
Сommit
29f4c9095a
1 измененных файлов с 163 добавлено и 3 удалено
  1. 163 3
      web/js/vue/ss-components.js

+ 163 - 3
web/js/vue/ss-components.js

@@ -1810,6 +1810,10 @@ import { EVEN_VAR } from "./EventBus.js";
         type: String,
         default: "1",
       },
+      inp: {
+        type: Boolean,
+        default: false,
+      },
 
       //级联菜单配置参数,如果是数组,则代表本下拉菜单是多套级联菜单共用的第一级菜单。如果是对象,则只有一套级联菜单用此下拉菜单。
       param: {
@@ -1825,6 +1829,13 @@ import { EVEN_VAR } from "./EventBus.js";
     emits: ["update:modelValue", "change"],
 
     setup(props, { emit }) {
+      const canInput = props.inp === true;
+      const inputText = Vue.ref("");
+      const filteredOptions = Vue.ref(props.opt);
+      const visibleOptions = Vue.computed(() =>
+        canInput ? filteredOptions.value : props.opt
+      );
+      let inputRequestId = 0;
       // alert('级联菜单初始化:'+props.name+':--:'+props.modelValue);
       const selectItem = Vue.ref({ label: props.placeholder, value: "" });
       const popupWinVisible = Vue.ref(false);
@@ -1866,6 +1877,8 @@ import { EVEN_VAR } from "./EventBus.js";
         );
 
         selectItem.value = ""; //清除本下拉菜单当前选中的值
+        inputText.value = "";
+        filteredOptions.value = props.opt;
         emit("update:modelValue", ""); //通知父级
 
         //清空下拉菜单,并设置第一项的值为placeholder
@@ -1992,9 +2005,21 @@ import { EVEN_VAR } from "./EventBus.js";
         return { valid: true };
       };
 
+      const updateSelectItem = () => {
+        const item = props.opt.find((it) => it.value === props.modelValue);
+        if (item) {
+          selectItem.value = item;
+          inputText.value = item.label;
+        } else {
+          selectItem.value = { label: "", value: "" };
+          inputText.value = "";
+        }
+      };
+
       // 处理选择事件
       const doSelectItem = (item) => {
         selectItem.value = item;
+        inputText.value = item.label;
         emit("update:modelValue", item.value); //修改本下拉菜单在vue中保存的值
 
         // alert('item.value:'+item.value);
@@ -2251,6 +2276,8 @@ import { EVEN_VAR } from "./EventBus.js";
             upperValue.value = "";
 
             selectItem.value = ""; //清除本下拉菜单当前选中的值
+            inputText.value = "";
+            filteredOptions.value = props.opt;
             emit("update:modelValue", ""); //通知父级
 
             //清空所有下拉菜单项
@@ -2394,11 +2421,107 @@ import { EVEN_VAR } from "./EventBus.js";
         const matchedOption = props.opt.find((opt) => opt.value === value);
         if (matchedOption) {
           selectItem.value = matchedOption;
+          inputText.value = matchedOption.label;
           emit("update:modelValue", value);
           emit("change", value);
         }
       };
 
+      async function updateOptionBYInputText(inputValue) {
+        const pickerParam = Array.isArray(props.param)
+          ? props.param[props.param.length - 1]
+          : props.param;
+        if (!props.url || !pickerParam || !pickerParam.codebook) return;
+
+        const requestId = ++inputRequestId;
+        const searchText = inputValue || "";
+        const searchAll = searchText.trim().length === 0;
+        let url = props.url;
+        const filterObj = {
+          ...(pickerParam.filter && typeof pickerParam.filter === "object"
+            ? pickerParam.filter
+            : {}),
+        };
+
+        Object.keys(filterObj).forEach((key) => {
+          url += "&" + key + "=" + encodeURIComponent(filterObj[key]);
+        });
+
+        if (pickerParam.filterfield) {
+          const filterFields = String(pickerParam.filterfield).split(",");
+          filterFields.forEach((fieldName) => {
+            const fields = document.getElementsByName(fieldName);
+            if (!fields || fields.length < 1) {
+              console.warn("下拉菜单配置的过滤条件" + fieldName + "不存在");
+              return;
+            }
+
+            const field = Array.from(fields).find((item) => item.value);
+            if (field) {
+              url += "&" + fieldName + "=" + encodeURIComponent(field.value);
+              filterObj[fieldName] = field.value;
+            }
+          });
+        }
+
+        const objectPickerParam = {
+          ...filterObj,
+          input: props.inp,
+          codebook: pickerParam.codebook,
+          cascadingLevel: Array.isArray(pickerParam.fieldOrd)
+            ? pickerParam.fieldOrd.join(",")
+            : pickerParam.fieldOrd || "",
+          name: props.name,
+          cascadingName: pickerParam.name,
+        };
+        if (pickerParam.combField) {
+          objectPickerParam.cascadingInputsName = pickerParam.combField;
+        }
+
+        const params = new URLSearchParams();
+        params.append("objectpickerparam", JSON.stringify(objectPickerParam));
+        params.append("objectpickertype", "1");
+        params.append("objectpickersearchAll", searchAll ? "1" : "0");
+        params.append("objectpickerinput", searchAll ? "" : searchText);
+        if (!searchAll) {
+          url += "&objectpickerinput=" + encodeURIComponent(searchText);
+        }
+        if (upperValue.value) {
+          params.append("upperValue", upperValue.value);
+        }
+
+        try {
+          const response = await axios.post(url, params, {
+            headers: {
+              "Content-Type": "application/x-www-form-urlencoded",
+            },
+          });
+          if (requestId !== inputRequestId) return;
+          if (response.data.statusText === "timeout") {
+            alert("网络超时!");
+            return;
+          }
+
+          const normalizedResult = normalizeCcpResult(response.data.result);
+          props.opt.length = 0;
+          normalizedResult.forEach((option) => props.opt.push(option));
+
+          const matchedOptions = searchAll
+            ? normalizedResult
+            : normalizedResult.filter((option) =>
+                String(option.label)
+                  .toLowerCase()
+                  .includes(searchText.toLowerCase())
+              );
+          filteredOptions.value = matchedOptions.length
+            ? [{ label: "", value: "" }, ...matchedOptions]
+            : [];
+          openPopup();
+        } catch (error) {
+          console.error("[SsCcp] 输入筛选失败:", error);
+        }
+      }
+
       // 计算弹出方向和最大高度的方法 by xu 20251212
       // 当空间不足时限制popup高度并显示滚动条
       const calculatePopupDirection = () => {
@@ -2564,6 +2687,10 @@ import { EVEN_VAR } from "./EventBus.js";
 
       //级联菜单点击事件
       const togglePopup = () => {
+        if (canInput) {
+          updateOptionBYInputText(inputText.value);
+          return;
+        }
         if (!popupWinVisible.value) {
           //如果当前下拉菜单是隐藏的,先ajax重新加载下拉菜单项,再显示。
 
@@ -2576,6 +2703,7 @@ import { EVEN_VAR } from "./EventBus.js";
       //显示下拉菜单,在此之前先清除下拉菜单项
       const showPopup = () => {
         //清空下拉菜单,并设置第一项的值为空
+        if (canInput) filteredOptions.value = props.opt;
         clearAndInit1stOpt();
         Vue.nextTick(() => {
           calculatePopupDirection();
@@ -2785,6 +2913,23 @@ import { EVEN_VAR } from "./EventBus.js";
         popupWinVisible.value = false;
       };
 
+      const suffixClick = () => {
+        if (popupWinVisible.value) {
+          hidePopup();
+          return;
+        }
+        if (canInput) {
+          updateOptionBYInputText("");
+        } else {
+          showPopup();
+        }
+      };
+
+      const handleInputChange = (event) => {
+        inputText.value = event.target.value || "";
+        updateOptionBYInputText(inputText.value);
+      };
+
       // 合并所有的 onMounted 逻辑
       Vue.onMounted(() => {
         window.addEventListener("resize", handleViewportChange);
@@ -2831,6 +2976,7 @@ import { EVEN_VAR } from "./EventBus.js";
                 );
                 if (matchedOption) {
                   selectItem.value = matchedOption;
+                  inputText.value = matchedOption.label;
                 }
               }
             });
@@ -2839,8 +2985,10 @@ import { EVEN_VAR } from "./EventBus.js";
             const item = props.opt.find((it) => it.value === newVal);
             if (item) {
               selectItem.value = item;
+              inputText.value = item.label;
             } else {
               selectItem.value = { label: "", value: "" };
+              inputText.value = "";
             }
           }
         },
@@ -2880,6 +3028,11 @@ import { EVEN_VAR } from "./EventBus.js";
         popupRef,
         teleportRootStyle,
         popupLayerStyle,
+        canInput,
+        inputText,
+        visibleOptions,
+        suffixClick,
+        handleInputChange,
       };
     },
 
@@ -2894,12 +3047,19 @@ import { EVEN_VAR } from "./EventBus.js";
               :value="selectItem.value"
             />
             <input
+              v-if="canInput"
+              v-model="inputText"
+              @input="handleInputChange"
+              :placeholder="placeholder"
+            />
+            <input
+              v-else
               :placeholder="placeholder"
               :value="selectItem.label"
               disabled
               style="pointer-events: none;"
             />
-            <div class="suffix">
+            <div class="suffix" @click.stop="suffixClick">
               <ss-form-icon :class="popupWinVisible ? 'form-icon-transform-select select' : 'form-icon-select'" />
             </div>
           </div>
@@ -2917,10 +3077,10 @@ import { EVEN_VAR } from "./EventBus.js";
               class="popup-win"
               :style="[popupLayerStyle, { maxHeight: popupMaxHeight !== 'none' ? popupMaxHeight : 'none', overflowY: popupMaxHeight !== 'none' ? 'auto' : 'visible' }]"
             >
-              <div v-if="opt && opt.length > 0" class="popup-content">
+              <div v-if="visibleOptions && visibleOptions.length > 0" class="popup-content">
                 <div class="content-area">
                   <div 
-                    v-for="(item, index) in opt" 
+                    v-for="(item, index) in visibleOptions"
                     :key="index" 
                     @click="doSelectItem(item)" 
                     :class="{ active: item.value === selectItem.value }"