Feature(config): add copy config \&\& add double confirm before copy \& delete config

This commit is contained in:
PiEgg
2025-12-27 17:17:35 +08:00
parent 840c33bfa5
commit 25f86a69e1
10 changed files with 88 additions and 12 deletions
+4 -1
View File
@@ -25,4 +25,7 @@ Place renderer unit specs in `test/unit/specs` with the `.spec.js` suffix; Karma
Commits follow the PicGo conventional preset enforced by Husky (`pnpm lint:dpdm` + Commitlint). Stage your changes and run `pnpm cz` to craft messages that pass CI. Pull requests should explain the change, link related issues, and attach UI screenshots or recordings. Note how you validated the work (dev server, build, Karma, Spectron) and call out migration or configuration steps reviewers must perform.
## Internationalization Tips
Add locales by creating `public/i18n/<locale>.yml`, exposing its `LANG_DISPLAY_LABEL`, and registering it in `src/universal/i18n/index.ts`. Finish with `pnpm gen-i18n` so the generated typings stay in sync.
Add locales by creating `public/i18n/<locale>.yml`, exposing its `LANG_DISPLAY_LABEL`, and registering it in `src/universal/i18n/index.ts`. After editing `public/i18n/*.yml`, run `pnpm gen-i18n` to regenerate TS typings and keep them in sync.
## Serena MCP & Context7 Tools
When starting work or if you hit issues, try checking MCP for Serena or Context7 tooling. If available, use those tools to navigate, edit, or fetch docs efficiently.
+2 -1
View File
@@ -248,6 +248,8 @@ TIPS_SHORTCUT_MODIFIED_SUCCEED: Shortcut modified successfully
TIPS_SHORTCUT_MODIFIED_CONFLICT: Shortcut conflict, please reset
TIPS_CUSTOM_LINK_STYLE_MODIFIED_SUCCEED: Custom link style modified successfully
TIPS_FIND_NEW_VERSION: Find new version ${v}update many new features, do you want to download the latest version?
TIPS_DELETE_UPLOADER_CONFIG: Are you sure you want to delete this config?
TIPS_COPY_UPLOADER_CONFIG: Are you sure you want to copy this config?
# privacy
PRIVACY: >
@@ -276,7 +278,6 @@ PRIVACY: >
b) In accordance with the relevant provisions of the law, or the requirements of administrative or judicial institutions, disclose to third parties or administrative or judicial institutions;
c) If you violate relevant Chinese laws, regulations or relevant rules, you need to disclose it to a third party;
4. Information Security
+2 -1
View File
@@ -248,6 +248,8 @@ TIPS_SHORTCUT_MODIFIED_SUCCEED: 快捷键已经修改成功
TIPS_SHORTCUT_MODIFIED_CONFLICT: 快捷键冲突,请重新设置
TIPS_CUSTOM_LINK_STYLE_MODIFIED_SUCCEED: 自定义链接格式已经修改成功
TIPS_FIND_NEW_VERSION: 发现新版本${v},更新了很多功能,是否去下载最新的版本?
TIPS_DELETE_UPLOADER_CONFIG: 是否要删除这个配置?
TIPS_COPY_UPLOADER_CONFIG: 是否要复制这个配置?
# privacy
PRIVACY: >
@@ -276,7 +278,6 @@ PRIVACY: >
b)根据法律的有关规定,或者行政或司法机构的要求,向第三方或者行政、司法机构披露;
c)如您出现违反中国有关法律、法规或者相关规则的情况,需要向第三方披露;
4.信息安全
+2 -1
View File
@@ -248,6 +248,8 @@ TIPS_SHORTCUT_MODIFIED_SUCCEED: 快捷鍵已經修改成功
TIPS_SHORTCUT_MODIFIED_CONFLICT: 快捷鍵衝突,請重新設定
TIPS_CUSTOM_LINK_STYLE_MODIFIED_SUCCEED: 自訂連結格式已經修改成功
TIPS_FIND_NEW_VERSION: 發現新版本${v},更新了很多功能,是否去下載最新的版本?
TIPS_DELETE_UPLOADER_CONFIG: 是否要刪除這個配置?
TIPS_COPY_UPLOADER_CONFIG: 是否要複製這個配置?
# privacy
PRIVACY: >
@@ -276,7 +278,6 @@ PRIVACY: >
b)根據法律的有關規定,或者行政或司法機構的要求,向第三方或者行政、司法機構披露;
c)如您出現違反中國有關法律、法規或者相關規則的情況,需要向第三方披露;
4.信息安全
+6 -1
View File
@@ -1,6 +1,6 @@
import { IRPCActionType } from '~/universal/types/enum'
import { RPCRouter } from '../router'
import { deleteUploaderConfig, getUploaderConfigList, selectUploaderConfig, updateUploaderConfig } from '~/main/utils/handleUploaderConfig'
import { copyUploaderConfig, deleteUploaderConfig, getUploaderConfigList, selectUploaderConfig, updateUploaderConfig } from '~/main/utils/handleUploaderConfig'
const configRouter = new RPCRouter()
@@ -15,6 +15,11 @@ configRouter
const config = deleteUploaderConfig(type, id)
return config
})
.add(IRPCActionType.COPY_UPLOADER_CONFIG, async (args) => {
const [type, id] = args as ICopyUploaderConfigArgs
const config = copyUploaderConfig(type, id)
return config
})
.add(IRPCActionType.SELECT_UPLOADER, async (args) => {
const [type, id] = args as ISelectUploaderConfigArgs
selectUploaderConfig(type, id)
+24 -1
View File
@@ -1,4 +1,4 @@
import { trimValues } from '#/utils/common'
import { simpleClone, trimValues } from '#/utils/common'
import picgo from '@core/picgo'
import { v4 as uuid } from 'uuid'
@@ -121,6 +121,29 @@ export const deleteUploaderConfig = (type: string, id: string): IUploaderConfigI
}
}
/**
* copy uploader config by type & id
*/
export const copyUploaderConfig = (type: string, id: string): IUploaderConfigItem | void => {
const { configList, defaultId } = getUploaderConfigList(type)
const existConfig = configList.find((item: IStringKeyMap) => item._id === id)
if (!existConfig) {
return
}
const copiedConfig = completeUploaderMetaConfig({
...simpleClone(existConfig),
_configName: `${existConfig._configName || 'Default'} - Copy`
})
configList.push(copiedConfig)
picgo.saveConfig({
[`uploader.${type}.configList`]: configList
})
return {
configList,
defaultId
}
}
/**
* upgrade old uploader config to new format
*/
+44 -6
View File
@@ -43,6 +43,12 @@
>
<Edit />
</el-icon>
<el-icon
class="el-icon-copy"
@click.stop="() => copyConfig(item._id)"
>
<DocumentCopy />
</el-icon>
<el-icon
class="el-icon-delete"
:class="curConfigList.length <= 1 ? 'disabled' : ''"
@@ -89,7 +95,8 @@
</div>
</template>
<script lang="ts" setup>
import { Edit, Delete, Plus } from '@element-plus/icons-vue'
import { Delete, DocumentCopy, Edit, Plus } from '@element-plus/icons-vue'
import { ElMessageBox } from 'element-plus'
import { saveConfig, triggerRPC } from '@/utils/dataSender'
import dayjs from 'dayjs'
import { IRPCActionType } from '~/universal/types/enum'
@@ -105,6 +112,7 @@ const type = ref('')
const curConfigList = ref<IStringKeyMap[]>([])
const defaultConfigId = ref('')
const store = useStore()
const $confirm = ElMessageBox.confirm
async function selectItem (id: string) {
await triggerRPC<void>(IRPCActionType.SELECT_UPLOADER, type.value, id)
@@ -147,11 +155,39 @@ function formatTime (time: number): string {
return dayjs(time).format('YYYY-MM-DD HH:mm:ss')
}
async function deleteConfig (id: string) {
const res = await triggerRPC<IUploaderConfigItem | undefined>(IRPCActionType.DELETE_PICBED_CONFIG, type.value, id)
if (!res) return
curConfigList.value = res.configList
defaultConfigId.value = res.defaultId
function deleteConfig (id: string) {
if (curConfigList.value.length <= 1) {
return
}
$confirm($T('TIPS_DELETE_UPLOADER_CONFIG'), $T('TIPS_NOTICE'), {
confirmButtonText: $T('CONFIRM'),
cancelButtonText: $T('CANCEL'),
type: 'warning'
}).then(async () => {
const res = await triggerRPC<IUploaderConfigItem | undefined>(IRPCActionType.DELETE_PICBED_CONFIG, type.value, id)
if (!res) return
curConfigList.value = res.configList
defaultConfigId.value = res.defaultId
}).catch((e) => {
console.log(e)
return true
})
}
function copyConfig (id: string) {
$confirm($T('TIPS_COPY_UPLOADER_CONFIG'), $T('TIPS_NOTICE'), {
confirmButtonText: $T('CONFIRM'),
cancelButtonText: $T('CANCEL'),
type: 'warning'
}).then(async () => {
const res = await triggerRPC<IUploaderConfigItem | undefined>(IRPCActionType.COPY_UPLOADER_CONFIG, type.value, id)
if (!res) return
curConfigList.value = res.configList
defaultConfigId.value = res.defaultId
}).catch((e) => {
console.log(e)
return true
})
}
function addNewConfig () {
@@ -226,9 +262,11 @@ export default {
align-items center
color #eee
.el-icon-edit
.el-icon-copy
.el-icon-delete
cursor pointer
.el-icon-edit
.el-icon-copy
margin-right 10px
.disabled
cursor not-allowed
+1
View File
@@ -58,6 +58,7 @@ export enum IRPCActionType {
CHANGE_CURRENT_UPLOADER = 'CHANGE_CURRENT_UPLOADER',
SELECT_UPLOADER = 'SELECT_UPLOADER',
UPDATE_UPLOADER_CONFIG = 'UPDATE_UPLOADER_CONFIG',
COPY_UPLOADER_CONFIG = 'COPY_UPLOADER_CONFIG',
// version rpc
GET_LATEST_VERSION = 'GET_LATEST_VERSION',
+2
View File
@@ -218,6 +218,8 @@ interface ILocales {
TIPS_SHORTCUT_MODIFIED_CONFLICT: string
TIPS_CUSTOM_LINK_STYLE_MODIFIED_SUCCEED: string
TIPS_FIND_NEW_VERSION: string
TIPS_DELETE_UPLOADER_CONFIG: string
TIPS_COPY_UPLOADER_CONFIG: string
PRIVACY: string
PRIVACY_TIPS: string
QUIT: string
+1
View File
@@ -3,6 +3,7 @@ type IGetUploaderConfigListArgs = [type: string]
type IDeleteUploaderConfigArgs = [type: string, id: string]
type ISelectUploaderConfigArgs = [type: string, id: string]
type IUpdateUploaderConfigArgs = [type: string, id: string, config: IStringKeyMap]
type ICopyUploaderConfigArgs = [type: string, id: string]
type IGetLatestVersionArgs = [isCheckBetaVersion: boolean]
type IToolboxCheckArgs = [type: import('./enum').IToolboxItemType]
type IOpenFileArgs = [filePath: string]