Unverified Commit ac91fcbe by Sendya

feat: add global loading wrapper

parent 987a56b4
增加全局 Loading 遮罩动画
====
## 需求
> 为了让操作不被用户中断,或体现一个全局的加载让用户得知当前状态时
## 实现方案
1. 使用 `spin` 组件实现
2. 增加一个 `Vue` 原型链属性 方法 `$loading.show()` `$loading.hide()`,去控制 `vuex` 中的 `app.globalLoading` 属性
具体参考 `src/App.vue``src/utils/helper/loadingWrap.js` 已经实现内容
\ No newline at end of file
<template> <template>
<a-locale-provider :locale="locale"> <a-locale-provider :locale="locale">
<div id="app"> <div id="app">
<router-view/> <a-spin :spinning="globalLoading" wrapperClassName="top-loading">
<router-view />
</a-spin>
</div> </div>
</a-locale-provider> </a-locale-provider>
</template> </template>
<script> <script>
import { mapState } from 'vuex'
import zhCN from 'ant-design-vue/lib/locale-provider/zh_CN' import zhCN from 'ant-design-vue/lib/locale-provider/zh_CN'
import { deviceEnquire, DEVICE_TYPE } from '@/utils/device' import { deviceEnquire, DEVICE_TYPE } from '@/utils/device'
...@@ -16,7 +19,17 @@ export default { ...@@ -16,7 +19,17 @@ export default {
locale: zhCN locale: zhCN
} }
}, },
computed: {
...mapState({
globalLoading: state => state.app.globalLoading
})
},
mounted () { mounted () {
console.log(this.globalLoading)
this.$loading.show()
setTimeout(() => {
this.$loading.hide()
}, 3000)
const { $store } = this const { $store } = this
deviceEnquire(deviceType => { deviceEnquire(deviceType => {
switch (deviceType) { switch (deviceType) {
...@@ -43,4 +56,10 @@ export default { ...@@ -43,4 +56,10 @@ export default {
#app { #app {
height: 100%; height: 100%;
} }
#app .top-loading {
height: 100%;
}
#app .top-loading .ant-spin-container {
height: 100%;
}
</style> </style>
import Vue from 'vue' import Vue from 'vue'
import VueStorage from 'vue-ls' import VueStorage from 'vue-ls'
import config from '@/config/defaultSettings' import config from '@/config/defaultSettings'
// base library // base library
import Antd from 'ant-design-vue' import Antd from 'ant-design-vue'
import Viser from 'viser-vue' import Viser from 'viser-vue'
import 'ant-design-vue/dist/antd.less' import 'ant-design-vue/dist/antd.less'
// ext library // ext library
import VueClipboard from 'vue-clipboard2' import VueClipboard from 'vue-clipboard2'
import PermissionHelper from '@/utils/helper/permission' import PermissionHelper from '@/utils/helper/permission'
// import '@/components/use' import LoadingWrap from '@/utils/helper/loadingWrap'
// import '@/components/use'
VueClipboard.config.autoSetContainer = true
VueClipboard.config.autoSetContainer = true
Vue.use(Antd)
Vue.use(Viser) Vue.use(Antd)
Vue.use(Viser)
Vue.use(VueStorage, config.storageOptions)
Vue.use(VueClipboard) Vue.use(VueStorage, config.storageOptions)
Vue.use(VueClipboard)
Vue.use(PermissionHelper) Vue.use(PermissionHelper)
Vue.use(LoadingWrap)
...@@ -8,7 +8,8 @@ const getters = { ...@@ -8,7 +8,8 @@ const getters = {
welcome: state => state.user.welcome, welcome: state => state.user.welcome,
roles: state => state.user.roles, roles: state => state.user.roles,
userInfo: state => state.user.info, userInfo: state => state.user.info,
addRouters: state => state.permission.addRouters addRouters: state => state.permission.addRouters,
loading: state => state.app.loading
} }
export default getters export default getters
...@@ -22,7 +22,8 @@ const app = { ...@@ -22,7 +22,8 @@ const app = {
fixSiderbar: false, fixSiderbar: false,
autoHideHeader: false, autoHideHeader: false,
color: null, color: null,
weak: false weak: false,
globalLoading: false
}, },
mutations: { mutations: {
SET_SIDEBAR_TYPE: (state, type) => { SET_SIDEBAR_TYPE: (state, type) => {
...@@ -70,6 +71,9 @@ const app = { ...@@ -70,6 +71,9 @@ const app = {
TOGGLE_WEAK: (state, flag) => { TOGGLE_WEAK: (state, flag) => {
Vue.ls.set(DEFAULT_COLOR_WEAK, flag) Vue.ls.set(DEFAULT_COLOR_WEAK, flag)
state.weak = flag state.weak = flag
},
TOGGLE_LOADING: (state, loading) => {
state.globalLoading = loading
} }
}, },
actions: { actions: {
...@@ -108,6 +112,9 @@ const app = { ...@@ -108,6 +112,9 @@ const app = {
}, },
ToggleWeak ({ commit }, weakFlag) { ToggleWeak ({ commit }, weakFlag) {
commit('TOGGLE_WEAK', weakFlag) commit('TOGGLE_WEAK', weakFlag)
},
ToggleLoading ({ commit }, loading) {
commit('TOGGLE_LOADING', loading)
} }
} }
} }
......
function loadingWrap (Vue) {
if (loadingWrap.installed) {
return
}
!Vue.prototype.$loading && Object.defineProperties(Vue.prototype, {
$loading: {
get () {
const { $store } = this
return {
show () {
console.log('this.$store', $store)
$store.commit('TOGGLE_LOADING', true)
},
hide () {
console.log('this.$store', $store)
$store.commit('TOGGLE_LOADING', false)
}
}
}
}
})
}
export default loadingWrap
...@@ -63,7 +63,7 @@ ...@@ -63,7 +63,7 @@
<div class="table-operator"> <div class="table-operator">
<a-button type="primary" icon="plus" v-action:add>新建</a-button> <a-button type="primary" icon="plus" v-action:add>新建</a-button>
<a-dropdown v-action:edit && selectedRowKeys.length > 0"> <a-dropdown v-action:edit v-if="selectedRowKeys.length > 0">
<a-menu slot="overlay"> <a-menu slot="overlay">
<a-menu-item key="1"><a-icon type="delete" />删除</a-menu-item> <a-menu-item key="1"><a-icon type="delete" />删除</a-menu-item>
<!-- lock | unlock --> <!-- lock | unlock -->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment