perf: 客户端更新提示

This commit is contained in:
kuaifan 2022-01-13 23:55:07 +08:00
parent 18e9fb99b5
commit e730875db3

View File

@ -1,5 +1,5 @@
<template> <template>
<div v-if="showButton" class="common-app-down" :class="{'on-client': $Electron}" :data-route="$route.name"> <div v-if="showButton" class="common-app-down" :class="{'on-client': !!$Electron}" :data-route="$route.name">
<div v-if="$Electron" class="common-app-down-link" @click="releasesNotification"> <div v-if="$Electron" class="common-app-down-link" @click="releasesNotification">
<Icon type="md-download"/> {{$L(repoTitle)}} <Icon type="md-download"/> {{$L(repoTitle)}}
</div> </div>
@ -15,18 +15,22 @@ import MarkdownPreview from "./MDEditor/components/preview";
import axios from "axios"; import axios from "axios";
Vue.component('MarkdownPreview', MarkdownPreview) Vue.component('MarkdownPreview', MarkdownPreview)
import { Notification } from 'element-ui'; import {Store} from "le5le-store";
export default { export default {
name: 'AppDown', name: 'AppDown',
data() { data() {
return { return {
loadIng: 0,
repoName: 'kuaifan/dootask', repoName: 'kuaifan/dootask',
repoData: {}, repoData: {},
status: 0, // 0 12 status: 0, // 0 12
releases: {}, releases: {},
downInfo: {} downInfo: {},
websocketOpenSubscribe: null
} }
}, },
mounted() { mounted() {
@ -40,6 +44,14 @@ export default {
} }
}) })
} }
//
this.websocketOpenSubscribe = Store.subscribe('websocketOpen', this.getReleases);
},
destroyed() {
if (this.websocketOpenSubscribe) {
this.websocketOpenSubscribe.unsubscribe();
this.websocketOpenSubscribe = null;
}
}, },
computed: { computed: {
repoTitle() { repoTitle() {
@ -98,6 +110,9 @@ export default {
if (this.status > 0) { if (this.status > 0) {
return; return;
} }
if (this.loadIng > 0) {
return;
}
// //
let cache = $A.getStorageJson("cacheAppdown"); let cache = $A.getStorageJson("cacheAppdown");
let timeout = 1800; let timeout = 1800;
@ -107,21 +122,21 @@ export default {
return; return;
} }
// //
;(() => { this.loadIng++;
axios axios.get("https://api.github.com/repos/" + this.repoName + "/releases/latest").then(({status, data}) => {
.get("https://api.github.com/repos/" + this.repoName + "/releases/latest") this.loadIng--;
.then(({status, data}) => { if (status === 200) {
if (status === 200) { $A.setStorage("cacheAppdown", {
$A.setStorage("cacheAppdown", { time: Math.round(new Date().getTime() / 1000),
time: Math.round(new Date().getTime() / 1000), data: data
data: data
});
this.releases = data;
this.chackReleases();
setTimeout(this.getReleases, timeout)
}
}); });
})(); this.releases = data;
this.chackReleases();
setTimeout(this.getReleases, timeout)
}
}).catch(() => {
this.loadIng--;
});
}, },
chackReleases() { chackReleases() {
@ -171,50 +186,38 @@ export default {
if (this.downInfo.state != "completed") { if (this.downInfo.state != "completed") {
return; return;
} }
const h = this.$createElement; $A.modalConfirm({
window.__appNotification && window.__appNotification.close(); okText: this.$L('立即更新'),
window.__appNotification = Notification({ onOk: () => {
title: this.$L("更新提示"), this.installApplication();
duration: 0, },
position: "bottom-right", onCancel: () => {
customClass: "common-app-down-notification",
onClose: () => {
this.status = 2; this.status = 2;
}, },
message: h('span', [ render: (h) => {
h('span', [ return h('div', {
h('span', this.$L('发现新版本') + ": "), class: 'common-app-down-notification'
h('Tag', {
props: {
color: 'volcano'
}
}, this.releases.tag_name)
]),
h('MarkdownPreview', {
class: 'common-app-down-body',
props: {
initialValue: this.releases.body
}
}),
h('div', {
class: 'common-app-down-link',
on: {
click: () => {
this.installApplication();
}
},
}, [ }, [
h('Icon', { h('div', {
class: "notification-head"
}, [
h('div', {
class: "notification-title"
}, this.$L('发现新版本')),
h('Tag', {
props: {
color: 'volcano'
}
}, this.releases.tag_name)
]),
h('MarkdownPreview', {
class: 'notification-body overlay-y',
props: { props: {
type: 'md-checkmark-circle-outline' initialValue: this.releases.body
},
style: {
marginRight: '5px'
} }
}), }),
h('span', this.$L('立即更新')) ])
]), }
])
}); });
}, },