match_cert.js 3.3 KB
define(['jquery', 'bootstrap', 'backend', 'table', 'form','upload','clipboard'], function ($, undefined, Backend, Table, Form,Upload,ClipboardJS) {
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'match/match_cert/index' + location.search,
                    add_url: 'match/match_cert/add',
                    edit_url: 'match/match_cert/edit',
                    del_url: 'match/match_cert/del',
                    table: 'match_cert',
                }
            });
            var table = $("#table");
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                searchFormVisible: false,
                search:false,
                clickToSelect: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate: false},
                        {field: 'cert_name', title: __('证书名称'),operate: false},
                        {field: 'cert_url', title: __('证书Url'),operate: false,formatter:function (value,row,index){
                                return '<a href="javascript:;"  data-clipboard-text="'+value+'" class="btn-copy" data-toggle="tooltip" data-original-title="点击复制">'+value+'</a>';
                            }},
                    ]
                ]
            });
            var clipboard = new ClipboardJS('.btn-copy');
            clipboard.on('success', function(e) {
                Toastr.success('复制成功');
            });
            clipboard.on('error', function(e) {
                Toastr.error('复制失败,请刷新后重试');
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            $("#cert_url_upload").data("upload-error", function(res,result){
                if(result.code == 0) {
                    Toastr.error("上传失败!");
                    return false;
                }
            });

            $("#cert_url_upload").data("upload-success", function (res) {
                console.log(res);
                var url = Backend.api.cdnurl(res.url);
                $("#c-cert_url").val(url);
                Toastr.success("上传成功!");
                return false;
            });

            Controller.api.bindevent();
        },
        edit: function () {
            $("#cert_url_upload").data("upload-error", function(res,result){
                if(result.code == 0) {
                    Toastr.error("上传失败!");
                    return false;
                }
            });

            $("#cert_url_upload").data("upload-success", function (res) {
                console.log(res);
                var url = Backend.api.cdnurl(res.url);
                $("#c-cert_url").val(url);
                Toastr.success("上传成功!");
                return false;
            });
            Controller.api.bindevent();
        },


        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});