🔨 调整 setting 的 interface 定义

This commit is contained in:
frostime 2024-04-30 16:00:03 +08:00
parent 4a9d0f3953
commit 7159755c70
2 changed files with 29 additions and 11 deletions

32
src/libs/index.d.ts vendored
View file

@ -1,10 +1,17 @@
/*
* Copyright (c) 2024 by frostime. All Rights Reserved.
* @Author : frostime
* @Date : 2024-04-19 18:30:12
* @FilePath : /src/libs/index.d.ts
* @LastEditTime : 2024-04-30 15:53:15
* @Description :
*/
type TSettingItemType = "checkbox" | "select" | "textinput" | "textarea" | "number" | "slider" | "button" | "hint"; type TSettingItemType = "checkbox" | "select" | "textinput" | "textarea" | "number" | "slider" | "button" | "hint";
interface ISettingItem {
interface ISettingItemCore {
type: TSettingItemType;
key: string; key: string;
value: any; value: any;
type: TSettingItemType;
title: string;
description?: string;
placeholder?: string; placeholder?: string;
slider?: { slider?: {
min: number; min: number;
@ -12,12 +19,23 @@ interface ISettingItem {
step: number; step: number;
}; };
options?: { [key: string | number]: string }; options?: { [key: string | number]: string };
action?: {
callback: () => void;
}
button?: { button?: {
label: string; label: string;
callback: () => void; callback: () => void;
} }
}
interface ISettingItem extends ISettingItemCore {
title: string;
description: string;
}
//Interface for setting-utils
interface ISettingUtilsItem extends ISettingItem {
direction?: "row" | "column";
action?: {
callback: () => void;
}
createElement?: (currentVal: any) => HTMLElement; createElement?: (currentVal: any) => HTMLElement;
} }

View file

@ -3,7 +3,7 @@
* @Author : frostime * @Author : frostime
* @Date : 2023-12-17 18:28:19 * @Date : 2023-12-17 18:28:19
* @FilePath : /src/libs/setting-utils.ts * @FilePath : /src/libs/setting-utils.ts
* @LastEditTime : 2024-04-29 17:17:19 * @LastEditTime : 2024-04-30 15:50:07
* @Description : * @Description :
*/ */
@ -56,7 +56,7 @@ export class SettingUtils {
name: string; name: string;
file: string; file: string;
settings: Map<string, ISettingItem> = new Map(); settings: Map<string, ISettingItemCore> = new Map();
elements: Map<string, HTMLElement> = new Map(); elements: Map<string, HTMLElement> = new Map();
constructor(args: { constructor(args: {
@ -214,7 +214,7 @@ export class SettingUtils {
return data; return data;
} }
addItem(item: ISettingItem) { addItem(item: ISettingUtilsItem) {
this.settings.set(item.key, item); this.settings.set(item.key, item);
if (item.createElement === undefined) { if (item.createElement === undefined) {
let itemElement = this.createDefaultElement(item); let itemElement = this.createDefaultElement(item);
@ -242,7 +242,7 @@ export class SettingUtils {
} }
} }
createDefaultElement(item: ISettingItem) { createDefaultElement(item: ISettingUtilsItem) {
let itemElement: HTMLElement; let itemElement: HTMLElement;
switch (item.type) { switch (item.type) {
case 'checkbox': case 'checkbox':