Blame view

web/WebMvc/wwwroot/productjs/base/SysFile.js 6.35 KB
HuXiYu authored
1
2
let action = null;
let app = null;
HuXiYu authored
3
4
5
6
let sendDataWhere = {
    targetId: null,
    targetName: null,
    targetTableName: "equipment_doc"
HuXiYu authored
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
};
layui.config({
    base: "/js/",
    version: 1
}).use(['system', 'ztree'], function () {
    var form = layui.form,
        $ = layui.jquery,
        system = layui.system,
        u = new system.u(),
        table = layui.table,
        rowData = null,

        areaName = "Base",
        controller = "SysFile";

    action = {
        deleteOptions: function () {
            var options = {
                url: `/${areaName}/${controller}/DelByIds`,
26
                keyId: "id"
HuXiYu authored
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
            }
            return options;
        },

        queryOptions: function () {
            var options = {
                resetFrom: "form[lay-filter=listForm]",
                fromId: "listForm",
                urlExport: `/${areaName}/${controller}/Export`,
                urlQuery: `/${areaName}/${controller}/Load`,
                mainTable: app.data.tableIns
            }
            return options;
        },

        uploadOptions: function () {
            var options = {
                area: ["600px", "500px"],
                url: `/${areaName}/${controller}/Import`,
HuXiYu authored
46
                fromFile: "#excelfile",
HuXiYu authored
47
48
49
50
                content: $("#ImportData")
            }
            return options;
        },
HuXiYu authored
51
        //内部不支持异步,成功返回true,失败返回false
HuXiYu authored
52
        uploadBefore: function (checkStatus, parm) {
HuXiYu authored
53
54
55
            if (sendDataWhere.targetId == null) {
                layer.alert("请选择设备类型!", { icon: u.config.iconoError, shade: 0.4, time: u.config.errorTime });
                return false;
HuXiYu authored
56
            }
57
HuXiYu authored
58
59
            $("#ImportData [name='targetId']").val(sendDataWhere.targetId);
            $("#ImportData [name='targetName']").val(sendDataWhere.targetName);
HuXiYu authored
60
61
62
63
64
65
66
67
            return true;
        },
        uploadSaveBefore: function (formData, selectRow, callBack) {
            if (callBack != null) callBack();
        },

        //所有动作成功之后
        actionSuccess: (falg) => {
68
69
70
71
72
73
            if (falg === "upload" || falg=="delete") {
                app.methods.initTable({ targetId: sendDataWhere.targetId });
            } else if (falg === "refresh") {
                app.data.tableIns.config.page.curr = 1;
                app.data.tableIns.reload("mainList", {});
            }
HuXiYu authored
74
75
76
77
78
79
80
        }
    }

    app = {
        data: {
            cols: [[
                { checkbox: true, fixed: true },
81
                { field: "id", width: 100, title: "编码", hide: true },
HuXiYu authored
82
83
84
                { field: 'fileName', width: 200, title: '文档名称', hide: true },
                {
                    field: 'url', width: 180, title: '文件下载', templet: function (d) {
85
86
87
88
89
                        var target = "_blank";
                        if (d.suffix.indexOf("pdf") > -1 || d.suffix.indexOf("docx") > -1 || d.suffix.indexOf("doc") > -1 || d.suffix.indexOf("xlsx") > -1) {
                            target = "";
                        }
                        return `<a href="../../Document/${d.url}"  target=${target} style="color: cornflowerblue;text-decoration: underline;cursor:pointer">${d.fileName}</a>`;
HuXiYu authored
90
91
                    }
                },
HuXiYu authored
92
93
                { field: 'size', width: 120, title: '文档大小' },
                { field: 'targetId', title: '适用的设备Id', hide: true },
HuXiYu authored
94
                { field: 'targetName', width: 120, title: '适用的设备', hide: true },
HuXiYu authored
95
96
97
98
                { field: 'suffix', width: 100, title: '文档类型' },
                { field: 'remark', width: 120, title: '备注' },

                { field: 'createTime', width: 150, title: '创建时间' },
HuXiYu authored
99
                { field: 'createBy', width: 100, title: '创建人' }
HuXiYu authored
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
            ]],
            urlTable: `/${areaName}/${controller}/Load`,
            tableIns: null,
            tableInsDesc: null,

            tableElem: "mainList",

            tree: $("#tree"),
            treeObj: null,
            setting: {
                view: { selectedMulti: false },
                async: {
                    enable: true,
                    url: `/${areaName}/${controller}/GetTreeList`,
                    type: "get"
                },
                data: {
                    simpleData: {
                        enable: true,
                        idKey: "keys",
                        pIdKey: "parentId",
                        rootPId: ""
                    }
                },
                callback: {
                    onClick: function (event, treeId, treeNode) {
HuXiYu authored
126
127
128
                        sendDataWhere.targetId = treeNode.id;
                        sendDataWhere.targetName = treeNode.name;
                        app.methods.initTable(sendDataWhere);
HuXiYu authored
129
130
131
132
133
134
135
136
137
                    },
                    onAsyncSuccess: function (event, treeId, treeNode, msg) {
                        app.data.treeObj.expandAll(true);
                    }
                }
            },
            selectOption: {
                //返回的数据 用于后续操作
                selectData: {
HuXiYu authored
138
                    targetTableName: "equipment_doc"
HuXiYu authored
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
                }
            }
        },
        methods: {
            initTable: function (options) {
                var config = {

                };
                if (options != undefined) $.extend(config, options);
                let opt = {
                    cols: u.columnRecord(app.data.tableElem, app.data.cols),
                    elem: "#" + app.data.tableElem,
                    url: app.data.urlTable,
                    height: 'full-0',
                    toolbar: '#toolbarTable',
                    where: config,
                    menuModule: controller
                }
                app.data.tableIns = u.initTable(opt);
            },
            initTree: function () {
                setTimeout(() => {
                    app.data.treeObj = $.fn.zTree.init(app.data.tree, app.data.setting);

                    app.data.tree.height($("div.layui-table-view").height() - 20);
                }, 50);
            },
            initFrom() {
                u.initSelect(app.data.selectOption);
            },
        },
        registerEvent: function () {

        },
        init: function () {
            app.registerEvent();
            app.methods.initTable();
            app.methods.initTree();
            app.methods.initFrom();
        }
    };
    app.init();
})