Index.cshtml
9.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
@using HHECS.WorkHourStatistics.Dtos
@using System.Text.Json
@using System.Text.Encodings.Web
@model TreeDto
@{
ViewData["Title"] = "长沙华恒-工时统计工具";
}
<div class="layui-row">
<div class="layui-col-md2">
<div id="ID-tree-demo-showLine"></div>
</div>
<div class="layui-col-md10">
<form class="layui-form layui-row layui-col-space16">
<div class="layui-col-md3">
<div class="layui-input-group">
<div class="layui-input-split layui-input-prefix">
工号,姓名
</div>
<input type="text" id="user" placeholder="请输入工号或姓名" class="layui-input">
</div>
</div>
<div class="layui-col-md6">
<div class="layui-form-item">
<div class="layui-input-group">
<label class="layui-form-label">日期范围</label>
<div class="layui-inline" id="ID-laydate-range">
<div class="layui-input-inline">
<input type="text" autocomplete="off" id="startDate" value="@DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd")" class="layui-input" placeholder="开始日期">
</div>
<div class="layui-form-mid">-</div>
<div class="layui-input-inline">
<input type="text" autocomplete="off" id="endDate" class="layui-input" value="@DateTime.Now.ToString("yyyy-MM-dd")" placeholder="结束日期">
</div>
</div>
</div>
</div>
</div>
<div class="layui-col-md1">
<button class="layui-btn" lay-submit lay-filter="table-search"><i class="layui-icon layui-icon-search"></i>搜索</button>
</div>
</form>
<table class="layui-hide" id="test" lay-filter="test"></table>
</div>
</div>
@section Scripts
{
<script>
layui.use(['table', 'laydate', 'tree'], function () {
var $ = layui.$;
var table = layui.table;
var tree = layui.tree;
var form = layui.form;
var laydate = layui.laydate;
// 渲染
let inst1 = tree.render({
elem: '#ID-tree-demo-showLine',
id: 'treeDom',
data: [@Html.Raw(JsonSerializer.Serialize(Model, new JsonSerializerOptions { Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, WriteIndented = true, PropertyNamingPolicy = JsonNamingPolicy.CamelCase }))],
showLine: true,// 是否开启连接线
accordion: true,
showCheckbox: true, // 是否显示复选框
onlyIconControl: true, // 是否仅允许节点左侧图标控制展开收缩
oncheck: function (obj) {
setTimeout(function () {
// console.log(obj.data);
let checkData = tree.getChecked('treeDom')[0];
// 执行搜索重载
table.reload('test', {
page: {
curr: 1 // 重新从第 1 页开始
},
// 搜索的字段
where: {
person: $('#user').val(),
dept: checkData,
startTime: $('#startDate').val(),
endTime: $('#endDate').val(),
}
});
})
}
});
laydate.render({
elem: '#ID-laydate-range',
range: ['#startDate', '#endDate'],
rangeLinked: true
});
// 创建渲染实例
table.render({
elem: '#test',
url: '/', // 此处为静态模拟数据,实际使用时需换成真实接口
method: 'post',
toolbar: '#toolbarDemo',
defaultToolbar: ['filter', { // 右上角工具图标
title: '导出',
layEvent: 'LAYTABLE_TIPS',
icon: 'layui-icon-export',
onClick: function (obj) { // 2.9.12+
$.ajax({
url: '/Home/Export',
type: 'POST',
data: {
person: $('#user').val(),
dept: tree.getChecked('treeDom')[0],
startTime: $('#startDate').val(),
endTime: $('#endDate').val(),
},
xhrFields: { responseType: "blob" },
success: function (data, textstatus, xhr) {
let contentdisposition = xhr.getResponseHeader('content-disposition');
let filename = '';
if (contentdisposition) {
console.log(contentdisposition);
let filenamematch = contentdisposition.match(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/);
let filenamestarmatch = contentdisposition.match(/filename\*=utf-8''([^;]*)/i); // filename\*=utf-8''([^;] *) /);
filename = filenamestarmatch ? decodeURIComponent(filenamestarmatch[1]) : (filenamematch ? filenamematch[1] : '');
}
if (filename) {
let blob = new Blob([data], { type: xhr.getResponseHeader('content-type') });
let link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = filename;
link.click();
}
},
error: function (error) {
console.log(error);
}
});
}
}, 'print'],
height: 'full-65', // 最大高度减去其他容器已占有的高度差
cellMinWidth: 80,
where: {
person: $('#user').val(),
dept: tree.getChecked('treeDom')[0],
startTime: $('#startDate').val(),
endTime: $('#endDate').val(),
},
page: true,
limit: 20,
cols: [[
{ field: 'id', title: 'ID', hide: true },
{ field: 'number', title: '工号', width: 110, fixed: 'left' },
{ field: 'personName', title: '姓名', width: 110, fixed: 'left' },
{ field: 'deptName', title: '部门', minWidth: 200 },
{ field: 'baseWorkCard', title: '上班时间', width: 160, templet: '{{= new Date(d.baseWorkCard).toLocaleString() }}' },
{
field: 'workCard', title: '上班打卡时间', width: 160, templet: function (d) {
if (d.workCard == null) {
return '';
} else {
return new Date(d.workCard).toLocaleString();
}
}
},
{ field: 'workCardLocationAddress', title: '上班打卡地址', minWidth: 200 },
{ field: 'baseOffDutyCard', title: '下班时间', width: 160, templet: '{{= new Date(d.baseOffDutyCard).toLocaleString() }}' },
{
field: 'offDutyCard', title: '下班打卡时间', width: 160, templet: function (d) {
if (d.offDutyCard == null) {
return '';
} else {
return new Date(d.offDutyCard).toLocaleString();
}
}
},
{ field: 'offDutyCardLocationAddress', title: '下班打卡地址', minWidth: 200 },
{ field: 'createTime', title: '数据同步时间', width: 160, templet: '{{= new Date(d.createTime).toLocaleString() }}' },
]],
error: function (res, msg) {
console.log(res, msg)
}
});
// 搜索提交
form.on('submit(table-search)', function (data) {
var field = data.field; // 获得表单字段
// 执行搜索重载
table.reload('test', {
page: {
curr: 1 // 重新从第 1 页开始
},
// 搜索的字段
where: {
person: $('#user').val(),
startTime: $('#startDate').val(),
endTime: $('#endDate').val(),
dept: tree.getChecked('treeDom')[0],
}
});
return false; // 阻止默认 form 跳转
});
});
</script>
}