mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-12 11:19:56 +00:00
perf: 优化全局提示
This commit is contained in:
parent
7de1ed7d45
commit
4dacc26567
@ -1,11 +1,11 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="common-network-exception">
|
<div class="common-network-exception">
|
||||||
<template v-if="type==='alert'">
|
<template v-if="type==='alert'">
|
||||||
<Alert v-if="show" type="error" show-icon closable>{{$L('网络连接失败,请检查网络设置。')}}</Alert>
|
<Alert v-if="show" type="error" show-icon closable @on-close="onClose">{{$L('网络连接失败,请检查网络设置。')}}</Alert>
|
||||||
</template>
|
</template>
|
||||||
<template v-else-if="type==='modal'">
|
<template v-else-if="type==='modal'">
|
||||||
<Modal
|
<Modal
|
||||||
v-model="show"
|
:value="show"
|
||||||
:width="416"
|
:width="416"
|
||||||
:closable="false"
|
:closable="false"
|
||||||
:mask-closable="false"
|
:mask-closable="false"
|
||||||
@ -18,7 +18,8 @@
|
|||||||
<div>{{ajaxNetworkException}}</div>
|
<div>{{ajaxNetworkException}}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="ivu-modal-confirm-footer">
|
<div class="ivu-modal-confirm-footer">
|
||||||
<Button type="primary" @click="show = false">{{$L('确定')}}</Button>
|
<Button type="text" @click="onClose">{{$L('关闭提示')}}</Button>
|
||||||
|
<Button type="primary" :loading="loadIng" @click="onCheck">{{$L('重试')}}</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
@ -39,32 +40,30 @@ export default {
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
show: false,
|
timer: null,
|
||||||
timeShow: null,
|
checkIng: false,
|
||||||
timeCheck: null,
|
loadIng: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
this.clearTimer()
|
this.onClose()
|
||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
...mapState(['ajaxNetworkException']),
|
...mapState(['ajaxNetworkException']),
|
||||||
|
|
||||||
|
show() {
|
||||||
|
return !!this.ajaxNetworkException
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
ajaxNetworkException: {
|
show(v) {
|
||||||
handler(v) {
|
this.timer && clearInterval(this.timer)
|
||||||
this.clearTimer()
|
if (v) {
|
||||||
if (v) {
|
this.timer = setInterval(this.checkNetwork, 3000)
|
||||||
this.checkNetwork();
|
}
|
||||||
this.timeShow = setTimeout(_ => {
|
|
||||||
this.show = true;
|
|
||||||
}, 5000)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
immediate: true
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -74,26 +73,60 @@ export default {
|
|||||||
return this.$isSoftware && (apiHome == "" || apiHome == "public")
|
return this.$isSoftware && (apiHome == "" || apiHome == "public")
|
||||||
},
|
},
|
||||||
|
|
||||||
checkNetwork() {
|
/**
|
||||||
this.timeCheck && clearTimeout(this.timeCheck);
|
* 调用网络
|
||||||
this.timeCheck = setTimeout(() => {
|
* @returns {Promise<void>}
|
||||||
if (!this.ajaxNetworkException) {
|
*/
|
||||||
return; // 已经恢复
|
async callNetwork() {
|
||||||
}
|
if (this.isNotServer()) {
|
||||||
if (this.isNotServer()) {
|
this.onClose()
|
||||||
return; // 没有配置服务器地址
|
return;
|
||||||
}
|
}
|
||||||
this.$store.dispatch("call", {
|
await this.$store.dispatch("call", {
|
||||||
url: "system/setting",
|
url: "system/setting",
|
||||||
}).finally(() => {
|
})
|
||||||
this.checkNetwork();
|
this.onClose()
|
||||||
});
|
|
||||||
}, 3000);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
clearTimer() {
|
/**
|
||||||
this.timeShow && clearTimeout(this.timeShow)
|
* 检查网络(自动)
|
||||||
this.show = false
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async checkNetwork() {
|
||||||
|
if (this.checkIng) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.checkIng = true
|
||||||
|
try {
|
||||||
|
await this.callNetwork()
|
||||||
|
} catch (e) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
this.checkIng = false
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查网络(重试)
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async onCheck() {
|
||||||
|
if (this.loadIng) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.loadIng = true
|
||||||
|
try {
|
||||||
|
await this.callNetwork()
|
||||||
|
} catch (e) {
|
||||||
|
$A.messageError("网络连接失败")
|
||||||
|
}
|
||||||
|
this.loadIng = false
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关闭提示
|
||||||
|
*/
|
||||||
|
onClose() {
|
||||||
|
this.$store.state.ajaxNetworkException = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -211,22 +211,29 @@ export default {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
onVersion() {
|
async onVersion() {
|
||||||
const array = []
|
const array = [
|
||||||
this.getServerVersion().then(version => {
|
`${this.$L('服务器')}: ${$A.getDomain($A.mainUrl())}`
|
||||||
array.push(`${this.$L('服务器')}: ${$A.getDomain($A.mainUrl())}`)
|
]
|
||||||
|
await this.$store.dispatch("showSpinner", 600)
|
||||||
|
try {
|
||||||
|
const version = await this.getServerVersion()
|
||||||
array.push(`${this.$L('服务器版本')}: v${version}`)
|
array.push(`${this.$L('服务器版本')}: v${version}`)
|
||||||
array.push(`${this.$L('客户端版本')}: v${this.version}`)
|
} catch (e) {
|
||||||
$A.modalInfo({
|
array.push(`${this.$L('服务器版本')}: ` + this.$L('获取失败'))
|
||||||
language: false,
|
}
|
||||||
title: this.$L('版本信息'),
|
await this.$store.dispatch("hiddenSpinner")
|
||||||
content: array.join('<br/>')
|
array.push(`${this.$L('客户端版本')}: v${this.version}`)
|
||||||
})
|
//
|
||||||
|
$A.modalInfo({
|
||||||
|
language: false,
|
||||||
|
title: this.$L('版本信息'),
|
||||||
|
content: array.join('<br/>')
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
getServerVersion() {
|
getServerVersion() {
|
||||||
return new Promise(resolve => {
|
return new Promise((resolve, reject) => {
|
||||||
if (/^\d+\.\d+\.\d+$/.test(this.systemConfig.server_version)) {
|
if (/^\d+\.\d+\.\d+$/.test(this.systemConfig.server_version)) {
|
||||||
resolve(this.systemConfig.server_version)
|
resolve(this.systemConfig.server_version)
|
||||||
return;
|
return;
|
||||||
@ -235,7 +242,7 @@ export default {
|
|||||||
if (status === 200) {
|
if (status === 200) {
|
||||||
resolve(data.version)
|
resolve(data.version)
|
||||||
}
|
}
|
||||||
}).catch(_ => { })
|
}).catch(reject)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2
resources/assets/js/store/actions.js
vendored
2
resources/assets/js/store/actions.js
vendored
@ -249,8 +249,6 @@ export default {
|
|||||||
|
|
||||||
// 请求成功
|
// 请求成功
|
||||||
params.success = async (result, status, xhr) => {
|
params.success = async (result, status, xhr) => {
|
||||||
state.ajaxNetworkException = null
|
|
||||||
|
|
||||||
// 数据校验
|
// 数据校验
|
||||||
if (!$A.isJson(result)) {
|
if (!$A.isJson(result)) {
|
||||||
console.log(result, status, xhr)
|
console.log(result, status, xhr)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user