优化权限设置。

This commit is contained in:
evoxwht 2023-05-25 09:17:46 +08:00
parent 5442c0e2cb
commit 7e41b75103
5 changed files with 64 additions and 42 deletions

View File

@ -76,7 +76,7 @@ class SystemMenusServices extends BaseServices
$systemRoleServices = app()->make(SystemRoleServices::class);
$rules = $systemRoleServices->getRoleArray(['status' => 1, 'id' => $rouleId], 'rules');
$rulesStr = Arr::unique($rules);
$menusList = $this->dao->getMenusRoule(['route' => $level ? $rulesStr : '']);
$menusList = $this->dao->getMenusRoule(['route' => $level ? $rulesStr : '', 'is_show_path' => 1]);
$unique = $this->dao->getMenusUnique(['unique' => $level ? $rulesStr : '']);
return [Arr::getMenuIviewList($this->getMenusData($menusList)), $unique];
}
@ -123,9 +123,6 @@ class SystemMenusServices extends BaseServices
protected function getFormCascaderMenus(int $value = 0, $auth_type = 0)
{
$where = ['is_del' => 0];
if ($auth_type == 3) {
$where = ['is_del' => 0, 'auth_type' => 3];
}
$menuList = $this->dao->getMenusRoule($where, ['id as value', 'pid', 'menu_name as label']);
$menuList = $this->getMenusData($menuList);
if ($value) {
@ -152,7 +149,7 @@ class SystemMenusServices extends BaseServices
$field[] = Form::input('unique_auth', '权限标识', $formData['unique_auth'] ?? '')->placeholder('不填写则后台自动生成');
$field[] = Form::frameInput('icon', '图标', $this->url(config('app.admin_prefix', 'admin') . '/widget.widgets/icon', ['fodder' => 'icon']), $formData['icon'] ?? '')->icon('md-add')->height('505px')->modal(['footer-hide' => true]);
$field[] = Form::number('sort', '排序', (int)($formData['sort'] ?? 0))->precision(0);
$field[] = Form::radio('auth_type', '类型', $formData['auth_type'] ?? 1)->options([['value' => 1, 'label' => '菜单'], ['value' => 3, 'label' => '按钮']]);
$field[] = Form::radio('auth_type', '类型', $formData['auth_type'] ?? 1)->options([['value' => 1, 'label' => '菜单'], ['value' => 3, 'label' => '按钮'], ['value' => 2, 'label' => '接口']]);
$field[] = Form::radio('is_show', '权限状态', $formData['is_show'] ?? 1)->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]);
$field[] = Form::radio('is_show_path', '是否显示', $formData['is_show_path'] ?? 0)->options([['value' => 1, 'label' => '显示'], ['value' => 0, 'label' => '隐藏']]);
[$menuList, $data] = $this->getFormCascaderMenus((int)($formData['pid'] ?? 0), 3);
@ -249,7 +246,7 @@ class SystemMenusServices extends BaseServices
public function getMenus($roles): array
{
$field = ['menu_name', 'pid', 'id'];
$where = ['is_del' => 0, 'auth_type' => 3];
$where = ['is_del' => 0, 'is_show_path' => 1];
if (!$roles) {
$menus = $this->dao->getMenusRoule($where, $field);
} else {

View File

@ -2,7 +2,7 @@
<div>
<Modal
v-model="modals"
width="700"
width="500"
scrollable
closable
:title="titleFrom"
@ -132,11 +132,11 @@ export default {
searchRule: '',
iconVal: '',
grid: {
xl: 23,
lg: 12,
md: 12,
sm: 24,
xs: 24,
xl: 22,
lg: 22,
md: 22,
sm: 22,
xs: 22,
},
modals: false,
modal12: false,

View File

@ -42,10 +42,11 @@
row-id="id"
>
<vxe-table-column field="menu_name" tree-node title="按钮名称" min-width="100"></vxe-table-column>
<vxe-table-column field="menu_path" title="路径" min-width="240" tooltip="true">
<vxe-table-column field="menu_path" title="类型" min-width="240" tooltip="true">
<template v-slot="{ row }">
<span v-if="row.auth_type == 1">页面:{{ row.menu_path }}</span>
<span v-if="row.auth_type == 2">按钮:[{{ row.methods }}]{{ row.api_url }}</span>
<span v-if="row.auth_type == 3">按钮</span>
<span v-if="row.auth_type == 2">数据权限</span>
</template>
</vxe-table-column>
<vxe-table-column field="sort" title="排序" width="150"></vxe-table-column>
@ -58,7 +59,6 @@
:false-value="0"
@on-change="onchangeIsShow(row)"
size="large"
v-if="row.auth_type == 1"
>
<span slot="open">显示</span>
<span slot="close">隐藏</span>
@ -177,7 +177,7 @@ export default {
roleData: {
is_show: 1,
keyword: '',
auth_type: 3,
// auth_type: 3,
},
defaultProps: {
children: 'children',

View File

@ -2,21 +2,33 @@
<div>
<Modal
v-model="modals"
width="700"
width="500"
scrollable
closable
:title="titleFrom"
:mask-closable="false"
:z-index="1"
@on-cancel="handleReset"
@on-visible-change="visible"
>
<Form ref="formValidate" :model="formValidate" :label-width="110" @submit.native.prevent>
<Row type="flex" :gutter="24">
<Col v-bind="grid">
<FormItem label="按钮名称:" prop="menu_name">
<FormItem label="类型:">
<RadioGroup v-model="formValidate.auth_type" @on-change="changeAuthType">
<Radio :label="item.value" v-for="(item, i) in optionsRadio" :key="i">
<Icon type="social-apple"></Icon>
<span>{{ item.label }}</span>
</Radio>
</RadioGroup>
</FormItem>
</Col>
<Col v-bind="grid">
<FormItem :label="authType == 2 ? '接口名称:' : authType == 1 ? '菜单名称:' : '按钮名称:'" prop="menu_name">
<div class="add">
<Input v-model="formValidate.menu_name" placeholder="请输入按钮名称">
<Input
v-model="formValidate.menu_name"
:placeholder="authType == 2 ? '请输入接口名称' : authType == 1 ? '请输入菜单名称' : '请输入按钮名称'"
>
</Input>
</div>
</FormItem>
@ -26,21 +38,30 @@
<Cascader :data="menuList" change-on-select v-model="formValidate.path" filterable></Cascader>
</FormItem>
</Col>
<Col v-bind="grid">
<FormItem label="路由地址:" prop="menu_path">
<Input v-model="formValidate.menu_path" placeholder="请输入路由地址" @on-change="changeUnique">
<Col v-bind="grid" v-if="authType != 2">
<FormItem label="页面地址:" prop="menu_path">
<Input v-model="formValidate.menu_path" placeholder="请输入页面地址" @on-change="changeUnique">
<template #prepend>
<span>{{ $routeProStr }}</span>
</template>
</Input>
</FormItem>
</Col>
<Col v-bind="grid" v-if="authType == 2">
<FormItem label="接口地址:" prop="api_url">
<Input v-model="formValidate.api_url" placeholder="请输入接口地址" @on-change="changeUnique">
<template #prepend>
<span>adminapi/</span>
</template>
</Input>
</FormItem>
</Col>
<Col v-bind="grid">
<FormItem label="权限标识:" prop="unique_auth">
<Input v-model="formValidate.unique_auth" placeholder="请输入权限标识"></Input>
</FormItem>
</Col>
<Col v-bind="grid">
<Col v-bind="grid" v-if="authType != 2">
<FormItem label="图标:">
<Input
v-model="formValidate.icon"
@ -50,20 +71,14 @@
></Input>
</FormItem>
</Col>
<Col v-bind="grid">
<FormItem label="排序:">
<Input type="number" v-model="formValidate.sort" placeholder="请输入排序" number></Input>
<FormItem label="备注:">
<Input v-model="formValidate.mark" placeholder="请输入备注" number></Input>
</FormItem>
</Col>
<Col v-bind="grid">
<FormItem label="类型:">
<RadioGroup v-model="formValidate.auth_type">
<Radio :label="item.value" v-for="(item, i) in optionsRadio" :key="i">
<Icon type="social-apple"></Icon>
<span>{{ item.label }}</span>
</Radio>
</RadioGroup>
<FormItem label="排序:">
<Input type="number" v-model="formValidate.sort" placeholder="请输入排序" number></Input>
</FormItem>
</Col>
<Col v-bind="grid">
@ -157,11 +172,11 @@ export default {
searchRule: '',
iconVal: '',
grid: {
xl: 12,
lg: 12,
md: 12,
sm: 24,
xs: 24,
xl: 22,
lg: 22,
md: 22,
sm: 22,
xs: 22,
},
modals: false,
modal12: false,
@ -172,12 +187,19 @@ export default {
search: icon,
ruleModal: false,
ruleList: [],
authType: 1
};
},
watch: {
'formValidate.header': function (n) {
this.formValidate.is_header = n ? 1 : 0;
},
'formValidate.auth_type': function (n) {
if (n === undefined) {
n = 1;
}
this.authType = n;
},
'formValidate.data': function (n) {},
},
computed: {
@ -275,6 +297,9 @@ export default {
if (value.slice(0, 1) === '/') value = value.replace('/', '');
this.formValidate.unique_auth = value.replaceAll('/', '-');
},
changeAuthType(val) {
this.authType = val;
},
selectRule(data) {
this.$emit('selectRule', data);
this.$nextTick((e) => {

View File

@ -69,9 +69,9 @@
<vxe-table-column field="date" title="操作" align="right" width="250" fixed="right">
<template v-slot="{ row }">
<span>
<a @click="addRoute(row)" v-if="row.auth_type === 1 || row.auth_type === 3">添加权限</a>
<a @click="addRoute(row)" v-if="row.auth_type === 1 || row.auth_type === 3">选择权限</a>
<Divider type="vertical" v-if="row.auth_type === 1 || row.auth_type === 3"/>
<a @click="addE(row, '添加子菜单')" v-if="row.auth_type === 1">添加子菜单</a>
<a @click="addE(row, '添加子菜单')" v-if="row.auth_type === 1">添加下级</a>
<!-- <a @click="addE(row, '添加规则')" v-else>添加规则</a> -->
</span>
<Divider type="vertical" v-if="row.auth_type === 1" />
@ -101,7 +101,7 @@
>
<div class="search-rule">
<Alert
>基础接口,可多选,并且添加后不会再展示出现;删除权限后才会出现;公共接口,可多选,并且添加后会继续展示;</Alert
>1.接口可多选,可重复添加;<br>2.添加路由按照路由规则进行添加,即可在开发工具->接口管理里面点击同步;<br>3.同步完成即可在此选择对应的接口;</Alert
>
<Input
class="mr10"