mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-05 19:41:44 +08:00
123 lines
3.9 KiB
PHP
123 lines
3.9 KiB
PHP
{extend name='main'}
|
|
|
|
{block name="content"}
|
|
<div class="think-box-shadow">
|
|
<ul id="zTree" class="ztree notselect"></ul>
|
|
<div class="hr-line-dashed"></div>
|
|
<div class="layui-form-item text-center">
|
|
<button class="layui-btn" data-submit-role type='button'>{:lang('保存数据')}</button>
|
|
<button class="layui-btn layui-btn-danger" type='button' onclick="window.history.back()">{:lang('取消编辑')}</button>
|
|
</div>
|
|
</div>
|
|
{/block}
|
|
|
|
{block name="script"}
|
|
<script>
|
|
require(['jquery.ztree'], function () {
|
|
new function () {
|
|
var that = this;
|
|
this.data = {}, this.ztree = null, this.setting = {
|
|
view: {showLine: false, showIcon: false, dblClickExpand: false},
|
|
check: {enable: true, nocheck: false, chkboxType: {"Y": "ps", "N": "ps"}}, callback: {
|
|
beforeClick: function (id, node) {
|
|
node.children.length < 1 ? that.ztree.checkNode(node, !node.checked, true, true) : that.ztree.expandNode(node);
|
|
return false;
|
|
}
|
|
}
|
|
};
|
|
this.renderChildren = function (list, level) {
|
|
var childrens = [];
|
|
for (var i in list) childrens.push({
|
|
open: true, node: list[i].node, name: list[i].title || list[i].node,
|
|
checked: list[i].checked || false, children: this.renderChildren(list[i]._sub_, level + 1)
|
|
});
|
|
return childrens;
|
|
};
|
|
this.getData = function () {
|
|
$.form.load('{:url("apply")}', {id: '{$vo.id}', action: 'get'}, 'post', function (ret) {
|
|
return (that.data = that.renderChildren(ret.data, 1)), that.showTree(), false;
|
|
});
|
|
};
|
|
this.showTree = function () {
|
|
this.ztree = $.fn.zTree.init($("#zTree"), this.setting, this.data);
|
|
while (true) {
|
|
var nodes = this.ztree.getNodesByFilter(function (node) {
|
|
return (!node.node && node.children.length < 1);
|
|
});
|
|
if (nodes.length < 1) break;
|
|
for (var i in nodes) this.ztree.removeNode(nodes[i]);
|
|
}
|
|
};
|
|
this.submit = function () {
|
|
var nodes = [], data = this.ztree.getCheckedNodes(true);
|
|
for (var i in data) if (data[i].node) nodes.push(data[i].node);
|
|
$.form.load('{:url("apply")}', {id: '{$vo.id}', action: 'save', nodes: nodes}, 'post');
|
|
};
|
|
// 刷新数据
|
|
this.getData();
|
|
// 提交表单
|
|
$('[data-submit-role]').on('click', function () {
|
|
that.submit();
|
|
});
|
|
};
|
|
});
|
|
</script>
|
|
{/block}
|
|
|
|
{block name="style"}
|
|
<style>
|
|
ul.ztree li {
|
|
line-height: 24px;
|
|
white-space: normal !important;
|
|
}
|
|
|
|
ul.ztree li span.button.switch {
|
|
margin-right: 5px;
|
|
}
|
|
|
|
ul.ztree ul ul li {
|
|
display: inline-block;
|
|
white-space: normal;
|
|
}
|
|
|
|
ul.ztree > li {
|
|
border: 1px solid rgba(0, 0, 0, 0.10);
|
|
padding: 15px;
|
|
background: rgba(0, 0, 0, 0.05);
|
|
border-radius: 3px;
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
ul.ztree > li > ul {
|
|
padding: 10px;
|
|
margin-top: 10px;
|
|
background: rgba(0, 0, 0, 0.05);
|
|
border-radius: 3px;
|
|
}
|
|
|
|
ul.ztree > li > ul > li {
|
|
padding: 5px 0;
|
|
}
|
|
|
|
ul.ztree > li > a > span {
|
|
font-size: 15px;
|
|
font-weight: 700;
|
|
}
|
|
|
|
ul.ztree .level2 .button.level2 {
|
|
width: 0;
|
|
}
|
|
|
|
ul.ztree li span.button.noline_open {
|
|
background-position-y: -73px;
|
|
}
|
|
|
|
ul.ztree li span.button.noline_close {
|
|
background-position-y: -73px;
|
|
}
|
|
|
|
ul.ztree .level1 > .node_name {
|
|
font-weight: bold;
|
|
}
|
|
</style>
|
|
{/block} |