perf: 优化文件同步到数据库

This commit is contained in:
jmal 2023-03-25 23:16:14 +08:00
parent d598b96e9e
commit cb6a2ff6e4
2 changed files with 15 additions and 6 deletions

View File

@ -41,7 +41,8 @@
</span> </span>
<div class="config-itme-label">网盘同步: <div class="config-itme-label">网盘同步:
<el-button class="sync-button" size="mini" :loading="syncLoading" type="primary" @click="sync()"><i <el-button class="sync-button" size="mini" :loading="syncLoading" type="primary" @click="sync()"><i
class="el-icon-refresh"></i></el-button> class="el-icon-refresh"></i>
</el-button> <span v-show="syncPercent < 100">{{syncPercent}}%</span>
</div> </div>
<span class="instruction">一般用于初始化操作, 将文件数据同步到数据库</span> <span class="instruction">一般用于初始化操作, 将文件数据同步到数据库</span>
<div class="config-itme-label">重置角色、菜单: <div class="config-itme-label">重置角色、菜单:
@ -68,6 +69,7 @@ export default {
uploadUrl: `${process.env.VUE_APP_BASE_API}/user/setting/upload_logo?jmal-token=${this.$store.state.user.token}&name=${this.$store.state.user.name}`, uploadUrl: `${process.env.VUE_APP_BASE_API}/user/setting/upload_logo?jmal-token=${this.$store.state.user.token}&name=${this.$store.state.user.name}`,
title: '网盘管理', title: '网盘管理',
syncLoading: false, syncLoading: false,
syncPercent: 100,
resetLoading: false, resetLoading: false,
webpEnabled: false, webpEnabled: false,
logoFileName: '', logoFileName: '',
@ -81,8 +83,11 @@ export default {
this.getWebsiteSetting() this.getWebsiteSetting()
this.getInfo() this.getInfo()
this.getIsSync() this.getIsSync()
Bus.$on('msg/synced', () => { Bus.$on('msg/synced', (msg) => {
this.syncLoading = false this.syncPercent = msg.body
if (this.syncPercent >= 100) {
this.syncLoading = false
}
}) })
}, },
destroyed() { destroyed() {
@ -162,8 +167,10 @@ export default {
}) })
}, },
getIsSync() { getIsSync() {
settingApi.isSync().then((res) => { settingApi.isSync({username: this.$store.state.user.name}).then((res) => {
this.syncLoading = res.data this.syncLoading = true;
this.syncPercent = res.data
this.syncLoading = this.syncPercent < 100;
}) })
}, },
sync() { sync() {
@ -173,6 +180,7 @@ export default {
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
this.syncLoading = true this.syncLoading = true
this.syncPercent = 0
settingApi.sync({username: this.$store.state.user.name}).then(() => { settingApi.sync({username: this.$store.state.user.name}).then(() => {
this.$message.success("开始同步...") this.$message.success("开始同步...")
}) })

View File

@ -50,6 +50,7 @@ function connect(username,token){
export function disconnect() { export function disconnect() {
if (ws.isConnected) { if (ws.isConnected) {
ws.stompClient.disconnect(); ws.stompClient.disconnect();
ws.isConnected = false
} }
clearInterval(ws.timer); clearInterval(ws.timer)
} }