refactor(仪表板): 资源数排序规则支持缓存到本地

This commit is contained in:
wangjiahao 2024-03-29 11:14:53 +08:00
parent 89813a228e
commit 48d76e68af
2 changed files with 14 additions and 9 deletions

View File

@ -18,8 +18,6 @@ export const sortPer = (subTree: BusiTreeNode[], sortType: string) => {
} else if (sortType === 'name_asc') { } else if (sortType === 'name_asc') {
subTree.sort((a, b) => a.name.localeCompare(b.name, 'zh-Hans-CN', { sensitivity: 'accent' })) subTree.sort((a, b) => a.name.localeCompare(b.name, 'zh-Hans-CN', { sensitivity: 'accent' }))
} else if (sortType === 'time_asc') { } else if (sortType === 'time_asc') {
return subTree.reverse() subTree.reverse()
} else {
return subTree
} }
} }

View File

@ -218,11 +218,13 @@ const getTree = async () => {
dvMainStore.resetDvInfo() dvMainStore.resetDvInfo()
} }
if (nodeData.length && nodeData[0]['id'] === '0' && nodeData[0]['name'] === 'root') { if (nodeData.length && nodeData[0]['id'] === '0' && nodeData[0]['name'] === 'root') {
state.resourceTree = nodeData[0]['children'] || [] state.originResourceTree = nodeData[0]['children'] || []
sortTypeChange(state.curSortType)
afterTreeInit() afterTreeInit()
return return
} }
state.resourceTree = nodeData state.originResourceTree = nodeData
sortTypeChange(state.curSortType)
afterTreeInit() afterTreeInit()
} }
@ -243,7 +245,6 @@ function flatTree(tree: BusiTreeNode[]) {
} }
const afterTreeInit = () => { const afterTreeInit = () => {
state.originResourceTree = _.cloneDeep(state.resourceTree)
mounted.value = true mounted.value = true
if (selectedNodeKey.value && returnMounted.value) { if (selectedNodeKey.value && returnMounted.value) {
expandedArray.value = getDefaultExpandedKeys() expandedArray.value = getDefaultExpandedKeys()
@ -323,9 +324,6 @@ const addOperation = (
} }
initOpenHandler(newWindow) initOpenHandler(newWindow)
} else if (cmd === 'newFromTemplate') { } else if (cmd === 'newFromTemplate') {
// state.templateCreatePid = data?.id
// // newFromTemplate
// resourceCreateOpt.value.optInit()
const params = { const params = {
curPosition: 'create', curPosition: 'create',
pid: data?.id, pid: data?.id,
@ -395,6 +393,7 @@ const getDefaultExpandedKeys = () => {
const sortTypeChange = sortType => { const sortTypeChange = sortType => {
state.resourceTree = treeSort(state.originResourceTree, sortType) state.resourceTree = treeSort(state.originResourceTree, sortType)
state.curSortType = sortType state.curSortType = sortType
wsCache.set('TreeSort-' + curCanvasType.value, state.curSortType)
} }
watch(filterText, val => { watch(filterText, val => {
@ -411,7 +410,15 @@ const initOpenHandler = newWindow => {
openHandler.value.invokeMethod(pm) openHandler.value.invokeMethod(pm)
} }
} }
const loadInit = () => {
const historyTreeSort = wsCache.get('TreeSort-' + curCanvasType.value)
if (historyTreeSort) {
state.curSortType = historyTreeSort
}
}
onMounted(() => { onMounted(() => {
loadInit()
getTree() getTree()
}) })