optimize: `日志文件保存目录` 可对话框选择了,另外,优化了文件选择框的参数,默认打开当前文件所在文件夹。
parent
da0695e1f0
commit
5d96a019b8
|
|
@ -3,10 +3,12 @@ export default {
|
||||||
const { ipcMain, dialog, log } = context
|
const { ipcMain, dialog, log } = context
|
||||||
ipcMain.on('file-selector', (event, message) => {
|
ipcMain.on('file-selector', (event, message) => {
|
||||||
if (message.key === 'open') {
|
if (message.key === 'open') {
|
||||||
dialog.showOpenDialog({
|
const options = message.options || {}
|
||||||
properties: ['openFile'],
|
if (options.properties == null || options.properties.length === 0) {
|
||||||
...message,
|
options.properties = ['openFile']
|
||||||
}).then((result) => {
|
}
|
||||||
|
|
||||||
|
dialog.showOpenDialog(options).then((result) => {
|
||||||
if (result.canceled) {
|
if (result.canceled) {
|
||||||
event.sender.send('file-selector', { key: 'canceled' })
|
event.sender.send('file-selector', { key: 'canceled' })
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -14,6 +16,7 @@ export default {
|
||||||
}
|
}
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
log.error('选择文件失败:', err)
|
log.error('选择文件失败:', err)
|
||||||
|
event.sender.send('file-selector', { key: 'error', error: err })
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,55 @@
|
||||||
function install (app, api) {
|
function install (app, api) {
|
||||||
api.fileSelector = {
|
api.fileSelector = {
|
||||||
open (value, options) {
|
|
||||||
|
/**
|
||||||
|
* 打开文件选择框
|
||||||
|
*
|
||||||
|
* 支持传参方式:
|
||||||
|
* 1. open(String defaultPath)
|
||||||
|
* 2. open(String defaultPath, String properties)
|
||||||
|
* 3. open(null, String properties)
|
||||||
|
* 4. open(String defaultPath, Object options)
|
||||||
|
* 5. open(Object options)
|
||||||
|
*
|
||||||
|
* @param value
|
||||||
|
* @param {Electron.OpenDialogOptions} options
|
||||||
|
* @returns {Promise<unknown>} promise
|
||||||
|
*/
|
||||||
|
open (value = null, options = null) {
|
||||||
|
if (options == null && value && typeof value !== 'string') {
|
||||||
|
options = { ...value }
|
||||||
|
value = null
|
||||||
|
} else {
|
||||||
|
if (typeof options === 'string') {
|
||||||
|
if (options === 'dir') {
|
||||||
|
options = 'openDirectory'
|
||||||
|
} else if (options === 'file') {
|
||||||
|
options = 'openFile'
|
||||||
|
}
|
||||||
|
|
||||||
|
options = { properties: [options] } // options 为字符串时,视为 properties 属性的值
|
||||||
|
} else {
|
||||||
|
options = options || {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果没有 defaultPath,则使用 value 作为 defaultPath
|
||||||
|
if (!options.defaultPath && value && typeof value === 'string') {
|
||||||
|
options.defaultPath = value
|
||||||
|
}
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
api.ipc.send('file-selector', { key: 'open', value, ...options })
|
api.ipc.send('file-selector', { key: 'open', options })
|
||||||
api.ipc.on('file-selector', (event, message) => {
|
api.ipc.on('file-selector', (event, message) => {
|
||||||
console.log('selector', message)
|
console.log('selector', message)
|
||||||
if (message.key === 'selected') {
|
if (message.key === 'selected') {
|
||||||
resolve(message.value)
|
resolve(message.value)
|
||||||
|
} else if (message.key === 'canceled') {
|
||||||
|
resolve('') // 没有选择文件
|
||||||
|
} else if (message.key === 'error') {
|
||||||
|
reject(message.error)
|
||||||
} else {
|
} else {
|
||||||
reject(new Error('没有选择文件'))
|
reject(new Error('未知的响应'))
|
||||||
}
|
}
|
||||||
api.ipc.on('file-selector', () => {})
|
api.ipc.on('file-selector', () => {})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -39,13 +39,13 @@ export default {
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async onCrtSelect () {
|
async onCrtSelect () {
|
||||||
const value = await this.$api.fileSelector.open()
|
const value = await this.$api.fileSelector.open(this.config.server.setting.rootCaFile.certPath, 'file')
|
||||||
if (value != null && value.length > 0) {
|
if (value != null && value.length > 0) {
|
||||||
this.config.server.setting.rootCaFile.certPath = value[0]
|
this.config.server.setting.rootCaFile.certPath = value[0]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async onKeySelect () {
|
async onKeySelect () {
|
||||||
const value = await this.$api.fileSelector.open()
|
const value = await this.$api.fileSelector.open(this.config.server.setting.rootCaFile.keyPath, 'file')
|
||||||
if (value != null && value.length > 0) {
|
if (value != null && value.length > 0) {
|
||||||
this.config.server.setting.rootCaFile.keyPath = value[0]
|
this.config.server.setting.rootCaFile.keyPath = value[0]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -321,6 +321,12 @@ export default {
|
||||||
}
|
}
|
||||||
this.$refs.maxLogFileSize.focus()
|
this.$refs.maxLogFileSize.focus()
|
||||||
},
|
},
|
||||||
|
async onLogFileSavePathSelect () {
|
||||||
|
const value = await this.$api.fileSelector.open(this.config.app.logFileSavePath, 'dir')
|
||||||
|
if (value != null && value.length > 0) {
|
||||||
|
this.config.app.logFileSavePath = value[0]
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
@ -470,7 +476,11 @@ export default {
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
<hr>
|
<hr>
|
||||||
<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.logFileSavePath" />
|
<a-input-search
|
||||||
|
v-model="config.app.logFileSavePath" enter-button="选择"
|
||||||
|
:title="config.app.logFileSavePath"
|
||||||
|
@search="onLogFileSavePathSelect"
|
||||||
|
/>
|
||||||
<div class="form-help">
|
<div class="form-help">
|
||||||
修改后,重启DS才生效!<br>
|
修改后,重启DS才生效!<br>
|
||||||
注意:原目录中的文件不会自动转移到新的目录,请自行转移或删除。
|
注意:原目录中的文件不会自动转移到新的目录,请自行转移或删除。
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue