feature: 启用/禁用 “远程配置” 时,自动加载配置并重启代理服务和系统代理。
parent
129da218f6
commit
925c20501a
|
@ -124,18 +124,24 @@ const configApi = {
|
||||||
defConfig = mergeApi.doMerge(defConfig, configApi.readRemoteConfig())
|
defConfig = mergeApi.doMerge(defConfig, configApi.readRemoteConfig())
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算新配置与默认配置(启用远程配置时,含远程配置)的差异,并保存到 config.json5 中
|
// 计算新配置与默认配置(启用远程配置时,含远程配置)的差异,并保存到 config.json 中
|
||||||
const diffConfig = mergeApi.doDiff(defConfig, newConfig)
|
const diffConfig = mergeApi.doDiff(defConfig, newConfig)
|
||||||
const configPath = _getConfigPath()
|
const configPath = _getConfigPath()
|
||||||
fs.writeFileSync(configPath, JSON.stringify(diffConfig, null, '\t'))
|
fs.writeFileSync(configPath, JSON.stringify(diffConfig, null, '\t'))
|
||||||
log.info('保存自定义配置文件成功:', configPath)
|
log.info('保存自定义配置文件成功:', configPath)
|
||||||
configApi.reload()
|
|
||||||
return diffConfig
|
// 重载配置
|
||||||
|
const allConfig = configApi.reload()
|
||||||
|
|
||||||
|
return {
|
||||||
|
diffConfig,
|
||||||
|
allConfig
|
||||||
|
}
|
||||||
},
|
},
|
||||||
doMerge: mergeApi.doMerge,
|
doMerge: mergeApi.doMerge,
|
||||||
doDiff: mergeApi.doDiff,
|
doDiff: mergeApi.doDiff,
|
||||||
/**
|
/**
|
||||||
* 读取 config.json5 后,合并配置
|
* 读取 config.json 后,合并配置
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
reload () {
|
reload () {
|
||||||
|
|
|
@ -190,7 +190,7 @@ export default {
|
||||||
},
|
},
|
||||||
doSave () {
|
doSave () {
|
||||||
return api.config.save(this.targetConfig).then(ret => {
|
return api.config.save(this.targetConfig).then(ret => {
|
||||||
this.$emit('change', ret)
|
this.$emit('change', ret.diffConfig)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
deleteDnsMapping (item, index) {
|
deleteDnsMapping (item, index) {
|
||||||
|
|
|
@ -7,6 +7,7 @@ export default {
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
|
key: undefined,
|
||||||
config: undefined,
|
config: undefined,
|
||||||
status: {},
|
status: {},
|
||||||
labelCol: { span: 4 },
|
labelCol: { span: 4 },
|
||||||
|
@ -31,10 +32,10 @@ export default {
|
||||||
this.status = this.$status
|
this.status = this.$status
|
||||||
|
|
||||||
const config = await this.$api.config.reload()
|
const config = await this.$api.config.reload()
|
||||||
this.$set(this, 'config', config)
|
this.setConfig(config)
|
||||||
this.systemPlatform = await this.$api.info.getSystemPlatform()
|
this.systemPlatform = await this.$api.info.getSystemPlatform()
|
||||||
console.log('config', this.config, this.systemPlatform)
|
|
||||||
// eslint-disable-next-line no-debugger
|
this.printConfig()
|
||||||
|
|
||||||
if (this.ready) {
|
if (this.ready) {
|
||||||
return this.ready(this.config)
|
return this.ready(this.config)
|
||||||
|
@ -74,8 +75,11 @@ export default {
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
saveConfig () {
|
saveConfig () {
|
||||||
return this.$api.config.save(this.config).then(() => {
|
return this.$api.config.save(this.config).then((ret) => {
|
||||||
this.$message.info('设置已保存')
|
this.$message.info('设置已保存')
|
||||||
|
this.setConfig(ret.allConfig)
|
||||||
|
this.printConfig('after saveConfig(), ')
|
||||||
|
return ret
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
getConfig (key) {
|
getConfig (key) {
|
||||||
|
@ -85,6 +89,12 @@ export default {
|
||||||
}
|
}
|
||||||
return value
|
return value
|
||||||
},
|
},
|
||||||
|
setConfig (newConfig) {
|
||||||
|
this.$set(this, 'config', newConfig)
|
||||||
|
},
|
||||||
|
printConfig (prefix = '') {
|
||||||
|
console.log(`${prefix}${this.key} page config:`, this.config, this.systemPlatform)
|
||||||
|
},
|
||||||
getStatus (key) {
|
getStatus (key) {
|
||||||
const value = lodash.get(this.status, key)
|
const value = lodash.get(this.status, key)
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
|
|
|
@ -100,9 +100,17 @@ export default {
|
||||||
this.$api.autoStart.enabled(this.config.app.autoStart.enabled)
|
this.$api.autoStart.enabled(this.config.app.autoStart.enabled)
|
||||||
this.saveConfig()
|
this.saveConfig()
|
||||||
},
|
},
|
||||||
onRemoteConfigEnabledChange () {
|
async onRemoteConfigEnabledChange () {
|
||||||
this.saveConfig()
|
this.saveConfig()
|
||||||
this.$message.info('请重启加速服务')
|
if (this.config.app.remoteConfig.enabled === true) {
|
||||||
|
await this.$api.config.startAutoDownloadRemoteConfig()
|
||||||
|
} else {
|
||||||
|
this.$api.config.reload()
|
||||||
|
}
|
||||||
|
if (this.status.server.enabled || this.status.proxy.enabled) {
|
||||||
|
await this.$api.proxy.restart()
|
||||||
|
this.$api.server.restart()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue