From 68ee8235c8cd659fba5e59e3d924d5ea093504ab Mon Sep 17 00:00:00 2001
From: wu <731351411@qq.com>
Date: 星期四, 18 七月 2024 08:39:57 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
UI-Project/src/views/User/rolelist.vue | 176 ++++++++++++++++++++++++++++++++++++++++------------------
1 files changed, 122 insertions(+), 54 deletions(-)
diff --git a/UI-Project/src/views/User/rolelist.vue b/UI-Project/src/views/User/rolelist.vue
index 5dcbb0b..78dfa0f 100644
--- a/UI-Project/src/views/User/rolelist.vue
+++ b/UI-Project/src/views/User/rolelist.vue
@@ -13,7 +13,7 @@
// import { ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
// import LanguageMixin from './lang/LanguageMixin'
-const selectedProjectNoa = ref(''); // 褰撳墠閫変腑鐨勮鑹�
+const selectedProjectNoa = ref(null); // 褰撳墠閫変腑鐨勮鑹�
// const options = ref<any[]>([]); // 涓嬫媺閫夐」鍒楄〃
const name = ref('');
const tableData = ref([])
@@ -53,26 +53,34 @@
console.error('Error fetching options:', error);
}
};
-// 娣诲姞
+// 娣诲姞
const getTableRow = async () => {
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,
- }
- ],
- });
+ let parentIdMap = {}; // 鐢ㄤ簬瀛樺偍宸茬粡娣诲姞鐨勭埗椤�
+ selectedOptions.value.forEach(array => {
+ if (array.length >= 2) {
+ let id = array[0];
+ let parentId = array[1];
+ // 濡傛灉id杩樻湭浣滀负鐖堕」娣诲姞锛屽垯娣诲姞瀹�
+ if (!parentIdMap[id]) {
+ menuList.push({
+ id: id,
+ parentId: 0, // 閫氬父锛岄《绾ч」鐨刾arentId鍙兘鏄痭ull鎴栫壒瀹氱殑鏍笽D锛岃繖閲岃涓�0鍙兘鏄釜鐗规畩鐢ㄩ��
+ children: []
+ });
+ parentIdMap[id] = menuList[menuList.length - 1]; // 鏇存柊鏄犲皠
+ }
+ // 鍚戝搴旂殑鐖堕」娣诲姞瀛愰」
+ if (!parentIdMap[id].children.some(child => child.id === parentId)) {
+ // 妫�鏌ユ槸鍚﹀凡瀛樺湪鐩稿悓鐨勫瓙椤癸紙鍩轰簬id锛夛紝閬垮厤閲嶅娣诲姞
+ parentIdMap[id].children.push({
+ id: parentId,
+ parentId: id
+ });
+ }
}
- });
+ });
const dataToSend = {
name: name.value,
menuList: menuList
@@ -91,64 +99,124 @@
console.error(error);
}
};
-// 澶勭悊缂栬緫鎸夐挳鐐瑰嚮
function handleEdit(row) {
- name.value = row.name;
- selectedOptions.value = row.selectedOptions
-// options.value = res.data.tree
- adda.value = true; // 鏄剧ず瀵硅瘽妗�
- window.localStorage.setItem('id', row.id)
+ name.value = row.name;
+ adda.value = true;
+ window.localStorage.setItem('ids', row.id);
+ const parentIdMap = {};
+ const menuItemsById = {}; // 蹇�熸煡鎵捐彍鍗曢」
+ let topLevelItems = []; // 瀛樺偍椤剁骇鑿滃崟椤�
+ row.menuList.forEach(item => {
+ const parentId = item.parentId === 0 ? null : item.parentId;
+ const menuItem = {
+ id: item.id,
+ parentId: parentId,
+ menuName: item.menuName,
+ children: []
+ };
+ menuItemsById[item.id] = menuItem;
+ // 鍒濆鍖栨垨鏇存柊parentIdMap涓殑鏁扮粍
+ if (!parentIdMap[parentId]) {
+ parentIdMap[parentId] = [];
+ }
+ if (parentId === null) {
+ // 椤剁骇鑿滃崟椤圭洿鎺ユ坊鍔犲埌topLevelItems
+ topLevelItems.push(menuItem);
+ } else {
+ // 闈為《绾ц彍鍗曢」娣诲姞鍒皃arentIdMap涓�
+ parentIdMap[parentId].push(menuItem);
+ }
+ });
+ for (const parentId in parentIdMap) {
+ if (parentId !== 'null') { // 璺宠繃椤剁骇鑿滃崟椤�
+ parentIdMap[parentId].forEach(child => {
+ // 鏌ユ壘鐖堕」骞舵坊鍔犲瓙椤�
+ if (menuItemsById[parentId]) {
+ menuItemsById[parentId].children.push(child);
+ }
+ });
+ }
+ }
+ if (selectedOptions.value !== topLevelItems) {
+ selectedOptions.value = topLevelItems;
+ }
+ console.log(topLevelItems);
+ // selectedOptions.value = topLevelItems;
+const topLevelItemsWithChildren = topLevelItems; // 鍖呭惈椤剁骇鑿滃崟椤瑰強鍏跺瓙鑿滃崟椤圭殑鏁扮粍 聽
+ let selectedPath = [];
+// 寰幆閬嶅巻 topLevelItemsWithChildren 鏁扮粍
+for (let i = 0; i < topLevelItemsWithChildren.length; i++) {
+ // 娣诲姞椤剁骇鑿滃崟椤圭殑 id
+ selectedPath.push(topLevelItemsWithChildren[i].id);
+ // 濡傛灉鏈夊瓙鑿滃崟椤癸紝娣诲姞绗竴涓瓙鑿滃崟椤圭殑 id
+ if (topLevelItemsWithChildren[i].children && topLevelItemsWithChildren[i].children.length > 0) {
+ for (let j = 0; j < topLevelItemsWithChildren[i].children.length; j++) {
+ // 灏嗘瘡涓瓙鑿滃崟椤圭殑 id 娣诲姞鍒� selectedPath 涓�
+ selectedPath.push(topLevelItemsWithChildren[i].children[j].id);
+ }
+ }
+}
+ console.log(selectedPath);
+selectedOptions.value = selectedPath;
}
// 缂栬緫
const getTableRowa = async () => {
- let id = window.localStorage.getItem('id')
+ let ids = window.localStorage.getItem('ids')
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,
- }
- ],
- });
+ let parentIdMap = {}; // 鐢ㄤ簬瀛樺偍宸茬粡娣诲姞鐨勭埗椤�
+ selectedOptions.value.forEach(array => {
+ if (array.length >= 2) {
+ let id = array[0];
+ let parentId = array[1];
+ // 濡傛灉id杩樻湭浣滀负鐖堕」娣诲姞锛屽垯娣诲姞瀹�
+ if (!parentIdMap[id]) {
+ menuList.push({
+ id: id,
+ parentId: 0, // 閫氬父锛岄《绾ч」鐨刾arentId鍙兘鏄痭ull鎴栫壒瀹氱殑鏍笽D锛岃繖閲岃涓�0鍙兘鏄釜鐗规畩鐢ㄩ��
+ children: []
+ });
+ parentIdMap[id] = menuList[menuList.length - 1]; // 鏇存柊鏄犲皠
+ }
+ // 鍚戝搴旂殑鐖堕」娣诲姞瀛愰」
+ if (!parentIdMap[id].children.some(child => child.id === parentId)) {
+ // 妫�鏌ユ槸鍚﹀凡瀛樺湪鐩稿悓鐨勫瓙椤癸紙鍩轰簬id锛夛紝閬垮厤閲嶅娣诲姞
+ parentIdMap[id].children.push({
+ id: parentId,
+ parentId: id
+ });
+ }
}
- });
+ });
const dataToSend = {
- id:id,
+ id:ids,
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) {
- // 缁戝畾鎴愬姛锛屽鐞嗛�昏緫
ElMessage.success(response.message);
adda.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 closeDialog(row) {
+ add.value = false;
+ name.value = '';
+ selectedOptions.value = '';
+}
+function closeDialoga(row) {
+ adda.value = false;
+ name.value = '';
+ selectedOptions.value = '';
+}
// 鍒犻櫎
const opena = async(row) => {
try {
@@ -244,7 +312,7 @@
<el-button type="primary" @click="getTableRow">
{{ $t('delivery.sure') }}
</el-button>
- <el-button @click="add = false"> {{ $t('delivery.cancel') }}</el-button>
+ <el-button @click="closeDialog"> {{ $t('delivery.cancel') }}</el-button>
</div>
</template>
</el-dialog>
@@ -284,7 +352,7 @@
<el-button type="primary" @click="getTableRowa">
{{ $t('delivery.sure') }}
</el-button>
- <el-button @click="adda = false">{{ $t('delivery.cancel') }}</el-button>
+ <el-button @click="closeDialoga">{{ $t('delivery.cancel') }}</el-button>
</div>
</template>
</el-dialog>
--
Gitblit v1.8.0