#
Junjie
2026-03-10 a637cdb04ab7e0954196ad0d8e7cc24ae22ee93a
#
30个文件已删除
3个文件已添加
79个文件已修改
78390 ■■■■ 已修改文件
src/main/java/com/core/generators/CoolGenerator.java 133 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/common/web/AuthController.java 17 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/utils/DualCrnOperateProcessUtils.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/system/entity/Api.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/system/entity/Host.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/system/entity/OperateLog.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/system/entity/User.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/system/entity/UserLogin.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/templates/Html.txt 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/templates/Js.txt 41 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/apiLog/apiLog.js 2105 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/basCrnp/basCrnp.js 1315 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/basCrnpErr/basCrnpErr.js 1144 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/basCrnpErrLog/basCrnpErrLog.js 1420 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/basCrnpOpt/basCrnpOpt.js 1277 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/basDevp/basDevp.js 2829 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/basDualCrnp/basDualCrnp.js 1353 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/basDualCrnpErr/basDualCrnpErr.js 1144 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/basDualCrnpErrLog/basDualCrnpErrLog.js 1420 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/basDualCrnpOpt/basDualCrnpOpt.js 1277 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/basLocSts/basLocSts.js 1487 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/basMap/basMap.js 1490 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/basRgv/basRgv.js 1163 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/basRgvErr/basRgvErr.js 1144 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/basRgvErrLog/basRgvErrLog.js 1420 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/basRgvOpt/basRgvOpt.js 1277 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/basStation/basStation.js 1492 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/basStationOpt/basStationOpt.js 1277 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/basWrkIotype/basWrkIotype.js 1544 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/basWrkStatus/basWrkStatus.js 1488 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/config/config.js 1923 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/detail/detail.js 247 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/deviceConfig/deviceConfig.js 1375 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/httpRequestLog/httpRequestLog.js 1372 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/locMast/locMast.js 2305 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/login/login.js 270 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/operateLog/operateLog.js 1648 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/password/password.js 169 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/permission/permission.js 842 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/resource/resource.js 825 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/role/role.js 950 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/user/user.js 3573 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/userLogin/userLogin.js 821 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/wrkLastno/wrkLastno.js 1724 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/wrkMastLog/wrkMastLog.js 2564 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/apiLog/apiLog.html 819 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/basCrnp/basCrnp.html 788 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/basCrnp/basCrnp_detail.html 112 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/basCrnpErr/basCrnpErr.html 730 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/basCrnpErr/basCrnpErr_detail.html 102 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/basCrnpErrLog/basCrnpErrLog.html 866 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/basCrnpErrLog/basCrnpErrLog_detail.html 202 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/basCrnpOpt/basCrnpOpt.html 802 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/basCrnpOpt/basCrnpOpt_detail.html 142 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/basDevp/basDevp.html 834 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/basDevp/basDevp_detail.html 112 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/basDualCrnp/basDualCrnp.html 824 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/basDualCrnp/basDualCrnp_detail.html 148 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/basDualCrnpErr/basDualCrnpErr.html 766 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/basDualCrnpErr/basDualCrnpErr_detail.html 102 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/basDualCrnpErrLog/basDualCrnpErrLog.html 866 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/basDualCrnpErrLog/basDualCrnpErrLog_detail.html 202 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/basDualCrnpOpt/basDualCrnpOpt.html 802 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/basDualCrnpOpt/basDualCrnpOpt_detail.html 142 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/basLocSts/basLocSts.html 692 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/basLocSts/basLocSts_detail.html 88 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/basMap/basMap.html 759 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/basMap/basMap_detail.html 90 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/basRgv/basRgv.html 770 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/basRgv/basRgv_detail.html 100 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/basRgvErr/basRgvErr.html 766 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/basRgvErr/basRgvErr_detail.html 102 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/basRgvErrLog/basRgvErrLog.html 866 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/basRgvErrLog/basRgvErrLog_detail.html 202 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/basRgvOpt/basRgvOpt.html 802 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/basRgvOpt/basRgvOpt_detail.html 142 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/basStation/basStation.html 789 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/basStation/basStation_detail.html 118 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/basStationOpt/basStationOpt.html 802 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/basStationOpt/basStationOpt_detail.html 142 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/basWrkIotype/basWrkIotype.html 692 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/basWrkIotype/basWrkIotype_detail.html 94 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/basWrkStatus/basWrkStatus.html 692 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/basWrkStatus/basWrkStatus_detail.html 96 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/config/config.html 707 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/config/config_detail.html 92 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/detail.html 406 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/deviceConfig/deviceConfig.html 770 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/deviceConfig/deviceConfig_detail.html 90 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/httpRequestLog/httpRequestLog.html 751 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/httpRequestLog/httpRequestLog_detail.html 72 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/locMast/locMast.html 806 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/locMast/locMast_detail.html 75 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/login.html 881 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/operateLog/operateLog.html 706 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/operateLog/operateLog_detail.html 87 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/password.html 203 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/permission/permission.html 458 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/permission/permission_detail.html 79 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/resource/resource.html 583 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/role/role.html 375 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/role/role_detail.html 81 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/user/user.html 799 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/user/user_detail.html 87 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/userLogin/userLogin.html 436 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/userLogin/userLogin_detail.html 69 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/watch/console.html 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/wrkLastno/wrkLastno.html 698 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/wrkLastno/wrkLastno_detail.html 78 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/wrkMast/wrkMast.html 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/wrkMastLog/wrkMastLog.html 730 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/wrkMastLog/wrkMastLog_detail.html 196 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/core/generators/CoolGenerator.java
@@ -26,6 +26,8 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class CoolGenerator {
@@ -69,6 +71,7 @@
    private String primaryKeyType;
    private String majorColumn;
    private String systemPackage;
    private Map<String, String> existingFieldLabels = new LinkedHashMap<>();
    public void build() throws Exception {
        init();
@@ -173,6 +176,7 @@
        primaryKeyColumn = resolvePrimaryKeyColumn();
        primaryKeyType = resolvePrimaryKeyType();
        majorColumn = resolveMajorColumn();
        existingFieldLabels = loadExistingFieldLabels();
        entityImport = buildEntityImports();
        entityContent = buildEntityContent();
        xmlContent = buildXmlContent();
@@ -236,7 +240,7 @@
    private static List<Column> getColumns(Connection connection, String table, boolean withForeignKey, SqlOsType sqlOsType) throws Exception {
        List<Column> columns = new ArrayList<>();
        DatabaseMetaData metaData = connection.getMetaData();
        TableRef tableRef = parseTableRef(table);
        TableRef tableRef = resolveTableRef(connection, table, sqlOsType);
        Set<String> primaryKeys = new LinkedHashSet<>();
        ResultSet pkRs = metaData.getPrimaryKeys(tableRef.catalog, tableRef.schema, tableRef.table);
        try {
@@ -247,10 +251,14 @@
            pkRs.close();
        }
        Map<String, Column> uniqueColumns = new LinkedHashMap<>();
        ResultSet columnRs = metaData.getColumns(tableRef.catalog, tableRef.schema, tableRef.table, null);
        try {
            while (columnRs.next()) {
                String columnName = columnRs.getString("COLUMN_NAME");
                if (uniqueColumns.containsKey(columnName)) {
                    continue;
                }
                int sqlType = columnRs.getInt("DATA_TYPE");
                String type = GeneratorUtils.getType(sqlType);
                if (Cools.isEmpty(type)) {
@@ -261,12 +269,13 @@
                boolean mainKey = primaryKey && isAutoIncrement(columnRs);
                boolean notNull = columnRs.getInt("NULLABLE") == DatabaseMetaData.columnNoNulls;
                Integer length = GeneratorUtils.getColumnLength(columnRs.getString("TYPE_NAME"));
                columns.add(new Column(connection, columnName, type, remarks, primaryKey, mainKey, notNull, length,
                uniqueColumns.put(columnName, new Column(connection, columnName, type, remarks, primaryKey, mainKey, notNull, length,
                        withForeignKey, sqlOsType));
            }
        } finally {
            columnRs.close();
        }
        columns.addAll(uniqueColumns.values());
        for (Column column : columns) {
            System.out.println(column.toString());
        }
@@ -281,12 +290,26 @@
        }
    }
    private static TableRef parseTableRef(String table) {
    private static TableRef resolveTableRef(Connection connection, String table, SqlOsType sqlOsType) throws SQLException {
        String catalog = connection.getCatalog();
        String schema = null;
        try {
            schema = connection.getSchema();
        } catch (SQLException ignored) {
        }
        if (table != null && table.contains(".")) {
            String[] arr = table.split("\\.");
            return new TableRef(null, arr[0], arr[arr.length - 1]);
            String scope = arr[0];
            String tableName = arr[arr.length - 1];
            if (sqlOsType == SqlOsType.MYSQL) {
                return new TableRef(scope, null, tableName);
            }
            return new TableRef(catalog, scope, tableName);
        }
        return new TableRef(null, null, table);
        if (sqlOsType == SqlOsType.MYSQL) {
            return new TableRef(catalog, null, table);
        }
        return new TableRef(catalog, schema, table);
    }
    private String resolvePrimaryKeyColumn() {
@@ -606,7 +629,7 @@
            builder.append("    {\n");
            builder.append("        field: '").append(column.getHumpName()).append("',\n");
            builder.append("        columnName: '").append(column.getName()).append("',\n");
            builder.append("        label: '").append(escapeJs(GeneratorUtils.supportHtmlName(column.getComment()))).append("',\n");
            builder.append("        label: '").append(escapeJs(resolveVueFieldLabel(column))).append("',\n");
            builder.append("        tableProp: '").append(resolveDisplayField(column)).append("',\n");
            builder.append("        exportField: '").append(resolveDisplayField(column)).append("',\n");
            builder.append("        kind: '").append(resolveVueFieldKind(column)).append("',\n");
@@ -740,6 +763,104 @@
        return column.getHumpName();
    }
    private String resolveVueFieldLabel(Column column) {
        String label = GeneratorUtils.supportHtmlName(column.getComment());
        if (!Cools.isEmpty(label)) {
            return label;
        }
        label = existingFieldLabels.get(column.getHumpName());
        if (!Cools.isEmpty(label)) {
            return label;
        }
        return buildFallbackLabel(column);
    }
    private String buildFallbackLabel(Column column) {
        String raw = Cools.isEmpty(column.getName()) ? column.getHumpName() : column.getName();
        if (Cools.isEmpty(raw)) {
            return "";
        }
        raw = raw.replace("$", "")
                .replaceAll("([a-z0-9])([A-Z])", "$1 $2")
                .replace("_", " ")
                .replaceAll("\\s+", " ")
                .trim();
        if (Cools.isEmpty(raw)) {
            return "";
        }
        StringBuilder builder = new StringBuilder();
        for (String item : raw.split(" ")) {
            if (item.isEmpty()) {
                continue;
            }
            if (builder.length() > 0) {
                builder.append(" ");
            }
            builder.append(item.substring(0, 1).toUpperCase()).append(item.substring(1));
        }
        return builder.toString();
    }
    private Map<String, String> loadExistingFieldLabels() {
        Map<String, String> labelMap = new LinkedHashMap<>();
        Path jsPath = Paths.get(frontendPrefixPath + "src/main/webapp/static/js/" + simpleEntityName + "/" + simpleEntityName + ".js");
        Path htmlPath = Paths.get(frontendPrefixPath + "src/main/webapp/views/" + simpleEntityName + "/" + simpleEntityName + ".html");
        Path detailPath = Paths.get(frontendPrefixPath + "src/main/webapp/views/" + simpleEntityName + "/" + simpleEntityName + "_detail.html");
        try {
            mergeExistingLabels(labelMap, jsPath, Pattern.compile("field:\\s*'([^']+)'.*?label:\\s*'([^']+)'", Pattern.DOTALL));
            mergeExistingLabels(labelMap, jsPath, Pattern.compile("field:\\s*'([^']+)'[^\\n]*title:\\s*'([^']+)'"));
            mergeExistingLabels(labelMap, detailPath, Pattern.compile("<label[^>]*>(.*?)</label>.*?<(?:(?:input)|(?:select))[^>]*\\sid=\"([^\"]+)\"", Pattern.DOTALL), true);
            mergeExistingLabels(labelMap, htmlPath, Pattern.compile("name=\"([^\"]+)\"[^>]*placeholder=\"([^\"]+)\""));
        } catch (IOException ignored) {
        }
        return labelMap;
    }
    private void mergeExistingLabels(Map<String, String> labelMap, Path path, Pattern pattern) throws IOException {
        mergeExistingLabels(labelMap, path, pattern, false);
    }
    private void mergeExistingLabels(Map<String, String> labelMap, Path path, Pattern pattern, boolean reversed) throws IOException {
        if (path == null || !Files.exists(path)) {
            return;
        }
        String content = Files.readString(path, StandardCharsets.UTF_8);
        Matcher matcher = pattern.matcher(content);
        while (matcher.find()) {
            String field = normalizeExistingField(reversed ? matcher.group(2) : matcher.group(1));
            String label = cleanExistingLabel(reversed ? matcher.group(1) : matcher.group(2));
            if (Cools.isEmpty(field, label) || labelMap.containsKey(field)) {
                continue;
            }
            labelMap.put(field, label);
        }
    }
    private String normalizeExistingField(String field) {
        if (Cools.isEmpty(field)) {
            return "";
        }
        field = field.trim();
        if (field.endsWith("$")) {
            field = field.substring(0, field.length() - 1);
        }
        if (field.contains("_")) {
            return GeneratorUtils._convert(field, true);
        }
        return field;
    }
    private String cleanExistingLabel(String label) {
        if (Cools.isEmpty(label)) {
            return "";
        }
        label = label.replaceAll("<[^>]+>", "")
                .replace(":", "")
                .replace(":", "")
                .trim();
        return label;
    }
    private List<Column> getNonPrimaryColumns() {
        List<Column> result = new ArrayList<>();
        for (Column column : columns) {
src/main/java/com/zy/common/web/AuthController.java
@@ -157,12 +157,14 @@
                    // 是否拥有查看权限
                    if (getUserId() != 9527) {
                        Resource view = resourceService.getOne(new QueryWrapper<Resource>().eq("resource_id", resource.getId()).like("code", "view"));
                        Resource view = firstResource(new QueryWrapper<Resource>()
                                .eq("resource_id", resource.getId())
                                .like("code", "view"));
                        if (!Cools.isEmpty(view)){
                            RoleResource param = new RoleResource();
                            param.setResourceId(view.getId());
                            param.setRoleId(user.getRoleId());
                            if (null == roleResourceService.getOne(new QueryWrapper<>(param))){
                            if (!existsRoleResource(new QueryWrapper<>(param))){
                                continue;
                            }
                        }
@@ -342,5 +344,16 @@
        return R.ok(resources);
    }
    private Resource firstResource(QueryWrapper<Resource> wrapper) {
        wrapper.last("limit 1");
        List<Resource> list = resourceService.list(wrapper);
        return list.isEmpty() ? null : list.get(0);
    }
    private boolean existsRoleResource(QueryWrapper<RoleResource> wrapper) {
        wrapper.last("limit 1");
        return !roleResourceService.list(wrapper).isEmpty();
    }
}
src/main/java/com/zy/core/utils/DualCrnOperateProcessUtils.java
@@ -199,18 +199,19 @@
        WrkMast stationOneWrkMast = null;
        WrkMast stationTwoWrkMast = null;
        List<Integer> disableList = basDualCrnp.getDisableStationOneBays$();
        List<Integer> disableOneList = basDualCrnp.getDisableStationOneBays$();
        List<Integer> disableTwoList = basDualCrnp.getDisableStationTwoBays$();
        for (WrkMast wrkMast : outTaskList) {
            if (stationOneWrkMast == null) {
                if (!disableList.contains(Utils.getBay(wrkMast.getSourceLocNo()))) {
                if (!disableOneList.contains(Utils.getBay(wrkMast.getSourceLocNo()))) {
                    stationOneWrkMast = wrkMast;
                    continue;
                }
            }
            if (stationTwoWrkMast == null) {
                if (!disableList.contains(Utils.getBay(wrkMast.getSourceLocNo()))) {
                if (!disableTwoList.contains(Utils.getBay(wrkMast.getSourceLocNo()))) {
                    stationTwoWrkMast = wrkMast;
                    continue;
                }
src/main/java/com/zy/system/entity/Api.java
@@ -5,6 +5,7 @@
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import com.core.common.Cools;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.text.SimpleDateFormat;
@@ -44,12 +45,14 @@
    /**
     * 添加时间
     */
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @TableField("create_time")
    private Date createTime;
    /**
     * 修改时间
     */
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @TableField("update_time")
    private Date updateTime;
src/main/java/com/zy/system/entity/Host.java
@@ -5,6 +5,7 @@
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import com.core.common.Cools;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.text.SimpleDateFormat;
@@ -34,12 +35,14 @@
    /**
     * 添加时间
     */
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @TableField("create_time")
    private Date createTime;
    /**
     * 修改时间
     */
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @TableField("update_time")
    private Date updateTime;
src/main/java/com/zy/system/entity/OperateLog.java
@@ -7,6 +7,7 @@
import com.core.common.Cools;
import com.core.common.SpringUtils;
import com.zy.system.service.UserService;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.text.SimpleDateFormat;
@@ -52,6 +53,7 @@
    /**
     * 添加时间
     */
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @TableField("create_time")
    private Date createTime;
src/main/java/com/zy/system/entity/User.java
@@ -8,6 +8,7 @@
import com.core.common.SpringUtils;
import com.zy.system.service.HostService;
import com.zy.system.service.RoleService;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.text.SimpleDateFormat;
@@ -56,6 +57,7 @@
    /**
     * 注册时间
     */
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @TableField("create_time")
    private Date createTime;
src/main/java/com/zy/system/entity/UserLogin.java
@@ -7,6 +7,7 @@
import com.core.common.Cools;
import com.core.common.SpringUtils;
import com.zy.system.service.UserService;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.text.SimpleDateFormat;
@@ -37,6 +38,7 @@
    /**
     * 添加时间
     */
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @TableField("create_time")
    private Date createTime;
src/main/resources/templates/Html.txt
@@ -514,6 +514,7 @@
                <div class="table-shell">
                    <el-table
                        ref="dataTable"
                        :key="'table-' + visibleColumnKeys.join('|')"
                        v-loading="loading"
                        :data="tableData"
                        border
@@ -664,6 +665,6 @@
<script type="text/javascript" src="../../static/js/common.js" charset="utf-8"></script>
<script type="text/javascript" src="../../static/vue/js/vue.min.js"></script>
<script type="text/javascript" src="../../static/vue/element/element.js"></script>
<script type="text/javascript" src="../../static/js/@{SIMPLEENTITYNAME}/@{SIMPLEENTITYNAME}.js" charset="utf-8"></script>
<script type="text/javascript" src="../../static/js/@{SIMPLEENTITYNAME}/@{SIMPLEENTITYNAME}.js?v=20260310" charset="utf-8"></script>
</body>
</html>
src/main/resources/templates/Js.txt
@@ -2,9 +2,43 @@
    var simpleEntityName = '@{SIMPLEENTITYNAME}';
    var entityName = '@{ENTITYNAME}';
    var primaryKeyField = '@{PRIMARYKEYCOLUMN0}';
    var fieldMeta = [
    var fieldMeta = dedupeFieldMeta([
@{VUEFIELDMETA}
    ];
    ]);
    function formatFieldLabel(field) {
        var raw = field && field.label ? String(field.label).trim() : '';
        if (raw) {
            return raw;
        }
        raw = field && field.columnName ? field.columnName : (field && field.field ? field.field : '');
        if (!raw) {
            return '';
        }
        raw = String(raw)
            .replace(/\$/g, '')
            .replace(/([a-z0-9])([A-Z])/g, '$1_$2')
            .replace(/_/g, ' ')
            .replace(/\s+/g, ' ')
            .trim();
        return raw.replace(/\b[a-z]/g, function (letter) {
            return letter.toUpperCase();
        });
    }
    function dedupeFieldMeta(list) {
        var result = [];
        var seen = {};
        (list || []).forEach(function (field) {
            if (!field || !field.field || seen[field.field]) {
                return;
            }
            field.label = formatFieldLabel(field);
            seen[field.field] = true;
            result.push(field);
        });
        return result;
    }
    function isEmptyValue(value) {
        return value === null || value === undefined || value === '';
@@ -165,6 +199,9 @@
                }
                return;
            }
            if (field.kind === 'date' && isEmptyValue(value)) {
                return;
            }
            if (field.kind === 'foreign' && isEmptyValue(value)) {
                value = null;
            }
src/main/webapp/static/js/apiLog/apiLog.js
@@ -1,268 +1,1867 @@
var pageCurr;
layui.config({
    base: baseUrl + "/static/layui/lay/modules/"
}).use(['table','laydate', 'form', 'admin'], function(){
    var table = layui.table;
    var $ = layui.jquery;
    var layer = layui.layer;
    var layDate = layui.laydate;
    var form = layui.form;
    var admin = layui.admin;
(function () {
    var simpleEntityName = 'apiLog';
    var entityName = 'ApiLog';
    var primaryKeyField = 'id';
    var fieldMeta = dedupeFieldMeta([
    {
        field: 'id',
        columnName: 'id',
        label: 'ID',
        tableProp: 'id',
        exportField: 'id',
        kind: 'text',
        valueType: 'number',
        required: true,
        primaryKey: true,
        sortable: true,
        textarea: false,
        minWidth: 90,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'uuid',
        columnName: 'uuid',
        label: '日志编号',
        tableProp: 'uuid',
        exportField: 'uuid',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'namespace',
        columnName: 'namespace',
        label: '名称空间',
        tableProp: 'namespace',
        exportField: 'namespace',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'url',
        columnName: 'url',
        label: '接口地址',
        tableProp: 'url',
        exportField: 'url',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'appkey',
        columnName: 'appkey',
        label: '平台密钥',
        tableProp: 'appkey',
        exportField: 'appkey',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'timestamp',
        columnName: 'timestamp',
        label: '时间戳',
        tableProp: 'timestamp',
        exportField: 'timestamp',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'clientIp',
        columnName: 'client_ip',
        label: '客户端IP',
        tableProp: 'clientIp',
        exportField: 'clientIp',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'request',
        columnName: 'request',
        label: '请求内容',
        tableProp: 'request',
        exportField: 'request',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: true,
        minWidth: 180,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'response',
        columnName: 'response',
        label: '响应内容',
        tableProp: 'response',
        exportField: 'response',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: true,
        minWidth: 180,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'err',
        columnName: 'err',
        label: '异常内容',
        tableProp: 'err',
        exportField: 'err',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'result',
        columnName: 'result',
        label: '结果',
        tableProp: 'result',
        exportField: 'result',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'status',
        columnName: 'status',
        label: '状态',
        tableProp: 'status',
        exportField: 'status',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'createTime',
        columnName: 'create_time',
        label: '添加时间',
        tableProp: 'createTime$',
        exportField: 'createTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'updateTime',
        columnName: 'update_time',
        label: '修改时间',
        tableProp: 'updateTime$',
        exportField: 'updateTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'memo',
        columnName: 'memo',
        label: '备注',
        tableProp: 'memo',
        exportField: 'memo',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: true,
        minWidth: 180,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'id',
        columnName: 'id',
        label: 'ID',
        tableProp: 'id',
        exportField: 'id',
        kind: 'text',
        valueType: 'number',
        required: true,
        primaryKey: true,
        sortable: true,
        textarea: false,
        minWidth: 90,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'uuid',
        columnName: 'uuid',
        label: '日志编号',
        tableProp: 'uuid',
        exportField: 'uuid',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'namespace',
        columnName: 'namespace',
        label: '名称空间',
        tableProp: 'namespace',
        exportField: 'namespace',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'url',
        columnName: 'url',
        label: '接口地址',
        tableProp: 'url',
        exportField: 'url',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'appkey',
        columnName: 'appkey',
        label: '平台密钥',
        tableProp: 'appkey',
        exportField: 'appkey',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'timestamp',
        columnName: 'timestamp',
        label: '时间戳',
        tableProp: 'timestamp',
        exportField: 'timestamp',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'clientIp',
        columnName: 'client_ip',
        label: '客户端IP',
        tableProp: 'clientIp',
        exportField: 'clientIp',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'request',
        columnName: 'request',
        label: '请求内容',
        tableProp: 'request',
        exportField: 'request',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: true,
        minWidth: 180,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'response',
        columnName: 'response',
        label: '响应内容',
        tableProp: 'response',
        exportField: 'response',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: true,
        minWidth: 180,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'err',
        columnName: 'err',
        label: '异常内容',
        tableProp: 'err',
        exportField: 'err',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'result',
        columnName: 'result',
        label: '结果',
        tableProp: 'result',
        exportField: 'result',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'status',
        columnName: 'status',
        label: '状态',
        tableProp: 'status',
        exportField: 'status',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'createTime',
        columnName: 'create_time',
        label: '添加时间',
        tableProp: 'createTime$',
        exportField: 'createTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'updateTime',
        columnName: 'update_time',
        label: '修改时间',
        tableProp: 'updateTime$',
        exportField: 'updateTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'memo',
        columnName: 'memo',
        label: '备注',
        tableProp: 'memo',
        exportField: 'memo',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: true,
        minWidth: 180,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'id',
        columnName: 'id',
        label: 'ID',
        tableProp: 'id',
        exportField: 'id',
        kind: 'text',
        valueType: 'number',
        required: true,
        primaryKey: true,
        sortable: true,
        textarea: false,
        minWidth: 90,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'uuid',
        columnName: 'uuid',
        label: '日志编号',
        tableProp: 'uuid',
        exportField: 'uuid',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'namespace',
        columnName: 'namespace',
        label: '名称空间',
        tableProp: 'namespace',
        exportField: 'namespace',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'url',
        columnName: 'url',
        label: '接口地址',
        tableProp: 'url',
        exportField: 'url',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'appkey',
        columnName: 'appkey',
        label: '平台密钥',
        tableProp: 'appkey',
        exportField: 'appkey',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'timestamp',
        columnName: 'timestamp',
        label: '时间戳',
        tableProp: 'timestamp',
        exportField: 'timestamp',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'clientIp',
        columnName: 'client_ip',
        label: '客户端IP',
        tableProp: 'clientIp',
        exportField: 'clientIp',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'request',
        columnName: 'request',
        label: '请求内容',
        tableProp: 'request',
        exportField: 'request',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: true,
        minWidth: 180,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'response',
        columnName: 'response',
        label: '响应内容',
        tableProp: 'response',
        exportField: 'response',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: true,
        minWidth: 180,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'err',
        columnName: 'err',
        label: '异常内容',
        tableProp: 'err',
        exportField: 'err',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'result',
        columnName: 'result',
        label: '结果',
        tableProp: 'result',
        exportField: 'result',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'status',
        columnName: 'status',
        label: '状态',
        tableProp: 'status',
        exportField: 'status',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'createTime',
        columnName: 'create_time',
        label: '添加时间',
        tableProp: 'createTime$',
        exportField: 'createTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'updateTime',
        columnName: 'update_time',
        label: '修改时间',
        tableProp: 'updateTime$',
        exportField: 'updateTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'memo',
        columnName: 'memo',
        label: '备注',
        tableProp: 'memo',
        exportField: 'memo',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: true,
        minWidth: 180,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'id',
        columnName: 'id',
        label: 'ID',
        tableProp: 'id',
        exportField: 'id',
        kind: 'text',
        valueType: 'number',
        required: true,
        primaryKey: true,
        sortable: true,
        textarea: false,
        minWidth: 90,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'uuid',
        columnName: 'uuid',
        label: '日志编号',
        tableProp: 'uuid',
        exportField: 'uuid',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'namespace',
        columnName: 'namespace',
        label: '名称空间',
        tableProp: 'namespace',
        exportField: 'namespace',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'url',
        columnName: 'url',
        label: '接口地址',
        tableProp: 'url',
        exportField: 'url',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'appkey',
        columnName: 'appkey',
        label: '平台密钥',
        tableProp: 'appkey',
        exportField: 'appkey',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'timestamp',
        columnName: 'timestamp',
        label: '时间戳',
        tableProp: 'timestamp',
        exportField: 'timestamp',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'clientIp',
        columnName: 'client_ip',
        label: '客户端IP',
        tableProp: 'clientIp',
        exportField: 'clientIp',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'request',
        columnName: 'request',
        label: '请求内容',
        tableProp: 'request',
        exportField: 'request',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: true,
        minWidth: 180,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'response',
        columnName: 'response',
        label: '响应内容',
        tableProp: 'response',
        exportField: 'response',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: true,
        minWidth: 180,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'err',
        columnName: 'err',
        label: '异常内容',
        tableProp: 'err',
        exportField: 'err',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'result',
        columnName: 'result',
        label: '结果',
        tableProp: 'result',
        exportField: 'result',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'status',
        columnName: 'status',
        label: '状态',
        tableProp: 'status',
        exportField: 'status',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'createTime',
        columnName: 'create_time',
        label: '添加时间',
        tableProp: 'createTime$',
        exportField: 'createTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'updateTime',
        columnName: 'update_time',
        label: '修改时间',
        tableProp: 'updateTime$',
        exportField: 'updateTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'memo',
        columnName: 'memo',
        label: '备注',
        tableProp: 'memo',
        exportField: 'memo',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: true,
        minWidth: 180,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    }
    // 数据渲染
    tableIns = table.render({
        elem: '#apiLog',
        headers: {token: localStorage.getItem('token')},
        url: baseUrl+'/apiLog/list/auth',
        page: true,
        limit: 15,
        limits: [15, 30, 50, 100, 200, 500],
        toolbar: '#toolbar',
        cellMinWidth: 50,
        height: 'full-120',
        cols: [[
            {type: 'checkbox'}
            // ,{field: 'id', align: 'center',title: 'ID'}
            // ,{field: 'uuid', align: 'center',title: '日志编号'}
            ,{field: 'namespace', align: 'center',title: '名称空间'}
            ,{field: 'url', align: 'center',title: '接口地址'}
            // ,{field: 'appkey', align: 'center',title: '平台密钥'}
            // ,{field: 'timestamp', align: 'center',title: '时间戳'}
            // ,{field: 'clientIp', align: 'center',title: '客户端IP'}
            ,{field: 'request', align: 'center',title: '请求内容'}
            ,{field: 'response', align: 'center',title: '响应内容'}
            // ,{field: 'err', align: 'center',title: '异常内容'}
            ,{field: 'result$', align: 'center',title: '结果', templet: '#resTpl', width: 80}
            // ,{field: 'status$', align: 'center',title: '状态'}
            ,{field: 'createTime$', align: 'center',title: '添加时间'}
            // ,{field: 'updateTime$', align: 'center',title: '修改时间'}
            ,{field: 'memo', align: 'center',title: '备注', hide: true}
    ]);
            ,{fixed: 'right', title:'操作', align: 'center', toolbar: '#operate', width: 80}
        ]],
        request: {
            pageName: 'curr',
            pageSize: 'limit'
        },
        parseData: function (res) {
            return {
                'code': res.code,
                'msg': res.msg,
                'count': res.data.total,
                'data': res.data.records
            }
        },
        response: {
            statusCode: 200
        },
        done: function(res, curr, count) {
            if (res.code === 403) {
                top.location.href = baseUrl+"/";
            }
            pageCurr=curr;
            limit();
    function formatFieldLabel(field) {
        var raw = field && field.label ? String(field.label).trim() : '';
        if (raw) {
            return raw;
        }
    });
    // 监听排序事件
    table.on('sort(apiLog)', function (obj) {
        var searchData = {};
        $.each($('#search-box [name]').serializeArray(), function() {
            searchData[this.name] = this.value;
        });
        searchData['orderByField'] = obj.field;
        searchData['orderByType'] = obj.type;
        tableIns.reload({
            where: searchData,
            page: {curr: 1}
        });
    });
    // 监听头工具栏事件
    table.on('toolbar(apiLog)', function (obj) {
        var checkStatus = table.checkStatus(obj.config.id).data;
        switch(obj.event) {
            case 'addData':
                showEditModel();
                break;
            case 'deleteData':
               if (checkStatus.length === 0) {
                   layer.msg('请选择要删除的数据', {icon: 2});
                   return;
               }
               del(checkStatus.map(function (d) {
                   return d.id;
               }));
               break;
            case 'exportData':
                admin.confirm('确定导出Excel吗', {shadeClose: true}, function(){
                    var titles=[];
                    var fields=[];
                    obj.config.cols[0].map(function (col) {
                        if (col.type === 'normal' && col.hide === false && col.toolbar == null) {
                            titles.push(col.title);
                            fields.push(col.field);
                        }
                    });
                    var exportData = {};
                    $.each($('#search-box [name]').serializeArray(), function() {
                        exportData[this.name] = this.value;
                    });
                    var param = {
                        'apiLog': exportData,
                        'fields': fields
                    };
                    $.ajax({
                        url: baseUrl+"/apiLog/export/auth",
                        headers: {'token': localStorage.getItem('token')},
                        data: JSON.stringify(param),
                        dataType:'json',
                        contentType:'application/json;charset=UTF-8',
                        method: 'POST',
                        success: function (res) {
                            layer.closeAll();
                            if (res.code === 200) {
                                table.exportFile(titles,res.data,'xls');
                            } else if (res.code === 403) {
                                top.location.href = baseUrl+"/";
                            } else {
                                layer.msg(res.msg, {icon: 2})
                            }
                        }
                    });
                });
                break;
        raw = field && field.columnName ? field.columnName : (field && field.field ? field.field : '');
        if (!raw) {
            return '';
        }
    });
    // 监听行工具事件
    table.on('tool(apiLog)', function(obj){
        var data = obj.data;
        switch (obj.event) {
            case 'edit':
                showEditModel(data);
                break;
            case "del":
                del([data.id]);
                break;
        }
    });
    /* 弹窗 - 新增、修改 */
    function showEditModel(mData) {
        admin.open({
            type: 1,
            area: '600px',
            title: (mData ? '修改' : '添加') + '订单状态',
            content: $('#editDialog').html(),
            success: function (layero, dIndex) {
                layDateRender(mData);
                form.val('detail', mData);
                form.on('submit(editSubmit)', function (data) {
                    var loadIndex = layer.load(2);
                    $.ajax({
                        url: baseUrl+"/apiLog/"+(mData?'update':'add')+"/auth",
                        headers: {'token': localStorage.getItem('token')},
                        data: data.field,
                        method: 'POST',
                        success: function (res) {
                            layer.close(loadIndex);
                            if (res.code === 200){
                                layer.close(dIndex);
                                layer.msg(res.msg, {icon: 1});
                                tableReload();
                            } else if (res.code === 403){
                                top.location.href = baseUrl+"/";
                            }else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }
                    })
                    return false;
                });
                $(layero).children('.layui-layer-content').css('overflow', 'visible');
                layui.form.render('select');
            }
        raw = String(raw)
            .replace(/\$/g, '')
            .replace(/([a-z0-9])([A-Z])/g, '$1_$2')
            .replace(/_/g, ' ')
            .replace(/\s+/g, ' ')
            .trim();
        return raw.replace(/\b[a-z]/g, function (letter) {
            return letter.toUpperCase();
        });
    }
    /* 删除 */
    function del(ids) {
        layer.confirm('确定要删除选中数据吗?', {
            skin: 'layui-layer-admin',
            shade: .1
        }, function (i) {
            layer.close(i);
            var loadIndex = layer.load(2);
    function dedupeFieldMeta(list) {
        var result = [];
        var seen = {};
        (list || []).forEach(function (field) {
            if (!field || !field.field || seen[field.field]) {
                return;
            }
            field.label = formatFieldLabel(field);
            seen[field.field] = true;
            result.push(field);
        });
        return result;
    }
    function isEmptyValue(value) {
        return value === null || value === undefined || value === '';
    }
    function stringValue(value) {
        return isEmptyValue(value) ? '' : String(value);
    }
    function valueOrDash(value) {
        return isEmptyValue(value) ? '--' : value;
    }
    function normalizeOptionValue(field, rawValue) {
        if (rawValue === null || rawValue === undefined) {
            return null;
        }
        if (rawValue === '') {
            return '';
        }
        if (field && field.valueType === 'number') {
            var numberVal = Number(rawValue);
            return isNaN(numberVal) ? rawValue : numberVal;
        }
        return String(rawValue);
    }
    function isSearchableField(field) {
        return !!field && field.kind !== 'image' && !field.textarea;
    }
    function isSortableField(field) {
        if (!field) {
            return false;
        }
        if (field.primaryKey) {
            return true;
        }
        return field.kind !== 'image' && !field.textarea && field.kind !== 'foreign';
    }
    function defaultFieldValue(field) {
        if (field.primaryKey) {
            return null;
        }
        if (field.kind === 'checkbox') {
            return normalizeOptionValue(field, field.checkboxInactiveRaw);
        }
        return '';
    }
    function defaultSearchFieldValue(field) {
        if (field.kind === 'date') {
            return [];
        }
        if (field.kind === 'enum' || field.kind === 'checkbox') {
            return null;
        }
        return '';
    }
    function createSearchDefaults() {
        var result = {
            condition: ''
        };
        fieldMeta.forEach(function (field) {
            if (!isSearchableField(field)) {
                return;
            }
            result[field.field] = defaultSearchFieldValue(field);
        });
        return result;
    }
    function createSearchDisplayDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            if (field.kind === 'foreign' && isSearchableField(field)) {
                result[field.field] = '';
            }
        });
        return result;
    }
    function createDefaultVisibleColumnKeys() {
        return fieldMeta.map(function (field) {
            return field.field;
        });
    }
    function createFormDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            result[field.field] = defaultFieldValue(field);
        });
        return result;
    }
    function createDisplayDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            if (field.kind === 'foreign') {
                result[field.field] = '';
            }
        });
        return result;
    }
    function createFormRules() {
        var rules = {};
        fieldMeta.forEach(function (field) {
            if (field.primaryKey || !field.required) {
                return;
            }
            rules[field.field] = [{
                required: true,
                message: (field.kind === 'date' || field.kind === 'enum' ? '请选择' : '请输入') + field.label,
                trigger: (field.kind === 'date' || field.kind === 'enum') ? 'change' : 'blur'
            }];
        });
        return rules;
    }
    function getTableValue(row, field) {
        var prop = field.tableProp || field.field;
        if (row && !isEmptyValue(row[prop])) {
            return row[prop];
        }
        return row ? row[field.field] : '';
    }
    function isCheckboxChecked(row, field) {
        var value = row ? row[field.field] : null;
        var activeValue = normalizeOptionValue(field, field.checkboxActiveRaw);
        return String(value) === String(activeValue);
    }
    function exportCell(value) {
        return stringValue(value).replace(/\t/g, ' ').replace(/\r?\n/g, ' ');
    }
    function escapeHtml(value) {
        return exportCell(value)
            .replace(/&/g, '&amp;')
            .replace(/</g, '&lt;')
            .replace(/>/g, '&gt;')
            .replace(/"/g, '&quot;')
            .replace(/'/g, '&#39;');
    }
    function buildPayload(form) {
        var payload = {};
        fieldMeta.forEach(function (field) {
            var value = form[field.field];
            if (field.primaryKey) {
                if (!isEmptyValue(value)) {
                    payload[field.field] = value;
                }
                return;
            }
            if (field.kind === 'foreign' && isEmptyValue(value)) {
                value = null;
            }
            if (field.kind === 'enum' && value === '') {
                value = null;
            }
            if (field.kind === 'checkbox' && isEmptyValue(value)) {
                value = normalizeOptionValue(field, field.checkboxInactiveRaw);
            }
            if (field.valueType === 'number' && !isEmptyValue(value)) {
                value = Number(value);
            }
            if (field.valueType === 'number' && value === '') {
                value = null;
            }
            payload[field.field] = value;
        });
        return payload;
    }
    function fillFormFromRow(row, form, display) {
        fieldMeta.forEach(function (field) {
            if (field.primaryKey) {
                form[field.field] = row[field.field];
                return;
            }
            if (field.kind === 'date') {
                form[field.field] = row[field.tableProp] || row[field.field] || '';
                return;
            }
            if (field.kind === 'foreign') {
                form[field.field] = isEmptyValue(row[field.field]) ? '' : normalizeOptionValue(field, row[field.field]);
                if (display) {
                    display[field.field] = row[field.tableProp] || (isEmptyValue(row[field.field]) ? '' : String(row[field.field]));
                }
                return;
            }
            if (field.kind === 'enum') {
                form[field.field] = isEmptyValue(row[field.field]) ? '' : normalizeOptionValue(field, row[field.field]);
                return;
            }
            if (field.kind === 'checkbox') {
                form[field.field] = isEmptyValue(row[field.field])
                    ? normalizeOptionValue(field, field.checkboxInactiveRaw)
                    : normalizeOptionValue(field, row[field.field]);
                return;
            }
            form[field.field] = isEmptyValue(row[field.field])
                ? ''
                : (field.valueType === 'number' ? String(row[field.field]) : row[field.field]);
        });
    }
    function resolveSearchParam(field) {
        if (field.kind === 'date' && field.columnName) {
            return field.columnName;
        }
        return field.field;
    }
    function createDownloadFile(filename, titles, rows) {
        var html = [
            '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">',
            '<head><meta charset="UTF-8"></head><body><table border="1"><thead><tr>',
            titles.map(function (title) {
                return '<th>' + escapeHtml(title) + '</th>';
            }).join(''),
            '</tr></thead><tbody>',
            (rows || []).map(function (row) {
                return '<tr>' + (row || []).map(function (value) {
                    return '<td style="mso-number-format:\\@;">' + escapeHtml(value) + '</td>';
                }).join('') + '</tr>';
            }).join(''),
            '</tbody></table></body></html>'
        ].join('');
        var blob = new Blob(['\ufeff' + html], {
            type: 'application/vnd.ms-excel;charset=utf-8;'
        });
        var anchor = document.createElement('a');
        anchor.href = URL.createObjectURL(blob);
        anchor.download = filename;
        document.body.appendChild(anchor);
        anchor.click();
        setTimeout(function () {
            URL.revokeObjectURL(anchor.href);
            document.body.removeChild(anchor);
        }, 0);
    }
    function buildTimestamp() {
        var now = new Date();
        var pad = function (num) {
            return num < 10 ? '0' + num : String(num);
        };
        return now.getFullYear()
            + pad(now.getMonth() + 1)
            + pad(now.getDate())
            + '_'
            + pad(now.getHours())
            + pad(now.getMinutes())
            + pad(now.getSeconds());
    }
    function authHeaders() {
        return {
            token: localStorage.getItem('token')
        };
    }
    function handleForbidden(res) {
        if (res && res.code === 403) {
            top.location.href = baseUrl + '/';
            return true;
        }
        return false;
    }
    var sharedMethods = {
        authHeaders: authHeaders,
        handleForbidden: handleForbidden,
        valueOrDash: valueOrDash,
        stringValue: stringValue,
        getTableValue: getTableValue,
        isCheckboxChecked: isCheckboxChecked,
        normalizeOptionValue: normalizeOptionValue,
        isSortableField: isSortableField,
        getSuggestionFetcher: function (field) {
            var self = this;
            return function (queryString, callback) {
                self.fetchForeignSuggestions(field, queryString, callback);
            };
        },
        fetchForeignSuggestions: function (field, queryString, callback) {
            if (!field.foreignQuery || !queryString) {
                callback([]);
                return;
            }
            var self = this;
            $.ajax({
                url: baseUrl+"/apiLog/delete/auth",
                headers: {'token': localStorage.getItem('token')},
                data: {ids: ids},
                method: 'POST',
                url: baseUrl + '/' + field.foreignQuery + 'Query/auth',
                method: 'GET',
                headers: self.authHeaders(),
                data: { condition: queryString },
                success: function (res) {
                    layer.close(loadIndex);
                    if (res.code === 200){
                        layer.msg(res.msg, {icon: 1});
                        tableReload();
                    } else if (res.code === 403){
                        top.location.href = baseUrl+"/";
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    if (self.handleForbidden(res)) {
                        return;
                    }
                    if (!res || res.code !== 200 || !Array.isArray(res.data)) {
                        callback([]);
                        return;
                    }
                    callback(res.data.map(function (item) {
                        return {
                            id: item.id,
                            value: item.value
                        };
                    }));
                },
                error: function () {
                    callback([]);
                }
            });
        },
        handleForeignSelect: function (field, item) {
            this.$set(this.displayTarget, field.field, item && item.value ? item.value : '');
            this.$set(this.formTarget, field.field, item && item.id !== undefined ? normalizeOptionValue(field, item.id) : '');
        },
        handleForeignInput: function (field) {
            if (!this.displayTarget || !this.formTarget) {
                return;
            }
            if (this.displayTarget[field.field]) {
                return;
            }
            this.$set(this.formTarget, field.field, '');
        }
    };
    if (document.getElementById('app')) {
        new Vue({
            el: '#app',
            data: function () {
                return {
                    fieldMeta: fieldMeta,
                    primaryKeyField: primaryKeyField,
                    loading: false,
                    exporting: false,
                    tableData: [],
                    selection: [],
                    advancedFiltersVisible: false,
                    allColumns: fieldMeta.slice(),
                    visibleColumnKeys: createDefaultVisibleColumnKeys(),
                    searchForm: createSearchDefaults(),
                    searchDisplay: createSearchDisplayDefaults(),
                    page: {
                        curr: 1,
                        limit: 15,
                        total: 0
                    },
                    sortState: {
                        prop: '',
                        order: ''
                    },
                    dialog: {
                        visible: false,
                        mode: 'create',
                        submitting: false
                    },
                    layoutTimer: null,
                    tableResizeHandler: null,
                    dialogForm: createFormDefaults(),
                    dialogDisplay: createDisplayDefaults(),
                    dialogRules: createFormRules()
                };
            },
            computed: {
                searchableFields: function () {
                    return this.fieldMeta.filter(function (field) {
                        return isSearchableField(field);
                    });
                },
                quickSearchableFields: function () {
                    var result = [];
                    this.searchableFields.forEach(function (field) {
                        if (result.length >= 3 || field.kind === 'date') {
                            return;
                        }
                        result.push(field);
                    });
                    return result;
                },
                advancedSearchableFields: function () {
                    var quickKeys = this.quickSearchableFields.map(function (field) {
                        return field.field;
                    });
                    return this.searchableFields.filter(function (field) {
                        return quickKeys.indexOf(field.field) === -1;
                    });
                },
                hasAdvancedFilters: function () {
                    return this.advancedSearchableFields.length > 0;
                },
                visibleColumns: function () {
                    var keys = this.visibleColumnKeys;
                    return this.allColumns.filter(function (field) {
                        return keys.indexOf(field.field) !== -1;
                    });
                },
                editableFields: function () {
                    return this.fieldMeta.filter(function (field) {
                        return !field.primaryKey;
                    });
                },
                exportColumns: function () {
                    return this.visibleColumns.map(function (field) {
                        return {
                            field: field.exportField || field.tableProp || field.field,
                            label: field.label
                        };
                    });
                },
                tableHeight: function () {
                    return this.advancedFiltersVisible && this.hasAdvancedFilters
                        ? 'calc(100vh - 390px)'
                        : 'calc(100vh - 300px)';
                },
                formTarget: function () {
                    return this.dialogForm;
                },
                displayTarget: function () {
                    return this.dialogDisplay;
                }
            },
            created: function () {
                this.loadTable();
            },
            mounted: function () {
                var self = this;
                self.requestTableLayout(80);
                self.tableResizeHandler = function () {
                    self.requestTableLayout(80);
                };
                window.addEventListener('resize', self.tableResizeHandler);
            },
            beforeDestroy: function () {
                if (this.layoutTimer) {
                    clearTimeout(this.layoutTimer);
                    this.layoutTimer = null;
                }
                if (this.tableResizeHandler) {
                    window.removeEventListener('resize', this.tableResizeHandler);
                    this.tableResizeHandler = null;
                }
            },
            methods: $.extend({}, sharedMethods, {
                requestTableLayout: function (delay) {
                    var self = this;
                    if (self.layoutTimer) {
                        clearTimeout(self.layoutTimer);
                    }
                    self.$nextTick(function () {
                        self.layoutTimer = setTimeout(function () {
                            var table = self.$refs.dataTable;
                            if (table && typeof table.doLayout === 'function') {
                                table.doLayout();
                            }
                        }, delay || 40);
                    });
                },
                isColumnVisible: function (fieldName) {
                    return this.visibleColumnKeys.indexOf(fieldName) !== -1;
                },
                toggleColumn: function (fieldName, visible) {
                    if (visible) {
                        if (this.visibleColumnKeys.indexOf(fieldName) === -1) {
                            this.visibleColumnKeys.push(fieldName);
                        }
                        this.requestTableLayout(80);
                        return;
                    }
                    if (this.visibleColumnKeys.length === 1) {
                        this.$message.warning('至少保留一列');
                        return;
                    }
                    this.visibleColumnKeys = this.visibleColumnKeys.filter(function (item) {
                        return item !== fieldName;
                    });
                    this.requestTableLayout(80);
                },
                selectAllColumns: function () {
                    this.visibleColumnKeys = createDefaultVisibleColumnKeys();
                    this.requestTableLayout(80);
                },
                resetColumns: function () {
                    this.visibleColumnKeys = createDefaultVisibleColumnKeys();
                    this.requestTableLayout(80);
                },
                toggleAdvancedFilters: function () {
                    this.advancedFiltersVisible = !this.advancedFiltersVisible;
                    this.requestTableLayout(260);
                },
                handleSearchForeignSelect: function (field, item) {
                    this.$set(this.searchDisplay, field.field, item && item.value ? item.value : '');
                    this.$set(this.searchForm, field.field, item && item.id !== undefined ? normalizeOptionValue(field, item.id) : '');
                },
                handleSearchForeignInput: function (field) {
                    if (this.searchDisplay[field.field]) {
                        return;
                    }
                    this.$set(this.searchForm, field.field, '');
                },
                buildQueryParams: function () {
                    var self = this;
                    var params = {
                        curr: self.page.curr,
                        limit: self.page.limit
                    };
                    if (self.searchForm.condition) {
                        params.condition = self.searchForm.condition;
                    }
                    self.searchableFields.forEach(function (field) {
                        var value = self.searchForm[field.field];
                        if (field.kind === 'date') {
                            if (value && value.length === 2) {
                                params[resolveSearchParam(field)] = value[0] + ' - ' + value[1];
                            }
                            return;
                        }
                        if (!isEmptyValue(value)) {
                            params[resolveSearchParam(field)] = value;
                        }
                    });
                    if (self.sortState.prop && self.sortState.order) {
                        params.orderByField = self.sortState.prop;
                        params.orderByType = self.sortState.order === 'ascending' ? 'asc' : 'desc';
                    }
                    return params;
                },
                loadTable: function () {
                    var self = this;
                    self.loading = true;
                    $.ajax({
                        url: baseUrl + '/' + simpleEntityName + '/list/auth',
                        method: 'GET',
                        headers: self.authHeaders(),
                        data: self.buildQueryParams(),
                        success: function (res) {
                            self.loading = false;
                            if (self.handleForbidden(res)) {
                                return;
                            }
                            if (!res || res.code !== 200) {
                                self.$message.error((res && res.msg) ? res.msg : '加载失败');
                                return;
                            }
                            var payload = res.data || {};
                            self.tableData = Array.isArray(payload.records) ? payload.records : [];
                            self.page.total = payload.total || 0;
                            self.requestTableLayout(80);
                        },
                        error: function () {
                            self.loading = false;
                            self.requestTableLayout(80);
                            self.$message.error('加载失败');
                        }
                    });
                },
                handleSearch: function () {
                    this.page.curr = 1;
                    this.loadTable();
                },
                handleReset: function () {
                    this.searchForm = createSearchDefaults();
                    this.searchDisplay = createSearchDisplayDefaults();
                    this.advancedFiltersVisible = false;
                    this.page.curr = 1;
                    this.sortState = {
                        prop: '',
                        order: ''
                    };
                    this.loadTable();
                },
                handleSelectionChange: function (rows) {
                    this.selection = rows || [];
                },
                handleSortChange: function (payload) {
                    this.sortState = {
                        prop: payload && payload.prop ? payload.prop : '',
                        order: payload && payload.order ? payload.order : ''
                    };
                    this.page.curr = 1;
                    this.loadTable();
                },
                handleCurrentChange: function (curr) {
                    this.page.curr = curr;
                    this.loadTable();
                },
                handleSizeChange: function (limit) {
                    this.page.limit = limit;
                    this.page.curr = 1;
                    this.loadTable();
                },
                resetDialogState: function () {
                    this.dialogForm = createFormDefaults();
                    this.dialogDisplay = createDisplayDefaults();
                    if (this.$refs.dialogForm) {
                        this.$refs.dialogForm.clearValidate();
                    }
                },
                openCreateDialog: function () {
                    this.dialog.mode = 'create';
                    this.dialog.visible = true;
                    this.$nextTick(this.resetDialogState);
                },
                openEditDialog: function (row) {
                    var self = this;
                    self.dialog.mode = 'edit';
                    self.dialog.visible = true;
                    self.$nextTick(function () {
                        self.resetDialogState();
                        fillFormFromRow(row, self.dialogForm, self.dialogDisplay);
                        if (self.$refs.dialogForm) {
                            self.$refs.dialogForm.clearValidate();
                        }
                    });
                },
                submitDialog: function () {
                    var self = this;
                    if (!self.$refs.dialogForm) {
                        return;
                    }
                    self.$refs.dialogForm.validate(function (valid) {
                        if (!valid) {
                            return false;
                        }
                        self.dialog.submitting = true;
                        $.ajax({
                            url: baseUrl + '/' + simpleEntityName + '/' + (self.dialog.mode === 'create' ? 'add' : 'update') + '/auth',
                            method: 'POST',
                            headers: self.authHeaders(),
                            data: buildPayload(self.dialogForm),
                            success: function (res) {
                                self.dialog.submitting = false;
                                if (self.handleForbidden(res)) {
                                    return;
                                }
                                if (!res || res.code !== 200) {
                                    self.$message.error((res && res.msg) ? res.msg : '保存失败');
                                    return;
                                }
                                self.$message.success(res.msg || '保存成功');
                                self.dialog.visible = false;
                                self.loadTable();
                            },
                            error: function () {
                                self.dialog.submitting = false;
                                self.$message.error('保存失败');
                            }
                        });
                        return true;
                    });
                },
                removeSelection: function () {
                    var self = this;
                    var ids = self.selection.map(function (row) {
                        return row[self.primaryKeyField];
                    });
                    self.removeRows(ids);
                },
                removeRows: function (ids) {
                    var self = this;
                    if (!ids || ids.length === 0) {
                        self.$message.warning('请选择要删除的数据');
                        return;
                    }
                    self.$confirm('确定删除选中的记录吗?', '提示', { type: 'warning' }).then(function () {
                        $.ajax({
                            url: baseUrl + '/' + simpleEntityName + '/delete/auth',
                            method: 'POST',
                            headers: self.authHeaders(),
                            traditional: true,
                            data: { 'ids[]': ids },
                            success: function (res) {
                                if (self.handleForbidden(res)) {
                                    return;
                                }
                                if (!res || res.code !== 200) {
                                    self.$message.error((res && res.msg) ? res.msg : '删除失败');
                                    return;
                                }
                                self.$message.success(res.msg || '删除成功');
                                self.selection = [];
                                if (self.tableData.length === ids.length && self.page.curr > 1) {
                                    self.page.curr = self.page.curr - 1;
                                }
                                self.loadTable();
                            },
                            error: function () {
                                self.$message.error('删除失败');
                            }
                        });
                    }).catch(function () {});
                },
                exportRows: function () {
                    var self = this;
                    self.exporting = true;
                    var requestBody = {
                        fields: self.exportColumns.map(function (item) {
                            return item.field;
                        })
                    };
                    requestBody[simpleEntityName] = self.buildQueryParams();
                    $.ajax({
                        url: baseUrl + '/' + simpleEntityName + '/export/auth',
                        method: 'POST',
                        headers: $.extend({ 'Content-Type': 'application/json;charset=UTF-8' }, self.authHeaders()),
                        data: JSON.stringify(requestBody),
                        success: function (res) {
                            self.exporting = false;
                            if (self.handleForbidden(res)) {
                                return;
                            }
                            if (!res || res.code !== 200) {
                                self.$message.error((res && res.msg) ? res.msg : '导出失败');
                                return;
                            }
                            createDownloadFile(
                                simpleEntityName + '_' + buildTimestamp() + '.xls',
                                self.exportColumns.map(function (item) {
                                    return item.label;
                                }),
                                Array.isArray(res.data) ? res.data : []
                            );
                            self.$message.success('导出成功');
                        },
                        error: function () {
                            self.exporting = false;
                            self.$message.error('导出失败');
                        }
                    });
                }
            })
        });
    }
    // 搜索
    form.on('submit(search)', function (data) {
        pageCurr = 1;
        tableReload(false);
    });
    // 重置
    form.on('submit(reset)', function (data) {
        pageCurr = 1;
        clearFormVal($('#search-box'));
        tableReload(false);
    });
    // 时间选择器
    function layDateRender(data) {
        setTimeout(function () {
            layDate.render({
                elem: '#createTime\\$',
                type: 'datetime',
                value: data!==undefined?data['createTime\\$']:null
            });
            layDate.render({
                elem: '#updateTime\\$',
                type: 'datetime',
                value: data!==undefined?data['updateTime\\$']:null
            });
            layDate.render({
                elem: '.layui-laydate-range'
                ,type: 'datetime'
                ,range: true
            });
        }, 300);
    }
    layDateRender();
});
// 关闭动作
$(document).on('click','#data-detail-close', function () {
    parent.layer.closeAll();
});
function tableReload(child) {
    var searchData = {};
    $.each($('#search-box [name]').serializeArray(), function() {
        searchData[this.name] = this.value;
    });
    tableIns.reload({
        where: searchData,
        page: {curr: pageCurr}
     });
}
})();
src/main/webapp/static/js/basCrnp/basCrnp.js
@@ -1,270 +1,1075 @@
var pageCurr;
layui.config({
    base: baseUrl + "/static/layui/lay/modules/"
}).use(['table','laydate', 'form', 'admin'], function(){
    var table = layui.table;
    var $ = layui.jquery;
    var layer = layui.layer;
    var layDate = layui.laydate;
    var form = layui.form;
    var admin = layui.admin;
(function () {
    var simpleEntityName = 'basCrnp';
    var entityName = 'BasCrnp';
    var primaryKeyField = 'crnNo';
    var fieldMeta = dedupeFieldMeta([
    {
        field: 'crnNo',
        columnName: 'crn_no',
        label: '编  号',
        tableProp: 'crnNo',
        exportField: 'crnNo',
        kind: 'text',
        valueType: 'number',
        required: true,
        primaryKey: true,
        sortable: true,
        textarea: false,
        minWidth: 90,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'status',
        columnName: 'status',
        label: '状  态',
        tableProp: 'status$',
        exportField: 'status$',
        kind: 'enum',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 120,
        enumOptions: [{ rawValue: '1', label: '正常' }, { rawValue: '0', label: '禁用' }],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'wrkNo',
        columnName: 'wrk_no',
        label: '工 作 号',
        tableProp: 'wrkNo',
        exportField: 'wrkNo',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 116,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'inEnable',
        columnName: 'in_enable',
        label: '可入(checkBox)',
        tableProp: 'inEnable',
        exportField: 'inEnable',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 180,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'outEnable',
        columnName: 'out_enable',
        label: '可出(checkBox)',
        tableProp: 'outEnable',
        exportField: 'outEnable',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 180,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'createBy',
        columnName: 'create_by',
        label: '创建人员',
        tableProp: 'createBy',
        exportField: 'createBy',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'createTime',
        columnName: 'create_time',
        label: '创建时间',
        tableProp: 'createTime$',
        exportField: 'createTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'updateBy',
        columnName: 'update_by',
        label: '修改人员',
        tableProp: 'updateBy',
        exportField: 'updateBy',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'updateTime',
        columnName: 'update_time',
        label: '修改时间',
        tableProp: 'updateTime$',
        exportField: 'updateTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'memo',
        columnName: 'memo',
        label: '备  注',
        tableProp: 'memo',
        exportField: 'memo',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: true,
        minWidth: 180,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'controlRows',
        columnName: 'control_rows',
        label: '控制库位排号',
        tableProp: 'controlRows',
        exportField: 'controlRows',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 134,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'deepRows',
        columnName: 'deep_rows',
        label: '深库位排号',
        tableProp: 'deepRows',
        exportField: 'deepRows',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 116,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'inStationList',
        columnName: 'in_station_list',
        label: '入库站点',
        tableProp: 'inStationList',
        exportField: 'inStationList',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'outStationList',
        columnName: 'out_station_list',
        label: '出库站点',
        tableProp: 'outStationList',
        exportField: 'outStationList',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'maxInTask',
        columnName: 'max_in_task',
        label: '最大入库任务数',
        tableProp: 'maxInTask',
        exportField: 'maxInTask',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 152,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'maxOutTask',
        columnName: 'max_out_task',
        label: '最大出库任务数',
        tableProp: 'maxOutTask',
        exportField: 'maxOutTask',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 152,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    }
    // 数据渲染
    tableIns = table.render({
        elem: '#basCrnp',
        headers: {token: localStorage.getItem('token')},
        url: baseUrl+'/basCrnp/list/auth',
        page: true,
        limit: 15,
        limits: [15, 30, 50, 100, 200, 500],
        toolbar: '#toolbar',
        cellMinWidth: 50,
        height: 'full-120',
        cols: [[
            {type: 'checkbox'}
            ,{field: 'crnNo', align: 'center',title: '编号'}
            ,{field: 'status$', align: 'center',title: '状态'}
            // ,{field: 'wrkNo', align: 'center',title: '工作号'}
            ,{field: 'inEnable', align: 'center',title: '可入(checkBox)'}
            ,{field: 'outEnable', align: 'center',title: '可出(checkBox)'}
            ,{field: 'controlRows', align: 'center',title: '控制库位排号'}
            ,{field: 'deepRows', align: 'center',title: '深库位排号'}
            ,{field: 'inStationList', align: 'center',title: '入库站列表'}
            ,{field: 'outStationList', align: 'center',title: '出库站列表'}
            ,{field: 'maxInTask', align: 'center',title: '最大入库任务数'}
            ,{field: 'maxOutTask', align: 'center',title: '最大出库任务数'}
            // ,{field: 'createBy', align: 'center',title: '创建人员'}
            // ,{field: 'createTime$', align: 'center',title: '创建时间'}
            // ,{field: 'updateBy', align: 'center',title: '修改人员'}
            // ,{field: 'updateTime$', align: 'center',title: '修改时间'}
            ,{field: 'memo', align: 'center',title: '备注'}
    ]);
            ,{fixed: 'right', title:'操作', align: 'center', toolbar: '#operate', width:120}
        ]],
        request: {
            pageName: 'curr',
            pageSize: 'limit'
        },
        parseData: function (res) {
            return {
                'code': res.code,
                'msg': res.msg,
                'count': res.data.total,
                'data': res.data.records
            }
        },
        response: {
            statusCode: 200
        },
        done: function(res, curr, count) {
            if (res.code === 403) {
                top.location.href = baseUrl+"/";
            }
            pageCurr=curr;
            limit();
    function formatFieldLabel(field) {
        var raw = field && field.label ? String(field.label).trim() : '';
        if (raw) {
            return raw;
        }
    });
    // 监听排序事件
    table.on('sort(basCrnp)', function (obj) {
        var searchData = {};
        $.each($('#search-box [name]').serializeArray(), function() {
            searchData[this.name] = this.value;
        });
        searchData['orderByField'] = obj.field;
        searchData['orderByType'] = obj.type;
        tableIns.reload({
            where: searchData,
            page: {curr: 1}
        });
    });
    // 监听头工具栏事件
    table.on('toolbar(basCrnp)', function (obj) {
        var checkStatus = table.checkStatus(obj.config.id).data;
        switch(obj.event) {
            case 'addData':
                showEditModel();
                break;
            case 'deleteData':
               if (checkStatus.length === 0) {
                   layer.msg('请选择要删除的数据', {icon: 2});
                   return;
               }
               del(checkStatus.map(function (d) {
                   return d.crnNo;
               }));
               break;
            case 'exportData':
                admin.confirm('确定导出Excel吗', {shadeClose: true}, function(){
                    var titles=[];
                    var fields=[];
                    obj.config.cols[0].map(function (col) {
                        if (col.type === 'normal' && col.hide === false && col.toolbar == null) {
                            titles.push(col.title);
                            fields.push(col.field);
                        }
                    });
                    var exportData = {};
                    $.each($('#search-box [name]').serializeArray(), function() {
                        exportData[this.name] = this.value;
                    });
                    var param = {
                        'basCrnp': exportData,
                        'fields': fields
                    };
                    $.ajax({
                        url: baseUrl+"/basCrnp/export/auth",
                        headers: {'token': localStorage.getItem('token')},
                        data: JSON.stringify(param),
                        dataType:'json',
                        contentType:'application/json;charset=UTF-8',
                        method: 'POST',
                        success: function (res) {
                            layer.closeAll();
                            if (res.code === 200) {
                                table.exportFile(titles,res.data,'xls');
                            } else if (res.code === 403) {
                                top.location.href = baseUrl+"/";
                            } else {
                                layer.msg(res.msg, {icon: 2})
                            }
                        }
                    });
                });
                break;
        raw = field && field.columnName ? field.columnName : (field && field.field ? field.field : '');
        if (!raw) {
            return '';
        }
    });
    // 监听行工具事件
    table.on('tool(basCrnp)', function(obj){
        var data = obj.data;
        switch (obj.event) {
            case 'edit':
                showEditModel(data);
                break;
            case "del":
                del([data.crnNo]);
                break;
        }
    });
    /* 弹窗 - 新增、修改 */
    function showEditModel(mData) {
        admin.open({
            type: 1,
            area: '600px',
            title: (mData ? '修改' : '添加') + '订单状态',
            content: $('#editDialog').html(),
            success: function (layero, dIndex) {
                layDateRender(mData);
                form.val('detail', mData);
                form.on('submit(editSubmit)', function (data) {
                    var loadIndex = layer.load(2);
                    $.ajax({
                        url: baseUrl+"/basCrnp/"+(mData?'update':'add')+"/auth",
                        headers: {'token': localStorage.getItem('token')},
                        data: data.field,
                        method: 'POST',
                        success: function (res) {
                            layer.close(loadIndex);
                            if (res.code === 200){
                                layer.close(dIndex);
                                layer.msg(res.msg, {icon: 1});
                                tableReload();
                            } else if (res.code === 403){
                                top.location.href = baseUrl+"/";
                            }else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }
                    })
                    return false;
                });
                $(layero).children('.layui-layer-content').css('overflow', 'visible');
                layui.form.render('select');
            }
        raw = String(raw)
            .replace(/\$/g, '')
            .replace(/([a-z0-9])([A-Z])/g, '$1_$2')
            .replace(/_/g, ' ')
            .replace(/\s+/g, ' ')
            .trim();
        return raw.replace(/\b[a-z]/g, function (letter) {
            return letter.toUpperCase();
        });
    }
    /* 删除 */
    function del(ids) {
        layer.confirm('确定要删除选中数据吗?', {
            skin: 'layui-layer-admin',
            shade: .1
        }, function (i) {
            layer.close(i);
            var loadIndex = layer.load(2);
    function dedupeFieldMeta(list) {
        var result = [];
        var seen = {};
        (list || []).forEach(function (field) {
            if (!field || !field.field || seen[field.field]) {
                return;
            }
            field.label = formatFieldLabel(field);
            seen[field.field] = true;
            result.push(field);
        });
        return result;
    }
    function isEmptyValue(value) {
        return value === null || value === undefined || value === '';
    }
    function stringValue(value) {
        return isEmptyValue(value) ? '' : String(value);
    }
    function valueOrDash(value) {
        return isEmptyValue(value) ? '--' : value;
    }
    function normalizeOptionValue(field, rawValue) {
        if (rawValue === null || rawValue === undefined) {
            return null;
        }
        if (rawValue === '') {
            return '';
        }
        if (field && field.valueType === 'number') {
            var numberVal = Number(rawValue);
            return isNaN(numberVal) ? rawValue : numberVal;
        }
        return String(rawValue);
    }
    function isSearchableField(field) {
        return !!field && field.kind !== 'image' && !field.textarea;
    }
    function isSortableField(field) {
        if (!field) {
            return false;
        }
        if (field.primaryKey) {
            return true;
        }
        return field.kind !== 'image' && !field.textarea && field.kind !== 'foreign';
    }
    function defaultFieldValue(field) {
        if (field.primaryKey) {
            return null;
        }
        if (field.kind === 'checkbox') {
            return normalizeOptionValue(field, field.checkboxInactiveRaw);
        }
        return '';
    }
    function defaultSearchFieldValue(field) {
        if (field.kind === 'date') {
            return [];
        }
        if (field.kind === 'enum' || field.kind === 'checkbox') {
            return null;
        }
        return '';
    }
    function createSearchDefaults() {
        var result = {
            condition: ''
        };
        fieldMeta.forEach(function (field) {
            if (!isSearchableField(field)) {
                return;
            }
            result[field.field] = defaultSearchFieldValue(field);
        });
        return result;
    }
    function createSearchDisplayDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            if (field.kind === 'foreign' && isSearchableField(field)) {
                result[field.field] = '';
            }
        });
        return result;
    }
    function createDefaultVisibleColumnKeys() {
        return fieldMeta.map(function (field) {
            return field.field;
        });
    }
    function createFormDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            result[field.field] = defaultFieldValue(field);
        });
        return result;
    }
    function createDisplayDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            if (field.kind === 'foreign') {
                result[field.field] = '';
            }
        });
        return result;
    }
    function createFormRules() {
        var rules = {};
        fieldMeta.forEach(function (field) {
            if (field.primaryKey || !field.required) {
                return;
            }
            rules[field.field] = [{
                required: true,
                message: (field.kind === 'date' || field.kind === 'enum' ? '请选择' : '请输入') + field.label,
                trigger: (field.kind === 'date' || field.kind === 'enum') ? 'change' : 'blur'
            }];
        });
        return rules;
    }
    function getTableValue(row, field) {
        var prop = field.tableProp || field.field;
        if (row && !isEmptyValue(row[prop])) {
            return row[prop];
        }
        return row ? row[field.field] : '';
    }
    function isCheckboxChecked(row, field) {
        var value = row ? row[field.field] : null;
        var activeValue = normalizeOptionValue(field, field.checkboxActiveRaw);
        return String(value) === String(activeValue);
    }
    function exportCell(value) {
        return stringValue(value).replace(/\t/g, ' ').replace(/\r?\n/g, ' ');
    }
    function escapeHtml(value) {
        return exportCell(value)
            .replace(/&/g, '&amp;')
            .replace(/</g, '&lt;')
            .replace(/>/g, '&gt;')
            .replace(/"/g, '&quot;')
            .replace(/'/g, '&#39;');
    }
    function buildPayload(form) {
        var payload = {};
        fieldMeta.forEach(function (field) {
            var value = form[field.field];
            if (field.primaryKey) {
                if (!isEmptyValue(value)) {
                    payload[field.field] = value;
                }
                return;
            }
            if (field.kind === 'foreign' && isEmptyValue(value)) {
                value = null;
            }
            if (field.kind === 'enum' && value === '') {
                value = null;
            }
            if (field.kind === 'checkbox' && isEmptyValue(value)) {
                value = normalizeOptionValue(field, field.checkboxInactiveRaw);
            }
            if (field.valueType === 'number' && !isEmptyValue(value)) {
                value = Number(value);
            }
            if (field.valueType === 'number' && value === '') {
                value = null;
            }
            payload[field.field] = value;
        });
        return payload;
    }
    function fillFormFromRow(row, form, display) {
        fieldMeta.forEach(function (field) {
            if (field.primaryKey) {
                form[field.field] = row[field.field];
                return;
            }
            if (field.kind === 'date') {
                form[field.field] = row[field.tableProp] || row[field.field] || '';
                return;
            }
            if (field.kind === 'foreign') {
                form[field.field] = isEmptyValue(row[field.field]) ? '' : normalizeOptionValue(field, row[field.field]);
                if (display) {
                    display[field.field] = row[field.tableProp] || (isEmptyValue(row[field.field]) ? '' : String(row[field.field]));
                }
                return;
            }
            if (field.kind === 'enum') {
                form[field.field] = isEmptyValue(row[field.field]) ? '' : normalizeOptionValue(field, row[field.field]);
                return;
            }
            if (field.kind === 'checkbox') {
                form[field.field] = isEmptyValue(row[field.field])
                    ? normalizeOptionValue(field, field.checkboxInactiveRaw)
                    : normalizeOptionValue(field, row[field.field]);
                return;
            }
            form[field.field] = isEmptyValue(row[field.field])
                ? ''
                : (field.valueType === 'number' ? String(row[field.field]) : row[field.field]);
        });
    }
    function resolveSearchParam(field) {
        if (field.kind === 'date' && field.columnName) {
            return field.columnName;
        }
        return field.field;
    }
    function createDownloadFile(filename, titles, rows) {
        var html = [
            '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">',
            '<head><meta charset="UTF-8"></head><body><table border="1"><thead><tr>',
            titles.map(function (title) {
                return '<th>' + escapeHtml(title) + '</th>';
            }).join(''),
            '</tr></thead><tbody>',
            (rows || []).map(function (row) {
                return '<tr>' + (row || []).map(function (value) {
                    return '<td style="mso-number-format:\\@;">' + escapeHtml(value) + '</td>';
                }).join('') + '</tr>';
            }).join(''),
            '</tbody></table></body></html>'
        ].join('');
        var blob = new Blob(['\ufeff' + html], {
            type: 'application/vnd.ms-excel;charset=utf-8;'
        });
        var anchor = document.createElement('a');
        anchor.href = URL.createObjectURL(blob);
        anchor.download = filename;
        document.body.appendChild(anchor);
        anchor.click();
        setTimeout(function () {
            URL.revokeObjectURL(anchor.href);
            document.body.removeChild(anchor);
        }, 0);
    }
    function buildTimestamp() {
        var now = new Date();
        var pad = function (num) {
            return num < 10 ? '0' + num : String(num);
        };
        return now.getFullYear()
            + pad(now.getMonth() + 1)
            + pad(now.getDate())
            + '_'
            + pad(now.getHours())
            + pad(now.getMinutes())
            + pad(now.getSeconds());
    }
    function authHeaders() {
        return {
            token: localStorage.getItem('token')
        };
    }
    function handleForbidden(res) {
        if (res && res.code === 403) {
            top.location.href = baseUrl + '/';
            return true;
        }
        return false;
    }
    var sharedMethods = {
        authHeaders: authHeaders,
        handleForbidden: handleForbidden,
        valueOrDash: valueOrDash,
        stringValue: stringValue,
        getTableValue: getTableValue,
        isCheckboxChecked: isCheckboxChecked,
        normalizeOptionValue: normalizeOptionValue,
        isSortableField: isSortableField,
        getSuggestionFetcher: function (field) {
            var self = this;
            return function (queryString, callback) {
                self.fetchForeignSuggestions(field, queryString, callback);
            };
        },
        fetchForeignSuggestions: function (field, queryString, callback) {
            if (!field.foreignQuery || !queryString) {
                callback([]);
                return;
            }
            var self = this;
            $.ajax({
                url: baseUrl+"/basCrnp/delete/auth",
                headers: {'token': localStorage.getItem('token')},
                data: {ids: ids},
                method: 'POST',
                url: baseUrl + '/' + field.foreignQuery + 'Query/auth',
                method: 'GET',
                headers: self.authHeaders(),
                data: { condition: queryString },
                success: function (res) {
                    layer.close(loadIndex);
                    if (res.code === 200){
                        layer.msg(res.msg, {icon: 1});
                        tableReload();
                    } else if (res.code === 403){
                        top.location.href = baseUrl+"/";
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    if (self.handleForbidden(res)) {
                        return;
                    }
                    if (!res || res.code !== 200 || !Array.isArray(res.data)) {
                        callback([]);
                        return;
                    }
                    callback(res.data.map(function (item) {
                        return {
                            id: item.id,
                            value: item.value
                        };
                    }));
                },
                error: function () {
                    callback([]);
                }
            });
        },
        handleForeignSelect: function (field, item) {
            this.$set(this.displayTarget, field.field, item && item.value ? item.value : '');
            this.$set(this.formTarget, field.field, item && item.id !== undefined ? normalizeOptionValue(field, item.id) : '');
        },
        handleForeignInput: function (field) {
            if (!this.displayTarget || !this.formTarget) {
                return;
            }
            if (this.displayTarget[field.field]) {
                return;
            }
            this.$set(this.formTarget, field.field, '');
        }
    };
    if (document.getElementById('app')) {
        new Vue({
            el: '#app',
            data: function () {
                return {
                    fieldMeta: fieldMeta,
                    primaryKeyField: primaryKeyField,
                    loading: false,
                    exporting: false,
                    tableData: [],
                    selection: [],
                    advancedFiltersVisible: false,
                    allColumns: fieldMeta.slice(),
                    visibleColumnKeys: createDefaultVisibleColumnKeys(),
                    searchForm: createSearchDefaults(),
                    searchDisplay: createSearchDisplayDefaults(),
                    page: {
                        curr: 1,
                        limit: 15,
                        total: 0
                    },
                    sortState: {
                        prop: '',
                        order: ''
                    },
                    dialog: {
                        visible: false,
                        mode: 'create',
                        submitting: false
                    },
                    layoutTimer: null,
                    tableResizeHandler: null,
                    dialogForm: createFormDefaults(),
                    dialogDisplay: createDisplayDefaults(),
                    dialogRules: createFormRules()
                };
            },
            computed: {
                searchableFields: function () {
                    return this.fieldMeta.filter(function (field) {
                        return isSearchableField(field);
                    });
                },
                quickSearchableFields: function () {
                    var result = [];
                    this.searchableFields.forEach(function (field) {
                        if (result.length >= 3 || field.kind === 'date') {
                            return;
                        }
                        result.push(field);
                    });
                    return result;
                },
                advancedSearchableFields: function () {
                    var quickKeys = this.quickSearchableFields.map(function (field) {
                        return field.field;
                    });
                    return this.searchableFields.filter(function (field) {
                        return quickKeys.indexOf(field.field) === -1;
                    });
                },
                hasAdvancedFilters: function () {
                    return this.advancedSearchableFields.length > 0;
                },
                visibleColumns: function () {
                    var keys = this.visibleColumnKeys;
                    return this.allColumns.filter(function (field) {
                        return keys.indexOf(field.field) !== -1;
                    });
                },
                editableFields: function () {
                    return this.fieldMeta.filter(function (field) {
                        return !field.primaryKey;
                    });
                },
                exportColumns: function () {
                    return this.visibleColumns.map(function (field) {
                        return {
                            field: field.exportField || field.tableProp || field.field,
                            label: field.label
                        };
                    });
                },
                tableHeight: function () {
                    return this.advancedFiltersVisible && this.hasAdvancedFilters
                        ? 'calc(100vh - 390px)'
                        : 'calc(100vh - 300px)';
                },
                formTarget: function () {
                    return this.dialogForm;
                },
                displayTarget: function () {
                    return this.dialogDisplay;
                }
            },
            created: function () {
                this.loadTable();
            },
            mounted: function () {
                var self = this;
                self.requestTableLayout(80);
                self.tableResizeHandler = function () {
                    self.requestTableLayout(80);
                };
                window.addEventListener('resize', self.tableResizeHandler);
            },
            beforeDestroy: function () {
                if (this.layoutTimer) {
                    clearTimeout(this.layoutTimer);
                    this.layoutTimer = null;
                }
                if (this.tableResizeHandler) {
                    window.removeEventListener('resize', this.tableResizeHandler);
                    this.tableResizeHandler = null;
                }
            },
            methods: $.extend({}, sharedMethods, {
                requestTableLayout: function (delay) {
                    var self = this;
                    if (self.layoutTimer) {
                        clearTimeout(self.layoutTimer);
                    }
                    self.$nextTick(function () {
                        self.layoutTimer = setTimeout(function () {
                            var table = self.$refs.dataTable;
                            if (table && typeof table.doLayout === 'function') {
                                table.doLayout();
                            }
                        }, delay || 40);
                    });
                },
                isColumnVisible: function (fieldName) {
                    return this.visibleColumnKeys.indexOf(fieldName) !== -1;
                },
                toggleColumn: function (fieldName, visible) {
                    if (visible) {
                        if (this.visibleColumnKeys.indexOf(fieldName) === -1) {
                            this.visibleColumnKeys.push(fieldName);
                        }
                        this.requestTableLayout(80);
                        return;
                    }
                    if (this.visibleColumnKeys.length === 1) {
                        this.$message.warning('至少保留一列');
                        return;
                    }
                    this.visibleColumnKeys = this.visibleColumnKeys.filter(function (item) {
                        return item !== fieldName;
                    });
                    this.requestTableLayout(80);
                },
                selectAllColumns: function () {
                    this.visibleColumnKeys = createDefaultVisibleColumnKeys();
                    this.requestTableLayout(80);
                },
                resetColumns: function () {
                    this.visibleColumnKeys = createDefaultVisibleColumnKeys();
                    this.requestTableLayout(80);
                },
                toggleAdvancedFilters: function () {
                    this.advancedFiltersVisible = !this.advancedFiltersVisible;
                    this.requestTableLayout(260);
                },
                handleSearchForeignSelect: function (field, item) {
                    this.$set(this.searchDisplay, field.field, item && item.value ? item.value : '');
                    this.$set(this.searchForm, field.field, item && item.id !== undefined ? normalizeOptionValue(field, item.id) : '');
                },
                handleSearchForeignInput: function (field) {
                    if (this.searchDisplay[field.field]) {
                        return;
                    }
                    this.$set(this.searchForm, field.field, '');
                },
                buildQueryParams: function () {
                    var self = this;
                    var params = {
                        curr: self.page.curr,
                        limit: self.page.limit
                    };
                    if (self.searchForm.condition) {
                        params.condition = self.searchForm.condition;
                    }
                    self.searchableFields.forEach(function (field) {
                        var value = self.searchForm[field.field];
                        if (field.kind === 'date') {
                            if (value && value.length === 2) {
                                params[resolveSearchParam(field)] = value[0] + ' - ' + value[1];
                            }
                            return;
                        }
                        if (!isEmptyValue(value)) {
                            params[resolveSearchParam(field)] = value;
                        }
                    });
                    if (self.sortState.prop && self.sortState.order) {
                        params.orderByField = self.sortState.prop;
                        params.orderByType = self.sortState.order === 'ascending' ? 'asc' : 'desc';
                    }
                    return params;
                },
                loadTable: function () {
                    var self = this;
                    self.loading = true;
                    $.ajax({
                        url: baseUrl + '/' + simpleEntityName + '/list/auth',
                        method: 'GET',
                        headers: self.authHeaders(),
                        data: self.buildQueryParams(),
                        success: function (res) {
                            self.loading = false;
                            if (self.handleForbidden(res)) {
                                return;
                            }
                            if (!res || res.code !== 200) {
                                self.$message.error((res && res.msg) ? res.msg : '加载失败');
                                return;
                            }
                            var payload = res.data || {};
                            self.tableData = Array.isArray(payload.records) ? payload.records : [];
                            self.page.total = payload.total || 0;
                            self.requestTableLayout(80);
                        },
                        error: function () {
                            self.loading = false;
                            self.requestTableLayout(80);
                            self.$message.error('加载失败');
                        }
                    });
                },
                handleSearch: function () {
                    this.page.curr = 1;
                    this.loadTable();
                },
                handleReset: function () {
                    this.searchForm = createSearchDefaults();
                    this.searchDisplay = createSearchDisplayDefaults();
                    this.advancedFiltersVisible = false;
                    this.page.curr = 1;
                    this.sortState = {
                        prop: '',
                        order: ''
                    };
                    this.loadTable();
                },
                handleSelectionChange: function (rows) {
                    this.selection = rows || [];
                },
                handleSortChange: function (payload) {
                    this.sortState = {
                        prop: payload && payload.prop ? payload.prop : '',
                        order: payload && payload.order ? payload.order : ''
                    };
                    this.page.curr = 1;
                    this.loadTable();
                },
                handleCurrentChange: function (curr) {
                    this.page.curr = curr;
                    this.loadTable();
                },
                handleSizeChange: function (limit) {
                    this.page.limit = limit;
                    this.page.curr = 1;
                    this.loadTable();
                },
                resetDialogState: function () {
                    this.dialogForm = createFormDefaults();
                    this.dialogDisplay = createDisplayDefaults();
                    if (this.$refs.dialogForm) {
                        this.$refs.dialogForm.clearValidate();
                    }
                },
                openCreateDialog: function () {
                    this.dialog.mode = 'create';
                    this.dialog.visible = true;
                    this.$nextTick(this.resetDialogState);
                },
                openEditDialog: function (row) {
                    var self = this;
                    self.dialog.mode = 'edit';
                    self.dialog.visible = true;
                    self.$nextTick(function () {
                        self.resetDialogState();
                        fillFormFromRow(row, self.dialogForm, self.dialogDisplay);
                        if (self.$refs.dialogForm) {
                            self.$refs.dialogForm.clearValidate();
                        }
                    });
                },
                submitDialog: function () {
                    var self = this;
                    if (!self.$refs.dialogForm) {
                        return;
                    }
                    self.$refs.dialogForm.validate(function (valid) {
                        if (!valid) {
                            return false;
                        }
                        self.dialog.submitting = true;
                        $.ajax({
                            url: baseUrl + '/' + simpleEntityName + '/' + (self.dialog.mode === 'create' ? 'add' : 'update') + '/auth',
                            method: 'POST',
                            headers: self.authHeaders(),
                            data: buildPayload(self.dialogForm),
                            success: function (res) {
                                self.dialog.submitting = false;
                                if (self.handleForbidden(res)) {
                                    return;
                                }
                                if (!res || res.code !== 200) {
                                    self.$message.error((res && res.msg) ? res.msg : '保存失败');
                                    return;
                                }
                                self.$message.success(res.msg || '保存成功');
                                self.dialog.visible = false;
                                self.loadTable();
                            },
                            error: function () {
                                self.dialog.submitting = false;
                                self.$message.error('保存失败');
                            }
                        });
                        return true;
                    });
                },
                removeSelection: function () {
                    var self = this;
                    var ids = self.selection.map(function (row) {
                        return row[self.primaryKeyField];
                    });
                    self.removeRows(ids);
                },
                removeRows: function (ids) {
                    var self = this;
                    if (!ids || ids.length === 0) {
                        self.$message.warning('请选择要删除的数据');
                        return;
                    }
                    self.$confirm('确定删除选中的记录吗?', '提示', { type: 'warning' }).then(function () {
                        $.ajax({
                            url: baseUrl + '/' + simpleEntityName + '/delete/auth',
                            method: 'POST',
                            headers: self.authHeaders(),
                            traditional: true,
                            data: { 'ids[]': ids },
                            success: function (res) {
                                if (self.handleForbidden(res)) {
                                    return;
                                }
                                if (!res || res.code !== 200) {
                                    self.$message.error((res && res.msg) ? res.msg : '删除失败');
                                    return;
                                }
                                self.$message.success(res.msg || '删除成功');
                                self.selection = [];
                                if (self.tableData.length === ids.length && self.page.curr > 1) {
                                    self.page.curr = self.page.curr - 1;
                                }
                                self.loadTable();
                            },
                            error: function () {
                                self.$message.error('删除失败');
                            }
                        });
                    }).catch(function () {});
                },
                exportRows: function () {
                    var self = this;
                    self.exporting = true;
                    var requestBody = {
                        fields: self.exportColumns.map(function (item) {
                            return item.field;
                        })
                    };
                    requestBody[simpleEntityName] = self.buildQueryParams();
                    $.ajax({
                        url: baseUrl + '/' + simpleEntityName + '/export/auth',
                        method: 'POST',
                        headers: $.extend({ 'Content-Type': 'application/json;charset=UTF-8' }, self.authHeaders()),
                        data: JSON.stringify(requestBody),
                        success: function (res) {
                            self.exporting = false;
                            if (self.handleForbidden(res)) {
                                return;
                            }
                            if (!res || res.code !== 200) {
                                self.$message.error((res && res.msg) ? res.msg : '导出失败');
                                return;
                            }
                            createDownloadFile(
                                simpleEntityName + '_' + buildTimestamp() + '.xls',
                                self.exportColumns.map(function (item) {
                                    return item.label;
                                }),
                                Array.isArray(res.data) ? res.data : []
                            );
                            self.$message.success('导出成功');
                        },
                        error: function () {
                            self.exporting = false;
                            self.$message.error('导出失败');
                        }
                    });
                }
            })
        });
    }
    // 搜索
    form.on('submit(search)', function (data) {
        pageCurr = 1;
        tableReload(false);
    });
    // 重置
    form.on('submit(reset)', function (data) {
        pageCurr = 1;
        clearFormVal($('#search-box'));
        tableReload(false);
    });
    // 时间选择器
    function layDateRender(data) {
        setTimeout(function () {
            layDate.render({
                elem: '.layui-laydate-range'
                ,type: 'datetime'
                ,range: true
            });
            layDate.render({
                elem: '#createTime\\$',
                type: 'datetime',
                value: data!==undefined?data['createTime\\$']:null
            });
            layDate.render({
                elem: '#updateTime\\$',
                type: 'datetime',
                value: data!==undefined?data['updateTime\\$']:null
            });
        }, 300);
    }
    layDateRender();
});
// 关闭动作
$(document).on('click','#data-detail-close', function () {
    parent.layer.closeAll();
});
function tableReload(child) {
    var searchData = {};
    $.each($('#search-box [name]').serializeArray(), function() {
        searchData[this.name] = this.value;
    });
    tableIns.reload({
        where: searchData,
        page: {curr: pageCurr}
     });
}
})();
src/main/webapp/static/js/basCrnpErr/basCrnpErr.js
@@ -1,261 +1,913 @@
var pageCurr;
layui.config({
    base: baseUrl + "/static/layui/lay/modules/"
}).use(['table','laydate', 'form', 'admin'], function(){
    var table = layui.table;
    var $ = layui.jquery;
    var layer = layui.layer;
    var layDate = layui.laydate;
    var form = layui.form;
    var admin = layui.admin;
(function () {
    var simpleEntityName = 'basCrnpErr';
    var entityName = 'BasCrnpErr';
    var primaryKeyField = 'id';
    var fieldMeta = dedupeFieldMeta([
    {
        field: 'id',
        columnName: 'id',
        label: '编  号',
        tableProp: 'id',
        exportField: 'id',
        kind: 'text',
        valueType: 'number',
        required: true,
        primaryKey: true,
        sortable: true,
        textarea: false,
        minWidth: 90,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'errorCode',
        columnName: 'error_code',
        label: '异 常 码',
        tableProp: 'errorCode',
        exportField: 'errorCode',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 116,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'errName',
        columnName: 'err_name',
        label: '异  常',
        tableProp: 'errName',
        exportField: 'errName',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'modiUser',
        columnName: 'modi_user',
        label: '修改人员',
        tableProp: 'modiUser$',
        exportField: 'modiUser$',
        kind: 'foreign',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: 'user',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'modiTime',
        columnName: 'modi_time',
        label: '修改时间',
        tableProp: 'modiTime$',
        exportField: 'modiTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'appeUser',
        columnName: 'appe_user',
        label: '添加人员',
        tableProp: 'appeUser$',
        exportField: 'appeUser$',
        kind: 'foreign',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: 'user',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'appeTime',
        columnName: 'appe_time',
        label: '添加时间',
        tableProp: 'appeTime$',
        exportField: 'appeTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    }
    // 数据渲染
    tableIns = table.render({
        elem: '#basCrnpErr',
        headers: {token: localStorage.getItem('token')},
        url: baseUrl+'/basCrnpErr/list/auth',
        page: true,
        limit: 15,
        limits: [15, 30, 50, 100, 200, 500],
        toolbar: '#toolbar',
        cellMinWidth: 50,
        height: 'full-120',
        cols: [[
            {type: 'checkbox'}
            ,{field: 'id', align: 'center',title: '编号'}
            ,{field: 'errorCode', align: 'center',title: '异常码'}
            ,{field: 'errName', align: 'center',title: '异常'}
            ,{field: 'modiUser$', align: 'center',title: '修改人员'}
            ,{field: 'modiTime$', align: 'center',title: '修改时间'}
            ,{field: 'appeUser$', align: 'center',title: '添加人员'}
            ,{field: 'appeTime$', align: 'center',title: '添加时间'}
    ]);
            ,{fixed: 'right', title:'操作', align: 'center', toolbar: '#operate', width:120}
        ]],
        request: {
            pageName: 'curr',
            pageSize: 'limit'
        },
        parseData: function (res) {
            return {
                'code': res.code,
                'msg': res.msg,
                'count': res.data.total,
                'data': res.data.records
            }
        },
        response: {
            statusCode: 200
        },
        done: function(res, curr, count) {
            if (res.code === 403) {
                top.location.href = baseUrl+"/";
            }
            pageCurr=curr;
            limit();
    function formatFieldLabel(field) {
        var raw = field && field.label ? String(field.label).trim() : '';
        if (raw) {
            return raw;
        }
    });
    // 监听排序事件
    table.on('sort(basCrnpErr)', function (obj) {
        var searchData = {};
        $.each($('#search-box [name]').serializeArray(), function() {
            searchData[this.name] = this.value;
        });
        searchData['orderByField'] = obj.field;
        searchData['orderByType'] = obj.type;
        tableIns.reload({
            where: searchData,
            page: {curr: 1}
        });
    });
    // 监听头工具栏事件
    table.on('toolbar(basCrnpErr)', function (obj) {
        var checkStatus = table.checkStatus(obj.config.id).data;
        switch(obj.event) {
            case 'addData':
                showEditModel();
                break;
            case 'deleteData':
               if (checkStatus.length === 0) {
                   layer.msg('请选择要删除的数据', {icon: 2});
                   return;
               }
               del(checkStatus.map(function (d) {
                   return d.id;
               }));
               break;
            case 'exportData':
                admin.confirm('确定导出Excel吗', {shadeClose: true}, function(){
                    var titles=[];
                    var fields=[];
                    obj.config.cols[0].map(function (col) {
                        if (col.type === 'normal' && col.hide === false && col.toolbar == null) {
                            titles.push(col.title);
                            fields.push(col.field);
                        }
                    });
                    var exportData = {};
                    $.each($('#search-box [name]').serializeArray(), function() {
                        exportData[this.name] = this.value;
                    });
                    var param = {
                        'basCrnpErr': exportData,
                        'fields': fields
                    };
                    $.ajax({
                        url: baseUrl+"/basCrnpErr/export/auth",
                        headers: {'token': localStorage.getItem('token')},
                        data: JSON.stringify(param),
                        dataType:'json',
                        contentType:'application/json;charset=UTF-8',
                        method: 'POST',
                        success: function (res) {
                            layer.closeAll();
                            if (res.code === 200) {
                                table.exportFile(titles,res.data,'xls');
                            } else if (res.code === 403) {
                                top.location.href = baseUrl+"/";
                            } else {
                                layer.msg(res.msg, {icon: 2})
                            }
                        }
                    });
                });
                break;
        raw = field && field.columnName ? field.columnName : (field && field.field ? field.field : '');
        if (!raw) {
            return '';
        }
    });
    // 监听行工具事件
    table.on('tool(basCrnpErr)', function(obj){
        var data = obj.data;
        switch (obj.event) {
            case 'edit':
                showEditModel(data);
                break;
            case "del":
                del([data.id]);
                break;
        }
    });
    /* 弹窗 - 新增、修改 */
    function showEditModel(mData) {
        admin.open({
            type: 1,
            area: '600px',
            title: (mData ? '修改' : '添加') + '订单状态',
            content: $('#editDialog').html(),
            success: function (layero, dIndex) {
                layDateRender(mData);
                form.val('detail', mData);
                form.on('submit(editSubmit)', function (data) {
                    var loadIndex = layer.load(2);
                    $.ajax({
                        url: baseUrl+"/basCrnpErr/"+(mData?'update':'add')+"/auth",
                        headers: {'token': localStorage.getItem('token')},
                        data: data.field,
                        method: 'POST',
                        success: function (res) {
                            layer.close(loadIndex);
                            if (res.code === 200){
                                layer.close(dIndex);
                                layer.msg(res.msg, {icon: 1});
                                tableReload();
                            } else if (res.code === 403){
                                top.location.href = baseUrl+"/";
                            }else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }
                    })
                    return false;
                });
                $(layero).children('.layui-layer-content').css('overflow', 'visible');
                layui.form.render('select');
            }
        raw = String(raw)
            .replace(/\$/g, '')
            .replace(/([a-z0-9])([A-Z])/g, '$1_$2')
            .replace(/_/g, ' ')
            .replace(/\s+/g, ' ')
            .trim();
        return raw.replace(/\b[a-z]/g, function (letter) {
            return letter.toUpperCase();
        });
    }
    /* 删除 */
    function del(ids) {
        layer.confirm('确定要删除选中数据吗?', {
            skin: 'layui-layer-admin',
            shade: .1
        }, function (i) {
            layer.close(i);
            var loadIndex = layer.load(2);
    function dedupeFieldMeta(list) {
        var result = [];
        var seen = {};
        (list || []).forEach(function (field) {
            if (!field || !field.field || seen[field.field]) {
                return;
            }
            field.label = formatFieldLabel(field);
            seen[field.field] = true;
            result.push(field);
        });
        return result;
    }
    function isEmptyValue(value) {
        return value === null || value === undefined || value === '';
    }
    function stringValue(value) {
        return isEmptyValue(value) ? '' : String(value);
    }
    function valueOrDash(value) {
        return isEmptyValue(value) ? '--' : value;
    }
    function normalizeOptionValue(field, rawValue) {
        if (rawValue === null || rawValue === undefined) {
            return null;
        }
        if (rawValue === '') {
            return '';
        }
        if (field && field.valueType === 'number') {
            var numberVal = Number(rawValue);
            return isNaN(numberVal) ? rawValue : numberVal;
        }
        return String(rawValue);
    }
    function isSearchableField(field) {
        return !!field && field.kind !== 'image' && !field.textarea;
    }
    function isSortableField(field) {
        if (!field) {
            return false;
        }
        if (field.primaryKey) {
            return true;
        }
        return field.kind !== 'image' && !field.textarea && field.kind !== 'foreign';
    }
    function defaultFieldValue(field) {
        if (field.primaryKey) {
            return null;
        }
        if (field.kind === 'checkbox') {
            return normalizeOptionValue(field, field.checkboxInactiveRaw);
        }
        return '';
    }
    function defaultSearchFieldValue(field) {
        if (field.kind === 'date') {
            return [];
        }
        if (field.kind === 'enum' || field.kind === 'checkbox') {
            return null;
        }
        return '';
    }
    function createSearchDefaults() {
        var result = {
            condition: ''
        };
        fieldMeta.forEach(function (field) {
            if (!isSearchableField(field)) {
                return;
            }
            result[field.field] = defaultSearchFieldValue(field);
        });
        return result;
    }
    function createSearchDisplayDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            if (field.kind === 'foreign' && isSearchableField(field)) {
                result[field.field] = '';
            }
        });
        return result;
    }
    function createDefaultVisibleColumnKeys() {
        return fieldMeta.map(function (field) {
            return field.field;
        });
    }
    function createFormDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            result[field.field] = defaultFieldValue(field);
        });
        return result;
    }
    function createDisplayDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            if (field.kind === 'foreign') {
                result[field.field] = '';
            }
        });
        return result;
    }
    function createFormRules() {
        var rules = {};
        fieldMeta.forEach(function (field) {
            if (field.primaryKey || !field.required) {
                return;
            }
            rules[field.field] = [{
                required: true,
                message: (field.kind === 'date' || field.kind === 'enum' ? '请选择' : '请输入') + field.label,
                trigger: (field.kind === 'date' || field.kind === 'enum') ? 'change' : 'blur'
            }];
        });
        return rules;
    }
    function getTableValue(row, field) {
        var prop = field.tableProp || field.field;
        if (row && !isEmptyValue(row[prop])) {
            return row[prop];
        }
        return row ? row[field.field] : '';
    }
    function isCheckboxChecked(row, field) {
        var value = row ? row[field.field] : null;
        var activeValue = normalizeOptionValue(field, field.checkboxActiveRaw);
        return String(value) === String(activeValue);
    }
    function exportCell(value) {
        return stringValue(value).replace(/\t/g, ' ').replace(/\r?\n/g, ' ');
    }
    function escapeHtml(value) {
        return exportCell(value)
            .replace(/&/g, '&amp;')
            .replace(/</g, '&lt;')
            .replace(/>/g, '&gt;')
            .replace(/"/g, '&quot;')
            .replace(/'/g, '&#39;');
    }
    function buildPayload(form) {
        var payload = {};
        fieldMeta.forEach(function (field) {
            var value = form[field.field];
            if (field.primaryKey) {
                if (!isEmptyValue(value)) {
                    payload[field.field] = value;
                }
                return;
            }
            if (field.kind === 'foreign' && isEmptyValue(value)) {
                value = null;
            }
            if (field.kind === 'enum' && value === '') {
                value = null;
            }
            if (field.kind === 'checkbox' && isEmptyValue(value)) {
                value = normalizeOptionValue(field, field.checkboxInactiveRaw);
            }
            if (field.valueType === 'number' && !isEmptyValue(value)) {
                value = Number(value);
            }
            if (field.valueType === 'number' && value === '') {
                value = null;
            }
            payload[field.field] = value;
        });
        return payload;
    }
    function fillFormFromRow(row, form, display) {
        fieldMeta.forEach(function (field) {
            if (field.primaryKey) {
                form[field.field] = row[field.field];
                return;
            }
            if (field.kind === 'date') {
                form[field.field] = row[field.tableProp] || row[field.field] || '';
                return;
            }
            if (field.kind === 'foreign') {
                form[field.field] = isEmptyValue(row[field.field]) ? '' : normalizeOptionValue(field, row[field.field]);
                if (display) {
                    display[field.field] = row[field.tableProp] || (isEmptyValue(row[field.field]) ? '' : String(row[field.field]));
                }
                return;
            }
            if (field.kind === 'enum') {
                form[field.field] = isEmptyValue(row[field.field]) ? '' : normalizeOptionValue(field, row[field.field]);
                return;
            }
            if (field.kind === 'checkbox') {
                form[field.field] = isEmptyValue(row[field.field])
                    ? normalizeOptionValue(field, field.checkboxInactiveRaw)
                    : normalizeOptionValue(field, row[field.field]);
                return;
            }
            form[field.field] = isEmptyValue(row[field.field])
                ? ''
                : (field.valueType === 'number' ? String(row[field.field]) : row[field.field]);
        });
    }
    function resolveSearchParam(field) {
        if (field.kind === 'date' && field.columnName) {
            return field.columnName;
        }
        return field.field;
    }
    function createDownloadFile(filename, titles, rows) {
        var html = [
            '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">',
            '<head><meta charset="UTF-8"></head><body><table border="1"><thead><tr>',
            titles.map(function (title) {
                return '<th>' + escapeHtml(title) + '</th>';
            }).join(''),
            '</tr></thead><tbody>',
            (rows || []).map(function (row) {
                return '<tr>' + (row || []).map(function (value) {
                    return '<td style="mso-number-format:\\@;">' + escapeHtml(value) + '</td>';
                }).join('') + '</tr>';
            }).join(''),
            '</tbody></table></body></html>'
        ].join('');
        var blob = new Blob(['\ufeff' + html], {
            type: 'application/vnd.ms-excel;charset=utf-8;'
        });
        var anchor = document.createElement('a');
        anchor.href = URL.createObjectURL(blob);
        anchor.download = filename;
        document.body.appendChild(anchor);
        anchor.click();
        setTimeout(function () {
            URL.revokeObjectURL(anchor.href);
            document.body.removeChild(anchor);
        }, 0);
    }
    function buildTimestamp() {
        var now = new Date();
        var pad = function (num) {
            return num < 10 ? '0' + num : String(num);
        };
        return now.getFullYear()
            + pad(now.getMonth() + 1)
            + pad(now.getDate())
            + '_'
            + pad(now.getHours())
            + pad(now.getMinutes())
            + pad(now.getSeconds());
    }
    function authHeaders() {
        return {
            token: localStorage.getItem('token')
        };
    }
    function handleForbidden(res) {
        if (res && res.code === 403) {
            top.location.href = baseUrl + '/';
            return true;
        }
        return false;
    }
    var sharedMethods = {
        authHeaders: authHeaders,
        handleForbidden: handleForbidden,
        valueOrDash: valueOrDash,
        stringValue: stringValue,
        getTableValue: getTableValue,
        isCheckboxChecked: isCheckboxChecked,
        normalizeOptionValue: normalizeOptionValue,
        isSortableField: isSortableField,
        getSuggestionFetcher: function (field) {
            var self = this;
            return function (queryString, callback) {
                self.fetchForeignSuggestions(field, queryString, callback);
            };
        },
        fetchForeignSuggestions: function (field, queryString, callback) {
            if (!field.foreignQuery || !queryString) {
                callback([]);
                return;
            }
            var self = this;
            $.ajax({
                url: baseUrl+"/basCrnpErr/delete/auth",
                headers: {'token': localStorage.getItem('token')},
                data: {ids: ids},
                method: 'POST',
                url: baseUrl + '/' + field.foreignQuery + 'Query/auth',
                method: 'GET',
                headers: self.authHeaders(),
                data: { condition: queryString },
                success: function (res) {
                    layer.close(loadIndex);
                    if (res.code === 200){
                        layer.msg(res.msg, {icon: 1});
                        tableReload();
                    } else if (res.code === 403){
                        top.location.href = baseUrl+"/";
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    if (self.handleForbidden(res)) {
                        return;
                    }
                    if (!res || res.code !== 200 || !Array.isArray(res.data)) {
                        callback([]);
                        return;
                    }
                    callback(res.data.map(function (item) {
                        return {
                            id: item.id,
                            value: item.value
                        };
                    }));
                },
                error: function () {
                    callback([]);
                }
            });
        },
        handleForeignSelect: function (field, item) {
            this.$set(this.displayTarget, field.field, item && item.value ? item.value : '');
            this.$set(this.formTarget, field.field, item && item.id !== undefined ? normalizeOptionValue(field, item.id) : '');
        },
        handleForeignInput: function (field) {
            if (!this.displayTarget || !this.formTarget) {
                return;
            }
            if (this.displayTarget[field.field]) {
                return;
            }
            this.$set(this.formTarget, field.field, '');
        }
    };
    if (document.getElementById('app')) {
        new Vue({
            el: '#app',
            data: function () {
                return {
                    fieldMeta: fieldMeta,
                    primaryKeyField: primaryKeyField,
                    loading: false,
                    exporting: false,
                    tableData: [],
                    selection: [],
                    advancedFiltersVisible: false,
                    allColumns: fieldMeta.slice(),
                    visibleColumnKeys: createDefaultVisibleColumnKeys(),
                    searchForm: createSearchDefaults(),
                    searchDisplay: createSearchDisplayDefaults(),
                    page: {
                        curr: 1,
                        limit: 15,
                        total: 0
                    },
                    sortState: {
                        prop: '',
                        order: ''
                    },
                    dialog: {
                        visible: false,
                        mode: 'create',
                        submitting: false
                    },
                    layoutTimer: null,
                    tableResizeHandler: null,
                    dialogForm: createFormDefaults(),
                    dialogDisplay: createDisplayDefaults(),
                    dialogRules: createFormRules()
                };
            },
            computed: {
                searchableFields: function () {
                    return this.fieldMeta.filter(function (field) {
                        return isSearchableField(field);
                    });
                },
                quickSearchableFields: function () {
                    var result = [];
                    this.searchableFields.forEach(function (field) {
                        if (result.length >= 3 || field.kind === 'date') {
                            return;
                        }
                        result.push(field);
                    });
                    return result;
                },
                advancedSearchableFields: function () {
                    var quickKeys = this.quickSearchableFields.map(function (field) {
                        return field.field;
                    });
                    return this.searchableFields.filter(function (field) {
                        return quickKeys.indexOf(field.field) === -1;
                    });
                },
                hasAdvancedFilters: function () {
                    return this.advancedSearchableFields.length > 0;
                },
                visibleColumns: function () {
                    var keys = this.visibleColumnKeys;
                    return this.allColumns.filter(function (field) {
                        return keys.indexOf(field.field) !== -1;
                    });
                },
                editableFields: function () {
                    return this.fieldMeta.filter(function (field) {
                        return !field.primaryKey;
                    });
                },
                exportColumns: function () {
                    return this.visibleColumns.map(function (field) {
                        return {
                            field: field.exportField || field.tableProp || field.field,
                            label: field.label
                        };
                    });
                },
                tableHeight: function () {
                    return this.advancedFiltersVisible && this.hasAdvancedFilters
                        ? 'calc(100vh - 390px)'
                        : 'calc(100vh - 300px)';
                },
                formTarget: function () {
                    return this.dialogForm;
                },
                displayTarget: function () {
                    return this.dialogDisplay;
                }
            },
            created: function () {
                this.loadTable();
            },
            mounted: function () {
                var self = this;
                self.requestTableLayout(80);
                self.tableResizeHandler = function () {
                    self.requestTableLayout(80);
                };
                window.addEventListener('resize', self.tableResizeHandler);
            },
            beforeDestroy: function () {
                if (this.layoutTimer) {
                    clearTimeout(this.layoutTimer);
                    this.layoutTimer = null;
                }
                if (this.tableResizeHandler) {
                    window.removeEventListener('resize', this.tableResizeHandler);
                    this.tableResizeHandler = null;
                }
            },
            methods: $.extend({}, sharedMethods, {
                requestTableLayout: function (delay) {
                    var self = this;
                    if (self.layoutTimer) {
                        clearTimeout(self.layoutTimer);
                    }
                    self.$nextTick(function () {
                        self.layoutTimer = setTimeout(function () {
                            var table = self.$refs.dataTable;
                            if (table && typeof table.doLayout === 'function') {
                                table.doLayout();
                            }
                        }, delay || 40);
                    });
                },
                isColumnVisible: function (fieldName) {
                    return this.visibleColumnKeys.indexOf(fieldName) !== -1;
                },
                toggleColumn: function (fieldName, visible) {
                    if (visible) {
                        if (this.visibleColumnKeys.indexOf(fieldName) === -1) {
                            this.visibleColumnKeys.push(fieldName);
                        }
                        this.requestTableLayout(80);
                        return;
                    }
                    if (this.visibleColumnKeys.length === 1) {
                        this.$message.warning('至少保留一列');
                        return;
                    }
                    this.visibleColumnKeys = this.visibleColumnKeys.filter(function (item) {
                        return item !== fieldName;
                    });
                    this.requestTableLayout(80);
                },
                selectAllColumns: function () {
                    this.visibleColumnKeys = createDefaultVisibleColumnKeys();
                    this.requestTableLayout(80);
                },
                resetColumns: function () {
                    this.visibleColumnKeys = createDefaultVisibleColumnKeys();
                    this.requestTableLayout(80);
                },
                toggleAdvancedFilters: function () {
                    this.advancedFiltersVisible = !this.advancedFiltersVisible;
                    this.requestTableLayout(260);
                },
                handleSearchForeignSelect: function (field, item) {
                    this.$set(this.searchDisplay, field.field, item && item.value ? item.value : '');
                    this.$set(this.searchForm, field.field, item && item.id !== undefined ? normalizeOptionValue(field, item.id) : '');
                },
                handleSearchForeignInput: function (field) {
                    if (this.searchDisplay[field.field]) {
                        return;
                    }
                    this.$set(this.searchForm, field.field, '');
                },
                buildQueryParams: function () {
                    var self = this;
                    var params = {
                        curr: self.page.curr,
                        limit: self.page.limit
                    };
                    if (self.searchForm.condition) {
                        params.condition = self.searchForm.condition;
                    }
                    self.searchableFields.forEach(function (field) {
                        var value = self.searchForm[field.field];
                        if (field.kind === 'date') {
                            if (value && value.length === 2) {
                                params[resolveSearchParam(field)] = value[0] + ' - ' + value[1];
                            }
                            return;
                        }
                        if (!isEmptyValue(value)) {
                            params[resolveSearchParam(field)] = value;
                        }
                    });
                    if (self.sortState.prop && self.sortState.order) {
                        params.orderByField = self.sortState.prop;
                        params.orderByType = self.sortState.order === 'ascending' ? 'asc' : 'desc';
                    }
                    return params;
                },
                loadTable: function () {
                    var self = this;
                    self.loading = true;
                    $.ajax({
                        url: baseUrl + '/' + simpleEntityName + '/list/auth',
                        method: 'GET',
                        headers: self.authHeaders(),
                        data: self.buildQueryParams(),
                        success: function (res) {
                            self.loading = false;
                            if (self.handleForbidden(res)) {
                                return;
                            }
                            if (!res || res.code !== 200) {
                                self.$message.error((res && res.msg) ? res.msg : '加载失败');
                                return;
                            }
                            var payload = res.data || {};
                            self.tableData = Array.isArray(payload.records) ? payload.records : [];
                            self.page.total = payload.total || 0;
                            self.requestTableLayout(80);
                        },
                        error: function () {
                            self.loading = false;
                            self.requestTableLayout(80);
                            self.$message.error('加载失败');
                        }
                    });
                },
                handleSearch: function () {
                    this.page.curr = 1;
                    this.loadTable();
                },
                handleReset: function () {
                    this.searchForm = createSearchDefaults();
                    this.searchDisplay = createSearchDisplayDefaults();
                    this.advancedFiltersVisible = false;
                    this.page.curr = 1;
                    this.sortState = {
                        prop: '',
                        order: ''
                    };
                    this.loadTable();
                },
                handleSelectionChange: function (rows) {
                    this.selection = rows || [];
                },
                handleSortChange: function (payload) {
                    this.sortState = {
                        prop: payload && payload.prop ? payload.prop : '',
                        order: payload && payload.order ? payload.order : ''
                    };
                    this.page.curr = 1;
                    this.loadTable();
                },
                handleCurrentChange: function (curr) {
                    this.page.curr = curr;
                    this.loadTable();
                },
                handleSizeChange: function (limit) {
                    this.page.limit = limit;
                    this.page.curr = 1;
                    this.loadTable();
                },
                resetDialogState: function () {
                    this.dialogForm = createFormDefaults();
                    this.dialogDisplay = createDisplayDefaults();
                    if (this.$refs.dialogForm) {
                        this.$refs.dialogForm.clearValidate();
                    }
                },
                openCreateDialog: function () {
                    this.dialog.mode = 'create';
                    this.dialog.visible = true;
                    this.$nextTick(this.resetDialogState);
                },
                openEditDialog: function (row) {
                    var self = this;
                    self.dialog.mode = 'edit';
                    self.dialog.visible = true;
                    self.$nextTick(function () {
                        self.resetDialogState();
                        fillFormFromRow(row, self.dialogForm, self.dialogDisplay);
                        if (self.$refs.dialogForm) {
                            self.$refs.dialogForm.clearValidate();
                        }
                    });
                },
                submitDialog: function () {
                    var self = this;
                    if (!self.$refs.dialogForm) {
                        return;
                    }
                    self.$refs.dialogForm.validate(function (valid) {
                        if (!valid) {
                            return false;
                        }
                        self.dialog.submitting = true;
                        $.ajax({
                            url: baseUrl + '/' + simpleEntityName + '/' + (self.dialog.mode === 'create' ? 'add' : 'update') + '/auth',
                            method: 'POST',
                            headers: self.authHeaders(),
                            data: buildPayload(self.dialogForm),
                            success: function (res) {
                                self.dialog.submitting = false;
                                if (self.handleForbidden(res)) {
                                    return;
                                }
                                if (!res || res.code !== 200) {
                                    self.$message.error((res && res.msg) ? res.msg : '保存失败');
                                    return;
                                }
                                self.$message.success(res.msg || '保存成功');
                                self.dialog.visible = false;
                                self.loadTable();
                            },
                            error: function () {
                                self.dialog.submitting = false;
                                self.$message.error('保存失败');
                            }
                        });
                        return true;
                    });
                },
                removeSelection: function () {
                    var self = this;
                    var ids = self.selection.map(function (row) {
                        return row[self.primaryKeyField];
                    });
                    self.removeRows(ids);
                },
                removeRows: function (ids) {
                    var self = this;
                    if (!ids || ids.length === 0) {
                        self.$message.warning('请选择要删除的数据');
                        return;
                    }
                    self.$confirm('确定删除选中的记录吗?', '提示', { type: 'warning' }).then(function () {
                        $.ajax({
                            url: baseUrl + '/' + simpleEntityName + '/delete/auth',
                            method: 'POST',
                            headers: self.authHeaders(),
                            traditional: true,
                            data: { 'ids[]': ids },
                            success: function (res) {
                                if (self.handleForbidden(res)) {
                                    return;
                                }
                                if (!res || res.code !== 200) {
                                    self.$message.error((res && res.msg) ? res.msg : '删除失败');
                                    return;
                                }
                                self.$message.success(res.msg || '删除成功');
                                self.selection = [];
                                if (self.tableData.length === ids.length && self.page.curr > 1) {
                                    self.page.curr = self.page.curr - 1;
                                }
                                self.loadTable();
                            },
                            error: function () {
                                self.$message.error('删除失败');
                            }
                        });
                    }).catch(function () {});
                },
                exportRows: function () {
                    var self = this;
                    self.exporting = true;
                    var requestBody = {
                        fields: self.exportColumns.map(function (item) {
                            return item.field;
                        })
                    };
                    requestBody[simpleEntityName] = self.buildQueryParams();
                    $.ajax({
                        url: baseUrl + '/' + simpleEntityName + '/export/auth',
                        method: 'POST',
                        headers: $.extend({ 'Content-Type': 'application/json;charset=UTF-8' }, self.authHeaders()),
                        data: JSON.stringify(requestBody),
                        success: function (res) {
                            self.exporting = false;
                            if (self.handleForbidden(res)) {
                                return;
                            }
                            if (!res || res.code !== 200) {
                                self.$message.error((res && res.msg) ? res.msg : '导出失败');
                                return;
                            }
                            createDownloadFile(
                                simpleEntityName + '_' + buildTimestamp() + '.xls',
                                self.exportColumns.map(function (item) {
                                    return item.label;
                                }),
                                Array.isArray(res.data) ? res.data : []
                            );
                            self.$message.success('导出成功');
                        },
                        error: function () {
                            self.exporting = false;
                            self.$message.error('导出失败');
                        }
                    });
                }
            })
        });
    }
    // 搜索
    form.on('submit(search)', function (data) {
        pageCurr = 1;
        tableReload(false);
    });
    // 重置
    form.on('submit(reset)', function (data) {
        pageCurr = 1;
        clearFormVal($('#search-box'));
        tableReload(false);
    });
    // 时间选择器
    function layDateRender(data) {
        setTimeout(function () {
            layDate.render({
                elem: '.layui-laydate-range'
                ,type: 'datetime'
                ,range: true
            });
            layDate.render({
                elem: '#modiTime\\$',
                type: 'datetime',
                value: data!==undefined?data['modiTime\\$']:null
            });
            layDate.render({
                elem: '#appeTime\\$',
                type: 'datetime',
                value: data!==undefined?data['appeTime\\$']:null
            });
        }, 300);
    }
    layDateRender();
});
// 关闭动作
$(document).on('click','#data-detail-close', function () {
    parent.layer.closeAll();
});
function tableReload(child) {
    var searchData = {};
    $.each($('#search-box [name]').serializeArray(), function() {
        searchData[this.name] = this.value;
    });
    tableIns.reload({
        where: searchData,
        page: {curr: pageCurr}
     });
}
})();
src/main/webapp/static/js/basCrnpErrLog/basCrnpErrLog.js
@@ -1,285 +1,1165 @@
var pageCurr;
layui.config({
    base: baseUrl + "/static/layui/lay/modules/"
}).use(['table','laydate', 'form', 'admin'], function(){
    var table = layui.table;
    var $ = layui.jquery;
    var layer = layui.layer;
    var layDate = layui.laydate;
    var form = layui.form;
    var admin = layui.admin;
(function () {
    var simpleEntityName = 'basCrnpErrLog';
    var entityName = 'BasCrnpErrLog';
    var primaryKeyField = 'id';
    var fieldMeta = dedupeFieldMeta([
    {
        field: 'id',
        columnName: 'id',
        label: '编  号',
        tableProp: 'id',
        exportField: 'id',
        kind: 'text',
        valueType: 'number',
        required: true,
        primaryKey: true,
        sortable: true,
        textarea: false,
        minWidth: 90,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'wrkNo',
        columnName: 'wrk_no',
        label: '工 作 号',
        tableProp: 'wrkNo',
        exportField: 'wrkNo',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 116,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'startTime',
        columnName: 'start_time',
        label: '发生时间',
        tableProp: 'startTime$',
        exportField: 'startTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'endTime',
        columnName: 'end_time',
        label: '结束时间',
        tableProp: 'endTime$',
        exportField: 'endTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'wrkSts',
        columnName: 'wrk_sts',
        label: '工作状态',
        tableProp: 'wrkSts$',
        exportField: 'wrkSts$',
        kind: 'foreign',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: 'basWrkStatus',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'ioType',
        columnName: 'io_type',
        label: '入出库类型',
        tableProp: 'ioType$',
        exportField: 'ioType$',
        kind: 'foreign',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 116,
        enumOptions: [],
        foreignQuery: 'basWrkIotype',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'crnNo',
        columnName: 'crn_no',
        label: '堆垛机号',
        tableProp: 'crnNo',
        exportField: 'crnNo',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'locNo',
        columnName: 'loc_no',
        label: '目标库位',
        tableProp: 'locNo',
        exportField: 'locNo',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'staNo',
        columnName: 'sta_no',
        label: '目 标 站',
        tableProp: 'staNo',
        exportField: 'staNo',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 116,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'sourceStaNo',
        columnName: 'source_sta_no',
        label: '源  站',
        tableProp: 'sourceStaNo',
        exportField: 'sourceStaNo',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'sourceLocNo',
        columnName: 'source_loc_no',
        label: '源 库 位',
        tableProp: 'sourceLocNo',
        exportField: 'sourceLocNo',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 116,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'barcode',
        columnName: 'barcode',
        label: '条  码',
        tableProp: 'barcode',
        exportField: 'barcode',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'errCode',
        columnName: 'err_code',
        label: '异 常 码',
        tableProp: 'errCode',
        exportField: 'errCode',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 116,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'error',
        columnName: 'error',
        label: '异  常',
        tableProp: 'error',
        exportField: 'error',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'status',
        columnName: 'status',
        label: '异常情况',
        tableProp: 'status$',
        exportField: 'status$',
        kind: 'enum',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 120,
        enumOptions: [{ rawValue: '1', label: '未处理' }, { rawValue: '2', label: '已修复' }],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'createTime',
        columnName: 'create_time',
        label: '添加时间',
        tableProp: 'createTime$',
        exportField: 'createTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'createBy',
        columnName: 'create_by',
        label: '添加人员',
        tableProp: 'createBy$',
        exportField: 'createBy$',
        kind: 'foreign',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: 'user',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'updateTime',
        columnName: 'update_time',
        label: '修改时间',
        tableProp: 'updateTime$',
        exportField: 'updateTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'updateBy',
        columnName: 'update_by',
        label: '修改人员',
        tableProp: 'updateBy$',
        exportField: 'updateBy$',
        kind: 'foreign',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: 'user',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'memo',
        columnName: 'memo',
        label: '备  注',
        tableProp: 'memo',
        exportField: 'memo',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: true,
        minWidth: 180,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'systemStatus',
        columnName: 'system_status',
        label: '系统状态数据',
        tableProp: 'systemStatus',
        exportField: 'systemStatus',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 134,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    }
    // 数据渲染
    tableIns = table.render({
        elem: '#basCrnpErrLog',
        headers: {token: localStorage.getItem('token')},
        url: baseUrl+'/basCrnpErrLog/list/auth',
        page: true,
        limit: 15,
        limits: [15, 30, 50, 100, 200, 500],
        toolbar: '#toolbar',
        cellMinWidth: 50,
        height: 'full-120',
        cols: [[
            {type: 'checkbox'}
            ,{field: 'id', align: 'center',title: '编号'}
            ,{field: 'wrkNo', align: 'center',title: '工作号'}
            ,{field: 'startTime$', align: 'center',title: '发生时间'}
            ,{field: 'endTime$', align: 'center',title: '结束时间'}
            ,{field: 'wrkSts$', align: 'center',title: '工作状态'}
            ,{field: 'ioType$', align: 'center',title: '入出库类型'}
            ,{field: 'crnNo', align: 'center',title: '堆垛机号'}
            ,{field: 'locNo', align: 'center',title: '目标库位'}
            ,{field: 'staNo', align: 'center',title: '目标站'}
            ,{field: 'sourceStaNo', align: 'center',title: '源站'}
            ,{field: 'sourceLocNo', align: 'center',title: '源库位'}
            ,{field: 'barcode', align: 'center',title: '条码'}
            ,{field: 'errCode', align: 'center',title: '异常码'}
            ,{field: 'error', align: 'center',title: '异常'}
            ,{field: 'status$', align: 'center',title: '异常情况'}
            ,{field: 'createTime$', align: 'center',title: '添加时间'}
            ,{field: 'createBy$', align: 'center',title: '添加人员'}
            ,{field: 'updateTime$', align: 'center',title: '修改时间'}
            ,{field: 'updateBy$', align: 'center',title: '修改人员'}
            ,{field: 'memo', align: 'center',title: '备注'}
            ,{field: 'systemStatus', align: 'center',title: '系统状态数据'}
    ]);
            ,{fixed: 'right', title:'操作', align: 'center', toolbar: '#operate', width:120}
        ]],
        request: {
            pageName: 'curr',
            pageSize: 'limit'
        },
        parseData: function (res) {
            return {
                'code': res.code,
                'msg': res.msg,
                'count': res.data.total,
                'data': res.data.records
            }
        },
        response: {
            statusCode: 200
        },
        done: function(res, curr, count) {
            if (res.code === 403) {
                top.location.href = baseUrl+"/";
            }
            pageCurr=curr;
            limit();
    function formatFieldLabel(field) {
        var raw = field && field.label ? String(field.label).trim() : '';
        if (raw) {
            return raw;
        }
    });
    // 监听排序事件
    table.on('sort(basCrnpErrLog)', function (obj) {
        var searchData = {};
        $.each($('#search-box [name]').serializeArray(), function() {
            searchData[this.name] = this.value;
        });
        searchData['orderByField'] = obj.field;
        searchData['orderByType'] = obj.type;
        tableIns.reload({
            where: searchData,
            page: {curr: 1}
        });
    });
    // 监听头工具栏事件
    table.on('toolbar(basCrnpErrLog)', function (obj) {
        var checkStatus = table.checkStatus(obj.config.id).data;
        switch(obj.event) {
            case 'addData':
                showEditModel();
                break;
            case 'deleteData':
               if (checkStatus.length === 0) {
                   layer.msg('请选择要删除的数据', {icon: 2});
                   return;
               }
               del(checkStatus.map(function (d) {
                   return d.id;
               }));
               break;
            case 'exportData':
                admin.confirm('确定导出Excel吗', {shadeClose: true}, function(){
                    var titles=[];
                    var fields=[];
                    obj.config.cols[0].map(function (col) {
                        if (col.type === 'normal' && col.hide === false && col.toolbar == null) {
                            titles.push(col.title);
                            fields.push(col.field);
                        }
                    });
                    var exportData = {};
                    $.each($('#search-box [name]').serializeArray(), function() {
                        exportData[this.name] = this.value;
                    });
                    var param = {
                        'basCrnpErrLog': exportData,
                        'fields': fields
                    };
                    $.ajax({
                        url: baseUrl+"/basCrnpErrLog/export/auth",
                        headers: {'token': localStorage.getItem('token')},
                        data: JSON.stringify(param),
                        dataType:'json',
                        contentType:'application/json;charset=UTF-8',
                        method: 'POST',
                        success: function (res) {
                            layer.closeAll();
                            if (res.code === 200) {
                                table.exportFile(titles,res.data,'xls');
                            } else if (res.code === 403) {
                                top.location.href = baseUrl+"/";
                            } else {
                                layer.msg(res.msg, {icon: 2})
                            }
                        }
                    });
                });
                break;
        raw = field && field.columnName ? field.columnName : (field && field.field ? field.field : '');
        if (!raw) {
            return '';
        }
    });
    // 监听行工具事件
    table.on('tool(basCrnpErrLog)', function(obj){
        var data = obj.data;
        switch (obj.event) {
            case 'edit':
                showEditModel(data);
                break;
            case "del":
                del([data.id]);
                break;
        }
    });
    /* 弹窗 - 新增、修改 */
    function showEditModel(mData) {
        admin.open({
            type: 1,
            area: '600px',
            title: (mData ? '修改' : '添加') + '订单状态',
            content: $('#editDialog').html(),
            success: function (layero, dIndex) {
                layDateRender(mData);
                form.val('detail', mData);
                form.on('submit(editSubmit)', function (data) {
                    var loadIndex = layer.load(2);
                    $.ajax({
                        url: baseUrl+"/basCrnpErrLog/"+(mData?'update':'add')+"/auth",
                        headers: {'token': localStorage.getItem('token')},
                        data: data.field,
                        method: 'POST',
                        success: function (res) {
                            layer.close(loadIndex);
                            if (res.code === 200){
                                layer.close(dIndex);
                                layer.msg(res.msg, {icon: 1});
                                tableReload();
                            } else if (res.code === 403){
                                top.location.href = baseUrl+"/";
                            }else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }
                    })
                    return false;
                });
                $(layero).children('.layui-layer-content').css('overflow', 'visible');
                layui.form.render('select');
            }
        raw = String(raw)
            .replace(/\$/g, '')
            .replace(/([a-z0-9])([A-Z])/g, '$1_$2')
            .replace(/_/g, ' ')
            .replace(/\s+/g, ' ')
            .trim();
        return raw.replace(/\b[a-z]/g, function (letter) {
            return letter.toUpperCase();
        });
    }
    /* 删除 */
    function del(ids) {
        layer.confirm('确定要删除选中数据吗?', {
            skin: 'layui-layer-admin',
            shade: .1
        }, function (i) {
            layer.close(i);
            var loadIndex = layer.load(2);
    function dedupeFieldMeta(list) {
        var result = [];
        var seen = {};
        (list || []).forEach(function (field) {
            if (!field || !field.field || seen[field.field]) {
                return;
            }
            field.label = formatFieldLabel(field);
            seen[field.field] = true;
            result.push(field);
        });
        return result;
    }
    function isEmptyValue(value) {
        return value === null || value === undefined || value === '';
    }
    function stringValue(value) {
        return isEmptyValue(value) ? '' : String(value);
    }
    function valueOrDash(value) {
        return isEmptyValue(value) ? '--' : value;
    }
    function normalizeOptionValue(field, rawValue) {
        if (rawValue === null || rawValue === undefined) {
            return null;
        }
        if (rawValue === '') {
            return '';
        }
        if (field && field.valueType === 'number') {
            var numberVal = Number(rawValue);
            return isNaN(numberVal) ? rawValue : numberVal;
        }
        return String(rawValue);
    }
    function isSearchableField(field) {
        return !!field && field.kind !== 'image' && !field.textarea;
    }
    function isSortableField(field) {
        if (!field) {
            return false;
        }
        if (field.primaryKey) {
            return true;
        }
        return field.kind !== 'image' && !field.textarea && field.kind !== 'foreign';
    }
    function defaultFieldValue(field) {
        if (field.primaryKey) {
            return null;
        }
        if (field.kind === 'checkbox') {
            return normalizeOptionValue(field, field.checkboxInactiveRaw);
        }
        return '';
    }
    function defaultSearchFieldValue(field) {
        if (field.kind === 'date') {
            return [];
        }
        if (field.kind === 'enum' || field.kind === 'checkbox') {
            return null;
        }
        return '';
    }
    function createSearchDefaults() {
        var result = {
            condition: ''
        };
        fieldMeta.forEach(function (field) {
            if (!isSearchableField(field)) {
                return;
            }
            result[field.field] = defaultSearchFieldValue(field);
        });
        return result;
    }
    function createSearchDisplayDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            if (field.kind === 'foreign' && isSearchableField(field)) {
                result[field.field] = '';
            }
        });
        return result;
    }
    function createDefaultVisibleColumnKeys() {
        return fieldMeta.map(function (field) {
            return field.field;
        });
    }
    function createFormDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            result[field.field] = defaultFieldValue(field);
        });
        return result;
    }
    function createDisplayDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            if (field.kind === 'foreign') {
                result[field.field] = '';
            }
        });
        return result;
    }
    function createFormRules() {
        var rules = {};
        fieldMeta.forEach(function (field) {
            if (field.primaryKey || !field.required) {
                return;
            }
            rules[field.field] = [{
                required: true,
                message: (field.kind === 'date' || field.kind === 'enum' ? '请选择' : '请输入') + field.label,
                trigger: (field.kind === 'date' || field.kind === 'enum') ? 'change' : 'blur'
            }];
        });
        return rules;
    }
    function getTableValue(row, field) {
        var prop = field.tableProp || field.field;
        if (row && !isEmptyValue(row[prop])) {
            return row[prop];
        }
        return row ? row[field.field] : '';
    }
    function isCheckboxChecked(row, field) {
        var value = row ? row[field.field] : null;
        var activeValue = normalizeOptionValue(field, field.checkboxActiveRaw);
        return String(value) === String(activeValue);
    }
    function exportCell(value) {
        return stringValue(value).replace(/\t/g, ' ').replace(/\r?\n/g, ' ');
    }
    function escapeHtml(value) {
        return exportCell(value)
            .replace(/&/g, '&amp;')
            .replace(/</g, '&lt;')
            .replace(/>/g, '&gt;')
            .replace(/"/g, '&quot;')
            .replace(/'/g, '&#39;');
    }
    function buildPayload(form) {
        var payload = {};
        fieldMeta.forEach(function (field) {
            var value = form[field.field];
            if (field.primaryKey) {
                if (!isEmptyValue(value)) {
                    payload[field.field] = value;
                }
                return;
            }
            if (field.kind === 'foreign' && isEmptyValue(value)) {
                value = null;
            }
            if (field.kind === 'enum' && value === '') {
                value = null;
            }
            if (field.kind === 'checkbox' && isEmptyValue(value)) {
                value = normalizeOptionValue(field, field.checkboxInactiveRaw);
            }
            if (field.valueType === 'number' && !isEmptyValue(value)) {
                value = Number(value);
            }
            if (field.valueType === 'number' && value === '') {
                value = null;
            }
            payload[field.field] = value;
        });
        return payload;
    }
    function fillFormFromRow(row, form, display) {
        fieldMeta.forEach(function (field) {
            if (field.primaryKey) {
                form[field.field] = row[field.field];
                return;
            }
            if (field.kind === 'date') {
                form[field.field] = row[field.tableProp] || row[field.field] || '';
                return;
            }
            if (field.kind === 'foreign') {
                form[field.field] = isEmptyValue(row[field.field]) ? '' : normalizeOptionValue(field, row[field.field]);
                if (display) {
                    display[field.field] = row[field.tableProp] || (isEmptyValue(row[field.field]) ? '' : String(row[field.field]));
                }
                return;
            }
            if (field.kind === 'enum') {
                form[field.field] = isEmptyValue(row[field.field]) ? '' : normalizeOptionValue(field, row[field.field]);
                return;
            }
            if (field.kind === 'checkbox') {
                form[field.field] = isEmptyValue(row[field.field])
                    ? normalizeOptionValue(field, field.checkboxInactiveRaw)
                    : normalizeOptionValue(field, row[field.field]);
                return;
            }
            form[field.field] = isEmptyValue(row[field.field])
                ? ''
                : (field.valueType === 'number' ? String(row[field.field]) : row[field.field]);
        });
    }
    function resolveSearchParam(field) {
        if (field.kind === 'date' && field.columnName) {
            return field.columnName;
        }
        return field.field;
    }
    function createDownloadFile(filename, titles, rows) {
        var html = [
            '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">',
            '<head><meta charset="UTF-8"></head><body><table border="1"><thead><tr>',
            titles.map(function (title) {
                return '<th>' + escapeHtml(title) + '</th>';
            }).join(''),
            '</tr></thead><tbody>',
            (rows || []).map(function (row) {
                return '<tr>' + (row || []).map(function (value) {
                    return '<td style="mso-number-format:\\@;">' + escapeHtml(value) + '</td>';
                }).join('') + '</tr>';
            }).join(''),
            '</tbody></table></body></html>'
        ].join('');
        var blob = new Blob(['\ufeff' + html], {
            type: 'application/vnd.ms-excel;charset=utf-8;'
        });
        var anchor = document.createElement('a');
        anchor.href = URL.createObjectURL(blob);
        anchor.download = filename;
        document.body.appendChild(anchor);
        anchor.click();
        setTimeout(function () {
            URL.revokeObjectURL(anchor.href);
            document.body.removeChild(anchor);
        }, 0);
    }
    function buildTimestamp() {
        var now = new Date();
        var pad = function (num) {
            return num < 10 ? '0' + num : String(num);
        };
        return now.getFullYear()
            + pad(now.getMonth() + 1)
            + pad(now.getDate())
            + '_'
            + pad(now.getHours())
            + pad(now.getMinutes())
            + pad(now.getSeconds());
    }
    function authHeaders() {
        return {
            token: localStorage.getItem('token')
        };
    }
    function handleForbidden(res) {
        if (res && res.code === 403) {
            top.location.href = baseUrl + '/';
            return true;
        }
        return false;
    }
    var sharedMethods = {
        authHeaders: authHeaders,
        handleForbidden: handleForbidden,
        valueOrDash: valueOrDash,
        stringValue: stringValue,
        getTableValue: getTableValue,
        isCheckboxChecked: isCheckboxChecked,
        normalizeOptionValue: normalizeOptionValue,
        isSortableField: isSortableField,
        getSuggestionFetcher: function (field) {
            var self = this;
            return function (queryString, callback) {
                self.fetchForeignSuggestions(field, queryString, callback);
            };
        },
        fetchForeignSuggestions: function (field, queryString, callback) {
            if (!field.foreignQuery || !queryString) {
                callback([]);
                return;
            }
            var self = this;
            $.ajax({
                url: baseUrl+"/basCrnpErrLog/delete/auth",
                headers: {'token': localStorage.getItem('token')},
                data: {ids: ids},
                method: 'POST',
                url: baseUrl + '/' + field.foreignQuery + 'Query/auth',
                method: 'GET',
                headers: self.authHeaders(),
                data: { condition: queryString },
                success: function (res) {
                    layer.close(loadIndex);
                    if (res.code === 200){
                        layer.msg(res.msg, {icon: 1});
                        tableReload();
                    } else if (res.code === 403){
                        top.location.href = baseUrl+"/";
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    if (self.handleForbidden(res)) {
                        return;
                    }
                    if (!res || res.code !== 200 || !Array.isArray(res.data)) {
                        callback([]);
                        return;
                    }
                    callback(res.data.map(function (item) {
                        return {
                            id: item.id,
                            value: item.value
                        };
                    }));
                },
                error: function () {
                    callback([]);
                }
            });
        },
        handleForeignSelect: function (field, item) {
            this.$set(this.displayTarget, field.field, item && item.value ? item.value : '');
            this.$set(this.formTarget, field.field, item && item.id !== undefined ? normalizeOptionValue(field, item.id) : '');
        },
        handleForeignInput: function (field) {
            if (!this.displayTarget || !this.formTarget) {
                return;
            }
            if (this.displayTarget[field.field]) {
                return;
            }
            this.$set(this.formTarget, field.field, '');
        }
    };
    if (document.getElementById('app')) {
        new Vue({
            el: '#app',
            data: function () {
                return {
                    fieldMeta: fieldMeta,
                    primaryKeyField: primaryKeyField,
                    loading: false,
                    exporting: false,
                    tableData: [],
                    selection: [],
                    advancedFiltersVisible: false,
                    allColumns: fieldMeta.slice(),
                    visibleColumnKeys: createDefaultVisibleColumnKeys(),
                    searchForm: createSearchDefaults(),
                    searchDisplay: createSearchDisplayDefaults(),
                    page: {
                        curr: 1,
                        limit: 15,
                        total: 0
                    },
                    sortState: {
                        prop: '',
                        order: ''
                    },
                    dialog: {
                        visible: false,
                        mode: 'create',
                        submitting: false
                    },
                    layoutTimer: null,
                    tableResizeHandler: null,
                    dialogForm: createFormDefaults(),
                    dialogDisplay: createDisplayDefaults(),
                    dialogRules: createFormRules()
                };
            },
            computed: {
                searchableFields: function () {
                    return this.fieldMeta.filter(function (field) {
                        return isSearchableField(field);
                    });
                },
                quickSearchableFields: function () {
                    var result = [];
                    this.searchableFields.forEach(function (field) {
                        if (result.length >= 3 || field.kind === 'date') {
                            return;
                        }
                        result.push(field);
                    });
                    return result;
                },
                advancedSearchableFields: function () {
                    var quickKeys = this.quickSearchableFields.map(function (field) {
                        return field.field;
                    });
                    return this.searchableFields.filter(function (field) {
                        return quickKeys.indexOf(field.field) === -1;
                    });
                },
                hasAdvancedFilters: function () {
                    return this.advancedSearchableFields.length > 0;
                },
                visibleColumns: function () {
                    var keys = this.visibleColumnKeys;
                    return this.allColumns.filter(function (field) {
                        return keys.indexOf(field.field) !== -1;
                    });
                },
                editableFields: function () {
                    return this.fieldMeta.filter(function (field) {
                        return !field.primaryKey;
                    });
                },
                exportColumns: function () {
                    return this.visibleColumns.map(function (field) {
                        return {
                            field: field.exportField || field.tableProp || field.field,
                            label: field.label
                        };
                    });
                },
                tableHeight: function () {
                    return this.advancedFiltersVisible && this.hasAdvancedFilters
                        ? 'calc(100vh - 390px)'
                        : 'calc(100vh - 300px)';
                },
                formTarget: function () {
                    return this.dialogForm;
                },
                displayTarget: function () {
                    return this.dialogDisplay;
                }
            },
            created: function () {
                this.loadTable();
            },
            mounted: function () {
                var self = this;
                self.requestTableLayout(80);
                self.tableResizeHandler = function () {
                    self.requestTableLayout(80);
                };
                window.addEventListener('resize', self.tableResizeHandler);
            },
            beforeDestroy: function () {
                if (this.layoutTimer) {
                    clearTimeout(this.layoutTimer);
                    this.layoutTimer = null;
                }
                if (this.tableResizeHandler) {
                    window.removeEventListener('resize', this.tableResizeHandler);
                    this.tableResizeHandler = null;
                }
            },
            methods: $.extend({}, sharedMethods, {
                requestTableLayout: function (delay) {
                    var self = this;
                    if (self.layoutTimer) {
                        clearTimeout(self.layoutTimer);
                    }
                    self.$nextTick(function () {
                        self.layoutTimer = setTimeout(function () {
                            var table = self.$refs.dataTable;
                            if (table && typeof table.doLayout === 'function') {
                                table.doLayout();
                            }
                        }, delay || 40);
                    });
                },
                isColumnVisible: function (fieldName) {
                    return this.visibleColumnKeys.indexOf(fieldName) !== -1;
                },
                toggleColumn: function (fieldName, visible) {
                    if (visible) {
                        if (this.visibleColumnKeys.indexOf(fieldName) === -1) {
                            this.visibleColumnKeys.push(fieldName);
                        }
                        this.requestTableLayout(80);
                        return;
                    }
                    if (this.visibleColumnKeys.length === 1) {
                        this.$message.warning('至少保留一列');
                        return;
                    }
                    this.visibleColumnKeys = this.visibleColumnKeys.filter(function (item) {
                        return item !== fieldName;
                    });
                    this.requestTableLayout(80);
                },
                selectAllColumns: function () {
                    this.visibleColumnKeys = createDefaultVisibleColumnKeys();
                    this.requestTableLayout(80);
                },
                resetColumns: function () {
                    this.visibleColumnKeys = createDefaultVisibleColumnKeys();
                    this.requestTableLayout(80);
                },
                toggleAdvancedFilters: function () {
                    this.advancedFiltersVisible = !this.advancedFiltersVisible;
                    this.requestTableLayout(260);
                },
                handleSearchForeignSelect: function (field, item) {
                    this.$set(this.searchDisplay, field.field, item && item.value ? item.value : '');
                    this.$set(this.searchForm, field.field, item && item.id !== undefined ? normalizeOptionValue(field, item.id) : '');
                },
                handleSearchForeignInput: function (field) {
                    if (this.searchDisplay[field.field]) {
                        return;
                    }
                    this.$set(this.searchForm, field.field, '');
                },
                buildQueryParams: function () {
                    var self = this;
                    var params = {
                        curr: self.page.curr,
                        limit: self.page.limit
                    };
                    if (self.searchForm.condition) {
                        params.condition = self.searchForm.condition;
                    }
                    self.searchableFields.forEach(function (field) {
                        var value = self.searchForm[field.field];
                        if (field.kind === 'date') {
                            if (value && value.length === 2) {
                                params[resolveSearchParam(field)] = value[0] + ' - ' + value[1];
                            }
                            return;
                        }
                        if (!isEmptyValue(value)) {
                            params[resolveSearchParam(field)] = value;
                        }
                    });
                    if (self.sortState.prop && self.sortState.order) {
                        params.orderByField = self.sortState.prop;
                        params.orderByType = self.sortState.order === 'ascending' ? 'asc' : 'desc';
                    }
                    return params;
                },
                loadTable: function () {
                    var self = this;
                    self.loading = true;
                    $.ajax({
                        url: baseUrl + '/' + simpleEntityName + '/list/auth',
                        method: 'GET',
                        headers: self.authHeaders(),
                        data: self.buildQueryParams(),
                        success: function (res) {
                            self.loading = false;
                            if (self.handleForbidden(res)) {
                                return;
                            }
                            if (!res || res.code !== 200) {
                                self.$message.error((res && res.msg) ? res.msg : '加载失败');
                                return;
                            }
                            var payload = res.data || {};
                            self.tableData = Array.isArray(payload.records) ? payload.records : [];
                            self.page.total = payload.total || 0;
                            self.requestTableLayout(80);
                        },
                        error: function () {
                            self.loading = false;
                            self.requestTableLayout(80);
                            self.$message.error('加载失败');
                        }
                    });
                },
                handleSearch: function () {
                    this.page.curr = 1;
                    this.loadTable();
                },
                handleReset: function () {
                    this.searchForm = createSearchDefaults();
                    this.searchDisplay = createSearchDisplayDefaults();
                    this.advancedFiltersVisible = false;
                    this.page.curr = 1;
                    this.sortState = {
                        prop: '',
                        order: ''
                    };
                    this.loadTable();
                },
                handleSelectionChange: function (rows) {
                    this.selection = rows || [];
                },
                handleSortChange: function (payload) {
                    this.sortState = {
                        prop: payload && payload.prop ? payload.prop : '',
                        order: payload && payload.order ? payload.order : ''
                    };
                    this.page.curr = 1;
                    this.loadTable();
                },
                handleCurrentChange: function (curr) {
                    this.page.curr = curr;
                    this.loadTable();
                },
                handleSizeChange: function (limit) {
                    this.page.limit = limit;
                    this.page.curr = 1;
                    this.loadTable();
                },
                resetDialogState: function () {
                    this.dialogForm = createFormDefaults();
                    this.dialogDisplay = createDisplayDefaults();
                    if (this.$refs.dialogForm) {
                        this.$refs.dialogForm.clearValidate();
                    }
                },
                openCreateDialog: function () {
                    this.dialog.mode = 'create';
                    this.dialog.visible = true;
                    this.$nextTick(this.resetDialogState);
                },
                openEditDialog: function (row) {
                    var self = this;
                    self.dialog.mode = 'edit';
                    self.dialog.visible = true;
                    self.$nextTick(function () {
                        self.resetDialogState();
                        fillFormFromRow(row, self.dialogForm, self.dialogDisplay);
                        if (self.$refs.dialogForm) {
                            self.$refs.dialogForm.clearValidate();
                        }
                    });
                },
                submitDialog: function () {
                    var self = this;
                    if (!self.$refs.dialogForm) {
                        return;
                    }
                    self.$refs.dialogForm.validate(function (valid) {
                        if (!valid) {
                            return false;
                        }
                        self.dialog.submitting = true;
                        $.ajax({
                            url: baseUrl + '/' + simpleEntityName + '/' + (self.dialog.mode === 'create' ? 'add' : 'update') + '/auth',
                            method: 'POST',
                            headers: self.authHeaders(),
                            data: buildPayload(self.dialogForm),
                            success: function (res) {
                                self.dialog.submitting = false;
                                if (self.handleForbidden(res)) {
                                    return;
                                }
                                if (!res || res.code !== 200) {
                                    self.$message.error((res && res.msg) ? res.msg : '保存失败');
                                    return;
                                }
                                self.$message.success(res.msg || '保存成功');
                                self.dialog.visible = false;
                                self.loadTable();
                            },
                            error: function () {
                                self.dialog.submitting = false;
                                self.$message.error('保存失败');
                            }
                        });
                        return true;
                    });
                },
                removeSelection: function () {
                    var self = this;
                    var ids = self.selection.map(function (row) {
                        return row[self.primaryKeyField];
                    });
                    self.removeRows(ids);
                },
                removeRows: function (ids) {
                    var self = this;
                    if (!ids || ids.length === 0) {
                        self.$message.warning('请选择要删除的数据');
                        return;
                    }
                    self.$confirm('确定删除选中的记录吗?', '提示', { type: 'warning' }).then(function () {
                        $.ajax({
                            url: baseUrl + '/' + simpleEntityName + '/delete/auth',
                            method: 'POST',
                            headers: self.authHeaders(),
                            traditional: true,
                            data: { 'ids[]': ids },
                            success: function (res) {
                                if (self.handleForbidden(res)) {
                                    return;
                                }
                                if (!res || res.code !== 200) {
                                    self.$message.error((res && res.msg) ? res.msg : '删除失败');
                                    return;
                                }
                                self.$message.success(res.msg || '删除成功');
                                self.selection = [];
                                if (self.tableData.length === ids.length && self.page.curr > 1) {
                                    self.page.curr = self.page.curr - 1;
                                }
                                self.loadTable();
                            },
                            error: function () {
                                self.$message.error('删除失败');
                            }
                        });
                    }).catch(function () {});
                },
                exportRows: function () {
                    var self = this;
                    self.exporting = true;
                    var requestBody = {
                        fields: self.exportColumns.map(function (item) {
                            return item.field;
                        })
                    };
                    requestBody[simpleEntityName] = self.buildQueryParams();
                    $.ajax({
                        url: baseUrl + '/' + simpleEntityName + '/export/auth',
                        method: 'POST',
                        headers: $.extend({ 'Content-Type': 'application/json;charset=UTF-8' }, self.authHeaders()),
                        data: JSON.stringify(requestBody),
                        success: function (res) {
                            self.exporting = false;
                            if (self.handleForbidden(res)) {
                                return;
                            }
                            if (!res || res.code !== 200) {
                                self.$message.error((res && res.msg) ? res.msg : '导出失败');
                                return;
                            }
                            createDownloadFile(
                                simpleEntityName + '_' + buildTimestamp() + '.xls',
                                self.exportColumns.map(function (item) {
                                    return item.label;
                                }),
                                Array.isArray(res.data) ? res.data : []
                            );
                            self.$message.success('导出成功');
                        },
                        error: function () {
                            self.exporting = false;
                            self.$message.error('导出失败');
                        }
                    });
                }
            })
        });
    }
    // 搜索
    form.on('submit(search)', function (data) {
        pageCurr = 1;
        tableReload(false);
    });
    // 重置
    form.on('submit(reset)', function (data) {
        pageCurr = 1;
        clearFormVal($('#search-box'));
        tableReload(false);
    });
    // 时间选择器
    function layDateRender(data) {
        setTimeout(function () {
            layDate.render({
                elem: '.layui-laydate-range'
                ,type: 'datetime'
                ,range: true
            });
            layDate.render({
                elem: '#startTime\\$',
                type: 'datetime',
                value: data!==undefined?data['startTime\\$']:null
            });
            layDate.render({
                elem: '#endTime\\$',
                type: 'datetime',
                value: data!==undefined?data['endTime\\$']:null
            });
            layDate.render({
                elem: '#createTime\\$',
                type: 'datetime',
                value: data!==undefined?data['createTime\\$']:null
            });
            layDate.render({
                elem: '#updateTime\\$',
                type: 'datetime',
                value: data!==undefined?data['updateTime\\$']:null
            });
        }, 300);
    }
    layDateRender();
});
// 关闭动作
$(document).on('click','#data-detail-close', function () {
    parent.layer.closeAll();
});
function tableReload(child) {
    var searchData = {};
    $.each($('#search-box [name]').serializeArray(), function() {
        searchData[this.name] = this.value;
    });
    tableIns.reload({
        where: searchData,
        page: {curr: pageCurr}
     });
}
})();
src/main/webapp/static/js/basCrnpOpt/basCrnpOpt.js
@@ -1,268 +1,1039 @@
var pageCurr;
layui.config({
    base: baseUrl + "/static/layui/lay/modules/"
}).use(['table','laydate', 'form', 'admin'], function(){
    var table = layui.table;
    var $ = layui.jquery;
    var layer = layui.layer;
    var layDate = layui.laydate;
    var form = layui.form;
    var admin = layui.admin;
(function () {
    var simpleEntityName = 'basCrnpOpt';
    var entityName = 'BasCrnpOpt';
    var primaryKeyField = 'id';
    var fieldMeta = dedupeFieldMeta([
    {
        field: 'id',
        columnName: 'id',
        label: '编  号',
        tableProp: 'id',
        exportField: 'id',
        kind: 'text',
        valueType: 'number',
        required: true,
        primaryKey: true,
        sortable: true,
        textarea: false,
        minWidth: 90,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'wrkNo',
        columnName: 'wrk_no',
        label: '工 作 号',
        tableProp: 'wrkNo',
        exportField: 'wrkNo',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 116,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'crnNo',
        columnName: 'crn_no',
        label: '堆垛机号',
        tableProp: 'crnNo',
        exportField: 'crnNo',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'sendTime',
        columnName: 'send_time',
        label: '下发时间',
        tableProp: 'sendTime$',
        exportField: 'sendTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'mode',
        columnName: 'mode',
        label: '作  业',
        tableProp: 'mode',
        exportField: 'mode',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'sourceLocNo',
        columnName: 'source_loc_no',
        label: '起点库位',
        tableProp: 'sourceLocNo',
        exportField: 'sourceLocNo',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'targetLocNo',
        columnName: 'target_loc_no',
        label: '目标库位',
        tableProp: 'targetLocNo',
        exportField: 'targetLocNo',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'updateTime',
        columnName: 'update_time',
        label: '修改时间',
        tableProp: 'updateTime$',
        exportField: 'updateTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'updateBy',
        columnName: 'update_by',
        label: '修改人员',
        tableProp: 'updateBy$',
        exportField: 'updateBy$',
        kind: 'foreign',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: 'user',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'memo',
        columnName: 'memo',
        label: '备  注',
        tableProp: 'memo',
        exportField: 'memo',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: true,
        minWidth: 180,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'command',
        columnName: 'command',
        label: '命  令',
        tableProp: 'command',
        exportField: 'command',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'systemStatus',
        columnName: 'system_status',
        label: '系统状态',
        tableProp: 'systemStatus',
        exportField: 'systemStatus',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'send',
        columnName: 'send',
        label: '下发状态',
        tableProp: 'send$',
        exportField: 'send$',
        kind: 'enum',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 120,
        enumOptions: [{ rawValue: '0', label: '未下发' }, { rawValue: '1', label: '已下发' }],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'response',
        columnName: 'response',
        label: '请求响应',
        tableProp: 'response',
        exportField: 'response',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: true,
        minWidth: 180,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    }
    // 数据渲染
    tableIns = table.render({
        elem: '#basCrnpOpt',
        headers: {token: localStorage.getItem('token')},
        url: baseUrl+'/basCrnpOpt/list/auth',
        page: true,
        limit: 15,
        limits: [15, 30, 50, 100, 200, 500],
        toolbar: '#toolbar',
        cellMinWidth: 50,
        height: 'full-120',
        cols: [[
            {type: 'checkbox'}
            ,{field: 'id', align: 'center',title: '编号'}
            ,{field: 'wrkNo', align: 'center',title: '工作号'}
            ,{field: 'crnNo', align: 'center',title: '堆垛机号'}
            ,{field: 'sendTime$', align: 'center',title: '下发时间'}
            ,{field: 'mode', align: 'center',title: '作业'}
            ,{field: 'sourceLocNo', align: 'center',title: '起点库位'}
            ,{field: 'targetLocNo', align: 'center',title: '目标库位'}
            ,{field: 'updateTime$', align: 'center',title: '修改时间'}
            ,{field: 'updateBy$', align: 'center',title: '修改人员'}
            ,{field: 'memo', align: 'center',title: '备注'}
            ,{field: 'command', align: 'center',title: '命令'}
            ,{field: 'systemStatus', align: 'center',title: '系统状态'}
            ,{field: 'send$', align: 'center',title: '下发状态'}
            ,{field: 'response', align: 'center',title: '请求响应'}
    ]);
            ,{fixed: 'right', title:'操作', align: 'center', toolbar: '#operate', width:120}
        ]],
        request: {
            pageName: 'curr',
            pageSize: 'limit'
        },
        parseData: function (res) {
            return {
                'code': res.code,
                'msg': res.msg,
                'count': res.data.total,
                'data': res.data.records
            }
        },
        response: {
            statusCode: 200
        },
        done: function(res, curr, count) {
            if (res.code === 403) {
                top.location.href = baseUrl+"/";
            }
            pageCurr=curr;
            limit();
    function formatFieldLabel(field) {
        var raw = field && field.label ? String(field.label).trim() : '';
        if (raw) {
            return raw;
        }
    });
    // 监听排序事件
    table.on('sort(basCrnpOpt)', function (obj) {
        var searchData = {};
        $.each($('#search-box [name]').serializeArray(), function() {
            searchData[this.name] = this.value;
        });
        searchData['orderByField'] = obj.field;
        searchData['orderByType'] = obj.type;
        tableIns.reload({
            where: searchData,
            page: {curr: 1}
        });
    });
    // 监听头工具栏事件
    table.on('toolbar(basCrnpOpt)', function (obj) {
        var checkStatus = table.checkStatus(obj.config.id).data;
        switch(obj.event) {
            case 'addData':
                showEditModel();
                break;
            case 'deleteData':
               if (checkStatus.length === 0) {
                   layer.msg('请选择要删除的数据', {icon: 2});
                   return;
               }
               del(checkStatus.map(function (d) {
                   return d.id;
               }));
               break;
            case 'exportData':
                admin.confirm('确定导出Excel吗', {shadeClose: true}, function(){
                    var titles=[];
                    var fields=[];
                    obj.config.cols[0].map(function (col) {
                        if (col.type === 'normal' && col.hide === false && col.toolbar == null) {
                            titles.push(col.title);
                            fields.push(col.field);
                        }
                    });
                    var exportData = {};
                    $.each($('#search-box [name]').serializeArray(), function() {
                        exportData[this.name] = this.value;
                    });
                    var param = {
                        'basCrnpOpt': exportData,
                        'fields': fields
                    };
                    $.ajax({
                        url: baseUrl+"/basCrnpOpt/export/auth",
                        headers: {'token': localStorage.getItem('token')},
                        data: JSON.stringify(param),
                        dataType:'json',
                        contentType:'application/json;charset=UTF-8',
                        method: 'POST',
                        success: function (res) {
                            layer.closeAll();
                            if (res.code === 200) {
                                table.exportFile(titles,res.data,'xls');
                            } else if (res.code === 403) {
                                top.location.href = baseUrl+"/";
                            } else {
                                layer.msg(res.msg, {icon: 2})
                            }
                        }
                    });
                });
                break;
        raw = field && field.columnName ? field.columnName : (field && field.field ? field.field : '');
        if (!raw) {
            return '';
        }
    });
    // 监听行工具事件
    table.on('tool(basCrnpOpt)', function(obj){
        var data = obj.data;
        switch (obj.event) {
            case 'edit':
                showEditModel(data);
                break;
            case "del":
                del([data.id]);
                break;
        }
    });
    /* 弹窗 - 新增、修改 */
    function showEditModel(mData) {
        admin.open({
            type: 1,
            area: '600px',
            title: (mData ? '修改' : '添加') + '订单状态',
            content: $('#editDialog').html(),
            success: function (layero, dIndex) {
                layDateRender(mData);
                form.val('detail', mData);
                form.on('submit(editSubmit)', function (data) {
                    var loadIndex = layer.load(2);
                    $.ajax({
                        url: baseUrl+"/basCrnpOpt/"+(mData?'update':'add')+"/auth",
                        headers: {'token': localStorage.getItem('token')},
                        data: data.field,
                        method: 'POST',
                        success: function (res) {
                            layer.close(loadIndex);
                            if (res.code === 200){
                                layer.close(dIndex);
                                layer.msg(res.msg, {icon: 1});
                                tableReload();
                            } else if (res.code === 403){
                                top.location.href = baseUrl+"/";
                            }else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }
                    })
                    return false;
                });
                $(layero).children('.layui-layer-content').css('overflow', 'visible');
                layui.form.render('select');
            }
        raw = String(raw)
            .replace(/\$/g, '')
            .replace(/([a-z0-9])([A-Z])/g, '$1_$2')
            .replace(/_/g, ' ')
            .replace(/\s+/g, ' ')
            .trim();
        return raw.replace(/\b[a-z]/g, function (letter) {
            return letter.toUpperCase();
        });
    }
    /* 删除 */
    function del(ids) {
        layer.confirm('确定要删除选中数据吗?', {
            skin: 'layui-layer-admin',
            shade: .1
        }, function (i) {
            layer.close(i);
            var loadIndex = layer.load(2);
    function dedupeFieldMeta(list) {
        var result = [];
        var seen = {};
        (list || []).forEach(function (field) {
            if (!field || !field.field || seen[field.field]) {
                return;
            }
            field.label = formatFieldLabel(field);
            seen[field.field] = true;
            result.push(field);
        });
        return result;
    }
    function isEmptyValue(value) {
        return value === null || value === undefined || value === '';
    }
    function stringValue(value) {
        return isEmptyValue(value) ? '' : String(value);
    }
    function valueOrDash(value) {
        return isEmptyValue(value) ? '--' : value;
    }
    function normalizeOptionValue(field, rawValue) {
        if (rawValue === null || rawValue === undefined) {
            return null;
        }
        if (rawValue === '') {
            return '';
        }
        if (field && field.valueType === 'number') {
            var numberVal = Number(rawValue);
            return isNaN(numberVal) ? rawValue : numberVal;
        }
        return String(rawValue);
    }
    function isSearchableField(field) {
        return !!field && field.kind !== 'image' && !field.textarea;
    }
    function isSortableField(field) {
        if (!field) {
            return false;
        }
        if (field.primaryKey) {
            return true;
        }
        return field.kind !== 'image' && !field.textarea && field.kind !== 'foreign';
    }
    function defaultFieldValue(field) {
        if (field.primaryKey) {
            return null;
        }
        if (field.kind === 'checkbox') {
            return normalizeOptionValue(field, field.checkboxInactiveRaw);
        }
        return '';
    }
    function defaultSearchFieldValue(field) {
        if (field.kind === 'date') {
            return [];
        }
        if (field.kind === 'enum' || field.kind === 'checkbox') {
            return null;
        }
        return '';
    }
    function createSearchDefaults() {
        var result = {
            condition: ''
        };
        fieldMeta.forEach(function (field) {
            if (!isSearchableField(field)) {
                return;
            }
            result[field.field] = defaultSearchFieldValue(field);
        });
        return result;
    }
    function createSearchDisplayDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            if (field.kind === 'foreign' && isSearchableField(field)) {
                result[field.field] = '';
            }
        });
        return result;
    }
    function createDefaultVisibleColumnKeys() {
        return fieldMeta.map(function (field) {
            return field.field;
        });
    }
    function createFormDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            result[field.field] = defaultFieldValue(field);
        });
        return result;
    }
    function createDisplayDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            if (field.kind === 'foreign') {
                result[field.field] = '';
            }
        });
        return result;
    }
    function createFormRules() {
        var rules = {};
        fieldMeta.forEach(function (field) {
            if (field.primaryKey || !field.required) {
                return;
            }
            rules[field.field] = [{
                required: true,
                message: (field.kind === 'date' || field.kind === 'enum' ? '请选择' : '请输入') + field.label,
                trigger: (field.kind === 'date' || field.kind === 'enum') ? 'change' : 'blur'
            }];
        });
        return rules;
    }
    function getTableValue(row, field) {
        var prop = field.tableProp || field.field;
        if (row && !isEmptyValue(row[prop])) {
            return row[prop];
        }
        return row ? row[field.field] : '';
    }
    function isCheckboxChecked(row, field) {
        var value = row ? row[field.field] : null;
        var activeValue = normalizeOptionValue(field, field.checkboxActiveRaw);
        return String(value) === String(activeValue);
    }
    function exportCell(value) {
        return stringValue(value).replace(/\t/g, ' ').replace(/\r?\n/g, ' ');
    }
    function escapeHtml(value) {
        return exportCell(value)
            .replace(/&/g, '&amp;')
            .replace(/</g, '&lt;')
            .replace(/>/g, '&gt;')
            .replace(/"/g, '&quot;')
            .replace(/'/g, '&#39;');
    }
    function buildPayload(form) {
        var payload = {};
        fieldMeta.forEach(function (field) {
            var value = form[field.field];
            if (field.primaryKey) {
                if (!isEmptyValue(value)) {
                    payload[field.field] = value;
                }
                return;
            }
            if (field.kind === 'foreign' && isEmptyValue(value)) {
                value = null;
            }
            if (field.kind === 'enum' && value === '') {
                value = null;
            }
            if (field.kind === 'checkbox' && isEmptyValue(value)) {
                value = normalizeOptionValue(field, field.checkboxInactiveRaw);
            }
            if (field.valueType === 'number' && !isEmptyValue(value)) {
                value = Number(value);
            }
            if (field.valueType === 'number' && value === '') {
                value = null;
            }
            payload[field.field] = value;
        });
        return payload;
    }
    function fillFormFromRow(row, form, display) {
        fieldMeta.forEach(function (field) {
            if (field.primaryKey) {
                form[field.field] = row[field.field];
                return;
            }
            if (field.kind === 'date') {
                form[field.field] = row[field.tableProp] || row[field.field] || '';
                return;
            }
            if (field.kind === 'foreign') {
                form[field.field] = isEmptyValue(row[field.field]) ? '' : normalizeOptionValue(field, row[field.field]);
                if (display) {
                    display[field.field] = row[field.tableProp] || (isEmptyValue(row[field.field]) ? '' : String(row[field.field]));
                }
                return;
            }
            if (field.kind === 'enum') {
                form[field.field] = isEmptyValue(row[field.field]) ? '' : normalizeOptionValue(field, row[field.field]);
                return;
            }
            if (field.kind === 'checkbox') {
                form[field.field] = isEmptyValue(row[field.field])
                    ? normalizeOptionValue(field, field.checkboxInactiveRaw)
                    : normalizeOptionValue(field, row[field.field]);
                return;
            }
            form[field.field] = isEmptyValue(row[field.field])
                ? ''
                : (field.valueType === 'number' ? String(row[field.field]) : row[field.field]);
        });
    }
    function resolveSearchParam(field) {
        if (field.kind === 'date' && field.columnName) {
            return field.columnName;
        }
        return field.field;
    }
    function createDownloadFile(filename, titles, rows) {
        var html = [
            '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">',
            '<head><meta charset="UTF-8"></head><body><table border="1"><thead><tr>',
            titles.map(function (title) {
                return '<th>' + escapeHtml(title) + '</th>';
            }).join(''),
            '</tr></thead><tbody>',
            (rows || []).map(function (row) {
                return '<tr>' + (row || []).map(function (value) {
                    return '<td style="mso-number-format:\\@;">' + escapeHtml(value) + '</td>';
                }).join('') + '</tr>';
            }).join(''),
            '</tbody></table></body></html>'
        ].join('');
        var blob = new Blob(['\ufeff' + html], {
            type: 'application/vnd.ms-excel;charset=utf-8;'
        });
        var anchor = document.createElement('a');
        anchor.href = URL.createObjectURL(blob);
        anchor.download = filename;
        document.body.appendChild(anchor);
        anchor.click();
        setTimeout(function () {
            URL.revokeObjectURL(anchor.href);
            document.body.removeChild(anchor);
        }, 0);
    }
    function buildTimestamp() {
        var now = new Date();
        var pad = function (num) {
            return num < 10 ? '0' + num : String(num);
        };
        return now.getFullYear()
            + pad(now.getMonth() + 1)
            + pad(now.getDate())
            + '_'
            + pad(now.getHours())
            + pad(now.getMinutes())
            + pad(now.getSeconds());
    }
    function authHeaders() {
        return {
            token: localStorage.getItem('token')
        };
    }
    function handleForbidden(res) {
        if (res && res.code === 403) {
            top.location.href = baseUrl + '/';
            return true;
        }
        return false;
    }
    var sharedMethods = {
        authHeaders: authHeaders,
        handleForbidden: handleForbidden,
        valueOrDash: valueOrDash,
        stringValue: stringValue,
        getTableValue: getTableValue,
        isCheckboxChecked: isCheckboxChecked,
        normalizeOptionValue: normalizeOptionValue,
        isSortableField: isSortableField,
        getSuggestionFetcher: function (field) {
            var self = this;
            return function (queryString, callback) {
                self.fetchForeignSuggestions(field, queryString, callback);
            };
        },
        fetchForeignSuggestions: function (field, queryString, callback) {
            if (!field.foreignQuery || !queryString) {
                callback([]);
                return;
            }
            var self = this;
            $.ajax({
                url: baseUrl+"/basCrnpOpt/delete/auth",
                headers: {'token': localStorage.getItem('token')},
                data: {ids: ids},
                method: 'POST',
                url: baseUrl + '/' + field.foreignQuery + 'Query/auth',
                method: 'GET',
                headers: self.authHeaders(),
                data: { condition: queryString },
                success: function (res) {
                    layer.close(loadIndex);
                    if (res.code === 200){
                        layer.msg(res.msg, {icon: 1});
                        tableReload();
                    } else if (res.code === 403){
                        top.location.href = baseUrl+"/";
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    if (self.handleForbidden(res)) {
                        return;
                    }
                    if (!res || res.code !== 200 || !Array.isArray(res.data)) {
                        callback([]);
                        return;
                    }
                    callback(res.data.map(function (item) {
                        return {
                            id: item.id,
                            value: item.value
                        };
                    }));
                },
                error: function () {
                    callback([]);
                }
            });
        },
        handleForeignSelect: function (field, item) {
            this.$set(this.displayTarget, field.field, item && item.value ? item.value : '');
            this.$set(this.formTarget, field.field, item && item.id !== undefined ? normalizeOptionValue(field, item.id) : '');
        },
        handleForeignInput: function (field) {
            if (!this.displayTarget || !this.formTarget) {
                return;
            }
            if (this.displayTarget[field.field]) {
                return;
            }
            this.$set(this.formTarget, field.field, '');
        }
    };
    if (document.getElementById('app')) {
        new Vue({
            el: '#app',
            data: function () {
                return {
                    fieldMeta: fieldMeta,
                    primaryKeyField: primaryKeyField,
                    loading: false,
                    exporting: false,
                    tableData: [],
                    selection: [],
                    advancedFiltersVisible: false,
                    allColumns: fieldMeta.slice(),
                    visibleColumnKeys: createDefaultVisibleColumnKeys(),
                    searchForm: createSearchDefaults(),
                    searchDisplay: createSearchDisplayDefaults(),
                    page: {
                        curr: 1,
                        limit: 15,
                        total: 0
                    },
                    sortState: {
                        prop: '',
                        order: ''
                    },
                    dialog: {
                        visible: false,
                        mode: 'create',
                        submitting: false
                    },
                    layoutTimer: null,
                    tableResizeHandler: null,
                    dialogForm: createFormDefaults(),
                    dialogDisplay: createDisplayDefaults(),
                    dialogRules: createFormRules()
                };
            },
            computed: {
                searchableFields: function () {
                    return this.fieldMeta.filter(function (field) {
                        return isSearchableField(field);
                    });
                },
                quickSearchableFields: function () {
                    var result = [];
                    this.searchableFields.forEach(function (field) {
                        if (result.length >= 3 || field.kind === 'date') {
                            return;
                        }
                        result.push(field);
                    });
                    return result;
                },
                advancedSearchableFields: function () {
                    var quickKeys = this.quickSearchableFields.map(function (field) {
                        return field.field;
                    });
                    return this.searchableFields.filter(function (field) {
                        return quickKeys.indexOf(field.field) === -1;
                    });
                },
                hasAdvancedFilters: function () {
                    return this.advancedSearchableFields.length > 0;
                },
                visibleColumns: function () {
                    var keys = this.visibleColumnKeys;
                    return this.allColumns.filter(function (field) {
                        return keys.indexOf(field.field) !== -1;
                    });
                },
                editableFields: function () {
                    return this.fieldMeta.filter(function (field) {
                        return !field.primaryKey;
                    });
                },
                exportColumns: function () {
                    return this.visibleColumns.map(function (field) {
                        return {
                            field: field.exportField || field.tableProp || field.field,
                            label: field.label
                        };
                    });
                },
                tableHeight: function () {
                    return this.advancedFiltersVisible && this.hasAdvancedFilters
                        ? 'calc(100vh - 390px)'
                        : 'calc(100vh - 300px)';
                },
                formTarget: function () {
                    return this.dialogForm;
                },
                displayTarget: function () {
                    return this.dialogDisplay;
                }
            },
            created: function () {
                this.loadTable();
            },
            mounted: function () {
                var self = this;
                self.requestTableLayout(80);
                self.tableResizeHandler = function () {
                    self.requestTableLayout(80);
                };
                window.addEventListener('resize', self.tableResizeHandler);
            },
            beforeDestroy: function () {
                if (this.layoutTimer) {
                    clearTimeout(this.layoutTimer);
                    this.layoutTimer = null;
                }
                if (this.tableResizeHandler) {
                    window.removeEventListener('resize', this.tableResizeHandler);
                    this.tableResizeHandler = null;
                }
            },
            methods: $.extend({}, sharedMethods, {
                requestTableLayout: function (delay) {
                    var self = this;
                    if (self.layoutTimer) {
                        clearTimeout(self.layoutTimer);
                    }
                    self.$nextTick(function () {
                        self.layoutTimer = setTimeout(function () {
                            var table = self.$refs.dataTable;
                            if (table && typeof table.doLayout === 'function') {
                                table.doLayout();
                            }
                        }, delay || 40);
                    });
                },
                isColumnVisible: function (fieldName) {
                    return this.visibleColumnKeys.indexOf(fieldName) !== -1;
                },
                toggleColumn: function (fieldName, visible) {
                    if (visible) {
                        if (this.visibleColumnKeys.indexOf(fieldName) === -1) {
                            this.visibleColumnKeys.push(fieldName);
                        }
                        this.requestTableLayout(80);
                        return;
                    }
                    if (this.visibleColumnKeys.length === 1) {
                        this.$message.warning('至少保留一列');
                        return;
                    }
                    this.visibleColumnKeys = this.visibleColumnKeys.filter(function (item) {
                        return item !== fieldName;
                    });
                    this.requestTableLayout(80);
                },
                selectAllColumns: function () {
                    this.visibleColumnKeys = createDefaultVisibleColumnKeys();
                    this.requestTableLayout(80);
                },
                resetColumns: function () {
                    this.visibleColumnKeys = createDefaultVisibleColumnKeys();
                    this.requestTableLayout(80);
                },
                toggleAdvancedFilters: function () {
                    this.advancedFiltersVisible = !this.advancedFiltersVisible;
                    this.requestTableLayout(260);
                },
                handleSearchForeignSelect: function (field, item) {
                    this.$set(this.searchDisplay, field.field, item && item.value ? item.value : '');
                    this.$set(this.searchForm, field.field, item && item.id !== undefined ? normalizeOptionValue(field, item.id) : '');
                },
                handleSearchForeignInput: function (field) {
                    if (this.searchDisplay[field.field]) {
                        return;
                    }
                    this.$set(this.searchForm, field.field, '');
                },
                buildQueryParams: function () {
                    var self = this;
                    var params = {
                        curr: self.page.curr,
                        limit: self.page.limit
                    };
                    if (self.searchForm.condition) {
                        params.condition = self.searchForm.condition;
                    }
                    self.searchableFields.forEach(function (field) {
                        var value = self.searchForm[field.field];
                        if (field.kind === 'date') {
                            if (value && value.length === 2) {
                                params[resolveSearchParam(field)] = value[0] + ' - ' + value[1];
                            }
                            return;
                        }
                        if (!isEmptyValue(value)) {
                            params[resolveSearchParam(field)] = value;
                        }
                    });
                    if (self.sortState.prop && self.sortState.order) {
                        params.orderByField = self.sortState.prop;
                        params.orderByType = self.sortState.order === 'ascending' ? 'asc' : 'desc';
                    }
                    return params;
                },
                loadTable: function () {
                    var self = this;
                    self.loading = true;
                    $.ajax({
                        url: baseUrl + '/' + simpleEntityName + '/list/auth',
                        method: 'GET',
                        headers: self.authHeaders(),
                        data: self.buildQueryParams(),
                        success: function (res) {
                            self.loading = false;
                            if (self.handleForbidden(res)) {
                                return;
                            }
                            if (!res || res.code !== 200) {
                                self.$message.error((res && res.msg) ? res.msg : '加载失败');
                                return;
                            }
                            var payload = res.data || {};
                            self.tableData = Array.isArray(payload.records) ? payload.records : [];
                            self.page.total = payload.total || 0;
                            self.requestTableLayout(80);
                        },
                        error: function () {
                            self.loading = false;
                            self.requestTableLayout(80);
                            self.$message.error('加载失败');
                        }
                    });
                },
                handleSearch: function () {
                    this.page.curr = 1;
                    this.loadTable();
                },
                handleReset: function () {
                    this.searchForm = createSearchDefaults();
                    this.searchDisplay = createSearchDisplayDefaults();
                    this.advancedFiltersVisible = false;
                    this.page.curr = 1;
                    this.sortState = {
                        prop: '',
                        order: ''
                    };
                    this.loadTable();
                },
                handleSelectionChange: function (rows) {
                    this.selection = rows || [];
                },
                handleSortChange: function (payload) {
                    this.sortState = {
                        prop: payload && payload.prop ? payload.prop : '',
                        order: payload && payload.order ? payload.order : ''
                    };
                    this.page.curr = 1;
                    this.loadTable();
                },
                handleCurrentChange: function (curr) {
                    this.page.curr = curr;
                    this.loadTable();
                },
                handleSizeChange: function (limit) {
                    this.page.limit = limit;
                    this.page.curr = 1;
                    this.loadTable();
                },
                resetDialogState: function () {
                    this.dialogForm = createFormDefaults();
                    this.dialogDisplay = createDisplayDefaults();
                    if (this.$refs.dialogForm) {
                        this.$refs.dialogForm.clearValidate();
                    }
                },
                openCreateDialog: function () {
                    this.dialog.mode = 'create';
                    this.dialog.visible = true;
                    this.$nextTick(this.resetDialogState);
                },
                openEditDialog: function (row) {
                    var self = this;
                    self.dialog.mode = 'edit';
                    self.dialog.visible = true;
                    self.$nextTick(function () {
                        self.resetDialogState();
                        fillFormFromRow(row, self.dialogForm, self.dialogDisplay);
                        if (self.$refs.dialogForm) {
                            self.$refs.dialogForm.clearValidate();
                        }
                    });
                },
                submitDialog: function () {
                    var self = this;
                    if (!self.$refs.dialogForm) {
                        return;
                    }
                    self.$refs.dialogForm.validate(function (valid) {
                        if (!valid) {
                            return false;
                        }
                        self.dialog.submitting = true;
                        $.ajax({
                            url: baseUrl + '/' + simpleEntityName + '/' + (self.dialog.mode === 'create' ? 'add' : 'update') + '/auth',
                            method: 'POST',
                            headers: self.authHeaders(),
                            data: buildPayload(self.dialogForm),
                            success: function (res) {
                                self.dialog.submitting = false;
                                if (self.handleForbidden(res)) {
                                    return;
                                }
                                if (!res || res.code !== 200) {
                                    self.$message.error((res && res.msg) ? res.msg : '保存失败');
                                    return;
                                }
                                self.$message.success(res.msg || '保存成功');
                                self.dialog.visible = false;
                                self.loadTable();
                            },
                            error: function () {
                                self.dialog.submitting = false;
                                self.$message.error('保存失败');
                            }
                        });
                        return true;
                    });
                },
                removeSelection: function () {
                    var self = this;
                    var ids = self.selection.map(function (row) {
                        return row[self.primaryKeyField];
                    });
                    self.removeRows(ids);
                },
                removeRows: function (ids) {
                    var self = this;
                    if (!ids || ids.length === 0) {
                        self.$message.warning('请选择要删除的数据');
                        return;
                    }
                    self.$confirm('确定删除选中的记录吗?', '提示', { type: 'warning' }).then(function () {
                        $.ajax({
                            url: baseUrl + '/' + simpleEntityName + '/delete/auth',
                            method: 'POST',
                            headers: self.authHeaders(),
                            traditional: true,
                            data: { 'ids[]': ids },
                            success: function (res) {
                                if (self.handleForbidden(res)) {
                                    return;
                                }
                                if (!res || res.code !== 200) {
                                    self.$message.error((res && res.msg) ? res.msg : '删除失败');
                                    return;
                                }
                                self.$message.success(res.msg || '删除成功');
                                self.selection = [];
                                if (self.tableData.length === ids.length && self.page.curr > 1) {
                                    self.page.curr = self.page.curr - 1;
                                }
                                self.loadTable();
                            },
                            error: function () {
                                self.$message.error('删除失败');
                            }
                        });
                    }).catch(function () {});
                },
                exportRows: function () {
                    var self = this;
                    self.exporting = true;
                    var requestBody = {
                        fields: self.exportColumns.map(function (item) {
                            return item.field;
                        })
                    };
                    requestBody[simpleEntityName] = self.buildQueryParams();
                    $.ajax({
                        url: baseUrl + '/' + simpleEntityName + '/export/auth',
                        method: 'POST',
                        headers: $.extend({ 'Content-Type': 'application/json;charset=UTF-8' }, self.authHeaders()),
                        data: JSON.stringify(requestBody),
                        success: function (res) {
                            self.exporting = false;
                            if (self.handleForbidden(res)) {
                                return;
                            }
                            if (!res || res.code !== 200) {
                                self.$message.error((res && res.msg) ? res.msg : '导出失败');
                                return;
                            }
                            createDownloadFile(
                                simpleEntityName + '_' + buildTimestamp() + '.xls',
                                self.exportColumns.map(function (item) {
                                    return item.label;
                                }),
                                Array.isArray(res.data) ? res.data : []
                            );
                            self.$message.success('导出成功');
                        },
                        error: function () {
                            self.exporting = false;
                            self.$message.error('导出失败');
                        }
                    });
                }
            })
        });
    }
    // 搜索
    form.on('submit(search)', function (data) {
        pageCurr = 1;
        tableReload(false);
    });
    // 重置
    form.on('submit(reset)', function (data) {
        pageCurr = 1;
        clearFormVal($('#search-box'));
        tableReload(false);
    });
    // 时间选择器
    function layDateRender(data) {
        setTimeout(function () {
            layDate.render({
                elem: '.layui-laydate-range'
                ,type: 'datetime'
                ,range: true
            });
            layDate.render({
                elem: '#sendTime\\$',
                type: 'datetime',
                value: data!==undefined?data['sendTime\\$']:null
            });
            layDate.render({
                elem: '#updateTime\\$',
                type: 'datetime',
                value: data!==undefined?data['updateTime\\$']:null
            });
        }, 300);
    }
    layDateRender();
});
// 关闭动作
$(document).on('click','#data-detail-close', function () {
    parent.layer.closeAll();
});
function tableReload(child) {
    var searchData = {};
    $.each($('#search-box [name]').serializeArray(), function() {
        searchData[this.name] = this.value;
    });
    tableIns.reload({
        where: searchData,
        page: {curr: pageCurr}
     });
}
})();
src/main/webapp/static/js/basDevp/basDevp.js
@@ -1,328 +1,2533 @@
var pageCurr;
layui
  .config({
    base: baseUrl + "/static/layui/lay/modules/",
  })
  .use(["table", "laydate", "form", "admin"], function () {
    var table = layui.table;
    var $ = layui.jquery;
    var layer = layui.layer;
    var layDate = layui.laydate;
    var form = layui.form;
    var admin = layui.admin;
(function () {
    var simpleEntityName = 'basDevp';
    var entityName = 'BasDevp';
    var primaryKeyField = 'id';
    var fieldMeta = dedupeFieldMeta([
    {
        field: 'devNo',
        columnName: 'dev_no',
        label: '',
        tableProp: 'devNo',
        exportField: 'devNo',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'decDesc',
        columnName: 'dec_desc',
        label: '',
        tableProp: 'decDesc',
        exportField: 'decDesc',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'devMk',
        columnName: 'dev_mk',
        label: '',
        tableProp: 'devMk',
        exportField: 'devMk',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'inEnable',
        columnName: 'in_enable',
        label: '',
        tableProp: 'inEnable',
        exportField: 'inEnable',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'outEnable',
        columnName: 'out_enable',
        label: '',
        tableProp: 'outEnable',
        exportField: 'outEnable',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'autoing',
        columnName: 'autoing',
        label: '',
        tableProp: 'autoing',
        exportField: 'autoing',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'loading',
        columnName: 'loading',
        label: '',
        tableProp: 'loading',
        exportField: 'loading',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'canining',
        columnName: 'canining',
        label: '',
        tableProp: 'canining',
        exportField: 'canining',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'canouting',
        columnName: 'canouting',
        label: '',
        tableProp: 'canouting',
        exportField: 'canouting',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'fronting',
        columnName: 'fronting',
        label: '',
        tableProp: 'fronting',
        exportField: 'fronting',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'rearing',
        columnName: 'rearing',
        label: '',
        tableProp: 'rearing',
        exportField: 'rearing',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'uping',
        columnName: 'uping',
        label: '',
        tableProp: 'uping',
        exportField: 'uping',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'downing',
        columnName: 'downing',
        label: '',
        tableProp: 'downing',
        exportField: 'downing',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'inreq1',
        columnName: 'inreq1',
        label: '',
        tableProp: 'inreq1',
        exportField: 'inreq1',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'inreq2',
        columnName: 'inreq2',
        label: '',
        tableProp: 'inreq2',
        exportField: 'inreq2',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'wrkNo',
        columnName: 'wrk_no',
        label: '',
        tableProp: 'wrkNo',
        exportField: 'wrkNo',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'wrkNo1',
        columnName: 'wrk_no1',
        label: '',
        tableProp: 'wrkNo1',
        exportField: 'wrkNo1',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'ctnType',
        columnName: 'ctn_type',
        label: '',
        tableProp: 'ctnType',
        exportField: 'ctnType',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'barcode',
        columnName: 'barcode',
        label: '',
        tableProp: 'barcode',
        exportField: 'barcode',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'inQty',
        columnName: 'in_qty',
        label: '',
        tableProp: 'inQty',
        exportField: 'inQty',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'row1',
        columnName: 'row1',
        label: '',
        tableProp: 'row1',
        exportField: 'row1',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'ioTime',
        columnName: 'io_time',
        label: '',
        tableProp: 'ioTime$',
        exportField: 'ioTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'area',
        columnName: 'area',
        label: '',
        tableProp: 'area',
        exportField: 'area',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'inOk',
        columnName: 'in_ok',
        label: '',
        tableProp: 'inOk',
        exportField: 'inOk',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'outOk',
        columnName: 'out_ok',
        label: '',
        tableProp: 'outOk',
        exportField: 'outOk',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'locType1',
        columnName: 'loc_type1',
        label: '',
        tableProp: 'locType1',
        exportField: 'locType1',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'locType2',
        columnName: 'loc_type2',
        label: '',
        tableProp: 'locType2',
        exportField: 'locType2',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'locType3',
        columnName: 'loc_type3',
        label: '',
        tableProp: 'locType3',
        exportField: 'locType3',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'modiUser',
        columnName: 'modi_user',
        label: '',
        tableProp: 'modiUser',
        exportField: 'modiUser',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'modiTime',
        columnName: 'modi_time',
        label: '',
        tableProp: 'modiTime$',
        exportField: 'modiTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'appeUser',
        columnName: 'appe_user',
        label: '',
        tableProp: 'appeUser',
        exportField: 'appeUser',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'appeTime',
        columnName: 'appe_time',
        label: '',
        tableProp: 'appeTime$',
        exportField: 'appeTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'stdQty',
        columnName: 'std_qty',
        label: '',
        tableProp: 'stdQty',
        exportField: 'stdQty',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'minWt',
        columnName: 'min_wt',
        label: '',
        tableProp: 'minWt',
        exportField: 'minWt',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'maxWt',
        columnName: 'max_wt',
        label: '',
        tableProp: 'maxWt',
        exportField: 'maxWt',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'grossWt',
        columnName: 'gross_wt',
        label: '',
        tableProp: 'grossWt',
        exportField: 'grossWt',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'cartPos',
        columnName: 'cart_pos',
        label: '',
        tableProp: 'cartPos',
        exportField: 'cartPos',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'qrCodeValue',
        columnName: 'qr_code_value',
        label: '',
        tableProp: 'qrCodeValue',
        exportField: 'qrCodeValue',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'locNo',
        columnName: 'loc_no',
        label: '',
        tableProp: 'locNo',
        exportField: 'locNo',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'lev',
        columnName: 'lev',
        label: '',
        tableProp: 'lev',
        exportField: 'lev',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'liftNo',
        columnName: 'lift_no',
        label: '',
        tableProp: 'liftNo',
        exportField: 'liftNo',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'devNo',
        columnName: 'dev_no',
        label: '',
        tableProp: 'devNo',
        exportField: 'devNo',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'decDesc',
        columnName: 'dec_desc',
        label: '',
        tableProp: 'decDesc',
        exportField: 'decDesc',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'devMk',
        columnName: 'dev_mk',
        label: '',
        tableProp: 'devMk',
        exportField: 'devMk',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'inEnable',
        columnName: 'in_enable',
        label: '',
        tableProp: 'inEnable',
        exportField: 'inEnable',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'outEnable',
        columnName: 'out_enable',
        label: '',
        tableProp: 'outEnable',
        exportField: 'outEnable',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'autoing',
        columnName: 'autoing',
        label: '',
        tableProp: 'autoing',
        exportField: 'autoing',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'loading',
        columnName: 'loading',
        label: '',
        tableProp: 'loading',
        exportField: 'loading',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'canining',
        columnName: 'canining',
        label: '',
        tableProp: 'canining',
        exportField: 'canining',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'canouting',
        columnName: 'canouting',
        label: '',
        tableProp: 'canouting',
        exportField: 'canouting',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'fronting',
        columnName: 'fronting',
        label: '',
        tableProp: 'fronting',
        exportField: 'fronting',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'rearing',
        columnName: 'rearing',
        label: '',
        tableProp: 'rearing',
        exportField: 'rearing',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'uping',
        columnName: 'uping',
        label: '',
        tableProp: 'uping',
        exportField: 'uping',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'downing',
        columnName: 'downing',
        label: '',
        tableProp: 'downing',
        exportField: 'downing',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'inreq1',
        columnName: 'inreq1',
        label: '',
        tableProp: 'inreq1',
        exportField: 'inreq1',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'inreq2',
        columnName: 'inreq2',
        label: '',
        tableProp: 'inreq2',
        exportField: 'inreq2',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'wrkNo',
        columnName: 'wrk_no',
        label: '',
        tableProp: 'wrkNo',
        exportField: 'wrkNo',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'wrkNo1',
        columnName: 'wrk_no1',
        label: '',
        tableProp: 'wrkNo1',
        exportField: 'wrkNo1',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'ctnType',
        columnName: 'ctn_type',
        label: '',
        tableProp: 'ctnType',
        exportField: 'ctnType',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'barcode',
        columnName: 'barcode',
        label: '',
        tableProp: 'barcode',
        exportField: 'barcode',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'inQty',
        columnName: 'in_qty',
        label: '',
        tableProp: 'inQty',
        exportField: 'inQty',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'row1',
        columnName: 'row1',
        label: '',
        tableProp: 'row1',
        exportField: 'row1',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'ioTime',
        columnName: 'io_time',
        label: '',
        tableProp: 'ioTime$',
        exportField: 'ioTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'area',
        columnName: 'area',
        label: '',
        tableProp: 'area',
        exportField: 'area',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'inOk',
        columnName: 'in_ok',
        label: '',
        tableProp: 'inOk',
        exportField: 'inOk',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'outOk',
        columnName: 'out_ok',
        label: '',
        tableProp: 'outOk',
        exportField: 'outOk',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'locType1',
        columnName: 'loc_type1',
        label: '',
        tableProp: 'locType1',
        exportField: 'locType1',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'locType2',
        columnName: 'loc_type2',
        label: '',
        tableProp: 'locType2',
        exportField: 'locType2',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'locType3',
        columnName: 'loc_type3',
        label: '',
        tableProp: 'locType3',
        exportField: 'locType3',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'modiUser',
        columnName: 'modi_user',
        label: '',
        tableProp: 'modiUser',
        exportField: 'modiUser',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'modiTime',
        columnName: 'modi_time',
        label: '',
        tableProp: 'modiTime$',
        exportField: 'modiTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'appeUser',
        columnName: 'appe_user',
        label: '',
        tableProp: 'appeUser',
        exportField: 'appeUser',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'appeTime',
        columnName: 'appe_time',
        label: '',
        tableProp: 'appeTime$',
        exportField: 'appeTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'stdQty',
        columnName: 'std_qty',
        label: '',
        tableProp: 'stdQty',
        exportField: 'stdQty',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'minWt',
        columnName: 'min_wt',
        label: '',
        tableProp: 'minWt',
        exportField: 'minWt',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'maxWt',
        columnName: 'max_wt',
        label: '',
        tableProp: 'maxWt',
        exportField: 'maxWt',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'grossWt',
        columnName: 'gross_wt',
        label: '',
        tableProp: 'grossWt',
        exportField: 'grossWt',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'cartPos',
        columnName: 'cart_pos',
        label: '',
        tableProp: 'cartPos',
        exportField: 'cartPos',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'qrCodeValue',
        columnName: 'qr_code_value',
        label: '',
        tableProp: 'qrCodeValue',
        exportField: 'qrCodeValue',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'locNo',
        columnName: 'loc_no',
        label: '',
        tableProp: 'locNo',
        exportField: 'locNo',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'lev',
        columnName: 'lev',
        label: '',
        tableProp: 'lev',
        exportField: 'lev',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'liftNo',
        columnName: 'lift_no',
        label: '',
        tableProp: 'liftNo',
        exportField: 'liftNo',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'id',
        columnName: 'id',
        label: '编  号',
        tableProp: 'id',
        exportField: 'id',
        kind: 'text',
        valueType: 'number',
        required: true,
        primaryKey: true,
        sortable: true,
        textarea: false,
        minWidth: 90,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'devpNo',
        columnName: 'devp_no',
        label: '设备编号',
        tableProp: 'devpNo',
        exportField: 'devpNo',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'status',
        columnName: 'status',
        label: '状  态',
        tableProp: 'status$',
        exportField: 'status$',
        kind: 'enum',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 120,
        enumOptions: [{ rawValue: '1', label: '正常' }, { rawValue: '0', label: '禁用' }],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'createBy',
        columnName: 'create_by',
        label: '创建人员',
        tableProp: 'createBy',
        exportField: 'createBy',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'createTime',
        columnName: 'create_time',
        label: '创建时间',
        tableProp: 'createTime$',
        exportField: 'createTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'updateBy',
        columnName: 'update_by',
        label: '修改人员',
        tableProp: 'updateBy',
        exportField: 'updateBy',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'updateTime',
        columnName: 'update_time',
        label: '修改时间',
        tableProp: 'updateTime$',
        exportField: 'updateTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'memo',
        columnName: 'memo',
        label: '备  注',
        tableProp: 'memo',
        exportField: 'memo',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: true,
        minWidth: 180,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'stationList',
        columnName: 'station_list',
        label: '站点数据',
        tableProp: 'stationList',
        exportField: 'stationList',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'barcodeStationList',
        columnName: 'barcode_station_list',
        label: '条码站点数据',
        tableProp: 'barcodeStationList',
        exportField: 'barcodeStationList',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 134,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'inStationList',
        columnName: 'in_station_list',
        label: '入库站点数据',
        tableProp: 'inStationList',
        exportField: 'inStationList',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 134,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'outStationList',
        columnName: 'out_station_list',
        label: '出库站点数据',
        tableProp: 'outStationList',
        exportField: 'outStationList',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 134,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'runBlockReassignLocStationList',
        columnName: 'run_block_reassign_loc_station_list',
        label: '运行堵塞重新分配库位站点数据',
        tableProp: 'runBlockReassignLocStationList',
        exportField: 'runBlockReassignLocStationList',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 180,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'isOutOrderList',
        columnName: 'is_out_order_list',
        label: '请输入出库排序交互点',
        tableProp: 'isOutOrderList',
        exportField: 'isOutOrderList',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'isLiftTransferList',
        columnName: 'is_lift_transfer_list',
        label: '请输入电梯中转点',
        tableProp: 'isLiftTransferList',
        exportField: 'isLiftTransferList',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    }
    // 数据渲染
    tableIns = table.render({
      elem: "#basDevp",
      headers: { token: localStorage.getItem("token") },
      url: baseUrl + "/basDevp/list/auth",
      page: true,
      limit: 15,
      limits: [15, 30, 50, 100, 200, 500],
      toolbar: "#toolbar",
      cellMinWidth: 50,
      height: "full-120",
      cols: [
        [
          { type: "checkbox" },
          { field: "id", align: "center", title: "编号" },
          { field: "devpNo", align: "center", title: "设备编号" },
          { field: "status$", align: "center", title: "状态" },
          // { field: "createBy", align: "center", title: "创建人员" },
          // { field: "createTime$", align: "center", title: "创建时间" },
          // { field: "updateBy", align: "center", title: "修改人员" },
          // { field: "updateTime$", align: "center", title: "修改时间" },
          { field: "memo", align: "center", title: "备注" },
          { field: "stationList", align: "center", title: "站点数据" },
          { field: "barcodeStationList", align: "center", title: "条码站点数据" },
          { field: "inStationList", align: "center", title: "入库站点数据" },
          { field: "outStationList", align: "center", title: "出库站点数据" },
          { field: "runBlockReassignLocStationList", align: "center", title: "运行堵塞重新分配库位站点数据" },
          { field: "isOutOrderList", align: "center", title: "出库排序交互点" },
          { field: "isLiftTransferList", align: "center", title: "顶升移栽点" },
    ]);
          {
            fixed: "right",
            title: "操作",
            align: "center",
            toolbar: "#operate",
            width: 240,
          },
        ],
      ],
      request: {
        pageName: "curr",
        pageSize: "limit",
      },
      parseData: function (res) {
        return {
          code: res.code,
          msg: res.msg,
          count: res.data.total,
          data: res.data.records,
    function formatFieldLabel(field) {
        var raw = field && field.label ? String(field.label).trim() : '';
        if (raw) {
            return raw;
        }
        raw = field && field.columnName ? field.columnName : (field && field.field ? field.field : '');
        if (!raw) {
            return '';
        }
        raw = String(raw)
            .replace(/\$/g, '')
            .replace(/([a-z0-9])([A-Z])/g, '$1_$2')
            .replace(/_/g, ' ')
            .replace(/\s+/g, ' ')
            .trim();
        return raw.replace(/\b[a-z]/g, function (letter) {
            return letter.toUpperCase();
        });
    }
    function dedupeFieldMeta(list) {
        var result = [];
        var seen = {};
        (list || []).forEach(function (field) {
            if (!field || !field.field || seen[field.field]) {
                return;
            }
            field.label = formatFieldLabel(field);
            seen[field.field] = true;
            result.push(field);
        });
        return result;
    }
    function isEmptyValue(value) {
        return value === null || value === undefined || value === '';
    }
    function stringValue(value) {
        return isEmptyValue(value) ? '' : String(value);
    }
    function valueOrDash(value) {
        return isEmptyValue(value) ? '--' : value;
    }
    function normalizeOptionValue(field, rawValue) {
        if (rawValue === null || rawValue === undefined) {
            return null;
        }
        if (rawValue === '') {
            return '';
        }
        if (field && field.valueType === 'number') {
            var numberVal = Number(rawValue);
            return isNaN(numberVal) ? rawValue : numberVal;
        }
        return String(rawValue);
    }
    function isSearchableField(field) {
        return !!field && field.kind !== 'image' && !field.textarea;
    }
    function isSortableField(field) {
        if (!field) {
            return false;
        }
        if (field.primaryKey) {
            return true;
        }
        return field.kind !== 'image' && !field.textarea && field.kind !== 'foreign';
    }
    function defaultFieldValue(field) {
        if (field.primaryKey) {
            return null;
        }
        if (field.kind === 'checkbox') {
            return normalizeOptionValue(field, field.checkboxInactiveRaw);
        }
        return '';
    }
    function defaultSearchFieldValue(field) {
        if (field.kind === 'date') {
            return [];
        }
        if (field.kind === 'enum' || field.kind === 'checkbox') {
            return null;
        }
        return '';
    }
    function createSearchDefaults() {
        var result = {
            condition: ''
        };
      },
      response: {
        statusCode: 200,
      },
      done: function (res, curr, count) {
        if (res.code === 403) {
          top.location.href = baseUrl + "/";
        fieldMeta.forEach(function (field) {
            if (!isSearchableField(field)) {
                return;
            }
            result[field.field] = defaultSearchFieldValue(field);
        });
        return result;
    }
    function createSearchDisplayDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            if (field.kind === 'foreign' && isSearchableField(field)) {
                result[field.field] = '';
            }
        });
        return result;
    }
    function createDefaultVisibleColumnKeys() {
        return fieldMeta.map(function (field) {
            return field.field;
        });
    }
    function createFormDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            result[field.field] = defaultFieldValue(field);
        });
        return result;
    }
    function createDisplayDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            if (field.kind === 'foreign') {
                result[field.field] = '';
            }
        });
        return result;
    }
    function createFormRules() {
        var rules = {};
        fieldMeta.forEach(function (field) {
            if (field.primaryKey || !field.required) {
                return;
            }
            rules[field.field] = [{
                required: true,
                message: (field.kind === 'date' || field.kind === 'enum' ? '请选择' : '请输入') + field.label,
                trigger: (field.kind === 'date' || field.kind === 'enum') ? 'change' : 'blur'
            }];
        });
        return rules;
    }
    function getTableValue(row, field) {
        var prop = field.tableProp || field.field;
        if (row && !isEmptyValue(row[prop])) {
            return row[prop];
        }
        pageCurr = curr;
        limit();
      },
    });
        return row ? row[field.field] : '';
    }
    // 监听排序事件
    table.on("sort(basDevp)", function (obj) {
      var searchData = {};
      $.each($("#search-box [name]").serializeArray(), function () {
        searchData[this.name] = this.value;
      });
      searchData["orderByField"] = obj.field;
      searchData["orderByType"] = obj.type;
      tableIns.reload({
        where: searchData,
        page: { curr: 1 },
      });
    });
    function isCheckboxChecked(row, field) {
        var value = row ? row[field.field] : null;
        var activeValue = normalizeOptionValue(field, field.checkboxActiveRaw);
        return String(value) === String(activeValue);
    }
    // 监听头工具栏事件
    table.on("toolbar(basDevp)", function (obj) {
      var checkStatus = table.checkStatus(obj.config.id).data;
      switch (obj.event) {
        case "addData":
          showEditModel();
          break;
        case "deleteData":
          if (checkStatus.length === 0) {
            layer.msg("请选择要删除的数据", { icon: 2 });
            return;
          }
          del(
            checkStatus.map(function (d) {
              return d.id;
            })
          );
          break;
        case "exportData":
          admin.confirm("确定导出Excel吗", { shadeClose: true }, function () {
            var titles = [];
            var fields = [];
            obj.config.cols[0].map(function (col) {
              if (
                col.type === "normal" &&
                col.hide === false &&
                col.toolbar == null
              ) {
                titles.push(col.title);
                fields.push(col.field);
              }
            });
            var exportData = {};
            $.each($("#search-box [name]").serializeArray(), function () {
              exportData[this.name] = this.value;
            });
            var param = {
              basDevp: exportData,
              fields: fields,
    function exportCell(value) {
        return stringValue(value).replace(/\t/g, ' ').replace(/\r?\n/g, ' ');
    }
    function escapeHtml(value) {
        return exportCell(value)
            .replace(/&/g, '&amp;')
            .replace(/</g, '&lt;')
            .replace(/>/g, '&gt;')
            .replace(/"/g, '&quot;')
            .replace(/'/g, '&#39;');
    }
    function buildPayload(form) {
        var payload = {};
        fieldMeta.forEach(function (field) {
            var value = form[field.field];
            if (field.primaryKey) {
                if (!isEmptyValue(value)) {
                    payload[field.field] = value;
                }
                return;
            }
            if (field.kind === 'foreign' && isEmptyValue(value)) {
                value = null;
            }
            if (field.kind === 'enum' && value === '') {
                value = null;
            }
            if (field.kind === 'checkbox' && isEmptyValue(value)) {
                value = normalizeOptionValue(field, field.checkboxInactiveRaw);
            }
            if (field.valueType === 'number' && !isEmptyValue(value)) {
                value = Number(value);
            }
            if (field.valueType === 'number' && value === '') {
                value = null;
            }
            payload[field.field] = value;
        });
        return payload;
    }
    function fillFormFromRow(row, form, display) {
        fieldMeta.forEach(function (field) {
            if (field.primaryKey) {
                form[field.field] = row[field.field];
                return;
            }
            if (field.kind === 'date') {
                form[field.field] = row[field.tableProp] || row[field.field] || '';
                return;
            }
            if (field.kind === 'foreign') {
                form[field.field] = isEmptyValue(row[field.field]) ? '' : normalizeOptionValue(field, row[field.field]);
                if (display) {
                    display[field.field] = row[field.tableProp] || (isEmptyValue(row[field.field]) ? '' : String(row[field.field]));
                }
                return;
            }
            if (field.kind === 'enum') {
                form[field.field] = isEmptyValue(row[field.field]) ? '' : normalizeOptionValue(field, row[field.field]);
                return;
            }
            if (field.kind === 'checkbox') {
                form[field.field] = isEmptyValue(row[field.field])
                    ? normalizeOptionValue(field, field.checkboxInactiveRaw)
                    : normalizeOptionValue(field, row[field.field]);
                return;
            }
            form[field.field] = isEmptyValue(row[field.field])
                ? ''
                : (field.valueType === 'number' ? String(row[field.field]) : row[field.field]);
        });
    }
    function resolveSearchParam(field) {
        if (field.kind === 'date' && field.columnName) {
            return field.columnName;
        }
        return field.field;
    }
    function createDownloadFile(filename, titles, rows) {
        var html = [
            '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">',
            '<head><meta charset="UTF-8"></head><body><table border="1"><thead><tr>',
            titles.map(function (title) {
                return '<th>' + escapeHtml(title) + '</th>';
            }).join(''),
            '</tr></thead><tbody>',
            (rows || []).map(function (row) {
                return '<tr>' + (row || []).map(function (value) {
                    return '<td style="mso-number-format:\\@;">' + escapeHtml(value) + '</td>';
                }).join('') + '</tr>';
            }).join(''),
            '</tbody></table></body></html>'
        ].join('');
        var blob = new Blob(['\ufeff' + html], {
            type: 'application/vnd.ms-excel;charset=utf-8;'
        });
        var anchor = document.createElement('a');
        anchor.href = URL.createObjectURL(blob);
        anchor.download = filename;
        document.body.appendChild(anchor);
        anchor.click();
        setTimeout(function () {
            URL.revokeObjectURL(anchor.href);
            document.body.removeChild(anchor);
        }, 0);
    }
    function buildTimestamp() {
        var now = new Date();
        var pad = function (num) {
            return num < 10 ? '0' + num : String(num);
        };
        return now.getFullYear()
            + pad(now.getMonth() + 1)
            + pad(now.getDate())
            + '_'
            + pad(now.getHours())
            + pad(now.getMinutes())
            + pad(now.getSeconds());
    }
    function authHeaders() {
        return {
            token: localStorage.getItem('token')
        };
    }
    function handleForbidden(res) {
        if (res && res.code === 403) {
            top.location.href = baseUrl + '/';
            return true;
        }
        return false;
    }
    var sharedMethods = {
        authHeaders: authHeaders,
        handleForbidden: handleForbidden,
        valueOrDash: valueOrDash,
        stringValue: stringValue,
        getTableValue: getTableValue,
        isCheckboxChecked: isCheckboxChecked,
        normalizeOptionValue: normalizeOptionValue,
        isSortableField: isSortableField,
        getSuggestionFetcher: function (field) {
            var self = this;
            return function (queryString, callback) {
                self.fetchForeignSuggestions(field, queryString, callback);
            };
            $.ajax({
              url: baseUrl + "/basDevp/export/auth",
              headers: { token: localStorage.getItem("token") },
              data: JSON.stringify(param),
              dataType: "json",
              contentType: "application/json;charset=UTF-8",
              method: "POST",
              success: function (res) {
                layer.closeAll();
                if (res.code === 200) {
                  table.exportFile(titles, res.data, "xls");
                } else if (res.code === 403) {
                  top.location.href = baseUrl + "/";
                } else {
                  layer.msg(res.msg, { icon: 2 });
                }
              },
            });
          });
          break;
      }
    });
    // 监听行工具事件
    table.on("tool(basDevp)", function (obj) {
      var data = obj.data;
      switch (obj.event) {
        case "edit":
          showEditModel(data);
          break;
        case "del":
          del([data.id]);
          break;
        case "initStation":
          showInitStation(data);
          break;
      }
    });
    function showInitStation(mData) {
      admin.open({
        type: 1,
        area: "600px",
        title: "初始化站点数据",
        content: $("#initStationDialog").html(),
        success: function (layero, dIndex) {
          layDateRender(mData);
          form.val("detail", mData);
          form.on("submit(editSubmit)", function (data) {
            var loadIndex = layer.load(2);
            $.ajax({
              url: baseUrl + "/basDevp/initStation/auth",
              headers: { token: localStorage.getItem("token") },
              contentType: "application/json;charset=UTF-8",
              data: JSON.stringify(data.field),
              method: "POST",
              success: function (res) {
                layer.close(loadIndex);
                if (res.code === 200) {
                  layer.close(dIndex);
                  layer.msg(res.msg, { icon: 1 });
                  tableReload();
                } else if (res.code === 403) {
                  top.location.href = baseUrl + "/";
                } else {
                  layer.msg(res.msg, { icon: 2 });
                }
              },
            });
            return false;
          });
          $(layero).children(".layui-layer-content").css("overflow", "visible");
          layui.form.render("select");
        },
      });
    }
    /* 弹窗 - 新增、修改 */
    function showEditModel(mData) {
      admin.open({
        type: 1,
        area: "600px",
        title: (mData ? "修改" : "添加") + "订单状态",
        content: $("#editDialog").html(),
        success: function (layero, dIndex) {
          layDateRender(mData);
          form.val("detail", mData);
          form.on("submit(editSubmit)", function (data) {
            var loadIndex = layer.load(2);
        fetchForeignSuggestions: function (field, queryString, callback) {
            if (!field.foreignQuery || !queryString) {
                callback([]);
                return;
            }
            var self = this;
            $.ajax({
              url: baseUrl + "/basDevp/" + (mData ? "update" : "add") + "/auth",
              headers: { token: localStorage.getItem("token") },
              data: data.field,
              method: "POST",
              success: function (res) {
                layer.close(loadIndex);
                if (res.code === 200) {
                  layer.close(dIndex);
                  layer.msg(res.msg, { icon: 1 });
                  tableReload();
                } else if (res.code === 403) {
                  top.location.href = baseUrl + "/";
                } else {
                  layer.msg(res.msg, { icon: 2 });
                url: baseUrl + '/' + field.foreignQuery + 'Query/auth',
                method: 'GET',
                headers: self.authHeaders(),
                data: { condition: queryString },
                success: function (res) {
                    if (self.handleForbidden(res)) {
                        return;
                    }
                    if (!res || res.code !== 200 || !Array.isArray(res.data)) {
                        callback([]);
                        return;
                    }
                    callback(res.data.map(function (item) {
                        return {
                            id: item.id,
                            value: item.value
                        };
                    }));
                },
                error: function () {
                    callback([]);
                }
              },
            });
            return false;
          });
          $(layero).children(".layui-layer-content").css("overflow", "visible");
          layui.form.render("select");
        },
      });
    }
    /* 删除 */
    function del(ids) {
      layer.confirm(
        "确定要删除选中数据吗?",
        {
          skin: "layui-layer-admin",
          shade: 0.1,
        handleForeignSelect: function (field, item) {
            this.$set(this.displayTarget, field.field, item && item.value ? item.value : '');
            this.$set(this.formTarget, field.field, item && item.id !== undefined ? normalizeOptionValue(field, item.id) : '');
        },
        function (i) {
          layer.close(i);
          var loadIndex = layer.load(2);
          $.ajax({
            url: baseUrl + "/basDevp/delete/auth",
            headers: { token: localStorage.getItem("token") },
            data: { ids: ids },
            method: "POST",
            success: function (res) {
              layer.close(loadIndex);
              if (res.code === 200) {
                layer.msg(res.msg, { icon: 1 });
                tableReload();
              } else if (res.code === 403) {
                top.location.href = baseUrl + "/";
              } else {
                layer.msg(res.msg, { icon: 2 });
              }
            },
          });
        handleForeignInput: function (field) {
            if (!this.displayTarget || !this.formTarget) {
                return;
            }
            if (this.displayTarget[field.field]) {
                return;
            }
            this.$set(this.formTarget, field.field, '');
        }
      );
    };
    if (document.getElementById('app')) {
        new Vue({
            el: '#app',
            data: function () {
                return {
                    fieldMeta: fieldMeta,
                    primaryKeyField: primaryKeyField,
                    loading: false,
                    exporting: false,
                    tableData: [],
                    selection: [],
                    advancedFiltersVisible: false,
                    allColumns: fieldMeta.slice(),
                    visibleColumnKeys: createDefaultVisibleColumnKeys(),
                    searchForm: createSearchDefaults(),
                    searchDisplay: createSearchDisplayDefaults(),
                    page: {
                        curr: 1,
                        limit: 15,
                        total: 0
                    },
                    sortState: {
                        prop: '',
                        order: ''
                    },
                    dialog: {
                        visible: false,
                        mode: 'create',
                        submitting: false
                    },
                    layoutTimer: null,
                    tableResizeHandler: null,
                    dialogForm: createFormDefaults(),
                    dialogDisplay: createDisplayDefaults(),
                    dialogRules: createFormRules()
                };
            },
            computed: {
                searchableFields: function () {
                    return this.fieldMeta.filter(function (field) {
                        return isSearchableField(field);
                    });
                },
                quickSearchableFields: function () {
                    var result = [];
                    this.searchableFields.forEach(function (field) {
                        if (result.length >= 3 || field.kind === 'date') {
                            return;
                        }
                        result.push(field);
                    });
                    return result;
                },
                advancedSearchableFields: function () {
                    var quickKeys = this.quickSearchableFields.map(function (field) {
                        return field.field;
                    });
                    return this.searchableFields.filter(function (field) {
                        return quickKeys.indexOf(field.field) === -1;
                    });
                },
                hasAdvancedFilters: function () {
                    return this.advancedSearchableFields.length > 0;
                },
                visibleColumns: function () {
                    var keys = this.visibleColumnKeys;
                    return this.allColumns.filter(function (field) {
                        return keys.indexOf(field.field) !== -1;
                    });
                },
                editableFields: function () {
                    return this.fieldMeta.filter(function (field) {
                        return !field.primaryKey;
                    });
                },
                exportColumns: function () {
                    return this.visibleColumns.map(function (field) {
                        return {
                            field: field.exportField || field.tableProp || field.field,
                            label: field.label
                        };
                    });
                },
                tableHeight: function () {
                    return this.advancedFiltersVisible && this.hasAdvancedFilters
                        ? 'calc(100vh - 390px)'
                        : 'calc(100vh - 300px)';
                },
                formTarget: function () {
                    return this.dialogForm;
                },
                displayTarget: function () {
                    return this.dialogDisplay;
                }
            },
            created: function () {
                this.loadTable();
            },
            mounted: function () {
                var self = this;
                self.requestTableLayout(80);
                self.tableResizeHandler = function () {
                    self.requestTableLayout(80);
                };
                window.addEventListener('resize', self.tableResizeHandler);
            },
            beforeDestroy: function () {
                if (this.layoutTimer) {
                    clearTimeout(this.layoutTimer);
                    this.layoutTimer = null;
                }
                if (this.tableResizeHandler) {
                    window.removeEventListener('resize', this.tableResizeHandler);
                    this.tableResizeHandler = null;
                }
            },
            methods: $.extend({}, sharedMethods, {
                requestTableLayout: function (delay) {
                    var self = this;
                    if (self.layoutTimer) {
                        clearTimeout(self.layoutTimer);
                    }
                    self.$nextTick(function () {
                        self.layoutTimer = setTimeout(function () {
                            var table = self.$refs.dataTable;
                            if (table && typeof table.doLayout === 'function') {
                                table.doLayout();
                            }
                        }, delay || 40);
                    });
                },
                isColumnVisible: function (fieldName) {
                    return this.visibleColumnKeys.indexOf(fieldName) !== -1;
                },
                toggleColumn: function (fieldName, visible) {
                    if (visible) {
                        if (this.visibleColumnKeys.indexOf(fieldName) === -1) {
                            this.visibleColumnKeys.push(fieldName);
                        }
                        this.requestTableLayout(80);
                        return;
                    }
                    if (this.visibleColumnKeys.length === 1) {
                        this.$message.warning('至少保留一列');
                        return;
                    }
                    this.visibleColumnKeys = this.visibleColumnKeys.filter(function (item) {
                        return item !== fieldName;
                    });
                    this.requestTableLayout(80);
                },
                selectAllColumns: function () {
                    this.visibleColumnKeys = createDefaultVisibleColumnKeys();
                    this.requestTableLayout(80);
                },
                resetColumns: function () {
                    this.visibleColumnKeys = createDefaultVisibleColumnKeys();
                    this.requestTableLayout(80);
                },
                toggleAdvancedFilters: function () {
                    this.advancedFiltersVisible = !this.advancedFiltersVisible;
                    this.requestTableLayout(260);
                },
                handleSearchForeignSelect: function (field, item) {
                    this.$set(this.searchDisplay, field.field, item && item.value ? item.value : '');
                    this.$set(this.searchForm, field.field, item && item.id !== undefined ? normalizeOptionValue(field, item.id) : '');
                },
                handleSearchForeignInput: function (field) {
                    if (this.searchDisplay[field.field]) {
                        return;
                    }
                    this.$set(this.searchForm, field.field, '');
                },
                buildQueryParams: function () {
                    var self = this;
                    var params = {
                        curr: self.page.curr,
                        limit: self.page.limit
                    };
                    if (self.searchForm.condition) {
                        params.condition = self.searchForm.condition;
                    }
                    self.searchableFields.forEach(function (field) {
                        var value = self.searchForm[field.field];
                        if (field.kind === 'date') {
                            if (value && value.length === 2) {
                                params[resolveSearchParam(field)] = value[0] + ' - ' + value[1];
                            }
                            return;
                        }
                        if (!isEmptyValue(value)) {
                            params[resolveSearchParam(field)] = value;
                        }
                    });
                    if (self.sortState.prop && self.sortState.order) {
                        params.orderByField = self.sortState.prop;
                        params.orderByType = self.sortState.order === 'ascending' ? 'asc' : 'desc';
                    }
                    return params;
                },
                loadTable: function () {
                    var self = this;
                    self.loading = true;
                    $.ajax({
                        url: baseUrl + '/' + simpleEntityName + '/list/auth',
                        method: 'GET',
                        headers: self.authHeaders(),
                        data: self.buildQueryParams(),
                        success: function (res) {
                            self.loading = false;
                            if (self.handleForbidden(res)) {
                                return;
                            }
                            if (!res || res.code !== 200) {
                                self.$message.error((res && res.msg) ? res.msg : '加载失败');
                                return;
                            }
                            var payload = res.data || {};
                            self.tableData = Array.isArray(payload.records) ? payload.records : [];
                            self.page.total = payload.total || 0;
                            self.requestTableLayout(80);
                        },
                        error: function () {
                            self.loading = false;
                            self.requestTableLayout(80);
                            self.$message.error('加载失败');
                        }
                    });
                },
                handleSearch: function () {
                    this.page.curr = 1;
                    this.loadTable();
                },
                handleReset: function () {
                    this.searchForm = createSearchDefaults();
                    this.searchDisplay = createSearchDisplayDefaults();
                    this.advancedFiltersVisible = false;
                    this.page.curr = 1;
                    this.sortState = {
                        prop: '',
                        order: ''
                    };
                    this.loadTable();
                },
                handleSelectionChange: function (rows) {
                    this.selection = rows || [];
                },
                handleSortChange: function (payload) {
                    this.sortState = {
                        prop: payload && payload.prop ? payload.prop : '',
                        order: payload && payload.order ? payload.order : ''
                    };
                    this.page.curr = 1;
                    this.loadTable();
                },
                handleCurrentChange: function (curr) {
                    this.page.curr = curr;
                    this.loadTable();
                },
                handleSizeChange: function (limit) {
                    this.page.limit = limit;
                    this.page.curr = 1;
                    this.loadTable();
                },
                resetDialogState: function () {
                    this.dialogForm = createFormDefaults();
                    this.dialogDisplay = createDisplayDefaults();
                    if (this.$refs.dialogForm) {
                        this.$refs.dialogForm.clearValidate();
                    }
                },
                openCreateDialog: function () {
                    this.dialog.mode = 'create';
                    this.dialog.visible = true;
                    this.$nextTick(this.resetDialogState);
                },
                openEditDialog: function (row) {
                    var self = this;
                    self.dialog.mode = 'edit';
                    self.dialog.visible = true;
                    self.$nextTick(function () {
                        self.resetDialogState();
                        fillFormFromRow(row, self.dialogForm, self.dialogDisplay);
                        if (self.$refs.dialogForm) {
                            self.$refs.dialogForm.clearValidate();
                        }
                    });
                },
                submitDialog: function () {
                    var self = this;
                    if (!self.$refs.dialogForm) {
                        return;
                    }
                    self.$refs.dialogForm.validate(function (valid) {
                        if (!valid) {
                            return false;
                        }
                        self.dialog.submitting = true;
                        $.ajax({
                            url: baseUrl + '/' + simpleEntityName + '/' + (self.dialog.mode === 'create' ? 'add' : 'update') + '/auth',
                            method: 'POST',
                            headers: self.authHeaders(),
                            data: buildPayload(self.dialogForm),
                            success: function (res) {
                                self.dialog.submitting = false;
                                if (self.handleForbidden(res)) {
                                    return;
                                }
                                if (!res || res.code !== 200) {
                                    self.$message.error((res && res.msg) ? res.msg : '保存失败');
                                    return;
                                }
                                self.$message.success(res.msg || '保存成功');
                                self.dialog.visible = false;
                                self.loadTable();
                            },
                            error: function () {
                                self.dialog.submitting = false;
                                self.$message.error('保存失败');
                            }
                        });
                        return true;
                    });
                },
                removeSelection: function () {
                    var self = this;
                    var ids = self.selection.map(function (row) {
                        return row[self.primaryKeyField];
                    });
                    self.removeRows(ids);
                },
                removeRows: function (ids) {
                    var self = this;
                    if (!ids || ids.length === 0) {
                        self.$message.warning('请选择要删除的数据');
                        return;
                    }
                    self.$confirm('确定删除选中的记录吗?', '提示', { type: 'warning' }).then(function () {
                        $.ajax({
                            url: baseUrl + '/' + simpleEntityName + '/delete/auth',
                            method: 'POST',
                            headers: self.authHeaders(),
                            traditional: true,
                            data: { 'ids[]': ids },
                            success: function (res) {
                                if (self.handleForbidden(res)) {
                                    return;
                                }
                                if (!res || res.code !== 200) {
                                    self.$message.error((res && res.msg) ? res.msg : '删除失败');
                                    return;
                                }
                                self.$message.success(res.msg || '删除成功');
                                self.selection = [];
                                if (self.tableData.length === ids.length && self.page.curr > 1) {
                                    self.page.curr = self.page.curr - 1;
                                }
                                self.loadTable();
                            },
                            error: function () {
                                self.$message.error('删除失败');
                            }
                        });
                    }).catch(function () {});
                },
                exportRows: function () {
                    var self = this;
                    self.exporting = true;
                    var requestBody = {
                        fields: self.exportColumns.map(function (item) {
                            return item.field;
                        })
                    };
                    requestBody[simpleEntityName] = self.buildQueryParams();
                    $.ajax({
                        url: baseUrl + '/' + simpleEntityName + '/export/auth',
                        method: 'POST',
                        headers: $.extend({ 'Content-Type': 'application/json;charset=UTF-8' }, self.authHeaders()),
                        data: JSON.stringify(requestBody),
                        success: function (res) {
                            self.exporting = false;
                            if (self.handleForbidden(res)) {
                                return;
                            }
                            if (!res || res.code !== 200) {
                                self.$message.error((res && res.msg) ? res.msg : '导出失败');
                                return;
                            }
                            createDownloadFile(
                                simpleEntityName + '_' + buildTimestamp() + '.xls',
                                self.exportColumns.map(function (item) {
                                    return item.label;
                                }),
                                Array.isArray(res.data) ? res.data : []
                            );
                            self.$message.success('导出成功');
                        },
                        error: function () {
                            self.exporting = false;
                            self.$message.error('导出失败');
                        }
                    });
                }
            })
        });
    }
    // 搜索
    form.on("submit(search)", function (data) {
      pageCurr = 1;
      tableReload(false);
    });
    // 重置
    form.on("submit(reset)", function (data) {
      pageCurr = 1;
      clearFormVal($("#search-box"));
      tableReload(false);
    });
    // 时间选择器
    function layDateRender(data) {
      setTimeout(function () {
        layDate.render({
          elem: ".layui-laydate-range",
          type: "datetime",
          range: true,
        });
        layDate.render({
          elem: "#createTime\\$",
          type: "datetime",
          value: data !== undefined ? data["createTime\\$"] : null,
        });
        layDate.render({
          elem: "#updateTime\\$",
          type: "datetime",
          value: data !== undefined ? data["updateTime\\$"] : null,
        });
      }, 300);
    }
    layDateRender();
  });
// 关闭动作
$(document).on("click", "#data-detail-close", function () {
  parent.layer.closeAll();
});
function tableReload(child) {
  var searchData = {};
  $.each($("#search-box [name]").serializeArray(), function () {
    searchData[this.name] = this.value;
  });
  tableIns.reload({
    where: searchData,
    page: { curr: pageCurr },
  });
}
})();
src/main/webapp/static/js/basDualCrnp/basDualCrnp.js
@@ -1,272 +1,1111 @@
var pageCurr;
layui.config({
    base: baseUrl + "/static/layui/lay/modules/"
}).use(['table','laydate', 'form', 'admin'], function(){
    var table = layui.table;
    var $ = layui.jquery;
    var layer = layui.layer;
    var layDate = layui.laydate;
    var form = layui.form;
    var admin = layui.admin;
(function () {
    var simpleEntityName = 'basDualCrnp';
    var entityName = 'BasDualCrnp';
    var primaryKeyField = 'crnNo';
    var fieldMeta = dedupeFieldMeta([
    {
        field: 'crnNo',
        columnName: 'crn_no',
        label: '编  号',
        tableProp: 'crnNo',
        exportField: 'crnNo',
        kind: 'text',
        valueType: 'number',
        required: true,
        primaryKey: true,
        sortable: true,
        textarea: false,
        minWidth: 90,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'status',
        columnName: 'status',
        label: '状  态',
        tableProp: 'status$',
        exportField: 'status$',
        kind: 'enum',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 120,
        enumOptions: [{ rawValue: '1', label: '正常' }, { rawValue: '0', label: '禁用' }],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'wrkNo',
        columnName: 'wrk_no',
        label: '工 作 号',
        tableProp: 'wrkNo',
        exportField: 'wrkNo',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 116,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'inEnable',
        columnName: 'in_enable',
        label: '可入(checkBox)',
        tableProp: 'inEnable',
        exportField: 'inEnable',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 180,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'outEnable',
        columnName: 'out_enable',
        label: '可出(checkBox)',
        tableProp: 'outEnable',
        exportField: 'outEnable',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 180,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'createBy',
        columnName: 'create_by',
        label: '创建人员',
        tableProp: 'createBy',
        exportField: 'createBy',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'createTime',
        columnName: 'create_time',
        label: '创建时间',
        tableProp: 'createTime$',
        exportField: 'createTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'updateBy',
        columnName: 'update_by',
        label: '修改人员',
        tableProp: 'updateBy',
        exportField: 'updateBy',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'updateTime',
        columnName: 'update_time',
        label: '修改时间',
        tableProp: 'updateTime$',
        exportField: 'updateTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'memo',
        columnName: 'memo',
        label: '备  注',
        tableProp: 'memo',
        exportField: 'memo',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: true,
        minWidth: 180,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'controlRows',
        columnName: 'control_rows',
        label: '控制库位排号',
        tableProp: 'controlRows',
        exportField: 'controlRows',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 134,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'deepRows',
        columnName: 'deep_rows',
        label: '深库位排号',
        tableProp: 'deepRows',
        exportField: 'deepRows',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 116,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'inStationList',
        columnName: 'in_station_list',
        label: '入库站点',
        tableProp: 'inStationList',
        exportField: 'inStationList',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'outStationList',
        columnName: 'out_station_list',
        label: '出库站点',
        tableProp: 'outStationList',
        exportField: 'outStationList',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'maxInTask',
        columnName: 'max_in_task',
        label: '最大入库任务数',
        tableProp: 'maxInTask',
        exportField: 'maxInTask',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 152,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'maxOutTask',
        columnName: 'max_out_task',
        label: '最大出库任务数',
        tableProp: 'maxOutTask',
        exportField: 'maxOutTask',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 152,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'disableStationOneBays',
        columnName: 'disable_station_one_bays',
        label: '工位1禁止执行列',
        tableProp: 'disableStationOneBays',
        exportField: 'disableStationOneBays',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 170,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'disableStationTwoBays',
        columnName: 'disable_station_two_bays',
        label: '工位2禁止执行列',
        tableProp: 'disableStationTwoBays',
        exportField: 'disableStationTwoBays',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 170,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    }
    // 数据渲染
    tableIns = table.render({
        elem: '#basDualCrnp',
        headers: {token: localStorage.getItem('token')},
        url: baseUrl+'/basDualCrnp/list/auth',
        page: true,
        limit: 15,
        limits: [15, 30, 50, 100, 200, 500],
        toolbar: '#toolbar',
        cellMinWidth: 50,
        height: 'full-120',
        cols: [[
            {type: 'checkbox'}
            ,{field: 'crnNo', align: 'center',title: '编号'}
            ,{field: 'status$', align: 'center',title: '状态'}
            // ,{field: 'wrkNo', align: 'center',title: '工作号'}
            ,{field: 'inEnable', align: 'center',title: '可入(checkBox)'}
            ,{field: 'outEnable', align: 'center',title: '可出(checkBox)'}
            // ,{field: 'createBy', align: 'center',title: '创建人员'}
            // ,{field: 'createTime$', align: 'center',title: '创建时间'}
            // ,{field: 'updateBy', align: 'center',title: '修改人员'}
            // ,{field: 'updateTime$', align: 'center',title: '修改时间'}
            ,{field: 'memo', align: 'center',title: '备注'}
            ,{field: 'controlRows', align: 'center',title: '控制库位排号'}
            ,{field: 'deepRows', align: 'center',title: '深库位排号'}
            ,{field: 'inStationList', align: 'center',title: '入库站点'}
            ,{field: 'outStationList', align: 'center',title: '出库站点'}
            ,{field: 'maxInTask', align: 'center',title: '最大入库任务数'}
            ,{field: 'maxOutTask', align: 'center',title: '最大出库任务数'}
            ,{field: 'disableStationOneBays', align: 'center',title: '工位1禁止执行列'}
            ,{field: 'disableStationTwoBays', align: 'center',title: '工位2禁止执行列'}
    ]);
            ,{fixed: 'right', title:'操作', align: 'center', toolbar: '#operate', width:120}
        ]],
        request: {
            pageName: 'curr',
            pageSize: 'limit'
        },
        parseData: function (res) {
            return {
                'code': res.code,
                'msg': res.msg,
                'count': res.data.total,
                'data': res.data.records
            }
        },
        response: {
            statusCode: 200
        },
        done: function(res, curr, count) {
            if (res.code === 403) {
                top.location.href = baseUrl+"/";
            }
            pageCurr=curr;
            limit();
    function formatFieldLabel(field) {
        var raw = field && field.label ? String(field.label).trim() : '';
        if (raw) {
            return raw;
        }
    });
    // 监听排序事件
    table.on('sort(basDualCrnp)', function (obj) {
        var searchData = {};
        $.each($('#search-box [name]').serializeArray(), function() {
            searchData[this.name] = this.value;
        });
        searchData['orderByField'] = obj.field;
        searchData['orderByType'] = obj.type;
        tableIns.reload({
            where: searchData,
            page: {curr: 1}
        });
    });
    // 监听头工具栏事件
    table.on('toolbar(basDualCrnp)', function (obj) {
        var checkStatus = table.checkStatus(obj.config.id).data;
        switch(obj.event) {
            case 'addData':
                showEditModel();
                break;
            case 'deleteData':
               if (checkStatus.length === 0) {
                   layer.msg('请选择要删除的数据', {icon: 2});
                   return;
               }
               del(checkStatus.map(function (d) {
                   return d.crnNo;
               }));
               break;
            case 'exportData':
                admin.confirm('确定导出Excel吗', {shadeClose: true}, function(){
                    var titles=[];
                    var fields=[];
                    obj.config.cols[0].map(function (col) {
                        if (col.type === 'normal' && col.hide === false && col.toolbar == null) {
                            titles.push(col.title);
                            fields.push(col.field);
                        }
                    });
                    var exportData = {};
                    $.each($('#search-box [name]').serializeArray(), function() {
                        exportData[this.name] = this.value;
                    });
                    var param = {
                        'basDualCrnp': exportData,
                        'fields': fields
                    };
                    $.ajax({
                        url: baseUrl+"/basDualCrnp/export/auth",
                        headers: {'token': localStorage.getItem('token')},
                        data: JSON.stringify(param),
                        dataType:'json',
                        contentType:'application/json;charset=UTF-8',
                        method: 'POST',
                        success: function (res) {
                            layer.closeAll();
                            if (res.code === 200) {
                                table.exportFile(titles,res.data,'xls');
                            } else if (res.code === 403) {
                                top.location.href = baseUrl+"/";
                            } else {
                                layer.msg(res.msg, {icon: 2})
                            }
                        }
                    });
                });
                break;
        raw = field && field.columnName ? field.columnName : (field && field.field ? field.field : '');
        if (!raw) {
            return '';
        }
    });
    // 监听行工具事件
    table.on('tool(basDualCrnp)', function(obj){
        var data = obj.data;
        switch (obj.event) {
            case 'edit':
                showEditModel(data);
                break;
            case "del":
                del([data.crnNo]);
                break;
        }
    });
    /* 弹窗 - 新增、修改 */
    function showEditModel(mData) {
        admin.open({
            type: 1,
            area: '600px',
            title: (mData ? '修改' : '添加') + '订单状态',
            content: $('#editDialog').html(),
            success: function (layero, dIndex) {
                layDateRender(mData);
                form.val('detail', mData);
                form.on('submit(editSubmit)', function (data) {
                    var loadIndex = layer.load(2);
                    $.ajax({
                        url: baseUrl+"/basDualCrnp/"+(mData?'update':'add')+"/auth",
                        headers: {'token': localStorage.getItem('token')},
                        data: data.field,
                        method: 'POST',
                        success: function (res) {
                            layer.close(loadIndex);
                            if (res.code === 200){
                                layer.close(dIndex);
                                layer.msg(res.msg, {icon: 1});
                                tableReload();
                            } else if (res.code === 403){
                                top.location.href = baseUrl+"/";
                            }else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }
                    })
                    return false;
                });
                $(layero).children('.layui-layer-content').css('overflow', 'visible');
                layui.form.render('select');
            }
        raw = String(raw)
            .replace(/\$/g, '')
            .replace(/([a-z0-9])([A-Z])/g, '$1_$2')
            .replace(/_/g, ' ')
            .replace(/\s+/g, ' ')
            .trim();
        return raw.replace(/\b[a-z]/g, function (letter) {
            return letter.toUpperCase();
        });
    }
    /* 删除 */
    function del(ids) {
        layer.confirm('确定要删除选中数据吗?', {
            skin: 'layui-layer-admin',
            shade: .1
        }, function (i) {
            layer.close(i);
            var loadIndex = layer.load(2);
    function dedupeFieldMeta(list) {
        var result = [];
        var seen = {};
        (list || []).forEach(function (field) {
            if (!field || !field.field || seen[field.field]) {
                return;
            }
            field.label = formatFieldLabel(field);
            seen[field.field] = true;
            result.push(field);
        });
        return result;
    }
    function isEmptyValue(value) {
        return value === null || value === undefined || value === '';
    }
    function stringValue(value) {
        return isEmptyValue(value) ? '' : String(value);
    }
    function valueOrDash(value) {
        return isEmptyValue(value) ? '--' : value;
    }
    function normalizeOptionValue(field, rawValue) {
        if (rawValue === null || rawValue === undefined) {
            return null;
        }
        if (rawValue === '') {
            return '';
        }
        if (field && field.valueType === 'number') {
            var numberVal = Number(rawValue);
            return isNaN(numberVal) ? rawValue : numberVal;
        }
        return String(rawValue);
    }
    function isSearchableField(field) {
        return !!field && field.kind !== 'image' && !field.textarea;
    }
    function isSortableField(field) {
        if (!field) {
            return false;
        }
        if (field.primaryKey) {
            return true;
        }
        return field.kind !== 'image' && !field.textarea && field.kind !== 'foreign';
    }
    function defaultFieldValue(field) {
        if (field.primaryKey) {
            return null;
        }
        if (field.kind === 'checkbox') {
            return normalizeOptionValue(field, field.checkboxInactiveRaw);
        }
        return '';
    }
    function defaultSearchFieldValue(field) {
        if (field.kind === 'date') {
            return [];
        }
        if (field.kind === 'enum' || field.kind === 'checkbox') {
            return null;
        }
        return '';
    }
    function createSearchDefaults() {
        var result = {
            condition: ''
        };
        fieldMeta.forEach(function (field) {
            if (!isSearchableField(field)) {
                return;
            }
            result[field.field] = defaultSearchFieldValue(field);
        });
        return result;
    }
    function createSearchDisplayDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            if (field.kind === 'foreign' && isSearchableField(field)) {
                result[field.field] = '';
            }
        });
        return result;
    }
    function createDefaultVisibleColumnKeys() {
        return fieldMeta.map(function (field) {
            return field.field;
        });
    }
    function createFormDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            result[field.field] = defaultFieldValue(field);
        });
        return result;
    }
    function createDisplayDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            if (field.kind === 'foreign') {
                result[field.field] = '';
            }
        });
        return result;
    }
    function createFormRules() {
        var rules = {};
        fieldMeta.forEach(function (field) {
            if (field.primaryKey || !field.required) {
                return;
            }
            rules[field.field] = [{
                required: true,
                message: (field.kind === 'date' || field.kind === 'enum' ? '请选择' : '请输入') + field.label,
                trigger: (field.kind === 'date' || field.kind === 'enum') ? 'change' : 'blur'
            }];
        });
        return rules;
    }
    function getTableValue(row, field) {
        var prop = field.tableProp || field.field;
        if (row && !isEmptyValue(row[prop])) {
            return row[prop];
        }
        return row ? row[field.field] : '';
    }
    function isCheckboxChecked(row, field) {
        var value = row ? row[field.field] : null;
        var activeValue = normalizeOptionValue(field, field.checkboxActiveRaw);
        return String(value) === String(activeValue);
    }
    function exportCell(value) {
        return stringValue(value).replace(/\t/g, ' ').replace(/\r?\n/g, ' ');
    }
    function escapeHtml(value) {
        return exportCell(value)
            .replace(/&/g, '&amp;')
            .replace(/</g, '&lt;')
            .replace(/>/g, '&gt;')
            .replace(/"/g, '&quot;')
            .replace(/'/g, '&#39;');
    }
    function buildPayload(form) {
        var payload = {};
        fieldMeta.forEach(function (field) {
            var value = form[field.field];
            if (field.primaryKey) {
                if (!isEmptyValue(value)) {
                    payload[field.field] = value;
                }
                return;
            }
            if (field.kind === 'foreign' && isEmptyValue(value)) {
                value = null;
            }
            if (field.kind === 'enum' && value === '') {
                value = null;
            }
            if (field.kind === 'checkbox' && isEmptyValue(value)) {
                value = normalizeOptionValue(field, field.checkboxInactiveRaw);
            }
            if (field.valueType === 'number' && !isEmptyValue(value)) {
                value = Number(value);
            }
            if (field.valueType === 'number' && value === '') {
                value = null;
            }
            payload[field.field] = value;
        });
        return payload;
    }
    function fillFormFromRow(row, form, display) {
        fieldMeta.forEach(function (field) {
            if (field.primaryKey) {
                form[field.field] = row[field.field];
                return;
            }
            if (field.kind === 'date') {
                form[field.field] = row[field.tableProp] || row[field.field] || '';
                return;
            }
            if (field.kind === 'foreign') {
                form[field.field] = isEmptyValue(row[field.field]) ? '' : normalizeOptionValue(field, row[field.field]);
                if (display) {
                    display[field.field] = row[field.tableProp] || (isEmptyValue(row[field.field]) ? '' : String(row[field.field]));
                }
                return;
            }
            if (field.kind === 'enum') {
                form[field.field] = isEmptyValue(row[field.field]) ? '' : normalizeOptionValue(field, row[field.field]);
                return;
            }
            if (field.kind === 'checkbox') {
                form[field.field] = isEmptyValue(row[field.field])
                    ? normalizeOptionValue(field, field.checkboxInactiveRaw)
                    : normalizeOptionValue(field, row[field.field]);
                return;
            }
            form[field.field] = isEmptyValue(row[field.field])
                ? ''
                : (field.valueType === 'number' ? String(row[field.field]) : row[field.field]);
        });
    }
    function resolveSearchParam(field) {
        if (field.kind === 'date' && field.columnName) {
            return field.columnName;
        }
        return field.field;
    }
    function createDownloadFile(filename, titles, rows) {
        var html = [
            '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">',
            '<head><meta charset="UTF-8"></head><body><table border="1"><thead><tr>',
            titles.map(function (title) {
                return '<th>' + escapeHtml(title) + '</th>';
            }).join(''),
            '</tr></thead><tbody>',
            (rows || []).map(function (row) {
                return '<tr>' + (row || []).map(function (value) {
                    return '<td style="mso-number-format:\\@;">' + escapeHtml(value) + '</td>';
                }).join('') + '</tr>';
            }).join(''),
            '</tbody></table></body></html>'
        ].join('');
        var blob = new Blob(['\ufeff' + html], {
            type: 'application/vnd.ms-excel;charset=utf-8;'
        });
        var anchor = document.createElement('a');
        anchor.href = URL.createObjectURL(blob);
        anchor.download = filename;
        document.body.appendChild(anchor);
        anchor.click();
        setTimeout(function () {
            URL.revokeObjectURL(anchor.href);
            document.body.removeChild(anchor);
        }, 0);
    }
    function buildTimestamp() {
        var now = new Date();
        var pad = function (num) {
            return num < 10 ? '0' + num : String(num);
        };
        return now.getFullYear()
            + pad(now.getMonth() + 1)
            + pad(now.getDate())
            + '_'
            + pad(now.getHours())
            + pad(now.getMinutes())
            + pad(now.getSeconds());
    }
    function authHeaders() {
        return {
            token: localStorage.getItem('token')
        };
    }
    function handleForbidden(res) {
        if (res && res.code === 403) {
            top.location.href = baseUrl + '/';
            return true;
        }
        return false;
    }
    var sharedMethods = {
        authHeaders: authHeaders,
        handleForbidden: handleForbidden,
        valueOrDash: valueOrDash,
        stringValue: stringValue,
        getTableValue: getTableValue,
        isCheckboxChecked: isCheckboxChecked,
        normalizeOptionValue: normalizeOptionValue,
        isSortableField: isSortableField,
        getSuggestionFetcher: function (field) {
            var self = this;
            return function (queryString, callback) {
                self.fetchForeignSuggestions(field, queryString, callback);
            };
        },
        fetchForeignSuggestions: function (field, queryString, callback) {
            if (!field.foreignQuery || !queryString) {
                callback([]);
                return;
            }
            var self = this;
            $.ajax({
                url: baseUrl+"/basDualCrnp/delete/auth",
                headers: {'token': localStorage.getItem('token')},
                data: {ids: ids},
                method: 'POST',
                url: baseUrl + '/' + field.foreignQuery + 'Query/auth',
                method: 'GET',
                headers: self.authHeaders(),
                data: { condition: queryString },
                success: function (res) {
                    layer.close(loadIndex);
                    if (res.code === 200){
                        layer.msg(res.msg, {icon: 1});
                        tableReload();
                    } else if (res.code === 403){
                        top.location.href = baseUrl+"/";
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    if (self.handleForbidden(res)) {
                        return;
                    }
                    if (!res || res.code !== 200 || !Array.isArray(res.data)) {
                        callback([]);
                        return;
                    }
                    callback(res.data.map(function (item) {
                        return {
                            id: item.id,
                            value: item.value
                        };
                    }));
                },
                error: function () {
                    callback([]);
                }
            });
        },
        handleForeignSelect: function (field, item) {
            this.$set(this.displayTarget, field.field, item && item.value ? item.value : '');
            this.$set(this.formTarget, field.field, item && item.id !== undefined ? normalizeOptionValue(field, item.id) : '');
        },
        handleForeignInput: function (field) {
            if (!this.displayTarget || !this.formTarget) {
                return;
            }
            if (this.displayTarget[field.field]) {
                return;
            }
            this.$set(this.formTarget, field.field, '');
        }
    };
    if (document.getElementById('app')) {
        new Vue({
            el: '#app',
            data: function () {
                return {
                    fieldMeta: fieldMeta,
                    primaryKeyField: primaryKeyField,
                    loading: false,
                    exporting: false,
                    tableData: [],
                    selection: [],
                    advancedFiltersVisible: false,
                    allColumns: fieldMeta.slice(),
                    visibleColumnKeys: createDefaultVisibleColumnKeys(),
                    searchForm: createSearchDefaults(),
                    searchDisplay: createSearchDisplayDefaults(),
                    page: {
                        curr: 1,
                        limit: 15,
                        total: 0
                    },
                    sortState: {
                        prop: '',
                        order: ''
                    },
                    dialog: {
                        visible: false,
                        mode: 'create',
                        submitting: false
                    },
                    layoutTimer: null,
                    tableResizeHandler: null,
                    dialogForm: createFormDefaults(),
                    dialogDisplay: createDisplayDefaults(),
                    dialogRules: createFormRules()
                };
            },
            computed: {
                searchableFields: function () {
                    return this.fieldMeta.filter(function (field) {
                        return isSearchableField(field);
                    });
                },
                quickSearchableFields: function () {
                    var result = [];
                    this.searchableFields.forEach(function (field) {
                        if (result.length >= 3 || field.kind === 'date') {
                            return;
                        }
                        result.push(field);
                    });
                    return result;
                },
                advancedSearchableFields: function () {
                    var quickKeys = this.quickSearchableFields.map(function (field) {
                        return field.field;
                    });
                    return this.searchableFields.filter(function (field) {
                        return quickKeys.indexOf(field.field) === -1;
                    });
                },
                hasAdvancedFilters: function () {
                    return this.advancedSearchableFields.length > 0;
                },
                visibleColumns: function () {
                    var keys = this.visibleColumnKeys;
                    return this.allColumns.filter(function (field) {
                        return keys.indexOf(field.field) !== -1;
                    });
                },
                editableFields: function () {
                    return this.fieldMeta.filter(function (field) {
                        return !field.primaryKey;
                    });
                },
                exportColumns: function () {
                    return this.visibleColumns.map(function (field) {
                        return {
                            field: field.exportField || field.tableProp || field.field,
                            label: field.label
                        };
                    });
                },
                tableHeight: function () {
                    return this.advancedFiltersVisible && this.hasAdvancedFilters
                        ? 'calc(100vh - 390px)'
                        : 'calc(100vh - 300px)';
                },
                formTarget: function () {
                    return this.dialogForm;
                },
                displayTarget: function () {
                    return this.dialogDisplay;
                }
            },
            created: function () {
                this.loadTable();
            },
            mounted: function () {
                var self = this;
                self.requestTableLayout(80);
                self.tableResizeHandler = function () {
                    self.requestTableLayout(80);
                };
                window.addEventListener('resize', self.tableResizeHandler);
            },
            beforeDestroy: function () {
                if (this.layoutTimer) {
                    clearTimeout(this.layoutTimer);
                    this.layoutTimer = null;
                }
                if (this.tableResizeHandler) {
                    window.removeEventListener('resize', this.tableResizeHandler);
                    this.tableResizeHandler = null;
                }
            },
            methods: $.extend({}, sharedMethods, {
                requestTableLayout: function (delay) {
                    var self = this;
                    if (self.layoutTimer) {
                        clearTimeout(self.layoutTimer);
                    }
                    self.$nextTick(function () {
                        self.layoutTimer = setTimeout(function () {
                            var table = self.$refs.dataTable;
                            if (table && typeof table.doLayout === 'function') {
                                table.doLayout();
                            }
                        }, delay || 40);
                    });
                },
                isColumnVisible: function (fieldName) {
                    return this.visibleColumnKeys.indexOf(fieldName) !== -1;
                },
                toggleColumn: function (fieldName, visible) {
                    if (visible) {
                        if (this.visibleColumnKeys.indexOf(fieldName) === -1) {
                            this.visibleColumnKeys.push(fieldName);
                        }
                        this.requestTableLayout(80);
                        return;
                    }
                    if (this.visibleColumnKeys.length === 1) {
                        this.$message.warning('至少保留一列');
                        return;
                    }
                    this.visibleColumnKeys = this.visibleColumnKeys.filter(function (item) {
                        return item !== fieldName;
                    });
                    this.requestTableLayout(80);
                },
                selectAllColumns: function () {
                    this.visibleColumnKeys = createDefaultVisibleColumnKeys();
                    this.requestTableLayout(80);
                },
                resetColumns: function () {
                    this.visibleColumnKeys = createDefaultVisibleColumnKeys();
                    this.requestTableLayout(80);
                },
                toggleAdvancedFilters: function () {
                    this.advancedFiltersVisible = !this.advancedFiltersVisible;
                    this.requestTableLayout(260);
                },
                handleSearchForeignSelect: function (field, item) {
                    this.$set(this.searchDisplay, field.field, item && item.value ? item.value : '');
                    this.$set(this.searchForm, field.field, item && item.id !== undefined ? normalizeOptionValue(field, item.id) : '');
                },
                handleSearchForeignInput: function (field) {
                    if (this.searchDisplay[field.field]) {
                        return;
                    }
                    this.$set(this.searchForm, field.field, '');
                },
                buildQueryParams: function () {
                    var self = this;
                    var params = {
                        curr: self.page.curr,
                        limit: self.page.limit
                    };
                    if (self.searchForm.condition) {
                        params.condition = self.searchForm.condition;
                    }
                    self.searchableFields.forEach(function (field) {
                        var value = self.searchForm[field.field];
                        if (field.kind === 'date') {
                            if (value && value.length === 2) {
                                params[resolveSearchParam(field)] = value[0] + ' - ' + value[1];
                            }
                            return;
                        }
                        if (!isEmptyValue(value)) {
                            params[resolveSearchParam(field)] = value;
                        }
                    });
                    if (self.sortState.prop && self.sortState.order) {
                        params.orderByField = self.sortState.prop;
                        params.orderByType = self.sortState.order === 'ascending' ? 'asc' : 'desc';
                    }
                    return params;
                },
                loadTable: function () {
                    var self = this;
                    self.loading = true;
                    $.ajax({
                        url: baseUrl + '/' + simpleEntityName + '/list/auth',
                        method: 'GET',
                        headers: self.authHeaders(),
                        data: self.buildQueryParams(),
                        success: function (res) {
                            self.loading = false;
                            if (self.handleForbidden(res)) {
                                return;
                            }
                            if (!res || res.code !== 200) {
                                self.$message.error((res && res.msg) ? res.msg : '加载失败');
                                return;
                            }
                            var payload = res.data || {};
                            self.tableData = Array.isArray(payload.records) ? payload.records : [];
                            self.page.total = payload.total || 0;
                            self.requestTableLayout(80);
                        },
                        error: function () {
                            self.loading = false;
                            self.requestTableLayout(80);
                            self.$message.error('加载失败');
                        }
                    });
                },
                handleSearch: function () {
                    this.page.curr = 1;
                    this.loadTable();
                },
                handleReset: function () {
                    this.searchForm = createSearchDefaults();
                    this.searchDisplay = createSearchDisplayDefaults();
                    this.advancedFiltersVisible = false;
                    this.page.curr = 1;
                    this.sortState = {
                        prop: '',
                        order: ''
                    };
                    this.loadTable();
                },
                handleSelectionChange: function (rows) {
                    this.selection = rows || [];
                },
                handleSortChange: function (payload) {
                    this.sortState = {
                        prop: payload && payload.prop ? payload.prop : '',
                        order: payload && payload.order ? payload.order : ''
                    };
                    this.page.curr = 1;
                    this.loadTable();
                },
                handleCurrentChange: function (curr) {
                    this.page.curr = curr;
                    this.loadTable();
                },
                handleSizeChange: function (limit) {
                    this.page.limit = limit;
                    this.page.curr = 1;
                    this.loadTable();
                },
                resetDialogState: function () {
                    this.dialogForm = createFormDefaults();
                    this.dialogDisplay = createDisplayDefaults();
                    if (this.$refs.dialogForm) {
                        this.$refs.dialogForm.clearValidate();
                    }
                },
                openCreateDialog: function () {
                    this.dialog.mode = 'create';
                    this.dialog.visible = true;
                    this.$nextTick(this.resetDialogState);
                },
                openEditDialog: function (row) {
                    var self = this;
                    self.dialog.mode = 'edit';
                    self.dialog.visible = true;
                    self.$nextTick(function () {
                        self.resetDialogState();
                        fillFormFromRow(row, self.dialogForm, self.dialogDisplay);
                        if (self.$refs.dialogForm) {
                            self.$refs.dialogForm.clearValidate();
                        }
                    });
                },
                submitDialog: function () {
                    var self = this;
                    if (!self.$refs.dialogForm) {
                        return;
                    }
                    self.$refs.dialogForm.validate(function (valid) {
                        if (!valid) {
                            return false;
                        }
                        self.dialog.submitting = true;
                        $.ajax({
                            url: baseUrl + '/' + simpleEntityName + '/' + (self.dialog.mode === 'create' ? 'add' : 'update') + '/auth',
                            method: 'POST',
                            headers: self.authHeaders(),
                            data: buildPayload(self.dialogForm),
                            success: function (res) {
                                self.dialog.submitting = false;
                                if (self.handleForbidden(res)) {
                                    return;
                                }
                                if (!res || res.code !== 200) {
                                    self.$message.error((res && res.msg) ? res.msg : '保存失败');
                                    return;
                                }
                                self.$message.success(res.msg || '保存成功');
                                self.dialog.visible = false;
                                self.loadTable();
                            },
                            error: function () {
                                self.dialog.submitting = false;
                                self.$message.error('保存失败');
                            }
                        });
                        return true;
                    });
                },
                removeSelection: function () {
                    var self = this;
                    var ids = self.selection.map(function (row) {
                        return row[self.primaryKeyField];
                    });
                    self.removeRows(ids);
                },
                removeRows: function (ids) {
                    var self = this;
                    if (!ids || ids.length === 0) {
                        self.$message.warning('请选择要删除的数据');
                        return;
                    }
                    self.$confirm('确定删除选中的记录吗?', '提示', { type: 'warning' }).then(function () {
                        $.ajax({
                            url: baseUrl + '/' + simpleEntityName + '/delete/auth',
                            method: 'POST',
                            headers: self.authHeaders(),
                            traditional: true,
                            data: { 'ids[]': ids },
                            success: function (res) {
                                if (self.handleForbidden(res)) {
                                    return;
                                }
                                if (!res || res.code !== 200) {
                                    self.$message.error((res && res.msg) ? res.msg : '删除失败');
                                    return;
                                }
                                self.$message.success(res.msg || '删除成功');
                                self.selection = [];
                                if (self.tableData.length === ids.length && self.page.curr > 1) {
                                    self.page.curr = self.page.curr - 1;
                                }
                                self.loadTable();
                            },
                            error: function () {
                                self.$message.error('删除失败');
                            }
                        });
                    }).catch(function () {});
                },
                exportRows: function () {
                    var self = this;
                    self.exporting = true;
                    var requestBody = {
                        fields: self.exportColumns.map(function (item) {
                            return item.field;
                        })
                    };
                    requestBody[simpleEntityName] = self.buildQueryParams();
                    $.ajax({
                        url: baseUrl + '/' + simpleEntityName + '/export/auth',
                        method: 'POST',
                        headers: $.extend({ 'Content-Type': 'application/json;charset=UTF-8' }, self.authHeaders()),
                        data: JSON.stringify(requestBody),
                        success: function (res) {
                            self.exporting = false;
                            if (self.handleForbidden(res)) {
                                return;
                            }
                            if (!res || res.code !== 200) {
                                self.$message.error((res && res.msg) ? res.msg : '导出失败');
                                return;
                            }
                            createDownloadFile(
                                simpleEntityName + '_' + buildTimestamp() + '.xls',
                                self.exportColumns.map(function (item) {
                                    return item.label;
                                }),
                                Array.isArray(res.data) ? res.data : []
                            );
                            self.$message.success('导出成功');
                        },
                        error: function () {
                            self.exporting = false;
                            self.$message.error('导出失败');
                        }
                    });
                }
            })
        });
    }
    // 搜索
    form.on('submit(search)', function (data) {
        pageCurr = 1;
        tableReload(false);
    });
    // 重置
    form.on('submit(reset)', function (data) {
        pageCurr = 1;
        clearFormVal($('#search-box'));
        tableReload(false);
    });
    // 时间选择器
    function layDateRender(data) {
        setTimeout(function () {
            layDate.render({
                elem: '.layui-laydate-range'
                ,type: 'datetime'
                ,range: true
            });
            layDate.render({
                elem: '#createTime\\$',
                type: 'datetime',
                value: data!==undefined?data['createTime\\$']:null
            });
            layDate.render({
                elem: '#updateTime\\$',
                type: 'datetime',
                value: data!==undefined?data['updateTime\\$']:null
            });
        }, 300);
    }
    layDateRender();
});
// 关闭动作
$(document).on('click','#data-detail-close', function () {
    parent.layer.closeAll();
});
function tableReload(child) {
    var searchData = {};
    $.each($('#search-box [name]').serializeArray(), function() {
        searchData[this.name] = this.value;
    });
    tableIns.reload({
        where: searchData,
        page: {curr: pageCurr}
     });
}
})();
src/main/webapp/static/js/basDualCrnpErr/basDualCrnpErr.js
@@ -1,261 +1,913 @@
var pageCurr;
layui.config({
    base: baseUrl + "/static/layui/lay/modules/"
}).use(['table','laydate', 'form', 'admin'], function(){
    var table = layui.table;
    var $ = layui.jquery;
    var layer = layui.layer;
    var layDate = layui.laydate;
    var form = layui.form;
    var admin = layui.admin;
(function () {
    var simpleEntityName = 'basDualCrnpErr';
    var entityName = 'BasDualCrnpErr';
    var primaryKeyField = 'id';
    var fieldMeta = dedupeFieldMeta([
    {
        field: 'id',
        columnName: 'id',
        label: '编  号',
        tableProp: 'id',
        exportField: 'id',
        kind: 'text',
        valueType: 'number',
        required: true,
        primaryKey: true,
        sortable: true,
        textarea: false,
        minWidth: 90,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'errorCode',
        columnName: 'error_code',
        label: '异 常 码',
        tableProp: 'errorCode',
        exportField: 'errorCode',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 116,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'errName',
        columnName: 'err_name',
        label: '异  常',
        tableProp: 'errName',
        exportField: 'errName',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'modiUser',
        columnName: 'modi_user',
        label: '修改人员',
        tableProp: 'modiUser$',
        exportField: 'modiUser$',
        kind: 'foreign',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: 'user',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'modiTime',
        columnName: 'modi_time',
        label: '修改时间',
        tableProp: 'modiTime$',
        exportField: 'modiTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'appeUser',
        columnName: 'appe_user',
        label: '添加人员',
        tableProp: 'appeUser$',
        exportField: 'appeUser$',
        kind: 'foreign',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: 'user',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'appeTime',
        columnName: 'appe_time',
        label: '添加时间',
        tableProp: 'appeTime$',
        exportField: 'appeTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    }
    // 数据渲染
    tableIns = table.render({
        elem: '#basDualCrnpErr',
        headers: {token: localStorage.getItem('token')},
        url: baseUrl+'/basDualCrnpErr/list/auth',
        page: true,
        limit: 15,
        limits: [15, 30, 50, 100, 200, 500],
        toolbar: '#toolbar',
        cellMinWidth: 50,
        height: 'full-120',
        cols: [[
            {type: 'checkbox'}
            ,{field: 'id', align: 'center',title: '编号'}
            ,{field: 'errorCode', align: 'center',title: '异常码'}
            ,{field: 'errName', align: 'center',title: '异常'}
            ,{field: 'modiUser$', align: 'center',title: '修改人员'}
            ,{field: 'modiTime$', align: 'center',title: '修改时间'}
            ,{field: 'appeUser$', align: 'center',title: '添加人员'}
            ,{field: 'appeTime$', align: 'center',title: '添加时间'}
    ]);
            ,{fixed: 'right', title:'操作', align: 'center', toolbar: '#operate', width:120}
        ]],
        request: {
            pageName: 'curr',
            pageSize: 'limit'
        },
        parseData: function (res) {
            return {
                'code': res.code,
                'msg': res.msg,
                'count': res.data.total,
                'data': res.data.records
            }
        },
        response: {
            statusCode: 200
        },
        done: function(res, curr, count) {
            if (res.code === 403) {
                top.location.href = baseUrl+"/";
            }
            pageCurr=curr;
            limit();
    function formatFieldLabel(field) {
        var raw = field && field.label ? String(field.label).trim() : '';
        if (raw) {
            return raw;
        }
    });
    // 监听排序事件
    table.on('sort(basDualCrnpErr)', function (obj) {
        var searchData = {};
        $.each($('#search-box [name]').serializeArray(), function() {
            searchData[this.name] = this.value;
        });
        searchData['orderByField'] = obj.field;
        searchData['orderByType'] = obj.type;
        tableIns.reload({
            where: searchData,
            page: {curr: 1}
        });
    });
    // 监听头工具栏事件
    table.on('toolbar(basDualCrnpErr)', function (obj) {
        var checkStatus = table.checkStatus(obj.config.id).data;
        switch(obj.event) {
            case 'addData':
                showEditModel();
                break;
            case 'deleteData':
               if (checkStatus.length === 0) {
                   layer.msg('请选择要删除的数据', {icon: 2});
                   return;
               }
               del(checkStatus.map(function (d) {
                   return d.id;
               }));
               break;
            case 'exportData':
                admin.confirm('确定导出Excel吗', {shadeClose: true}, function(){
                    var titles=[];
                    var fields=[];
                    obj.config.cols[0].map(function (col) {
                        if (col.type === 'normal' && col.hide === false && col.toolbar == null) {
                            titles.push(col.title);
                            fields.push(col.field);
                        }
                    });
                    var exportData = {};
                    $.each($('#search-box [name]').serializeArray(), function() {
                        exportData[this.name] = this.value;
                    });
                    var param = {
                        'basDualCrnpErr': exportData,
                        'fields': fields
                    };
                    $.ajax({
                        url: baseUrl+"/basDualCrnpErr/export/auth",
                        headers: {'token': localStorage.getItem('token')},
                        data: JSON.stringify(param),
                        dataType:'json',
                        contentType:'application/json;charset=UTF-8',
                        method: 'POST',
                        success: function (res) {
                            layer.closeAll();
                            if (res.code === 200) {
                                table.exportFile(titles,res.data,'xls');
                            } else if (res.code === 403) {
                                top.location.href = baseUrl+"/";
                            } else {
                                layer.msg(res.msg, {icon: 2})
                            }
                        }
                    });
                });
                break;
        raw = field && field.columnName ? field.columnName : (field && field.field ? field.field : '');
        if (!raw) {
            return '';
        }
    });
    // 监听行工具事件
    table.on('tool(basDualCrnpErr)', function(obj){
        var data = obj.data;
        switch (obj.event) {
            case 'edit':
                showEditModel(data);
                break;
            case "del":
                del([data.id]);
                break;
        }
    });
    /* 弹窗 - 新增、修改 */
    function showEditModel(mData) {
        admin.open({
            type: 1,
            area: '600px',
            title: (mData ? '修改' : '添加') + '订单状态',
            content: $('#editDialog').html(),
            success: function (layero, dIndex) {
                layDateRender(mData);
                form.val('detail', mData);
                form.on('submit(editSubmit)', function (data) {
                    var loadIndex = layer.load(2);
                    $.ajax({
                        url: baseUrl+"/basDualCrnpErr/"+(mData?'update':'add')+"/auth",
                        headers: {'token': localStorage.getItem('token')},
                        data: data.field,
                        method: 'POST',
                        success: function (res) {
                            layer.close(loadIndex);
                            if (res.code === 200){
                                layer.close(dIndex);
                                layer.msg(res.msg, {icon: 1});
                                tableReload();
                            } else if (res.code === 403){
                                top.location.href = baseUrl+"/";
                            }else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }
                    })
                    return false;
                });
                $(layero).children('.layui-layer-content').css('overflow', 'visible');
                layui.form.render('select');
            }
        raw = String(raw)
            .replace(/\$/g, '')
            .replace(/([a-z0-9])([A-Z])/g, '$1_$2')
            .replace(/_/g, ' ')
            .replace(/\s+/g, ' ')
            .trim();
        return raw.replace(/\b[a-z]/g, function (letter) {
            return letter.toUpperCase();
        });
    }
    /* 删除 */
    function del(ids) {
        layer.confirm('确定要删除选中数据吗?', {
            skin: 'layui-layer-admin',
            shade: .1
        }, function (i) {
            layer.close(i);
            var loadIndex = layer.load(2);
    function dedupeFieldMeta(list) {
        var result = [];
        var seen = {};
        (list || []).forEach(function (field) {
            if (!field || !field.field || seen[field.field]) {
                return;
            }
            field.label = formatFieldLabel(field);
            seen[field.field] = true;
            result.push(field);
        });
        return result;
    }
    function isEmptyValue(value) {
        return value === null || value === undefined || value === '';
    }
    function stringValue(value) {
        return isEmptyValue(value) ? '' : String(value);
    }
    function valueOrDash(value) {
        return isEmptyValue(value) ? '--' : value;
    }
    function normalizeOptionValue(field, rawValue) {
        if (rawValue === null || rawValue === undefined) {
            return null;
        }
        if (rawValue === '') {
            return '';
        }
        if (field && field.valueType === 'number') {
            var numberVal = Number(rawValue);
            return isNaN(numberVal) ? rawValue : numberVal;
        }
        return String(rawValue);
    }
    function isSearchableField(field) {
        return !!field && field.kind !== 'image' && !field.textarea;
    }
    function isSortableField(field) {
        if (!field) {
            return false;
        }
        if (field.primaryKey) {
            return true;
        }
        return field.kind !== 'image' && !field.textarea && field.kind !== 'foreign';
    }
    function defaultFieldValue(field) {
        if (field.primaryKey) {
            return null;
        }
        if (field.kind === 'checkbox') {
            return normalizeOptionValue(field, field.checkboxInactiveRaw);
        }
        return '';
    }
    function defaultSearchFieldValue(field) {
        if (field.kind === 'date') {
            return [];
        }
        if (field.kind === 'enum' || field.kind === 'checkbox') {
            return null;
        }
        return '';
    }
    function createSearchDefaults() {
        var result = {
            condition: ''
        };
        fieldMeta.forEach(function (field) {
            if (!isSearchableField(field)) {
                return;
            }
            result[field.field] = defaultSearchFieldValue(field);
        });
        return result;
    }
    function createSearchDisplayDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            if (field.kind === 'foreign' && isSearchableField(field)) {
                result[field.field] = '';
            }
        });
        return result;
    }
    function createDefaultVisibleColumnKeys() {
        return fieldMeta.map(function (field) {
            return field.field;
        });
    }
    function createFormDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            result[field.field] = defaultFieldValue(field);
        });
        return result;
    }
    function createDisplayDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            if (field.kind === 'foreign') {
                result[field.field] = '';
            }
        });
        return result;
    }
    function createFormRules() {
        var rules = {};
        fieldMeta.forEach(function (field) {
            if (field.primaryKey || !field.required) {
                return;
            }
            rules[field.field] = [{
                required: true,
                message: (field.kind === 'date' || field.kind === 'enum' ? '请选择' : '请输入') + field.label,
                trigger: (field.kind === 'date' || field.kind === 'enum') ? 'change' : 'blur'
            }];
        });
        return rules;
    }
    function getTableValue(row, field) {
        var prop = field.tableProp || field.field;
        if (row && !isEmptyValue(row[prop])) {
            return row[prop];
        }
        return row ? row[field.field] : '';
    }
    function isCheckboxChecked(row, field) {
        var value = row ? row[field.field] : null;
        var activeValue = normalizeOptionValue(field, field.checkboxActiveRaw);
        return String(value) === String(activeValue);
    }
    function exportCell(value) {
        return stringValue(value).replace(/\t/g, ' ').replace(/\r?\n/g, ' ');
    }
    function escapeHtml(value) {
        return exportCell(value)
            .replace(/&/g, '&amp;')
            .replace(/</g, '&lt;')
            .replace(/>/g, '&gt;')
            .replace(/"/g, '&quot;')
            .replace(/'/g, '&#39;');
    }
    function buildPayload(form) {
        var payload = {};
        fieldMeta.forEach(function (field) {
            var value = form[field.field];
            if (field.primaryKey) {
                if (!isEmptyValue(value)) {
                    payload[field.field] = value;
                }
                return;
            }
            if (field.kind === 'foreign' && isEmptyValue(value)) {
                value = null;
            }
            if (field.kind === 'enum' && value === '') {
                value = null;
            }
            if (field.kind === 'checkbox' && isEmptyValue(value)) {
                value = normalizeOptionValue(field, field.checkboxInactiveRaw);
            }
            if (field.valueType === 'number' && !isEmptyValue(value)) {
                value = Number(value);
            }
            if (field.valueType === 'number' && value === '') {
                value = null;
            }
            payload[field.field] = value;
        });
        return payload;
    }
    function fillFormFromRow(row, form, display) {
        fieldMeta.forEach(function (field) {
            if (field.primaryKey) {
                form[field.field] = row[field.field];
                return;
            }
            if (field.kind === 'date') {
                form[field.field] = row[field.tableProp] || row[field.field] || '';
                return;
            }
            if (field.kind === 'foreign') {
                form[field.field] = isEmptyValue(row[field.field]) ? '' : normalizeOptionValue(field, row[field.field]);
                if (display) {
                    display[field.field] = row[field.tableProp] || (isEmptyValue(row[field.field]) ? '' : String(row[field.field]));
                }
                return;
            }
            if (field.kind === 'enum') {
                form[field.field] = isEmptyValue(row[field.field]) ? '' : normalizeOptionValue(field, row[field.field]);
                return;
            }
            if (field.kind === 'checkbox') {
                form[field.field] = isEmptyValue(row[field.field])
                    ? normalizeOptionValue(field, field.checkboxInactiveRaw)
                    : normalizeOptionValue(field, row[field.field]);
                return;
            }
            form[field.field] = isEmptyValue(row[field.field])
                ? ''
                : (field.valueType === 'number' ? String(row[field.field]) : row[field.field]);
        });
    }
    function resolveSearchParam(field) {
        if (field.kind === 'date' && field.columnName) {
            return field.columnName;
        }
        return field.field;
    }
    function createDownloadFile(filename, titles, rows) {
        var html = [
            '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">',
            '<head><meta charset="UTF-8"></head><body><table border="1"><thead><tr>',
            titles.map(function (title) {
                return '<th>' + escapeHtml(title) + '</th>';
            }).join(''),
            '</tr></thead><tbody>',
            (rows || []).map(function (row) {
                return '<tr>' + (row || []).map(function (value) {
                    return '<td style="mso-number-format:\\@;">' + escapeHtml(value) + '</td>';
                }).join('') + '</tr>';
            }).join(''),
            '</tbody></table></body></html>'
        ].join('');
        var blob = new Blob(['\ufeff' + html], {
            type: 'application/vnd.ms-excel;charset=utf-8;'
        });
        var anchor = document.createElement('a');
        anchor.href = URL.createObjectURL(blob);
        anchor.download = filename;
        document.body.appendChild(anchor);
        anchor.click();
        setTimeout(function () {
            URL.revokeObjectURL(anchor.href);
            document.body.removeChild(anchor);
        }, 0);
    }
    function buildTimestamp() {
        var now = new Date();
        var pad = function (num) {
            return num < 10 ? '0' + num : String(num);
        };
        return now.getFullYear()
            + pad(now.getMonth() + 1)
            + pad(now.getDate())
            + '_'
            + pad(now.getHours())
            + pad(now.getMinutes())
            + pad(now.getSeconds());
    }
    function authHeaders() {
        return {
            token: localStorage.getItem('token')
        };
    }
    function handleForbidden(res) {
        if (res && res.code === 403) {
            top.location.href = baseUrl + '/';
            return true;
        }
        return false;
    }
    var sharedMethods = {
        authHeaders: authHeaders,
        handleForbidden: handleForbidden,
        valueOrDash: valueOrDash,
        stringValue: stringValue,
        getTableValue: getTableValue,
        isCheckboxChecked: isCheckboxChecked,
        normalizeOptionValue: normalizeOptionValue,
        isSortableField: isSortableField,
        getSuggestionFetcher: function (field) {
            var self = this;
            return function (queryString, callback) {
                self.fetchForeignSuggestions(field, queryString, callback);
            };
        },
        fetchForeignSuggestions: function (field, queryString, callback) {
            if (!field.foreignQuery || !queryString) {
                callback([]);
                return;
            }
            var self = this;
            $.ajax({
                url: baseUrl+"/basDualCrnpErr/delete/auth",
                headers: {'token': localStorage.getItem('token')},
                data: {ids: ids},
                method: 'POST',
                url: baseUrl + '/' + field.foreignQuery + 'Query/auth',
                method: 'GET',
                headers: self.authHeaders(),
                data: { condition: queryString },
                success: function (res) {
                    layer.close(loadIndex);
                    if (res.code === 200){
                        layer.msg(res.msg, {icon: 1});
                        tableReload();
                    } else if (res.code === 403){
                        top.location.href = baseUrl+"/";
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    if (self.handleForbidden(res)) {
                        return;
                    }
                    if (!res || res.code !== 200 || !Array.isArray(res.data)) {
                        callback([]);
                        return;
                    }
                    callback(res.data.map(function (item) {
                        return {
                            id: item.id,
                            value: item.value
                        };
                    }));
                },
                error: function () {
                    callback([]);
                }
            });
        },
        handleForeignSelect: function (field, item) {
            this.$set(this.displayTarget, field.field, item && item.value ? item.value : '');
            this.$set(this.formTarget, field.field, item && item.id !== undefined ? normalizeOptionValue(field, item.id) : '');
        },
        handleForeignInput: function (field) {
            if (!this.displayTarget || !this.formTarget) {
                return;
            }
            if (this.displayTarget[field.field]) {
                return;
            }
            this.$set(this.formTarget, field.field, '');
        }
    };
    if (document.getElementById('app')) {
        new Vue({
            el: '#app',
            data: function () {
                return {
                    fieldMeta: fieldMeta,
                    primaryKeyField: primaryKeyField,
                    loading: false,
                    exporting: false,
                    tableData: [],
                    selection: [],
                    advancedFiltersVisible: false,
                    allColumns: fieldMeta.slice(),
                    visibleColumnKeys: createDefaultVisibleColumnKeys(),
                    searchForm: createSearchDefaults(),
                    searchDisplay: createSearchDisplayDefaults(),
                    page: {
                        curr: 1,
                        limit: 15,
                        total: 0
                    },
                    sortState: {
                        prop: '',
                        order: ''
                    },
                    dialog: {
                        visible: false,
                        mode: 'create',
                        submitting: false
                    },
                    layoutTimer: null,
                    tableResizeHandler: null,
                    dialogForm: createFormDefaults(),
                    dialogDisplay: createDisplayDefaults(),
                    dialogRules: createFormRules()
                };
            },
            computed: {
                searchableFields: function () {
                    return this.fieldMeta.filter(function (field) {
                        return isSearchableField(field);
                    });
                },
                quickSearchableFields: function () {
                    var result = [];
                    this.searchableFields.forEach(function (field) {
                        if (result.length >= 3 || field.kind === 'date') {
                            return;
                        }
                        result.push(field);
                    });
                    return result;
                },
                advancedSearchableFields: function () {
                    var quickKeys = this.quickSearchableFields.map(function (field) {
                        return field.field;
                    });
                    return this.searchableFields.filter(function (field) {
                        return quickKeys.indexOf(field.field) === -1;
                    });
                },
                hasAdvancedFilters: function () {
                    return this.advancedSearchableFields.length > 0;
                },
                visibleColumns: function () {
                    var keys = this.visibleColumnKeys;
                    return this.allColumns.filter(function (field) {
                        return keys.indexOf(field.field) !== -1;
                    });
                },
                editableFields: function () {
                    return this.fieldMeta.filter(function (field) {
                        return !field.primaryKey;
                    });
                },
                exportColumns: function () {
                    return this.visibleColumns.map(function (field) {
                        return {
                            field: field.exportField || field.tableProp || field.field,
                            label: field.label
                        };
                    });
                },
                tableHeight: function () {
                    return this.advancedFiltersVisible && this.hasAdvancedFilters
                        ? 'calc(100vh - 390px)'
                        : 'calc(100vh - 300px)';
                },
                formTarget: function () {
                    return this.dialogForm;
                },
                displayTarget: function () {
                    return this.dialogDisplay;
                }
            },
            created: function () {
                this.loadTable();
            },
            mounted: function () {
                var self = this;
                self.requestTableLayout(80);
                self.tableResizeHandler = function () {
                    self.requestTableLayout(80);
                };
                window.addEventListener('resize', self.tableResizeHandler);
            },
            beforeDestroy: function () {
                if (this.layoutTimer) {
                    clearTimeout(this.layoutTimer);
                    this.layoutTimer = null;
                }
                if (this.tableResizeHandler) {
                    window.removeEventListener('resize', this.tableResizeHandler);
                    this.tableResizeHandler = null;
                }
            },
            methods: $.extend({}, sharedMethods, {
                requestTableLayout: function (delay) {
                    var self = this;
                    if (self.layoutTimer) {
                        clearTimeout(self.layoutTimer);
                    }
                    self.$nextTick(function () {
                        self.layoutTimer = setTimeout(function () {
                            var table = self.$refs.dataTable;
                            if (table && typeof table.doLayout === 'function') {
                                table.doLayout();
                            }
                        }, delay || 40);
                    });
                },
                isColumnVisible: function (fieldName) {
                    return this.visibleColumnKeys.indexOf(fieldName) !== -1;
                },
                toggleColumn: function (fieldName, visible) {
                    if (visible) {
                        if (this.visibleColumnKeys.indexOf(fieldName) === -1) {
                            this.visibleColumnKeys.push(fieldName);
                        }
                        this.requestTableLayout(80);
                        return;
                    }
                    if (this.visibleColumnKeys.length === 1) {
                        this.$message.warning('至少保留一列');
                        return;
                    }
                    this.visibleColumnKeys = this.visibleColumnKeys.filter(function (item) {
                        return item !== fieldName;
                    });
                    this.requestTableLayout(80);
                },
                selectAllColumns: function () {
                    this.visibleColumnKeys = createDefaultVisibleColumnKeys();
                    this.requestTableLayout(80);
                },
                resetColumns: function () {
                    this.visibleColumnKeys = createDefaultVisibleColumnKeys();
                    this.requestTableLayout(80);
                },
                toggleAdvancedFilters: function () {
                    this.advancedFiltersVisible = !this.advancedFiltersVisible;
                    this.requestTableLayout(260);
                },
                handleSearchForeignSelect: function (field, item) {
                    this.$set(this.searchDisplay, field.field, item && item.value ? item.value : '');
                    this.$set(this.searchForm, field.field, item && item.id !== undefined ? normalizeOptionValue(field, item.id) : '');
                },
                handleSearchForeignInput: function (field) {
                    if (this.searchDisplay[field.field]) {
                        return;
                    }
                    this.$set(this.searchForm, field.field, '');
                },
                buildQueryParams: function () {
                    var self = this;
                    var params = {
                        curr: self.page.curr,
                        limit: self.page.limit
                    };
                    if (self.searchForm.condition) {
                        params.condition = self.searchForm.condition;
                    }
                    self.searchableFields.forEach(function (field) {
                        var value = self.searchForm[field.field];
                        if (field.kind === 'date') {
                            if (value && value.length === 2) {
                                params[resolveSearchParam(field)] = value[0] + ' - ' + value[1];
                            }
                            return;
                        }
                        if (!isEmptyValue(value)) {
                            params[resolveSearchParam(field)] = value;
                        }
                    });
                    if (self.sortState.prop && self.sortState.order) {
                        params.orderByField = self.sortState.prop;
                        params.orderByType = self.sortState.order === 'ascending' ? 'asc' : 'desc';
                    }
                    return params;
                },
                loadTable: function () {
                    var self = this;
                    self.loading = true;
                    $.ajax({
                        url: baseUrl + '/' + simpleEntityName + '/list/auth',
                        method: 'GET',
                        headers: self.authHeaders(),
                        data: self.buildQueryParams(),
                        success: function (res) {
                            self.loading = false;
                            if (self.handleForbidden(res)) {
                                return;
                            }
                            if (!res || res.code !== 200) {
                                self.$message.error((res && res.msg) ? res.msg : '加载失败');
                                return;
                            }
                            var payload = res.data || {};
                            self.tableData = Array.isArray(payload.records) ? payload.records : [];
                            self.page.total = payload.total || 0;
                            self.requestTableLayout(80);
                        },
                        error: function () {
                            self.loading = false;
                            self.requestTableLayout(80);
                            self.$message.error('加载失败');
                        }
                    });
                },
                handleSearch: function () {
                    this.page.curr = 1;
                    this.loadTable();
                },
                handleReset: function () {
                    this.searchForm = createSearchDefaults();
                    this.searchDisplay = createSearchDisplayDefaults();
                    this.advancedFiltersVisible = false;
                    this.page.curr = 1;
                    this.sortState = {
                        prop: '',
                        order: ''
                    };
                    this.loadTable();
                },
                handleSelectionChange: function (rows) {
                    this.selection = rows || [];
                },
                handleSortChange: function (payload) {
                    this.sortState = {
                        prop: payload && payload.prop ? payload.prop : '',
                        order: payload && payload.order ? payload.order : ''
                    };
                    this.page.curr = 1;
                    this.loadTable();
                },
                handleCurrentChange: function (curr) {
                    this.page.curr = curr;
                    this.loadTable();
                },
                handleSizeChange: function (limit) {
                    this.page.limit = limit;
                    this.page.curr = 1;
                    this.loadTable();
                },
                resetDialogState: function () {
                    this.dialogForm = createFormDefaults();
                    this.dialogDisplay = createDisplayDefaults();
                    if (this.$refs.dialogForm) {
                        this.$refs.dialogForm.clearValidate();
                    }
                },
                openCreateDialog: function () {
                    this.dialog.mode = 'create';
                    this.dialog.visible = true;
                    this.$nextTick(this.resetDialogState);
                },
                openEditDialog: function (row) {
                    var self = this;
                    self.dialog.mode = 'edit';
                    self.dialog.visible = true;
                    self.$nextTick(function () {
                        self.resetDialogState();
                        fillFormFromRow(row, self.dialogForm, self.dialogDisplay);
                        if (self.$refs.dialogForm) {
                            self.$refs.dialogForm.clearValidate();
                        }
                    });
                },
                submitDialog: function () {
                    var self = this;
                    if (!self.$refs.dialogForm) {
                        return;
                    }
                    self.$refs.dialogForm.validate(function (valid) {
                        if (!valid) {
                            return false;
                        }
                        self.dialog.submitting = true;
                        $.ajax({
                            url: baseUrl + '/' + simpleEntityName + '/' + (self.dialog.mode === 'create' ? 'add' : 'update') + '/auth',
                            method: 'POST',
                            headers: self.authHeaders(),
                            data: buildPayload(self.dialogForm),
                            success: function (res) {
                                self.dialog.submitting = false;
                                if (self.handleForbidden(res)) {
                                    return;
                                }
                                if (!res || res.code !== 200) {
                                    self.$message.error((res && res.msg) ? res.msg : '保存失败');
                                    return;
                                }
                                self.$message.success(res.msg || '保存成功');
                                self.dialog.visible = false;
                                self.loadTable();
                            },
                            error: function () {
                                self.dialog.submitting = false;
                                self.$message.error('保存失败');
                            }
                        });
                        return true;
                    });
                },
                removeSelection: function () {
                    var self = this;
                    var ids = self.selection.map(function (row) {
                        return row[self.primaryKeyField];
                    });
                    self.removeRows(ids);
                },
                removeRows: function (ids) {
                    var self = this;
                    if (!ids || ids.length === 0) {
                        self.$message.warning('请选择要删除的数据');
                        return;
                    }
                    self.$confirm('确定删除选中的记录吗?', '提示', { type: 'warning' }).then(function () {
                        $.ajax({
                            url: baseUrl + '/' + simpleEntityName + '/delete/auth',
                            method: 'POST',
                            headers: self.authHeaders(),
                            traditional: true,
                            data: { 'ids[]': ids },
                            success: function (res) {
                                if (self.handleForbidden(res)) {
                                    return;
                                }
                                if (!res || res.code !== 200) {
                                    self.$message.error((res && res.msg) ? res.msg : '删除失败');
                                    return;
                                }
                                self.$message.success(res.msg || '删除成功');
                                self.selection = [];
                                if (self.tableData.length === ids.length && self.page.curr > 1) {
                                    self.page.curr = self.page.curr - 1;
                                }
                                self.loadTable();
                            },
                            error: function () {
                                self.$message.error('删除失败');
                            }
                        });
                    }).catch(function () {});
                },
                exportRows: function () {
                    var self = this;
                    self.exporting = true;
                    var requestBody = {
                        fields: self.exportColumns.map(function (item) {
                            return item.field;
                        })
                    };
                    requestBody[simpleEntityName] = self.buildQueryParams();
                    $.ajax({
                        url: baseUrl + '/' + simpleEntityName + '/export/auth',
                        method: 'POST',
                        headers: $.extend({ 'Content-Type': 'application/json;charset=UTF-8' }, self.authHeaders()),
                        data: JSON.stringify(requestBody),
                        success: function (res) {
                            self.exporting = false;
                            if (self.handleForbidden(res)) {
                                return;
                            }
                            if (!res || res.code !== 200) {
                                self.$message.error((res && res.msg) ? res.msg : '导出失败');
                                return;
                            }
                            createDownloadFile(
                                simpleEntityName + '_' + buildTimestamp() + '.xls',
                                self.exportColumns.map(function (item) {
                                    return item.label;
                                }),
                                Array.isArray(res.data) ? res.data : []
                            );
                            self.$message.success('导出成功');
                        },
                        error: function () {
                            self.exporting = false;
                            self.$message.error('导出失败');
                        }
                    });
                }
            })
        });
    }
    // 搜索
    form.on('submit(search)', function (data) {
        pageCurr = 1;
        tableReload(false);
    });
    // 重置
    form.on('submit(reset)', function (data) {
        pageCurr = 1;
        clearFormVal($('#search-box'));
        tableReload(false);
    });
    // 时间选择器
    function layDateRender(data) {
        setTimeout(function () {
            layDate.render({
                elem: '.layui-laydate-range'
                ,type: 'datetime'
                ,range: true
            });
            layDate.render({
                elem: '#modiTime\\$',
                type: 'datetime',
                value: data!==undefined?data['modiTime\\$']:null
            });
            layDate.render({
                elem: '#appeTime\\$',
                type: 'datetime',
                value: data!==undefined?data['appeTime\\$']:null
            });
        }, 300);
    }
    layDateRender();
});
// 关闭动作
$(document).on('click','#data-detail-close', function () {
    parent.layer.closeAll();
});
function tableReload(child) {
    var searchData = {};
    $.each($('#search-box [name]').serializeArray(), function() {
        searchData[this.name] = this.value;
    });
    tableIns.reload({
        where: searchData,
        page: {curr: pageCurr}
     });
}
})();
src/main/webapp/static/js/basDualCrnpErrLog/basDualCrnpErrLog.js
@@ -1,285 +1,1165 @@
var pageCurr;
layui.config({
    base: baseUrl + "/static/layui/lay/modules/"
}).use(['table','laydate', 'form', 'admin'], function(){
    var table = layui.table;
    var $ = layui.jquery;
    var layer = layui.layer;
    var layDate = layui.laydate;
    var form = layui.form;
    var admin = layui.admin;
(function () {
    var simpleEntityName = 'basDualCrnpErrLog';
    var entityName = 'BasDualCrnpErrLog';
    var primaryKeyField = 'id';
    var fieldMeta = dedupeFieldMeta([
    {
        field: 'id',
        columnName: 'id',
        label: '编  号',
        tableProp: 'id',
        exportField: 'id',
        kind: 'text',
        valueType: 'number',
        required: true,
        primaryKey: true,
        sortable: true,
        textarea: false,
        minWidth: 90,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'wrkNo',
        columnName: 'wrk_no',
        label: '工 作 号',
        tableProp: 'wrkNo',
        exportField: 'wrkNo',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 116,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'startTime',
        columnName: 'start_time',
        label: '发生时间',
        tableProp: 'startTime$',
        exportField: 'startTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'endTime',
        columnName: 'end_time',
        label: '结束时间',
        tableProp: 'endTime$',
        exportField: 'endTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'wrkSts',
        columnName: 'wrk_sts',
        label: '工作状态',
        tableProp: 'wrkSts$',
        exportField: 'wrkSts$',
        kind: 'foreign',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: 'basWrkStatus',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'ioType',
        columnName: 'io_type',
        label: '入出库类型',
        tableProp: 'ioType$',
        exportField: 'ioType$',
        kind: 'foreign',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 116,
        enumOptions: [],
        foreignQuery: 'basWrkIotype',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'crnNo',
        columnName: 'crn_no',
        label: '堆垛机号',
        tableProp: 'crnNo',
        exportField: 'crnNo',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'locNo',
        columnName: 'loc_no',
        label: '目标库位',
        tableProp: 'locNo',
        exportField: 'locNo',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'staNo',
        columnName: 'sta_no',
        label: '目 标 站',
        tableProp: 'staNo',
        exportField: 'staNo',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 116,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'sourceStaNo',
        columnName: 'source_sta_no',
        label: '源  站',
        tableProp: 'sourceStaNo',
        exportField: 'sourceStaNo',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'sourceLocNo',
        columnName: 'source_loc_no',
        label: '源 库 位',
        tableProp: 'sourceLocNo',
        exportField: 'sourceLocNo',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 116,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'barcode',
        columnName: 'barcode',
        label: '条  码',
        tableProp: 'barcode',
        exportField: 'barcode',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'errCode',
        columnName: 'err_code',
        label: '异 常 码',
        tableProp: 'errCode',
        exportField: 'errCode',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 116,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'error',
        columnName: 'error',
        label: '异  常',
        tableProp: 'error',
        exportField: 'error',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'status',
        columnName: 'status',
        label: '异常情况',
        tableProp: 'status$',
        exportField: 'status$',
        kind: 'enum',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 120,
        enumOptions: [{ rawValue: '1', label: '未处理' }, { rawValue: '2', label: '已修复' }],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'createTime',
        columnName: 'create_time',
        label: '添加时间',
        tableProp: 'createTime$',
        exportField: 'createTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'createBy',
        columnName: 'create_by',
        label: '添加人员',
        tableProp: 'createBy$',
        exportField: 'createBy$',
        kind: 'foreign',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: 'user',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'updateTime',
        columnName: 'update_time',
        label: '修改时间',
        tableProp: 'updateTime$',
        exportField: 'updateTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'updateBy',
        columnName: 'update_by',
        label: '修改人员',
        tableProp: 'updateBy$',
        exportField: 'updateBy$',
        kind: 'foreign',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: 'user',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'memo',
        columnName: 'memo',
        label: '备  注',
        tableProp: 'memo',
        exportField: 'memo',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: true,
        minWidth: 180,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'systemStatus',
        columnName: 'system_status',
        label: '系统状态数据',
        tableProp: 'systemStatus',
        exportField: 'systemStatus',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 134,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    }
    // 数据渲染
    tableIns = table.render({
        elem: '#basDualCrnpErrLog',
        headers: {token: localStorage.getItem('token')},
        url: baseUrl+'/basDualCrnpErrLog/list/auth',
        page: true,
        limit: 15,
        limits: [15, 30, 50, 100, 200, 500],
        toolbar: '#toolbar',
        cellMinWidth: 50,
        height: 'full-120',
        cols: [[
            {type: 'checkbox'}
            ,{field: 'id', align: 'center',title: '编号'}
            ,{field: 'wrkNo', align: 'center',title: '工作号'}
            ,{field: 'startTime$', align: 'center',title: '发生时间'}
            ,{field: 'endTime$', align: 'center',title: '结束时间'}
            ,{field: 'wrkSts$', align: 'center',title: '工作状态'}
            ,{field: 'ioType$', align: 'center',title: '入出库类型'}
            ,{field: 'crnNo', align: 'center',title: '堆垛机号'}
            ,{field: 'locNo', align: 'center',title: '目标库位'}
            ,{field: 'staNo', align: 'center',title: '目标站'}
            ,{field: 'sourceStaNo', align: 'center',title: '源站'}
            ,{field: 'sourceLocNo', align: 'center',title: '源库位'}
            ,{field: 'barcode', align: 'center',title: '条码'}
            ,{field: 'errCode', align: 'center',title: '异常码'}
            ,{field: 'error', align: 'center',title: '异常'}
            ,{field: 'status$', align: 'center',title: '异常情况'}
            ,{field: 'createTime$', align: 'center',title: '添加时间'}
            ,{field: 'createBy$', align: 'center',title: '添加人员'}
            ,{field: 'updateTime$', align: 'center',title: '修改时间'}
            ,{field: 'updateBy$', align: 'center',title: '修改人员'}
            ,{field: 'memo', align: 'center',title: '备注'}
            ,{field: 'systemStatus', align: 'center',title: '系统状态数据'}
    ]);
            ,{fixed: 'right', title:'操作', align: 'center', toolbar: '#operate', width:120}
        ]],
        request: {
            pageName: 'curr',
            pageSize: 'limit'
        },
        parseData: function (res) {
            return {
                'code': res.code,
                'msg': res.msg,
                'count': res.data.total,
                'data': res.data.records
            }
        },
        response: {
            statusCode: 200
        },
        done: function(res, curr, count) {
            if (res.code === 403) {
                top.location.href = baseUrl+"/";
            }
            pageCurr=curr;
            limit();
    function formatFieldLabel(field) {
        var raw = field && field.label ? String(field.label).trim() : '';
        if (raw) {
            return raw;
        }
    });
    // 监听排序事件
    table.on('sort(basDualCrnpErrLog)', function (obj) {
        var searchData = {};
        $.each($('#search-box [name]').serializeArray(), function() {
            searchData[this.name] = this.value;
        });
        searchData['orderByField'] = obj.field;
        searchData['orderByType'] = obj.type;
        tableIns.reload({
            where: searchData,
            page: {curr: 1}
        });
    });
    // 监听头工具栏事件
    table.on('toolbar(basDualCrnpErrLog)', function (obj) {
        var checkStatus = table.checkStatus(obj.config.id).data;
        switch(obj.event) {
            case 'addData':
                showEditModel();
                break;
            case 'deleteData':
               if (checkStatus.length === 0) {
                   layer.msg('请选择要删除的数据', {icon: 2});
                   return;
               }
               del(checkStatus.map(function (d) {
                   return d.id;
               }));
               break;
            case 'exportData':
                admin.confirm('确定导出Excel吗', {shadeClose: true}, function(){
                    var titles=[];
                    var fields=[];
                    obj.config.cols[0].map(function (col) {
                        if (col.type === 'normal' && col.hide === false && col.toolbar == null) {
                            titles.push(col.title);
                            fields.push(col.field);
                        }
                    });
                    var exportData = {};
                    $.each($('#search-box [name]').serializeArray(), function() {
                        exportData[this.name] = this.value;
                    });
                    var param = {
                        'basDualCrnpErrLog': exportData,
                        'fields': fields
                    };
                    $.ajax({
                        url: baseUrl+"/basDualCrnpErrLog/export/auth",
                        headers: {'token': localStorage.getItem('token')},
                        data: JSON.stringify(param),
                        dataType:'json',
                        contentType:'application/json;charset=UTF-8',
                        method: 'POST',
                        success: function (res) {
                            layer.closeAll();
                            if (res.code === 200) {
                                table.exportFile(titles,res.data,'xls');
                            } else if (res.code === 403) {
                                top.location.href = baseUrl+"/";
                            } else {
                                layer.msg(res.msg, {icon: 2})
                            }
                        }
                    });
                });
                break;
        raw = field && field.columnName ? field.columnName : (field && field.field ? field.field : '');
        if (!raw) {
            return '';
        }
    });
    // 监听行工具事件
    table.on('tool(basDualCrnpErrLog)', function(obj){
        var data = obj.data;
        switch (obj.event) {
            case 'edit':
                showEditModel(data);
                break;
            case "del":
                del([data.id]);
                break;
        }
    });
    /* 弹窗 - 新增、修改 */
    function showEditModel(mData) {
        admin.open({
            type: 1,
            area: '600px',
            title: (mData ? '修改' : '添加') + '订单状态',
            content: $('#editDialog').html(),
            success: function (layero, dIndex) {
                layDateRender(mData);
                form.val('detail', mData);
                form.on('submit(editSubmit)', function (data) {
                    var loadIndex = layer.load(2);
                    $.ajax({
                        url: baseUrl+"/basDualCrnpErrLog/"+(mData?'update':'add')+"/auth",
                        headers: {'token': localStorage.getItem('token')},
                        data: data.field,
                        method: 'POST',
                        success: function (res) {
                            layer.close(loadIndex);
                            if (res.code === 200){
                                layer.close(dIndex);
                                layer.msg(res.msg, {icon: 1});
                                tableReload();
                            } else if (res.code === 403){
                                top.location.href = baseUrl+"/";
                            }else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }
                    })
                    return false;
                });
                $(layero).children('.layui-layer-content').css('overflow', 'visible');
                layui.form.render('select');
            }
        raw = String(raw)
            .replace(/\$/g, '')
            .replace(/([a-z0-9])([A-Z])/g, '$1_$2')
            .replace(/_/g, ' ')
            .replace(/\s+/g, ' ')
            .trim();
        return raw.replace(/\b[a-z]/g, function (letter) {
            return letter.toUpperCase();
        });
    }
    /* 删除 */
    function del(ids) {
        layer.confirm('确定要删除选中数据吗?', {
            skin: 'layui-layer-admin',
            shade: .1
        }, function (i) {
            layer.close(i);
            var loadIndex = layer.load(2);
    function dedupeFieldMeta(list) {
        var result = [];
        var seen = {};
        (list || []).forEach(function (field) {
            if (!field || !field.field || seen[field.field]) {
                return;
            }
            field.label = formatFieldLabel(field);
            seen[field.field] = true;
            result.push(field);
        });
        return result;
    }
    function isEmptyValue(value) {
        return value === null || value === undefined || value === '';
    }
    function stringValue(value) {
        return isEmptyValue(value) ? '' : String(value);
    }
    function valueOrDash(value) {
        return isEmptyValue(value) ? '--' : value;
    }
    function normalizeOptionValue(field, rawValue) {
        if (rawValue === null || rawValue === undefined) {
            return null;
        }
        if (rawValue === '') {
            return '';
        }
        if (field && field.valueType === 'number') {
            var numberVal = Number(rawValue);
            return isNaN(numberVal) ? rawValue : numberVal;
        }
        return String(rawValue);
    }
    function isSearchableField(field) {
        return !!field && field.kind !== 'image' && !field.textarea;
    }
    function isSortableField(field) {
        if (!field) {
            return false;
        }
        if (field.primaryKey) {
            return true;
        }
        return field.kind !== 'image' && !field.textarea && field.kind !== 'foreign';
    }
    function defaultFieldValue(field) {
        if (field.primaryKey) {
            return null;
        }
        if (field.kind === 'checkbox') {
            return normalizeOptionValue(field, field.checkboxInactiveRaw);
        }
        return '';
    }
    function defaultSearchFieldValue(field) {
        if (field.kind === 'date') {
            return [];
        }
        if (field.kind === 'enum' || field.kind === 'checkbox') {
            return null;
        }
        return '';
    }
    function createSearchDefaults() {
        var result = {
            condition: ''
        };
        fieldMeta.forEach(function (field) {
            if (!isSearchableField(field)) {
                return;
            }
            result[field.field] = defaultSearchFieldValue(field);
        });
        return result;
    }
    function createSearchDisplayDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            if (field.kind === 'foreign' && isSearchableField(field)) {
                result[field.field] = '';
            }
        });
        return result;
    }
    function createDefaultVisibleColumnKeys() {
        return fieldMeta.map(function (field) {
            return field.field;
        });
    }
    function createFormDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            result[field.field] = defaultFieldValue(field);
        });
        return result;
    }
    function createDisplayDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            if (field.kind === 'foreign') {
                result[field.field] = '';
            }
        });
        return result;
    }
    function createFormRules() {
        var rules = {};
        fieldMeta.forEach(function (field) {
            if (field.primaryKey || !field.required) {
                return;
            }
            rules[field.field] = [{
                required: true,
                message: (field.kind === 'date' || field.kind === 'enum' ? '请选择' : '请输入') + field.label,
                trigger: (field.kind === 'date' || field.kind === 'enum') ? 'change' : 'blur'
            }];
        });
        return rules;
    }
    function getTableValue(row, field) {
        var prop = field.tableProp || field.field;
        if (row && !isEmptyValue(row[prop])) {
            return row[prop];
        }
        return row ? row[field.field] : '';
    }
    function isCheckboxChecked(row, field) {
        var value = row ? row[field.field] : null;
        var activeValue = normalizeOptionValue(field, field.checkboxActiveRaw);
        return String(value) === String(activeValue);
    }
    function exportCell(value) {
        return stringValue(value).replace(/\t/g, ' ').replace(/\r?\n/g, ' ');
    }
    function escapeHtml(value) {
        return exportCell(value)
            .replace(/&/g, '&amp;')
            .replace(/</g, '&lt;')
            .replace(/>/g, '&gt;')
            .replace(/"/g, '&quot;')
            .replace(/'/g, '&#39;');
    }
    function buildPayload(form) {
        var payload = {};
        fieldMeta.forEach(function (field) {
            var value = form[field.field];
            if (field.primaryKey) {
                if (!isEmptyValue(value)) {
                    payload[field.field] = value;
                }
                return;
            }
            if (field.kind === 'foreign' && isEmptyValue(value)) {
                value = null;
            }
            if (field.kind === 'enum' && value === '') {
                value = null;
            }
            if (field.kind === 'checkbox' && isEmptyValue(value)) {
                value = normalizeOptionValue(field, field.checkboxInactiveRaw);
            }
            if (field.valueType === 'number' && !isEmptyValue(value)) {
                value = Number(value);
            }
            if (field.valueType === 'number' && value === '') {
                value = null;
            }
            payload[field.field] = value;
        });
        return payload;
    }
    function fillFormFromRow(row, form, display) {
        fieldMeta.forEach(function (field) {
            if (field.primaryKey) {
                form[field.field] = row[field.field];
                return;
            }
            if (field.kind === 'date') {
                form[field.field] = row[field.tableProp] || row[field.field] || '';
                return;
            }
            if (field.kind === 'foreign') {
                form[field.field] = isEmptyValue(row[field.field]) ? '' : normalizeOptionValue(field, row[field.field]);
                if (display) {
                    display[field.field] = row[field.tableProp] || (isEmptyValue(row[field.field]) ? '' : String(row[field.field]));
                }
                return;
            }
            if (field.kind === 'enum') {
                form[field.field] = isEmptyValue(row[field.field]) ? '' : normalizeOptionValue(field, row[field.field]);
                return;
            }
            if (field.kind === 'checkbox') {
                form[field.field] = isEmptyValue(row[field.field])
                    ? normalizeOptionValue(field, field.checkboxInactiveRaw)
                    : normalizeOptionValue(field, row[field.field]);
                return;
            }
            form[field.field] = isEmptyValue(row[field.field])
                ? ''
                : (field.valueType === 'number' ? String(row[field.field]) : row[field.field]);
        });
    }
    function resolveSearchParam(field) {
        if (field.kind === 'date' && field.columnName) {
            return field.columnName;
        }
        return field.field;
    }
    function createDownloadFile(filename, titles, rows) {
        var html = [
            '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">',
            '<head><meta charset="UTF-8"></head><body><table border="1"><thead><tr>',
            titles.map(function (title) {
                return '<th>' + escapeHtml(title) + '</th>';
            }).join(''),
            '</tr></thead><tbody>',
            (rows || []).map(function (row) {
                return '<tr>' + (row || []).map(function (value) {
                    return '<td style="mso-number-format:\\@;">' + escapeHtml(value) + '</td>';
                }).join('') + '</tr>';
            }).join(''),
            '</tbody></table></body></html>'
        ].join('');
        var blob = new Blob(['\ufeff' + html], {
            type: 'application/vnd.ms-excel;charset=utf-8;'
        });
        var anchor = document.createElement('a');
        anchor.href = URL.createObjectURL(blob);
        anchor.download = filename;
        document.body.appendChild(anchor);
        anchor.click();
        setTimeout(function () {
            URL.revokeObjectURL(anchor.href);
            document.body.removeChild(anchor);
        }, 0);
    }
    function buildTimestamp() {
        var now = new Date();
        var pad = function (num) {
            return num < 10 ? '0' + num : String(num);
        };
        return now.getFullYear()
            + pad(now.getMonth() + 1)
            + pad(now.getDate())
            + '_'
            + pad(now.getHours())
            + pad(now.getMinutes())
            + pad(now.getSeconds());
    }
    function authHeaders() {
        return {
            token: localStorage.getItem('token')
        };
    }
    function handleForbidden(res) {
        if (res && res.code === 403) {
            top.location.href = baseUrl + '/';
            return true;
        }
        return false;
    }
    var sharedMethods = {
        authHeaders: authHeaders,
        handleForbidden: handleForbidden,
        valueOrDash: valueOrDash,
        stringValue: stringValue,
        getTableValue: getTableValue,
        isCheckboxChecked: isCheckboxChecked,
        normalizeOptionValue: normalizeOptionValue,
        isSortableField: isSortableField,
        getSuggestionFetcher: function (field) {
            var self = this;
            return function (queryString, callback) {
                self.fetchForeignSuggestions(field, queryString, callback);
            };
        },
        fetchForeignSuggestions: function (field, queryString, callback) {
            if (!field.foreignQuery || !queryString) {
                callback([]);
                return;
            }
            var self = this;
            $.ajax({
                url: baseUrl+"/basDualCrnpErrLog/delete/auth",
                headers: {'token': localStorage.getItem('token')},
                data: {ids: ids},
                method: 'POST',
                url: baseUrl + '/' + field.foreignQuery + 'Query/auth',
                method: 'GET',
                headers: self.authHeaders(),
                data: { condition: queryString },
                success: function (res) {
                    layer.close(loadIndex);
                    if (res.code === 200){
                        layer.msg(res.msg, {icon: 1});
                        tableReload();
                    } else if (res.code === 403){
                        top.location.href = baseUrl+"/";
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    if (self.handleForbidden(res)) {
                        return;
                    }
                    if (!res || res.code !== 200 || !Array.isArray(res.data)) {
                        callback([]);
                        return;
                    }
                    callback(res.data.map(function (item) {
                        return {
                            id: item.id,
                            value: item.value
                        };
                    }));
                },
                error: function () {
                    callback([]);
                }
            });
        },
        handleForeignSelect: function (field, item) {
            this.$set(this.displayTarget, field.field, item && item.value ? item.value : '');
            this.$set(this.formTarget, field.field, item && item.id !== undefined ? normalizeOptionValue(field, item.id) : '');
        },
        handleForeignInput: function (field) {
            if (!this.displayTarget || !this.formTarget) {
                return;
            }
            if (this.displayTarget[field.field]) {
                return;
            }
            this.$set(this.formTarget, field.field, '');
        }
    };
    if (document.getElementById('app')) {
        new Vue({
            el: '#app',
            data: function () {
                return {
                    fieldMeta: fieldMeta,
                    primaryKeyField: primaryKeyField,
                    loading: false,
                    exporting: false,
                    tableData: [],
                    selection: [],
                    advancedFiltersVisible: false,
                    allColumns: fieldMeta.slice(),
                    visibleColumnKeys: createDefaultVisibleColumnKeys(),
                    searchForm: createSearchDefaults(),
                    searchDisplay: createSearchDisplayDefaults(),
                    page: {
                        curr: 1,
                        limit: 15,
                        total: 0
                    },
                    sortState: {
                        prop: '',
                        order: ''
                    },
                    dialog: {
                        visible: false,
                        mode: 'create',
                        submitting: false
                    },
                    layoutTimer: null,
                    tableResizeHandler: null,
                    dialogForm: createFormDefaults(),
                    dialogDisplay: createDisplayDefaults(),
                    dialogRules: createFormRules()
                };
            },
            computed: {
                searchableFields: function () {
                    return this.fieldMeta.filter(function (field) {
                        return isSearchableField(field);
                    });
                },
                quickSearchableFields: function () {
                    var result = [];
                    this.searchableFields.forEach(function (field) {
                        if (result.length >= 3 || field.kind === 'date') {
                            return;
                        }
                        result.push(field);
                    });
                    return result;
                },
                advancedSearchableFields: function () {
                    var quickKeys = this.quickSearchableFields.map(function (field) {
                        return field.field;
                    });
                    return this.searchableFields.filter(function (field) {
                        return quickKeys.indexOf(field.field) === -1;
                    });
                },
                hasAdvancedFilters: function () {
                    return this.advancedSearchableFields.length > 0;
                },
                visibleColumns: function () {
                    var keys = this.visibleColumnKeys;
                    return this.allColumns.filter(function (field) {
                        return keys.indexOf(field.field) !== -1;
                    });
                },
                editableFields: function () {
                    return this.fieldMeta.filter(function (field) {
                        return !field.primaryKey;
                    });
                },
                exportColumns: function () {
                    return this.visibleColumns.map(function (field) {
                        return {
                            field: field.exportField || field.tableProp || field.field,
                            label: field.label
                        };
                    });
                },
                tableHeight: function () {
                    return this.advancedFiltersVisible && this.hasAdvancedFilters
                        ? 'calc(100vh - 390px)'
                        : 'calc(100vh - 300px)';
                },
                formTarget: function () {
                    return this.dialogForm;
                },
                displayTarget: function () {
                    return this.dialogDisplay;
                }
            },
            created: function () {
                this.loadTable();
            },
            mounted: function () {
                var self = this;
                self.requestTableLayout(80);
                self.tableResizeHandler = function () {
                    self.requestTableLayout(80);
                };
                window.addEventListener('resize', self.tableResizeHandler);
            },
            beforeDestroy: function () {
                if (this.layoutTimer) {
                    clearTimeout(this.layoutTimer);
                    this.layoutTimer = null;
                }
                if (this.tableResizeHandler) {
                    window.removeEventListener('resize', this.tableResizeHandler);
                    this.tableResizeHandler = null;
                }
            },
            methods: $.extend({}, sharedMethods, {
                requestTableLayout: function (delay) {
                    var self = this;
                    if (self.layoutTimer) {
                        clearTimeout(self.layoutTimer);
                    }
                    self.$nextTick(function () {
                        self.layoutTimer = setTimeout(function () {
                            var table = self.$refs.dataTable;
                            if (table && typeof table.doLayout === 'function') {
                                table.doLayout();
                            }
                        }, delay || 40);
                    });
                },
                isColumnVisible: function (fieldName) {
                    return this.visibleColumnKeys.indexOf(fieldName) !== -1;
                },
                toggleColumn: function (fieldName, visible) {
                    if (visible) {
                        if (this.visibleColumnKeys.indexOf(fieldName) === -1) {
                            this.visibleColumnKeys.push(fieldName);
                        }
                        this.requestTableLayout(80);
                        return;
                    }
                    if (this.visibleColumnKeys.length === 1) {
                        this.$message.warning('至少保留一列');
                        return;
                    }
                    this.visibleColumnKeys = this.visibleColumnKeys.filter(function (item) {
                        return item !== fieldName;
                    });
                    this.requestTableLayout(80);
                },
                selectAllColumns: function () {
                    this.visibleColumnKeys = createDefaultVisibleColumnKeys();
                    this.requestTableLayout(80);
                },
                resetColumns: function () {
                    this.visibleColumnKeys = createDefaultVisibleColumnKeys();
                    this.requestTableLayout(80);
                },
                toggleAdvancedFilters: function () {
                    this.advancedFiltersVisible = !this.advancedFiltersVisible;
                    this.requestTableLayout(260);
                },
                handleSearchForeignSelect: function (field, item) {
                    this.$set(this.searchDisplay, field.field, item && item.value ? item.value : '');
                    this.$set(this.searchForm, field.field, item && item.id !== undefined ? normalizeOptionValue(field, item.id) : '');
                },
                handleSearchForeignInput: function (field) {
                    if (this.searchDisplay[field.field]) {
                        return;
                    }
                    this.$set(this.searchForm, field.field, '');
                },
                buildQueryParams: function () {
                    var self = this;
                    var params = {
                        curr: self.page.curr,
                        limit: self.page.limit
                    };
                    if (self.searchForm.condition) {
                        params.condition = self.searchForm.condition;
                    }
                    self.searchableFields.forEach(function (field) {
                        var value = self.searchForm[field.field];
                        if (field.kind === 'date') {
                            if (value && value.length === 2) {
                                params[resolveSearchParam(field)] = value[0] + ' - ' + value[1];
                            }
                            return;
                        }
                        if (!isEmptyValue(value)) {
                            params[resolveSearchParam(field)] = value;
                        }
                    });
                    if (self.sortState.prop && self.sortState.order) {
                        params.orderByField = self.sortState.prop;
                        params.orderByType = self.sortState.order === 'ascending' ? 'asc' : 'desc';
                    }
                    return params;
                },
                loadTable: function () {
                    var self = this;
                    self.loading = true;
                    $.ajax({
                        url: baseUrl + '/' + simpleEntityName + '/list/auth',
                        method: 'GET',
                        headers: self.authHeaders(),
                        data: self.buildQueryParams(),
                        success: function (res) {
                            self.loading = false;
                            if (self.handleForbidden(res)) {
                                return;
                            }
                            if (!res || res.code !== 200) {
                                self.$message.error((res && res.msg) ? res.msg : '加载失败');
                                return;
                            }
                            var payload = res.data || {};
                            self.tableData = Array.isArray(payload.records) ? payload.records : [];
                            self.page.total = payload.total || 0;
                            self.requestTableLayout(80);
                        },
                        error: function () {
                            self.loading = false;
                            self.requestTableLayout(80);
                            self.$message.error('加载失败');
                        }
                    });
                },
                handleSearch: function () {
                    this.page.curr = 1;
                    this.loadTable();
                },
                handleReset: function () {
                    this.searchForm = createSearchDefaults();
                    this.searchDisplay = createSearchDisplayDefaults();
                    this.advancedFiltersVisible = false;
                    this.page.curr = 1;
                    this.sortState = {
                        prop: '',
                        order: ''
                    };
                    this.loadTable();
                },
                handleSelectionChange: function (rows) {
                    this.selection = rows || [];
                },
                handleSortChange: function (payload) {
                    this.sortState = {
                        prop: payload && payload.prop ? payload.prop : '',
                        order: payload && payload.order ? payload.order : ''
                    };
                    this.page.curr = 1;
                    this.loadTable();
                },
                handleCurrentChange: function (curr) {
                    this.page.curr = curr;
                    this.loadTable();
                },
                handleSizeChange: function (limit) {
                    this.page.limit = limit;
                    this.page.curr = 1;
                    this.loadTable();
                },
                resetDialogState: function () {
                    this.dialogForm = createFormDefaults();
                    this.dialogDisplay = createDisplayDefaults();
                    if (this.$refs.dialogForm) {
                        this.$refs.dialogForm.clearValidate();
                    }
                },
                openCreateDialog: function () {
                    this.dialog.mode = 'create';
                    this.dialog.visible = true;
                    this.$nextTick(this.resetDialogState);
                },
                openEditDialog: function (row) {
                    var self = this;
                    self.dialog.mode = 'edit';
                    self.dialog.visible = true;
                    self.$nextTick(function () {
                        self.resetDialogState();
                        fillFormFromRow(row, self.dialogForm, self.dialogDisplay);
                        if (self.$refs.dialogForm) {
                            self.$refs.dialogForm.clearValidate();
                        }
                    });
                },
                submitDialog: function () {
                    var self = this;
                    if (!self.$refs.dialogForm) {
                        return;
                    }
                    self.$refs.dialogForm.validate(function (valid) {
                        if (!valid) {
                            return false;
                        }
                        self.dialog.submitting = true;
                        $.ajax({
                            url: baseUrl + '/' + simpleEntityName + '/' + (self.dialog.mode === 'create' ? 'add' : 'update') + '/auth',
                            method: 'POST',
                            headers: self.authHeaders(),
                            data: buildPayload(self.dialogForm),
                            success: function (res) {
                                self.dialog.submitting = false;
                                if (self.handleForbidden(res)) {
                                    return;
                                }
                                if (!res || res.code !== 200) {
                                    self.$message.error((res && res.msg) ? res.msg : '保存失败');
                                    return;
                                }
                                self.$message.success(res.msg || '保存成功');
                                self.dialog.visible = false;
                                self.loadTable();
                            },
                            error: function () {
                                self.dialog.submitting = false;
                                self.$message.error('保存失败');
                            }
                        });
                        return true;
                    });
                },
                removeSelection: function () {
                    var self = this;
                    var ids = self.selection.map(function (row) {
                        return row[self.primaryKeyField];
                    });
                    self.removeRows(ids);
                },
                removeRows: function (ids) {
                    var self = this;
                    if (!ids || ids.length === 0) {
                        self.$message.warning('请选择要删除的数据');
                        return;
                    }
                    self.$confirm('确定删除选中的记录吗?', '提示', { type: 'warning' }).then(function () {
                        $.ajax({
                            url: baseUrl + '/' + simpleEntityName + '/delete/auth',
                            method: 'POST',
                            headers: self.authHeaders(),
                            traditional: true,
                            data: { 'ids[]': ids },
                            success: function (res) {
                                if (self.handleForbidden(res)) {
                                    return;
                                }
                                if (!res || res.code !== 200) {
                                    self.$message.error((res && res.msg) ? res.msg : '删除失败');
                                    return;
                                }
                                self.$message.success(res.msg || '删除成功');
                                self.selection = [];
                                if (self.tableData.length === ids.length && self.page.curr > 1) {
                                    self.page.curr = self.page.curr - 1;
                                }
                                self.loadTable();
                            },
                            error: function () {
                                self.$message.error('删除失败');
                            }
                        });
                    }).catch(function () {});
                },
                exportRows: function () {
                    var self = this;
                    self.exporting = true;
                    var requestBody = {
                        fields: self.exportColumns.map(function (item) {
                            return item.field;
                        })
                    };
                    requestBody[simpleEntityName] = self.buildQueryParams();
                    $.ajax({
                        url: baseUrl + '/' + simpleEntityName + '/export/auth',
                        method: 'POST',
                        headers: $.extend({ 'Content-Type': 'application/json;charset=UTF-8' }, self.authHeaders()),
                        data: JSON.stringify(requestBody),
                        success: function (res) {
                            self.exporting = false;
                            if (self.handleForbidden(res)) {
                                return;
                            }
                            if (!res || res.code !== 200) {
                                self.$message.error((res && res.msg) ? res.msg : '导出失败');
                                return;
                            }
                            createDownloadFile(
                                simpleEntityName + '_' + buildTimestamp() + '.xls',
                                self.exportColumns.map(function (item) {
                                    return item.label;
                                }),
                                Array.isArray(res.data) ? res.data : []
                            );
                            self.$message.success('导出成功');
                        },
                        error: function () {
                            self.exporting = false;
                            self.$message.error('导出失败');
                        }
                    });
                }
            })
        });
    }
    // 搜索
    form.on('submit(search)', function (data) {
        pageCurr = 1;
        tableReload(false);
    });
    // 重置
    form.on('submit(reset)', function (data) {
        pageCurr = 1;
        clearFormVal($('#search-box'));
        tableReload(false);
    });
    // 时间选择器
    function layDateRender(data) {
        setTimeout(function () {
            layDate.render({
                elem: '.layui-laydate-range'
                ,type: 'datetime'
                ,range: true
            });
            layDate.render({
                elem: '#startTime\\$',
                type: 'datetime',
                value: data!==undefined?data['startTime\\$']:null
            });
            layDate.render({
                elem: '#endTime\\$',
                type: 'datetime',
                value: data!==undefined?data['endTime\\$']:null
            });
            layDate.render({
                elem: '#createTime\\$',
                type: 'datetime',
                value: data!==undefined?data['createTime\\$']:null
            });
            layDate.render({
                elem: '#updateTime\\$',
                type: 'datetime',
                value: data!==undefined?data['updateTime\\$']:null
            });
        }, 300);
    }
    layDateRender();
});
// 关闭动作
$(document).on('click','#data-detail-close', function () {
    parent.layer.closeAll();
});
function tableReload(child) {
    var searchData = {};
    $.each($('#search-box [name]').serializeArray(), function() {
        searchData[this.name] = this.value;
    });
    tableIns.reload({
        where: searchData,
        page: {curr: pageCurr}
     });
}
})();
src/main/webapp/static/js/basDualCrnpOpt/basDualCrnpOpt.js
@@ -1,268 +1,1039 @@
var pageCurr;
layui.config({
    base: baseUrl + "/static/layui/lay/modules/"
}).use(['table','laydate', 'form', 'admin'], function(){
    var table = layui.table;
    var $ = layui.jquery;
    var layer = layui.layer;
    var layDate = layui.laydate;
    var form = layui.form;
    var admin = layui.admin;
(function () {
    var simpleEntityName = 'basDualCrnpOpt';
    var entityName = 'BasDualCrnpOpt';
    var primaryKeyField = 'id';
    var fieldMeta = dedupeFieldMeta([
    {
        field: 'id',
        columnName: 'id',
        label: '编  号',
        tableProp: 'id',
        exportField: 'id',
        kind: 'text',
        valueType: 'number',
        required: true,
        primaryKey: true,
        sortable: true,
        textarea: false,
        minWidth: 90,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'wrkNo',
        columnName: 'wrk_no',
        label: '工 作 号',
        tableProp: 'wrkNo',
        exportField: 'wrkNo',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 116,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'crnNo',
        columnName: 'crn_no',
        label: '堆垛机号',
        tableProp: 'crnNo',
        exportField: 'crnNo',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'sendTime',
        columnName: 'send_time',
        label: '下发时间',
        tableProp: 'sendTime$',
        exportField: 'sendTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'mode',
        columnName: 'mode',
        label: '作  业',
        tableProp: 'mode',
        exportField: 'mode',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'sourceLocNo',
        columnName: 'source_loc_no',
        label: '起点库位',
        tableProp: 'sourceLocNo',
        exportField: 'sourceLocNo',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'targetLocNo',
        columnName: 'target_loc_no',
        label: '目标库位',
        tableProp: 'targetLocNo',
        exportField: 'targetLocNo',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'updateTime',
        columnName: 'update_time',
        label: '修改时间',
        tableProp: 'updateTime$',
        exportField: 'updateTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'updateBy',
        columnName: 'update_by',
        label: '修改人员',
        tableProp: 'updateBy$',
        exportField: 'updateBy$',
        kind: 'foreign',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: 'user',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'memo',
        columnName: 'memo',
        label: '备  注',
        tableProp: 'memo',
        exportField: 'memo',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: true,
        minWidth: 180,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'command',
        columnName: 'command',
        label: '命  令',
        tableProp: 'command',
        exportField: 'command',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'systemStatus',
        columnName: 'system_status',
        label: '系统状态',
        tableProp: 'systemStatus',
        exportField: 'systemStatus',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'send',
        columnName: 'send',
        label: '下发状态',
        tableProp: 'send$',
        exportField: 'send$',
        kind: 'enum',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 120,
        enumOptions: [{ rawValue: '0', label: '未下发' }, { rawValue: '1', label: '已下发' }],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'response',
        columnName: 'response',
        label: '请求响应',
        tableProp: 'response',
        exportField: 'response',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: true,
        minWidth: 180,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    }
    // 数据渲染
    tableIns = table.render({
        elem: '#basDualCrnpOpt',
        headers: {token: localStorage.getItem('token')},
        url: baseUrl+'/basDualCrnpOpt/list/auth',
        page: true,
        limit: 15,
        limits: [15, 30, 50, 100, 200, 500],
        toolbar: '#toolbar',
        cellMinWidth: 50,
        height: 'full-120',
        cols: [[
            {type: 'checkbox'}
            ,{field: 'id', align: 'center',title: '编号'}
            ,{field: 'wrkNo', align: 'center',title: '工作号'}
            ,{field: 'crnNo', align: 'center',title: '堆垛机号'}
            ,{field: 'sendTime$', align: 'center',title: '下发时间'}
            ,{field: 'mode', align: 'center',title: '作业'}
            ,{field: 'sourceLocNo', align: 'center',title: '起点库位'}
            ,{field: 'targetLocNo', align: 'center',title: '目标库位'}
            ,{field: 'updateTime$', align: 'center',title: '修改时间'}
            ,{field: 'updateBy$', align: 'center',title: '修改人员'}
            ,{field: 'memo', align: 'center',title: '备注'}
            ,{field: 'command', align: 'center',title: '命令'}
            ,{field: 'systemStatus', align: 'center',title: '系统状态'}
            ,{field: 'send$', align: 'center',title: '下发状态'}
            ,{field: 'response', align: 'center',title: '请求响应'}
    ]);
            ,{fixed: 'right', title:'操作', align: 'center', toolbar: '#operate', width:120}
        ]],
        request: {
            pageName: 'curr',
            pageSize: 'limit'
        },
        parseData: function (res) {
            return {
                'code': res.code,
                'msg': res.msg,
                'count': res.data.total,
                'data': res.data.records
            }
        },
        response: {
            statusCode: 200
        },
        done: function(res, curr, count) {
            if (res.code === 403) {
                top.location.href = baseUrl+"/";
            }
            pageCurr=curr;
            limit();
    function formatFieldLabel(field) {
        var raw = field && field.label ? String(field.label).trim() : '';
        if (raw) {
            return raw;
        }
    });
    // 监听排序事件
    table.on('sort(basDualCrnpOpt)', function (obj) {
        var searchData = {};
        $.each($('#search-box [name]').serializeArray(), function() {
            searchData[this.name] = this.value;
        });
        searchData['orderByField'] = obj.field;
        searchData['orderByType'] = obj.type;
        tableIns.reload({
            where: searchData,
            page: {curr: 1}
        });
    });
    // 监听头工具栏事件
    table.on('toolbar(basDualCrnpOpt)', function (obj) {
        var checkStatus = table.checkStatus(obj.config.id).data;
        switch(obj.event) {
            case 'addData':
                showEditModel();
                break;
            case 'deleteData':
               if (checkStatus.length === 0) {
                   layer.msg('请选择要删除的数据', {icon: 2});
                   return;
               }
               del(checkStatus.map(function (d) {
                   return d.id;
               }));
               break;
            case 'exportData':
                admin.confirm('确定导出Excel吗', {shadeClose: true}, function(){
                    var titles=[];
                    var fields=[];
                    obj.config.cols[0].map(function (col) {
                        if (col.type === 'normal' && col.hide === false && col.toolbar == null) {
                            titles.push(col.title);
                            fields.push(col.field);
                        }
                    });
                    var exportData = {};
                    $.each($('#search-box [name]').serializeArray(), function() {
                        exportData[this.name] = this.value;
                    });
                    var param = {
                        'basDualCrnpOpt': exportData,
                        'fields': fields
                    };
                    $.ajax({
                        url: baseUrl+"/basDualCrnpOpt/export/auth",
                        headers: {'token': localStorage.getItem('token')},
                        data: JSON.stringify(param),
                        dataType:'json',
                        contentType:'application/json;charset=UTF-8',
                        method: 'POST',
                        success: function (res) {
                            layer.closeAll();
                            if (res.code === 200) {
                                table.exportFile(titles,res.data,'xls');
                            } else if (res.code === 403) {
                                top.location.href = baseUrl+"/";
                            } else {
                                layer.msg(res.msg, {icon: 2})
                            }
                        }
                    });
                });
                break;
        raw = field && field.columnName ? field.columnName : (field && field.field ? field.field : '');
        if (!raw) {
            return '';
        }
    });
    // 监听行工具事件
    table.on('tool(basDualCrnpOpt)', function(obj){
        var data = obj.data;
        switch (obj.event) {
            case 'edit':
                showEditModel(data);
                break;
            case "del":
                del([data.id]);
                break;
        }
    });
    /* 弹窗 - 新增、修改 */
    function showEditModel(mData) {
        admin.open({
            type: 1,
            area: '600px',
            title: (mData ? '修改' : '添加') + '订单状态',
            content: $('#editDialog').html(),
            success: function (layero, dIndex) {
                layDateRender(mData);
                form.val('detail', mData);
                form.on('submit(editSubmit)', function (data) {
                    var loadIndex = layer.load(2);
                    $.ajax({
                        url: baseUrl+"/basDualCrnpOpt/"+(mData?'update':'add')+"/auth",
                        headers: {'token': localStorage.getItem('token')},
                        data: data.field,
                        method: 'POST',
                        success: function (res) {
                            layer.close(loadIndex);
                            if (res.code === 200){
                                layer.close(dIndex);
                                layer.msg(res.msg, {icon: 1});
                                tableReload();
                            } else if (res.code === 403){
                                top.location.href = baseUrl+"/";
                            }else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }
                    })
                    return false;
                });
                $(layero).children('.layui-layer-content').css('overflow', 'visible');
                layui.form.render('select');
            }
        raw = String(raw)
            .replace(/\$/g, '')
            .replace(/([a-z0-9])([A-Z])/g, '$1_$2')
            .replace(/_/g, ' ')
            .replace(/\s+/g, ' ')
            .trim();
        return raw.replace(/\b[a-z]/g, function (letter) {
            return letter.toUpperCase();
        });
    }
    /* 删除 */
    function del(ids) {
        layer.confirm('确定要删除选中数据吗?', {
            skin: 'layui-layer-admin',
            shade: .1
        }, function (i) {
            layer.close(i);
            var loadIndex = layer.load(2);
    function dedupeFieldMeta(list) {
        var result = [];
        var seen = {};
        (list || []).forEach(function (field) {
            if (!field || !field.field || seen[field.field]) {
                return;
            }
            field.label = formatFieldLabel(field);
            seen[field.field] = true;
            result.push(field);
        });
        return result;
    }
    function isEmptyValue(value) {
        return value === null || value === undefined || value === '';
    }
    function stringValue(value) {
        return isEmptyValue(value) ? '' : String(value);
    }
    function valueOrDash(value) {
        return isEmptyValue(value) ? '--' : value;
    }
    function normalizeOptionValue(field, rawValue) {
        if (rawValue === null || rawValue === undefined) {
            return null;
        }
        if (rawValue === '') {
            return '';
        }
        if (field && field.valueType === 'number') {
            var numberVal = Number(rawValue);
            return isNaN(numberVal) ? rawValue : numberVal;
        }
        return String(rawValue);
    }
    function isSearchableField(field) {
        return !!field && field.kind !== 'image' && !field.textarea;
    }
    function isSortableField(field) {
        if (!field) {
            return false;
        }
        if (field.primaryKey) {
            return true;
        }
        return field.kind !== 'image' && !field.textarea && field.kind !== 'foreign';
    }
    function defaultFieldValue(field) {
        if (field.primaryKey) {
            return null;
        }
        if (field.kind === 'checkbox') {
            return normalizeOptionValue(field, field.checkboxInactiveRaw);
        }
        return '';
    }
    function defaultSearchFieldValue(field) {
        if (field.kind === 'date') {
            return [];
        }
        if (field.kind === 'enum' || field.kind === 'checkbox') {
            return null;
        }
        return '';
    }
    function createSearchDefaults() {
        var result = {
            condition: ''
        };
        fieldMeta.forEach(function (field) {
            if (!isSearchableField(field)) {
                return;
            }
            result[field.field] = defaultSearchFieldValue(field);
        });
        return result;
    }
    function createSearchDisplayDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            if (field.kind === 'foreign' && isSearchableField(field)) {
                result[field.field] = '';
            }
        });
        return result;
    }
    function createDefaultVisibleColumnKeys() {
        return fieldMeta.map(function (field) {
            return field.field;
        });
    }
    function createFormDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            result[field.field] = defaultFieldValue(field);
        });
        return result;
    }
    function createDisplayDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            if (field.kind === 'foreign') {
                result[field.field] = '';
            }
        });
        return result;
    }
    function createFormRules() {
        var rules = {};
        fieldMeta.forEach(function (field) {
            if (field.primaryKey || !field.required) {
                return;
            }
            rules[field.field] = [{
                required: true,
                message: (field.kind === 'date' || field.kind === 'enum' ? '请选择' : '请输入') + field.label,
                trigger: (field.kind === 'date' || field.kind === 'enum') ? 'change' : 'blur'
            }];
        });
        return rules;
    }
    function getTableValue(row, field) {
        var prop = field.tableProp || field.field;
        if (row && !isEmptyValue(row[prop])) {
            return row[prop];
        }
        return row ? row[field.field] : '';
    }
    function isCheckboxChecked(row, field) {
        var value = row ? row[field.field] : null;
        var activeValue = normalizeOptionValue(field, field.checkboxActiveRaw);
        return String(value) === String(activeValue);
    }
    function exportCell(value) {
        return stringValue(value).replace(/\t/g, ' ').replace(/\r?\n/g, ' ');
    }
    function escapeHtml(value) {
        return exportCell(value)
            .replace(/&/g, '&amp;')
            .replace(/</g, '&lt;')
            .replace(/>/g, '&gt;')
            .replace(/"/g, '&quot;')
            .replace(/'/g, '&#39;');
    }
    function buildPayload(form) {
        var payload = {};
        fieldMeta.forEach(function (field) {
            var value = form[field.field];
            if (field.primaryKey) {
                if (!isEmptyValue(value)) {
                    payload[field.field] = value;
                }
                return;
            }
            if (field.kind === 'foreign' && isEmptyValue(value)) {
                value = null;
            }
            if (field.kind === 'enum' && value === '') {
                value = null;
            }
            if (field.kind === 'checkbox' && isEmptyValue(value)) {
                value = normalizeOptionValue(field, field.checkboxInactiveRaw);
            }
            if (field.valueType === 'number' && !isEmptyValue(value)) {
                value = Number(value);
            }
            if (field.valueType === 'number' && value === '') {
                value = null;
            }
            payload[field.field] = value;
        });
        return payload;
    }
    function fillFormFromRow(row, form, display) {
        fieldMeta.forEach(function (field) {
            if (field.primaryKey) {
                form[field.field] = row[field.field];
                return;
            }
            if (field.kind === 'date') {
                form[field.field] = row[field.tableProp] || row[field.field] || '';
                return;
            }
            if (field.kind === 'foreign') {
                form[field.field] = isEmptyValue(row[field.field]) ? '' : normalizeOptionValue(field, row[field.field]);
                if (display) {
                    display[field.field] = row[field.tableProp] || (isEmptyValue(row[field.field]) ? '' : String(row[field.field]));
                }
                return;
            }
            if (field.kind === 'enum') {
                form[field.field] = isEmptyValue(row[field.field]) ? '' : normalizeOptionValue(field, row[field.field]);
                return;
            }
            if (field.kind === 'checkbox') {
                form[field.field] = isEmptyValue(row[field.field])
                    ? normalizeOptionValue(field, field.checkboxInactiveRaw)
                    : normalizeOptionValue(field, row[field.field]);
                return;
            }
            form[field.field] = isEmptyValue(row[field.field])
                ? ''
                : (field.valueType === 'number' ? String(row[field.field]) : row[field.field]);
        });
    }
    function resolveSearchParam(field) {
        if (field.kind === 'date' && field.columnName) {
            return field.columnName;
        }
        return field.field;
    }
    function createDownloadFile(filename, titles, rows) {
        var html = [
            '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">',
            '<head><meta charset="UTF-8"></head><body><table border="1"><thead><tr>',
            titles.map(function (title) {
                return '<th>' + escapeHtml(title) + '</th>';
            }).join(''),
            '</tr></thead><tbody>',
            (rows || []).map(function (row) {
                return '<tr>' + (row || []).map(function (value) {
                    return '<td style="mso-number-format:\\@;">' + escapeHtml(value) + '</td>';
                }).join('') + '</tr>';
            }).join(''),
            '</tbody></table></body></html>'
        ].join('');
        var blob = new Blob(['\ufeff' + html], {
            type: 'application/vnd.ms-excel;charset=utf-8;'
        });
        var anchor = document.createElement('a');
        anchor.href = URL.createObjectURL(blob);
        anchor.download = filename;
        document.body.appendChild(anchor);
        anchor.click();
        setTimeout(function () {
            URL.revokeObjectURL(anchor.href);
            document.body.removeChild(anchor);
        }, 0);
    }
    function buildTimestamp() {
        var now = new Date();
        var pad = function (num) {
            return num < 10 ? '0' + num : String(num);
        };
        return now.getFullYear()
            + pad(now.getMonth() + 1)
            + pad(now.getDate())
            + '_'
            + pad(now.getHours())
            + pad(now.getMinutes())
            + pad(now.getSeconds());
    }
    function authHeaders() {
        return {
            token: localStorage.getItem('token')
        };
    }
    function handleForbidden(res) {
        if (res && res.code === 403) {
            top.location.href = baseUrl + '/';
            return true;
        }
        return false;
    }
    var sharedMethods = {
        authHeaders: authHeaders,
        handleForbidden: handleForbidden,
        valueOrDash: valueOrDash,
        stringValue: stringValue,
        getTableValue: getTableValue,
        isCheckboxChecked: isCheckboxChecked,
        normalizeOptionValue: normalizeOptionValue,
        isSortableField: isSortableField,
        getSuggestionFetcher: function (field) {
            var self = this;
            return function (queryString, callback) {
                self.fetchForeignSuggestions(field, queryString, callback);
            };
        },
        fetchForeignSuggestions: function (field, queryString, callback) {
            if (!field.foreignQuery || !queryString) {
                callback([]);
                return;
            }
            var self = this;
            $.ajax({
                url: baseUrl+"/basDualCrnpOpt/delete/auth",
                headers: {'token': localStorage.getItem('token')},
                data: {ids: ids},
                method: 'POST',
                url: baseUrl + '/' + field.foreignQuery + 'Query/auth',
                method: 'GET',
                headers: self.authHeaders(),
                data: { condition: queryString },
                success: function (res) {
                    layer.close(loadIndex);
                    if (res.code === 200){
                        layer.msg(res.msg, {icon: 1});
                        tableReload();
                    } else if (res.code === 403){
                        top.location.href = baseUrl+"/";
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    if (self.handleForbidden(res)) {
                        return;
                    }
                    if (!res || res.code !== 200 || !Array.isArray(res.data)) {
                        callback([]);
                        return;
                    }
                    callback(res.data.map(function (item) {
                        return {
                            id: item.id,
                            value: item.value
                        };
                    }));
                },
                error: function () {
                    callback([]);
                }
            });
        },
        handleForeignSelect: function (field, item) {
            this.$set(this.displayTarget, field.field, item && item.value ? item.value : '');
            this.$set(this.formTarget, field.field, item && item.id !== undefined ? normalizeOptionValue(field, item.id) : '');
        },
        handleForeignInput: function (field) {
            if (!this.displayTarget || !this.formTarget) {
                return;
            }
            if (this.displayTarget[field.field]) {
                return;
            }
            this.$set(this.formTarget, field.field, '');
        }
    };
    if (document.getElementById('app')) {
        new Vue({
            el: '#app',
            data: function () {
                return {
                    fieldMeta: fieldMeta,
                    primaryKeyField: primaryKeyField,
                    loading: false,
                    exporting: false,
                    tableData: [],
                    selection: [],
                    advancedFiltersVisible: false,
                    allColumns: fieldMeta.slice(),
                    visibleColumnKeys: createDefaultVisibleColumnKeys(),
                    searchForm: createSearchDefaults(),
                    searchDisplay: createSearchDisplayDefaults(),
                    page: {
                        curr: 1,
                        limit: 15,
                        total: 0
                    },
                    sortState: {
                        prop: '',
                        order: ''
                    },
                    dialog: {
                        visible: false,
                        mode: 'create',
                        submitting: false
                    },
                    layoutTimer: null,
                    tableResizeHandler: null,
                    dialogForm: createFormDefaults(),
                    dialogDisplay: createDisplayDefaults(),
                    dialogRules: createFormRules()
                };
            },
            computed: {
                searchableFields: function () {
                    return this.fieldMeta.filter(function (field) {
                        return isSearchableField(field);
                    });
                },
                quickSearchableFields: function () {
                    var result = [];
                    this.searchableFields.forEach(function (field) {
                        if (result.length >= 3 || field.kind === 'date') {
                            return;
                        }
                        result.push(field);
                    });
                    return result;
                },
                advancedSearchableFields: function () {
                    var quickKeys = this.quickSearchableFields.map(function (field) {
                        return field.field;
                    });
                    return this.searchableFields.filter(function (field) {
                        return quickKeys.indexOf(field.field) === -1;
                    });
                },
                hasAdvancedFilters: function () {
                    return this.advancedSearchableFields.length > 0;
                },
                visibleColumns: function () {
                    var keys = this.visibleColumnKeys;
                    return this.allColumns.filter(function (field) {
                        return keys.indexOf(field.field) !== -1;
                    });
                },
                editableFields: function () {
                    return this.fieldMeta.filter(function (field) {
                        return !field.primaryKey;
                    });
                },
                exportColumns: function () {
                    return this.visibleColumns.map(function (field) {
                        return {
                            field: field.exportField || field.tableProp || field.field,
                            label: field.label
                        };
                    });
                },
                tableHeight: function () {
                    return this.advancedFiltersVisible && this.hasAdvancedFilters
                        ? 'calc(100vh - 390px)'
                        : 'calc(100vh - 300px)';
                },
                formTarget: function () {
                    return this.dialogForm;
                },
                displayTarget: function () {
                    return this.dialogDisplay;
                }
            },
            created: function () {
                this.loadTable();
            },
            mounted: function () {
                var self = this;
                self.requestTableLayout(80);
                self.tableResizeHandler = function () {
                    self.requestTableLayout(80);
                };
                window.addEventListener('resize', self.tableResizeHandler);
            },
            beforeDestroy: function () {
                if (this.layoutTimer) {
                    clearTimeout(this.layoutTimer);
                    this.layoutTimer = null;
                }
                if (this.tableResizeHandler) {
                    window.removeEventListener('resize', this.tableResizeHandler);
                    this.tableResizeHandler = null;
                }
            },
            methods: $.extend({}, sharedMethods, {
                requestTableLayout: function (delay) {
                    var self = this;
                    if (self.layoutTimer) {
                        clearTimeout(self.layoutTimer);
                    }
                    self.$nextTick(function () {
                        self.layoutTimer = setTimeout(function () {
                            var table = self.$refs.dataTable;
                            if (table && typeof table.doLayout === 'function') {
                                table.doLayout();
                            }
                        }, delay || 40);
                    });
                },
                isColumnVisible: function (fieldName) {
                    return this.visibleColumnKeys.indexOf(fieldName) !== -1;
                },
                toggleColumn: function (fieldName, visible) {
                    if (visible) {
                        if (this.visibleColumnKeys.indexOf(fieldName) === -1) {
                            this.visibleColumnKeys.push(fieldName);
                        }
                        this.requestTableLayout(80);
                        return;
                    }
                    if (this.visibleColumnKeys.length === 1) {
                        this.$message.warning('至少保留一列');
                        return;
                    }
                    this.visibleColumnKeys = this.visibleColumnKeys.filter(function (item) {
                        return item !== fieldName;
                    });
                    this.requestTableLayout(80);
                },
                selectAllColumns: function () {
                    this.visibleColumnKeys = createDefaultVisibleColumnKeys();
                    this.requestTableLayout(80);
                },
                resetColumns: function () {
                    this.visibleColumnKeys = createDefaultVisibleColumnKeys();
                    this.requestTableLayout(80);
                },
                toggleAdvancedFilters: function () {
                    this.advancedFiltersVisible = !this.advancedFiltersVisible;
                    this.requestTableLayout(260);
                },
                handleSearchForeignSelect: function (field, item) {
                    this.$set(this.searchDisplay, field.field, item && item.value ? item.value : '');
                    this.$set(this.searchForm, field.field, item && item.id !== undefined ? normalizeOptionValue(field, item.id) : '');
                },
                handleSearchForeignInput: function (field) {
                    if (this.searchDisplay[field.field]) {
                        return;
                    }
                    this.$set(this.searchForm, field.field, '');
                },
                buildQueryParams: function () {
                    var self = this;
                    var params = {
                        curr: self.page.curr,
                        limit: self.page.limit
                    };
                    if (self.searchForm.condition) {
                        params.condition = self.searchForm.condition;
                    }
                    self.searchableFields.forEach(function (field) {
                        var value = self.searchForm[field.field];
                        if (field.kind === 'date') {
                            if (value && value.length === 2) {
                                params[resolveSearchParam(field)] = value[0] + ' - ' + value[1];
                            }
                            return;
                        }
                        if (!isEmptyValue(value)) {
                            params[resolveSearchParam(field)] = value;
                        }
                    });
                    if (self.sortState.prop && self.sortState.order) {
                        params.orderByField = self.sortState.prop;
                        params.orderByType = self.sortState.order === 'ascending' ? 'asc' : 'desc';
                    }
                    return params;
                },
                loadTable: function () {
                    var self = this;
                    self.loading = true;
                    $.ajax({
                        url: baseUrl + '/' + simpleEntityName + '/list/auth',
                        method: 'GET',
                        headers: self.authHeaders(),
                        data: self.buildQueryParams(),
                        success: function (res) {
                            self.loading = false;
                            if (self.handleForbidden(res)) {
                                return;
                            }
                            if (!res || res.code !== 200) {
                                self.$message.error((res && res.msg) ? res.msg : '加载失败');
                                return;
                            }
                            var payload = res.data || {};
                            self.tableData = Array.isArray(payload.records) ? payload.records : [];
                            self.page.total = payload.total || 0;
                            self.requestTableLayout(80);
                        },
                        error: function () {
                            self.loading = false;
                            self.requestTableLayout(80);
                            self.$message.error('加载失败');
                        }
                    });
                },
                handleSearch: function () {
                    this.page.curr = 1;
                    this.loadTable();
                },
                handleReset: function () {
                    this.searchForm = createSearchDefaults();
                    this.searchDisplay = createSearchDisplayDefaults();
                    this.advancedFiltersVisible = false;
                    this.page.curr = 1;
                    this.sortState = {
                        prop: '',
                        order: ''
                    };
                    this.loadTable();
                },
                handleSelectionChange: function (rows) {
                    this.selection = rows || [];
                },
                handleSortChange: function (payload) {
                    this.sortState = {
                        prop: payload && payload.prop ? payload.prop : '',
                        order: payload && payload.order ? payload.order : ''
                    };
                    this.page.curr = 1;
                    this.loadTable();
                },
                handleCurrentChange: function (curr) {
                    this.page.curr = curr;
                    this.loadTable();
                },
                handleSizeChange: function (limit) {
                    this.page.limit = limit;
                    this.page.curr = 1;
                    this.loadTable();
                },
                resetDialogState: function () {
                    this.dialogForm = createFormDefaults();
                    this.dialogDisplay = createDisplayDefaults();
                    if (this.$refs.dialogForm) {
                        this.$refs.dialogForm.clearValidate();
                    }
                },
                openCreateDialog: function () {
                    this.dialog.mode = 'create';
                    this.dialog.visible = true;
                    this.$nextTick(this.resetDialogState);
                },
                openEditDialog: function (row) {
                    var self = this;
                    self.dialog.mode = 'edit';
                    self.dialog.visible = true;
                    self.$nextTick(function () {
                        self.resetDialogState();
                        fillFormFromRow(row, self.dialogForm, self.dialogDisplay);
                        if (self.$refs.dialogForm) {
                            self.$refs.dialogForm.clearValidate();
                        }
                    });
                },
                submitDialog: function () {
                    var self = this;
                    if (!self.$refs.dialogForm) {
                        return;
                    }
                    self.$refs.dialogForm.validate(function (valid) {
                        if (!valid) {
                            return false;
                        }
                        self.dialog.submitting = true;
                        $.ajax({
                            url: baseUrl + '/' + simpleEntityName + '/' + (self.dialog.mode === 'create' ? 'add' : 'update') + '/auth',
                            method: 'POST',
                            headers: self.authHeaders(),
                            data: buildPayload(self.dialogForm),
                            success: function (res) {
                                self.dialog.submitting = false;
                                if (self.handleForbidden(res)) {
                                    return;
                                }
                                if (!res || res.code !== 200) {
                                    self.$message.error((res && res.msg) ? res.msg : '保存失败');
                                    return;
                                }
                                self.$message.success(res.msg || '保存成功');
                                self.dialog.visible = false;
                                self.loadTable();
                            },
                            error: function () {
                                self.dialog.submitting = false;
                                self.$message.error('保存失败');
                            }
                        });
                        return true;
                    });
                },
                removeSelection: function () {
                    var self = this;
                    var ids = self.selection.map(function (row) {
                        return row[self.primaryKeyField];
                    });
                    self.removeRows(ids);
                },
                removeRows: function (ids) {
                    var self = this;
                    if (!ids || ids.length === 0) {
                        self.$message.warning('请选择要删除的数据');
                        return;
                    }
                    self.$confirm('确定删除选中的记录吗?', '提示', { type: 'warning' }).then(function () {
                        $.ajax({
                            url: baseUrl + '/' + simpleEntityName + '/delete/auth',
                            method: 'POST',
                            headers: self.authHeaders(),
                            traditional: true,
                            data: { 'ids[]': ids },
                            success: function (res) {
                                if (self.handleForbidden(res)) {
                                    return;
                                }
                                if (!res || res.code !== 200) {
                                    self.$message.error((res && res.msg) ? res.msg : '删除失败');
                                    return;
                                }
                                self.$message.success(res.msg || '删除成功');
                                self.selection = [];
                                if (self.tableData.length === ids.length && self.page.curr > 1) {
                                    self.page.curr = self.page.curr - 1;
                                }
                                self.loadTable();
                            },
                            error: function () {
                                self.$message.error('删除失败');
                            }
                        });
                    }).catch(function () {});
                },
                exportRows: function () {
                    var self = this;
                    self.exporting = true;
                    var requestBody = {
                        fields: self.exportColumns.map(function (item) {
                            return item.field;
                        })
                    };
                    requestBody[simpleEntityName] = self.buildQueryParams();
                    $.ajax({
                        url: baseUrl + '/' + simpleEntityName + '/export/auth',
                        method: 'POST',
                        headers: $.extend({ 'Content-Type': 'application/json;charset=UTF-8' }, self.authHeaders()),
                        data: JSON.stringify(requestBody),
                        success: function (res) {
                            self.exporting = false;
                            if (self.handleForbidden(res)) {
                                return;
                            }
                            if (!res || res.code !== 200) {
                                self.$message.error((res && res.msg) ? res.msg : '导出失败');
                                return;
                            }
                            createDownloadFile(
                                simpleEntityName + '_' + buildTimestamp() + '.xls',
                                self.exportColumns.map(function (item) {
                                    return item.label;
                                }),
                                Array.isArray(res.data) ? res.data : []
                            );
                            self.$message.success('导出成功');
                        },
                        error: function () {
                            self.exporting = false;
                            self.$message.error('导出失败');
                        }
                    });
                }
            })
        });
    }
    // 搜索
    form.on('submit(search)', function (data) {
        pageCurr = 1;
        tableReload(false);
    });
    // 重置
    form.on('submit(reset)', function (data) {
        pageCurr = 1;
        clearFormVal($('#search-box'));
        tableReload(false);
    });
    // 时间选择器
    function layDateRender(data) {
        setTimeout(function () {
            layDate.render({
                elem: '.layui-laydate-range'
                ,type: 'datetime'
                ,range: true
            });
            layDate.render({
                elem: '#sendTime\\$',
                type: 'datetime',
                value: data!==undefined?data['sendTime\\$']:null
            });
            layDate.render({
                elem: '#updateTime\\$',
                type: 'datetime',
                value: data!==undefined?data['updateTime\\$']:null
            });
        }, 300);
    }
    layDateRender();
});
// 关闭动作
$(document).on('click','#data-detail-close', function () {
    parent.layer.closeAll();
});
function tableReload(child) {
    var searchData = {};
    $.each($('#search-box [name]').serializeArray(), function() {
        searchData[this.name] = this.value;
    });
    tableIns.reload({
        where: searchData,
        page: {curr: pageCurr}
     });
}
})();
src/main/webapp/static/js/basLocSts/basLocSts.js
@@ -1,440 +1,1111 @@
var pageCurr;
layui.use(['table','laydate', 'form'], function(){
    var table = layui.table;
    var $ = layui.jquery;
    var layer = layui.layer;
    var layDate = layui.laydate;
    var form = layui.form;
(function () {
    var simpleEntityName = 'basLocSts';
    var entityName = 'BasLocSts';
    var primaryKeyField = 'locSts';
    var fieldMeta = dedupeFieldMeta([
    {
        field: 'locSts',
        columnName: 'loc_sts',
        label: '库位状态代号',
        tableProp: 'locSts',
        exportField: 'locSts',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'locDesc',
        columnName: 'loc_desc',
        label: '库位状态描述',
        tableProp: 'locDesc',
        exportField: 'locDesc',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'modiUser',
        columnName: 'modi_user',
        label: '修改人员',
        tableProp: 'modiUser',
        exportField: 'modiUser',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'modiTime',
        columnName: 'modi_time',
        label: '修改时间',
        tableProp: 'modiTime$',
        exportField: 'modiTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'appeUser',
        columnName: 'appe_user',
        label: '创建者',
        tableProp: 'appeUser',
        exportField: 'appeUser',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'appeTime',
        columnName: 'appe_time',
        label: '添加时间',
        tableProp: 'appeTime$',
        exportField: 'appeTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'locSts',
        columnName: 'loc_sts',
        label: '库位状态代号',
        tableProp: 'locSts',
        exportField: 'locSts',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'locDesc',
        columnName: 'loc_desc',
        label: '库位状态描述',
        tableProp: 'locDesc',
        exportField: 'locDesc',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'modiUser',
        columnName: 'modi_user',
        label: '修改人员',
        tableProp: 'modiUser',
        exportField: 'modiUser',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'modiTime',
        columnName: 'modi_time',
        label: '修改时间',
        tableProp: 'modiTime$',
        exportField: 'modiTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'appeUser',
        columnName: 'appe_user',
        label: '创建者',
        tableProp: 'appeUser',
        exportField: 'appeUser',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'appeTime',
        columnName: 'appe_time',
        label: '添加时间',
        tableProp: 'appeTime$',
        exportField: 'appeTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'locSts',
        columnName: 'loc_sts',
        label: '库位状态代号',
        tableProp: 'locSts',
        exportField: 'locSts',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'locDesc',
        columnName: 'loc_desc',
        label: '库位状态描述',
        tableProp: 'locDesc',
        exportField: 'locDesc',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'modiUser',
        columnName: 'modi_user',
        label: '修改人员',
        tableProp: 'modiUser',
        exportField: 'modiUser',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'modiTime',
        columnName: 'modi_time',
        label: '修改时间',
        tableProp: 'modiTime$',
        exportField: 'modiTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'appeUser',
        columnName: 'appe_user',
        label: '创建者',
        tableProp: 'appeUser',
        exportField: 'appeUser',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'appeTime',
        columnName: 'appe_time',
        label: '添加时间',
        tableProp: 'appeTime$',
        exportField: 'appeTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    }
    // 数据渲染
    tableIns = table.render({
        elem: '#basLocSts',
        headers: {token: localStorage.getItem('token')},
        url: baseUrl+'/basLocSts/list/auth',
        page: true,
        limit: 16,
        limits: [16, 30, 50, 100, 200, 500],
        even: true,
        toolbar: '#toolbar',
        cellMinWidth: 50,
        cols: [[
            {type: 'checkbox', fixed: 'left'}
//            ,{field: 'id', title: 'ID', sort: true,align: 'center', fixed: 'left', width: 80}
            ,{field: 'locSts', align: 'center',sort:true,title: '库位状态代号'}
            ,{field: 'locDesc', align: 'center',sort: true,title: '库位状态描述'}
            ,{field: 'modiUser$', align: 'center',title: '修改人员'}
            ,{field: 'modiTime$', align: 'center',title: '修改时间'}
            // ,{field: 'appeUser$', align: 'center',title: '创建者',event: 'appeUser', style: 'text-decoration: underline;cursor:pointer'}
            // ,{field: 'appeTime$', align: 'center',title: '添加时间'}
    ]);
            ,{fixed: 'right', title:'操作', align: 'center', toolbar: '#operate', width:150}
        ]],
        request: {
            pageName: 'curr',
            pageSize: 'limit'
        },
        parseData: function (res) {
            return {
                'code': res.code,
                'msg': res.msg,
                'count': res.data.total,
                'data': res.data.records
            }
        },
        response: {
            statusCode: 200
        },
        done: function(res, curr, count) {
            if (res.code === 403) {
                top.location.href = baseUrl+"/";
            }
            pageCurr=curr;
            limit();
    function formatFieldLabel(field) {
        var raw = field && field.label ? String(field.label).trim() : '';
        if (raw) {
            return raw;
        }
    });
    // 监听排序事件
    table.on('sort(basLocSts)', function (obj) {
        var searchData = {};
        $.each($('#search-box [name]').serializeArray(), function() {
            searchData[this.name] = this.value;
        raw = field && field.columnName ? field.columnName : (field && field.field ? field.field : '');
        if (!raw) {
            return '';
        }
        raw = String(raw)
            .replace(/\$/g, '')
            .replace(/([a-z0-9])([A-Z])/g, '$1_$2')
            .replace(/_/g, ' ')
            .replace(/\s+/g, ' ')
            .trim();
        return raw.replace(/\b[a-z]/g, function (letter) {
            return letter.toUpperCase();
        });
        searchData['orderByField'] = obj.field;
        searchData['orderByType'] = obj.type;
        tableIns.reload({
            where: searchData,
            page: {
                curr: 1
            },
            done: function (res, curr, count) {
                if (res.code === 403) {
                    top.location.href = baseUrl+"/";
                }
                pageCurr=curr;
                limit();
    }
    function dedupeFieldMeta(list) {
        var result = [];
        var seen = {};
        (list || []).forEach(function (field) {
            if (!field || !field.field || seen[field.field]) {
                return;
            }
            field.label = formatFieldLabel(field);
            seen[field.field] = true;
            result.push(field);
        });
    });
        return result;
    }
    // 监听头工具栏事件
    table.on('toolbar(basLocSts)', function (obj) {
        var checkStatus = table.checkStatus(obj.config.id);
        switch(obj.event) {
            case 'addData':
                layer.open({
                    type: 2,
                    title: '新增',
                    maxmin: true,
                    area: ['500px', top.detailHeight],
                    shadeClose: false,
                    content: 'basLocSts_detail.html',
                    success: function(layero, index){
                        layer.getChildFrame('#data-detail-submit-edit', index).hide();
                        clearFormVal(layer.getChildFrame('#detail', index));
                        layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
                    }
                });
                break;
            case 'refreshData':
                tableIns.reload({
                    page: {
                        curr: pageCurr
                    }
                });
                limit();
                break;
            case 'deleteData':
                var data = checkStatus.data;
                if (data.length === 0){
                    layer.msg('请选择数据');
                } else {
                    layer.confirm('确定删除'+(data.length===1?'此':data.length)+'条数据吗', function(){
                        $.ajax({
                            url: baseUrl+"/basLocSts/delete/auth",
                            headers: {'token': localStorage.getItem('token')},
                            data: {param: JSON.stringify(data)},
                            method: 'POST',
                            traditional:true,
                            success: function (res) {
                                if (res.code === 200){
                                    layer.closeAll();
                                    tableReload(false);
                                } else if (res.code === 403){
                                    top.location.href = baseUrl+"/";
                                } else {
                                    layer.msg(res.msg)
                                }
                            }
                        })
                    });
                }
                break;
            case 'exportData':
                layer.confirm('确定导出Excel吗', {shadeClose: true}, function(){
                    var titles=[];
                    var fields=[];
                    obj.config.cols[0].map(function (col) {
                        if (col.type === 'normal' && col.hide === false && col.toolbar == null) {
                            titles.push(col.title);
                            fields.push(col.field);
                        }
                    });
                    var exportData = {};
                    $.each($('#search-box [name]').serializeArray(), function() {
                        exportData[this.name] = this.value;
                    });
                    var param = {
                        'basLocSts': exportData,
                        'fields': fields
                    };
                    $.ajax({
                        url: baseUrl+"/basLocSts/export/auth",
                        headers: {'token': localStorage.getItem('token')},
                        data: JSON.stringify(param),
                        dataType:'json',
                        contentType:'application/json;charset=UTF-8',
                        method: 'POST',
                        success: function (res) {
                            layer.closeAll();
                            if (res.code === 200) {
                                table.exportFile(titles,res.data,'xls');
                            } else if (res.code === 403) {
                                top.location.href = baseUrl+"/";
                            } else {
                                layer.msg(res.msg)
                            }
                        }
                    });
                });
                break;
    function isEmptyValue(value) {
        return value === null || value === undefined || value === '';
    }
    function stringValue(value) {
        return isEmptyValue(value) ? '' : String(value);
    }
    function valueOrDash(value) {
        return isEmptyValue(value) ? '--' : value;
    }
    function normalizeOptionValue(field, rawValue) {
        if (rawValue === null || rawValue === undefined) {
            return null;
        }
    });
    // 监听行工具事件
    table.on('tool(basLocSts)', function(obj){
        var data = obj.data;
        switch (obj.event) {
            // 详情
            case 'detail':
                layer.open({
                    type: 2,
                    title: '详情',
                    maxmin: true,
                    area: [top.detailWidth, top.detailHeight],
                    shadeClose: false,
                    content: 'basLocSts_detail.html',
                    success: function(layero, index){
                        setFormVal(layer.getChildFrame('#detail', index), data, true);
                        top.convertDisabled(layer.getChildFrame('#data-detail :input', index), true);
                        layer.getChildFrame('#data-detail-submit-save,#prompt', index).hide();
                        layer.getChildFrame('#data-detail-submit-edit', index).hide();
                        layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
                        layero.find('iframe')[0].contentWindow.layui.form.render('select');
                    }
                });
                break;
            // 编辑
            case 'edit':
                layer.open({
                    type: 2,
                    title: '修改',
                    maxmin: true,
                    area: ['500px', top.detailHeight],
                    shadeClose: false,
                    content: 'basLocSts_detail.html',
                    success: function(layero, index){
                        layer.getChildFrame('#data-detail-submit-save', index).hide();
                        setFormVal(layer.getChildFrame('#detail', index), data, false);
                        top.convertDisabled(layer.getChildFrame('#data-detail :input', index), false);
                        top.convertDisabled(layer.getChildFrame('#locSts', index), true);
                        layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
                        layero.find('iframe')[0].contentWindow.layui.form.render('select');
                    }
                });
                break;
            case 'modiUser':
                var param = top.reObject(data).modiUser;
                if (param === undefined) {
                    layer.msg("无数据");
                } else {
                   layer.open({
                       type: 2,
                       title: '修改详情',
                       maxmin: true,
                       area: [top.detailWidth, top.detailHeight],
                       shadeClose: false,
                       content: '../user/user_detail.html',
                       success: function(layero, index){
                           $.ajax({
                               url: baseUrl+"/user/"+ param +"/auth",
                               headers: {'token': localStorage.getItem('token')},
                               method: 'GET',
                               success: function (res) {
                                   if (res.code === 200){
                                       setFormVal(layer.getChildFrame('#detail', index), res.data, true);
                                       top.convertDisabled(layer.getChildFrame('#data-detail :input', index), true);
                                       layer.getChildFrame('#password,#createTime\\$,#status', index).parent().parent().hide();
                                       layer.getChildFrame('#data-detail-submit,#prompt', index).hide();
                                       layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
                                       layero.find('iframe')[0].contentWindow.layui.form.render('select');
                                   } else if (res.code === 403){
                                       parent.location.href = "/";
                                   }else {
                                       layer.msg(res.msg)
                                   }
                               }
                           })
                       }
                   });
                }
                break;
            case 'appeUser':
                var param = top.reObject(data).appeUser;
                if (param === undefined) {
                    layer.msg("无数据");
                } else {
                   layer.open({
                       type: 2,
                       title: '创详情',
                       maxmin: true,
                       area: [top.detailWidth, top.detailHeight],
                       shadeClose: false,
                       content: '../user/user_detail.html',
                       success: function(layero, index){
                           $.ajax({
                               url: baseUrl+"/user/"+ param +"/auth",
                               headers: {'token': localStorage.getItem('token')},
                               method: 'GET',
                               success: function (res) {
                                   if (res.code === 200){
                                       setFormVal(layer.getChildFrame('#detail', index), res.data, true);
                                       top.convertDisabled(layer.getChildFrame('#data-detail :input', index), true);
                                       layer.getChildFrame('#data-detail-submit', index).hide();
                                       layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
                                       layero.find('iframe')[0].contentWindow.layui.form.render('select');
                                   } else if (res.code === 403){
                                       parent.location.href = "/";
                                   }else {
                                       layer.msg(res.msg)
                                   }
                               }
                           })
                       }
                   });
                }
                break;
        if (rawValue === '') {
            return '';
        }
    });
    // 数据保存动作
    form.on('submit(save)', function () {
        if (banMsg != null){
            layer.msg(banMsg);
            return;
        if (field && field.valueType === 'number') {
            var numberVal = Number(rawValue);
            return isNaN(numberVal) ? rawValue : numberVal;
        }
        method("add");
    });
        return String(rawValue);
    }
    // 数据修改动作
    form.on('submit(edit)', function () {
        method("update")
    });
    function isSearchableField(field) {
        return !!field && field.kind !== 'image' && !field.textarea;
    }
    function method(name){
        var index = layer.load(1, {
            shade: [0.5,'#000'] //0.1透明度的背景
        });
        var data = {
//            id: $('#id').val(),
            locSts: $('#locSts').val(),
            locDesc: $('#locDesc').val(),
            modiUser: $('#modiUser').val(),
            modiTime: top.strToDate($('#modiTime\\$').val()),
            appeUser: $('#appeUser').val(),
            appeTime: top.strToDate($('#appeTime\\$').val()),
    function isSortableField(field) {
        if (!field) {
            return false;
        }
        if (field.primaryKey) {
            return true;
        }
        return field.kind !== 'image' && !field.textarea && field.kind !== 'foreign';
    }
    function defaultFieldValue(field) {
        if (field.primaryKey) {
            return null;
        }
        if (field.kind === 'checkbox') {
            return normalizeOptionValue(field, field.checkboxInactiveRaw);
        }
        return '';
    }
    function defaultSearchFieldValue(field) {
        if (field.kind === 'date') {
            return [];
        }
        if (field.kind === 'enum' || field.kind === 'checkbox') {
            return null;
        }
        return '';
    }
    function createSearchDefaults() {
        var result = {
            condition: ''
        };
        $.ajax({
            url: baseUrl+"/basLocSts/"+name+"/auth",
            headers: {'token': localStorage.getItem('token')},
            data: top.reObject(data),
            method: 'POST',
            success: function (res) {
                if (res.code === 200){
                    parent.layer.closeAll();
                    tableReload(true);
                    $("#data-detail :input").each(function () {
                        $(this).val("");
                    });
                } else if (res.code === 403){
                    top.location.href = baseUrl+"/";
                }else {
                    layer.msg(res.msg)
                }
                layer.close(index);
        fieldMeta.forEach(function (field) {
            if (!isSearchableField(field)) {
                return;
            }
        })
            result[field.field] = defaultSearchFieldValue(field);
        });
        return result;
    }
    // 搜索栏搜索事件
    form.on('submit(search)', function (data) {
        pageCurr = 1;
        tableReload(false);
    });
    function createSearchDisplayDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            if (field.kind === 'foreign' && isSearchableField(field)) {
                result[field.field] = '';
            }
        });
        return result;
    }
    // 搜索栏重置事件
    form.on('submit(reset)', function (data) {
        pageCurr = 1;
        clearFormVal($('#search-box'));
        tableReload(false);
    });
    function createDefaultVisibleColumnKeys() {
        return fieldMeta.map(function (field) {
            return field.field;
        });
    }
    // 时间选择器
    layDate.render({
        elem: '#modiTime\\$',
        type: 'datetime'
    });
    layDate.render({
        elem: '#appeTime\\$',
        type: 'datetime'
    });
    function createFormDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            result[field.field] = defaultFieldValue(field);
        });
        return result;
    }
    function createDisplayDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            if (field.kind === 'foreign') {
                result[field.field] = '';
            }
        });
        return result;
    }
});
    function createFormRules() {
        var rules = {};
        fieldMeta.forEach(function (field) {
            if (field.primaryKey || !field.required) {
                return;
            }
            rules[field.field] = [{
                required: true,
                message: (field.kind === 'date' || field.kind === 'enum' ? '请选择' : '请输入') + field.label,
                trigger: (field.kind === 'date' || field.kind === 'enum') ? 'change' : 'blur'
            }];
        });
        return rules;
    }
// 关闭动作
$(document).on('click','#data-detail-close', function () {
    parent.layer.closeAll();
});
    function getTableValue(row, field) {
        var prop = field.tableProp || field.field;
        if (row && !isEmptyValue(row[prop])) {
            return row[prop];
        }
        return row ? row[field.field] : '';
    }
function tableReload(child) {
    var searchData = {};
    $.each($('#search-box [name]').serializeArray(), function() {
        searchData[this.name] = this.value;
    });
    (child ? parent.tableIns : tableIns).reload({
        where: searchData,
        page: {
            curr: pageCurr
    function isCheckboxChecked(row, field) {
        var value = row ? row[field.field] : null;
        var activeValue = normalizeOptionValue(field, field.checkboxActiveRaw);
        return String(value) === String(activeValue);
    }
    function exportCell(value) {
        return stringValue(value).replace(/\t/g, ' ').replace(/\r?\n/g, ' ');
    }
    function escapeHtml(value) {
        return exportCell(value)
            .replace(/&/g, '&amp;')
            .replace(/</g, '&lt;')
            .replace(/>/g, '&gt;')
            .replace(/"/g, '&quot;')
            .replace(/'/g, '&#39;');
    }
    function buildPayload(form) {
        var payload = {};
        fieldMeta.forEach(function (field) {
            var value = form[field.field];
            if (field.primaryKey) {
                if (!isEmptyValue(value)) {
                    payload[field.field] = value;
                }
                return;
            }
            if (field.kind === 'foreign' && isEmptyValue(value)) {
                value = null;
            }
            if (field.kind === 'enum' && value === '') {
                value = null;
            }
            if (field.kind === 'checkbox' && isEmptyValue(value)) {
                value = normalizeOptionValue(field, field.checkboxInactiveRaw);
            }
            if (field.valueType === 'number' && !isEmptyValue(value)) {
                value = Number(value);
            }
            if (field.valueType === 'number' && value === '') {
                value = null;
            }
            payload[field.field] = value;
        });
        return payload;
    }
    function fillFormFromRow(row, form, display) {
        fieldMeta.forEach(function (field) {
            if (field.primaryKey) {
                form[field.field] = row[field.field];
                return;
            }
            if (field.kind === 'date') {
                form[field.field] = row[field.tableProp] || row[field.field] || '';
                return;
            }
            if (field.kind === 'foreign') {
                form[field.field] = isEmptyValue(row[field.field]) ? '' : normalizeOptionValue(field, row[field.field]);
                if (display) {
                    display[field.field] = row[field.tableProp] || (isEmptyValue(row[field.field]) ? '' : String(row[field.field]));
                }
                return;
            }
            if (field.kind === 'enum') {
                form[field.field] = isEmptyValue(row[field.field]) ? '' : normalizeOptionValue(field, row[field.field]);
                return;
            }
            if (field.kind === 'checkbox') {
                form[field.field] = isEmptyValue(row[field.field])
                    ? normalizeOptionValue(field, field.checkboxInactiveRaw)
                    : normalizeOptionValue(field, row[field.field]);
                return;
            }
            form[field.field] = isEmptyValue(row[field.field])
                ? ''
                : (field.valueType === 'number' ? String(row[field.field]) : row[field.field]);
        });
    }
    function resolveSearchParam(field) {
        if (field.kind === 'date' && field.columnName) {
            return field.columnName;
        }
        return field.field;
    }
    function createDownloadFile(filename, titles, rows) {
        var html = [
            '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">',
            '<head><meta charset="UTF-8"></head><body><table border="1"><thead><tr>',
            titles.map(function (title) {
                return '<th>' + escapeHtml(title) + '</th>';
            }).join(''),
            '</tr></thead><tbody>',
            (rows || []).map(function (row) {
                return '<tr>' + (row || []).map(function (value) {
                    return '<td style="mso-number-format:\\@;">' + escapeHtml(value) + '</td>';
                }).join('') + '</tr>';
            }).join(''),
            '</tbody></table></body></html>'
        ].join('');
        var blob = new Blob(['\ufeff' + html], {
            type: 'application/vnd.ms-excel;charset=utf-8;'
        });
        var anchor = document.createElement('a');
        anchor.href = URL.createObjectURL(blob);
        anchor.download = filename;
        document.body.appendChild(anchor);
        anchor.click();
        setTimeout(function () {
            URL.revokeObjectURL(anchor.href);
            document.body.removeChild(anchor);
        }, 0);
    }
    function buildTimestamp() {
        var now = new Date();
        var pad = function (num) {
            return num < 10 ? '0' + num : String(num);
        };
        return now.getFullYear()
            + pad(now.getMonth() + 1)
            + pad(now.getDate())
            + '_'
            + pad(now.getHours())
            + pad(now.getMinutes())
            + pad(now.getSeconds());
    }
    function authHeaders() {
        return {
            token: localStorage.getItem('token')
        };
    }
    function handleForbidden(res) {
        if (res && res.code === 403) {
            top.location.href = baseUrl + '/';
            return true;
        }
        return false;
    }
    var sharedMethods = {
        authHeaders: authHeaders,
        handleForbidden: handleForbidden,
        valueOrDash: valueOrDash,
        stringValue: stringValue,
        getTableValue: getTableValue,
        isCheckboxChecked: isCheckboxChecked,
        normalizeOptionValue: normalizeOptionValue,
        isSortableField: isSortableField,
        getSuggestionFetcher: function (field) {
            var self = this;
            return function (queryString, callback) {
                self.fetchForeignSuggestions(field, queryString, callback);
            };
        },
        done: function (res, curr, count) {
            if (res.code === 403) {
                top.location.href = baseUrl+"/";
        fetchForeignSuggestions: function (field, queryString, callback) {
            if (!field.foreignQuery || !queryString) {
                callback([]);
                return;
            }
            pageCurr=curr;
            if (res.data.length === 0 && count !== 0) {
                tableIns.reload({
                    where: searchData,
                    page: {
                        curr: pageCurr-1
            var self = this;
            $.ajax({
                url: baseUrl + '/' + field.foreignQuery + 'Query/auth',
                method: 'GET',
                headers: self.authHeaders(),
                data: { condition: queryString },
                success: function (res) {
                    if (self.handleForbidden(res)) {
                        return;
                    }
                });
                pageCurr -= 1;
            }
            limit(child);
        }
    });
}
function setFormVal(el, data, showImg) {
    for (var val in data) {
        var find = el.find(":input[id='" + val + "']");
        find.val(data[val]);
        if (showImg){
            var next = find.next();
            if (next.get(0)){
                if (next.get(0).localName === "img") {
                    find.hide();
                    next.attr("src", data[val]);
                    next.show();
                    if (!res || res.code !== 200 || !Array.isArray(res.data)) {
                        callback([]);
                        return;
                    }
                    callback(res.data.map(function (item) {
                        return {
                            id: item.id,
                            value: item.value
                        };
                    }));
                },
                error: function () {
                    callback([]);
                }
            });
        },
        handleForeignSelect: function (field, item) {
            this.$set(this.displayTarget, field.field, item && item.value ? item.value : '');
            this.$set(this.formTarget, field.field, item && item.id !== undefined ? normalizeOptionValue(field, item.id) : '');
        },
        handleForeignInput: function (field) {
            if (!this.displayTarget || !this.formTarget) {
                return;
            }
            if (this.displayTarget[field.field]) {
                return;
            }
            this.$set(this.formTarget, field.field, '');
        }
    }
}
    };
function clearFormVal(el) {
    $(':input', el)
        .val('')
        .removeAttr('checked')
        .removeAttr('selected');
}
function detailScreen(index) {
    var detail = layer.getChildFrame('#data-detail', index);
    var height = detail.height()+60;
    if (height > ($(window).height()*0.9)) {
        height = ($(window).height()*0.9);
    if (document.getElementById('app')) {
        new Vue({
            el: '#app',
            data: function () {
                return {
                    fieldMeta: fieldMeta,
                    primaryKeyField: primaryKeyField,
                    loading: false,
                    exporting: false,
                    tableData: [],
                    selection: [],
                    advancedFiltersVisible: false,
                    allColumns: fieldMeta.slice(),
                    visibleColumnKeys: createDefaultVisibleColumnKeys(),
                    searchForm: createSearchDefaults(),
                    searchDisplay: createSearchDisplayDefaults(),
                    page: {
                        curr: 1,
                        limit: 15,
                        total: 0
                    },
                    sortState: {
                        prop: '',
                        order: ''
                    },
                    dialog: {
                        visible: false,
                        mode: 'create',
                        submitting: false
                    },
                    layoutTimer: null,
                    tableResizeHandler: null,
                    dialogForm: createFormDefaults(),
                    dialogDisplay: createDisplayDefaults(),
                    dialogRules: createFormRules()
                };
            },
            computed: {
                searchableFields: function () {
                    return this.fieldMeta.filter(function (field) {
                        return isSearchableField(field);
                    });
                },
                quickSearchableFields: function () {
                    var result = [];
                    this.searchableFields.forEach(function (field) {
                        if (result.length >= 3 || field.kind === 'date') {
                            return;
                        }
                        result.push(field);
                    });
                    return result;
                },
                advancedSearchableFields: function () {
                    var quickKeys = this.quickSearchableFields.map(function (field) {
                        return field.field;
                    });
                    return this.searchableFields.filter(function (field) {
                        return quickKeys.indexOf(field.field) === -1;
                    });
                },
                hasAdvancedFilters: function () {
                    return this.advancedSearchableFields.length > 0;
                },
                visibleColumns: function () {
                    var keys = this.visibleColumnKeys;
                    return this.allColumns.filter(function (field) {
                        return keys.indexOf(field.field) !== -1;
                    });
                },
                editableFields: function () {
                    return this.fieldMeta.filter(function (field) {
                        return !field.primaryKey;
                    });
                },
                exportColumns: function () {
                    return this.visibleColumns.map(function (field) {
                        return {
                            field: field.exportField || field.tableProp || field.field,
                            label: field.label
                        };
                    });
                },
                tableHeight: function () {
                    return this.advancedFiltersVisible && this.hasAdvancedFilters
                        ? 'calc(100vh - 390px)'
                        : 'calc(100vh - 300px)';
                },
                formTarget: function () {
                    return this.dialogForm;
                },
                displayTarget: function () {
                    return this.dialogDisplay;
                }
            },
            created: function () {
                this.loadTable();
            },
            mounted: function () {
                var self = this;
                self.requestTableLayout(80);
                self.tableResizeHandler = function () {
                    self.requestTableLayout(80);
                };
                window.addEventListener('resize', self.tableResizeHandler);
            },
            beforeDestroy: function () {
                if (this.layoutTimer) {
                    clearTimeout(this.layoutTimer);
                    this.layoutTimer = null;
                }
                if (this.tableResizeHandler) {
                    window.removeEventListener('resize', this.tableResizeHandler);
                    this.tableResizeHandler = null;
                }
            },
            methods: $.extend({}, sharedMethods, {
                requestTableLayout: function (delay) {
                    var self = this;
                    if (self.layoutTimer) {
                        clearTimeout(self.layoutTimer);
                    }
                    self.$nextTick(function () {
                        self.layoutTimer = setTimeout(function () {
                            var table = self.$refs.dataTable;
                            if (table && typeof table.doLayout === 'function') {
                                table.doLayout();
                            }
                        }, delay || 40);
                    });
                },
                isColumnVisible: function (fieldName) {
                    return this.visibleColumnKeys.indexOf(fieldName) !== -1;
                },
                toggleColumn: function (fieldName, visible) {
                    if (visible) {
                        if (this.visibleColumnKeys.indexOf(fieldName) === -1) {
                            this.visibleColumnKeys.push(fieldName);
                        }
                        this.requestTableLayout(80);
                        return;
                    }
                    if (this.visibleColumnKeys.length === 1) {
                        this.$message.warning('至少保留一列');
                        return;
                    }
                    this.visibleColumnKeys = this.visibleColumnKeys.filter(function (item) {
                        return item !== fieldName;
                    });
                    this.requestTableLayout(80);
                },
                selectAllColumns: function () {
                    this.visibleColumnKeys = createDefaultVisibleColumnKeys();
                    this.requestTableLayout(80);
                },
                resetColumns: function () {
                    this.visibleColumnKeys = createDefaultVisibleColumnKeys();
                    this.requestTableLayout(80);
                },
                toggleAdvancedFilters: function () {
                    this.advancedFiltersVisible = !this.advancedFiltersVisible;
                    this.requestTableLayout(260);
                },
                handleSearchForeignSelect: function (field, item) {
                    this.$set(this.searchDisplay, field.field, item && item.value ? item.value : '');
                    this.$set(this.searchForm, field.field, item && item.id !== undefined ? normalizeOptionValue(field, item.id) : '');
                },
                handleSearchForeignInput: function (field) {
                    if (this.searchDisplay[field.field]) {
                        return;
                    }
                    this.$set(this.searchForm, field.field, '');
                },
                buildQueryParams: function () {
                    var self = this;
                    var params = {
                        curr: self.page.curr,
                        limit: self.page.limit
                    };
                    if (self.searchForm.condition) {
                        params.condition = self.searchForm.condition;
                    }
                    self.searchableFields.forEach(function (field) {
                        var value = self.searchForm[field.field];
                        if (field.kind === 'date') {
                            if (value && value.length === 2) {
                                params[resolveSearchParam(field)] = value[0] + ' - ' + value[1];
                            }
                            return;
                        }
                        if (!isEmptyValue(value)) {
                            params[resolveSearchParam(field)] = value;
                        }
                    });
                    if (self.sortState.prop && self.sortState.order) {
                        params.orderByField = self.sortState.prop;
                        params.orderByType = self.sortState.order === 'ascending' ? 'asc' : 'desc';
                    }
                    return params;
                },
                loadTable: function () {
                    var self = this;
                    self.loading = true;
                    $.ajax({
                        url: baseUrl + '/' + simpleEntityName + '/list/auth',
                        method: 'GET',
                        headers: self.authHeaders(),
                        data: self.buildQueryParams(),
                        success: function (res) {
                            self.loading = false;
                            if (self.handleForbidden(res)) {
                                return;
                            }
                            if (!res || res.code !== 200) {
                                self.$message.error((res && res.msg) ? res.msg : '加载失败');
                                return;
                            }
                            var payload = res.data || {};
                            self.tableData = Array.isArray(payload.records) ? payload.records : [];
                            self.page.total = payload.total || 0;
                            self.requestTableLayout(80);
                        },
                        error: function () {
                            self.loading = false;
                            self.requestTableLayout(80);
                            self.$message.error('加载失败');
                        }
                    });
                },
                handleSearch: function () {
                    this.page.curr = 1;
                    this.loadTable();
                },
                handleReset: function () {
                    this.searchForm = createSearchDefaults();
                    this.searchDisplay = createSearchDisplayDefaults();
                    this.advancedFiltersVisible = false;
                    this.page.curr = 1;
                    this.sortState = {
                        prop: '',
                        order: ''
                    };
                    this.loadTable();
                },
                handleSelectionChange: function (rows) {
                    this.selection = rows || [];
                },
                handleSortChange: function (payload) {
                    this.sortState = {
                        prop: payload && payload.prop ? payload.prop : '',
                        order: payload && payload.order ? payload.order : ''
                    };
                    this.page.curr = 1;
                    this.loadTable();
                },
                handleCurrentChange: function (curr) {
                    this.page.curr = curr;
                    this.loadTable();
                },
                handleSizeChange: function (limit) {
                    this.page.limit = limit;
                    this.page.curr = 1;
                    this.loadTable();
                },
                resetDialogState: function () {
                    this.dialogForm = createFormDefaults();
                    this.dialogDisplay = createDisplayDefaults();
                    if (this.$refs.dialogForm) {
                        this.$refs.dialogForm.clearValidate();
                    }
                },
                openCreateDialog: function () {
                    this.dialog.mode = 'create';
                    this.dialog.visible = true;
                    this.$nextTick(this.resetDialogState);
                },
                openEditDialog: function (row) {
                    var self = this;
                    self.dialog.mode = 'edit';
                    self.dialog.visible = true;
                    self.$nextTick(function () {
                        self.resetDialogState();
                        fillFormFromRow(row, self.dialogForm, self.dialogDisplay);
                        if (self.$refs.dialogForm) {
                            self.$refs.dialogForm.clearValidate();
                        }
                    });
                },
                submitDialog: function () {
                    var self = this;
                    if (!self.$refs.dialogForm) {
                        return;
                    }
                    self.$refs.dialogForm.validate(function (valid) {
                        if (!valid) {
                            return false;
                        }
                        self.dialog.submitting = true;
                        $.ajax({
                            url: baseUrl + '/' + simpleEntityName + '/' + (self.dialog.mode === 'create' ? 'add' : 'update') + '/auth',
                            method: 'POST',
                            headers: self.authHeaders(),
                            data: buildPayload(self.dialogForm),
                            success: function (res) {
                                self.dialog.submitting = false;
                                if (self.handleForbidden(res)) {
                                    return;
                                }
                                if (!res || res.code !== 200) {
                                    self.$message.error((res && res.msg) ? res.msg : '保存失败');
                                    return;
                                }
                                self.$message.success(res.msg || '保存成功');
                                self.dialog.visible = false;
                                self.loadTable();
                            },
                            error: function () {
                                self.dialog.submitting = false;
                                self.$message.error('保存失败');
                            }
                        });
                        return true;
                    });
                },
                removeSelection: function () {
                    var self = this;
                    var ids = self.selection.map(function (row) {
                        return row[self.primaryKeyField];
                    });
                    self.removeRows(ids);
                },
                removeRows: function (ids) {
                    var self = this;
                    if (!ids || ids.length === 0) {
                        self.$message.warning('请选择要删除的数据');
                        return;
                    }
                    self.$confirm('确定删除选中的记录吗?', '提示', { type: 'warning' }).then(function () {
                        $.ajax({
                            url: baseUrl + '/' + simpleEntityName + '/delete/auth',
                            method: 'POST',
                            headers: self.authHeaders(),
                            traditional: true,
                            data: { 'ids[]': ids },
                            success: function (res) {
                                if (self.handleForbidden(res)) {
                                    return;
                                }
                                if (!res || res.code !== 200) {
                                    self.$message.error((res && res.msg) ? res.msg : '删除失败');
                                    return;
                                }
                                self.$message.success(res.msg || '删除成功');
                                self.selection = [];
                                if (self.tableData.length === ids.length && self.page.curr > 1) {
                                    self.page.curr = self.page.curr - 1;
                                }
                                self.loadTable();
                            },
                            error: function () {
                                self.$message.error('删除失败');
                            }
                        });
                    }).catch(function () {});
                },
                exportRows: function () {
                    var self = this;
                    self.exporting = true;
                    var requestBody = {
                        fields: self.exportColumns.map(function (item) {
                            return item.field;
                        })
                    };
                    requestBody[simpleEntityName] = self.buildQueryParams();
                    $.ajax({
                        url: baseUrl + '/' + simpleEntityName + '/export/auth',
                        method: 'POST',
                        headers: $.extend({ 'Content-Type': 'application/json;charset=UTF-8' }, self.authHeaders()),
                        data: JSON.stringify(requestBody),
                        success: function (res) {
                            self.exporting = false;
                            if (self.handleForbidden(res)) {
                                return;
                            }
                            if (!res || res.code !== 200) {
                                self.$message.error((res && res.msg) ? res.msg : '导出失败');
                                return;
                            }
                            createDownloadFile(
                                simpleEntityName + '_' + buildTimestamp() + '.xls',
                                self.exportColumns.map(function (item) {
                                    return item.label;
                                }),
                                Array.isArray(res.data) ? res.data : []
                            );
                            self.$message.success('导出成功');
                        },
                        error: function () {
                            self.exporting = false;
                            self.$message.error('导出失败');
                        }
                    });
                }
            })
        });
    }
    layer.style(index, {
//        top: (($(window).height()-height)/3)+"px",
        height: height+'px'
    });
}
$('body').keydown(function () {
    if (event.keyCode === 13) {
        $("#search").click();
    }
});
})();
src/main/webapp/static/js/basMap/basMap.js
@@ -1,323 +1,1219 @@
var pageCurr;
layui.config({
    base: baseUrl + "/static/layui/lay/modules/"
}).use(['table', 'laydate', 'form', 'admin', 'upload'], function () {
    var table = layui.table;
    var $ = layui.jquery;
    var layer = layui.layer;
    var layDate = layui.laydate;
    var form = layui.form;
    var admin = layui.admin;
    var upload = layui.upload;
(function () {
    var simpleEntityName = 'basMap';
    var entityName = 'BasMap';
    var primaryKeyField = 'id';
    var fieldMeta = dedupeFieldMeta([
    {
        field: 'id',
        columnName: 'id',
        label: '#',
        tableProp: 'id',
        exportField: 'id',
        kind: 'text',
        valueType: 'number',
        required: true,
        primaryKey: true,
        sortable: true,
        textarea: false,
        minWidth: 90,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'data',
        columnName: 'data',
        label: '实时数据',
        tableProp: 'data',
        exportField: 'data',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'createTime',
        columnName: 'create_time',
        label: '创建时间',
        tableProp: 'createTime$',
        exportField: 'createTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'updateTime',
        columnName: 'update_time',
        label: '更新时间',
        tableProp: 'updateTime$',
        exportField: 'updateTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'lastData',
        columnName: 'last_data',
        label: '最近数据',
        tableProp: 'lastData',
        exportField: 'lastData',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'lev',
        columnName: 'lev',
        label: '层数',
        tableProp: 'lev',
        exportField: 'lev',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'id',
        columnName: 'id',
        label: '#',
        tableProp: 'id',
        exportField: 'id',
        kind: 'text',
        valueType: 'number',
        required: true,
        primaryKey: true,
        sortable: true,
        textarea: false,
        minWidth: 90,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'data',
        columnName: 'data',
        label: '实时数据',
        tableProp: 'data',
        exportField: 'data',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'createTime',
        columnName: 'create_time',
        label: '创建时间',
        tableProp: 'createTime$',
        exportField: 'createTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'updateTime',
        columnName: 'update_time',
        label: '更新时间',
        tableProp: 'updateTime$',
        exportField: 'updateTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'lastData',
        columnName: 'last_data',
        label: '最近数据',
        tableProp: 'lastData',
        exportField: 'lastData',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'lev',
        columnName: 'lev',
        label: '层数',
        tableProp: 'lev',
        exportField: 'lev',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'originData',
        columnName: 'origin_data',
        label: '原始地图',
        tableProp: 'originData',
        exportField: 'originData',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'id',
        columnName: 'id',
        label: '#',
        tableProp: 'id',
        exportField: 'id',
        kind: 'text',
        valueType: 'number',
        required: true,
        primaryKey: true,
        sortable: true,
        textarea: false,
        minWidth: 90,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'data',
        columnName: 'data',
        label: '实时数据',
        tableProp: 'data',
        exportField: 'data',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'createTime',
        columnName: 'create_time',
        label: '创建时间',
        tableProp: 'createTime$',
        exportField: 'createTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'updateTime',
        columnName: 'update_time',
        label: '更新时间',
        tableProp: 'updateTime$',
        exportField: 'updateTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'lastData',
        columnName: 'last_data',
        label: '最近数据',
        tableProp: 'lastData',
        exportField: 'lastData',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'lev',
        columnName: 'lev',
        label: '层数',
        tableProp: 'lev',
        exportField: 'lev',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'originData',
        columnName: 'origin_data',
        label: '原始地图',
        tableProp: 'originData',
        exportField: 'originData',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'baseRow',
        columnName: 'base_row',
        label: '基准排',
        tableProp: 'baseRow',
        exportField: 'baseRow',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'baseRowCode',
        columnName: 'base_row_code',
        label: '基准排-code',
        tableProp: 'baseRowCode',
        exportField: 'baseRowCode',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'baseBay',
        columnName: 'base_bay',
        label: '基准列',
        tableProp: 'baseBay',
        exportField: 'baseBay',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'baseBayCode',
        columnName: 'base_bay_code',
        label: '基准列-code',
        tableProp: 'baseBayCode',
        exportField: 'baseBayCode',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    }
    // 数据渲染
    tableIns = table.render({
        elem: '#basMap',
        headers: {token: localStorage.getItem('token')},
        url: baseUrl + '/basMap/list/auth',
        page: true,
        limit: 15,
        limits: [15, 30, 50, 100, 200, 500],
        toolbar: '#toolbar',
        cellMinWidth: 50,
        height: 'full-120',
        cols: [[
            {type: 'checkbox'}
            // ,{field: 'id', align: 'center',title: '#'}
            , {field: 'lev', align: 'center', title: '层数'}
            , {field: 'data', align: 'center', title: '实时数据'}
            , {field: 'createTime$', align: 'center', title: '创建时间'}
            , {field: 'updateTime$', align: 'center', title: '更新时间'}
            , {field: 'lastData', align: 'center', title: '最近数据'}
            , {field: 'originData', align: 'center', title: '原始地图'}
            // , {field: 'baseRow', align: 'center', title: '基准排'}
            // , {field: 'baseRowCode', align: 'center', title: '基准排-code'}
            // , {field: 'baseBay', align: 'center', title: '基准列'}
            // , {field: 'baseBayCode', align: 'center', title: '基准列-code'}
    ]);
            , {fixed: 'right', title: '操作', align: 'center', toolbar: '#operate', width: 120}
        ]],
        request: {
            pageName: 'curr',
            pageSize: 'limit'
        },
        parseData: function (res) {
            return {
                'code': res.code,
                'msg': res.msg,
                'count': res.data.total,
                'data': res.data.records
            }
        },
        response: {
            statusCode: 200
        },
        done: function (res, curr, count) {
            if (res.code === 403) {
                top.location.href = baseUrl + "/";
            }
            pageCurr = curr;
            limit();
            renderUpload();
    function formatFieldLabel(field) {
        var raw = field && field.label ? String(field.label).trim() : '';
        if (raw) {
            return raw;
        }
    });
        raw = field && field.columnName ? field.columnName : (field && field.field ? field.field : '');
        if (!raw) {
            return '';
        }
        raw = String(raw)
            .replace(/\$/g, '')
            .replace(/([a-z0-9])([A-Z])/g, '$1_$2')
            .replace(/_/g, ' ')
            .replace(/\s+/g, ' ')
            .trim();
        return raw.replace(/\b[a-z]/g, function (letter) {
            return letter.toUpperCase();
        });
    }
    // 渲染
    var loadIndex;
    function renderUpload() {
        upload.render({
            elem: '.demo-class-accept', // 绑定多个元素
            url: baseUrl + "/basMap/crn/upload", // 此处配置你自己的上传接口即可
            accept: 'file', // 普通文件
            before: function (obj) {
                loadIndex = layer.load(2);
            },
            done: function (res) {
                layer.close(loadIndex);
                if (res.code == 200) {
                    layer.msg('导入成功');
                    tableReload()
                }else {
                    layer.msg(res.msg, {icon: 2})
                }
            },
            error: function () {
                layer.close(loadIndex);
                layer.msg('上传失败', {icon: 2});
    function dedupeFieldMeta(list) {
        var result = [];
        var seen = {};
        (list || []).forEach(function (field) {
            if (!field || !field.field || seen[field.field]) {
                return;
            }
            field.label = formatFieldLabel(field);
            seen[field.field] = true;
            result.push(field);
        });
        return result;
    }
    function isEmptyValue(value) {
        return value === null || value === undefined || value === '';
    }
    function stringValue(value) {
        return isEmptyValue(value) ? '' : String(value);
    }
    function valueOrDash(value) {
        return isEmptyValue(value) ? '--' : value;
    }
    function normalizeOptionValue(field, rawValue) {
        if (rawValue === null || rawValue === undefined) {
            return null;
        }
        if (rawValue === '') {
            return '';
        }
        if (field && field.valueType === 'number') {
            var numberVal = Number(rawValue);
            return isNaN(numberVal) ? rawValue : numberVal;
        }
        return String(rawValue);
    }
    function isSearchableField(field) {
        return !!field && field.kind !== 'image' && !field.textarea;
    }
    function isSortableField(field) {
        if (!field) {
            return false;
        }
        if (field.primaryKey) {
            return true;
        }
        return field.kind !== 'image' && !field.textarea && field.kind !== 'foreign';
    }
    function defaultFieldValue(field) {
        if (field.primaryKey) {
            return null;
        }
        if (field.kind === 'checkbox') {
            return normalizeOptionValue(field, field.checkboxInactiveRaw);
        }
        return '';
    }
    function defaultSearchFieldValue(field) {
        if (field.kind === 'date') {
            return [];
        }
        if (field.kind === 'enum' || field.kind === 'checkbox') {
            return null;
        }
        return '';
    }
    function createSearchDefaults() {
        var result = {
            condition: ''
        };
        fieldMeta.forEach(function (field) {
            if (!isSearchableField(field)) {
                return;
            }
            result[field.field] = defaultSearchFieldValue(field);
        });
        return result;
    }
    function createSearchDisplayDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            if (field.kind === 'foreign' && isSearchableField(field)) {
                result[field.field] = '';
            }
        });
        return result;
    }
    // 监听排序事件
    table.on('sort(basMap)', function (obj) {
        var searchData = {};
        $.each($('#search-box [name]').serializeArray(), function () {
            searchData[this.name] = this.value;
        });
        searchData['orderByField'] = obj.field;
        searchData['orderByType'] = obj.type;
        tableIns.reload({
            where: searchData,
            page: {curr: 1}
        });
    });
    // 监听头工具栏事件
    table.on('toolbar(basMap)', function (obj) {
        var checkStatus = table.checkStatus(obj.config.id).data;
        switch (obj.event) {
            case 'addData':
                showEditModel();
                break;
            case 'deleteData':
                if (checkStatus.length === 0) {
                    layer.msg('请选择要删除的数据', {icon: 2});
                    return;
                }
                del(checkStatus.map(function (d) {
                    return d.id;
                }));
                break;
            case 'initLocMast':
                initLocMast()
                break;
            case 'exportData':
                admin.confirm('确定导出Excel吗', {shadeClose: true}, function () {
                    var titles = [];
                    var fields = [];
                    obj.config.cols[0].map(function (col) {
                        if (col.type === 'normal' && col.hide === false && col.toolbar == null) {
                            titles.push(col.title);
                            fields.push(col.field);
                        }
                    });
                    var exportData = {};
                    $.each($('#search-box [name]').serializeArray(), function () {
                        exportData[this.name] = this.value;
                    });
                    var param = {
                        'basMap': exportData,
                        'fields': fields
                    };
                    $.ajax({
                        url: baseUrl + "/basMap/export/auth",
                        headers: {'token': localStorage.getItem('token')},
                        data: JSON.stringify(param),
                        dataType: 'json',
                        contentType: 'application/json;charset=UTF-8',
                        method: 'POST',
                        success: function (res) {
                            layer.closeAll();
                            if (res.code === 200) {
                                table.exportFile(titles, res.data, 'xls');
                            } else if (res.code === 403) {
                                top.location.href = baseUrl + "/";
                            } else {
                                layer.msg(res.msg, {icon: 2})
                            }
                        }
                    });
                });
                break;
        }
    });
    // 监听行工具事件
    table.on('tool(basMap)', function (obj) {
        var data = obj.data;
        switch (obj.event) {
            case 'edit':
                showEditModel(data);
                break;
            case "del":
                del([data.id]);
                break;
        }
    });
    function initLocMast() {
        layer.prompt({title: '请输入初始化库位层数', formType: 0,   shadeClose: true}, function(lev, idx){
            var loadIndex = layer.load(2);
            $.ajax({
                url: baseUrl + "/locMast/init",
                headers: {'token': localStorage.getItem('token')},
                data: {
                    'lev': lev
                },
                method: 'POST',
                success: function (res) {
                    layer.close(loadIndex);
                    layer.close(idx);
                    if (res.code === 200) {
                        layer.msg(res.msg, {icon: 1});
                        tableReload();
                    } else if (res.code === 403) {
                        top.location.href = baseUrl + "/";
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }
            })
    function createDefaultVisibleColumnKeys() {
        return fieldMeta.map(function (field) {
            return field.field;
        });
    }
    /* 弹窗 - 新增、修改 */
    function showEditModel(mData) {
        admin.open({
            type: 1,
            area: '600px',
            title: (mData ? '修改' : '添加') + '订单状态',
            content: $('#editDialog').html(),
            success: function (layero, dIndex) {
                layDateRender(mData);
                form.val('detail', mData);
                form.on('submit(editSubmit)', function (data) {
                    var loadIndex = layer.load(2);
                    $.ajax({
                        url: baseUrl + "/basMap/" + (mData ? 'update' : 'add') + "/auth",
                        headers: {'token': localStorage.getItem('token')},
                        data: data.field,
                        method: 'POST',
                        success: function (res) {
                            layer.close(loadIndex);
                            if (res.code === 200) {
                                layer.close(dIndex);
                                layer.msg(res.msg, {icon: 1});
                                tableReload();
                            } else if (res.code === 403) {
                                top.location.href = baseUrl + "/";
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }
                    })
                    return false;
                });
                $(layero).children('.layui-layer-content').css('overflow', 'visible');
                layui.form.render('select');
    function createFormDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            result[field.field] = defaultFieldValue(field);
        });
        return result;
    }
    function createDisplayDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            if (field.kind === 'foreign') {
                result[field.field] = '';
            }
        });
        return result;
    }
    /* 删除 */
    function del(ids) {
        layer.confirm('确定要删除选中数据吗?', {
            skin: 'layui-layer-admin',
            shade: .1
        }, function (i) {
            layer.close(i);
            var loadIndex = layer.load(2);
            $.ajax({
                url: baseUrl + "/basMap/delete/auth",
                headers: {'token': localStorage.getItem('token')},
                data: {ids: ids},
                method: 'POST',
                success: function (res) {
                    layer.close(loadIndex);
                    if (res.code === 200) {
                        layer.msg(res.msg, {icon: 1});
                        tableReload();
                    } else if (res.code === 403) {
                        top.location.href = baseUrl + "/";
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
    function createFormRules() {
        var rules = {};
        fieldMeta.forEach(function (field) {
            if (field.primaryKey || !field.required) {
                return;
            }
            rules[field.field] = [{
                required: true,
                message: (field.kind === 'date' || field.kind === 'enum' ? '请选择' : '请输入') + field.label,
                trigger: (field.kind === 'date' || field.kind === 'enum') ? 'change' : 'blur'
            }];
        });
        return rules;
    }
    function getTableValue(row, field) {
        var prop = field.tableProp || field.field;
        if (row && !isEmptyValue(row[prop])) {
            return row[prop];
        }
        return row ? row[field.field] : '';
    }
    function isCheckboxChecked(row, field) {
        var value = row ? row[field.field] : null;
        var activeValue = normalizeOptionValue(field, field.checkboxActiveRaw);
        return String(value) === String(activeValue);
    }
    function exportCell(value) {
        return stringValue(value).replace(/\t/g, ' ').replace(/\r?\n/g, ' ');
    }
    function escapeHtml(value) {
        return exportCell(value)
            .replace(/&/g, '&amp;')
            .replace(/</g, '&lt;')
            .replace(/>/g, '&gt;')
            .replace(/"/g, '&quot;')
            .replace(/'/g, '&#39;');
    }
    function buildPayload(form) {
        var payload = {};
        fieldMeta.forEach(function (field) {
            var value = form[field.field];
            if (field.primaryKey) {
                if (!isEmptyValue(value)) {
                    payload[field.field] = value;
                }
            })
                return;
            }
            if (field.kind === 'foreign' && isEmptyValue(value)) {
                value = null;
            }
            if (field.kind === 'enum' && value === '') {
                value = null;
            }
            if (field.kind === 'checkbox' && isEmptyValue(value)) {
                value = normalizeOptionValue(field, field.checkboxInactiveRaw);
            }
            if (field.valueType === 'number' && !isEmptyValue(value)) {
                value = Number(value);
            }
            if (field.valueType === 'number' && value === '') {
                value = null;
            }
            payload[field.field] = value;
        });
        return payload;
    }
    function fillFormFromRow(row, form, display) {
        fieldMeta.forEach(function (field) {
            if (field.primaryKey) {
                form[field.field] = row[field.field];
                return;
            }
            if (field.kind === 'date') {
                form[field.field] = row[field.tableProp] || row[field.field] || '';
                return;
            }
            if (field.kind === 'foreign') {
                form[field.field] = isEmptyValue(row[field.field]) ? '' : normalizeOptionValue(field, row[field.field]);
                if (display) {
                    display[field.field] = row[field.tableProp] || (isEmptyValue(row[field.field]) ? '' : String(row[field.field]));
                }
                return;
            }
            if (field.kind === 'enum') {
                form[field.field] = isEmptyValue(row[field.field]) ? '' : normalizeOptionValue(field, row[field.field]);
                return;
            }
            if (field.kind === 'checkbox') {
                form[field.field] = isEmptyValue(row[field.field])
                    ? normalizeOptionValue(field, field.checkboxInactiveRaw)
                    : normalizeOptionValue(field, row[field.field]);
                return;
            }
            form[field.field] = isEmptyValue(row[field.field])
                ? ''
                : (field.valueType === 'number' ? String(row[field.field]) : row[field.field]);
        });
    }
    // 搜索
    form.on('submit(search)', function (data) {
        pageCurr = 1;
        tableReload(false);
    });
    function resolveSearchParam(field) {
        if (field.kind === 'date' && field.columnName) {
            return field.columnName;
        }
        return field.field;
    }
    // 重置
    form.on('submit(reset)', function (data) {
        pageCurr = 1;
        clearFormVal($('#search-box'));
        tableReload(false);
    });
    // 时间选择器
    function layDateRender(data) {
    function createDownloadFile(filename, titles, rows) {
        var html = [
            '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">',
            '<head><meta charset="UTF-8"></head><body><table border="1"><thead><tr>',
            titles.map(function (title) {
                return '<th>' + escapeHtml(title) + '</th>';
            }).join(''),
            '</tr></thead><tbody>',
            (rows || []).map(function (row) {
                return '<tr>' + (row || []).map(function (value) {
                    return '<td style="mso-number-format:\\@;">' + escapeHtml(value) + '</td>';
                }).join('') + '</tr>';
            }).join(''),
            '</tbody></table></body></html>'
        ].join('');
        var blob = new Blob(['\ufeff' + html], {
            type: 'application/vnd.ms-excel;charset=utf-8;'
        });
        var anchor = document.createElement('a');
        anchor.href = URL.createObjectURL(blob);
        anchor.download = filename;
        document.body.appendChild(anchor);
        anchor.click();
        setTimeout(function () {
            layDate.render({
                elem: '.layui-laydate-range'
                , type: 'datetime'
                , range: true
            });
            layDate.render({
                elem: '#createTime\\$',
                type: 'datetime',
                value: data !== undefined ? data['createTime\\$'] : null
            });
            layDate.render({
                elem: '#updateTime\\$',
                type: 'datetime',
                value: data !== undefined ? data['updateTime\\$'] : null
            });
        }, 300);
            URL.revokeObjectURL(anchor.href);
            document.body.removeChild(anchor);
        }, 0);
    }
    layDateRender();
    function buildTimestamp() {
        var now = new Date();
        var pad = function (num) {
            return num < 10 ? '0' + num : String(num);
        };
        return now.getFullYear()
            + pad(now.getMonth() + 1)
            + pad(now.getDate())
            + '_'
            + pad(now.getHours())
            + pad(now.getMinutes())
            + pad(now.getSeconds());
    }
});
    function authHeaders() {
        return {
            token: localStorage.getItem('token')
        };
    }
// 关闭动作
$(document).on('click','#data-detail-close', function () {
    parent.layer.closeAll();
});
    function handleForbidden(res) {
        if (res && res.code === 403) {
            top.location.href = baseUrl + '/';
            return true;
        }
        return false;
    }
function tableReload(child) {
    var searchData = {};
    $.each($('#search-box [name]').serializeArray(), function() {
        searchData[this.name] = this.value;
    });
    tableIns.reload({
        where: searchData,
        page: {curr: pageCurr}
     });
}
    var sharedMethods = {
        authHeaders: authHeaders,
        handleForbidden: handleForbidden,
        valueOrDash: valueOrDash,
        stringValue: stringValue,
        getTableValue: getTableValue,
        isCheckboxChecked: isCheckboxChecked,
        normalizeOptionValue: normalizeOptionValue,
        isSortableField: isSortableField,
        getSuggestionFetcher: function (field) {
            var self = this;
            return function (queryString, callback) {
                self.fetchForeignSuggestions(field, queryString, callback);
            };
        },
        fetchForeignSuggestions: function (field, queryString, callback) {
            if (!field.foreignQuery || !queryString) {
                callback([]);
                return;
            }
            var self = this;
            $.ajax({
                url: baseUrl + '/' + field.foreignQuery + 'Query/auth',
                method: 'GET',
                headers: self.authHeaders(),
                data: { condition: queryString },
                success: function (res) {
                    if (self.handleForbidden(res)) {
                        return;
                    }
                    if (!res || res.code !== 200 || !Array.isArray(res.data)) {
                        callback([]);
                        return;
                    }
                    callback(res.data.map(function (item) {
                        return {
                            id: item.id,
                            value: item.value
                        };
                    }));
                },
                error: function () {
                    callback([]);
                }
            });
        },
        handleForeignSelect: function (field, item) {
            this.$set(this.displayTarget, field.field, item && item.value ? item.value : '');
            this.$set(this.formTarget, field.field, item && item.id !== undefined ? normalizeOptionValue(field, item.id) : '');
        },
        handleForeignInput: function (field) {
            if (!this.displayTarget || !this.formTarget) {
                return;
            }
            if (this.displayTarget[field.field]) {
                return;
            }
            this.$set(this.formTarget, field.field, '');
        }
    };
    if (document.getElementById('app')) {
        new Vue({
            el: '#app',
            data: function () {
                return {
                    fieldMeta: fieldMeta,
                    primaryKeyField: primaryKeyField,
                    loading: false,
                    exporting: false,
                    tableData: [],
                    selection: [],
                    advancedFiltersVisible: false,
                    allColumns: fieldMeta.slice(),
                    visibleColumnKeys: createDefaultVisibleColumnKeys(),
                    searchForm: createSearchDefaults(),
                    searchDisplay: createSearchDisplayDefaults(),
                    page: {
                        curr: 1,
                        limit: 15,
                        total: 0
                    },
                    sortState: {
                        prop: '',
                        order: ''
                    },
                    dialog: {
                        visible: false,
                        mode: 'create',
                        submitting: false
                    },
                    layoutTimer: null,
                    tableResizeHandler: null,
                    dialogForm: createFormDefaults(),
                    dialogDisplay: createDisplayDefaults(),
                    dialogRules: createFormRules()
                };
            },
            computed: {
                searchableFields: function () {
                    return this.fieldMeta.filter(function (field) {
                        return isSearchableField(field);
                    });
                },
                quickSearchableFields: function () {
                    var result = [];
                    this.searchableFields.forEach(function (field) {
                        if (result.length >= 3 || field.kind === 'date') {
                            return;
                        }
                        result.push(field);
                    });
                    return result;
                },
                advancedSearchableFields: function () {
                    var quickKeys = this.quickSearchableFields.map(function (field) {
                        return field.field;
                    });
                    return this.searchableFields.filter(function (field) {
                        return quickKeys.indexOf(field.field) === -1;
                    });
                },
                hasAdvancedFilters: function () {
                    return this.advancedSearchableFields.length > 0;
                },
                visibleColumns: function () {
                    var keys = this.visibleColumnKeys;
                    return this.allColumns.filter(function (field) {
                        return keys.indexOf(field.field) !== -1;
                    });
                },
                editableFields: function () {
                    return this.fieldMeta.filter(function (field) {
                        return !field.primaryKey;
                    });
                },
                exportColumns: function () {
                    return this.visibleColumns.map(function (field) {
                        return {
                            field: field.exportField || field.tableProp || field.field,
                            label: field.label
                        };
                    });
                },
                tableHeight: function () {
                    return this.advancedFiltersVisible && this.hasAdvancedFilters
                        ? 'calc(100vh - 390px)'
                        : 'calc(100vh - 300px)';
                },
                formTarget: function () {
                    return this.dialogForm;
                },
                displayTarget: function () {
                    return this.dialogDisplay;
                }
            },
            created: function () {
                this.loadTable();
            },
            mounted: function () {
                var self = this;
                self.requestTableLayout(80);
                self.tableResizeHandler = function () {
                    self.requestTableLayout(80);
                };
                window.addEventListener('resize', self.tableResizeHandler);
            },
            beforeDestroy: function () {
                if (this.layoutTimer) {
                    clearTimeout(this.layoutTimer);
                    this.layoutTimer = null;
                }
                if (this.tableResizeHandler) {
                    window.removeEventListener('resize', this.tableResizeHandler);
                    this.tableResizeHandler = null;
                }
            },
            methods: $.extend({}, sharedMethods, {
                requestTableLayout: function (delay) {
                    var self = this;
                    if (self.layoutTimer) {
                        clearTimeout(self.layoutTimer);
                    }
                    self.$nextTick(function () {
                        self.layoutTimer = setTimeout(function () {
                            var table = self.$refs.dataTable;
                            if (table && typeof table.doLayout === 'function') {
                                table.doLayout();
                            }
                        }, delay || 40);
                    });
                },
                isColumnVisible: function (fieldName) {
                    return this.visibleColumnKeys.indexOf(fieldName) !== -1;
                },
                toggleColumn: function (fieldName, visible) {
                    if (visible) {
                        if (this.visibleColumnKeys.indexOf(fieldName) === -1) {
                            this.visibleColumnKeys.push(fieldName);
                        }
                        this.requestTableLayout(80);
                        return;
                    }
                    if (this.visibleColumnKeys.length === 1) {
                        this.$message.warning('至少保留一列');
                        return;
                    }
                    this.visibleColumnKeys = this.visibleColumnKeys.filter(function (item) {
                        return item !== fieldName;
                    });
                    this.requestTableLayout(80);
                },
                selectAllColumns: function () {
                    this.visibleColumnKeys = createDefaultVisibleColumnKeys();
                    this.requestTableLayout(80);
                },
                resetColumns: function () {
                    this.visibleColumnKeys = createDefaultVisibleColumnKeys();
                    this.requestTableLayout(80);
                },
                toggleAdvancedFilters: function () {
                    this.advancedFiltersVisible = !this.advancedFiltersVisible;
                    this.requestTableLayout(260);
                },
                handleSearchForeignSelect: function (field, item) {
                    this.$set(this.searchDisplay, field.field, item && item.value ? item.value : '');
                    this.$set(this.searchForm, field.field, item && item.id !== undefined ? normalizeOptionValue(field, item.id) : '');
                },
                handleSearchForeignInput: function (field) {
                    if (this.searchDisplay[field.field]) {
                        return;
                    }
                    this.$set(this.searchForm, field.field, '');
                },
                buildQueryParams: function () {
                    var self = this;
                    var params = {
                        curr: self.page.curr,
                        limit: self.page.limit
                    };
                    if (self.searchForm.condition) {
                        params.condition = self.searchForm.condition;
                    }
                    self.searchableFields.forEach(function (field) {
                        var value = self.searchForm[field.field];
                        if (field.kind === 'date') {
                            if (value && value.length === 2) {
                                params[resolveSearchParam(field)] = value[0] + ' - ' + value[1];
                            }
                            return;
                        }
                        if (!isEmptyValue(value)) {
                            params[resolveSearchParam(field)] = value;
                        }
                    });
                    if (self.sortState.prop && self.sortState.order) {
                        params.orderByField = self.sortState.prop;
                        params.orderByType = self.sortState.order === 'ascending' ? 'asc' : 'desc';
                    }
                    return params;
                },
                loadTable: function () {
                    var self = this;
                    self.loading = true;
                    $.ajax({
                        url: baseUrl + '/' + simpleEntityName + '/list/auth',
                        method: 'GET',
                        headers: self.authHeaders(),
                        data: self.buildQueryParams(),
                        success: function (res) {
                            self.loading = false;
                            if (self.handleForbidden(res)) {
                                return;
                            }
                            if (!res || res.code !== 200) {
                                self.$message.error((res && res.msg) ? res.msg : '加载失败');
                                return;
                            }
                            var payload = res.data || {};
                            self.tableData = Array.isArray(payload.records) ? payload.records : [];
                            self.page.total = payload.total || 0;
                            self.requestTableLayout(80);
                        },
                        error: function () {
                            self.loading = false;
                            self.requestTableLayout(80);
                            self.$message.error('加载失败');
                        }
                    });
                },
                handleSearch: function () {
                    this.page.curr = 1;
                    this.loadTable();
                },
                handleReset: function () {
                    this.searchForm = createSearchDefaults();
                    this.searchDisplay = createSearchDisplayDefaults();
                    this.advancedFiltersVisible = false;
                    this.page.curr = 1;
                    this.sortState = {
                        prop: '',
                        order: ''
                    };
                    this.loadTable();
                },
                handleSelectionChange: function (rows) {
                    this.selection = rows || [];
                },
                handleSortChange: function (payload) {
                    this.sortState = {
                        prop: payload && payload.prop ? payload.prop : '',
                        order: payload && payload.order ? payload.order : ''
                    };
                    this.page.curr = 1;
                    this.loadTable();
                },
                handleCurrentChange: function (curr) {
                    this.page.curr = curr;
                    this.loadTable();
                },
                handleSizeChange: function (limit) {
                    this.page.limit = limit;
                    this.page.curr = 1;
                    this.loadTable();
                },
                resetDialogState: function () {
                    this.dialogForm = createFormDefaults();
                    this.dialogDisplay = createDisplayDefaults();
                    if (this.$refs.dialogForm) {
                        this.$refs.dialogForm.clearValidate();
                    }
                },
                openCreateDialog: function () {
                    this.dialog.mode = 'create';
                    this.dialog.visible = true;
                    this.$nextTick(this.resetDialogState);
                },
                openEditDialog: function (row) {
                    var self = this;
                    self.dialog.mode = 'edit';
                    self.dialog.visible = true;
                    self.$nextTick(function () {
                        self.resetDialogState();
                        fillFormFromRow(row, self.dialogForm, self.dialogDisplay);
                        if (self.$refs.dialogForm) {
                            self.$refs.dialogForm.clearValidate();
                        }
                    });
                },
                submitDialog: function () {
                    var self = this;
                    if (!self.$refs.dialogForm) {
                        return;
                    }
                    self.$refs.dialogForm.validate(function (valid) {
                        if (!valid) {
                            return false;
                        }
                        self.dialog.submitting = true;
                        $.ajax({
                            url: baseUrl + '/' + simpleEntityName + '/' + (self.dialog.mode === 'create' ? 'add' : 'update') + '/auth',
                            method: 'POST',
                            headers: self.authHeaders(),
                            data: buildPayload(self.dialogForm),
                            success: function (res) {
                                self.dialog.submitting = false;
                                if (self.handleForbidden(res)) {
                                    return;
                                }
                                if (!res || res.code !== 200) {
                                    self.$message.error((res && res.msg) ? res.msg : '保存失败');
                                    return;
                                }
                                self.$message.success(res.msg || '保存成功');
                                self.dialog.visible = false;
                                self.loadTable();
                            },
                            error: function () {
                                self.dialog.submitting = false;
                                self.$message.error('保存失败');
                            }
                        });
                        return true;
                    });
                },
                removeSelection: function () {
                    var self = this;
                    var ids = self.selection.map(function (row) {
                        return row[self.primaryKeyField];
                    });
                    self.removeRows(ids);
                },
                removeRows: function (ids) {
                    var self = this;
                    if (!ids || ids.length === 0) {
                        self.$message.warning('请选择要删除的数据');
                        return;
                    }
                    self.$confirm('确定删除选中的记录吗?', '提示', { type: 'warning' }).then(function () {
                        $.ajax({
                            url: baseUrl + '/' + simpleEntityName + '/delete/auth',
                            method: 'POST',
                            headers: self.authHeaders(),
                            traditional: true,
                            data: { 'ids[]': ids },
                            success: function (res) {
                                if (self.handleForbidden(res)) {
                                    return;
                                }
                                if (!res || res.code !== 200) {
                                    self.$message.error((res && res.msg) ? res.msg : '删除失败');
                                    return;
                                }
                                self.$message.success(res.msg || '删除成功');
                                self.selection = [];
                                if (self.tableData.length === ids.length && self.page.curr > 1) {
                                    self.page.curr = self.page.curr - 1;
                                }
                                self.loadTable();
                            },
                            error: function () {
                                self.$message.error('删除失败');
                            }
                        });
                    }).catch(function () {});
                },
                exportRows: function () {
                    var self = this;
                    self.exporting = true;
                    var requestBody = {
                        fields: self.exportColumns.map(function (item) {
                            return item.field;
                        })
                    };
                    requestBody[simpleEntityName] = self.buildQueryParams();
                    $.ajax({
                        url: baseUrl + '/' + simpleEntityName + '/export/auth',
                        method: 'POST',
                        headers: $.extend({ 'Content-Type': 'application/json;charset=UTF-8' }, self.authHeaders()),
                        data: JSON.stringify(requestBody),
                        success: function (res) {
                            self.exporting = false;
                            if (self.handleForbidden(res)) {
                                return;
                            }
                            if (!res || res.code !== 200) {
                                self.$message.error((res && res.msg) ? res.msg : '导出失败');
                                return;
                            }
                            createDownloadFile(
                                simpleEntityName + '_' + buildTimestamp() + '.xls',
                                self.exportColumns.map(function (item) {
                                    return item.label;
                                }),
                                Array.isArray(res.data) ? res.data : []
                            );
                            self.$message.success('导出成功');
                        },
                        error: function () {
                            self.exporting = false;
                            self.$message.error('导出失败');
                        }
                    });
                }
            })
        });
    }
})();
src/main/webapp/static/js/basRgv/basRgv.js
@@ -1,262 +1,931 @@
var pageCurr;
layui.config({
    base: baseUrl + "/static/layui/lay/modules/"
}).use(['table','laydate', 'form', 'admin'], function(){
    var table = layui.table;
    var $ = layui.jquery;
    var layer = layui.layer;
    var layDate = layui.laydate;
    var form = layui.form;
    var admin = layui.admin;
(function () {
    var simpleEntityName = 'basRgv';
    var entityName = 'BasRgv';
    var primaryKeyField = 'rgvNo';
    var fieldMeta = dedupeFieldMeta([
    {
        field: 'rgvNo',
        columnName: 'rgv_no',
        label: '编  号',
        tableProp: 'rgvNo',
        exportField: 'rgvNo',
        kind: 'text',
        valueType: 'number',
        required: true,
        primaryKey: true,
        sortable: true,
        textarea: false,
        minWidth: 90,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'status',
        columnName: 'status',
        label: '状  态',
        tableProp: 'status$',
        exportField: 'status$',
        kind: 'enum',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 120,
        enumOptions: [{ rawValue: '1', label: '正常' }, { rawValue: '0', label: '禁用' }],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'taskNo',
        columnName: 'task_no',
        label: '工 作 号',
        tableProp: 'taskNo',
        exportField: 'taskNo',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 116,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'createBy',
        columnName: 'create_by',
        label: '创建人员',
        tableProp: 'createBy',
        exportField: 'createBy',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'createTime',
        columnName: 'create_time',
        label: '创建时间',
        tableProp: 'createTime$',
        exportField: 'createTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'updateBy',
        columnName: 'update_by',
        label: '修改人员',
        tableProp: 'updateBy',
        exportField: 'updateBy',
        kind: 'text',
        valueType: 'number',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 110,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: '1',
        checkboxInactiveRaw: '0'
    },
    {
        field: 'updateTime',
        columnName: 'update_time',
        label: '修改时间',
        tableProp: 'updateTime$',
        exportField: 'updateTime$',
        kind: 'date',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: false,
        minWidth: 168,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    },
    {
        field: 'memo',
        columnName: 'memo',
        label: '备  注',
        tableProp: 'memo',
        exportField: 'memo',
        kind: 'text',
        valueType: 'string',
        required: false,
        primaryKey: false,
        sortable: false,
        textarea: true,
        minWidth: 180,
        enumOptions: [],
        foreignQuery: '',
        checkboxActiveRaw: 'Y',
        checkboxInactiveRaw: 'N'
    }
    // 数据渲染
    tableIns = table.render({
        elem: '#basRgv',
        headers: {token: localStorage.getItem('token')},
        url: baseUrl+'/basRgv/list/auth',
        page: true,
        limit: 15,
        limits: [15, 30, 50, 100, 200, 500],
        toolbar: '#toolbar',
        cellMinWidth: 50,
        height: 'full-120',
        cols: [[
            {type: 'checkbox'}
            ,{field: 'rgvNo', align: 'center',title: '编号'}
            ,{field: 'status$', align: 'center',title: '状态'}
            ,{field: 'taskNo', align: 'center',title: '工作号'}
            ,{field: 'createBy', align: 'center',title: '创建人员'}
            ,{field: 'createTime$', align: 'center',title: '创建时间'}
            ,{field: 'updateBy', align: 'center',title: '修改人员'}
            ,{field: 'updateTime$', align: 'center',title: '修改时间'}
            ,{field: 'memo', align: 'center',title: '备注'}
    ]);
            ,{fixed: 'right', title:'操作', align: 'center', toolbar: '#operate', width:120}
        ]],
        request: {
            pageName: 'curr',
            pageSize: 'limit'
        },
        parseData: function (res) {
            return {
                'code': res.code,
                'msg': res.msg,
                'count': res.data.total,
                'data': res.data.records
            }
        },
        response: {
            statusCode: 200
        },
        done: function(res, curr, count) {
            if (res.code === 403) {
                top.location.href = baseUrl+"/";
            }
            pageCurr=curr;
            limit();
    function formatFieldLabel(field) {
        var raw = field && field.label ? String(field.label).trim() : '';
        if (raw) {
            return raw;
        }
    });
    // 监听排序事件
    table.on('sort(basRgv)', function (obj) {
        var searchData = {};
        $.each($('#search-box [name]').serializeArray(), function() {
            searchData[this.name] = this.value;
        });
        searchData['orderByField'] = obj.field;
        searchData['orderByType'] = obj.type;
        tableIns.reload({
            where: searchData,
            page: {curr: 1}
        });
    });
    // 监听头工具栏事件
    table.on('toolbar(basRgv)', function (obj) {
        var checkStatus = table.checkStatus(obj.config.id).data;
        switch(obj.event) {
            case 'addData':
                showEditModel();
                break;
            case 'deleteData':
               if (checkStatus.length === 0) {
                   layer.msg('请选择要删除的数据', {icon: 2});
                   return;
               }
               del(checkStatus.map(function (d) {
                   return d.rgvNo;
               }));
               break;
            case 'exportData':
                admin.confirm('确定导出Excel吗', {shadeClose: true}, function(){
                    var titles=[];
                    var fields=[];
                    obj.config.cols[0].map(function (col) {
                        if (col.type === 'normal' && col.hide === false && col.toolbar == null) {
                            titles.push(col.title);
                            fields.push(col.field);
                        }
                    });
                    var exportData = {};
                    $.each($('#search-box [name]').serializeArray(), function() {
                        exportData[this.name] = this.value;
                    });
                    var param = {
                        'basRgv': exportData,
                        'fields': fields
                    };
                    $.ajax({
                        url: baseUrl+"/basRgv/export/auth",
                        headers: {'token': localStorage.getItem('token')},
                        data: JSON.stringify(param),
                        dataType:'json',
                        contentType:'application/json;charset=UTF-8',
                        method: 'POST',
                        success: function (res) {
                            layer.closeAll();
                            if (res.code === 200) {
                                table.exportFile(titles,res.data,'xls');
                            } else if (res.code === 403) {
                                top.location.href = baseUrl+"/";
                            } else {
                                layer.msg(res.msg, {icon: 2})
                            }
                        }
                    });
                });
                break;
        raw = field && field.columnName ? field.columnName : (field && field.field ? field.field : '');
        if (!raw) {
            return '';
        }
    });
    // 监听行工具事件
    table.on('tool(basRgv)', function(obj){
        var data = obj.data;
        switch (obj.event) {
            case 'edit':
                showEditModel(data);
                break;
            case "del":
                del([data.rgvNo]);
                break;
        }
    });
    /* 弹窗 - 新增、修改 */
    function showEditModel(mData) {
        admin.open({
            type: 1,
            area: '600px',
            title: (mData ? '修改' : '添加') + 'RGV',
            content: $('#editDialog').html(),
            success: function (layero, dIndex) {
                layDateRender(mData);
                form.val('detail', mData);
                form.on('submit(editSubmit)', function (data) {
                    var loadIndex = layer.load(2);
                    $.ajax({
                        url: baseUrl+"/basRgv/"+(mData?'update':'add')+"/auth",
                        headers: {'token': localStorage.getItem('token')},
                        data: data.field,
                        method: 'POST',
                        success: function (res) {
                            layer.close(loadIndex);
                            if (res.code === 200){
                                layer.close(dIndex);
                                layer.msg(res.msg, {icon: 1});
                                tableReload();
                            } else if (res.code === 403){
                                top.location.href = baseUrl+"/";
                            }else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }
                    })
                    return false;
                });
                $(layero).children('.layui-layer-content').css('overflow', 'visible');
                layui.form.render('select');
            }
        raw = String(raw)
            .replace(/\$/g, '')
            .replace(/([a-z0-9])([A-Z])/g, '$1_$2')
            .replace(/_/g, ' ')
            .replace(/\s+/g, ' ')
            .trim();
        return raw.replace(/\b[a-z]/g, function (letter) {
            return letter.toUpperCase();
        });
    }
    /* 删除 */
    function del(ids) {
        layer.confirm('确定要删除选中数据吗?', {
            skin: 'layui-layer-admin',
            shade: .1
        }, function (i) {
            layer.close(i);
            var loadIndex = layer.load(2);
    function dedupeFieldMeta(list) {
        var result = [];
        var seen = {};
        (list || []).forEach(function (field) {
            if (!field || !field.field || seen[field.field]) {
                return;
            }
            field.label = formatFieldLabel(field);
            seen[field.field] = true;
            result.push(field);
        });
        return result;
    }
    function isEmptyValue(value) {
        return value === null || value === undefined || value === '';
    }
    function stringValue(value) {
        return isEmptyValue(value) ? '' : String(value);
    }
    function valueOrDash(value) {
        return isEmptyValue(value) ? '--' : value;
    }
    function normalizeOptionValue(field, rawValue) {
        if (rawValue === null || rawValue === undefined) {
            return null;
        }
        if (rawValue === '') {
            return '';
        }
        if (field && field.valueType === 'number') {
            var numberVal = Number(rawValue);
            return isNaN(numberVal) ? rawValue : numberVal;
        }
        return String(rawValue);
    }
    function isSearchableField(field) {
        return !!field && field.kind !== 'image' && !field.textarea;
    }
    function isSortableField(field) {
        if (!field) {
            return false;
        }
        if (field.primaryKey) {
            return true;
        }
        return field.kind !== 'image' && !field.textarea && field.kind !== 'foreign';
    }
    function defaultFieldValue(field) {
        if (field.primaryKey) {
            return null;
        }
        if (field.kind === 'checkbox') {
            return normalizeOptionValue(field, field.checkboxInactiveRaw);
        }
        return '';
    }
    function defaultSearchFieldValue(field) {
        if (field.kind === 'date') {
            return [];
        }
        if (field.kind === 'enum' || field.kind === 'checkbox') {
            return null;
        }
        return '';
    }
    function createSearchDefaults() {
        var result = {
            condition: ''
        };
        fieldMeta.forEach(function (field) {
            if (!isSearchableField(field)) {
                return;
            }
            result[field.field] = defaultSearchFieldValue(field);
        });
        return result;
    }
    function createSearchDisplayDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            if (field.kind === 'foreign' && isSearchableField(field)) {
                result[field.field] = '';
            }
        });
        return result;
    }
    function createDefaultVisibleColumnKeys() {
        return fieldMeta.map(function (field) {
            return field.field;
        });
    }
    function createFormDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            result[field.field] = defaultFieldValue(field);
        });
        return result;
    }
    function createDisplayDefaults() {
        var result = {};
        fieldMeta.forEach(function (field) {
            if (field.kind === 'foreign') {
                result[field.field] = '';
            }
        });
        return result;
    }
    function createFormRules() {
        var rules = {};
        fieldMeta.forEach(function (field) {
            if (field.primaryKey || !field.required) {
                return;
            }
            rules[field.field] = [{
                required: true,
                message: (field.kind === 'date' || field.kind === 'enum' ? '请选择' : '请输入') + field.label,
                trigger: (field.kind === 'date' || field.kind === 'enum') ? 'change' : 'blur'
            }];
        });
        return rules;
    }
    function getTableValue(row, field) {
        var prop = field.tableProp || field.field;
        if (row && !isEmptyValue(row[prop])) {
            return row[prop];
        }
        return row ? row[field.field] : '';
    }
    function isCheckboxChecked(row, field) {
        var value = row ? row[field.field] : null;
        var activeValue = normalizeOptionValue(field, field.checkboxActiveRaw);
        return String(value) === String(activeValue);
    }
    function exportCell(value) {
        return stringValue(value).replace(/\t/g, ' ').replace(/\r?\n/g, ' ');
    }
    function escapeHtml(value) {
        return exportCell(value)
            .replace(/&/g, '&amp;')
            .replace(/</g, '&lt;')
            .replace(/>/g, '&gt;')
            .replace(/"/g, '&quot;')
            .replace(/'/g, '&#39;');
    }
    function buildPayload(form) {
        var payload = {};
        fieldMeta.forEach(function (field) {
            var value = form[field.field];
            if (field.primaryKey) {
                if (!isEmptyValue(value)) {
                    payload[field.field] = value;
                }
                return;
            }
            if (field.kind === 'foreign' && isEmptyValue(value)) {
                value = null;
            }
            if (field.kind === 'enum' && value === '') {
                value = null;
            }
            if (field.kind === 'checkbox' && isEmptyValue(value)) {
                value = normalizeOptionValue(field, field.checkboxInactiveRaw);
            }
            if (field.valueType === 'number' && !isEmptyValue(value)) {
                value = Number(value);
            }
            if (field.valueType === 'number' && value === '') {
                value = null;
            }
            payload[field.field] = value;
        });
        return payload;
    }
    function fillFormFromRow(row, form, display) {
        fieldMeta.forEach(function (field) {
            if (field.primaryKey) {
                form[field.field] = row[field.field];
                return;
            }
            if (field.kind === 'date') {
                form[field.field] = row[field.tableProp] || row[field.field] || '';
                return;
            }
            if (field.kind === 'foreign') {
                form[field.field] = isEmptyValue(row[field.field]) ? '' : normalizeOptionValue(field, row[field.field]);
                if (display) {
                    display[field.field] = row[field.tableProp] || (isEmptyValue(row[field.field]) ? '' : String(row[field.field]));
                }
                return;
            }
            if (field.kind === 'enum') {
                form[field.field] = isEmptyValue(row[field.field]) ? '' : normalizeOptionValue(field, row[field.field]);
                return;
            }
            if (field.kind === 'checkbox') {
                form[field.field] = isEmptyValue(row[field.field])
                    ? normalizeOptionValue(field, field.checkboxInactiveRaw)
                    : normalizeOptionValue(field, row[field.field]);
                return;
            }
            form[field.field] = isEmptyValue(row[field.field])
                ? ''
                : (field.valueType === 'number' ? String(row[field.field]) : row[field.field]);
        });
    }
    function resolveSearchParam(field) {
        if (field.kind === 'date' && field.columnName) {
            return field.columnName;
        }
        return field.field;
    }
    function createDownloadFile(filename, titles, rows) {
        var html = [
            '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">',
            '<head><meta charset="UTF-8"></head><body><table border="1"><thead><tr>',
            titles.map(function (title) {
                return '<th>' + escapeHtml(title) + '</th>';
            }).join(''),
            '</tr></thead><tbody>',
            (rows || []).map(function (row) {
                return '<tr>' + (row || []).map(function (value) {
                    return '<td style="mso-number-format:\\@;">' + escapeHtml(value) + '</td>';
                }).join('') + '</tr>';
            }).join(''),
            '</tbody></table></body></html>'
        ].join('');
        var blob = new Blob(['\ufeff' + html], {
            type: 'application/vnd.ms-excel;charset=utf-8;'
        });
        var anchor = document.createElement('a');
        anchor.href = URL.createObjectURL(blob);
        anchor.download = filename;
        document.body.appendChild(anchor);
        anchor.click();
        setTimeout(function () {
            URL.revokeObjectURL(anchor.href);
            document.body.removeChild(anchor);
        }, 0);
    }
    function buildTimestamp() {
        var now = new Date();
        var pad = function (num) {
            return num < 10 ? '0' + num : String(num);
        };
        return now.getFullYear()
            + pad(now.getMonth() + 1)
            + pad(now.getDate())
            + '_'
            + pad(now.getHours())
            + pad(now.getMinutes())
            + pad(now.getSeconds());
    }
    function authHeaders() {
        return {
            token: localStorage.getItem('token')
        };
    }
    function handleForbidden(res) {
        if (res && res.code === 403) {
            top.location.href = baseUrl + '/';
            return true;
        }
        return false;
    }
    var sharedMethods = {
        authHeaders: authHeaders,
        handleForbidden: handleForbidden,
        valueOrDash: valueOrDash,
        stringValue: stringValue,
        getTableValue: getTableValue,
        isCheckboxChecked: isCheckboxChecked,
        normalizeOptionValue: normalizeOptionValue,
        isSortableField: isSortableField,
        getSuggestionFetcher: function (field) {
            var self = this;
            return function (queryString, callback) {
                self.fetchForeignSuggestions(field, queryString, callback);
            };
        },
        fetchForeignSuggestions: function (field, queryString, callback) {
            if (!field.foreignQuery || !queryString) {
                callback([]);
                return;
            }
            var self = this;
            $.ajax({
                url: baseUrl+"/basRgv/delete/auth",
                headers: {'token': localStorage.getItem('token')},
                data: {ids: ids},
                method: 'POST',
                url: baseUrl + '/' + field.foreignQuery + 'Query/auth',
                method: 'GET',
                headers: self.authHeaders(),
                data: { condition: queryString },
                success: function (res) {
                    layer.close(loadIndex);
                    if (res.code === 200){
                        layer.msg(res.msg, {icon: 1});
                        tableReload();
                    } else if (res.code === 403){
                        top.location.href = baseUrl+"/";
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    if (self.handleForbidden(res)) {
                        return;
                    }
                    if (!res || res.code !== 200 || !Array.isArray(res.data)) {
                        callback([]);
                        return;
                    }
                    callback(res.data.map(function (item) {
                        return {
                            id: item.id,
                            value: item.value
                        };
                    }));
                },
                error: function () {
                    callback([]);
                }
            });
        },
        handleForeignSelect: function (field, item) {
            this.$set(this.displayTarget, field.field, item && item.value ? item.value : '');
            this.$set(this.formTarget, field.field, item && item.id !== undefined ? normalizeOptionValue(field, item.id) : '');
        },
        handleForeignInput: function (field) {
            if (!this.displayTarget || !this.formTarget) {
                return;
            }
            if (this.displayTarget[field.field]) {
                return;
            }
            this.$set(this.formTarget, field.field, '');
        }
    };
    if (document.getElementById('app')) {
        new Vue({
            el: '#app',
            data: function () {
                return {
                    fieldMeta: fieldMeta,
                    primaryKeyField: primaryKeyField,
                    loading: false,
                    exporting: false,
                    tableData: [],
                    selection: [],
                    advancedFiltersVisible: false,
                    allColumns: fieldMeta.slice(),
                    visibleColumnKeys: createDefaultVisibleColumnKeys(),
                    searchForm: createSearchDefaults(),
                    searchDisplay: createSearchDisplayDefaults(),
                    page: {
                        curr: 1,
                        limit: 15,
                        total: 0
                    },
                    sortState: {
                        prop: '',
                        order: ''
                    },
                    dialog: {
                        visible: false,
                        mode: 'create',
                        submitting: false
                    },
                    layoutTimer: null,
                    tableResizeHandler: null,
                    dialogForm: createFormDefaults(),
                    dialogDisplay: createDisplayDefaults(),
                    dialogRules: createFormRules()
                };
            },
            computed: {
                searchableFields: function () {
                    return this.fieldMeta.filter(function (field) {
                        return isSearchableField(field);
                    });
                },
                quickSearchableFields: function () {
                    var result = [];
                    this.searchableFields.forEach(function (field) {
                        if (result.length >= 3 || field.kind === 'date') {
                            return;
                        }
                        result.push(field);
                    });
                    return result;
                },
                advancedSearchableFields: function () {
                    var quickKeys = this.quickSearchableFields.map(function (field) {
                        return field.field;
                    });
                    return this.searchableFields.filter(function (field) {
                        return quickKeys.indexOf(field.field) === -1;
                    });
                },
                hasAdvancedFilters: function () {
                    return this.advancedSearchableFields.length > 0;
                },
                visibleColumns: function () {
                    var keys = this.visibleColumnKeys;
                    return this.allColumns.filter(function (field) {
                        return keys.indexOf(field.field) !== -1;
                    });
                },
                editableFields: function () {
                    return this.fieldMeta.filter(function (field) {
                        return !field.primaryKey;
                    });
                },
                exportColumns: function () {
                    return this.visibleColumns.map(function (field) {
                        return {
                            field: field.exportField || field.tableProp || field.field,
                            label: field.label
                        };
                    });
                },
                tableHeight: function () {
                    return this.advancedFiltersVisible && this.hasAdvancedFilters
                        ? 'calc(100vh - 390px)'
                        : 'calc(100vh - 300px)';
                },
                formTarget: function () {
                    return this.dialogForm;
                },
                displayTarget: function () {
                    return this.dialogDisplay;
                }
            },
            created: function () {
                this.loadTable();
            },
            mounted: function () {
                var self = this;
                self.requestTableLayout(80);
                self.tableResizeHandler = function () {
                    self.requestTableLayout(80);
                };
                window.addEventListener('resize', self.tableResizeHandler);
            },
            beforeDestroy: function () {
                if (this.layoutTimer) {
                    clearTimeout(this.layoutTimer);
                    this.layoutTimer = null;
                }
                if (this.tableResizeHandler) {
                    window.removeEventListener('resize', this.tableResizeHandler);
                    this.tableResizeHandler = null;
                }
            },
            methods: $.extend({}, sharedMethods, {
                requestTableLayout: function (delay) {
                    var self = this;
                    if (self.layoutTimer) {
                        clearTimeout(self.layoutTimer);
                    }
                    self.$nextTick(function () {
                        self.layoutTimer = setTimeout(function () {
                            var table = self.$refs.dataTable;
                            if (table && typeof table.doLayout === 'function') {
                                table.doLayout();
                            }
                        }, delay || 40);
                    });
                },
                isColumnVisible: function (fieldName) {
                    return this.visibleColumnKeys.indexOf(fieldName) !== -1;
                },
                toggleColumn: function (fieldName, visible) {
                    if (visible) {
                        if (this.visibleColumnKeys.indexOf(fieldName) === -1) {
                            this.visibleColumnKeys.push(fieldName);
                        }
                        this.requestTableLayout(80);
                        return;
                    }
                    if (this.visibleColumnKeys.length === 1) {
                        this.$message.warning('至少保留一列');
                        return;
                    }
                    this.visibleColumnKeys = this.visibleColumnKeys.filter(function (item) {
                        return item !== fieldName;
                    });
                    this.requestTableLayout(80);
                },
                selectAllColumns: function () {
                    this.visibleColumnKeys = createDefaultVisibleColumnKeys();
                    this.requestTableLayout(80);
                },
                resetColumns: function () {
                    this.visibleColumnKeys = createDefaultVisibleColumnKeys();
                    this.requestTableLayout(80);
                },
                toggleAdvancedFilters: function () {
                    this.advancedFiltersVisible = !this.advancedFiltersVisible;
                    this.requestTableLayout(260);
                },
                handleSearchForeignSelect: function (field, item) {
                    this.$set(this.searchDisplay, field.field, item && item.value ? item.value : '');
                    this.$set(this.searchForm, field.field, item && item.id !== undefined ? normalizeOptionValue(field, item.id) : '');
                },
                handleSearchForeignInput: function (field) {
                    if (this.searchDisplay[field.field]) {
                        return;
                    }
                    this.$set(this.searchForm, field.field, '');
                },
                buildQueryParams: function () {
                    var self = this;
                    var params = {
                        curr: self.page.curr,
                        limit: self.page.limit
                    };
                    if (self.searchForm.condition) {
                        params.condition = self.searchForm.condition;
                    }
                    self.searchableFields.forEach(function (field) {
                        var value = self.searchForm[field.field];
                        if (field.kind === 'date') {
                            if (value && value.length === 2) {
                                params[resolveSearchParam(field)] = value[0] + ' - ' + value[1];
                            }
                            return;
                        }
                        if (!isEmptyValue(value)) {
                            params[resolveSearchParam(field)] = value;
                        }
                    });
                    if (self.sortState.prop && self.sortState.order) {
                        params.orderByField = self.sortState.prop;
                        params.orderByType = self.sortState.order === 'ascending' ? 'asc' : 'desc';
                    }
                    return params;
                },
                loadTable: function () {
                    var self = this;
                    self.loading = true;
                    $.ajax({
                        url: baseUrl + '/' + simpleEntityName + '/list/auth',
                        method: 'GET',
                        headers: self.authHeaders(),
                        data: self.buildQueryParams(),
                        success: function (res) {
                            self.loading = false;
                            if (self.handleForbidden(res)) {
                                return;
                            }
                            if (!res || res.code !== 200) {
                                self.$message.error((res && res.msg) ? res.msg : '加载失败');
                                return;
                            }
                            var payload = res.data || {};
                            self.tableData = Array.isArray(payload.records) ? payload.records : [];
                            self.page.total = payload.total || 0;
                            self.requestTableLayout(80);
                        },
                        error: function () {
                            self.loading = false;
                            self.requestTableLayout(80);
                            self.$message.error('加载失败');
                        }
                    });
                },
                handleSearch: function () {
                    this.page.curr = 1;
                    this.loadTable();
                },
                handleReset: function () {
                    this.searchForm = createSearchDefaults();
                    this.searchDisplay = createSearchDisplayDefaults();
                    this.advancedFiltersVisible = false;
                    this.page.curr = 1;
                    this.sortState = {
                        prop: '',
                        order: ''
                    };
                    this.loadTable();
                },
                handleSelectionChange: function (rows) {
                    this.selection = rows || [];
                },
                handleSortChange: function (payload) {
                    this.sortState = {
                        prop: payload && payload.prop ? payload.prop : '',
                        order: payload && payload.order ? payload.order : ''
                    };
                    this.page.curr = 1;
                    this.loadTable();
                },
                handleCurrentChange: function (curr) {
                    this.page.curr = curr;
                    this.loadTable();
                },
                handleSizeChange: function (limit) {
                    this.page.limit = limit;
                    this.page.curr = 1;
                    this.loadTable();
                },
                resetDialogState: function () {
                    this.dialogForm = createFormDefaults();
                    this.dialogDisplay = createDisplayDefaults();
                    if (this.$refs.dialogForm) {
                        this.$refs.dialogForm.clearValidate();
                    }
                },
                openCreateDialog: function () {
                    this.dialog.mode = 'create';
                    this.dialog.visible = true;
                    this.$nextTick(this.resetDialogState);
                },
                openEditDialog: function (row) {
                    var self = this;
                    self.dialog.mode = 'edit';
                    self.dialog.visible = true;
                    self.$nextTick(function () {
                        self.resetDialogState();
                        fillFormFromRow(row, self.dialogForm, self.dialogDisplay);
                        if (self.$refs.dialogForm) {
                            self.$refs.dialogForm.clearValidate();
                        }
                    });
                },
                submitDialog: function () {
                    var self = this;
                    if (!self.$refs.dialogForm) {
                        return;
                    }
                    self.$refs.dialogForm.validate(function (valid) {
                        if (!valid) {
                            return false;
                        }
                        self.dialog.submitting = true;
                        $.ajax({
                            url: baseUrl + '/' + simpleEntityName + '/' + (self.dialog.mode === 'create' ? 'add' : 'update') + '/auth',
                            method: 'POST',
                            headers: self.authHeaders(),
                            data: buildPayload(self.dialogForm),
                            success: function (res) {
                                self.dialog.submitting = false;
                                if (self.handleForbidden(res)) {
                                    return;
                                }
                                if (!res || res.code !== 200) {
                                    self.$message.error((res && res.msg) ? res.msg : '保存失败');
                                    return;
                                }
                                self.$message.success(res.msg || '保存成功');
                                self.dialog.visible = false;
                                self.loadTable();
                            },
                            error: function () {
                                self.dialog.submitting = false;
                                self.$message.error('保存失败');
                            }
                        });
                        return true;
                    });
                },
                removeSelection: function () {
                    var self = this;
                    var ids = self.selection.map(function (row) {
                        return row[self.primaryKeyField];
                    });
                    self.removeRows(ids);
                },
                removeRows: function (ids) {
                    var self = this;
                    if (!ids || ids.length === 0) {
                        self.$message.warning('请选择要删除的数据');
                        return;
                    }
                    self.$confirm('确定删除选中的记录吗?', '提示', { type: 'warning' }).then(function () {
                        $.ajax({
                            url: baseUrl + '/' + simpleEntityName + '/delete/auth',
                            method: 'POST',
                            headers: self.authHeaders(),
                            traditional: true,
                            data: { 'ids[]': ids },
                            success: function (res) {
                                if (self.handleForbidden(res)) {
                                    return;
                                }
                                if (!res || res.code !== 200) {
                                    self.$message.error((res && res.msg) ? res.msg : '删除失败');
                                    return;
                                }
                                self.$message.success(res.msg || '删除成功');
                                self.selection = [];
                                if (self.tableData.length === ids.length && self.page.curr > 1) {
                                    self.page.curr = self.page.curr - 1;
                                }
                                self.loadTable();
                            },
                            error: function () {
                                self.$message.error('删除失败');
                            }
                        });
                    }).catch(function () {});
                },
                exportRows: function () {
                    var self = this;
                    self.exporting = true;
                    var requestBody = {
                        fields: self.exportColumns.map(function (item) {
                            return item.field;
                        })
                    };
                    requestBody[simpleEntityName] = self.buildQueryParams();
                    $.ajax({
                        url: baseUrl + '/' + simpleEntityName + '/export/auth',
                        method: 'POST',
                        headers: $.extend({ 'Content-Type': 'application/json;charset=UTF-8' }, self.authHeaders()),
                        data: JSON.stringify(requestBody),
                        success: function (res) {
                            self.exporting = false;
                            if (self.handleForbidden(res)) {
                                return;
                            }
                            if (!res || res.code !== 200) {
                                self.$message.error((res && res.msg) ? res.msg : '导出失败');
                                return;
                            }
                            createDownloadFile(
                                simpleEntityName + '_' + buildTimestamp() + '.xls',
                                self.exportColumns.map(function (item) {
                                    return item.label;
                                }),
                                Array.isArray(res.data) ? res.data : []
                            );
                            self.$message.success('导出成功');
                        },
                        error: function () {
                            self.exporting = false;
                            self.$message.error('导出失败');
                        }
                    });
                }
            })
        });
    }
    // 搜索
    form.on('submit(search)', function (data) {
        pageCurr = 1;
        tableReload(false);
    });
    // 重置
    form.on('submit(reset)', function (data) {
        pageCurr = 1;
        clearFormVal($('#search-box'));
        tableReload(false);
    });
    // 时间选择器
    function layDateRender(data) {
        setTimeout(function () {
            layDate.render({
                elem: '.layui-laydate-range'
                ,type: 'datetime'
                ,range: true
            });
            layDate.render({
                elem: '#createTime\\$',
                type: 'datetime',
                value: data!==undefined?data['createTime\\$']:null
            });
            layDate.render({
                elem: '#updateTime\\$',
                type: 'datetime',
                value: data!==undefined?data['updateTime\\$']:null
            });
        }, 300);
    }
    layDateRender();
});
// 关闭动作
$(document).on('click','#data-detail-close', function () {
    parent.layer.closeAll();
});
function tableReload(child) {
    var searchData = {};
    $.each($('#search-box [name]').serializeArray(), function() {
        searchData[this.name] = this.value;
    });
    tableIns.reload({
        where: searchData,
        page: {curr: pageCurr}
     });
}
})();
Diff truncated after the above file
src/main/webapp/static/js/basRgvErr/basRgvErr.js src/main/webapp/static/js/basRgvErrLog/basRgvErrLog.js src/main/webapp/static/js/basRgvOpt/basRgvOpt.js src/main/webapp/static/js/basStation/basStation.js src/main/webapp/static/js/basStationOpt/basStationOpt.js src/main/webapp/static/js/basWrkIotype/basWrkIotype.js src/main/webapp/static/js/basWrkStatus/basWrkStatus.js src/main/webapp/static/js/config/config.js src/main/webapp/static/js/detail/detail.js src/main/webapp/static/js/deviceConfig/deviceConfig.js src/main/webapp/static/js/httpRequestLog/httpRequestLog.js src/main/webapp/static/js/locMast/locMast.js src/main/webapp/static/js/login/login.js src/main/webapp/static/js/operateLog/operateLog.js src/main/webapp/static/js/password/password.js src/main/webapp/static/js/permission/permission.js src/main/webapp/static/js/resource/resource.js src/main/webapp/static/js/role/role.js src/main/webapp/static/js/user/user.js src/main/webapp/static/js/userLogin/userLogin.js src/main/webapp/static/js/wrkLastno/wrkLastno.js src/main/webapp/static/js/wrkMastLog/wrkMastLog.js src/main/webapp/views/apiLog/apiLog.html src/main/webapp/views/basCrnp/basCrnp.html src/main/webapp/views/basCrnp/basCrnp_detail.html (deleted) src/main/webapp/views/basCrnpErr/basCrnpErr.html src/main/webapp/views/basCrnpErr/basCrnpErr_detail.html (deleted) src/main/webapp/views/basCrnpErrLog/basCrnpErrLog.html src/main/webapp/views/basCrnpErrLog/basCrnpErrLog_detail.html (deleted) src/main/webapp/views/basCrnpOpt/basCrnpOpt.html src/main/webapp/views/basCrnpOpt/basCrnpOpt_detail.html (deleted) src/main/webapp/views/basDevp/basDevp.html src/main/webapp/views/basDevp/basDevp_detail.html (deleted) src/main/webapp/views/basDualCrnp/basDualCrnp.html src/main/webapp/views/basDualCrnp/basDualCrnp_detail.html (deleted) src/main/webapp/views/basDualCrnpErr/basDualCrnpErr.html src/main/webapp/views/basDualCrnpErr/basDualCrnpErr_detail.html (deleted) src/main/webapp/views/basDualCrnpErrLog/basDualCrnpErrLog.html src/main/webapp/views/basDualCrnpErrLog/basDualCrnpErrLog_detail.html (deleted) src/main/webapp/views/basDualCrnpOpt/basDualCrnpOpt.html src/main/webapp/views/basDualCrnpOpt/basDualCrnpOpt_detail.html (deleted) src/main/webapp/views/basLocSts/basLocSts.html src/main/webapp/views/basLocSts/basLocSts_detail.html (deleted) src/main/webapp/views/basMap/basMap.html src/main/webapp/views/basMap/basMap_detail.html (deleted) src/main/webapp/views/basRgv/basRgv.html src/main/webapp/views/basRgv/basRgv_detail.html (deleted) src/main/webapp/views/basRgvErr/basRgvErr.html src/main/webapp/views/basRgvErr/basRgvErr_detail.html (deleted) src/main/webapp/views/basRgvErrLog/basRgvErrLog.html src/main/webapp/views/basRgvErrLog/basRgvErrLog_detail.html (deleted) src/main/webapp/views/basRgvOpt/basRgvOpt.html src/main/webapp/views/basRgvOpt/basRgvOpt_detail.html (deleted) src/main/webapp/views/basStation/basStation.html src/main/webapp/views/basStation/basStation_detail.html (deleted) src/main/webapp/views/basStationOpt/basStationOpt.html src/main/webapp/views/basStationOpt/basStationOpt_detail.html (deleted) src/main/webapp/views/basWrkIotype/basWrkIotype.html src/main/webapp/views/basWrkIotype/basWrkIotype_detail.html (deleted) src/main/webapp/views/basWrkStatus/basWrkStatus.html src/main/webapp/views/basWrkStatus/basWrkStatus_detail.html (deleted) src/main/webapp/views/config/config.html src/main/webapp/views/config/config_detail.html (deleted) src/main/webapp/views/detail.html src/main/webapp/views/deviceConfig/deviceConfig.html src/main/webapp/views/deviceConfig/deviceConfig_detail.html (deleted) src/main/webapp/views/httpRequestLog/httpRequestLog.html src/main/webapp/views/httpRequestLog/httpRequestLog_detail.html (deleted) src/main/webapp/views/locMast/locMast.html src/main/webapp/views/locMast/locMast_detail.html (deleted) src/main/webapp/views/login.html src/main/webapp/views/operateLog/operateLog.html src/main/webapp/views/operateLog/operateLog_detail.html (deleted) src/main/webapp/views/password.html src/main/webapp/views/permission/permission.html src/main/webapp/views/permission/permission_detail.html (deleted) src/main/webapp/views/resource/resource.html src/main/webapp/views/role/role.html src/main/webapp/views/role/role_detail.html (deleted) src/main/webapp/views/user/user.html src/main/webapp/views/user/user_detail.html (deleted) src/main/webapp/views/userLogin/userLogin.html src/main/webapp/views/userLogin/userLogin_detail.html (deleted) src/main/webapp/views/watch/console.html src/main/webapp/views/wrkLastno/wrkLastno.html src/main/webapp/views/wrkLastno/wrkLastno_detail.html (deleted) src/main/webapp/views/wrkMast/wrkMast.html src/main/webapp/views/wrkMastLog/wrkMastLog.html src/main/webapp/views/wrkMastLog/wrkMastLog_detail.html (deleted)