feat:完成所有功能
This commit is contained in:
parent
7b1d87aa65
commit
5566e6693b
@ -1,5 +1,5 @@
|
||||
from core.utils import list_to_tree
|
||||
from dbhelper.menu import del_menu, get_tree_menu, insert_menu, put_menu
|
||||
from dbhelper.menu import del_menu, get_menu, get_tree_menu, insert_menu, put_menu
|
||||
from schemas import MenuIn, MenuRead, Response
|
||||
|
||||
|
||||
@ -9,10 +9,16 @@ async def menu_add(data: MenuIn) -> Response[MenuRead]:
|
||||
|
||||
async def menu_arr() -> Response:
|
||||
menus = await get_tree_menu()
|
||||
return Response(data=list_to_tree(menus))
|
||||
try:
|
||||
data = list_to_tree(menus)
|
||||
except KeyError:
|
||||
return Response(code=400, msg="菜单根节点丢失")
|
||||
return Response(data=data)
|
||||
|
||||
|
||||
async def menu_del(pk: int) -> Response:
|
||||
if await get_menu({"pid": pk}) is not None:
|
||||
return Response(code=400, msg="请先删除子节点")
|
||||
if await del_menu(pk) == 0:
|
||||
return Response(code=400, msg="菜单不存在")
|
||||
return Response()
|
||||
|
@ -26,8 +26,7 @@ async def role_has_menu(rid: int):
|
||||
rid: 角色ID
|
||||
"""
|
||||
menus = await get_role_menus(rid)
|
||||
for obj in menus:
|
||||
obj["meta"] = json.loads(obj["meta"]) if obj["meta"] is not None else None
|
||||
|
||||
try:
|
||||
result = list_to_tree(menus)
|
||||
except KeyError:
|
||||
|
@ -70,7 +70,7 @@ async def check_permissions(request: Request, user: UserModel = Depends(check_to
|
||||
result = await get_user_info(user)
|
||||
active_rid = result["roles"][0]["id"]
|
||||
|
||||
# 白名单
|
||||
# 白名单 登录用户信息, 登录用户菜单信息
|
||||
whitelist = [f"/user/{user.id}", f"/role/{active_rid}/menu"]
|
||||
flag = request.url.path in whitelist and request.method == "GET"
|
||||
if flag:
|
||||
|
@ -45,7 +45,7 @@ async def get_menu(kwargs):
|
||||
|
||||
|
||||
async def del_menu(mid: int):
|
||||
"""删除用户"""
|
||||
"""删除菜单"""
|
||||
return await MenuModel.filter(id=mid).update(status=9)
|
||||
|
||||
|
||||
|
@ -9,11 +9,12 @@ async def get_role_menus(rid: int):
|
||||
根据角色id 获取菜单
|
||||
"""
|
||||
db = connections.get("default")
|
||||
# asc 降序
|
||||
return await db.execute_query_dict(
|
||||
"""
|
||||
select m.id, m.name, m.meta, m.path, m.type, m.component, m.pid, m.identifier, m.api, m.method
|
||||
select m.id, m.name, m.icon, m.path, m.type, m.component, m.pid, m.identifier, m.api, m.method
|
||||
FROM sys_menu as m, sys_role_menu WHERE m.id = sys_role_menu.mid
|
||||
AND sys_role_menu.rid = (?) AND sys_role_menu.`status` = 1""",
|
||||
AND sys_role_menu.rid = (?) AND sys_role_menu.`status` = 1 order by m.id asc""",
|
||||
[rid],
|
||||
)
|
||||
|
||||
|
@ -31,7 +31,6 @@ async def get_user_info(user: UserModel):
|
||||
""",
|
||||
[user.id],
|
||||
)
|
||||
|
||||
return {
|
||||
**jsonable_encoder(user),
|
||||
"roles": sql_result,
|
||||
@ -81,9 +80,9 @@ async def put_user(uid: int, data: UserPut):
|
||||
"""更新用户"""
|
||||
from core.security import get_password_hash
|
||||
|
||||
roles = data.roles
|
||||
rids = data.roles
|
||||
del data.roles
|
||||
for role in roles:
|
||||
for role in rids:
|
||||
if await get_role({"id": role.rid, "status__not": 9}) is None:
|
||||
return role.rid
|
||||
# 更新用户
|
||||
@ -104,7 +103,6 @@ async def put_user(uid: int, data: UserPut):
|
||||
""",
|
||||
[uid],
|
||||
)
|
||||
print(has_roles)
|
||||
|
||||
# 2. 将先有的数据标记 删除
|
||||
[
|
||||
@ -119,11 +117,13 @@ async def put_user(uid: int, data: UserPut):
|
||||
|
||||
# 2. 新增次此更新的数据
|
||||
await UserRoleModel.bulk_create(
|
||||
[UserRoleModel(uid=uid, **role.dict()) for role in roles]
|
||||
[UserRoleModel(uid=uid, **role.dict()) for role in rids]
|
||||
)
|
||||
|
||||
|
||||
async def select_role(uid: int, rid: int):
|
||||
"""用户切换角色"""
|
||||
await UserRoleModel.filter(uid=uid, rid__not=rid).update(status=1)
|
||||
return await UserRoleModel.filter(uid=uid, rid=rid).update(status=5)
|
||||
# 1.将用户id 未删除角色状态置为正常 1 ( 除切换角色id )
|
||||
await UserRoleModel.filter(uid=uid, rid__not=rid, status__not=9).update(status=1)
|
||||
# 2.将用户id 角色id 和当前角色匹配的数据置为选中
|
||||
return await UserRoleModel.filter(uid=uid, rid=rid, status__not=9).update(status=5)
|
||||
|
BIN
backend/mini.db
Normal file
BIN
backend/mini.db
Normal file
Binary file not shown.
BIN
backend/mini.db-shm
Normal file
BIN
backend/mini.db-shm
Normal file
Binary file not shown.
BIN
backend/mini.db-wal
Normal file
BIN
backend/mini.db-wal
Normal file
Binary file not shown.
@ -7,9 +7,9 @@ class MenuModel(Table):
|
||||
"""
|
||||
|
||||
name = fields.CharField(max_length=20, description="名称", null=True)
|
||||
meta = fields.JSONField(description="元数据信息", null=True)
|
||||
icon = fields.CharField(max_length=100, description="菜单图标", null=True)
|
||||
path = fields.CharField(max_length=128, description="菜单url", null=True)
|
||||
type = fields.SmallIntField(description="菜单类型 0目录 1组件 2按钮")
|
||||
type = fields.SmallIntField(description="菜单类型 0目录 1组件 2按钮 3数据")
|
||||
component = fields.CharField(max_length=128, description="组件地址", null=True)
|
||||
pid = fields.IntField(description="父id", null=True)
|
||||
identifier = fields.CharField(max_length=30, description="权限标识 user:add", null=True)
|
||||
|
@ -121,7 +121,6 @@ class Route(routing.APIRoute):
|
||||
|
||||
|
||||
has_perm = {"dependencies": [Depends(check_permissions)]}
|
||||
has_perm = {}
|
||||
|
||||
routes = [
|
||||
Route.post("/login", endpoint=login, tags=["公共"], summary="登录"),
|
||||
|
@ -6,8 +6,8 @@ from schemas.common import ReadBase
|
||||
|
||||
|
||||
class MenuBasic(BaseModel):
|
||||
name: str
|
||||
meta: dict = Field(default=None, description="元信息")
|
||||
name: str = Field(..., description="菜单名称")
|
||||
icon: str = Field(default=None, description="菜单图标")
|
||||
path: Optional[str] = Field(default=None, description="前端路由地址")
|
||||
type: int = Field(description="0 目录 1 组件 2 按钮 3数据")
|
||||
component: Optional[str] = Field(default=None, description="前端组件地址")
|
||||
|
@ -13,29 +13,21 @@ dirs = [
|
||||
(
|
||||
"/menu",
|
||||
MenuIn( # id 1
|
||||
name="系统管理",
|
||||
meta={"icon": "AppstoreOutlined"},
|
||||
path="/system",
|
||||
name="系统面板",
|
||||
icon="DashboardOutlined",
|
||||
path="/dashboard",
|
||||
type=0,
|
||||
component=None,
|
||||
pid=0,
|
||||
identifier=None,
|
||||
api=None,
|
||||
method=None,
|
||||
).dict(),
|
||||
),
|
||||
(
|
||||
"/menu",
|
||||
MenuIn( # id 2
|
||||
name="系统设置",
|
||||
meta={"icon": "SettingOutlined"},
|
||||
name="系统管理",
|
||||
icon="AppstoreOutlined",
|
||||
path="/system",
|
||||
type=0,
|
||||
component=None,
|
||||
pid=0,
|
||||
identifier=None,
|
||||
api=None,
|
||||
method=None,
|
||||
).dict(),
|
||||
),
|
||||
]
|
||||
@ -54,44 +46,44 @@ menus = [
|
||||
"/menu",
|
||||
MenuIn( # id 3
|
||||
name="用户管理",
|
||||
meta={"icon": "TeamOutlined", "title": "用户管理"},
|
||||
icon="TeamOutlined",
|
||||
path="/system/user",
|
||||
type=1,
|
||||
component="/system/user/user.vue",
|
||||
pid=1,
|
||||
pid=2,
|
||||
).dict(),
|
||||
),
|
||||
(
|
||||
"/menu",
|
||||
MenuIn( # id 4
|
||||
name="角色管理",
|
||||
meta={"icon": "UserOutlined", "title": "角色管理"},
|
||||
icon="UserOutlined",
|
||||
path="/system/role",
|
||||
type=1,
|
||||
component="/system/role/role.vue",
|
||||
pid=1,
|
||||
pid=2,
|
||||
).dict(),
|
||||
),
|
||||
(
|
||||
"/menu",
|
||||
MenuIn( # id 5
|
||||
name="菜单管理",
|
||||
meta={"icon": "MenuOutlined", "title": "菜单管理"},
|
||||
icon="MenuOutlined",
|
||||
path="/system/menu",
|
||||
type=1,
|
||||
component="/system/menu/menu.vue",
|
||||
pid=1,
|
||||
pid=2,
|
||||
).dict(),
|
||||
),
|
||||
(
|
||||
"/menu",
|
||||
MenuIn( # id 6
|
||||
name="关于",
|
||||
meta={"icon": "DashboardOutlined", "title": "关于"},
|
||||
path="/setting/about",
|
||||
name="数据面板",
|
||||
icon="AreaChartOutlined",
|
||||
path="/dashboard/index",
|
||||
type=1,
|
||||
component="/setting/about/about.vue",
|
||||
pid=2,
|
||||
component="/dashboard/index/index.vue",
|
||||
pid=1,
|
||||
).dict(),
|
||||
),
|
||||
]
|
||||
@ -174,7 +166,6 @@ role_manager_pre = [
|
||||
),
|
||||
MenuIn(
|
||||
name="角色查询",
|
||||
meta={"icon": "Search"},
|
||||
type=2,
|
||||
identifier="role:query",
|
||||
api="/role/query",
|
||||
@ -260,13 +251,14 @@ menus_len = (
|
||||
+ len(dirs)
|
||||
+ len(role_manager_pre)
|
||||
+ len(menu_manager_pre)
|
||||
+ 1
|
||||
)
|
||||
|
||||
datas = [
|
||||
(
|
||||
"/role",
|
||||
RoleIn(
|
||||
name="superStar",
|
||||
name="超管",
|
||||
remark="全部权限",
|
||||
menus=[num for num in range(1, menus_len)],
|
||||
),
|
||||
@ -276,7 +268,7 @@ datas = [
|
||||
"/user",
|
||||
UserAdd(
|
||||
username="admin",
|
||||
nickname="666管理员",
|
||||
nickname="乐师高渐离",
|
||||
password="123456",
|
||||
roles=[RoleActive(rid=1, status=5)],
|
||||
),
|
||||
|
@ -1,6 +1,6 @@
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import UserInfo from '@/components/layout/layout-info/layout-info.vue'
|
||||
import UserInfo from '@/components/layout/right/info.vue'
|
||||
import HeaderCrumb from './header-crumb.vue'
|
||||
|
||||
// 记录图标状态
|
@ -14,7 +14,7 @@ const roleChangeRef = ref()
|
||||
const onClick = ({ key }) => {
|
||||
if (key === '1') {
|
||||
// 点击切换角色
|
||||
roleChangeRef.value?.showModal()
|
||||
roleChangeRef.value.visible = true
|
||||
} else {
|
||||
store.$reset()
|
||||
router.push('/login')
|
@ -1,10 +1,11 @@
|
||||
<script setup>
|
||||
import { ref, computed } from 'vue'
|
||||
import { userStore } from '@/stores/user'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
const store = userStore()
|
||||
const router = useRouter()
|
||||
|
||||
const loading = ref(false)
|
||||
const visible = ref(false)
|
||||
|
||||
const currentRoleId = ref(store.userInfo.roles[0].id)
|
||||
@ -17,35 +18,32 @@ const options = computed(() => {
|
||||
}))
|
||||
})
|
||||
|
||||
const showModal = () => {
|
||||
visible.value = true
|
||||
}
|
||||
|
||||
const handleOk = () => {
|
||||
loading.value = true
|
||||
visible.value = !visible.value
|
||||
store.userSelectRole(currentRoleId.value)
|
||||
// 刷新组件 todo
|
||||
visible.value = false
|
||||
router.replace({
|
||||
path: '/back'
|
||||
})
|
||||
visible.value = !visible.value
|
||||
}
|
||||
|
||||
const handleCancel = () => {
|
||||
visible.value = false
|
||||
visible.value = !visible.value
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
showModal
|
||||
visible
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="select-role">
|
||||
<a-modal v-model:visible="visible" title="切换角色" @ok="handleOk">
|
||||
<a-modal v-model:visible="visible" title="切换角色">
|
||||
<template #footer>
|
||||
<a-button key="back" @click="handleCancel">取消</a-button>
|
||||
<a-button
|
||||
key="submit"
|
||||
type="primary"
|
||||
:loading="loading"
|
||||
@click="handleOk"
|
||||
:disabled="currentRoleId === store.userInfo.roles[0]['id']"
|
||||
>确定</a-button
|
@ -20,14 +20,14 @@ const menuClick = (menu) => {
|
||||
<template v-if="menu.type === 0">
|
||||
<a-sub-menu :key="menu.id">
|
||||
<template #icon>
|
||||
<component :is="$loadIconCpn(menu.meta.icon)"></component>
|
||||
<component :is="$loadIconCpn(menu.icon)"></component>
|
||||
</template>
|
||||
<template #title>{{ menu.name }}</template>
|
||||
<!-- 1 组件 子菜单项 -->
|
||||
<template v-for="sub in menu.children" :key="sub.id">
|
||||
<a-menu-item @click="menuClick(sub)">
|
||||
<template #icon>
|
||||
<component :is="$loadIconCpn(sub.meta.icon)"></component>
|
||||
<component :is="$loadIconCpn(sub.icon)"></component>
|
||||
</template>
|
||||
<span>{{ sub.name }}</span>
|
||||
</a-menu-item>
|
||||
|
@ -1,21 +1,5 @@
|
||||
import { ref } from 'vue'
|
||||
|
||||
// 菜单类型映射
|
||||
export const menuType = {
|
||||
0: '目录',
|
||||
1: '菜单',
|
||||
2: '按钮',
|
||||
3: '数据'
|
||||
}
|
||||
|
||||
// 请求方法颜色映射
|
||||
export const methodColor = {
|
||||
GET: '#61AFFE',
|
||||
POST: '#49CC90',
|
||||
DELETE: '#F93E3E',
|
||||
PUT: '#FCA130'
|
||||
}
|
||||
|
||||
export const tableTree = () => {
|
||||
// 1.适配菜单表格
|
||||
// 展开行 https://blog.csdn.net/weixin_52691965/article/details/120494451
|
||||
|
@ -1,5 +1,6 @@
|
||||
<script setup>
|
||||
import { menuType, methodColor, tableTree } from './conf'
|
||||
import { tableTree } from './conf'
|
||||
import { menuType, methodColor } from '@/views/main/system/menu/conf'
|
||||
|
||||
/**接受父组件传递过来的值 */
|
||||
defineProps({
|
||||
@ -73,8 +74,8 @@ const expand = tableTree()
|
||||
>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<!-- 适配菜单表格 -->
|
||||
<template v-if="column.key === 'meta'">
|
||||
<component :is="$loadIconCpn(record.meta?.icon)"></component>
|
||||
<template v-if="column.key === 'icon'">
|
||||
<component :is="$loadIconCpn(record.icon)"></component>
|
||||
</template>
|
||||
<template v-if="column.key === 'type'">
|
||||
{{ menuType[record.type] }}
|
||||
|
@ -1,5 +1,4 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { userStore } from '@/stores/user'
|
||||
|
||||
const routes = [
|
||||
@ -21,6 +20,10 @@ const routes = [
|
||||
{
|
||||
path: '/:pathMatch(.*)*',
|
||||
component: () => import('@/views/error/404.vue')
|
||||
},
|
||||
{
|
||||
path: '/back',
|
||||
component: () => import('@/views/error/back.vue')
|
||||
}
|
||||
]
|
||||
|
||||
@ -31,18 +34,17 @@ const router = createRouter({
|
||||
|
||||
// 导航守卫
|
||||
router.beforeEach((to) => {
|
||||
// 修改页面标题
|
||||
if (to.meta.title) {
|
||||
document.title = to.meta.title
|
||||
}
|
||||
|
||||
if (to.path !== '/login') {
|
||||
if (userStore().token) {
|
||||
return
|
||||
}
|
||||
message.warning('请登录')
|
||||
return '/login'
|
||||
}
|
||||
})
|
||||
|
||||
router.afterEach((next) => {
|
||||
// 修改页面标题
|
||||
document.title = next.name || 'Mini RBAC'
|
||||
})
|
||||
|
||||
export default router
|
||||
|
@ -1,3 +1,5 @@
|
||||
import { message } from 'ant-design-vue'
|
||||
|
||||
import { formatTime } from './format'
|
||||
import { loadIconCpn } from './loadCpn'
|
||||
|
||||
@ -5,3 +7,10 @@ export const registerFilter = (app) => {
|
||||
app.config.globalProperties.$formatTime = (value) => formatTime(value)
|
||||
app.config.globalProperties.$loadIconCpn = (value) => loadIconCpn(value)
|
||||
}
|
||||
|
||||
// 响应msg
|
||||
export const messageTip = (res) => {
|
||||
if (res.code === 200) {
|
||||
message.success(res.msg)
|
||||
}
|
||||
}
|
||||
|
14
frontend/src/views/error/back.vue
Normal file
14
frontend/src/views/error/back.vue
Normal file
@ -0,0 +1,14 @@
|
||||
<script setup>
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
const router = useRouter()
|
||||
router.replace({
|
||||
path: '/main'
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div></div>
|
||||
</template>
|
||||
|
||||
<style scoped></style>
|
@ -2,7 +2,7 @@
|
||||
import { ref } from 'vue'
|
||||
|
||||
import SiderMenu from '@/components/layout/sider-menu.vue'
|
||||
import LayoutHeader from '@/components/layout/layout-header.vue'
|
||||
import Header from '@/components/layout/header.vue'
|
||||
|
||||
// a-ayout-sider 折叠状态响应式数据
|
||||
const collapsed = ref(false)
|
||||
@ -23,7 +23,7 @@ const changeSiderFold = (subValue) => {
|
||||
<a-layout>
|
||||
<a-layout-header style="background: #fff; padding: 0">
|
||||
<!-- 页头 -->
|
||||
<LayoutHeader @changeFold="changeSiderFold" />
|
||||
<Header @changeFold="changeSiderFold" />
|
||||
</a-layout-header>
|
||||
<a-layout-content
|
||||
class="content"
|
||||
|
@ -1,3 +1,4 @@
|
||||
import * as icons from '@ant-design/icons-vue'
|
||||
export const columns = [
|
||||
{
|
||||
title: '名称',
|
||||
@ -7,8 +8,8 @@ export const columns = [
|
||||
},
|
||||
{
|
||||
title: '图标',
|
||||
dataIndex: 'meta',
|
||||
key: 'meta',
|
||||
dataIndex: 'icon',
|
||||
key: 'icon',
|
||||
width: 60
|
||||
},
|
||||
{
|
||||
@ -65,3 +66,53 @@ export const columns = [
|
||||
width: 120
|
||||
}
|
||||
]
|
||||
|
||||
// 菜单类型映射
|
||||
export const menuType = {
|
||||
0: '目录',
|
||||
1: '菜单',
|
||||
2: '按钮',
|
||||
3: '数据'
|
||||
}
|
||||
|
||||
// 请求方法颜色映射
|
||||
export const methodColor = {
|
||||
GET: '#61AFFE',
|
||||
POST: '#49CC90',
|
||||
DELETE: '#F93E3E',
|
||||
PUT: '#FCA130'
|
||||
}
|
||||
|
||||
const nullOption = {
|
||||
label: null,
|
||||
value: null
|
||||
}
|
||||
// 转换成select 需要的options
|
||||
export const menuTypeMap = () => {
|
||||
return Object.keys(menuType).map((k) => ({ label: menuType[k], value: parseInt(k) }))
|
||||
}
|
||||
|
||||
export const methodMap = () => {
|
||||
let arr = Object.keys(methodColor).map((k) => ({ label: k, value: k }))
|
||||
arr.unshift(nullOption)
|
||||
return arr
|
||||
}
|
||||
|
||||
export const iconMap = () => {
|
||||
let arr = Object.keys(icons)
|
||||
.filter((k) => k.indexOf('Outlined') !== -1)
|
||||
.map((k) => ({ label: k, value: k }))
|
||||
arr.unshift(nullOption)
|
||||
return arr
|
||||
}
|
||||
|
||||
export const rules = {
|
||||
name: [
|
||||
{ required: true, message: '请输入名称', trigger: 'blur' },
|
||||
{ min: 3, max: 12, message: '3-12', trigger: 'blur' }
|
||||
],
|
||||
path: [
|
||||
{ required: true, message: '请输入路由', trigger: 'blur' },
|
||||
{ min: 1, max: 20, message: '1~20', trigger: 'blur' }
|
||||
]
|
||||
}
|
||||
|
@ -1,5 +1,10 @@
|
||||
<script setup>
|
||||
import { reactive, watch, toRefs } from 'vue'
|
||||
import useModal from '@/hooks/useModal'
|
||||
import { menuTypeMap, methodMap, iconMap, rules } from './conf'
|
||||
import { getMenus, addMenu, putMenu } from '@/service/menu'
|
||||
import { userStore } from '@/stores/user'
|
||||
import { messageTip } from '@/utils'
|
||||
|
||||
const props = defineProps({
|
||||
modalTitle: {
|
||||
@ -15,19 +20,74 @@ const props = defineProps({
|
||||
|
||||
const { showModal, updateId, formRef } = useModal()
|
||||
|
||||
// 响应式数据
|
||||
const data = reactive({
|
||||
// 表单响应式数据
|
||||
menuForm: {
|
||||
name: '',
|
||||
icon: null,
|
||||
path: null,
|
||||
type: 0,
|
||||
component: null,
|
||||
pid: 0,
|
||||
identifier: null,
|
||||
api: null,
|
||||
method: null
|
||||
},
|
||||
// 上层菜单列表
|
||||
menusOptions: []
|
||||
})
|
||||
|
||||
//菜单筛选
|
||||
const filterTreeNode = (inputValue, treeNode) => {
|
||||
return treeNode.name.toLowerCase().indexOf(inputValue.toLowerCase()) >= 0
|
||||
}
|
||||
|
||||
// 图标筛选
|
||||
const filterOption = (input, option) => {
|
||||
if (option.value) {
|
||||
return option.value.toLowerCase().indexOf(input.toLowerCase()) >= 0
|
||||
}
|
||||
}
|
||||
watch(showModal, async (newValue) => {
|
||||
if (newValue) {
|
||||
const res = await getMenus()
|
||||
data.menusOptions = res.data
|
||||
data.menusOptions.unshift({
|
||||
id: 0,
|
||||
name: '顶层菜单'
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
// 编辑
|
||||
const openModal = (record) => {
|
||||
showModal.value = true
|
||||
|
||||
updateId.value = record.id
|
||||
data.menuForm = record
|
||||
}
|
||||
|
||||
const onOk = () => {
|
||||
//新增
|
||||
console.log(props)
|
||||
formRef.value.validateFields().then(async () => {
|
||||
let res
|
||||
if (props.modalType === 'create') {
|
||||
res = await addMenu(data.menuForm)
|
||||
} else {
|
||||
res = await putMenu(updateId.value, data.menuForm)
|
||||
}
|
||||
messageTip(res)
|
||||
formRef.value.resetFields()
|
||||
showModal.value = !showModal.value
|
||||
userStore().isPush = true
|
||||
})
|
||||
}
|
||||
|
||||
const onCancel = () => {}
|
||||
const onCancel = () => {
|
||||
formRef.value.resetFields()
|
||||
}
|
||||
|
||||
const { menuForm, menusOptions } = toRefs(data)
|
||||
|
||||
defineExpose({ openModal, showModal })
|
||||
</script>
|
||||
@ -42,13 +102,87 @@ defineExpose({ openModal, showModal })
|
||||
@ok="onOk"
|
||||
@cancel="onCancel"
|
||||
>
|
||||
<a-form ref="formRef">
|
||||
<a-form-item>
|
||||
<a-input></a-input>
|
||||
<a-form ref="formRef" :model="menuForm" class="form" :rules="rules">
|
||||
<a-form-item name="pid" label="上级菜单" class="item">
|
||||
<a-tree-select
|
||||
v-model:value="menuForm.pid"
|
||||
show-search
|
||||
style="width: 100%"
|
||||
:dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
|
||||
allow-clear
|
||||
:tree-data="menusOptions"
|
||||
:field-names="{
|
||||
children: 'children',
|
||||
label: 'name',
|
||||
value: 'id'
|
||||
}"
|
||||
:filterTreeNode="filterTreeNode"
|
||||
></a-tree-select>
|
||||
</a-form-item>
|
||||
<a-form-item name="name" label="名称">
|
||||
<a-input v-model:value="menuForm.name" />
|
||||
</a-form-item>
|
||||
<a-form-item name="icon" label="图标">
|
||||
<a-select
|
||||
v-model:value="menuForm.icon"
|
||||
style="width: 100%"
|
||||
show-search
|
||||
:filterOption="filterOption"
|
||||
>
|
||||
<template v-for="option in iconMap()" :key="option.value">
|
||||
<a-select-option :value="option.value">
|
||||
<component :is="$loadIconCpn(option.label)"></component>
|
||||
{{ option.label }}
|
||||
</a-select-option>
|
||||
</template>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item name="path" label="路由">
|
||||
<a-input v-model:value="menuForm.path" />
|
||||
</a-form-item>
|
||||
<a-form-item name="type" label="类型">
|
||||
<a-select
|
||||
v-model:value="menuForm.type"
|
||||
style="width: 100%"
|
||||
:options="menuTypeMap()"
|
||||
></a-select>
|
||||
</a-form-item>
|
||||
<a-form-item name="component" label="组件">
|
||||
<a-input v-model:value="menuForm.component" placeholder="views/main" />
|
||||
</a-form-item>
|
||||
<a-form-item name="identifier" label="权限">
|
||||
<a-input v-model:value="menuForm.identifier" />
|
||||
</a-form-item>
|
||||
<a-form-item name="api" label="接口">
|
||||
<a-input v-model:value="menuForm.api" />
|
||||
</a-form-item>
|
||||
<a-form-item name="method" label="方法">
|
||||
<a-select
|
||||
v-model:value="menuForm.method"
|
||||
style="width: 100%"
|
||||
:options="methodMap()"
|
||||
></a-select>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped></style>
|
||||
<style scoped>
|
||||
.ant-form {
|
||||
display: flex;
|
||||
justify-content: space-between; /* 横向中间自动空间 */
|
||||
align-content: space-between; /* 竖向中间自动空间 */
|
||||
flex-wrap: wrap; /* 换行 */
|
||||
}
|
||||
.ant-form-item:nth-child(0) {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.ant-form-item {
|
||||
width: 48%;
|
||||
}
|
||||
.item {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
|
@ -1,16 +1,33 @@
|
||||
<script setup>
|
||||
import { ref, reactive, toRefs } from 'vue'
|
||||
import { ref, reactive, toRefs, onMounted } from 'vue'
|
||||
|
||||
import { columns } from './conf'
|
||||
import { getMenus } from '@/service/menu'
|
||||
import { delMenu, getMenus } from '@/service/menu'
|
||||
|
||||
import Table from '@/components/table/table.vue'
|
||||
import MenuModal from './menu-modal.vue'
|
||||
import { userStore } from '@/stores/user'
|
||||
import { messageTip } from '@/utils'
|
||||
|
||||
const store = userStore()
|
||||
|
||||
store.$subscribe((mutation, state) => {
|
||||
if (state.isPush) {
|
||||
getPageData()
|
||||
state.isPush = false
|
||||
}
|
||||
})
|
||||
|
||||
// 列表数据
|
||||
const dataSource = ref([])
|
||||
|
||||
getMenus().then((res) => (dataSource.value = res.data))
|
||||
function getPageData() {
|
||||
getMenus().then((res) => (dataSource.value = res.data))
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
getPageData()
|
||||
})
|
||||
|
||||
const modalRef = ref()
|
||||
const modalConf = reactive({
|
||||
@ -24,16 +41,16 @@ const addClick = () => {
|
||||
modalRef.value.showModal = true
|
||||
}
|
||||
|
||||
//
|
||||
const putClick = (record) => {
|
||||
console.log(record)
|
||||
modalConf.title = '编辑菜单'
|
||||
modalConf.type = 'create'
|
||||
modalConf.type = 'update'
|
||||
modalRef.value.openModal(record)
|
||||
}
|
||||
|
||||
const delClick = (record) => {
|
||||
console.log('点击', record)
|
||||
const delClick = async (record) => {
|
||||
const res = await delMenu(record.id)
|
||||
messageTip(res)
|
||||
getPageData()
|
||||
}
|
||||
|
||||
const { title, type } = toRefs(modalConf)
|
||||
|
@ -1,7 +1,5 @@
|
||||
<script setup>
|
||||
import { ref, reactive, watch } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
|
||||
import { rules, treeFieldNames } from './conf'
|
||||
import { addRole, putRole } from '@/service/role'
|
||||
import { getMenus as getRoleMenu } from '@/service/user'
|
||||
@ -9,6 +7,7 @@ import { getMenus } from '@/service/menu'
|
||||
import { userStore } from '@/stores/user'
|
||||
|
||||
import useModal from '@/hooks/useModal'
|
||||
import { messageTip } from '@/utils'
|
||||
|
||||
const props = defineProps({
|
||||
modalTitle: {
|
||||
@ -98,9 +97,9 @@ const onOk = () => {
|
||||
} else {
|
||||
res = await putRole(updateId.value, roleForm)
|
||||
}
|
||||
message.success(res.msg)
|
||||
messageTip(res)
|
||||
resetData()
|
||||
showModal.value = false
|
||||
showModal.value = !showModal.value
|
||||
userStore().isPush = true
|
||||
})
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import RoleSearch from './role-search.vue'
|
||||
import RoleModal from './role-modal.vue'
|
||||
|
||||
import { userStore } from '@/stores/user'
|
||||
import { messageTip } from '@/utils'
|
||||
|
||||
const store = userStore()
|
||||
|
||||
@ -75,8 +76,9 @@ const resetQueryForm = () => {
|
||||
}
|
||||
|
||||
// 删除
|
||||
const delClick = (record) => {
|
||||
delRole(record.id)
|
||||
const delClick = async (record) => {
|
||||
const res = await delRole(record.id)
|
||||
messageTip(res)
|
||||
getPageData()
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,13 @@
|
||||
<script setup>
|
||||
import { reactive, ref, watch } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { addUserRules, putUserRules } from './conf'
|
||||
|
||||
import { addUser, putUser, getUserInfo } from '@/service/user'
|
||||
import { userStore } from '@/stores/user'
|
||||
import { getRoles } from '@/service/role'
|
||||
import useModal from '@/hooks/useModal'
|
||||
import { messageTip } from '@/utils'
|
||||
import { message } from 'ant-design-vue'
|
||||
|
||||
const props = defineProps({
|
||||
modalTitle: {
|
||||
@ -67,6 +68,7 @@ const openModal = async (record) => {
|
||||
const onOk = () => {
|
||||
formRef.value.validateFields().then(async () => {
|
||||
let res
|
||||
let flag = false
|
||||
if (props.modalType === 'create') {
|
||||
newUserForm.roles = newUserForm.roles.map((e, i) => ({ rid: e, status: i === 0 ? 5 : 1 }))
|
||||
res = await addUser(newUserForm)
|
||||
@ -79,13 +81,14 @@ const onOk = () => {
|
||||
roles: rids
|
||||
})
|
||||
if (updateId.value === store.userInfo.id) {
|
||||
// 并且修改了激活角色
|
||||
if (rids[0]['rid'] !== store.userInfo.roles[0]['id']) {
|
||||
store.getUserData(updateId.value)
|
||||
message.warning('修改登录用户信息,重新登录生效.')
|
||||
flag = true
|
||||
}
|
||||
}
|
||||
if (!flag) {
|
||||
messageTip(res)
|
||||
}
|
||||
message.success(res.msg)
|
||||
|
||||
formRef.value.resetFields()
|
||||
showModal.value = !showModal.value
|
||||
store.isPush = true
|
||||
|
@ -9,7 +9,7 @@ import { columns } from './conf'
|
||||
import UserSearch from './user-search.vue'
|
||||
import UserModal from './user-modal.vue'
|
||||
import { userStore } from '@/stores/user'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { messageTip } from '@/utils'
|
||||
|
||||
const store = userStore()
|
||||
|
||||
@ -85,7 +85,7 @@ const resetQueryForm = () => {
|
||||
// 删除
|
||||
const delClick = async (record) => {
|
||||
const res = await delUser(record.id)
|
||||
message.success(res.msg)
|
||||
messageTip(res)
|
||||
getPageData()
|
||||
}
|
||||
|
||||
@ -120,7 +120,8 @@ const putClick = async (record) => {
|
||||
@create-click="addClick"
|
||||
@update-click="putClick"
|
||||
@delete-click="delClick"
|
||||
/>
|
||||
>
|
||||
</Table>
|
||||
|
||||
<!-- 新增&编辑 -->
|
||||
<UserModal ref="modalRef" :modal-title="modalConf.title" :modal-type="modalConf.type" />
|
||||
|
7
frontend/src/views/main/test/debug/debug.vue
Normal file
7
frontend/src/views/main/test/debug/debug.vue
Normal file
@ -0,0 +1,7 @@
|
||||
<script setup></script>
|
||||
|
||||
<template>
|
||||
<div>debug123123</div>
|
||||
</template>
|
||||
|
||||
<style scoped></style>
|
Loading…
Reference in New Issue
Block a user