Feature: add config import for picbed setting

This commit is contained in:
萌萌哒赫萝 2023-04-11 16:55:57 +08:00
parent dce26ff6f3
commit 1b15ccb19c
2 changed files with 67 additions and 3 deletions

View File

@ -167,7 +167,16 @@ async function getCurConfigFormData () {
return curTypeConfigList.find(i => i._id === configId) || {}
}
function updateRuleForm (key: string, value: any) {
try {
ruleForm[key] = value
} catch (e) {
console.log(e)
}
}
defineExpose({
updateRuleForm,
validate,
getConfigType
})

View File

@ -44,6 +44,31 @@
>
{{ $T('CONFIRM') }}
</el-button>
<el-button
class="confirm-btn"
round
type="warning"
@mouseenter="handleMouseEnter"
@mouseleave="handleMouseLeave"
>
<el-dropdown
ref="$dropdown"
placement="top"
style="color: #fff; font-size: 12px;width: 100%;"
:disabled="picBedConfigList.length === 0"
>
{{ $T('MANAGE_LOGIN_PAGE_PANE_IMPORT') }}
<template #dropdown>
<el-dropdown-item
v-for="i in picBedConfigList"
:key="i._id"
@click="handleConfigImport(i)"
>
{{ i._configName }}
</el-dropdown-item>
</template>
</el-dropdown>
</el-button>
</el-button-group>
</el-form-item>
</config-form>
@ -73,18 +98,23 @@ import {
} from 'electron'
import { OPEN_URL } from '~/universal/events/constants'
import { Link } from '@element-plus/icons-vue'
import dayjs from 'dayjs'
import { ElDropdown } from 'element-plus'
const type = ref('')
const config = ref<IPicGoPluginConfig[]>([])
const picBedConfigList = ref<IUploaderConfigListItem[]>([])
const picBedName = ref('')
const $route = useRoute()
const $router = useRouter()
const $configForm = ref<InstanceType<typeof ConfigForm> | null>(null)
const $dropdown = ref<InstanceType<typeof ElDropdown> | null>(null)
type.value = $route.params.type as string
onBeforeMount(() => {
onBeforeMount(async () => {
sendToMain('getPicBedConfig', $route.params.type)
ipcRenderer.on('getPicBedConfig', getPicBeds)
await getPicBedConfigList()
})
const handleConfirm = async () => {
@ -101,6 +131,31 @@ const handleConfirm = async () => {
}
}
function handleMouseEnter () {
$dropdown.value?.handleOpen()
}
function handleMouseLeave () {
$dropdown.value?.handleClose()
}
async function getPicBedConfigList () {
const res = await triggerRPC<IUploaderConfigItem>(IRPCActionType.GET_PICBED_CONFIG_LIST, type.value) || undefined
const configList = res?.configList || []
picBedConfigList.value = configList.filter((item) => item._id !== $route.params.configId)
}
async function handleConfigImport (configItem: IUploaderConfigListItem) {
const { _id, _configName, _updatedAt, _createdAt, ...rest } = configItem
for (const key in rest) {
if (Object.prototype.hasOwnProperty.call(rest, key)) {
const value = rest[key]
$configForm.value?.updateRuleForm(key, value)
}
}
$configForm.value?.updateRuleForm('_configName', dayjs(_updatedAt).format('YYYYMMDDHHmmss'))
}
const handleReset = async () => {
await triggerRPC<void>(IRPCActionType.RESET_UPLOADER_CONFIG, type.value, $route.params.configId)
const successNotification = new Notification($T('SETTINGS_RESULT'), {
@ -175,7 +230,7 @@ export default {
cursor pointer
color #409EFF
.confirm-btn
width: 250px
width: 110px
.el-form
label
line-height 22px
@ -186,7 +241,7 @@ export default {
.el-button-group
width 100%
.el-button
width 50%
width 33%
.el-radio-group
margin-left 25px
.el-switch__label