Demo:一些耗时的操作添加loading

This commit is contained in:
wanglin2 2023-08-09 09:09:43 +08:00
parent dc8efbe3ef
commit 885647cedf
4 changed files with 40 additions and 0 deletions

View File

@ -857,6 +857,7 @@ export default {
this.style[key] = value this.style[key] = value
} }
this.data.theme.config[key] = value this.data.theme.config[key] = value
this.$bus.$emit('showLoading')
this.mindMap.setThemeConfig(this.data.theme.config) this.mindMap.setThemeConfig(this.data.theme.config)
storeConfig({ storeConfig({
theme: { theme: {

View File

@ -69,6 +69,7 @@ import Search from './Search.vue'
import NodeIconSidebar from './NodeIconSidebar.vue' import NodeIconSidebar from './NodeIconSidebar.vue'
import NodeIconToolbar from './NodeIconToolbar.vue' import NodeIconToolbar from './NodeIconToolbar.vue'
import OutlineEdit from './OutlineEdit.vue' import OutlineEdit from './OutlineEdit.vue'
import { showLoading, hideLoading } from '@/utils/loading'
// //
MindMap MindMap
@ -120,6 +121,7 @@ export default {
}, },
data() { data() {
return { return {
enableShowLoading: true,
mindMap: null, mindMap: null,
mindMapData: null, mindMapData: null,
prevImg: '', prevImg: '',
@ -143,6 +145,7 @@ export default {
} }
}, },
mounted() { mounted() {
showLoading()
// this.showNewFeatureInfo() // this.showNewFeatureInfo()
this.getData() this.getData()
this.init() this.init()
@ -162,11 +165,27 @@ export default {
this.$bus.$on('startPainter', () => { this.$bus.$on('startPainter', () => {
this.mindMap.painter.startPainter() this.mindMap.painter.startPainter()
}) })
this.$bus.$on('node_tree_render_end', this.handleHideLoading)
this.$bus.$on('showLoading', this.handleShowLoading)
window.addEventListener('resize', () => { window.addEventListener('resize', () => {
this.mindMap.resize() this.mindMap.resize()
}) })
}, },
methods: { methods: {
// loading
handleShowLoading() {
this.enableShowLoading = true
showLoading()
},
// loading
handleHideLoading() {
if (this.enableShowLoading) {
this.enableShowLoading = false
hideLoading()
}
},
/** /**
* @Author: 王林 * @Author: 王林
* @Date: 2021-07-03 22:11:37 * @Date: 2021-07-03 22:11:37
@ -315,6 +334,7 @@ export default {
* @Desc: 动态设置思维导图数据 * @Desc: 动态设置思维导图数据
*/ */
setData(data) { setData(data) {
this.handleShowLoading()
if (data.root) { if (data.root) {
this.mindMap.setFullData(data) this.mindMap.setFullData(data)
} else { } else {

View File

@ -136,6 +136,7 @@ export default {
}, },
useTheme(theme) { useTheme(theme) {
if (theme.value === this.theme) return
this.theme = theme.value this.theme = theme.value
this.handleDark() this.handleDark()
const customThemeConfig = this.mindMap.getCustomThemeConfig() const customThemeConfig = this.mindMap.getCustomThemeConfig()
@ -159,6 +160,7 @@ export default {
}, },
changeTheme(theme, config) { changeTheme(theme, config) {
this.$bus.$emit('showLoading')
this.mindMap.setTheme(theme.value) this.mindMap.setTheme(theme.value)
storeConfig({ storeConfig({
theme: { theme: {

17
web/src/utils/loading.js Normal file
View File

@ -0,0 +1,17 @@
import { Loading } from 'element-ui'
let loadingInstance = null
export const showLoading = () => {
loadingInstance = Loading.service({
lock: true
})
}
export const hideLoading = () => {
if (loadingInstance) {
loadingInstance.close()
loadingInstance = null
}
}