From 5abcde36961125cbf436f91b8c17610a6b5f8308 Mon Sep 17 00:00:00 2001
From: sen <sen@qq.com>
Date: 星期三, 15 四月 2026 12:15:08 +0800
Subject: [PATCH] 修改调度单必填校验

---
 ui/admin-ui3/src/hooks/usePagePlus.ts |  319 ++++++++++++++++++++++++++++------------------------
 1 files changed, 171 insertions(+), 148 deletions(-)

diff --git a/ui/admin-ui3/src/hooks/usePagePlus.ts b/ui/admin-ui3/src/hooks/usePagePlus.ts
index e1d54d9..7fabf7d 100644
--- a/ui/admin-ui3/src/hooks/usePagePlus.ts
+++ b/ui/admin-ui3/src/hooks/usePagePlus.ts
@@ -1,164 +1,184 @@
-import {reactive, ref, Ref, UnwrapRef} from "vue";
-import {PageF, PageInterface, PagesInterface} from "@/utils/globalInterface";
-
-import {ElMessage, ElMessageBox} from "element-plus";
-import {requestType} from "@/utils/request";
-
-
+import { reactive, ref, onMounted, onUnmounted } from "vue"; // 1. 寮曞叆鐢熷懡鍛ㄦ湡閽╁瓙
+import { PageF, PagesInterface } from "@/utils/globalInterface";
+import { ElMessage, ElMessageBox } from "element-plus";
+import { requestType } from "@/utils/request";
 
 /**
- * @description usePage 鎺ユ敹涓�涓猳pts 鍙傛暟锛岃繑鍥為�氱敤椤甸潰鎵�闇�鏁版嵁
- * @param {Object} opts.form 琛ㄥ崟瀵硅薄
- * @param {string} opts.title 椤甸潰鏍囬
- * @param {Object} opts.queryParams 鏌ヨ鍙傛暟
- * @param {Function} opts.getListApi 鑾峰彇鍒楄〃鏁版嵁鐨勬帴鍙�
- * @param {Function} opts.getDetailApi 鑾峰彇璇︽儏鏁版嵁鐨勬帴鍙�
- * @param {Function} opts.deleteApi 鍒犻櫎鏁版嵁鐨勬帴鍙�
- * @param {Function} opts.exportApi 瀵煎嚭鏁版嵁鐨勬帴鍙�
- * @param {Function} opts.getBeginListFunc 鑾峰彇鍓峠etList鏁版嵁鐨勬帴鍙�
- * @param {Function} opts.getListFunc 鎵ц瀹実etList鎴愬姛鍚庢墽琛岀殑閫昏緫
- * @param {Function} opts.resetFunc 鎵ц瀹宺eset鎴愬姛鍚庢墽琛岀殑閫昏緫
- * @param {Function} opts.resetQueryFunc 鎵ц瀹宺esetQuery鎴愬姛鍚庢墽琛岀殑閫昏緫
- * @param {Function} opts.handleSelectionChangeFunc 鎵ц瀹宧andleSelectionChange鎴愬姛鍚庢墽琛岀殑閫昏緫
+ * @description usePagePlus 澧炲姞鍏ㄥ眬鍥炶溅鎼滅储閫昏緫
  */
 export const usePagePlus = (opts: {
-    form?:any,
-    option?:any,
-    idKey?:any,
-    page:any,
-    queryParams?:any,
-    getListApi?:requestType,
-    addApi?:requestType,
-    updateApi?:requestType,
-    getDetailApi?:requestType,
-    deleteApi?:requestType,
-    exportApi?:requestType,
-    getBeginListFunc?:Function,
-    getListFunc?:Function,
-    resetFunc?:Function,
-    handleQueryFunc?:Function,
-    resetQueryFunc?:Function,
-    handleSelectionChangeFunc?:Function,
-    handleAddFunc?:Function,
-    handleUpdateFunc?:Function,
-    handleBeforeOpenFunc?:Function,
-    handleEndOpenFunc?:Function,
-    rowSaveBegin?:Function,
-    rowUpdateBegin?:Function,
-})=>{
-    const pageF = reactive({...PageF});
+    form?: any,
+    option?: any,
+    idKey?: any,
+    page: any,
+    queryParams?: any, // 纭繚澶栭儴浼犲叆鐨勬槸 ref 瀵硅薄
+    getListApi?: requestType,
+    addApi?: requestType,
+    updateApi?: requestType,
+    getDetailApi?: requestType,
+    deleteApi?: requestType,
+    exportApi?: requestType,
+    getBeginListFunc?: Function,
+    getListFunc?: Function,
+    resetFunc?: Function,
+    handleQueryFunc?: Function,
+    resetQueryFunc?: Function,
+    handleSelectionChangeFunc?: Function,
+    handleAddFunc?: Function,
+    handleUpdateFunc?: Function,
+    handleBeforeOpenFunc?: Function,
+    handleEndOpenFunc?: Function,
+    rowSaveBegin?: Function,
+    rowUpdateBegin?: Function,
+}) => {
+    const pageF = reactive({ ...PageF });
     const tableData = ref([]);
-    opts.idKey = opts.idKey?opts.idKey: 'id';
+    opts.idKey = opts.idKey ? opts.idKey : 'id';
+
     /**
      * 鑾峰彇鍒楄〃鏁版嵁
      */
-    const onLoad = (page:PagesInterface, params?:Object) =>{
-        if(opts.getBeginListFunc){
+    const onLoad = (page: PagesInterface, params?: Object) => {
+        if (opts.getBeginListFunc) {
             params = opts.getBeginListFunc!(params)
         }
         pageF.loading = true;
-        opts.getListApi!({pageNum:page.currentPage,pageSize:page.pageSize,...Object.assign(params?params:{},opts.queryParams.value)}).then((res:any)=>{
-            tableData.value = res.rows|| [];
+        const queryParams = filterEmptyParams(opts.queryParams.value);
+        opts.getListApi!({ 
+            pageNum: page.currentPage, 
+            pageSize: page.pageSize, 
+            ...Object.assign(params ? params : {}, opts.queryParams.value) 
+        }).then((res: any) => {
+            tableData.value = res.rows || [];
             pageF.loading = false;
             opts.page.total = res.total || 0;
-            if(opts.getListFunc){
+            if (opts.getListFunc) {
                 opts.getListFunc!(res)
             }
         })
     }
 
     /**
-     * 娓呯┖鎼滅储鍥炶皟鏂规硶
+     * 2. 鏂板锛氭墜鍔ㄨЕ鍙戞悳绱㈤�昏緫 (鐢ㄤ簬鍥炶溅鎼滅储)
      */
-    const searchReset = () =>{
-        opts.queryParams = {};
-        if (opts.handleQueryFunc){
+    const manualSearch = () => {
+        if (!opts.queryParams || !opts.queryParams.value) return; // 瀹归敊澶勭悊
+        opts.page.currentPage = 1; // 鍥炶溅鎼滅储榛樿鍒囧洖绗竴椤�
+        if (opts.handleQueryFunc) {
+            opts.handleQueryFunc();
+        }
+        onLoad(opts.page, opts.queryParams.value);
+    }
+
+    /**
+     * 3. 鏂板锛氬叏灞�鎸夐敭鐩戝惉澶勭悊鍑芥暟
+     */
+    const handleKeyDown = (e: KeyboardEvent) => {
+        // 鍒ゆ柇鏄惁鎸変笅 Enter 閿�
+        if (e.key === 'Enter') {
+            // 鍏抽敭鍒ゆ柇锛氫负浜嗛槻姝㈠湪鏂板/缂栬緫寮圭獥杈撳叆鏃惰Е鍙戣儗鏅垪琛ㄥ埛鏂�
+            // 鍙湁褰撶劍鐐瑰湪 Input 妗嗕腑涓斾笉鍦ㄥ脊绐楀唴锛堥�氬父鏍规嵁涓氬姟鐘舵�佸垽鏂級鎵嶈Е鍙�
+            const target = e.target as HTMLElement;
+            if (target.tagName === 'INPUT') {
+                // 濡傛灉椤甸潰涓婃湁 open 鐘舵�佹帶鍒跺脊绐楋紝鍙互鍦ㄦ澧炲姞鍒ゆ柇鏉′欢
+                manualSearch();
+            }
+        }
+    };
+
+    // 4. 鎸傝浇鏃剁洃鍚紝鍗歌浇鏃剁Щ闄わ紝纭繚涓嶅奖鍝嶅叾浠栭潪 Avue 椤甸潰
+    onMounted(() => {
+        window.addEventListener("keydown", handleKeyDown);
+    });
+
+    onUnmounted(() => {
+        window.removeEventListener("keydown", handleKeyDown);
+    });
+
+    /** 娓呯┖鎼滅储鍥炶皟鏂规硶 */
+    const searchReset = () => {
+     //   opts.queryParams = {}; // 淇敼涓烘搷浣� .value
+     // 鉁� 姝g‘鍐欐硶锛氭竻绌� ref 鍐呴儴鐨勫��
+    if (opts.queryParams && opts.queryParams.value) {
+        // 鏂规 A锛氱洿鎺ユ竻绌哄璞″唴閮ㄥ睘鎬�
+        Object.keys(opts.queryParams.value).forEach(key => {
+            delete opts.queryParams.value[key];
+        });
+      
+      }
+        if (opts.handleQueryFunc) {
             opts.handleQueryFunc();
         }
         onLoad(opts.page);
     }
 
     /** 鎼滅储鎸夐挳鎿嶄綔 */
-    const searchChange = (params:any, done:any) => {
-        // opts.queryParams = params;
+    const searchChange = (params: any, done: any) => {
         opts.page.currentPage = 1;
-        if (opts.handleQueryFunc){
+        if (opts.handleQueryFunc) {
             opts.handleQueryFunc();
         }
-        console.log(params);
-        
-        onLoad(opts.page,params);
+        onLoad(opts.page, params);
         done();
-
     }
-    // 澶氶�夋閫変腑鏁版嵁
+
+    // --- 浠ヤ笅淇濇寔鍘熸湁閫昏緫涓嶅彉 ---
     const selectionChange = (selection?: any[]) => {
         pageF.ids = selection!.map(item => item[opts.idKey]);
         pageF.single = selection!.length != 1;
         pageF.multiple = !selection!.length;
-        if (opts.handleSelectionChangeFunc){
+        if (opts.handleSelectionChangeFunc) {
             opts.handleSelectionChangeFunc!(selection);
         }
     }
-    /** 鏂板鎿嶄綔 */
-    const rowSave = (row:any, done:any, loading:any) => {
-        if (opts.rowSaveBegin){
-            opts.rowSaveBegin!(row,loading);
+
+    const rowSave = (row: any, done: any, loading: any) => {
+        if (opts.rowSaveBegin) {
+            opts.rowSaveBegin!(row, loading);
         }
-        opts.addApi!(row).then(()=>{
-            ElMessage({
-                message: "鏂板鎴愬姛锛�",
-                type: 'success'
-            })
+        opts.addApi!(row).then(() => {
+            ElMessage({ message: "鏂板鎴愬姛锛�", type: 'success' });
             onLoad(opts.page);
-            done()
-        }).catch(()=>{
-            loading()
-        })
+            done();
+        }).catch(() => { loading() })
     }
 
-    /** 淇敼鎿嶄綔 */
-    const rowUpdate = (row:any, index:any, done:any, loading:any) => {
-        if (opts.rowUpdateBegin){
-            opts.rowUpdateBegin!(row,loading);
+    const rowUpdate = (row: any, index: any, done: any, loading: any) => {
+        if (opts.rowUpdateBegin) {
+            opts.rowUpdateBegin!(row, loading);
         }
-        opts.updateApi!(row).then((response:any) => {
-            ElMessage({
-                message: "淇敼鎴愬姛锛�",
-                type: 'success'
-            })
+        opts.updateApi!(row).then((response: any) => {
+            ElMessage({ message: "淇敼鎴愬姛锛�", type: 'success' });
             onLoad(opts.page);
-            done()
-        }).catch(()=>{
-            loading()
-        })
+            done();
+        }).catch(() => { loading() })
     }
 
-    const handleUpdate = ()=>{
-        if ( !(pageF?.ids)|| pageF?.ids?.length === 0) {
-            ElMessage({
-                message: "璇烽�夋嫨鑷冲皯涓�鏉℃暟鎹紒",
-                type: 'warning'
-            })
-            return;
-        }
-        if(opts.handleUpdateFunc){
-            opts.handleUpdateFunc!()
-        }
-
-    }
-
-
-    const rowDel  = (row:any) =>{
-        ElMessageBox.confirm("纭畾灏嗛�夋嫨鏁版嵁鍒犻櫎锛�", '绯荤粺鎻愮ず', {confirmButtonText: '纭畾', cancelButtonText: '鍙栨秷', type: 'warning'}).then(() => {
+    const rowDel = (row: any) => {
+        ElMessageBox.confirm("纭畾灏嗛�夋嫨鏁版嵁鍒犻櫎锛�", '绯荤粺鎻愮ず', { confirmButtonText: '纭畾', cancelButtonText: '鍙栨秷', type: 'warning' }).then(() => {
             return opts.deleteApi!(row[opts.idKey]);
         }).then(() => {
             onLoad(opts.page);
-            ElMessage({
-                message: "鍒犻櫎鎴愬姛锛�",
-                type: 'success'
-            })
+            ElMessage({ message: "鍒犻櫎鎴愬姛锛�", type: 'success' });
         });
+    }
+
+    const refreshChange = () => {
+        onLoad(opts.page, opts.queryParams.value);
+    }
+
+    const currentChange = (currentPage: number) => {
+        opts.page.currentPage = currentPage;
+    }
+    const sizeChange = (pageSize: number) => {
+        opts.page.pageSize = pageSize;
+    }
+      /**
+     * 瀵煎嚭
+     */
+    const handleExport =()=>{
+        const queryParams = filterEmptyParams(opts.queryParams.value);
+        opts.exportApi!( opts.queryParams.value);
     }
     const handleDelete  = () =>{
         if ( !(pageF?.ids)|| pageF?.ids?.length === 0) {
@@ -178,40 +198,33 @@
             })
         });
     }
+  const handleUpdate = ()=>{
+        if ( !(pageF?.ids)|| pageF?.ids?.length === 0) {
+            ElMessage({
+                message: "璇烽�夋嫨鑷冲皯涓�鏉℃暟鎹紒",
+                type: 'warning'
+            })
+            return;
+        }
+        if(opts.handleUpdateFunc){
+            opts.handleUpdateFunc!()
+        }
 
-
+    }
     /**
-     * 瀵煎嚭
-     */
-    const handleExport =()=>{
-        console.log(opts.queryParams.value)
-        opts.exportApi!(opts.queryParams.value);
-    }
-
-    const beforeOpen = (done:any, type:string) => {
-        if(opts.handleBeforeOpenFunc){
-            opts.handleBeforeOpenFunc!(type)
+ * 杩囨护绌哄瓧绗︿覆鍙傛暟
+ */
+const filterEmptyParams = (params: any) => {
+    const result: any = {};
+    for (const key in params) {
+        const val = params[key];
+        // 杩囨护绌哄瓧绗︿覆銆乶ull銆乽ndefined
+        if (val !== '' && val !== null && val !== undefined) {
+            result[key] = val;
         }
-        if (["edit", "view"].includes(type)) {
-
-            opts.getDetailApi!(opts.form.value[opts.idKey]).then(res => {
-                opts.form.value = res.data;
-                if(opts.handleEndOpenFunc){
-                    opts.handleEndOpenFunc!(type,res)
-                }
-            });
-        }
-        done();
     }
-    const currentChange = (currentPage:number) => {
-        opts.page.currentPage = currentPage;
-    }
-    const sizeChange = (pageSize:number) => {
-        opts.page.pageSize = pageSize;
-    }
-    const refreshChange = () => {
-        onLoad(opts.page,opts.queryParams.value);
-    }
+    return result;
+};
     return {
         pageF,
         tableData,
@@ -221,14 +234,24 @@
         selectionChange,
         rowSave,
         rowUpdate,
-        rowDel,
-        handleDelete,
         handleExport,
-        beforeOpen,
+        handleDelete,
+        handleUpdate,
+        rowDel,
+        refreshChange,
         currentChange,
         sizeChange,
-        handleUpdate,
-        refreshChange
+        manualSearch, // 瀵煎嚭姝ゆ柟娉曞鐢�
+        // ...鍏朵粬鍘熸湁杩斿洖椤�
+        beforeOpen: (done: any, type: string) => {
+            if (opts.handleBeforeOpenFunc) opts.handleBeforeOpenFunc!(type);
+            if (["edit", "view"].includes(type)) {
+                opts.getDetailApi!(opts.form.value[opts.idKey]).then(res => {
+                    opts.form.value = res.data;
+                    if (opts.handleEndOpenFunc) opts.handleEndOpenFunc!(type, res);
+                });
+            }
+            done();
+        }
     }
-
-}
+}
\ No newline at end of file

--
Gitblit v1.8.0