Merge pull request 'master' (#44) from master into prod
Reviewed-on: http://git.feashow.cn/clay/mosr-web/pulls/44
This commit is contained in:
@@ -37,6 +37,13 @@ export const getRoleExcludeMenuId = (params) => {
|
|||||||
params
|
params
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 新增修改
|
||||||
|
export const operate = (data) => {
|
||||||
|
if(data.roleId) return editRole(data)
|
||||||
|
return addRole(data)
|
||||||
|
}
|
||||||
|
|
||||||
// 新增角色
|
// 新增角色
|
||||||
export const addRole = (data) => {
|
export const addRole = (data) => {
|
||||||
return request({
|
return request({
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
v-loading="localData.loading"
|
v-loading="localData.loading"
|
||||||
:row-key="tableConfig?.rowKey || 'id'"
|
:row-key="tableConfig?.rowKey || 'id'"
|
||||||
v-bind="$attrs"
|
v-bind="$attrs"
|
||||||
table-layout="fixed"
|
table-layout="auto"
|
||||||
:show-overflow-tooltip="true"
|
:show-overflow-tooltip="true"
|
||||||
highlight-current-row
|
highlight-current-row
|
||||||
@selection-change="selectionChange"
|
@selection-change="selectionChange"
|
||||||
|
|||||||
@@ -3,21 +3,69 @@
|
|||||||
<baseTitle title="角色信息录入"></baseTitle>
|
<baseTitle title="角色信息录入"></baseTitle>
|
||||||
<fvForm :schema="schame" @getInstance="getInstance" :rules="rules"></fvForm>
|
<fvForm :schema="schame" @getInstance="getInstance" :rules="rules"></fvForm>
|
||||||
<baseTitle title="分配菜单"></baseTitle>
|
<baseTitle title="分配菜单"></baseTitle>
|
||||||
|
<fvCheckbox :options="localData.checkOptions" v-model="localData.checkList" @change="checkBoxChange" />
|
||||||
|
<el-input v-model="localData.filterText" placeholder="请输入关键词" style="width: 400px;" />
|
||||||
|
<div class="menu-assign">
|
||||||
|
<el-tree
|
||||||
|
ref="menuTree"
|
||||||
|
:data="localData.menuData"
|
||||||
|
:filter-node-method="filterMenu"
|
||||||
|
:props="localData.menuTreeProps"
|
||||||
|
:check-strictly="localData.checkStrictly"
|
||||||
|
show-checkbox
|
||||||
|
node-key="menuId"
|
||||||
|
@check-change="checkChange"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="oper-page-btn">
|
||||||
|
<el-button type="primary" @click="handleSubmit">提交</el-button>
|
||||||
|
<el-button type="primary" @click="handleBack">返回</el-button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="jsx">
|
<script setup lang="jsx">
|
||||||
import { useTagsView } from '@/stores/tagsview.js'
|
import { useTagsView } from '@/stores/tagsview.js'
|
||||||
|
import { useAuthStore } from '@/stores/userstore.js'
|
||||||
import fvRadio from '@/fvcomponents/fvRadio/index.vue'
|
import fvRadio from '@/fvcomponents/fvRadio/index.vue'
|
||||||
|
import { ElLoading, ElNotification } from 'element-plus';
|
||||||
|
import { getMenuList } from '@/api/system/menuman.js'
|
||||||
|
import { getRoleDetail, operate} from "@/api/role/role";
|
||||||
|
|
||||||
const tagsViewStore = useTagsView()
|
const tagsViewStore = useTagsView()
|
||||||
|
const authStore = useAuthStore()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
|
|
||||||
const form = ref(null)
|
const form = ref(null)
|
||||||
|
const menuTree = ref(null)
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
|
|
||||||
|
const isExpand = ref('展开')
|
||||||
|
const isAllChose = ref('全选')
|
||||||
const localData = reactive({
|
const localData = reactive({
|
||||||
|
filterText: '',
|
||||||
|
menuData: [],
|
||||||
|
menuTreeProps: {
|
||||||
|
value: "menuId",
|
||||||
|
label: 'menuName',
|
||||||
|
children: 'children'
|
||||||
|
},
|
||||||
|
checkStrictly: false,
|
||||||
|
checkList: ['3'],
|
||||||
|
checkOptions: [
|
||||||
|
{
|
||||||
|
label: isExpand.value,
|
||||||
|
value: '1'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: isAllChose.value,
|
||||||
|
value: '2'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '父子联动',
|
||||||
|
value: '3'
|
||||||
|
},
|
||||||
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
const schame = computed(()=>{
|
const schame = computed(()=>{
|
||||||
@@ -47,19 +95,6 @@ const schame = computed(()=>{
|
|||||||
type: 'number'
|
type: 'number'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
|
||||||
label: '数据范围',
|
|
||||||
prop: 'dataScope',
|
|
||||||
component: markRaw(fvRadio),
|
|
||||||
props: {
|
|
||||||
options: [
|
|
||||||
{value:'1',label:'所有数据权限'},
|
|
||||||
{value:'2',label:'自定义数据权限'},
|
|
||||||
{value:'3',label:'本部门数据权限'},
|
|
||||||
{value:'4',label:'本部门及以下数据权限'}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
label: '状态',
|
label: '状态',
|
||||||
prop: 'state',
|
prop: 'state',
|
||||||
@@ -67,9 +102,20 @@ const schame = computed(()=>{
|
|||||||
props: {
|
props: {
|
||||||
cacheKey: 'normal_disable'
|
cacheKey: 'normal_disable'
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
label: '是否为模版',
|
||||||
|
prop: 'template',
|
||||||
|
component: markRaw(fvRadio),
|
||||||
|
props: {
|
||||||
|
options: [
|
||||||
|
{ label: '是', value: true },
|
||||||
|
{ label: '否', value: false },
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
]
|
]
|
||||||
return arr
|
return !authStore.roles.includes('superAdmin') ? arr.slice(-1) : arr
|
||||||
})
|
})
|
||||||
|
|
||||||
const rules = reactive({
|
const rules = reactive({
|
||||||
@@ -82,15 +128,99 @@ const getInstance = (e) => {
|
|||||||
form.value = e
|
form.value = e
|
||||||
}
|
}
|
||||||
|
|
||||||
const init = () => {
|
const init = async () => {
|
||||||
form.value.setValues({state: '1', dataScope: '1'})
|
form.value.setValues({state: '1', template: false})
|
||||||
|
const { data } = await getMenuList()
|
||||||
|
localData.menuData = data
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(()=>{
|
const getInfo = async () => {
|
||||||
init()
|
if(!route.query.id) return
|
||||||
|
const { data } = await getRoleDetail(route.query.id)
|
||||||
|
data.menuIds.forEach(key=>{
|
||||||
|
menuTree.value.setChecked(key, true, false)
|
||||||
|
})
|
||||||
|
if(route.query.isAdd) {
|
||||||
|
delete data.roleId
|
||||||
|
delete data.roleName
|
||||||
|
delete data.roleKey
|
||||||
|
}
|
||||||
|
form.value.setValues(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
const filterMenu = (value, data) => {
|
||||||
|
if(!value) return true
|
||||||
|
return data.menuName.includes(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkChange = (data) => {
|
||||||
|
return menuTree.value.getCheckedKeys()
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkBoxChange = (val) => {
|
||||||
|
localData.checkStrictly = val.includes('3')
|
||||||
|
let nodes = menuTree.value.store.nodesMap
|
||||||
|
if (val.includes('1')) {
|
||||||
|
for (const node in nodes) {
|
||||||
|
nodes[node].expanded = true;
|
||||||
|
}
|
||||||
|
isExpand.value = '折叠'
|
||||||
|
} else {
|
||||||
|
for (const node in nodes) {
|
||||||
|
nodes[node].expanded = false;
|
||||||
|
}
|
||||||
|
isExpand.value = '展开'
|
||||||
|
}
|
||||||
|
if (val.includes('2')) {
|
||||||
|
menuTree.value.setCheckedNodes(localData.menuData)
|
||||||
|
isAllChose.value = '不全选'
|
||||||
|
} else {
|
||||||
|
menuTree.value.setCheckedNodes([])
|
||||||
|
isAllChose.value = '全选'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSubmit = async () => {
|
||||||
|
const loading = ElLoading.service({fullscreen: true})
|
||||||
|
const { isValidate } = await form.value.validate()
|
||||||
|
if(!isValidate) return Promise.reject()
|
||||||
|
const values = form.value.getValues()
|
||||||
|
values.menuIds = checkChange()
|
||||||
|
operate(values).then(res=>{
|
||||||
|
ElNotification({
|
||||||
|
title: route.query.isAdd ? '新增' : '编辑',
|
||||||
|
message: res.msg,
|
||||||
|
type: res.code === 1000 ? 'success' : 'error'
|
||||||
|
})
|
||||||
|
loading.close()
|
||||||
|
res.code === 1000 ? tagsViewStore.delViewAndGoView('/system/role') : null
|
||||||
|
}).finally(()=>{
|
||||||
|
loading.close()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleBack = () => {
|
||||||
|
history.back()
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(localData, (val)=>{
|
||||||
|
menuTree.value.filter(val.filterText)
|
||||||
|
})
|
||||||
|
|
||||||
|
onMounted( async ()=>{
|
||||||
|
loading.value = true
|
||||||
|
await init()
|
||||||
|
if(route.query.id) {
|
||||||
|
await getInfo()
|
||||||
|
}
|
||||||
|
loading.value = false
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
.menu-assign {
|
||||||
|
width: 400px;
|
||||||
|
max-height: 500px;
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -6,8 +6,11 @@
|
|||||||
<script setup lang="jsx">
|
<script setup lang="jsx">
|
||||||
import fvSelect from '@/fvcomponents/fvSelect/index.vue'
|
import fvSelect from '@/fvcomponents/fvSelect/index.vue'
|
||||||
import Tag from '@/components/Tag.vue'
|
import Tag from '@/components/Tag.vue'
|
||||||
import { ElMessageBox } from 'element-plus';
|
import { ElMessageBox, ElNotification } from 'element-plus';
|
||||||
|
import { deleteRole } from "@/api/role/role";
|
||||||
|
import { useAuthStore } from '@/stores/userstore.js'
|
||||||
|
|
||||||
|
const authStore = useAuthStore()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
const shortcuts = [
|
const shortcuts = [
|
||||||
@@ -87,6 +90,12 @@ const searchConfig = reactive([
|
|||||||
|
|
||||||
const tableIns = ref()
|
const tableIns = ref()
|
||||||
|
|
||||||
|
const auths = {
|
||||||
|
edit: ['admin:role:edit'],
|
||||||
|
del: ['admin:role:del'],
|
||||||
|
add: ['admin:role:add'],
|
||||||
|
}
|
||||||
|
|
||||||
const tableConfig = reactive({
|
const tableConfig = reactive({
|
||||||
columns: [
|
columns: [
|
||||||
{
|
{
|
||||||
@@ -119,18 +128,52 @@ const tableConfig = reactive({
|
|||||||
{
|
{
|
||||||
prop: 'oper',
|
prop: 'oper',
|
||||||
label: '操作',
|
label: '操作',
|
||||||
align: 'center',
|
align: 'right',
|
||||||
currentRender: ({row, index}) => (
|
currentRender: ({row, index}) => {
|
||||||
<div>
|
let btn = [{label: '修改', auth: auths.edit, func: ()=>handleEdit(row) , type: 'primary'}]
|
||||||
<el-button type="primary" link onClick={()=>handleEdit(row)}>修改</el-button>
|
row.template ?
|
||||||
<el-button type="primary" link onClick={()=>handleAssign(row)}>分配用户</el-button>
|
btn.push(
|
||||||
<el-button type="danger" link onClick={()=>handleDel(row)}>删除</el-button>
|
{
|
||||||
</div>
|
label: '使用模版',
|
||||||
)
|
auth: auths.edit,
|
||||||
|
func: ()=>handleUseTemp(row),
|
||||||
|
type: 'primary'
|
||||||
|
}
|
||||||
|
) :
|
||||||
|
btn.push(
|
||||||
|
{
|
||||||
|
label: '分配用户',
|
||||||
|
auth: auths.edit,
|
||||||
|
func: ()=>handleAssign(row),
|
||||||
|
type: 'primary'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
if(authStore.roles.includes('superAdmin')) {
|
||||||
|
btn.push({label: '删除', auth: auths.edit, func: ()=>handleDel(row) , type: 'danger'})
|
||||||
|
} else if(!row.template) {
|
||||||
|
btn.push({label: '删除', auth: auths.edit, func: ()=>handleDel(row) , type: 'danger'})
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{
|
||||||
|
btn.map(item=>(
|
||||||
|
<el-button
|
||||||
|
type={item.type}
|
||||||
|
v-perm={item.auth}
|
||||||
|
onClick={()=>item.func()}
|
||||||
|
link
|
||||||
|
>
|
||||||
|
{item.label}
|
||||||
|
</el-button>
|
||||||
|
))
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
api: '/admin/role',
|
api: '/admin/role',
|
||||||
btns: [{name: '新增', key: 'add', auth: ['admin:role:add'], type: 'primary'}],
|
btns: [{name: '新增', key: 'add', auth: auths.add, type: 'primary'}],
|
||||||
params: {}
|
params: {}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -170,7 +213,22 @@ const handleAdd = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleEdit = (row) => {
|
const handleEdit = (row) => {
|
||||||
|
router.push({
|
||||||
|
path: '/system/roleedit',
|
||||||
|
query: {
|
||||||
|
id: row.roleId
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleUseTemp = (row) => {
|
||||||
|
router.push({
|
||||||
|
path: '/system/roleadd',
|
||||||
|
query: {
|
||||||
|
id: row.roleId,
|
||||||
|
isAdd: 1
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleAssign = (row) => {
|
const handleAssign = (row) => {
|
||||||
@@ -178,12 +236,27 @@ const handleAssign = (row) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleDel = (row) => {
|
const handleDel = (row) => {
|
||||||
|
if (!(row.template && authStore.roles.includes('superAdmin'))) {
|
||||||
|
ElNotification({
|
||||||
|
title: '提示',
|
||||||
|
message: '模版角色只能由超级管理员删除!',
|
||||||
|
type: 'warning'
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
ElMessageBox.confirm('确定删除该条数据吗?', '确定删除', {
|
ElMessageBox.confirm('确定删除该条数据吗?', '确定删除', {
|
||||||
type: 'warning',
|
type: 'warning',
|
||||||
confirmButtonText: '确定',
|
confirmButtonText: '确定',
|
||||||
cancelButtonText: '取消'
|
cancelButtonText: '取消'
|
||||||
}).then(async res => {
|
}).then(async res => {
|
||||||
// const { code } = await
|
const { code, msg } = await deleteRole(row.roleId)
|
||||||
|
ElNotification({
|
||||||
|
title: '删除',
|
||||||
|
message: msg,
|
||||||
|
type: code === 1000 ? 'success' : 'error'
|
||||||
|
})
|
||||||
|
tableIns.value.refresh()
|
||||||
}).catch(()=>{})
|
}).catch(()=>{})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user