Skip to content

Commit

Permalink
feat: reactive config setting
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Mar 22, 2024
1 parent 025d5f6 commit 9e15e43
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 53 deletions.
63 changes: 34 additions & 29 deletions libs/zhi-siyuan-picgo/src/lib/picgoHelper.ts
Expand Up @@ -51,7 +51,7 @@ class PicgoHelper {
* @param key
* @param defaultValue
*/
public getPicgoConfig2(key?: string, defaultValue?: any) {
public getPicgoConfig(key?: string, defaultValue?: any) {
if (!key) {
return this.readonlyCfg as unknown
}
Expand Down Expand Up @@ -84,7 +84,7 @@ class PicgoHelper {
*/
public getPicBeds(): IPicBedType[] {
const picBedTypes = this.ctx.helper.uploader.getIdList()
const picBedFromDB = this.getPicgoConfig2("picBed.list") || []
const picBedFromDB = this.getPicgoConfig("picBed.list") || []

const picBeds = picBedTypes
.map((item: any) => {
Expand All @@ -105,33 +105,31 @@ class PicgoHelper {
return picBeds
}

// /**
// * 获取启用的图床
// *
// * @param ctx
// */
// public static getVisiablePicBeds(ctx: IPicGo): IPicBedType[] {
// const picBeds = this.getPicBeds(ctx)
// const visiablePicBeds = picBeds
// .map((item: IPicBedType) => {
// if (item.visible) {
// return item
// }
// return null
// })
// .filter((item: any) => item) as IPicBedType[]
//
// // SM.MS是必选的
// if (visiablePicBeds.length == 0) {
// const defaultPicbed = {
// type: "smms",
// name: "SM.MS",
// } as IPicBedType
// visiablePicBeds.push(defaultPicbed)
// }
// return visiablePicBeds
// }
//
/**
* 获取启用的图床
*/
public getVisiablePicBeds(): IPicBedType[] {
const picBeds = this.getPicBeds()
const visiablePicBeds = picBeds
.map((item: IPicBedType) => {
if (item.visible) {
return item
}
return null
})
.filter((item: any) => item) as IPicBedType[]

// SM.MS是必选的
if (visiablePicBeds.length == 0) {
const defaultPicbed = {
type: "smms",
name: "SM.MS",
} as IPicBedType
visiablePicBeds.push(defaultPicbed)
}
return visiablePicBeds
}

// /**
// * 获取可用的图床列表名称
// *
Expand Down Expand Up @@ -165,6 +163,13 @@ class PicgoHelper {
.filter((item: any) => item) as string[]
}

/**
* 获取当前图床
*/
public getCurrentUploader() {
return this.getPicgoConfig("picBed.uploader") || this.getPicgoConfig("picBed.current") || "smms"
}

// public static getUploaderConfigList(ctx: IPicGo, cfg: IConfig, type: string): IUploaderConfigItem {
// if (!type) {
// return {
Expand Down
Expand Up @@ -22,12 +22,12 @@ const { t } = useVueI18n()
const props = defineProps({
ctx: {
type: Object,
default: null,
default: null
},
cfg: {
type: Object,
default: null,
},
default: null
}
})
const formData = reactive({
Expand All @@ -46,13 +46,15 @@ const formData = reactive({
// 当前图床配置列表
curConfigList: [] as IUploaderConfigListItem[],
// 当前配置
curConfig: {} as IUploaderConfigListItem,
curConfig: {} as IUploaderConfigListItem
},
// 表单展示
isNewForm: false,
showConfigForm: false,
showConfigForm: false
})
// PicGo 持久化操作帮助类
const picgoHelper = new PicgoHelper(props.ctx, formData.cfg)
// computed
const picbedTips = computed(() => {
Expand Down Expand Up @@ -88,17 +90,6 @@ const isProfileSelected = (id: string) => {
// 从formData.picBeds中查找对应type的图片床类型名称
const findPicbedName = (type: string) => formData.picBeds.find((x) => x.type === type)?.name || type
/**
* 获取当前图床
*/
const getCurrentUploader = () => {
return (
PicgoHelper.getPicgoConfig(formData.cfg, "picBed.uploader") ||
PicgoHelper.getPicgoConfig(formData.cfg, "picBed.current") ||
"smms"
)
}
const getProfileList = (bedType: string): IUploaderConfigItem => {
const profileList = PicgoHelper.getUploaderConfigList(props.ctx, formData.cfg, bedType)
return profileList
Expand Down Expand Up @@ -132,18 +123,21 @@ const selectItem = (id: string) => {
* 删除配置
* @param id 配置ID
*/
function deleteConfig(id: string) {}
function deleteConfig(id: string) {
}
/**
* 编辑配置
* @param id 配置ID
*/
function editConfig(id: string) {}
function editConfig(id: string) {
}
/**
* 新增配置
*/
function addNewConfig() {}
function addNewConfig() {
}
const findProfileConfig = (id: string) => {
return formData.profileData.curConfigList.find((x) => x._id === id) ?? ({} as IUploaderConfigListItem)
Expand All @@ -157,15 +151,15 @@ const reloadProfile = () => {
const initConfig = () => {
// 获取图床列表
const picBeds = PicgoHelper.getVisiablePicBeds(props.ctx)
const picBeds = picgoHelper.getVisiablePicBeds()
formData.picBeds = picBeds
formData.dbBedType = getCurrentUploader()
formData.dbBedType = picgoHelper.getCurrentUploader()
formData.selectedBedType = formData.dbBedType
}
const initPage = () => {
initConfig()
reloadProfile()
// reloadProfile()
}
onBeforeMount(() => {
Expand All @@ -185,7 +179,7 @@ onBeforeMount(() => {
:key="item.type"
:type="selectedPicbedStyle(item.type)"
@click="handlePicBedTypeChange(item)"
>{{ item.name }}
>{{ item.name }}
</el-button>
</el-button-group>
</div>
Expand Down
Expand Up @@ -35,7 +35,7 @@ const formData = reactive({
// 全量图床集合
picBeds: [] as IPicBedType[],
})
// PicGo 持久化操作帮助类
const picgoHelper = new PicgoHelper(props.ctx, formData.cfg)
const handleShowPicBedListChange = (val: ICheckBoxValueType[]) => {
Expand Down

0 comments on commit 9e15e43

Please sign in to comment.