From 68b27795ae929f5300fc6fb301b31aada74a2e2f Mon Sep 17 00:00:00 2001
From: zhangback <zhangback@163.com>
Date: 星期二, 10 三月 2026 15:26:03 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/yagwly_fa_master' into yagwly_fa_master
---
ui/admin-ui3/src/hooks/usePagePlus.ts | 283 ++++++++++++++++++++++++--------------------------------
1 files changed, 122 insertions(+), 161 deletions(-)
diff --git a/ui/admin-ui3/src/hooks/usePagePlus.ts b/ui/admin-ui3/src/hooks/usePagePlus.ts
index dd0c40d..76501e6 100644
--- a/ui/admin-ui3/src/hooks/usePagePlus.ts
+++ b/ui/admin-ui3/src/hooks/usePagePlus.ts
@@ -1,215 +1,169 @@
-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|| [];
+ 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 = () => {
+ 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 = {}; // 淇敼涓烘搷浣� .value
+ 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();
}
- 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'
- })
- });
- }
- const handleDelete = () =>{
- if ( !(pageF?.ids)|| pageF?.ids?.length === 0) {
- ElMessage({
- message: "璇烽�夋嫨鑷冲皯涓�鏉℃暟鎹紒",
- type: 'warning'
- })
- return;
- }
- ElMessageBox.confirm("纭畾灏嗛�夋嫨鏁版嵁鍒犻櫎锛�", '绯荤粺鎻愮ず', {confirmButtonText: '纭畾', cancelButtonText: '鍙栨秷', type: 'warning'}).then(() => {
- return opts.deleteApi!(pageF?.ids);
- }).then(() => {
- onLoad(opts.page);
- ElMessage({
- message: "鍒犻櫎鎴愬姛锛�",
- type: 'success'
- })
+ ElMessage({ message: "鍒犻櫎鎴愬姛锛�", type: 'success' });
});
}
-
- /**
- * 瀵煎嚭
- */
- const handleExport =()=>{
- console.log(opts.queryParams.value)
- opts.exportApi!(opts.queryParams.value);
+ const refreshChange = () => {
+ onLoad(opts.page, opts.queryParams.value);
}
- const 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();
- }
- const currentChange = (currentPage:number) => {
+ const currentChange = (currentPage: number) => {
opts.page.currentPage = currentPage;
}
- const sizeChange = (pageSize:number) => {
+ const sizeChange = (pageSize: number) => {
opts.page.pageSize = pageSize;
}
- const refreshChange = () => {
- onLoad(opts.page,opts.queryParams.value);
- }
+
return {
pageF,
tableData,
@@ -220,13 +174,20 @@
rowSave,
rowUpdate,
rowDel,
- handleDelete,
- handleExport,
- beforeOpen,
+ 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