Blogger Information
Blog 62
fans 3
comment 1
visits 29562
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
vue后台管理系统 二级路由与菜单列表(增删查改)
kiraseo_wwwkiraercom
Original
467 people have browsed it

调整后台二级路由 把登录页面单独显示

菜单列表(增删查改)

php代码如下

  1. 查询
  2. public function MenuList(){
  3. $data= Db::table('bew_admin_sys_menu')->where(['status'=>1])->select()->toArray();
  4. if(!empty($data)){
  5. foreach ($data as &$data_v){
  6. if($data_v['status']==1){
  7. $data_v['status_v'] = '开启';
  8. }else{
  9. $data_v['status_v'] = '关闭';
  10. }
  11. if($data_v['type']==0){
  12. $data_v['type_v'] = '分组';
  13. }elseif ($data_v['type']==1){
  14. $data_v['type_v'] = '内部链接';
  15. }elseif ($data_v['type']==2){
  16. $data_v['type_v'] = '外部链接';
  17. }
  18. }
  19. }
  20. $arr =[
  21. 'code'=>0,
  22. 'msg'=>'成功',
  23. 'data'=>$data,
  24. ];
  25. echo json_encode($arr);
  26. }
  27. //删除与修改代码
  28. public function MenuSave(){
  29. if(Request::isPost()){
  30. $data = Request::param();
  31. //提交值
  32. $datalist = [
  33. 'label'=>$data['label'],
  34. 'sort'=>$data['sort'],
  35. 'type'=>$data['type'],
  36. 'icon_class' => $data['icon_class'],
  37. 'status'=>$data['status'],
  38. ];
  39. //判断了是否有主键
  40. if($data['mid'] !=0){
  41. $datalist['mid'] = $data['mid'];
  42. }else{
  43. $datalist['parent_id']=0;
  44. }
  45. if($data['type'] ==0){
  46. $datalist['src'] = '';
  47. }else{
  48. $datalist['src'] = $data['src'];
  49. }
  50. //修改与提交方法
  51. $res = Db::name('bew_admin_sys_menu')->save($datalist);
  52. if (!empty($res)){
  53. $rest = ['code'=>0,'msg'=>"操作成功"];
  54. echo json_encode($rest);
  55. }else{
  56. $rest = ['code'=>1,'msg'=>"操作失败"];
  57. echo json_encode($rest);
  58. exit;
  59. }
  60. }
  61. }
  62. //删除方法
  63. public function MenuDel(){
  64. if(Request::isPost()){
  65. $uid = Request::param();
  66. if(empty($uid['mid'])){
  67. $rest = ['code'=>1,'msg'=>"删除不存在数据"];
  68. echo json_encode($rest);
  69. exit;
  70. }
  71. $del = Db::table('bew_admin_sys_menu')->where('mid', $uid['mid'])->update(['status' => 0]);
  72. if (!empty($del)){
  73. $rest = ['code'=>0,'msg'=>"操作成功"];
  74. echo json_encode($rest);
  75. }else{
  76. $rest = ['code'=>1,'msg'=>"操作失败"];
  77. echo json_encode($rest);
  78. exit;
  79. }
  80. }else{
  81. $rest = ['code'=>1,'msg'=>"非法请求"];
  82. echo json_encode($rest);
  83. exit;
  84. }
  85. }

引入接口文件

  1. import { MenuList ,MenuAdd,MenuDel } from "../../network/admin.js";
  1. //查询
  2. MenuList().then( (e)=>{
  3. console.log(e);
  4. tableData.lists = e.data;
  5. } )
  6. //添加与修改
  7. MenuAdd(fromData).then( (e)=>{
  8. if(e.code == 0){
  9. ElMessage({
  10. message: e.msg,
  11. type: 'success'
  12. });
  13. data.is_form = false;
  14. MenuList().then( (e)=>{
  15. tableData.lists = e.data;
  16. } )
  17. }else{
  18. ElMessage({
  19. message: e.msg,
  20. type: 'error'
  21. });
  22. }
  23. } )
  24. //删除
  25. MenuDel({mid:e.mid}).then( (e)=>{
  26. if(e.code == 0){
  27. ElMessage({
  28. message: e.msg,
  29. type: 'success'
  30. });
  31. MenuList().then( (e)=>{
  32. tableData.lists = e.data;
  33. } )
  34. }else{
  35. ElMessage({
  36. message: e.msg,
  37. type: 'error'
  38. });
  39. }
  40. } )

查询与添加

修改

修改前.jpg
修改后

删除

删除前
删除后.jpg

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post