typescript 引入layui 之 layui.d.ts

技术文摘
ts 
0 73
admin
xukai 5 2021/4/30 15:46:19
编辑此贴 收藏

描述:-


declare module layui {
    type LayerCallbackSuccess = null | ((layero: JQuery, index: number) => void);
    type LayerCallbackYes = null | ((index: number, layero: JQuery) => boolean | void);
    type LayerCallbackCancel = null | ((index: number, layero: JQuery) => boolean | void);
    type LayerCallbackEnd = null | (() => void);
    type LayerCallbackFull = null | ((layero: JQuery) => void);
    type LayerCallbackMin = null | ((layero: JQuery) => void);
    type LayerCallbackRestore = null | ((layero: JQuery) => void);
    type LayerCallbackPrompt = null | ((value: string, index: number, elem: JQuery) => void);

    /**
     * Layer options
     */
    interface LayerOptions {
        type?: number;
        title?: string | boolean | string[];
        content?: string | HTMLElement | JQuery | string[];
        skin?: string;
        area?: string | string[];
        offset?: number | string | string[];
        icon?: number;
        btn?: string | string[];
        closeBtn?: string | boolean;
        shade?: string | boolean | (number | string)[];
        shadeClose?: boolean;
        time?: number;
        id?: string;
        anim?: number;
        isOutAnim?: boolean;
        maxmin?: boolean;
        fixed?: boolean;
        resize?: boolean;
        resizing?: Function;
        scrollbar?: boolean;
        maxWidth?: number;
        zIndex?: number;
        move?: string | boolean | HTMLElement;
        moveType?: boolean;
        moveOut?: boolean;
        moveEnd?: null | (() => void);
        tips?: number | (number | string)[];
        tipsMore?: boolean;
        success?: LayerCallbackSuccess;
        yes?: LayerCallbackYes;
        btn2?: LayerCallbackYes;
        btn3?: LayerCallbackYes;
        cancel?: LayerCallbackCancel;
        end?: LayerCallbackEnd;
        full?: LayerCallbackFull;
        min?: LayerCallbackMin;
        restore?: LayerCallbackRestore;
    }

    interface LayerConfigOptions extends LayerOptions {
        path?: string;
        extend?: string[];
    }

    interface LayerPromptOptions extends LayerOptions {
        formType?: number;
        value?: string;
        maxlength?: number;
        area?: string[];
    }

    interface LayerTabOptions extends LayerOptions {
        tab: ({ title: string, content: string })[];
    }

    interface LayerPhotosOptions extends LayerOptions {
        photos: LayerPhotosData | string;
        tab?: (pic: LayerPhotosDataItem, layero: JQuery) => void;
    }

    interface LayerPhotosData {
        title: string;
        id: number;
        start?: number;
        data: LayerPhotosDataItem[];
    }

    interface LayerPhotosDataItem {
        alt: string;
        pid?: number;
        src: string;
        thumb: string;
    }

    /**
     * Layer object
     */
    interface Layer {
        /**
         * 初始化全局配置
         * @param {LayerConfigOptions} options;
         */
        config(options: LayerConfigOptions): void;
        /**
         * 初始化就绪
         * @param {string} path
         * @param {Function} callback
         */
        ready(path: string, callback: () => void): void;
        /**
         * 初始化就绪
         * @param {Function} callback
         */
        ready(callback: () => void): void;
        /**
         * 原始核心方法
         * @param {LayerOptions} options
         */
        open(options?: LayerOptions): number;
        /**
         * 普通信息框
         * @param {string} content
         * @param {LayerOptions} options
         * @param {Function} yes
         */
        alert(content: string, options?: LayerOptions, yes?: LayerCallbackYes): number;
        /**
         * 普通信息框
         * @param {string} content
         * @param {Function} yes
         */
        alert(content: string, yes?: LayerCallbackYes): number;

        confirm(content: string, options?: LayerOptions, yes?: LayerCallbackYes, cancel?: LayerCallbackCancel): number;

        confirm(content: string, yes?: LayerCallbackYes, cancel?: LayerCallbackCancel): number;

        msg(content: string, options?: LayerOptions, end?: LayerCallbackEnd): number;

        msg(content: string, end?: LayerCallbackEnd): number;

        load(icon?: number, options?: LayerOptions): number;

        tips(content: string, follow: string | this, options?: LayerOptions): number;

        close(index: number): void;

        closeAll(type?: 'dialog' | 'page' | 'iframe' | 'loading' | 'tips'): void;

        style(index: number, cssStyle: { [key: string]: string | number }): void;

        title(title: string, index: number): void;

        getChildFrame(selector: string, index: number): JQuery;

        getFrameIndex(windowName: string): number;

        iframeAuto(index: number): void;

        iframeSrc(index: number, url: string): void;

        setTop(layero: JQuery): void;

        full(): void;

        min(): void;

        restore(): void;

        prompt(options?: LayerPromptOptions, yes?: LayerCallbackPrompt): number;

        prompt(yes?: LayerCallbackPrompt): number;

        tab(options: LayerTabOptions): number;

        photos(options: LayerPhotosOptions): number;
    }

    interface TabOption {
        title: string;
        content: string;
        id: string;
    }

    interface Element {
        init(type?: string, filter?: string): void;
        on(filter: string, callback: (data: any) => any): void;
        tabAdd(filter: string, options: TabOption): void;
        tabDelete(filter: string, layid: string): void;
        tabChange(filter: string, layid: string): void;
        progress(filter: string, percent: string);
        render(type?: string, filter?: string): void;
    }

    interface LayFormData {
        elem?: HTMLElement;
        othis?: any;
        value?: string;
        form?: any;
        field?: any;
    }

    interface Form {
        on(event: string, callback: (data: LayFormData) => any): void;
        render(type?: string, filter?: string);
        verify(config: object);
    }

    interface PageOptions {
        elem: string | Object;
        count?: number;
        limit?: number;
        limits?: number[];
        curr?: number;
        groups?: number;
        prev?: string;
        next?: string;
        first?: string;
        last?: string;
        layout?: ['count' | 'prev' | 'page' | 'next' | 'limit' | 'skip'];
        theme?: string;
        hash?: string | boolean;
        jump?: (obj: PageOptions, first: boolean) => void;
    }

    interface Laypage {
        render(options: PageOptions): any;
    }

    interface DateParam {
        year?: number;
        month?: number;
        date?: number;
        hours?: number;
        minutes?: number;
        seconds?: number;
    }

    interface DateOption {
        elem?: string | HTMLElement;
        type?: 'year' | 'month' | 'date' | 'time' | 'datetime';
        range?: string | boolean;
        format?: string;
        value?: string | Date;
        min?: string;
        max?: string;
        trigger?: string;
        show?: boolean;
        position?: string;
        zIndex?: number;
        showBottom?: boolean;
        btns?: 'clear' | 'now' | 'confirm';
        lang?: 'cn' | 'en';
        theme?: string | 'default' | 'molv' | 'grid';
        calendar?: boolean;
        mark?: Object;
        ready?: (date: DateParam) => void;
        change?: (value: string, date: DateParam, endDate?: DateParam) => void;
        done?: (value: string, date: DateParam, endDate?: DateParam) => void;
    }

    interface Laydate {
        render(options: DateOption): Object;
        set(options: DateOption): void;
        getEndDate(month: number, year?: number): number;
    }

    interface Layui {
        layer?: Layer;
        element?: Element;
        form?: Form;
        laydate?: Laydate;
        laypage?: Laypage;
        use(mods: string | string[], callback: (...args: any[]) => any): any;
    }


    export let layer: Layer;
    export let element: Element;
    export let form: Form;
    export let laydate: Laydate;
    export let laypage: Laypage;
    export let jquery: JQueryStatic;
    export let $: JQueryStatic


    //interface JQuery {
    //    html(): string;
    //    text(): string;
    //}
    export function use(mods: string | string[], callback: (...args: any[]) => any): any;
}
如果需要layui.jquery能有智能提示,那么需要同时引用jquery.d.ts,语法如下:

/// <reference path="jquery.d.ts" />

jquery.d.ts 内容可查看另一篇:https://ktblog.top/jie/detail/26dd7d9f61df4d798cc


个人签名:己所不欲勿施于人

回帖
  • 消灭零回复
本周热议
非法访问资源ip地址公布 1
不用写一句sql的ORM框架,支持多种数据库 1
c# winform 身份证信息读取 0
c#如何集成控制Led屏,实现数据发送自动开机、关机等操作! 0
c#如何获取电脑mac地址,超简单! 0
批量检测指定ip某些端口是否开启,用来做什么自己想吧!!! 0
c# 实现文件下载功能,带下载进度条,可用到软件的自动更新中 0
winform程序如何做到开机自动启动 0
怎么判断两张图片是否完全相同,通过读取图片内容进行对比 0
c# 如何打印条形码 0
热门资讯
看图猜成语:明明很简单,是不是大意了 65 
【每日一习话】把事业放在心上 把责任扛在肩上 64 
第一观察 | 从两会“如期”召开看百年大党的执政能力 63 
美日共同发表"对中国措辞最强硬"声明 外交部撂重话 61 
玖月奇迹王小玮近照曝光!穿紧身裤秀出小鸟腿,皮肤白到发光 60 
成人体验馆被封,客人一天点3个娃娃:男人的孤独,谁能懂? 59 
《奇葩说》第七季总决赛,肖骁用不是自己风格的夺冠后,获得表扬 59 
联播+ | 谋定而动 习近平引领京津冀携手下好“一盘棋” 58 
强力堆料,几乎没有短板、铭瑄iCraft B550M电竞之心主板评测 58 
美媒承认搞错了,但已经来不及了 56 
广东一男子离职索赔270万,公司:你月薪才25万 55 
王霜首次回应结束留洋原因:不因贾秀全 只因这3个字 54 
扒女明星每日穿搭,千元Coach这样搭,千元CHANEL这样买! 53 
亲戚之子前来投奔杜月笙,故意在家中掉钱,捡与不捡两个结局 29 
多名主播带货遭网友围攻 耐克小姐姐被骂哭 阿迪小哥要去找工作 18