2021-09-08 14:41:21 +08:00
|
|
|
|
---
|
|
|
|
|
title: 页面组件
|
|
|
|
|
description: 页面上使用的组件
|
|
|
|
|
published: true
|
2021-09-08 14:49:57 +08:00
|
|
|
|
date: 2021-09-08T06:49:56.594Z
|
2021-09-08 14:41:21 +08:00
|
|
|
|
tags: wg-basic
|
|
|
|
|
editor: markdown
|
|
|
|
|
dateCreated: 2021-09-08T06:41:19.351Z
|
|
|
|
|
---
|
|
|
|
|
|
2021-09-08 14:42:52 +08:00
|
|
|
|
# 1. 表单下拉列表
|
2021-09-08 14:41:21 +08:00
|
|
|
|
```html
|
|
|
|
|
<div class="layui-form-item">
|
|
|
|
|
<label class="layui-form-label">类型</label>
|
|
|
|
|
<div class="layui-input-block">
|
|
|
|
|
<select id="type" name="type" lay-filter="typeFilter">
|
|
|
|
|
<option value="1">舆情收集</option>
|
|
|
|
|
<option value="2">政法干警监督举报</option>
|
|
|
|
|
<option value="3">执法、司法监督举报</option>
|
|
|
|
|
</select>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
```
|
|
|
|
|
|
2021-09-08 14:42:52 +08:00
|
|
|
|
# 2. 表单下拉联动
|
|
|
|
|
```html
|
|
|
|
|
<div class="layui-form-item">
|
|
|
|
|
<label class="layui-form-label">1级区域</label>
|
|
|
|
|
<div class="layui-input-block layui-form" id="area1SelectTemplateBox" lay-filter="area1SelectTemplateBox"></div>
|
|
|
|
|
<script id="area1SelectTemplate" type="text/html">
|
|
|
|
|
<select id="area1" name="area1" lay-filter="area1" disabled>
|
|
|
|
|
<option value="">暂无1级区域</option>
|
|
|
|
|
{{# for(var i = 0, item; item = d[i++];) { }}
|
|
|
|
|
<option value="{{item.dictionaryId}}">{{item.dictionaryName}}</option>
|
|
|
|
|
{{# } }}
|
|
|
|
|
</select>
|
|
|
|
|
</script>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="layui-form-item">
|
|
|
|
|
<label class="layui-form-label">2级区域</label>
|
|
|
|
|
<div class="layui-input-block layui-form" id="area2SelectTemplateBox" lay-filter="area2SelectTemplateBox"></div>
|
|
|
|
|
<script id="area2SelectTemplate" type="text/html">
|
|
|
|
|
<select id="area2" name="area2" lay-filter="area2" disabled>
|
|
|
|
|
<option value="">暂无2级区域</option>
|
|
|
|
|
{{# for(var i = 0, item; item = d[i++];) { }}
|
|
|
|
|
<option value="{{item.dictionaryId}}">{{item.dictionaryName}}</option>
|
|
|
|
|
{{# } }}
|
|
|
|
|
</select>
|
|
|
|
|
</script>
|
|
|
|
|
</div>
|
|
|
|
|
```
|
|
|
|
|
初始化
|
|
|
|
|
```javascript
|
|
|
|
|
// 统一渲染方法
|
|
|
|
|
function initSelectRadioCheckboxTemplate(templateId, templateBoxId, data, callback) {
|
|
|
|
|
laytpl(document.getElementById(templateId).innerHTML).render(data, function(html) {
|
|
|
|
|
document.getElementById(templateBoxId).innerHTML = html;
|
|
|
|
|
});
|
|
|
|
|
form.render('select', templateBoxId);
|
|
|
|
|
if(callback) {
|
|
|
|
|
callback();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 初始化1级区域下拉选择
|
|
|
|
|
function initArea1Select(selectValue) {
|
|
|
|
|
top.restAjax.get(top.restAjax.path('api/datadictionary/listdictionarybyparentid/81583ade-5466-49aa-b7b6-c643c131ea34', []), {
|
|
|
|
|
}, null, function(code, data, args) {
|
|
|
|
|
initSelectRadioCheckboxTemplate('area1SelectTemplate', 'area1SelectTemplateBox', data, function() {
|
|
|
|
|
var selectObj = {};
|
|
|
|
|
selectObj['area1'] = selectValue;
|
|
|
|
|
form.val('dataForm', selectObj);
|
|
|
|
|
});
|
|
|
|
|
}, function(code, data) {
|
|
|
|
|
top.dialog.msg(data.msg);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 初始化2级区域下拉选择
|
|
|
|
|
function initArea2Select(area1, selectValue) {
|
|
|
|
|
if(!area1) {
|
|
|
|
|
initSelectRadioCheckboxTemplate('area2SelectTemplate', 'area2SelectTemplateBox', [], function() {
|
|
|
|
|
var selectObj = {};
|
|
|
|
|
selectObj['area2'] = selectValue;
|
|
|
|
|
form.val('dataForm', selectObj);
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
top.restAjax.get(top.restAjax.path('api/datadictionary/listdictionarybyparentid/{area1}', [area1]), {
|
|
|
|
|
}, null, function(code, data, args) {
|
|
|
|
|
initSelectRadioCheckboxTemplate('area2SelectTemplate', 'area2SelectTemplateBox', data, function() {
|
|
|
|
|
var selectObj = {};
|
|
|
|
|
selectObj['area2'] = selectValue;
|
|
|
|
|
form.val('dataForm', selectObj);
|
|
|
|
|
});
|
|
|
|
|
}, function(code, data) {
|
|
|
|
|
top.dialog.msg(data.msg);
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-09-08 14:43:46 +08:00
|
|
|
|
```
|
|
|
|
|
赋值初始化
|
|
|
|
|
```javascript
|
|
|
|
|
initArea1Select(data['area1']);
|
|
|
|
|
initArea2Select(data['area1'], data['area2']);
|
|
|
|
|
```
|
|
|
|
|
联动
|
|
|
|
|
```javascript
|
|
|
|
|
// area1 选择事件,多级联动继续添加
|
|
|
|
|
form.on('select(area1)', function(data) {
|
|
|
|
|
initArea2Select(data.value);
|
|
|
|
|
});
|
2021-09-08 14:45:20 +08:00
|
|
|
|
```
|
|
|
|
|
# 3. 表单单选
|
|
|
|
|
```html
|
|
|
|
|
<div class="layui-form-item" pane>
|
|
|
|
|
<label class="layui-form-label">名称</label>
|
|
|
|
|
<div class="layui-input-block">
|
|
|
|
|
<input type="radio" name="isLogOff" value="0" title="否" checked>
|
|
|
|
|
<input type="radio" name="isLogOff" value="1" title="是">
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
```
|
|
|
|
|
# 4. 表单多选
|
|
|
|
|
```html
|
|
|
|
|
<div class="layui-form-item" pane>
|
|
|
|
|
<label class="layui-form-label">授权模式 *</label>
|
|
|
|
|
<div class="layui-input-block">
|
|
|
|
|
<input type="checkbox" name="authorizedGrantTypes[authorization_code]" title="授权码模式" checked>
|
|
|
|
|
<input type="checkbox" name="authorizedGrantTypes[password]" title="密码模式">
|
|
|
|
|
<input type="checkbox" name="authorizedGrantTypes[client_credentials]" title="客户端模式" checked>
|
|
|
|
|
<input type="checkbox" name="authorizedGrantTypes[implicit]" title="简单模式">
|
|
|
|
|
<input type="checkbox" name="authorizedGrantTypes[refresh_token]" title="刷新" checked>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
```
|
|
|
|
|
处理多选结果
|
|
|
|
|
```javascript
|
|
|
|
|
var authorizedGrantTypes = top.restAjax.checkBoxToString(formData.field, 'authorizedGrantTypes');
|
|
|
|
|
formData.field.authorizedGrantTypes = authorizedGrantTypes;
|
|
|
|
|
```
|
|
|
|
|
赋值多选结果
|
|
|
|
|
```javascript
|
|
|
|
|
var authorizedGrantTypes = data.authorizedGrantTypes.split(',');
|
|
|
|
|
var formObj = {};
|
|
|
|
|
for(var i = 0, item = authorizedGrantTypes[i]; item = authorizedGrantTypes[i++];) {
|
|
|
|
|
formObj['authorizedGrantTypes['+ item +']'] = true;
|
|
|
|
|
form.val('dataForm', formObj);
|
|
|
|
|
}
|
|
|
|
|
form.render(null, 'dataForm');
|
2021-09-08 14:46:19 +08:00
|
|
|
|
```
|
|
|
|
|
# 5. 表单下拉、单选、复选统一处理
|
|
|
|
|
```javascript
|
|
|
|
|
// 初始化选择框、单选、复选模板
|
|
|
|
|
function initSelectRadioCheckboxTemplate(templateId, templateBoxId, data, callback) {
|
|
|
|
|
laytpl(document.getElementById(templateId).innerHTML).render(data, function(html) {
|
|
|
|
|
document.getElementById(templateBoxId).innerHTML = html;
|
|
|
|
|
});
|
|
|
|
|
form.render('select', templateBoxId);
|
|
|
|
|
if(callback) {
|
|
|
|
|
callback();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
# 6. viewer,具体是用参考官方API
|
|
|
|
|
```html
|
|
|
|
|
<link rel="stylesheet" type="text/css" href="assets/js/vendor/viewer/viewer.min.css">
|
|
|
|
|
<script src="assets/js/vendor/viewer/viewer.min.js"></script>
|
|
|
|
|
<script>
|
|
|
|
|
new Viewer(document.getElementById('boxId'), {navbar: true});
|
|
|
|
|
</script>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
# 7. 列表按钮
|
|
|
|
|
```javascript
|
|
|
|
|
// 列表模板
|
|
|
|
|
templet: function(item) {
|
|
|
|
|
return '<button type="button" class="layui-btn layui-btn-sm" lay-event="resetPasswordEvent"><i class="fa fa-key"></i> 重置密码</button>';
|
|
|
|
|
}
|
|
|
|
|
// 事件处理
|
|
|
|
|
table.on('tool(dataTable)', function(obj) {
|
|
|
|
|
var layEvent = obj.event;
|
|
|
|
|
var data = obj.data;
|
|
|
|
|
if(layEvent === 'resetPasswordEvent') {
|
|
|
|
|
top.dialog.open({
|
|
|
|
|
url: top.restAjax.path('route/system/user/update-rest-password.html?userId={userId}', [data.userId]),
|
|
|
|
|
title: '【'+ data.userName +'】重置密码',
|
|
|
|
|
width: '320px',
|
|
|
|
|
height: '280px',
|
|
|
|
|
onClose: function() {
|
|
|
|
|
reloadTable();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
```
|
|
|
|
|
|
2021-09-08 14:49:22 +08:00
|
|
|
|
# 8. 选择人员(表格)
|
2021-09-08 14:46:19 +08:00
|
|
|
|
```javascript
|
|
|
|
|
top.dialog.dialogData.oldSelectedUserList = [{userId:''}];
|
|
|
|
|
top.dialog.open({
|
|
|
|
|
url: 'route/common/listselectuser?selectType=checkbox(radio)',
|
|
|
|
|
title: '选择用户',
|
|
|
|
|
width: '1000px',
|
|
|
|
|
height: '500px',
|
|
|
|
|
onClose: function() {
|
|
|
|
|
var newSelectedUserList = top.dialog.dialogData.newSelectedUserList;
|
|
|
|
|
if(newSelectedUserList.length != 0) {
|
|
|
|
|
// newSelectedUserList[0].userId;
|
|
|
|
|
// newSelectedUserList[0].userName;
|
|
|
|
|
}
|
|
|
|
|
top.dialog.dialogData.oldSelectedUserList = [];
|
|
|
|
|
}
|
|
|
|
|
});
|
2021-09-08 14:49:22 +08:00
|
|
|
|
```
|
2021-09-08 14:49:57 +08:00
|
|
|
|
# 9. 文件上传(图片示例)
|
|
|
|
|
|