在ThinkAdmin中弹出层关闭后回调

在thinkadmin里面,窗口的的一些方法全部都集成在admin.js里面,在之前的文章中也有出现过类似的问题,就是对动态加载的数据进行统计,那时候写也是想记录下,现在自己都不记得是哪个站用的了,所以在这里也把这次的操作记录下

这次是因为有些操作必须等到窗口关闭以后才需要运行,所以看下弹出的代码,基本都是运用data-modaldata-opendata-iframe等进行窗口操作

所以我们看下admin.js的代码

    onEvent('click', '[data-modal]', function () {
        var un = undefined, emap = this.dataset, data = {open_type: 'modal'};
        return applyRuleValue(this, data, function () {
            return $.form.modal(emap.modal, data, emap.title || this.innerText || '编辑', un, un, un, emap.area || emap.width || '800px', emap.offset || 'auto', emap.full !== un);
        })
    });

这里可以看出,他是调用的集成的from里面的modal方法,然后我们再看这个方法:


        /*! 加载 HTML 到弹出层 */
        this.modal = function (url, data, name, call, load, tips, area, offset, isfull) {
            this.load(url, data, 'GET', function (res) {
                if (typeof res === 'object') return $.msg.auto(res), false;
                return $.msg.mdx.push(this.idx = layer.open({
                    type: 1, btn: false, area: area || "800px", resize: false, content: res, title: name || '', offset: offset || 'auto', success: function ($dom, idx) {
                        typeof call === 'function' && call.call($.form, $dom);
                        $.form.reInit($dom.off('click', '[data-close]').on('click', '[data-close]', function () {
                            onConfirm(this.dataset.confirm, function () {
                                layer.close(idx);
                            });
                        }));
                    }
                })), isfull && layer.full(this.idx), false;
            }, load, tips);
        };

这里看出他是定义了layer.open,找到这个我们结合layui的文档就可以看出,想要执行窗口关闭以后我们只需要在对应的layer.open增加一个关闭后回调,即:cancel,也可以增加一个销毁后回调:end

但是又不是每个弹窗都需要执行这个回调,那我们最好的办法就是再增加一个参数来判断是否执行回调,但是这样的改动不是很有必要,因为我目前只需要针对一种特定的情况执行,所以这边我就偷个懒,用原本有的参数来判断,而其中最常用的肯定是宽度:area了,所以改完以后的代码如下:


        /*! 加载 HTML 到弹出层 */
        this.modal = function (url, data, name, call, load, tips, area, offset, isfull) {
            this.load(url, data, 'GET', function (res) {
                if (typeof res === 'object') return $.msg.auto(res), false;
                return $.msg.mdx.push(this.idx = layer.open({
                    type: 1, btn: false, area: area || "800px", resize: false, content: res, title: name || '', offset: offset || 'auto', success: function ($dom, idx) {
                        typeof call === 'function' && call.call($.form, $dom);
                        $.form.reInit($dom.off('click', '[data-close]').on('click', '[data-close]', function () {
                            onConfirm(this.dataset.confirm, function () {
                                layer.close(idx);
                            });
                        }));
                    },end: function () {
                        // 用宽度来判断是否需要关闭后刷新
                        if(area == "91.1%") {
                            console.log('此处执行需要的操作')
                        }
                    }
                })), isfull && layer.full(this.idx), false;
            }, load, tips);
        };

当然,知道怎么改以后可以实现的方法有很多,我这边的办法不可取因为后期你这里可能就是一段没有用处的代码或者影响到其他弹窗,然后你会半天找不到为什么,所以如果这个回调是系统的常用回调的话,建议还是自己多加个参数吧

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值