diff --git a/public/i18n/en.yml b/public/i18n/en.yml index 02bc69f..966f034 100644 --- a/public/i18n/en.yml +++ b/public/i18n/en.yml @@ -109,6 +109,9 @@ SETTINGS_SET_DEFAULT_PICBED: Set Default Picbed SETTINGS_NOT_CONFIG_OPTIONS: Not Config Options SETTINGS_USE_BUILTIN_CLIPBOARD_UPLOAD: Use Builtin Clipboard to Upload SETTINGS_CHOOSE_LANGUAGE: Choose Language +UPLOADER_CONFIG_NAME: Configuration Name +UPLOADER_CONFIG_PLACEHOLDER: Please Enter Configuration Name +SELECTED_SETTING_HINT: Selected # shortcut-page diff --git a/public/i18n/zh-CN.yml b/public/i18n/zh-CN.yml index 9e32884..4ac67da 100644 --- a/public/i18n/zh-CN.yml +++ b/public/i18n/zh-CN.yml @@ -110,6 +110,9 @@ SETTINGS_NOT_CONFIG_OPTIONS: 暂无配置项 SETTINGS_USE_BUILTIN_CLIPBOARD_UPLOAD: 使用内置剪贴板上传 SETTINGS_CHOOSE_LANGUAGE: 选择语言 BUILTIN_CLIPBOARD_TIPS: 使用内置剪贴板函数而不是调用脚本获取剪贴板图片 +UPLOADER_CONFIG_NAME: 图床配置名 +UPLOADER_CONFIG_PLACEHOLDER: 请输入配置名称 +SELECTED_SETTING_HINT: 已选中 # shortcut-page diff --git a/public/i18n/zh-TW.yml b/public/i18n/zh-TW.yml index 1d702f8..0a242af 100644 --- a/public/i18n/zh-TW.yml +++ b/public/i18n/zh-TW.yml @@ -110,6 +110,9 @@ SETTINGS_NOT_CONFIG_OPTIONS: 暫無設定選項 SETTINGS_USE_BUILTIN_CLIPBOARD_UPLOAD: 使用內建剪貼簿上傳 SETTINGS_CHOOSE_LANGUAGE: 選擇語言 BUILTIN_CLIPBOARD_TIPS: 使用內建剪貼簿函數而不是調用腳本取得剪貼簿內的照片 +UPLOADER_CONFIG_NAME: 圖床配置名 +UPLOADER_CONFIG_PLACEHOLDER: 請輸入配置名稱 +SELECTED_SETTING_HINT: 已選中 # shortcut-page diff --git a/src/renderer/components/ConfigForm.vue b/src/renderer/components/ConfigForm.vue index 9b5bc55..234f3bc 100644 --- a/src/renderer/components/ConfigForm.vue +++ b/src/renderer/components/ConfigForm.vue @@ -7,6 +7,18 @@ ref="form" size="mini" > + + + + (this.getConfigType()) + const config = await this.getCurConfigFormData() + const configId = this.$route.params.configId + this.ruleForm = Object.assign({}, config) if (val.length > 0) { this.configList = cloneDeep(val).map((item) => { + if (!configId) return item let defaultValue = item.default !== undefined ? item.default : item.type === 'checkbox' @@ -138,6 +152,12 @@ export default class extends Vue { }) } } + + async getCurConfigFormData () { + const configId = this.$route.params.configId + const curTypeConfigList = await this.getConfig(`uploader.${this.id}.configList`) || [] + return curTypeConfigList.find(i => i._id === configId) || {} + } } diff --git a/src/renderer/pages/picbeds/index.vue b/src/renderer/pages/picbeds/index.vue index b8b4dd9..f9d9623 100644 --- a/src/renderer/pages/picbeds/index.vue +++ b/src/renderer/pages/picbeds/index.vue @@ -1,7 +1,7 @@ - - + + {{ picBedName }} {{ $T('SETTINGS') }} @@ -13,15 +13,11 @@ :id="type" > - - {{ $T('CONFIRM') }} - {{ $T('SETTINGS_SET_DEFAULT_PICBED') }} - + {{ $T('CONFIRM') }} {{ $T('SETTINGS_NOT_CONFIG_OPTIONS') }} - {{ $T('SETTINGS_SET_DEFAULT_PICBED') }} @@ -35,6 +31,7 @@ import { ipcRenderer, IpcRendererEvent } from 'electron' +import { completeUploaderMetaConfig } from '@/utils/uploader' import { trimValues } from '@/utils/common' @Component({ @@ -58,15 +55,36 @@ export default class extends Vue { // @ts-ignore const result = await this.$refs.configForm.validate() if (result !== false) { - this.saveConfig({ - [`picBed.${this.type}`]: trimValues(result) - }) + const configListConfigPath = `uploader.${this.type}.configList` + const configList = await this.getConfig(configListConfigPath) + // Finds the specified item from the config array and modifies it + const existItem = configList?.find(item => item._id === result._id) + // edit + if (existItem) { + Object.assign(existItem, trimValues(result), { + _updatedAt: Date.now() + }) + } else { // add new + configList?.push(trimValues(completeUploaderMetaConfig(result))) + } + + await this.saveConfig(configListConfigPath, configList) + existItem && await this.shouldUpdateDefaultConfig(existItem) + const successNotification = new Notification(this.$T('SETTINGS_RESULT'), { body: this.$T('TIPS_SET_SUCCEED') }) successNotification.onclick = () => { return true } + this.$router.back() + } + } + + shouldUpdateDefaultConfig (item: IStringKeyMap) { + const curDefaultConfigId = this.$route.query.defaultConfigId + if (item._id === curDefaultConfigId) { + this.saveConfig(`picBed.${this.type}`, item) } } @@ -101,6 +119,8 @@ export default class extends Vue { height 425px overflow-y auto overflow-x hidden + .confirm-btn + width: 250px .el-form label line-height 22px diff --git a/src/renderer/router/index.ts b/src/renderer/router/index.ts index dd8d332..8ac21eb 100644 --- a/src/renderer/router/index.ts +++ b/src/renderer/router/index.ts @@ -32,7 +32,7 @@ export default new Router({ name: 'upload' }, { - path: 'picbeds/:type', + path: 'picbeds/:type/:configId', component: () => import(/* webpackChunkName: "Other" */ '@/pages/picbeds/index.vue'), name: 'picbeds' }, @@ -58,6 +58,11 @@ export default new Router({ path: 'shortKey', component: () => import(/* webpackChunkName: "ShortkeyPage" */ '@/pages/ShortKey.vue'), name: 'shortKey' + }, + { + path: 'uploader-config-page/:type', + component: () => import(/* webpackChunkName: "Other" */ '@/pages/UploaderConfigPage.vue'), + name: 'UploaderConfigPage' } ] }, diff --git a/src/renderer/utils/uploader.ts b/src/renderer/utils/uploader.ts new file mode 100644 index 0000000..8e23663 --- /dev/null +++ b/src/renderer/utils/uploader.ts @@ -0,0 +1,11 @@ +import { uuid } from 'uuidv4' + +export const completeUploaderMetaConfig = (originData: IStringKeyMap): IStringKeyMap => { + return Object.assign({ + _configName: 'Default' + }, originData, { + _id: uuid(), + _createdAt: Date.now(), + _updatedAt: Date.now() + }) +} diff --git a/src/universal/types/i18n.d.ts b/src/universal/types/i18n.d.ts index 6c56485..69261fd 100644 --- a/src/universal/types/i18n.d.ts +++ b/src/universal/types/i18n.d.ts @@ -105,6 +105,9 @@ interface ILocales { SETTINGS_USE_BUILTIN_CLIPBOARD_UPLOAD: string SETTINGS_CHOOSE_LANGUAGE: string BUILTIN_CLIPBOARD_TIPS: string + UPLOADER_CONFIG_NAME: string + UPLOADER_CONFIG_PLACEHOLDER: string + SELECTED_SETTING_HINT: string SHORTCUT_NAME: string SHORTCUT_BIND: string SHORTCUT_STATUS: string