import.js 3.4 KB
let action = null;
let customImportFileName = ["form", "table", "element", "jquery"];
layui.config({
    base: "/js/",
    version: 111
}).use(["system", "vue"], function () {
    var form = layui.form,
        $ = layui.jquery,
        system = layui.system,
        sysU = new system.u(),
        vueApp = null,
        areaName = "Planned",
        tableName = "Import";

    action = {
        uploadOptions: function () {
            var options = {
                url: `/${areaName}/${tableName}/Import`,
                fromFile: "#excelfile",
                content: $("#ImportData")
            }
            return options;
        },
        uploadSaveBefore: function (formData, selectRow, callBack) {
            debugger
            var excelfile = formData.formFile.getAll("excelfile");
            if (excelfile.length === 0) {
                layer.close(formData.closeIndex);
                layer.alert(`请先选择需要上传的文件!`, { icon: sysU.config.iconoError, shadeClose: true, title: sysU.config.titleOpen });
                return false;
            }
            var tableName = $(".fileName");
            for (var i = 0; i < excelfile.length; i++) {
                var isOk = false;
                var excelfileName = "";
                var tableFileName = "";
                for (var xp = 0; xp < tableName.length; xp++) {
                    excelfileName = excelfile[i].name;
                    tableFileName = $(tableName[xp]).text();
                    if (tableFileName == excelfileName) {
                        isOk = true;
                        break;
                    }
                }
                if (!isOk) {
                    layer.alert(`导入的文件名【${excelfileName}】和Excel列表模板名称不一致!`, { icon: sysU.config.iconoError, shadeClose: true, title: sysU.config.titleOpen });
                    layer.close(formData.closeIndex);
                    return false;
                }
            }

            if (callBack != null) callBack();
        },

        //所有动作成功之后
        actionSuccess: (falg) => {

        },
        getFileName:(data) =>{
            return data.substring(0, data.indexOf("."));
        }
    }
    var app = {
        data: {

        },
        methods: {
            initVue: function () {
                vueApp = new Vue({
                    el: '#listForm',
                    data: {
                        contentList: [
                            {  title: "设备管理", href: "../../ExcelTemplate/设备管理.xlsx" },
                            {  title: "工艺路线", href: "../../ExcelTemplate/工艺路线.xlsx" },
                            {  title: "物料信息", href: "../../ExcelTemplate/物料信息.xlsx" },
                            {  title: "人员信息", href: "../../ExcelTemplate/人员信息.xlsx" },
                            {  title: "生产订单", href: "../../ExcelTemplate/生产订单.xlsx" },
                        ]
                    },
                    methods: {

                    }
                });
            },

            initFrom: function () {
            }
        },
        registerEvent: function () {
            //自定义按钮执行公共方法
            system.query();
            system.queryExtend();
        },
        init: function () {
            app.registerEvent();
            app.methods.initVue();
        }
    };
    app.init();
});