|
|
<!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;
|
|
|
}
|
|
|
|
|
|
.dh_ico {
|
|
|
display: none;
|
|
|
}
|
|
|
|
|
|
.layui-layer-title {
|
|
|
padding: 0 80px 0 20px;
|
|
|
height: 50px;
|
|
|
line-height: 50px;
|
|
|
border-bottom: 1px solid #F0F0F0;
|
|
|
font-size: 14px;
|
|
|
color: #333;
|
|
|
overflow: hidden;
|
|
|
border-radius: 2px 2px 0 0;
|
|
|
}
|
|
|
|
|
|
.layui-layer-setwin {
|
|
|
width: 50px;
|
|
|
height: 100%;
|
|
|
position: absolute;
|
|
|
right: 15px;
|
|
|
top: 17px;
|
|
|
font-size: 0;
|
|
|
line-height: initial;
|
|
|
}
|
|
|
</style>
|
|
|
</head>
|
|
|
|
|
|
<body class="layui-bg-gray">
|
|
|
|
|
|
<div style="background-color: #fff;display: flex;justify-content: space-between;align-items:center;margin: 0 5px">
|
|
|
<div class="layui-layer-title" style="font-weight: bolder;">创建任务</div>
|
|
|
<div style="width: 140px;">
|
|
|
<button type="button" class="layui-btn layui-btn-sm" lay-on="save">保存</button>
|
|
|
<button type="button" class="layui-btn layui-btn-primary layui-btn-sm" lay-on="returnList">返回</button>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
|
|
|
<div class="layui-row layui-col-space10" style="height: 100%;">
|
|
|
<div class="layui-col-md2" style="height: 100%;">
|
|
|
<div class="layui-card" style="margin-top: 10px;margin-left: 10px;height: calc(100% - 60px);">
|
|
|
<div class="layui-card-header">Sheet表</div>
|
|
|
<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>
|
|
|
|
|
|
<i id="ico{{item.sheet_index}}" class="layui-icon layui-icon-ok-circle {{ item.is_check == 0 ? 'dh_ico' : '' }}"
|
|
|
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% - 60px);">
|
|
|
<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="confirm">
|
|
|
<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 initSheetIndex = 0;
|
|
|
|
|
|
//获取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(initSheetIndex);
|
|
|
|
|
|
function tableRender(sheetIndex) {
|
|
|
table.render({
|
|
|
id: 'setField',
|
|
|
elem: '#data-table',
|
|
|
url: '/QingLong/collect/getSheetStruct?job_id=' + jobId + '&sheet_index=' + sheetIndex,
|
|
|
height: 'full-150',
|
|
|
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(res.table_name);
|
|
|
|
|
|
// 获取当前行数据
|
|
|
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.data_type_id = value;
|
|
|
$('#ico' + initSheetIndex).addClass('dh_ico');
|
|
|
});
|
|
|
|
|
|
form.on('switch(requiredSwitch)', function (obj) {
|
|
|
var data = table.getRowData(options.id, this);
|
|
|
if (obj.elem.checked) {
|
|
|
data.allow_blank = 0;
|
|
|
} else {
|
|
|
data.allow_blank = 1;
|
|
|
}
|
|
|
$('#ico' + initSheetIndex).addClass('dh_ico');
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
util.on({
|
|
|
confirm: function () {
|
|
|
var data = table.getData('setField');
|
|
|
// if (errArr.length > 0) {
|
|
|
// layer.msg("有问题的数据,请检查!");
|
|
|
// } else {
|
|
|
// layer.msg(JSON.stringify(data));
|
|
|
// }
|
|
|
|
|
|
var tableName = $("#tableName").val();
|
|
|
$.ajax({
|
|
|
type: "POST",
|
|
|
async: false,
|
|
|
dataType: "json",
|
|
|
url: "/QingLong/collect/saveSheet",
|
|
|
data: {
|
|
|
"json": JSON.stringify(data),
|
|
|
"table_name": tableName,
|
|
|
"job_id": jobId,
|
|
|
"sheet_index": initSheetIndex
|
|
|
},
|
|
|
success: function (result) {
|
|
|
if (result.success) {
|
|
|
$('#ico' + initSheetIndex).removeClass('dh_ico');
|
|
|
layer.msg("成功!", {
|
|
|
icon: 1,
|
|
|
time: 1500
|
|
|
});
|
|
|
} else {
|
|
|
layer.msg(result.message, {
|
|
|
icon: 2,
|
|
|
time: 1500
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
save: function () {
|
|
|
|
|
|
$.ajax({
|
|
|
type: 'GET',
|
|
|
async: false,
|
|
|
url: '/QingLong/collect/getSheets?job_id=' + jobId,
|
|
|
success: function (res) {
|
|
|
var data = res.data;
|
|
|
var count = 0;
|
|
|
for (var i = 0; i < data.length; i++) {
|
|
|
if (data[i].is_check === 0) {
|
|
|
count++;
|
|
|
}
|
|
|
}
|
|
|
if (count > 0) {
|
|
|
layer.msg('还有' + count + '个sheet未保存,请保存后再提交!', {
|
|
|
icon: 2,
|
|
|
time: 1500,
|
|
|
});
|
|
|
} else {
|
|
|
layer.open({
|
|
|
type: 2,
|
|
|
title: '保存任务',
|
|
|
shade: 0.1,
|
|
|
area: ['450px', '230px'],
|
|
|
content: './save_excel.html?job_id=' + jobId
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
returnList: function () {
|
|
|
returnTaskList();
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
//监听单元格编辑
|
|
|
table.on('edit(setField)', function (obj) {
|
|
|
|
|
|
$('#ico' + initSheetIndex).addClass('dh_ico');
|
|
|
// var field = obj.field;
|
|
|
|
|
|
// var regex = /^[a-z][a-z0-9]{0,31}$/;
|
|
|
// var cellElem = obj.tr.find('td[data-field="column_name"]');
|
|
|
// 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) {
|
|
|
initSheetIndex = options.id;
|
|
|
tableRender(options.id);
|
|
|
});
|
|
|
|
|
|
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
window.returnTaskList = function () {
|
|
|
window.location = "./task_list.html";
|
|
|
}
|
|
|
|
|
|
|
|
|
});
|
|
|
</script>
|
|
|
</body>
|
|
|
|
|
|
</html> |