提交 7cc5169a authored 作者: wangjiahao's avatar wangjiahao

refactor: 前端增加菜单缓存,加快相应速度

上级 521b35f9
import request from '@/utils/request' import request from '@/utils/request'
export function queryAuthModel(data) { export function queryAuthModel(data, loading = true, timeout = 30000) {
return request({ return request({
url: 'authModel/queryAuthModel', url: 'authModel/queryAuthModel',
method: 'post', method: 'post',
loading: true, loading: loading,
timeout: 30000, timeout: timeout,
data data
}) })
} }
...@@ -40,7 +40,7 @@ export function chartGroupTree(data) { ...@@ -40,7 +40,7 @@ export function chartGroupTree(data) {
return request({ return request({
url: '/chart/group/tree', url: '/chart/group/tree',
method: 'post', method: 'post',
loading: true, loading: false,
data data
}) })
} }
......
...@@ -36,20 +36,22 @@ export function querySubjectWithGroup(data) { ...@@ -36,20 +36,22 @@ export function querySubjectWithGroup(data) {
}) })
} }
export function defaultTree(data) { export function defaultTree(data, loading = true, timeout = 30000) {
return request({ return request({
url: '/panel/group/defaultTree', url: '/panel/group/defaultTree',
method: 'post', method: 'post',
loading: true, loading: loading,
timeout: timeout,
data data
}) })
} }
export function groupTree(data) { export function groupTree(data, loading = true, timeout = 30000) {
return request({ return request({
url: '/panel/group/tree', url: '/panel/group/tree',
method: 'post', method: 'post',
loading: true, loading: loading,
timeout: timeout,
data data
}) })
} }
......
...@@ -337,6 +337,11 @@ export default { ...@@ -337,6 +337,11 @@ export default {
type: String, type: String,
required: false, required: false,
default: null default: null
},
mountedInit: {
type: Boolean,
required: false,
default: true
} }
}, },
data() { data() {
...@@ -440,10 +445,11 @@ export default { ...@@ -440,10 +445,11 @@ export default {
}, },
mounted() { mounted() {
this.treeNode(this.groupForm) if (this.mountedInit) {
this.refresh() this.treeNode(true)
// this.chartTree() this.refresh()
this.getChartGroupTree() this.getChartGroupTree()
}
}, },
methods: { methods: {
clickAdd(param) { clickAdd(param) {
...@@ -620,9 +626,17 @@ export default { ...@@ -620,9 +626,17 @@ export default {
}) })
}, },
treeNode(group) { treeNode(cache = false) {
queryAuthModel({ modelType: 'chart' }).then(res => { const modelInfo = localStorage.getItem('chart-tree')
this.tData = res.data const userCache = (modelInfo && cache)
if (userCache) {
this.tData = JSON.parse(modelInfo)
}
queryAuthModel({ modelType: 'chart' }, !userCache).then(res => {
localStorage.setItem('chart-tree', JSON.stringify(res.data))
if (!userCache) {
this.tData = res.data
}
}) })
}, },
......
...@@ -181,7 +181,7 @@ export default { ...@@ -181,7 +181,7 @@ export default {
this.unionDataChange() this.unionDataChange()
}, },
'table': function() { 'table': function() {
this.treeNode(this.groupForm) this.treeNode()
}, },
filterText(val) { filterText(val) {
this.searchPids = [] this.searchPids = []
...@@ -193,7 +193,7 @@ export default { ...@@ -193,7 +193,7 @@ export default {
} }
}, },
mounted() { mounted() {
this.treeNode(this.groupForm) this.treeNode(true)
}, },
created() { created() {
this.kettleState() this.kettleState()
...@@ -223,9 +223,17 @@ export default { ...@@ -223,9 +223,17 @@ export default {
} }
}, },
treeNode(group) { treeNode(cache) {
queryAuthModel({ modelType: 'dataset' }).then(res => { const modelInfo = localStorage.getItem('dataset-tree')
this.data = res.data const userCache = (modelInfo && cache)
if (userCache) {
this.data = JSON.parse(modelInfo)
}
queryAuthModel({ modelType: 'dataset' }, !userCache).then(res => {
localStorage.setItem('dataset-tree', JSON.stringify(res.data))
if (!userCache) {
this.data = res.data
}
}) })
}, },
nodeClick(data, node) { nodeClick(data, node) {
......
...@@ -325,7 +325,7 @@ export default { ...@@ -325,7 +325,7 @@ export default {
this.kettleState() this.kettleState()
}, },
mounted() { mounted() {
this.treeNode(this.groupForm) this.treeNode(true)
this.refresh() this.refresh()
}, },
methods: { methods: {
...@@ -407,7 +407,7 @@ export default { ...@@ -407,7 +407,7 @@ export default {
showClose: true showClose: true
}) })
this.expandedArray.push(group.pid) this.expandedArray.push(group.pid)
this.treeNode(group.pid) this.treeNode()
}) })
} else { } else {
return false return false
...@@ -451,7 +451,7 @@ export default { ...@@ -451,7 +451,7 @@ export default {
message: this.$t('dataset.delete_success'), message: this.$t('dataset.delete_success'),
showClose: true showClose: true
}) })
this.treeNode(data.pid) this.treeNode()
}) })
}).catch(() => { }).catch(() => {
}) })
...@@ -469,7 +469,7 @@ export default { ...@@ -469,7 +469,7 @@ export default {
message: this.$t('dataset.delete_success'), message: this.$t('dataset.delete_success'),
showClose: true showClose: true
}) })
this.treeNode(data.sceneId) this.treeNode()
this.$store.dispatch('dataset/setTable', new Date().getTime()) this.$store.dispatch('dataset/setTable', new Date().getTime())
}) })
}).catch(() => { }).catch(() => {
...@@ -496,9 +496,17 @@ export default { ...@@ -496,9 +496,17 @@ export default {
} }
}, },
treeNode(group) { treeNode(cache) {
queryAuthModel({ modelType: 'dataset' }).then(res => { const modelInfo = localStorage.getItem('dataset-tree')
this.tData = res.data const userCache = (modelInfo && cache)
if (userCache) {
this.tData = JSON.parse(modelInfo)
}
queryAuthModel({ modelType: 'dataset' }, !userCache).then(res => {
localStorage.setItem('dataset-tree', JSON.stringify(res.data))
if (!userCache) {
this.tData = res.data
}
}) })
}, },
...@@ -682,7 +690,7 @@ export default { ...@@ -682,7 +690,7 @@ export default {
this.searchTree(val) this.searchTree(val)
} else { } else {
this.isTreeSearch = false this.isTreeSearch = false
this.treeNode(this.groupForm) this.treeNode()
} }
}, },
filterNode(value, data) { filterNode(value, data) {
......
...@@ -92,7 +92,13 @@ export default { ...@@ -92,7 +92,13 @@ export default {
axiosFinished: false, axiosFinished: false,
loginTypes: [0], loginTypes: [0],
isPluginLoaded: false, isPluginLoaded: false,
contentShow: false contentShow: false,
clearLocalStorage: [
'panel-main-tree',
'panel-default-tree',
'chart-tree',
'dataset-tree'
]
} }
}, },
computed: { computed: {
...@@ -178,8 +184,14 @@ export default { ...@@ -178,8 +184,14 @@ export default {
} }
} */ } */
}, },
initCache() {
this.clearLocalStorage.forEach(item => {
localStorage.removeItem(item)
})
},
handleLogin() { handleLogin() {
this.initCache()
this.clearOidcMsg() this.clearOidcMsg()
this.$refs.loginForm.validate(valid => { this.$refs.loginForm.validate(valid => {
if (valid) { if (valid) {
......
...@@ -191,6 +191,7 @@ ...@@ -191,6 +191,7 @@
:opt-from="'panel'" :opt-from="'panel'"
:advice-group-id="adviceGroupId" :advice-group-id="adviceGroupId"
style="height: 0px;width:0px;padding:0px;overflow: hidden" style="height: 0px;width:0px;padding:0px;overflow: hidden"
:mounted-init="false"
@newViewInfo="newViewInfo" @newViewInfo="newViewInfo"
/> />
......
...@@ -233,6 +233,7 @@ import { ...@@ -233,6 +233,7 @@ import {
DEFAULT_COMMON_CANVAS_STYLE_STRING DEFAULT_COMMON_CANVAS_STYLE_STRING
} from '@/views/panel/panel' } from '@/views/panel/panel'
import TreeSelector from '@/components/TreeSelector' import TreeSelector from '@/components/TreeSelector'
import { queryAuthModel } from '@/api/authModel/authModel'
export default { export default {
name: 'PanelList', name: 'PanelList',
...@@ -334,7 +335,11 @@ export default { ...@@ -334,7 +335,11 @@ export default {
searchMap: { searchMap: {
all: this.$t('commons.all'), all: this.$t('commons.all'),
folder: this.$t('commons.folder') folder: this.$t('commons.folder')
} },
initLocalStorage: [
'chart',
'dataset'
]
} }
}, },
computed: { computed: {
...@@ -367,9 +372,20 @@ export default { ...@@ -367,9 +372,20 @@ export default {
this.$store.commit('setComponentData', []) this.$store.commit('setComponentData', [])
this.$store.commit('setCanvasStyle', DEFAULT_COMMON_CANVAS_STYLE_STRING) this.$store.commit('setCanvasStyle', DEFAULT_COMMON_CANVAS_STYLE_STRING)
this.defaultTree() this.defaultTree()
this.tree(this.groupForm) this.tree(true)
this.initCache()
}, },
methods: { methods: {
initCache() {
// 初始化时提前加载视图和数据集的缓存
this.initLocalStorage.forEach(item => {
if (!localStorage.getItem(item + '-tree')) {
queryAuthModel({ modelType: item }, false).then(res => {
localStorage.setItem(item + '-tree', JSON.stringify(res.data))
})
}
})
},
closeEditPanelDialog(panelInfo) { closeEditPanelDialog(panelInfo) {
this.editPanel.visible = false this.editPanel.visible = false
if (panelInfo) { if (panelInfo) {
...@@ -392,7 +408,7 @@ export default { ...@@ -392,7 +408,7 @@ export default {
} }
this.activeNodeAndClick(panelInfo) this.activeNodeAndClick(panelInfo)
} else { } else {
this.tree(this.groupForm) this.tree()
} }
} }
}, },
...@@ -535,7 +551,7 @@ export default { ...@@ -535,7 +551,7 @@ export default {
type: 'success', type: 'success',
showClose: true showClose: true
}) })
this.tree(this.groupForm) this.tree()
this.defaultTree() this.defaultTree()
}) })
} else { } else {
...@@ -562,7 +578,7 @@ export default { ...@@ -562,7 +578,7 @@ export default {
showClose: true showClose: true
}) })
this.clearCanvas() this.clearCanvas()
this.tree(this.groupForm) this.tree()
this.defaultTree() this.defaultTree()
}) })
}).catch(() => { }).catch(() => {
...@@ -591,17 +607,32 @@ export default { ...@@ -591,17 +607,32 @@ export default {
sort: 'node_type desc,name asc' sort: 'node_type desc,name asc'
} }
}, },
tree(group) { tree(cache = false) {
groupTree(group).then(res => { const modelInfo = localStorage.getItem('panel-main-tree')
this.tData = res.data const userCache = (modelInfo && cache)
if (userCache) {
this.tData = JSON.parse(modelInfo)
}
groupTree(this.groupForm, !userCache).then(res => {
localStorage.setItem('panel-main-tree', JSON.stringify(res.data))
if (!userCache) {
this.tData = res.data
}
}) })
}, },
defaultTree() { defaultTree() {
const requestInfo = { const requestInfo = {
panelType: 'system' panelType: 'system'
} }
defaultTree(requestInfo).then(res => { const modelInfo = localStorage.getItem('panel-default-tree')
this.defaultData = res.data if (modelInfo) {
this.defaultData = JSON.parse(modelInfo)
}
defaultTree(requestInfo, false).then(res => {
localStorage.setItem('panel-default-tree', JSON.stringify(res.data))
if (!modelInfo) {
this.defaultData = res.data
}
}) })
}, },
...@@ -768,7 +799,7 @@ export default { ...@@ -768,7 +799,7 @@ export default {
this.moveInfo.pid = this.tGroup.id this.moveInfo.pid = this.tGroup.id
this.moveInfo['optType'] = 'move' this.moveInfo['optType'] = 'move'
panelSave(this.moveInfo).then(response => { panelSave(this.moveInfo).then(response => {
this.tree(this.groupForm) this.tree()
this.closeMoveGroup() this.closeMoveGroup()
}) })
}, },
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论