fix:修复每次点击都刷新树形控件bug

This commit is contained in:
zyh
2022-05-27 16:54:02 +08:00
parent 394926e7ea
commit a668ea9bd0
2 changed files with 20 additions and 11 deletions

View File

@@ -165,7 +165,7 @@ export default {
}, },
methods: { methods: {
// 获取收藏的列表 // 获取收藏的列表
async getStarred () { async getStarred (type) {
const params = { const params = {
type: 'panel' type: 'panel'
} }
@@ -174,7 +174,12 @@ export default {
this.tempArr = [] this.tempArr = []
this.recursionStarred(this.panelData, response.data) this.recursionStarred(this.panelData, response.data)
this.starredData[0].children = this.formatStarred(this.tempArr) this.starredData[0].children = this.formatStarred(this.tempArr)
this.$emit('refreshStarred', this.panelData) if (type === 'tree') {
// 刷新树形控件
this.$emit('refreshStarred', { data: this.panelData, type: 'tree' })
} else {
this.$emit('refreshStarred', { data: this.panelData })
}
} }
}, },
// 比对收藏的列表和全部列表 改变状态 // 比对收藏的列表和全部列表 改变状态
@@ -221,9 +226,10 @@ export default {
type: 'panel', type: 'panel',
tid: data.id tid: data.id
} }
this.$post('/sys/user/starred', params).then(response => { this.$post('/sys/user/starred', params).then(async response => {
if (response.code === 200) { if (response.code === 200) {
this.getStarred() await this.getStarred()
data.starred = true
} }
}) })
}, },
@@ -231,9 +237,10 @@ export default {
// 删除收藏 // 删除收藏
delStarred: bus.debounceFn(function (data) { delStarred: bus.debounceFn(function (data) {
this.$delete('/sys/user/starred?type=panel&tid=' + data.id).then(response => { this.$delete('/sys/user/starred?type=panel&tid=' + data.id).then(async response => {
if (response.code === 200) { if (response.code === 200) {
this.getStarred() await this.getStarred()
data.starred = false
} }
}) })
}, },

View File

@@ -308,15 +308,17 @@ export default {
} }
}, },
methods: { methods: {
refreshStarred (value) { // 刷新树形菜单视图
// 重新赋值,否则树形菜单不更新 refreshStarred ({ data, type }) {
this.panelData = JSON.parse(JSON.stringify(value)) if (type === 'tree') {
this.panelData = JSON.parse(JSON.stringify(data))
}
this.$nextTick(() => { this.$nextTick(() => {
this.$refs.selectPanel.$refs.starredTree.filter(this.filterPanel) this.$refs.selectPanel.$refs.starredTree.filter(this.filterPanel)
this.$refs.selectPanel.$refs.panelTree.filter(this.filterPanel) this.$refs.selectPanel.$refs.panelTree.filter(this.filterPanel)
this.$refs.selectPanel.$refs.panelTree.setCurrentKey(this.showPanel) this.$refs.selectPanel.$refs.panelTree.setCurrentKey(this.showPanel)
}) })
// // 判断当前页面收藏状态 // 判断当前页面收藏状态
const starredArr = this.$refs.selectPanel.tempArr const starredArr = this.$refs.selectPanel.tempArr
this.showPanel.starred = starredArr.some(item => item.id === this.showPanel.id) this.showPanel.starred = starredArr.some(item => item.id === this.showPanel.id)
}, },
@@ -673,7 +675,7 @@ export default {
let isInitData = false let isInitData = false
this.panelData = JSON.parse(JSON.stringify(response.data.list)) this.panelData = JSON.parse(JSON.stringify(response.data.list))
this.$nextTick(() => { this.$nextTick(() => {
this.$refs.selectPanel.getStarred() this.$refs.selectPanel.getStarred('tree')
}) })
if (response.data.list.length > 0) { if (response.data.list.length > 0) {
if (this.$store.state.showPanel.id > 0 && this.$store.state.showPanel.name) { if (this.$store.state.showPanel.id > 0 && this.$store.state.showPanel.name) {