From 4680c0007b7ea3a061f80502abeac70f49d7a0f0 Mon Sep 17 00:00:00 2001 From: wangfei <3597712270@qq.com> Date: 星期五, 05 七月 2024 11:43:55 +0800 Subject: [PATCH] 角色管理 --- UI-Project/src/views/User/rolelist.vue | 97 ++++++++++++++++++++++++++++-------------------- 1 files changed, 57 insertions(+), 40 deletions(-) diff --git a/UI-Project/src/views/User/rolelist.vue b/UI-Project/src/views/User/rolelist.vue index 14d1ad3..5dcbb0b 100644 --- a/UI-Project/src/views/User/rolelist.vue +++ b/UI-Project/src/views/User/rolelist.vue @@ -18,7 +18,7 @@ const name = ref(''); const tableData = ref([]) const options = ref([]) -const selectedOptions = ref('') +const selectedOptions = ref([]) // 瀹氫箟绾ц仈閫夋嫨鍣ㄧ殑灞炴�� const cascaderProps = { value: 'id', @@ -31,27 +31,19 @@ processType: [], }) -// const handleInputChangea = async (value: string) => { -// if (value) { -// await fetchOptionsa(value); -// } else { -// options.value = []; // 娓呯┖閫夐」鍒楄〃 -// } -// }; onMounted(() => { - // 鍦ㄧ粍浠舵寕杞藉悗璋冪敤 fetchOptions('') 鏉ュ姞杞藉垵濮嬫暟鎹紙濡傛灉闇�瑕侊級 fetchOptionsa(''); }); // 瑙掕壊涓嬫媺閫� const fetchOptionsa = async () => { try { - // 鍙戦�佽姹傚埌鍚庣鎺ュ彛 const response = await request.post('/loadGlass/sys/role/queryRole',{ key: '' }); if (response.code == 200) { tableData.value = response.data // titleSelectJsona.value.processTypea = response.data.menuList; + // options.value = response.data.menuList console.log(response.data); } else { @@ -63,57 +55,82 @@ }; // 娣诲姞 const getTableRow = async () => { - - const lastId = selectedOptions.value[selectedOptions.value.length - 1]; - // sendDataToServer(dataToSend); - console.log(selectedOptions.value[selectedOptions.value.length - 1]); - // 鍙互杩涗竴姝ュ鐞嗭紝濡傚彂閫佽姹傜瓑 - try { + try { + let menuList = []; + selectedOptions.value.forEach(array => { + if (array.length >= 2) { + let id = array[0]; + let parentId = array[1]; + menuList.push({ + id: id, + parentId: 0, + children: [ + { + id: parentId, + parentId: id, + } + ], + }); + } + }); const dataToSend = { name: name.value, - // id: selectedOptions.value, - menuList: [lastId] - // [ - // { - // menuName: selectedOptions.value, - // selectedOptions.value, - // } - // ] - }; - const response = await request.post('/loadGlass/sys/role/saveRole', dataToSend); + menuList: menuList + }; + const response = await request.post('/loadGlass/sys/role/saveRole', dataToSend); if (response.code == 200) { - // 缁戝畾鎴愬姛锛屽鐞嗛�昏緫 ElMessage.success(response.message); add.value = false; name.value = ''; - selectedOptions.value = ''; - fetchOptionsa() - // tableData.value = response.data; + selectedOptions.value = ''; + fetchOptionsa(); } else { - // 璇锋眰澶辫触锛屾樉绀洪敊璇秷鎭� ElMessage.error(response.message); } } catch (error) { - // 澶勭悊閿欒 console.error(error); } }; // 澶勭悊缂栬緫鎸夐挳鐐瑰嚮 function handleEdit(row) { name.value = row.name; - selectedOptions.value = row.selectedOptions; - adda.value = true; // 鏄剧ず瀵硅瘽妗� + selectedOptions.value = row.selectedOptions +// options.value = res.data.tree + adda.value = true; // 鏄剧ず瀵硅瘽妗� window.localStorage.setItem('id', row.id) } // 缂栬緫 const getTableRowa = async () => { let id = window.localStorage.getItem('id') - - try { - const response = await request.post('/loadGlass/sys/role/updateRole', { - id: id, + try { + let menuList = []; + selectedOptions.value.forEach(array => { + if (array.length >= 2) { + let id = array[0]; + let parentId = array[1]; + menuList.push({ + id: id, + parentId: 0, + children: [ + { + id: parentId, + parentId: id, + } + ], + }); + } + }); + const dataToSend = { + id:id, name: name.value, - }); + menuList: menuList + }; + const response = await request.post('/loadGlass/sys/role/updateRole', dataToSend); + // try { + // const response = await request.post('/loadGlass/sys/role/updateRole', { + // id: id, + // name: name.value, + // }); if (response.code == 200) { // 缁戝畾鎴愬姛锛屽鐞嗛�昏緫 @@ -248,7 +265,7 @@ <el-col :span="6"> <div id="dt" style="font-size: 15px;"> <div> - <el-form-item :label="$t('delivery.choice')" :required="true" style="width: 25vw;"> + <el-form-item :label="$t('delivery.choice')" :required="true" style="width: 25vw;"> <el-cascader v-model="selectedOptions" :placeholder="$t('delivery.inchoice')" -- Gitblit v1.8.0