0525\antd\src\App.vue
<template>
<a-layout style="min-height: 100vh" id="oyk">
<a-layout-sider v-model:collapsed="collapsed" collapsible>
<div class="logo" />
<a-menu v-model:selectedKeys="selectedKeys" theme="dark" mode="inline">
<router-link to="/">
<a-menu-item key="-1">
<DesktopOutlined />
<span>首页</span>
</a-menu-item>
</router-link>
<router-link to="/info">
<a-menu-item key="-2">
<UserOutlined />
<span>个人中心</span>
</a-menu-item>
</router-link>
<a-sub-menu v-for="(item,index,key) in data.menu" :key="item.mid">
<template #title v-if="item.type == 0">
<span>
<HeartOutlined />
<span>{{item.label}}</span>
</span>
</template>
<template #title v-if="item.type == 1">
<router-link :key="item.mid" :to="item.src">
<MenuOutlined />
<span>{{item.label}}</span>
</router-link>
</template>
<template #title v-if="item.type == 2">
<a :href="item.src">
<MenuOutlined />
<span>{{item.label}}</span>
</a>
</template>
<template v-if="item.son" v-for="(items,indexs,keys) in item.son" >
<router-link :key="items.mid" :to="items.src" v-if="items.type==1">
<a-menu-item :key="items.mid">
<MenuOutlined />
<span>{{items.label}}</span>
</a-menu-item>
</router-link>
<a :key="items.mid" :href="items.src" v-if="items.type==2">
<a-menu-item :key="items.mid">
<MenuOutlined />
<span>{{items.label}}</span>
</a-menu-item>
</a>
</template>
</a-sub-menu>
<!-- <a-sub-menu key="3">
<template #title>
<span>
<SettingOutlined />
<span>系统配置</span>
</span>
</template>
<a-menu-item key="4">
<TeamOutlined />
<span>部门管理</span>
</a-menu-item>
<router-link to="/user_lists">
<a-menu-item key="5">
<UserOutlined />
<span>管理员管理</span>
</a-menu-item>
</router-link>
</a-sub-menu>
<a-sub-menu key="4">
<template #title>
<span>
<SettingOutlined />
<span>商城项目</span>
</span>
</template>
<router-link to="/shop_lists">
<a-menu-item key="10">
<UserOutlined />
<span>商品列表</span>
</a-menu-item>
</router-link>
<a-menu-item key="11">
<UserOutlined />
<span>商品分类列表</span>
</a-menu-item>
<a-menu-item key="12">
<UserOutlined />
<span>订单列表</span>
</a-menu-item>
<a-menu-item key="13">
<UserOutlined />
<span>用户列表</span>
</a-menu-item>
<a-menu-item key="14">
<UserOutlined />
<span>用户地址列表</span>
</a-menu-item>
<a-menu-item key="15">
<UserOutlined />
<span>广告列表</span>
</a-menu-item>
</a-sub-menu> -->
</a-menu>
</a-layout-sider>
<a-layout>
<a-layout-content style="margin: 0 16px">
<div :style="{ padding: '24px', background: '#fff', minHeight: '360px' }">
<router-view></router-view>
</div>
</a-layout-content>
</a-layout>
</a-layout>
</template>
<script>
import { reactive, toRef } from '@vue/reactivity';
import {AdminIndexLists} from './network/index.js';
import { message, Modal } from "ant-design-vue";
import {
DesktopOutlined,
UserOutlined,
HeartOutlined,
MenuOutlined,
SettingOutlined,
TeamOutlined,
ApiOutlined
} from "@ant-design/icons-vue";
import { defineComponent, ref } from "vue";
export default defineComponent({
components: {
DesktopOutlined,
UserOutlined,
HeartOutlined,
MenuOutlined,
SettingOutlined,
TeamOutlined,
ApiOutlined
},
data() {
return {
collapsed: ref(false),
selectedKeys: ref(["-1"]),
};
},
setup(){
const data = reactive({
menu:[],
})
AdminIndexLists().then( (res)=>{
data.menu = res.data.menu;
} )
return{
data
}
}
});
</script>
0525\antd\src\views\GroupLists.vue
<template>
<a-button type="default" @click="add(2)">修改</a-button>
<a-modal
v-model:visible="data.addModal"
width="100%"
centered
:title="data.title"
:mask="mask"
wrapClassName="full-modal"
okText="确定"
okType="primary"
cancelText="取消"
@ok="add_ok()"
>
<a-form name="form" :model="formData" @submit="submit">
<a-form-item name="group_name" label="部门名">
<a-input v-model:value="formData.group_name" />
</a-form-item>
<a-form-item name="name" label="权限">
<a-checkbox-group name="rights" v-model:value="formData.rights">
<div v-for="(item,index,key) in data.menu" :key="item.id">
<a-checkbox :value="item.mid">{{item.label}}</a-checkbox>
<hr style="border:dotted #0066CC;"/>
<div>
<a-checkbox v-for="(items,indexs,keys) in item.son" :key="items.mid" :value="items.mid">{{items.label}}</a-checkbox>
<hr/>
</div>
</div>
</a-checkbox-group>
</a-form-item>
</a-form>
</a-modal>
<a-table :dataSource="data.dataSource" :columns="data.columns" :rowSelection="rowSelection">
<template #bodyCell="{ text, record, index, column }">
<template v-if="column.dataIndex=='sex'">
<span v-if="record.sex == 1">男</span>
<span v-if="record.sex == 2">女</span>
</template>
<template v-if="column.dataIndex=='status'">
<span v-if="record.status == 1" style="color:green;">开启</span>
<span v-if="record.status == 0" style="color:red;">关闭</span>
<a-button type="default" @click="edit( record.group_id )">修改</a-button>
</template>
</template>
</a-table>
</template>
<script>
import { reactive, toRef } from '@vue/reactivity';
import { AdminGroupLists,AdminMenuAdd,AdminMenuLists } from '../network/index.js';
import { message,Modal } from "ant-design-vue";
export default {
setup() {
const rowSelection = {
type : "radio" ,
onChange(selectedRowKeys, selectedRows) {
console.log(selectedRowKeys,selectedRows);
data.select_id = selectedRowKeys[0];
data.select_data = selectedRows[0];
}
};
const data = reactive({
select_id : 0,
// columns 表单头
columns: [
{
title: "ID", // 是显示在表单头上的名字
dataIndex: "group_id", // 对应接口返回的字段名,就是key
},
{
title: "部门名",
dataIndex: "group_name"
},
{
title: "状态",
dataIndex: "status"
}
],
dataSource: [],
menu: [],
addModal : false,
b_status : 1,
title : "修改",
select_data : []
})
const formData = reactive({
group_name : '',
rights : '',
});
const add = (e)=>{
if(e == 2){
if(data.select_id == 0){
message.warning('请您选择一条数据');
return false;
}
data.title = "修改";
formData.group_name = data.select_data.group_name;
formData.rights = data.select_data.rights;
}else{
data.title = "添加";
}
data.b_status = e;
data.addModal = true;
}
// 模态框确认按钮
const add_ok = ()=>{
// 可以在这里判断form表单的数据,不能为空。
// 减少服务器压力,必然的。
// 但是后端接口,也要判断。
// 前端比较多,如果不是你写的前端呢?安卓和ios,它们在传值的时候没有判断
// 那么后端接口就会吃大亏。
if(data.select_id == 0){
formData.group_id = 0;
}else{
formData.group_id = data.select_data.group_id;
}
AdminMenuAdd(formData).then( (res)=>{
console.log(res);
if(res.code == 0){
message.success(res.msg);
data.addModal = false;
AdminGroupLists().then( (res)=>{
data.dataSource = res.data.group;
data.menu = res.data.menu;
} )
}else{
message.warning(res.msg);
}
} )
}
AdminGroupLists().then( (res)=>{
data.dataSource = res.data.group;
data.menu = res.data.menu;
} )
return {
data,
rowSelection,
add,
formData,
add_ok,
};
}
};
</script>
0525\antd\src\network\index.js
import {request} from "./request.js";
export function AdminUserLists(data={}){
return request( {
method : "POST",
url : "Index/admin_user_lists",
data
} )
}
export function AdminUserAdd(data={}){
return request( {
method : "POST",
url : "Index/admin_user_add",
data
} )
}
export function AdminUserDel(data={}){
return request( {
method : "POST",
url : "Index/admin_user_del",
data
} )
}
export function AdminMenuLists(data={}){
return request( {
method : "POST",
url : "Index/admin_menu_lists",
data
} )
}
export function AdminIndexLists(data={}){
return request( {
method : "POST",
url : "Index/admin_index_lists",
data
} )
}
export function AdminGroupLists(data={}){
return request( {
method : "POST",
url : "Index/admin_group_lists",
data
} )
}
export function AdminMenuAdd(data={}){
return request( {
method : "POST",
url : "Index/admin_menu_add",
data
} )
}
0525\antd\src\router\index.js
import { createRouter, createWebHashHistory } from "vue-router";
import Index from "../views/Index.vue";
import UserLists from "../views/UserLists.vue";
import MenuLists from "../views/MenuLists.vue";
import GroupLists from "../views/GroupLists.vue";
const routes = [
{
path: "/",
alias: "/index",
name: "Index",
component: Index,
meta: {
title: "首页",
}
},
{
path: "/user_lists",
name: "UserLists",
component: UserLists,
meta: {
title: "用户列表"
}
},
{
path: "/menu_lists",
name: "MenuLists",
component: MenuLists,
meta: {
title: "菜单列表"
}
},
{
path: "/group_lists",
name: "GroupLists",
component: GroupLists,
meta: {
title: "权限列表"
}
}
];
const router = createRouter({
history: createWebHashHistory(process.env.BASE_URL),
routes,
});
router.beforeEach((to) => {
document.title = to.meta.title;
});
export default router;
0525\tp\app\admin\controller\Index.php
<?php
namespace app\admin\controller;
use think\facade\Db;
use think\facade\Request;
class Index
{
public function __construct(){
// 使用php的header函数,设置为*,全部能访问
header("Access-Control-Allow-Origin:*");
}
public function admin_index_lists(){
$user = Db::table('bew_admin_user')->where('uid',1)->find();
$group = Db::table('bew_admin_user_group')->where('group_id',$user['group_id'])->find();
$rights = json_decode($group['rights'],true);
$menu = Db::table('bew_admin_sys_menu')->where('mid','in',$rights)->where('status',1)->order('sort DESC')->select()->toArray();
$tmp = [];
foreach($menu as $k=>&$v){
if($v['parent_id'] == 0 ){
$v['key'] = $k;
$tmp[$v['mid']] = $v;
}else{
$v['key'] = $k;
$tmp[$v['parent_id']]['son'][] = $v;
}
}
echo json_encode([
'code' => 0,
'msg' => '成功',
'data' => [
'menu' => $tmp
]
]);
}
public function admin_user_lists()
{
$user = Db::table('bew_admin_user')->select()->toArray();
foreach($user as &$v){
$v['key'] = $v['uid']; // 前端用到的字段,key,可以让多选框,选中一条数据。必要的,只要是唯一的就可以用
$v['time_last_s'] = date('Y-m-d H:i:s',$v['time_last']);
}
echo json_encode([
'code' => 0,
'msg' => '成功',
'data' => $user
]);
}
public function admin_user_add(){
$account = input('post.account');
if(empty($account)){
echo json_encode([
'code' => 1,
'msg' => '请输入账号'
]);
exit;
}
$password = input('post.password');
$name = input('post.name');
$phone = input('post.phone');
$qq = input('post.qq');
$sex = input('post.sex',1);
$data = [
'account' => $account,
'password' => md5($password),
'name' => $name,
'phone' => $phone,
'qq' => $qq,
'sex' => $sex,
];
$uid = input('post.uid',0);
if($uid == 0){
$data['time_add'] = time();
if(empty($password)){
echo json_encode([
'code' => 1,
'msg' => '请输入密码'
]);
exit;
}
$data['password'] = md5($password);
$insert = Db::table('bew_admin_user')->insert($data);
if(empty($insert)){
echo json_encode([
'code' => 1,
'msg' => '添加失败'
]);
exit;
}
echo json_encode([
'code' => 0,
'msg' => '添加成功'
]);
}else{
if(!empty($password)){
$data['password'] = md5($password);
}
$update = Db::table('bew_admin_user')->where('uid',$uid)->update($data);
if(empty($update)){
echo json_encode([
'code' => 1,
'msg' => '修改失败'
]);
exit;
}
echo json_encode([
'code' => 0,
'msg' => '修改成功'
]);
}
}
public function admin_user_del(){
$uid = input('post.uid');
$delete = Db::table('bew_admin_user')->where('uid',$uid)->delete();
if(empty($delete)){
echo json_encode([
'code' => 1,
'msg' => '删除失败'
]);
}
echo json_encode([
'code' => 0,
'msg' => '删除成功'
]);
}
public function admin_menu_lists(){
$lists = Db::table('bew_admin_sys_menu')->order('sort DESC')->select()->toArray();
$tmp = [];
foreach($lists as $k=>&$v){
if($v['parent_id'] == 0 ){
$v['key'] = $k;
$tmp[$v['mid']] = $v;
}else{
$v['key'] = $k;
$tmp[$v['parent_id']]['son'][] = $v;
}
}
echo json_encode([
'code' => 0,
'msg' => '成功',
'data' => array_merge($tmp)
]);
}
public function admin_group_lists(){
$group = Db::table('bew_admin_user_group')->select()->toArray();
foreach($group as &$v){
$v['key'] = $v['group_id'];
}
$lists = Db::table('bew_admin_sys_menu')->order('sort DESC')->select()->toArray();
$tmp = [];
foreach($lists as $k=>&$v){
if($v['parent_id'] == 0 ){
$v['key'] = $k;
$tmp[$v['mid']] = $v;
}else{
$v['key'] = $k;
$tmp[$v['parent_id']]['son'][] = $v;
}
}
echo json_encode([
'code' => 0,
'msg' => '成功',
'data' => [
'group' => $group,
'menu' => $tmp
]
]);
}
public function admin_menu_add(){
$group_id = input('post.group_id');
$rights = input('post.rights');
$group_name = input('post.group_name');
$update = Db::table('bew_admin_user_group')->where('group_id',$group_id)->update([
'group_name' => $group_name,
'rights' => json_encode($rights)
]);
if(empty($update)){
echo json_encode([
'code'=>1,
'msg'=>'修改失败'
]);
exit;
}
echo json_encode([
'code'=>0,
'msg'=>'成功'
]);
}
}