🔨 调整 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";
interface ISettingItem {
interface ISettingItemCore {
type: TSettingItemType;
key: string;
value: any;
type: TSettingItemType;
title: string;
description?: string;
placeholder?: string;
slider?: {
min: number;
@ -12,12 +19,23 @@ interface ISettingItem {
step: number;
};
options?: { [key: string | number]: string };
action?: {
callback: () => void;
}
button?: {
label: string;
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;
}

View file

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