添加 重载远程配置 按钮,方便获取新的远程配置。
parent
925c20501a
commit
61b6db8a94
|
@ -111,6 +111,25 @@ const configApi = {
|
||||||
|
|
||||||
return {}
|
return {}
|
||||||
},
|
},
|
||||||
|
readRemoteConfigStr () {
|
||||||
|
if (get().app.remoteConfig.enabled !== true) {
|
||||||
|
return '{}'
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const path = _getRemoteSavePath()
|
||||||
|
if (fs.existsSync(path)) {
|
||||||
|
log.info('读取远程配置文件内容:', path)
|
||||||
|
const file = fs.readFileSync(path)
|
||||||
|
return file.toString()
|
||||||
|
} else {
|
||||||
|
log.warn('远程配置文件不存在:', path)
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log.warn('远程配置内容读取失败:', e)
|
||||||
|
}
|
||||||
|
|
||||||
|
return '{}'
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* 保存自定义的 config
|
* 保存自定义的 config
|
||||||
* @param newConfig
|
* @param newConfig
|
||||||
|
|
|
@ -35,6 +35,13 @@
|
||||||
<a-form-item label="远程配置地址" :label-col="labelCol" :wrapper-col="wrapperCol">
|
<a-form-item label="远程配置地址" :label-col="labelCol" :wrapper-col="wrapperCol">
|
||||||
<a-input v-model="config.app.remoteConfig.url"></a-input>
|
<a-input v-model="config.app.remoteConfig.url"></a-input>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
|
<a-form-item label="重载远程配置" :label-col="labelCol" :wrapper-col="wrapperCol">
|
||||||
|
<a-button :disabled="config.app.remoteConfig.enabled === false" :loading="reloadLoading" icon="sync" @click="reloadRemoteConfig()">重载远程配置</a-button>
|
||||||
|
<div class="form-help">
|
||||||
|
注意,部分远程配置文件所在站点,修改内容后可能需要等待一段时间才能生效。
|
||||||
|
<br/>如果重载远程配置后发现下载的还是修改前的内容,请稍等片刻再重试。
|
||||||
|
</div>
|
||||||
|
</a-form-item>
|
||||||
<a-form-item label="首页提示" :label-col="labelCol" :wrapper-col="wrapperCol">
|
<a-form-item label="首页提示" :label-col="labelCol" :wrapper-col="wrapperCol">
|
||||||
<a-radio-group v-model="config.app.showShutdownTip"
|
<a-radio-group v-model="config.app.showShutdownTip"
|
||||||
default-value="true" button-style="solid">
|
default-value="true" button-style="solid">
|
||||||
|
@ -84,7 +91,8 @@ export default {
|
||||||
mixins: [Plugin],
|
mixins: [Plugin],
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
key: 'app'
|
key: 'app',
|
||||||
|
reloadLoading: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created () {
|
created () {
|
||||||
|
@ -100,17 +108,48 @@ export default {
|
||||||
this.$api.autoStart.enabled(this.config.app.autoStart.enabled)
|
this.$api.autoStart.enabled(this.config.app.autoStart.enabled)
|
||||||
this.saveConfig()
|
this.saveConfig()
|
||||||
},
|
},
|
||||||
async onRemoteConfigEnabledChange () {
|
async reloadAndRestart () {
|
||||||
this.saveConfig()
|
|
||||||
if (this.config.app.remoteConfig.enabled === true) {
|
|
||||||
await this.$api.config.startAutoDownloadRemoteConfig()
|
|
||||||
} else {
|
|
||||||
this.$api.config.reload()
|
this.$api.config.reload()
|
||||||
}
|
|
||||||
if (this.status.server.enabled || this.status.proxy.enabled) {
|
if (this.status.server.enabled || this.status.proxy.enabled) {
|
||||||
await this.$api.proxy.restart()
|
await this.$api.proxy.restart()
|
||||||
this.$api.server.restart()
|
await this.$api.server.restart()
|
||||||
|
this.$message.info('代理服务和系统代理重启成功')
|
||||||
|
} else {
|
||||||
|
this.$message.info('代理服务和系统代理未启动,无需重启')
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
async onRemoteConfigEnabledChange () {
|
||||||
|
await this.saveConfig()
|
||||||
|
if (this.config.app.remoteConfig.enabled === true) {
|
||||||
|
this.reloadLoading = true
|
||||||
|
this.$message.info('开始下载远程配置')
|
||||||
|
await this.$api.config.downloadRemoteConfig()
|
||||||
|
this.$message.info('下载远程配置成功,开始重启代理服务和系统代理')
|
||||||
|
await this.reloadAndRestart()
|
||||||
|
this.reloadLoading = false
|
||||||
|
} else {
|
||||||
|
this.$message.info('开始重启代理服务和系统代理')
|
||||||
|
await this.reloadAndRestart()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async reloadRemoteConfig () {
|
||||||
|
this.reloadLoading = true
|
||||||
|
|
||||||
|
const remoteConfig = {}
|
||||||
|
|
||||||
|
await this.$api.config.readRemoteConfigStr().then((ret) => { remoteConfig.old = ret })
|
||||||
|
await this.$api.config.downloadRemoteConfig()
|
||||||
|
await this.$api.config.readRemoteConfigStr().then((ret) => { remoteConfig.new = ret })
|
||||||
|
|
||||||
|
if (remoteConfig.old === remoteConfig.new) {
|
||||||
|
this.$message.info('远程配置没有变化,不做任何处理。')
|
||||||
|
this.$message.info('如果您确实修改了远程配置,请稍等片刻再重试!')
|
||||||
|
} else {
|
||||||
|
this.$message.info('获取到了最新的远程配置,开始重启代理服务和系统代理')
|
||||||
|
await this.reloadAndRestart()
|
||||||
|
}
|
||||||
|
|
||||||
|
this.reloadLoading = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue