gz-component

一个常用的组件库

Dieses Skript sollte nicht direkt installiert werden. Es handelt sich hier um eine Bibliothek für andere Skripte, welche über folgenden Befehl in den Metadaten eines Skriptes eingebunden wird // @require https://update.greatest.deepsurf.us/scripts/524094/1522518/gz-component.js

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

Autor
hgztask
Version
1.0.1
Erstellt am
18.01.2025
Letzte Aktualisierung
18.01.2025
Größe
6,86 KB
Lizenz
Apache-2.0

gz-component(gz组件)


目前已有的组件

  1. SheetDialog sheet对话框

使用方法

  • 通过 new gz.组件名称(配置项) 创建组件实例

SheetDialog sheet对话框

  • 使用方法

// 创建实例
const sheetDialog = new gz.SheetDialog({
    title: '标题',
    //是否点击遮罩关闭对话框
    closeOnOverlayClick: false,
    //选项组
    options: [
        //直接指定选项内容
        '选项1',
        //也可以通过对象的形式指定
        {
            //使用label作为选项内容
            label: '选项2',
            //使用其他自定义key作为选项的属性
            value1: 'value1',
            value2: 'value2',
            value3: 'value3'
        },
        {
            //同上
            label: '选项3',
            value: '选项3的值',
            /**
             * 该属性指定点击事件
             * @param event 事件对象
             * @param attrs {[{name:string,value:string}]} 该选项的属性
             * @param This {SheetDialog} 当前组件实例
             * @returns {boolean} 如果返回true则阻止全局选项的点击事件,否则继续执行全局选项的点击事件
             */
            event: (event, attrs, This) => {
                const label = event.target.textContent.trim();
                console.log(label, attrs);
                console.log(This.getAllOptionAttrs());
                //是否阻止全局选项的点击事件
                return true
            }
        }
    ],
    /**
     * 该实例的全局选项点击事件
     * @param event 事件对象
     * @param attrs {[{name:string,value:string}]} 当前选项的属性
     * @param This {SheetDialog} 当前组件实例
     * @returns {boolean} 如果返回true则阻止全局选项的点击事件,否则继续执行全局选项的点击事件
     *
     */
    optionEvent: (event, attrs, This) => {
        const targetButEl = event.target;
        const label = targetButEl.textContent;
        console.log(This);
        console.log(`点击了${label}`, attrs, targetButEl);
        return true;
    }
});

//添加到网页body中
sheetDialog.addBody()
//获取实例所有选项的属性
const allOptionAttrs = sheetDialog.getAllOptionAttrs();

//设置实例的全局选项点击事件
sheetDialog.setOptionEvent(回调事件);

//销毁实例并在页面中移除内容
sheetDialog.destroy();