Commit 14736857 by 杨树贤

优化树形节点选中

parent bd80f014
......@@ -196,7 +196,7 @@ class SupplierAccountApiController extends Controller
unset($data['sbat_id']);
$result = (new SupplierSubAccountService())->addSupplierSubAccount($accountId, $data);
} else {
$result = (new SupplierSubAccountService())->addSupplierSubAccount($accountId, $data);
$result = (new SupplierSubAccountService())->updateSupplierSubAccount($accountId, $data);
}
if ($result === true) {
$this->response(0, '操作成功');
......
......@@ -100,20 +100,27 @@ class SupplierSubAccountService
} else {
$params['method'] = 'add';
}
// dump($params);
$result = json_decode(curl($url, $params), true);
if (isset($result['code']) && $result['code'] == 0) {
$permList = $result['data']['data'];
// dump($permList);
//还要转换成layui能用的格式
$list = [];
// dump($permList);
foreach ($permList as $perm) {
$children = !empty($perm['children']) ? $this->getChildPermList($perm['children']) : [];
$list[] = [
'title' => $perm['name'],
'id' => !empty($perm['path']) ? $perm['path'] : '',
'checked' => $perm['checked'],
'checked' => false,
'disabled' => $perm['disabled'],
'id' => $perm['id'],
'spread' => true,
'children' => !empty($perm['children']) ? $this->getChildPermList($perm['children']) : [],
'children' => $children
];
}
// dd($list);
return $list;
}
return [];
......@@ -125,11 +132,12 @@ class SupplierSubAccountService
return [];
}
$childPermList = [];
foreach ($perm as $item) {
foreach ($perm as $key => $item) {
$childPermList[] = [
'title' => $item['name'],
'id' => !empty($item['path']) ? $item['path'] : '',
'id' => !empty($item['id']) ? $item['id'] : str_random(100),
'checked' => $item['checked'],
'disabled' => isset($item['disabled'])?$item['disabled']:false,
'spread' => true,
];
}
......@@ -150,9 +158,9 @@ class SupplierSubAccountService
$list = [];
foreach ($permList as $perm) {
$list[] = [
'id' => $perm['id'],
'title' => $perm['name'],
'id' => !empty($perm['path']) ? $perm['path'] : '',
'checked' => $perm['checked'],
'checked' => false,
'spread' => true,
'children' => !empty($perm['children']) ? $this->getChildPermList($perm['children']) : [],
];
......@@ -185,6 +193,7 @@ class SupplierSubAccountService
{
$url = config('website.CloudUrl') . '/inner/subAccount/saveMessageMenu ';
$params = $this->generateRequestAuthData($accountId);
$userMessageRule = $userMessageRule ?: [];
$params['user_message_rule'] = is_array($userMessageRule) ? json_encode($userMessageRule) : $userMessageRule;
$result = json_decode(curl($url, $params, true), true);
if (isset($result['code'])) {
......
......@@ -30,6 +30,7 @@
});
let messagePermTreeData = {!! json_encode($messagePerms) !!};
console.log(messagePermTreeData);
// 渲染树形组件
let messagePermTree = tree.render({
elem: '#messagePermTree',
......
......@@ -34,14 +34,15 @@
});
let permTreeData = {!! json_encode($menuPerms) !!};
console.log(permTreeData);
// 渲染树形组件
let permTree = tree.render({
elem: '#permTree',
id: 'permTree',
showCheckbox: true,
data: permTreeData,
click: function (obj) {
tree.reload('permTree');
oncheck: function (obj) {
$('#permTree .layui-checkbox-disbaled').addClass('layui-form-checked');
}
});
......@@ -52,8 +53,7 @@
id: 'messagePermTree',
showCheckbox: true,
data: messagePermTreeData,
click: function (obj) {
tree.reload('messagePermTree');
oncheck: function (obj) {
}
});
......@@ -82,5 +82,9 @@
tree.reload('messagePermTree');
});
$(function () {
$('#permTree .layui-checkbox-disbaled').addClass('layui-form-checked');
});
});
</script>
......@@ -17,6 +17,7 @@
</blockquote>
<div class="layui-form-item">
<button class="layui-btn layui-btn-sm" type="button" id="selectAllMessagePerm">全选</button>
<br>
<div id="messagePermTree"></div>
</div>
<div class="layui-form-item">
......
......@@ -69,6 +69,7 @@
</blockquote>
<div class="layui-form-item">
<button class="layui-btn layui-btn-sm" type="button" id="selectAllPerm">全选</button>
<br>
<div id="permTree"></div>
</div>
<blockquote class="layui-elem-quote layui-text">
......@@ -76,6 +77,7 @@
</blockquote>
<div class="layui-form-item">
<button class="layui-btn layui-btn-sm" type="button" id="selectAllMessagePerm">全选</button>
<br>
<div id="messagePermTree"></div>
</div>
<div class="layui-form-item">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment