Commit 14736857 by 杨树贤

优化树形节点选中

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