Support check update method.

pull/3445/head
ruibaby 2019-08-27 16:52:32 +08:00
parent a6b8dcaa65
commit ab390983a7
2 changed files with 67 additions and 20 deletions

View File

@ -29,7 +29,7 @@
showTime
:defaultValue="pickerDefaultValue"
format="YYYY-MM-DD HH:mm:ss"
placeholder="Select Publish Time"
placeholder="选择页面发表时间"
@change="onSheetDateChange"
@ok="onSheetDateOk"
/>

View File

@ -39,7 +39,7 @@
</a-button>
</a-popconfirm>
<ul>
<ul style="margin: 0;padding: 0;list-style: none;">
<li>Server 版本{{ environments.version }}</li>
<li>Admin 版本{{ adminVersion }}</li>
<li>数据库{{ environments.database }}</li>
@ -50,16 +50,19 @@
<a
href="https://github.com/halo-dev"
target="_blank"
style="margin-right: 10px;"
>开源地址
<a-icon type="link" /></a>
<a
href="https://halo.run/guide"
target="_blank"
style="margin-right: 10px;"
>用户文档
<a-icon type="link" /></a>
<a
href="https://bbs.halo.run"
target="_blank"
style="margin-right: 10px;"
>在线社区
<a-icon type="link" /></a>
</a-card>
@ -107,6 +110,7 @@
<script>
import adminApi from '@/api/admin'
import axios from 'axios'
export default {
data() {
return {
@ -199,6 +203,7 @@ export default {
},
created() {
this.getEnvironments()
this.checkUpdate()
},
computed: {
updateText() {
@ -229,7 +234,8 @@ export default {
const text = `Server 版本:${this.environments.version}
Admin 版本${this.adminVersion}
数据库${this.environments.database}
运行模式${this.environments.mode}`
运行模式${this.environments.mode}
UA 信息${navigator.userAgent}`
this.$copyText(text)
.then(message => {
console.log('copy', message)
@ -239,25 +245,66 @@ Admin 版本:${this.adminVersion}
console.log('copy.err', err)
this.$message.error('复制失败!')
})
},
async checkUpdate() {
const _this = this
axios
.get('https://api.github.com/repos/halo-dev/halo/releases/latest')
.then(response => {
const data = response.data
if (data.draft || data.prerelease) {
return
}
const current = _this.calculateIntValue(_this.environments.version)
const latest = _this.calculateIntValue(data.name)
if (current >= latest) {
return
}
const title = '新版本提醒'
const content = '检测到新版本:' + data.name + ',点击下方按钮下载最新版本。'
const url = data.html_url
this.$notification.open({
message: title,
description: content,
icon: <a-icon type="smile" style="color: #108ee9" />,
btn: h => {
return h(
'a-button',
{
props: {
type: 'primary',
size: 'small'
},
on: {
click: () => window.open(url, '_blank')
}
},
'去看看'
)
}
})
})
.catch(function(error) {
console.error('Check update fail', error)
})
},
calculateIntValue(version) {
version = version.replace(/v/g, '')
const ss = version.split('.')
if (ss == null || ss.length !== 3) {
return -1
}
const major = parseInt(ss[0])
const minor = parseInt(ss[1])
const micro = parseInt(ss[2])
if (isNaN(major) || isNaN(minor) || isNaN(micro)) {
return -1
}
return major * 1000000 + minor * 1000 + micro
}
}
}
</script>
<style lang="less" scope>
ul {
margin: 0;
padding: 0;
list-style: none;
}
.environment-info {
ul {
margin: 0;
padding: 0;
list-style: none;
}
a {
margin-right: 10px;
}
}
<style lang="less">
</style>