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.

328 lines
14 KiB

2 years ago
<!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;
}
2 years ago
.dh_ico {
display: none;
}
2 years ago
.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;
}
2 years ago
</style>
</head>
<body class="layui-bg-gray">
2 years ago
2 years ago
<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>
2 years ago
<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>
2 years ago
</div>
2 years ago
<div class="layui-row layui-col-space10" style="height: 100%;">
2 years ago
<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>
2 years ago
<div class="layui-card-body">
2 years ago
<ul class="layui-menu" id="sheetListView">
2 years ago
</ul>
2 years ago
<script id="sheetListScript" type="text/html">
2 years ago
{{# layui.each(d, function(index, item){ }}
2 years ago
<li lay-options="{ id: '{{item.sheet_index}}',table_name:'{{item.table_name}}' }" class="{{ index == 0 ? 'layui-menu-item-checked' : '' }}" >
2 years ago
<div class="layui-menu-body-title">
2 years ago
<a href="javascript:;">{{item.sheet_name}}</a>
2 years ago
2 years ago
<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>
2 years ago
2 years ago
</div>
</li>
{{# }); }}
</select>
</script>
2 years ago
</div>
</div>
</div>
2 years ago
<div class="layui-col-md10" style="height: 100%;">
2 years ago
<div class="layui-card" style="margin-top: 10px;margin-right: 10px;height: calc(100% - 60px);">
2 years ago
<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">
2 years ago
<input type="text" id="tableName" placeholder="请输入数据库表名称" class="layui-input"
2 years ago
style="width: 300px;">
</div>
<div class="layui-input-inline">
2 years ago
<button class="layui-btn layui-btn-primary layui-border-green" lay-on="confirm">
2 years ago
<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){ }}
2 years ago
<option value="{{item.id}}" {{item.id === d.data_type_id ? 'selected' : '' }}>{{item.name}}</option>
2 years ago
{{# }); }}
</select>
</script>
<script type="text/html" id="required_switch">
2 years ago
<input type="checkbox" title="是|否" lay-skin="switch" lay-filter="requiredSwitch" {{d.allow_blank == false ? "checked" : "" }}>
2 years ago
</script>
</div>
</div>
</div>
</div>
2 years ago
<script src="../../../component/layui/layui.js"></script>
2 years ago
<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 = [];
2 years ago
var laytpl = layui.laytpl;
2 years ago
var jobId = GetQueryString("job_id");
2 years ago
var initSheetIndex = 0;
2 years ago
//获取sheet列表
$.ajax({
type: 'GET',
async: false,
url: '/QingLong/collect/getSheets?job_id=' + jobId,
success: function (res) {
2 years ago
2 years ago
var sheetListTpl = sheetListScript.innerHTML;
var sheetListView = document.getElementById('sheetListView');
laytpl(sheetListTpl).render(res.data, function (html) {
sheetListView.innerHTML = html;
});
form.render();
}
});
2 years ago
tableRender(initSheetIndex);
2 years ago
function tableRender(sheetIndex) {
table.render({
id: 'setField',
elem: '#data-table',
url: '/QingLong/collect/getSheetStruct?job_id=' + jobId + '&sheet_index=' + sheetIndex,
2 years ago
height: 'full-150',
2 years ago
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' },
2 years ago
{ title: '数据范围(用,号分隔)', field: 'options', align: 'center', edit: 'text' }
2 years ago
]],
// skin: 'line',
defaultToolbar: [],
done: function (res, curr, count) {
var options = this;
2 years ago
$("#tableName").val(res.table_name);
2 years ago
// 获取当前行数据
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);
2 years ago
data.data_type_id = value;
2 years ago
$('#ico' + initSheetIndex).addClass('dh_ico');
2 years ago
});
form.on('switch(requiredSwitch)', function (obj) {
var data = table.getRowData(options.id, this);
if (obj.elem.checked) {
2 years ago
data.allow_blank = 0;
2 years ago
} else {
2 years ago
data.allow_blank = 1;
2 years ago
}
2 years ago
$('#ico' + initSheetIndex).addClass('dh_ico');
2 years ago
});
}
});
}
2 years ago
2 years ago
util.on({
2 years ago
confirm: function () {
2 years ago
var data = table.getData('setField');
2 years ago
// 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
},
2 years ago
success: function (result) {
2 years ago
if (result.success) {
2 years ago
$('#ico' + initSheetIndex).removeClass('dh_ico');
layer.msg("成功!", {
2 years ago
icon: 1,
time: 1500
});
} else {
layer.msg(result.message, {
icon: 2,
time: 1500
});
}
2 years ago
}
});
},
save: function () {
2 years ago
2 years ago
$.ajax({
2 years ago
type: 'GET',
2 years ago
async: false,
2 years ago
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
});
}
2 years ago
}
});
2 years ago
},
returnList: function () {
returnTaskList();
2 years ago
}
2 years ago
2 years ago
});
//监听单元格编辑
table.on('edit(setField)', function (obj) {
2 years ago
$('#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));
2 years ago
});
//菜单的点击事件
2 years ago
dropdown.on('click(sheetListView)', function (options) {
2 years ago
initSheetIndex = options.id;
tableRender(options.id);
2 years ago
});
2 years ago
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;
}
2 years ago
window.returnTaskList = function () {
window.location = "./task_list.html";
}
2 years ago
2 years ago
});
</script>
</body>
</html>