You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

234 lines
9.7 KiB

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="../../../component/layui/css/layui.css" />
<style>
html,
body {
height: 100%;
margin: 0;
overflow: hidden;
}
</style>
</head>
<body class="layui-bg-gray">
默认分割线
<hr>
<div class="layui-row layui-col-space10" style="height: 100%;">
<div class="layui-col-md2">
<div class="layui-card" style="margin-top: 10px;margin-left: 10px;">
<div class="layui-card-body">
<ul class="layui-menu" id="sheetListView">
</ul>
<script id="sheetListScript" type="text/html">
{{# layui.each(d, function(index, item){ }}
<li lay-options="{ id: '{{item.sheet_index}}',table_name:'{{item.table_name}}' }" class="{{ index == 0 ? 'layui-menu-item-checked' : '' }}" >
<div class="layui-menu-body-title">
<a href="javascript:;">{{item.sheet_name}}</a>
{{# if(item.is_check==1){ }}
<i class="layui-icon layui-icon-ok-circle"
style="font-size: 18px; color: #04B543;margin-top: -10px;"></i>
{{# } }}
</div>
</li>
{{# }); }}
</select>
</script>
</div>
</div>
</div>
<div class="layui-col-md10" style="height: 100%;">
<div class="layui-card" style="margin-top: 10px;margin-right: 10px;height: calc(100% - 10px);">
<div class="layui-inline" style="margin-top: 15px;margin-bottom: 5px;">
<label class="layui-form-label" style="width: auto;margin-left: 1px;">数据库表名称:</label>
<div class="layui-input-inline">
<input type="text" id="tableName" placeholder="请输入数据库表名称" class="layui-input"
style="width: 300px;">
</div>
<div class="layui-input-inline">
<button class="layui-btn layui-btn-primary layui-border-green" lay-on="save">
<i class="layui-icon layui-icon-success"></i>
确认
</button>
</div>
</div>
<div class="layui-card-body">
<table id="data-table"></table>
<script type="text/html" id="fieldsType_select">
{{# var fieldsTypeList = [{"id":1,"name":"文本"},{"id":2,"name":"日期"},{"id":3,"name":"数值"},{"id":4,"name":"小数"},]; }}
<select name="fieldsType" class="layui-border fields-select" lay-ignore>
{{# layui.each(fieldsTypeList, function(index, item){ }}
<option value="{{item.id}}" {{item.id === d.data_type_id ? 'selected' : '' }}>{{item.name}}</option>
{{# }); }}
</select>
</script>
<script type="text/html" id="required_switch">
<input type="checkbox" title="是|否" lay-skin="switch" lay-filter="requiredSwitch" {{d.allow_blank == false ? "checked" : "" }}>
</script>
</div>
</div>
</div>
</div>
<script src="../../../component/layui/layui.js"></script>
<script>
layui.use(function () {
var form = layui.form;
var table = layui.table;
var $ = layui.jquery;
var util = layui.util;
var dropdown = layui.dropdown;
var errArr = [];
var laytpl = layui.laytpl;
var jobId = GetQueryString("job_id");
var index0TableName = "";
//获取sheet列表
$.ajax({
type: 'GET',
async: false,
url: '/QingLong/collect/getSheets?job_id=' + jobId,
success: function (res) {
var sheetListTpl = sheetListScript.innerHTML;
var sheetListView = document.getElementById('sheetListView');
laytpl(sheetListTpl).render(res.data, function (html) {
sheetListView.innerHTML = html;
});
form.render();
}
});
tableRender(0);
function tableRender(sheetIndex) {
table.render({
id: 'setField',
elem: '#data-table',
url: '/QingLong/collect/getSheetStruct?job_id=' + jobId + '&sheet_index=' + sheetIndex,
height: 'full-100',
page: false,
even: true,
css: [
'.layui-table-cell{height: 50px; line-height: 40px;}',
'.layui-table-cell select{height: 36px; padding: 0 5px;}'
].join(''),
cols: [[
{ title: '序号', align: 'center', width: "5%", type: 'numbers' },
{ title: '字段名称', field: 'column_name', align: 'center', width: "20%", edit: 'text' },
{ title: '原始名称', field: 'original_name', align: 'center', width: "20%" },
{ title: '字段类型', align: 'center', width: "10%", templet: '#fieldsType_select' },
{ title: '必填', align: 'center', width: "10%", templet: '#required_switch' },
{ title: '数据范围', field: 'options', align: 'center', edit: 'text' }
]],
// skin: 'line',
defaultToolbar: [],
done: function (res, curr, count) {
var options = this;
$("#tableName").val('11111111')
// 获取当前行数据
table.getRowData = function (tableId, elem) {
var index = $(elem).closest('tr').data('index');
return table.cache[tableId][index] || {};
};
var tableViewElem = this.elem.next();
tableViewElem.find('.fields-select').on('change', function () {
var value = this.value;
var data = table.getRowData(options.id, this);
data.login = value;
console.log('选中值: ' + value + '<br>当前行数据:' + JSON.stringify(data));
});
form.on('switch(requiredSwitch)', function (obj) {
var data = table.getRowData(options.id, this);
if (obj.elem.checked) {
data.sex = 1;
} else {
data.sex = 2;
}
console.log('选中值: ' + obj.elem.checked + '<br>当前行数据:' + JSON.stringify(data));
});
}
});
}
util.on({
save: function () {
var data = table.getData('setField');
if (errArr.length > 0) {
layer.msg("有问题的数据,请检查!");
} else {
layer.msg(JSON.stringify(data));
}
}
});
//监听单元格编辑
table.on('edit(setField)', function (obj) {
var field = obj.field;
var regex = /^[a-z][a-z0-9]{0,31}$/;
var cellElem = obj.tr.find('td[data-field="username"]');
if (regex.test(obj.value)) {
var _index = errArr.indexOf(obj.index);
errArr.splice(_index, 1);
console.log('变量值符合正则表达式');
cellElem.css('color', '');
} else {
if (!errArr.includes(obj.index)) {
errArr.push(obj.index);
}
console.log('变量值不符合正则表达式');
cellElem.css('color', 'red');
}
console.log('修改的字段为' + obj.field + '<br>' + '修改的值为' + obj.value + '<br>' + JSON.stringify(obj.data));
});
//菜单的点击事件
dropdown.on('click(sheetListView)', function (options) {
console.log(this, options);
// 显示 - 仅用于演示
layer.msg(util.escape(JSON.stringify(options)));
});
function GetQueryString(name, istop) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (typeof (istop) != "undefined") r = top.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]);
return null;
}
});
</script>
</body>
</html>