mirror of
https://gitee.com/layui/layui.git
synced 2025-11-24 08:33:12 +08:00
* style: 统一代码格式,修复ESLint错误 - 为所有模块添加尾随逗号 - 修复缺少分号的语句 - 统一对象字面量格式 - 添加ESLint配置文件和文档 - 更新package.json中的脚本和依赖项 * build: 添加 ESLint 配置文件以支持 IE9+ 兼容性 * refactor(upload): 使用已缓存的hint实例替换直接调用 优化代码性能,避免重复实例化hint对象,直接使用模块顶部已缓存的实例 * chore: 更新.gitignore文件以包含更多忽略规则 添加了更多常见的临时文件、编辑器文件、构建输出目录和运行时数据的忽略规则,使项目更加整洁并避免不必要的文件被提交到版本控制中 * fix(lay.js): 修复passive事件监听器选项的返回值 确保getter函数返回true以正确支持passive事件监听 * refactor(form): 移除表单模块中的冗余代码 删除表单模块中无实际作用的冗余代码行,这些代码只是将属性重新赋值为自身,没有实际功能意义 * fix(form): 修复复选框状态处理逻辑 确保复选框的 indeterminate 和 checked 状态被正确转换为布尔值,并优化事件调用时的空格格式 * feat(eslint): 完善 ESLint 配置并添加 VSCode 支持 添加 VSCode 配置文件以支持 ESLint 自动修复和格式化 更新 ESLint 配置,增强代码风格和兼容性规则 修复 package.json 中的脚本拼写错误并添加 format 脚本 调整 .gitignore 以允许特定 VSCode 配置文件 * style: 统一代码中的引号格式并修复缩进问题 统一将双引号改为单引号,修复部分代码缩进不一致的问题,提升代码风格一致性 * docs: 删除过时的ESLint配置文档文件 * build: 采用 prettier 作为代码格式化工具,剔除 ESLint 格式化部分 * chore: 剔除 .vscode/ 配置,保持编辑器中立 * build: 修改 ESLint 为「扁平化配置」方式,避免大量参数堆砌 * chore: 格式化代码 * ci: 添加 git hooks 和 CI 环节把关代码风格 * ci: update * ci: update * test: 测试 ci format * ci: 改用 husky 作为 git hooks,与 Layui 3 保持一致 经测试,simple-git-hooks 生成的 pre-commit 默认为 sh,在 Windows 不兼容(必须用 git bash 执行 commits) * build: 新增 CI 和生产环境跳过 husky 安装的判断 * build: 剔除重复配置 * build: 优化 eslint 配置 --------- Co-authored-by: 贤心 <3277200+sentsim@users.noreply.github.com>
301 lines
10 KiB
HTML
301 lines
10 KiB
HTML
<!-- 引用自 https://github.com/layui/layui/issues/1815 -->
|
|
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<title>Document</title>
|
|
<link
|
|
rel="stylesheet"
|
|
href="../src/css/layui.css"
|
|
href2="//cdnjs.cloudflare.com/ajax/libs/layui/2.9.6/css/layui.css"
|
|
/>
|
|
</head>
|
|
|
|
<body>
|
|
<table
|
|
class="layui-table"
|
|
id="MianTable"
|
|
lay-filter="MianTable"
|
|
lay-data="{id: 'MianTable'}"
|
|
></table>
|
|
<script type="text/html" id="toolbar">
|
|
<div class="layui-btn-container">
|
|
<button class="layui-btn layui-btn-sm" lay-event="AddRowButton">
|
|
新增主件
|
|
</button>
|
|
<button class="layui-btn layui-btn-sm" lay-event="InitTableButton">
|
|
初始化数据
|
|
</button>
|
|
<button class="layui-btn layui-btn-sm" lay-event="SubmitButton">
|
|
保存
|
|
</button>
|
|
<button class="layui-btn layui-btn-sm" lay-event="expandAll-true">
|
|
expandAll-true
|
|
</button>
|
|
<button class="layui-btn layui-btn-sm" lay-event="expandAll-false">
|
|
expandAll-false
|
|
</button>
|
|
</div>
|
|
</script>
|
|
<script type="text/html" id="TableItemTools">
|
|
<div class="layui-btn-container">
|
|
<a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="addChild"
|
|
>新增子件</a
|
|
>
|
|
<a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="delChild"
|
|
>删除</a
|
|
>
|
|
</div>
|
|
</script>
|
|
<script type="text/html" id="TableItemTools">
|
|
<div class="layui-btn-container">
|
|
<a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="addChild"
|
|
>新增子件</a
|
|
>
|
|
<a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="delChild"
|
|
>删除</a
|
|
>
|
|
</div>
|
|
</script>
|
|
|
|
<script type="text/html" id="sexTpl">
|
|
<select name="select-sex" class="layui-border select-sex" lay-ignore lay-filter="sex_{{d.rowid}}" id="sex_{{d.rowid}}">
|
|
<option value="">请选择</option>
|
|
<option value="男" {{d.sex=="男"?"selected":""}}>男</option>
|
|
<option value="女" {{d.sex=="女"?"selected":""}}>女</option>
|
|
</select>
|
|
</script>
|
|
<script type="text/html" id="provinceTpl">
|
|
<select name="select-province" class="layui-border select-province" lay-ignore lay-filter="province_{{d.rowid}}" id="province_{{d.rowid}}">
|
|
<option value="">请选择</option>
|
|
{{# layui.each(d.provinceList, function(i, v){ }}
|
|
<option value="{{v.id}}" {{d.province==v.id?"selected":""}}>{{v.name}}</option>
|
|
{{# }); }}
|
|
</select>
|
|
</script>
|
|
<script type="text/html" id="cityTpl">
|
|
<select name="select-city" class="layui-border select-city" lay-ignore lay-filter="city_{{d.rowid}}" id="city_{{d.rowid}}">
|
|
<option value="">请选择</option>
|
|
{{# layui.each(d.cityList, function(i, v){ }}
|
|
<option value="{{v.id}}" {{d.city==v.id?"selected":""}}>{{v.name}}</option>
|
|
{{# }); }}
|
|
</select>
|
|
</script>
|
|
<script type="text/html" id="districtTpl">
|
|
<select name="select-district" class="layui-border select-district" lay-ignore lay-filter="district_{{d.rowid}}" id="district_{{d.rowid}}">
|
|
<option value="">请选择</option>
|
|
{{# layui.each(d.districtList, function(i, v){ }}
|
|
<option value="{{v.id}}" {{d.district==v.id?"selected":""}}>{{v.name}}</option>
|
|
{{# }); }}
|
|
</select>
|
|
</script>
|
|
<script
|
|
src="../src/layui.js"
|
|
src1="//cdnjs.cloudflare.com/ajax/libs/layui/2.9.9/layui.js"
|
|
></script>
|
|
<script>
|
|
layui.use(['jquery', 'treeTable', 'form'], function () {
|
|
var $ = layui.jquery;
|
|
var table = layui.table;
|
|
var treeTable = layui.treeTable;
|
|
var form = layui.form;
|
|
|
|
var provinceList = [
|
|
{ id: '01', name: '湖北省' },
|
|
{ id: '02', name: '湖南省' },
|
|
{ id: '03', name: '广东省' }
|
|
];
|
|
var cityList = [
|
|
{ id: '01.01', name: '武汉市' },
|
|
{ id: '01.02', name: '黄石市' },
|
|
|
|
{ id: '02.01', name: '长沙市' },
|
|
{ id: '02.02', name: '株洲市' },
|
|
|
|
{ id: '03.01', name: '广州市' }
|
|
];
|
|
var districtList = [
|
|
{ id: '01.01.01', name: '江岸区' },
|
|
{ id: '01.01.02', name: '江汉区' },
|
|
{ id: '01.01.03', name: '武昌区' },
|
|
{ id: '01.02.01', name: '下陆区' },
|
|
{ id: '01.02.02', name: '铁山区' },
|
|
|
|
{ id: '02.01.01', name: '天心区' },
|
|
{ id: '02.01.02', name: '芙蓉区' },
|
|
{ id: '02.01.03', name: '浏阳市' },
|
|
{ id: '02.02.01', name: '天元区' },
|
|
{ id: '02.02.02', name: '石峰区' },
|
|
|
|
{ id: '03.01.01', name: '越秀区' },
|
|
{ id: '03.01.02', name: '海珠区' }
|
|
];
|
|
|
|
var isHtmlIcon = false;
|
|
var genIcon = function (str, isHtml) {
|
|
return isHtml ? normalizedIcon(str) : str;
|
|
};
|
|
var icons = {
|
|
flexIconClose: genIcon('layui-icon layui-icon-addition', isHtmlIcon),
|
|
flexIconOpen: genIcon(
|
|
'layui-icon layui-icon-subtraction',
|
|
isHtmlIcon
|
|
),
|
|
iconClose: genIcon('layui-icon layui-icon-add-circle', isHtmlIcon),
|
|
iconOpen: genIcon('layui-icon layui-icon-reduce-circle', isHtmlIcon),
|
|
iconLeaf: genIcon('layui-icon layui-icon-snowflake', isHtmlIcon),
|
|
icon: genIcon('layui-icon layui-icon-addition', isHtmlIcon)
|
|
};
|
|
|
|
treeTable.render({
|
|
elem: '#MianTable',
|
|
toolbar: '#toolbar',
|
|
limit: 100,
|
|
tree: {
|
|
// customName: {
|
|
// id: "id",
|
|
// name: "id",
|
|
// },
|
|
view: {
|
|
// showFlexIconIfNotParent: true,
|
|
// flexIconClose: icons.flexIconClose,
|
|
// flexIconOpen: icons.flexIconOpen,
|
|
// iconClose: icons.iconClose,
|
|
// iconOpen: icons.iconOpen,
|
|
// iconLeaf: icons.iconLeaf,
|
|
// icon: icons.icon
|
|
}
|
|
},
|
|
cols: [
|
|
[
|
|
//标题栏
|
|
{ checkbox: true, fixed: 'left' },
|
|
{ field: 'id', title: 'ID', width: 150 },
|
|
{
|
|
title: '操作',
|
|
width: 150,
|
|
align: 'center',
|
|
toolbar: '#TableItemTools'
|
|
},
|
|
{ field: 'name', title: '用户名', width: 180, edit: 'text' },
|
|
{ field: 'sex', title: '性别', templet: '#sexTpl' },
|
|
{ field: 'province', title: '省', templet: '#provinceTpl' },
|
|
{ field: 'city', title: '市', templet: '#cityTpl' },
|
|
{ field: 'district', title: '区', templet: '#districtTpl' }
|
|
]
|
|
],
|
|
data: [],
|
|
done: function () {
|
|
var options = this;
|
|
|
|
// 获取当前行数据
|
|
table.getRowData = function (tableId, elem) {
|
|
var index = $(elem).closest('tr').data('index');
|
|
return table.cache[tableId][index] || {};
|
|
};
|
|
|
|
var tableViewElem = this.elem.next();
|
|
tableViewElem.off('change.tbSelect');
|
|
tableViewElem.on('change.tbSelect', '.select-sex', function () {
|
|
var value = this.value; // 获取选中项 value
|
|
var data = table.getRowData(options.id, this);
|
|
data.sex = value;
|
|
|
|
var DATA_INDEX = data.LAY_DATA_INDEX; //此处需要内部字段更新行数据
|
|
treeTable.updateNode('MianTable', DATA_INDEX, {
|
|
province: '01'
|
|
});
|
|
});
|
|
}
|
|
});
|
|
|
|
treeTable.on('toolbar(MianTable)', function (obj) {
|
|
var id = obj.config.id;
|
|
var checkStatus = treeTable.checkStatus(id);
|
|
|
|
switch (obj.event) {
|
|
case 'AddRowButton':
|
|
treeTable.addNodes(id, {
|
|
parentIndex: null,
|
|
index: -1,
|
|
//index: 0,
|
|
data: {
|
|
id: Date.now(),
|
|
provinceList: $.extend(true, [], provinceList)
|
|
// icon: 'layui-icon layui-icon-github'
|
|
}
|
|
});
|
|
console.log('add', table.cache['MianTable']);
|
|
|
|
break;
|
|
|
|
case 'InitTableButton':
|
|
treeTable.reloadData('MianTable', {
|
|
data: [
|
|
{
|
|
name: 1,
|
|
provinceList: provinceList,
|
|
children: [{ name: 2, provinceList: provinceList }]
|
|
},
|
|
{ name: 3, provinceList: provinceList }
|
|
]
|
|
});
|
|
break;
|
|
case 'SubmitButton':
|
|
console.log(treeTable.getData('MianTable'));
|
|
case 'expandAll-true':
|
|
treeTable.expandAll('MianTable', true);
|
|
break;
|
|
case 'expandAll-false':
|
|
treeTable.expandAll('MianTable', false);
|
|
break;
|
|
break;
|
|
default:
|
|
}
|
|
});
|
|
treeTable.on('tool(MianTable)', function (obj) {
|
|
var data = obj.data;
|
|
var id = obj.config.id;
|
|
var trElem = obj.tr;
|
|
switch (obj.event) {
|
|
case 'addChild':
|
|
let json = {
|
|
id: Date.now(),
|
|
provinceList: $.extend(true, [], provinceList)
|
|
};
|
|
|
|
treeTable.addNodes(id, {
|
|
parentIndex: data['LAY_DATA_INDEX'],
|
|
index: -1,
|
|
data: json
|
|
});
|
|
|
|
console.log('addChild', table.cache['MianTable']);
|
|
|
|
break;
|
|
case 'delChild':
|
|
// obj.del();
|
|
// treeTable.removeNode(id, data["LAY_DATA_INDEX"]);
|
|
treeTable.removeNode(id, trElem.attr('data-index'));
|
|
console.log('del', table.cache['MianTable']);
|
|
|
|
break;
|
|
|
|
default:
|
|
}
|
|
});
|
|
|
|
function normalizedIcon(iconStr) {
|
|
return iconStr
|
|
? /<[^>]+?>/.test(iconStr)
|
|
? iconStr
|
|
: '<i class="' + iconStr + '"></i>'
|
|
: '';
|
|
}
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|