optimize: `日志文件保存目录` 可对话框选择了,另外,优化了文件选择框的参数,默认打开当前文件所在文件夹。
parent
da0695e1f0
commit
5d96a019b8
|
@ -3,10 +3,12 @@ export default {
|
|||
const { ipcMain, dialog, log } = context
|
||||
ipcMain.on('file-selector', (event, message) => {
|
||||
if (message.key === 'open') {
|
||||
dialog.showOpenDialog({
|
||||
properties: ['openFile'],
|
||||
...message,
|
||||
}).then((result) => {
|
||||
const options = message.options || {}
|
||||
if (options.properties == null || options.properties.length === 0) {
|
||||
options.properties = ['openFile']
|
||||
}
|
||||
|
||||
dialog.showOpenDialog(options).then((result) => {
|
||||
if (result.canceled) {
|
||||
event.sender.send('file-selector', { key: 'canceled' })
|
||||
} else {
|
||||
|
@ -14,6 +16,7 @@ export default {
|
|||
}
|
||||
}).catch((err) => {
|
||||
log.error('选择文件失败:', err)
|
||||
event.sender.send('file-selector', { key: 'error', error: err })
|
||||
})
|
||||
}
|
||||
})
|
||||
|
|
|
@ -1,14 +1,55 @@
|
|||
function install (app, api) {
|
||||
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) => {
|
||||
api.ipc.send('file-selector', { key: 'open', value, ...options })
|
||||
api.ipc.send('file-selector', { key: 'open', options })
|
||||
api.ipc.on('file-selector', (event, message) => {
|
||||
console.log('selector', message)
|
||||
if (message.key === 'selected') {
|
||||
resolve(message.value)
|
||||
} else if (message.key === 'canceled') {
|
||||
resolve('') // 没有选择文件
|
||||
} else if (message.key === 'error') {
|
||||
reject(message.error)
|
||||
} else {
|
||||
reject(new Error('没有选择文件'))
|
||||
reject(new Error('未知的响应'))
|
||||
}
|
||||
api.ipc.on('file-selector', () => {})
|
||||
})
|
||||
|
|
|
@ -39,13 +39,13 @@ export default {
|
|||
},
|
||||
methods: {
|
||||
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) {
|
||||
this.config.server.setting.rootCaFile.certPath = value[0]
|
||||
}
|
||||
},
|
||||
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) {
|
||||
this.config.server.setting.rootCaFile.keyPath = value[0]
|
||||
}
|
||||
|
|
|
@ -321,6 +321,12 @@ export default {
|
|||
}
|
||||
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>
|
||||
|
@ -470,7 +476,11 @@ export default {
|
|||
</a-form-item>
|
||||
<hr>
|
||||
<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">
|
||||
修改后,重启DS才生效!<br>
|
||||
注意:原目录中的文件不会自动转移到新的目录,请自行转移或删除。
|
||||
|
|
Loading…
Reference in New Issue