mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-05-06 20:42:57 +08:00
✨ Feature(custom): optimize per picbed setting logic when the value is same to default
This commit is contained in:
@@ -1111,40 +1111,38 @@ const compressForm = ref<IBuildInCompressOptions>({
|
||||
/* Only used if configId is not provided */
|
||||
const formatConvertObjStr = ref('{}')
|
||||
|
||||
const defaultSkipProcessSetting = {
|
||||
skipProcessExtList: 'zip,rar,7z,tar,gz,tar.gz,tar.bz2,tar.xz',
|
||||
}
|
||||
/* Only used if configId is not provided */
|
||||
const skipProcessForm = ref<IBuildInSkipProcessOptions>({
|
||||
skipProcessExtList: 'zip,rar,7z,tar,gz,tar.gz,tar.bz2,tar.xz',
|
||||
...defaultSkipProcessSetting,
|
||||
})
|
||||
|
||||
const isInitialized = ref(false)
|
||||
|
||||
function saveSkipProcessConfig() {
|
||||
saveConfig(configPaths.buildIn.skipProcess, toRaw(skipProcessForm.value))
|
||||
}
|
||||
|
||||
function saveCompressConfig() {
|
||||
const cleanFullMap: Record<string, any> = {}
|
||||
Object.entries(compressForm.value.formatConvertObjMap || {}).forEach(([picbedType, value]) => {
|
||||
try {
|
||||
const cleanedObj = cleanFormatConvertObj(value)
|
||||
|
||||
if (Object.keys(cleanedObj).length > 0) {
|
||||
cleanFullMap[picbedType] = cleanedObj
|
||||
}
|
||||
} catch (_error) {}
|
||||
})
|
||||
if (JSON.stringify(cleanFullMap) !== JSON.stringify(compressForm.value.formatConvertObjMap)) {
|
||||
compressForm.value.formatConvertObjMap = cleanFullMap
|
||||
}
|
||||
|
||||
saveConfig(configPaths.buildIn.compress, toRaw(compressForm.value))
|
||||
}
|
||||
|
||||
function saveWaterMarkConfig() {
|
||||
saveConfig(configPaths.buildIn.watermark, toRaw(waterMarkForm.value))
|
||||
}
|
||||
|
||||
const singleConfigSettings = ref<IBuildInListItem>({} as IBuildInListItem)
|
||||
const singleConfigSettings = ref<IBuildInListItem>({
|
||||
id: '',
|
||||
compress: {
|
||||
...defaultCompressSetting,
|
||||
},
|
||||
watermark: {
|
||||
...defaultWaterMarkSetting,
|
||||
},
|
||||
skipProcess: {
|
||||
...defaultSkipProcessSetting,
|
||||
},
|
||||
rename: {
|
||||
enable: false,
|
||||
format: '{filename}',
|
||||
},
|
||||
autoRename: false,
|
||||
manualRename: false,
|
||||
} as IBuildInListItem)
|
||||
|
||||
function cleanFormatConvertObj(obj: any) {
|
||||
const cleanedObj: Record<string, any> = {}
|
||||
@@ -1157,18 +1155,6 @@ function cleanFormatConvertObj(obj: any) {
|
||||
}
|
||||
|
||||
async function initData() {
|
||||
//single config settings
|
||||
if (configId) {
|
||||
const buildInList = await getConfig<Undefinable<IBuildInListItem[]>>(configPaths.buildIn.list)
|
||||
if (!buildInList) {
|
||||
console.error('Failed to load built-in config list.')
|
||||
}
|
||||
const targetConfig = buildInList?.find(item => item.id === configId)
|
||||
if (targetConfig) {
|
||||
singleConfigSettings.value = targetConfig
|
||||
}
|
||||
}
|
||||
|
||||
// global settings
|
||||
const compress = (await getConfig<IBuildInCompressOptions>(configPaths.buildIn.compress)) || {}
|
||||
const watermark = (await getConfig<IBuildInWaterMarkOptions>(configPaths.buildIn.watermark)) || {}
|
||||
@@ -1230,6 +1216,17 @@ async function initData() {
|
||||
...skipProcess,
|
||||
}
|
||||
}
|
||||
if (configId) {
|
||||
let buildInList = await getConfig<Undefinable<IBuildInListItem[]>>(configPaths.buildIn.list)
|
||||
if (!buildInList) {
|
||||
saveConfig(configPaths.buildIn.list, [])
|
||||
buildInList = []
|
||||
}
|
||||
const targetConfig = buildInList?.find(item => item.id === configId)
|
||||
if (!targetConfig) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function safeSetMapValue(form: any, fieldName: string, picbedType: string, value: any, defaultValue: any) {
|
||||
@@ -1250,7 +1247,7 @@ function safeSetMapValue(form: any, fieldName: string, picbedType: string, value
|
||||
if (!form[mapFieldName]) {
|
||||
form[mapFieldName] = {}
|
||||
}
|
||||
if (value === defaultValue) {
|
||||
if (value === defaultValue && form[fieldName] === defaultValue) {
|
||||
delete form[mapFieldName][picbedType]
|
||||
} else {
|
||||
if (fieldName === 'formatConvertObj') {
|
||||
@@ -1261,6 +1258,28 @@ function safeSetMapValue(form: any, fieldName: string, picbedType: string, value
|
||||
}
|
||||
}
|
||||
|
||||
function saveSkipProcessConfig() {
|
||||
saveConfig(configPaths.buildIn.skipProcess, toRaw(skipProcessForm.value))
|
||||
}
|
||||
|
||||
function saveCompressConfig() {
|
||||
const cleanFullMap: Record<string, any> = {}
|
||||
Object.entries(compressForm.value.formatConvertObjMap || {}).forEach(([picbedType, value]) => {
|
||||
try {
|
||||
const cleanedObj = cleanFormatConvertObj(value)
|
||||
|
||||
if (Object.keys(cleanedObj).length > 0) {
|
||||
cleanFullMap[picbedType] = cleanedObj
|
||||
}
|
||||
} catch (_error) {}
|
||||
})
|
||||
if (JSON.stringify(cleanFullMap) !== JSON.stringify(compressForm.value.formatConvertObjMap)) {
|
||||
compressForm.value.formatConvertObjMap = cleanFullMap
|
||||
}
|
||||
|
||||
saveConfig(configPaths.buildIn.compress, toRaw(compressForm.value))
|
||||
}
|
||||
|
||||
watch(activeTab, () => {
|
||||
nextTick(updateTabIndicator)
|
||||
})
|
||||
|
||||
@@ -104,7 +104,7 @@
|
||||
},
|
||||
"generalSettings": "General",
|
||||
"perPicBed": {
|
||||
"defaultValue": "Default Value: {value}",
|
||||
"defaultValue": "Global Value: {value}",
|
||||
"description": "Configure settings for each PicBed individually",
|
||||
"title": "Per-PicBed Settings"
|
||||
},
|
||||
|
||||
@@ -104,7 +104,7 @@
|
||||
},
|
||||
"generalSettings": "常规",
|
||||
"perPicBed": {
|
||||
"defaultValue": "默认值: {value}",
|
||||
"defaultValue": "全局值: {value}",
|
||||
"description": "为每个图床单独配置设置",
|
||||
"title": "图床独立设置"
|
||||
},
|
||||
|
||||
@@ -104,7 +104,7 @@
|
||||
},
|
||||
"generalSettings": "常規",
|
||||
"perPicBed": {
|
||||
"defaultValue": "默認值: {value}",
|
||||
"defaultValue": "全局值: {value}",
|
||||
"description": "為每個圖床單獨配置設置",
|
||||
"title": "圖床獨立設置"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user