更新权限

This commit is contained in:
evoxwht 2023-05-21 23:49:11 +08:00
parent 9647d96978
commit a12c774c45
6 changed files with 32 additions and 74 deletions

View File

@ -77,6 +77,10 @@ class SystemRole extends AuthController
if (!$data['role_name']) return app('json')->fail(400220);
if (!is_array($data['rules']) || !count($data['rules']))
return app('json')->fail(400221);
$res = app()->make(SystemMenusServices::class)->getColumn([['pid', 'in', $data['rules']]], 'id');
$data['rules'] = array_merge($data['rules'], $res);
$data['rules'] = implode(',', $data['rules']);
if ($id) {
if (!$this->services->update($id, $data)) return app('json')->fail(100007);

View File

@ -232,7 +232,11 @@ class SystemMenus extends BaseModel
public function searchAuthTypeAttr($query, $value)
{
if ($value !== '') {
$query->where('auth_type', $value);
if ($value == 3) {
$query->whereIn('auth_type', [1, 3]);
} else {
$query->where('auth_type', $value);
}
}
}
}

View File

@ -120,9 +120,13 @@ class SystemMenusServices extends BaseServices
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
protected function getFormCascaderMenus(int $value = 0)
protected function getFormCascaderMenus(int $value = 0, $auth_type = 0)
{
$menuList = $this->dao->getMenusRoule(['is_del' => 0], ['id as value', 'pid', 'menu_name as label']);
$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) {
$data = get_tree_value($menuList, $value);
@ -151,7 +155,7 @@ class SystemMenusServices extends BaseServices
$field[] = Form::radio('auth_type', '类型', $formData['auth_type'] ?? 1)->options([['value' => 1, 'label' => '菜单'], ['value' => 3, '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));
[$menuList, $data] = $this->getFormCascaderMenus((int)($formData['pid'] ?? 0), 3);
$field[] = Form::cascader('menu_list', '父级id', $data)->data($menuList)->filterable(true);
return $field;
}
@ -245,7 +249,7 @@ class SystemMenusServices extends BaseServices
public function getMenus($roles): array
{
$field = ['menu_name', 'pid', 'id'];
$where = ['is_del' => 0];
$where = ['is_del' => 0, 'auth_type' => 3];
if (!$roles) {
$menus = $this->dao->getMenusRoule($where, $field);
} else {

View File

@ -177,7 +177,7 @@ export default {
roleData: {
is_show: 1,
keyword: '',
// auth_type: 1,
auth_type: 3,
},
defaultProps: {
children: 'children',

View File

@ -14,11 +14,10 @@
<Form ref="formValidate" :model="formValidate" :label-width="110" @submit.native.prevent>
<Row type="flex" :gutter="24">
<Col v-bind="grid">
<FormItem :label="!authType ? '接口名称:' : '按钮名称:'" prop="menu_name">
<FormItem label="按钮名称:" prop="menu_name">
<div class="add">
<Input v-model="formValidate.menu_name" :placeholder="!authType ? '请输入接口名称' : '请输入按钮名称'">
<Input v-model="formValidate.menu_name" placeholder="请输入按钮名称">
</Input>
<!-- <Button class="ml10 df" v-show="!authType" @click="getRuleList()" icon="ios-apps"></Button> -->
</div>
</FormItem>
</Col>
@ -27,23 +26,7 @@
<Cascader :data="menuList" change-on-select v-model="formValidate.path" filterable></Cascader>
</FormItem>
</Col>
<!-- <Col v-bind="grid" v-if="!authType">
<FormItem label="请求方式:" prop="methods">
<Select v-model="formValidate.methods">
<Option value="">请求</Option>
<Option value="GET">GET</Option>
<Option value="POST">POST</Option>
<Option value="PUT">PUT</Option>
<Option value="DELETE">DELETE</Option>
</Select>
</FormItem>
</Col> -->
<!-- <Col v-bind="grid" v-if="!authType">
<FormItem label="接口地址:">
<Input v-model="formValidate.api_url" placeholder="请输入接口地址" prop="api_url"></Input>
</FormItem>
</Col> -->
<Col v-bind="grid" v-show="authType">
<Col v-bind="grid">
<FormItem label="路由地址:" prop="menu_path">
<Input v-model="formValidate.menu_path" placeholder="请输入路由地址" @on-change="changeUnique">
<template #prepend>
@ -57,7 +40,7 @@
<Input v-model="formValidate.unique_auth" placeholder="请输入权限标识"></Input>
</FormItem>
</Col>
<Col v-bind="grid" v-if="authType">
<Col v-bind="grid">
<FormItem label="图标:">
<Input
v-model="formValidate.icon"
@ -68,24 +51,14 @@
</FormItem>
</Col>
<Col v-bind="grid" v-if="authType">
<Col v-bind="grid">
<FormItem label="排序:">
<Input type="number" v-model="formValidate.sort" placeholder="请输入排序" number></Input>
</FormItem>
</Col>
<!-- <Col v-bind="grid" v-show="authType">
<FormItem label="隐藏菜单:">
<RadioGroup v-model="formValidate.is_show_path">
<Radio :label="item.value" v-for="(item, i) in isShowPathRadio" :key="i">
<Icon type="social-apple"></Icon>
<span>{{ item.label }}</span>
</Radio>
</RadioGroup>
</FormItem>
</Col> -->
<Col v-bind="grid">
<FormItem label="类型:">
<RadioGroup v-model="formValidate.auth_type" @on-change="changeRadio">
<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>
@ -196,7 +169,6 @@ export default {
valids: false,
list2: [],
list: icon,
authType: true,
search: icon,
ruleModal: false,
ruleList: [],
@ -206,12 +178,6 @@ export default {
'formValidate.header': function (n) {
this.formValidate.is_header = n ? 1 : 0;
},
'formValidate.auth_type': function (n) {
if (n === undefined) {
n = 1;
}
this.authType = n === 1;
},
'formValidate.data': function (n) {},
},
computed: {
@ -309,20 +275,12 @@ export default {
if (value.slice(0, 1) === '/') value = value.replace('/', '');
this.formValidate.unique_auth = value.replaceAll('/', '-');
},
visible(type) {
if (!type) {
this.authType = true;
}
},
selectRule(data) {
this.$emit('selectRule', data);
this.$nextTick((e) => {
this.ruleModal = false;
});
},
changeRadio(n) {
this.authType = n === 1 ? true : false;
},
// 搜索
upIcon(n) {
let arrs = [];
@ -385,23 +343,11 @@ export default {
method: this.formValidate.id ? 'put' : 'post',
datas: this.formValidate,
};
if (this.authType) {
if (!this.formValidate.menu_name) {
return this.$Message.warning('请填写按钮名称');
}
if (!this.formValidate.menu_path) {
return this.$Message.warning('请填写路由地址');
}
} else {
if (!this.formValidate.menu_name) {
return this.$Message.warning('请填写接口名称');
}
if (!this.formValidate.methods) {
return this.$Message.warning('请选择请求方式');
}
if (!this.formValidate.api_url) {
return this.$Message.warning('请选择接口地址');
}
if (!this.formValidate.menu_name) {
return this.$Message.warning('请填写按钮名称');
}
if (!this.formValidate.menu_path) {
return this.$Message.warning('请填写路由地址');
}
this.valids = true;
addMenusApi(data)
@ -419,7 +365,6 @@ export default {
},
handleReset() {
this.modals = false;
this.authType = true;
this.$refs['formValidate'].resetFields();
this.$emit('clearFrom');
},

View File

@ -47,6 +47,7 @@
<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>
</template>
</vxe-table-column>
<vxe-table-column field="flag" title="规则状态" min-width="120">
@ -68,8 +69,8 @@
<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">添加权限</a>
<Divider type="vertical" v-if="row.auth_type === 1" />
<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-else>添加规则</a> -->
</span>