Fix app loader
This commit is contained in:
parent
be6bc867fe
commit
d8c0371d43
|
@ -1,6 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<div id="app" class="bg-white dark:bg-notion-dark">
|
<div id="app" class="bg-white dark:bg-notion-dark">
|
||||||
<!-- <loading v-show="!isIframe" ref="loading" />-->
|
<loading v-show="!isIframe" ref="loading" />
|
||||||
|
|
||||||
<!-- <hotjar />-->
|
<!-- <hotjar />-->
|
||||||
<amplitude />
|
<amplitude />
|
||||||
|
@ -103,16 +103,6 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
watch: {
|
|
||||||
},
|
|
||||||
|
|
||||||
mounted () {
|
|
||||||
// // Make it globally accessible
|
|
||||||
// const app = getCurrentInstance().appContext
|
|
||||||
// app.config.globalProperties.$loading = this.$refs.loading
|
|
||||||
// console.log(app.config.globalProperties.$loading)
|
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
workspaceAdded () {
|
workspaceAdded () {
|
||||||
this.$router.push({ name: 'home' })
|
this.$router.push({ name: 'home' })
|
||||||
|
|
|
@ -10,77 +10,21 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// https://github.com/nuxt/nuxt.js/blob/master/lib/app/components/nuxt-loading.vue
|
// https://github.com/nuxt/nuxt.js/blob/master/lib/app/components/nuxt-loading.vue
|
||||||
|
import { mapState } from 'vuex'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data: () => ({
|
data: () => ({
|
||||||
percent: 0,
|
|
||||||
show: false,
|
|
||||||
canSuccess: true,
|
|
||||||
duration: 3000,
|
|
||||||
height: '2px',
|
height: '2px',
|
||||||
color: '#77b6ff',
|
color: '#77b6ff',
|
||||||
failedColor: 'red'
|
failedColor: 'red'
|
||||||
}),
|
}),
|
||||||
|
|
||||||
methods: {
|
computed: {
|
||||||
start () {
|
...mapState({
|
||||||
this.show = true
|
percent: state => state.app.loader.percent,
|
||||||
this.canSuccess = true
|
canSuccess: state => state.app.loader.canSuccess,
|
||||||
if (this._timer) {
|
show: state => state.app.loader.show
|
||||||
clearInterval(this._timer)
|
})
|
||||||
this.percent = 0
|
|
||||||
}
|
|
||||||
this._cut = 10000 / Math.floor(this.duration)
|
|
||||||
this._timer = setInterval(() => {
|
|
||||||
this.increase(this._cut * Math.random())
|
|
||||||
if (this.percent > 95) {
|
|
||||||
this.finish()
|
|
||||||
}
|
|
||||||
}, 100)
|
|
||||||
return this
|
|
||||||
},
|
|
||||||
set (num) {
|
|
||||||
this.show = true
|
|
||||||
this.canSuccess = true
|
|
||||||
this.percent = Math.floor(num)
|
|
||||||
return this
|
|
||||||
},
|
|
||||||
get () {
|
|
||||||
return Math.floor(this.percent)
|
|
||||||
},
|
|
||||||
increase (num) {
|
|
||||||
this.percent = this.percent + Math.floor(num)
|
|
||||||
return this
|
|
||||||
},
|
|
||||||
decrease (num) {
|
|
||||||
this.percent = this.percent - Math.floor(num)
|
|
||||||
return this
|
|
||||||
},
|
|
||||||
finish () {
|
|
||||||
this.percent = 100
|
|
||||||
this.hide()
|
|
||||||
return this
|
|
||||||
},
|
|
||||||
pause () {
|
|
||||||
clearInterval(this._timer)
|
|
||||||
return this
|
|
||||||
},
|
|
||||||
hide () {
|
|
||||||
clearInterval(this._timer)
|
|
||||||
this._timer = null
|
|
||||||
setTimeout(() => {
|
|
||||||
this.show = false
|
|
||||||
this.$nextTick(() => {
|
|
||||||
setTimeout(() => {
|
|
||||||
this.percent = 0
|
|
||||||
}, 200)
|
|
||||||
})
|
|
||||||
}, 500)
|
|
||||||
return this
|
|
||||||
},
|
|
||||||
fail () {
|
|
||||||
this.canSuccess = false
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -2,8 +2,7 @@ import routes from './routes'
|
||||||
import { createWebHistory, createRouter } from 'vue-router'
|
import { createWebHistory, createRouter } from 'vue-router'
|
||||||
import * as Sentry from '@sentry/vue'
|
import * as Sentry from '@sentry/vue'
|
||||||
import store from '../store'
|
import store from '../store'
|
||||||
import { defineComponent } from 'vue'
|
import { defineComponent, nextTick } from 'vue'
|
||||||
// import { nextTick } from '@vue/compat'
|
|
||||||
|
|
||||||
// The middleware for every page of the application.
|
// The middleware for every page of the application.
|
||||||
const globalMiddleware = ['check-auth', 'notion-connection']
|
const globalMiddleware = ['check-auth', 'notion-connection']
|
||||||
|
@ -76,7 +75,7 @@ async function beforeEach (to, from, next) {
|
||||||
|
|
||||||
// Start the loading bar.
|
// Start the loading bar.
|
||||||
if (components[components.length - 1].loading !== false) {
|
if (components[components.length - 1].loading !== false) {
|
||||||
// nextTick(() => router.app.$loading.start())
|
nextTick(() => store.commit('app/loaderStart'))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the middleware for all the matched components.
|
// Get the middleware for all the matched components.
|
||||||
|
@ -107,8 +106,7 @@ async function beforeEach (to, from, next) {
|
||||||
* @param {Function} next
|
* @param {Function} next
|
||||||
*/
|
*/
|
||||||
async function afterEach (to, from, next) {
|
async function afterEach (to, from, next) {
|
||||||
// await nextTick()
|
nextTick(() => store.commit('app/loaderFinish'))
|
||||||
// router.app.$loading.finish()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -125,9 +123,9 @@ function callMiddleware (middleware, to, from, next) {
|
||||||
const _next = (...args) => {
|
const _next = (...args) => {
|
||||||
// Stop if "_next" was called with an argument or the stack is empty.
|
// Stop if "_next" was called with an argument or the stack is empty.
|
||||||
if (args.length > 0 || stack.length === 0) {
|
if (args.length > 0 || stack.length === 0) {
|
||||||
// if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
// router.app.$loading.finish()
|
store.commit('app/loaderFinish')
|
||||||
// }
|
}
|
||||||
|
|
||||||
return next(...args)
|
return next(...args)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,73 @@
|
||||||
|
import { nextTick } from 'vue'
|
||||||
|
|
||||||
export const state = {
|
export const state = {
|
||||||
layout: 'default'
|
layout: 'default',
|
||||||
|
|
||||||
|
// App Loader
|
||||||
|
loader: {
|
||||||
|
percent: 0,
|
||||||
|
show: false,
|
||||||
|
canSuccess: true,
|
||||||
|
duration: 3000,
|
||||||
|
_timer: null,
|
||||||
|
_cut: null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const mutations = {
|
export const mutations = {
|
||||||
setLayout (state, layout) {
|
setLayout (state, layout) {
|
||||||
state.layout = layout ?? 'default'
|
state.layout = layout ?? 'default'
|
||||||
|
},
|
||||||
|
loaderStart (state) {
|
||||||
|
state.loader.show = true
|
||||||
|
state.loader.canSuccess = true
|
||||||
|
if (state.loader._timer) {
|
||||||
|
clearInterval(state.loader._timer)
|
||||||
|
state.loader.percent = 0
|
||||||
|
}
|
||||||
|
state.loader._cut = 10000 / Math.floor(state.loader.duration)
|
||||||
|
},
|
||||||
|
loaderIncrease (state, num) {
|
||||||
|
state.loader.percent = state.loader.percent + Math.floor(num)
|
||||||
|
},
|
||||||
|
loaderDecrease (state, num) {
|
||||||
|
state.loader.percent = state.loader.percent - Math.floor(num)
|
||||||
|
},
|
||||||
|
loaderFinish (state) {
|
||||||
|
state.loader.percent = 100
|
||||||
|
mutations.loaderHide(state)
|
||||||
|
},
|
||||||
|
loaderSetTimer (state, timerVal) {
|
||||||
|
state._timer = timerVal
|
||||||
|
},
|
||||||
|
loaderPause (state) {
|
||||||
|
clearInterval(state.loader._timer)
|
||||||
|
},
|
||||||
|
loaderHide (state) {
|
||||||
|
clearInterval(state.loader._timer)
|
||||||
|
state.loader._timer = null
|
||||||
|
setTimeout(() => {
|
||||||
|
state.loader.show = false
|
||||||
|
nextTick(() => {
|
||||||
|
setTimeout(() => {
|
||||||
|
state.loader.percent = 0
|
||||||
|
}, 200)
|
||||||
|
})
|
||||||
|
}, 500)
|
||||||
|
},
|
||||||
|
loaderFail () {
|
||||||
|
state.loader.canSuccess = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const actions = {
|
||||||
|
loaderStart ({ commit, dispatch }) {
|
||||||
|
mutations.loaderStart()
|
||||||
|
mutations.loaderSetTimer(setInterval(() => {
|
||||||
|
mutations.loaderIncrease(state.loader._cut * Math.random())
|
||||||
|
if (state.loader.percent > 95) {
|
||||||
|
mutations.loaderFinish()
|
||||||
|
}
|
||||||
|
}, 100))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue