1. 优化更新后刷新页面

This commit is contained in:
ngfchl
2022-08-30 13:42:16 +08:00
parent 431a1b30e8
commit 90b18d4f48
2 changed files with 109 additions and 107 deletions

View File

@@ -165,14 +165,16 @@ def restart_container(request):
# res = scraper.get('https://gitee.com/ngfchl/ptools/raw/master/update.md')
# update_md = markdown.markdown(res.text, extensions=['tables'])
# 获取docker对象
client = docker.from_env()
# 从内部获取容器id
cid = socket.gethostname()
started_at = client.api.inspect_container(cid).get('State').get('StartedAt')[:19]
UTC_FORMAT = "%Y-%m-%dT%H:%M:%S"
utc_time = datetime.strptime(started_at, UTC_FORMAT)
delta = datetime.now() - utc_time
try:
client = docker.from_env()
# 从内部获取容器id
cid = socket.gethostname()
started_at = client.api.inspect_container(cid).get('State').get('StartedAt')[:19]
UTC_FORMAT = "%Y-%m-%dT%H:%M:%S"
utc_time = datetime.strptime(started_at, UTC_FORMAT)
delta = (datetime.now() - utc_time).seconds
except Exception as e:
delta = ''
if get_update_logs():
update = 'false'
update_tips = '目前您使用的是最新版本!'
@@ -181,7 +183,7 @@ def restart_container(request):
update_tips = '已有新版本,请根据需要升级!'
return render(request, 'auto_pt/restart.html',
context={
'delta': delta.seconds,
'delta': delta,
'local_logs': get_git_logs(),
'update_notes': get_git_logs(master='origin/master'),
'update': update,

View File

@@ -16,11 +16,12 @@
width="200"
trigger="hover"
content="如果遇到无法更新的情况,您可以选择重建容器或者进入容器命令行到项目根目录执行`git pull`命令!">
<el-link slot="reference" type="success">{{ update_tips }} + <span>启动时间:{{ delta }}</span></el-link>
<el-link slot="reference"
type="success">{{ update_tips }} + <span>启动时间:{{ delta }}</span></el-link>
</el-popover>
</span>
<span style="float: right;margin-top: -10px">
{# <el-button type="primary" @click="get_update">获取更新</el-button>#}
{# <el-button type="primary" @click="do_refresh">刷新页面</el-button>#}
<el-button type="success" @click="do_update" v-if="update">更新</el-button>
<el-button type="danger" @click="do_restart">重启</el-button>
</span>
@@ -28,9 +29,9 @@
<div class="text item">
<el-row>
<el-card class="box-card">
<ul v-for="o in update_log" :key="o" class="text item">
<li v-html="o"></li>
</ul>
<ul v-for="o in update_log" :key="o" class="text item">
<li v-html="o"></li>
</ul>
</el-card>
</el-row>
<el-row>
@@ -98,107 +99,106 @@
el: '#app',
data: {
update_notes: {{ update_notes | safe }},
local_logs: {{ local_logs | safe }} ,
local_logs: {{ local_logs | safe }},
local_log: [],
update_log:[],
update: false,
local_log_width:24,
},
created()
{
this.update = {{ update }}
if (this.update) {
this.local_log_width = 12
}
this.$message({
showClose: true,
message: "{{ update_tips }}",
type: 'success'
});
}
,
methods: {
do_restart()
{
this.$confirm('此操作将重启容器,并更新软件, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
axios.get(
"{% url "do_restart" %}"
).then(res => {
if (res.data.code === 0) {
this.$message({
type: 'success',
message: res.data.msg
});
} else {
console.log(res)
this.$message({
type: 'warning',
message: res.data.msg
});
}
this.reload()
}).catch(res => {
this.$message({
type: 'error',
message: "重启失败!"
});
})
}).catch(res => {
{#console.log(res)#}
this.$message({
type: 'info',
message: '已取消重启'
});
});
update_log: [],
update: {{ update }},
local_log_width: 24,
},
created() {
do_update()
{
this.$confirm('此操作会拉取软件更新软件,新版本不一定稳定,是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
axios.get(
"{% url "do_update" %}"
).then(res => {
if (res.data.code === 0) {
console.log(res, 1)
this.update_log = res.data.data
if (this.update) {
this.local_log_width = 12
}
this.$message({
showClose: true,
message: "{{ update_tips }}",
type: 'success'
});
}
,
methods: {
do_refresh() {
},
do_restart() {
this.$confirm('此操作将重启容器,并更新软件, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
axios.get(
"{% url "do_restart" %}"
).then(res => {
if (res.data.code === 0) {
this.$message({
type: 'success',
message: res.data.msg
});
} else {
console.log(res)
this.$message({
type: 'warning',
message: res.data.msg
});
}
}).catch(res => {
this.$message({
type: 'error',
message: "重启失败!"
});
})
location.reload()
}).catch(res => {
{#console.log(res)#}
this.$message({
type: 'success',
message: res.data.msg
type: 'info',
message: '已取消重启'
});
} else {
console.log(res, 2)
});
},
do_update() {
this.$confirm('此操作会拉取软件更新软件,新版本不一定稳定,是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
axios.get(
"{% url "do_update" %}"
).then(res => {
if (res.data.code === 0) {
console.log(res, 1)
this.update_log = res.data.data
this.$message({
type: 'success',
message: res.data.msg
});
} else {
console.log(res, 2)
this.$message({
type: 'warning',
message: res.data.msg
});
}
}).catch(res => {
console.log(res, 3)
this.$message({
type: 'error',
message: "更新失败!"
});
})
location.reload()
}).catch(res => {
console.log(res)
this.$message({
type: 'warning',
message: res.data.msg
message: '已取消更新'
});
}
this.reload()
}).catch(res => {
console.log(res, 3)
this.$message({
type: 'error',
message: "更新失败!"
});
})
}).catch(res => {
console.log(res)
this.$message({
type: 'warning',
message: '已取消更新'
});
});
}
}
}
}
});
</script>