From a0adb6373dbe1d37858998c12e206219dc45ac5c Mon Sep 17 00:00:00 2001
From: chenyong <chenyong@hnkhzn.com>
Date: 星期二, 17 三月 2026 15:36:07 +0800
Subject: [PATCH] 修复用户编辑页面下拉框无最近角色选项问题

---
 项目代码/WMS/WIDESEA_WMSClient/src/extension/system/Sys_User.js |  162 +++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 136 insertions(+), 26 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSClient/src/extension/system/Sys_User.js" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSClient/src/extension/system/Sys_User.js"
index 4be7155..f8c3903 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSClient/src/extension/system/Sys_User.js"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSClient/src/extension/system/Sys_User.js"
@@ -1,4 +1,6 @@
-import {  defineAsyncComponent } from "vue";
+import { defineAsyncComponent } from "vue";
+import axios from 'axios';
+
 let extension = {
     components: { //鍔ㄦ�佹墿鍏呯粍浠舵垨缁勪欢璺緞
         //琛ㄥ崟header銆乧ontent銆乫ooter瀵瑰簲浣嶇疆鎵╁厖鐨勭粍浠�
@@ -12,10 +14,82 @@
         modelFooter: ''
     },
     text: "鍙兘鐪嬪埌褰撳墠瑙掕壊涓嬬殑鎵�鏈夊笎鍙�",
-    buttons: [], //鎵╁睍鐨勬寜閽�
+    buttons: [],//鎵╁睍鐨勬寜閽�
     methods: { //浜嬩欢鎵╁睍
+        // 鍔犺浇瑙掕壊鏁版嵁 - 娣诲姞forceRefresh鍙傛暟
+        async loadRoles(forceRefresh = true) {
+            try {
+                const http = this.$http || window.axios || axios;
+                
+                if (!http) {
+                    console.error("HTTP璇锋眰瀵硅薄涓嶅瓨鍦�");
+                    return;
+                }
+                
+                console.log("寮�濮嬪姞杞借鑹叉暟鎹�...", forceRefresh ? "寮哄埗鍒锋柊" : "鏅�氬姞杞�");
+                
+                const url = "/api/Sys_Role/getUserChildRoles" + (forceRefresh ? "?t=" + Date.now() : "");
+                
+                const res = await http.post(url);
+                console.log("API杩斿洖鍘熷鏁版嵁:", res.data);
+                
+                if (res.data && res.data.status) {
+                    const selectOptions = res.data.data.map(role => ({
+                        // 鍏煎澶у啓鍜屽皬鍐欏睘鎬у悕
+                        value: role.id || role.Id,
+                        label: role.roleName || role.RoleName,
+                        // 鍚屾椂淇濆瓨鍘熷灞炴�э紝渚涜〃鏍兼樉绀轰娇鐢�
+                        id: role.id || role.Id,
+                        roleName: role.roleName || role.RoleName
+                    }));
+                    
+                    console.log("杞崲鍚庣殑涓嬫媺閫夐」:", selectOptions);
+
+                    if (this.editFormOptions && Array.isArray(this.editFormOptions)) {
+                        let found = false;
+                        for(let i = 0; i < this.editFormOptions.length; i++) {
+                            const group = this.editFormOptions[i];
+                            if (group && Array.isArray(group)) {
+                                for(let j = 0; j < group.length; j++) {
+                                    const field = group[j];
+                                    if (field && field.field === "role_Id") {
+                                        console.log("璁剧疆role_Id瀛楁鏁版嵁");
+                                        field.data = selectOptions;
+                                        found = true;
+                                        break;
+                                    }
+                                }
+                            }
+                            if (found) break;
+                        }
+                        
+                        this.$forceUpdate();
+                    }
+                    
+                    // 鍚屾椂鏇存柊琛ㄦ牸涓殑瑙掕壊鏁版嵁婧�
+                    if (this.columns && Array.isArray(this.columns)) {
+                        for(let i = 0; i < this.columns.length; i++) {
+                            const column = this.columns[i];
+                            if (column && column.field === "role_Id" && column.bind) {
+                                // 灏嗚鑹叉暟鎹浆鎹负key-value鏍煎紡锛屼緵琛ㄦ牸鏄剧ず浣跨敤
+                                const bindData = res.data.data.map(role => ({
+                                    key: role.id || role.Id,
+                                    value: role.roleName || role.RoleName
+                                }));
+                                column.bind.data = bindData;
+                                break;
+                            }
+                        }
+                    }
+                }
+            } catch (error) {
+                console.error("鍔犺浇瑙掕壊鏁版嵁澶辫触:", error);
+            }
+        },
+
         onInit() {
             this.boxOptions.height = 530;
+
             this.columns.push({
                 title: '鎿嶄綔',
                 hidden: false,
@@ -30,7 +104,9 @@
                             style: { 'margin-right': '15px' },
                             onClick: (e) => {
                                 e.stopPropagation()
-                                this.$refs.gridHeader.open(row);
+                                if (this.$refs.gridHeader) {
+                                    this.$refs.gridHeader.open(row);
+                                }
                             }
                         }, "淇敼瀵嗙爜"
                         ),
@@ -46,41 +122,75 @@
                         ),
                     ])
                 }
-            })
+            });
+            
+            // 鍒濆鍖栨椂鍔犺浇
+            setTimeout(() => {
+                this.loadRoles(false);
+            }, 100);
         },
-        onInited() { },
-        addAfter(result) { //鐢ㄦ埛鏂板缓鍚庯紝鏄剧ず闅忔満鐢熸垚鐨勫瘑鐮�
+        
+        modelOpenAfter() {
+            let isEDIT = this.currentAction == this.const.EDIT;
+            
+            // 璁剧疆UserName绂佺敤鐘舵��
+            if (this.editFormOptions && Array.isArray(this.editFormOptions)) {
+                for(let i = 0; i < this.editFormOptions.length; i++) {
+                    const group = this.editFormOptions[i];
+                    if (group && Array.isArray(group)) {
+                        for(let j = 0; j < group.length; j++) {
+                            const field = group[j];
+                            if (field && field.field === "UserName") {
+                                field.disabled = isEDIT;
+                            }
+                        }
+                    }
+                }
+            }
+            
+            if (this.currentAction == this.const.ADD) {
+                this.editFormFields.Gender = "0";
+            }
+            
+            // 姣忔鎵撳紑缂栬緫妗嗘椂寮哄埗閲嶆柊鍔犺浇瑙掕壊鏁版嵁锛堝甫鏃堕棿鎴筹級
+            setTimeout(() => {
+                this.loadRoles(true); 
+            }, 100);
+        },
+        refreshRoles() {
+            this.loadRoles(true);
+        },
+        
+        addAfter(result) {
             if (!result.status) {
                 return true;
             }
-            //鏄剧ず鏂板缓鐢ㄦ埛鐨勫瘑鐮�
-            //2020.08.28浼樺寲鏂板缓鎴愬悗鎻愮ず鏂瑰紡
-            this.$confirm(result.message, '鏂板缓鐢ㄦ埛鎴愬姛', {
+            this.$confirm(result.message, '鏂板缓鐢ㄦ埛鎴愬姛', { 
                 confirmButtonText: '纭畾',
                 type: 'success',
                 center: true
-            }).then(() => { })
-
+            }).then(() => { 
+                this.refreshRoles();
+            })
             this.boxModel = false;
             this.refresh();
             return false;
         },
-        modelOpenAfter() {
-            //鐐瑰嚮寮瑰嚭妗嗗悗锛屽鏋滄槸缂栬緫鐘舵�侊紝绂佹缂栬緫鐢ㄦ埛鍚嶏紝濡傛灉鏂板缓鐘舵�侊紝灏嗙敤鎴峰悕瀛楁璁剧疆涓哄彲缂栬緫
-            let isEDIT = this.currentAction == this.const.EDIT;
-            this.editFormOptions.forEach(item => {
-                item.forEach(x => {
-                    if (x.field == "UserName") {
-                        x.disabled=isEDIT;
-                    }
-                })
-                //涓嶆槸鏂板缓锛屾�у埆榛樿鍊艰缃负鐢�
-                if (!isEDIT) {
-                    this.editFormFields.Gender = "0";
-                }
-            })
+        
+        // 鍒锋柊鍚庨噸鏂板姞杞借鑹叉暟鎹紝纭繚鍒锋柊鍚庤鑹插悕绉颁粛鐒舵樉绀烘纭�
+        refreshAfter() {
+            setTimeout(() => {
+                this.loadRoles(true);
+            }, 100);
+        },
+        
+        // 琛ㄦ牸鏁版嵁鍔犺浇瀹屾垚鍚庨噸鏂板姞杞借鑹叉暟鎹紝纭繚鍒锋柊鍚庤鑹插悕绉颁粛鐒舵樉绀烘纭�
+        searchAfter() {
+            setTimeout(() => {
+                this.loadRoles(true);
+            }, 100);
+            return true;
         }
-
     }
 };
 export default extension;
\ No newline at end of file

--
Gitblit v1.9.3