From 6ec9fe61a3d1820fcc11d3d0d70c7b0a155795f2 Mon Sep 17 00:00:00 2001 From: 18317449825 <18317449825@163.com> Date: Wed, 25 May 2022 14:56:46 +0800 Subject: [PATCH 01/11] =?UTF-8?q?NEZ-1868=20feat=EF=BC=9Apanel=20starred?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/common/popBox/selectPanel.vue | 141 +++++++++++++++++- .../src/components/page/dashboard/panel.vue | 41 ++++- 2 files changed, 170 insertions(+), 12 deletions(-) diff --git a/nezha-fronted/src/components/common/popBox/selectPanel.vue b/nezha-fronted/src/components/common/popBox/selectPanel.vue index e83036f50..6f79ab1c8 100644 --- a/nezha-fronted/src/components/common/popBox/selectPanel.vue +++ b/nezha-fronted/src/components/common/popBox/selectPanel.vue @@ -2,10 +2,43 @@
- -
+ +
+ {{ node.label }} + + + + + + +
{{$t('overall.edit')}}
+
+ +
{{$t('overall.delete')}}
+
+
+
+ +
+
+
+
{{ node.label }} - + - + @@ -35,6 +68,8 @@ + +
@@ -72,6 +107,7 @@ export default { immediate: true, handler (n) { this.$refs.panelTree && this.$refs.panelTree.filter(n) + // this.$refs.starredTree && this.$refs.starredTree.filter(n) } }, showPanel: { @@ -95,10 +131,88 @@ export default { data () { return { popBox: { show: false }, - panel: { id: 0, name: '' } + panel: { id: 0, name: '' }, + starredData: [ + { + name: 'Starred', + children: [] + } + ], + tempArr: [] } }, methods: { + // 获取收藏的列表 + async getStarred () { + const params = { + type: 'panel' + } + const response = await this.$get('/sys/user/starred', params) + if (response.code === 200) { + this.tempArr = [] + this.recursionStarred(this.panelData, response.data) + this.starredData[0].children = this.formatStarred(this.tempArr) + this.$emit('refreshStarred', this.panelData) + } + }, + // 比对收藏的列表和全部列表 改变状态 + recursionStarred (allList, starredList) { + allList.forEach((item) => { + item.starred = false + starredList.forEach((subItem) => { + // 判断全部列表每一项的id和收藏列表每一项的id是否相等 + if (item.id === subItem.tid) { + if (this.tempArr.every(val => val.id !== item.id)) { + item.starred = true + this.tempArr.push({ + ...item, + children: [] + }) + } + } + }) + if (item.children && item.children.length) { + this.recursionStarred(item.children, starredList) + } + }) + }, + // 格式化收藏列表 (树形) + formatStarred (list) { + const arr = JSON.parse(JSON.stringify(list)) + arr.reverse() + for (let i = 0; i < arr.length; i++) { + if (arr[i].pid) { + // 找到父级所在下标 + const parentIndex = arr.findIndex(subItem => subItem.id === arr[i].pid) + if (parentIndex > -1) { + arr[parentIndex].children.unshift(arr[i]) + arr.splice(i, 1) + i-- + } + } + } + return arr.reverse() + }, + // 新增收藏 + addStarred (data) { + const params = { + type: 'panel', + tid: data.id + } + this.$post('/sys/user/starred', params).then(response => { + if (response.code === 200) { + this.getStarred() + } + }) + }, + // 删除收藏 + delStarred (data) { + this.$delete('/sys/user/starred?type=panel&tid=' + data.id).then(response => { + if (response.code === 200) { + this.getStarred() + } + }) + }, /* * node: 被拖的节点 * relative: 发生关系的节点 @@ -119,8 +233,8 @@ export default { updateWeight () { const toUpdate = [] let count = 0 - handler(this.panelData) + handler(this.panelData) function handler (panelData) { panelData.forEach(panel => { panel.weight = count++ @@ -130,7 +244,7 @@ export default { } }) } - + this.getStarred() this.$put('visual/panel/tree', toUpdate) }, deletePanel (data) { @@ -144,6 +258,9 @@ export default { }, // 确认选择某个节点,与父组件交互 selectPanel (data, checked, child) { + if (data.name === 'Starred') { + return false + } this.$emit('selectPanel', data) this.$refs.panelTree.setCurrentKey(data) this.esc() @@ -151,3 +268,13 @@ export default { } } + diff --git a/nezha-fronted/src/components/page/dashboard/panel.vue b/nezha-fronted/src/components/page/dashboard/panel.vue index 83a2811cb..67598cdbb 100644 --- a/nezha-fronted/src/components/page/dashboard/panel.vue +++ b/nezha-fronted/src/components/page/dashboard/panel.vue @@ -13,7 +13,7 @@