当前位置: 首页 > news >正文

群控系统服务端开发模式-应用开发-前端个人资料开发

一、总结

        其实程序开发到现在,简单的后端框架就只剩下获取登录账号信息及获取登录账号菜单这两个功能咯。详细见下图:

        1、未登录时总业务流程图

        2、登录后总业务流程图

二、获取登录账号信息对接

        在根目录下src文件夹下store文件夹下modules文件夹下的user.js文件中,修改代码如下:

const state = {token: getToken(),username: '',avatar: '',email: '',realname: '',department_title: '',grade_title: '',rolename: '',roles: [],butts: []
}const mutations = {SET_TOKEN: (state, token) => {state.token = token},SET_EMAIL: (state, email) => {state.email = email},SET_USERNAME: (state, username) => {state.username = username},SET_AVATAR: (state, avatar) => {state.avatar = avatar},SET_REALNAME: (state, realname) => {state.realname = realname},SET_DEPARTMENT_TITLE: (state, department_title) => {state.department_title = department_title},SET_GRADE_TITLE: (state, grade_title) => {state.grade_title = grade_title},SET_ROLENAME: (state, rolename) => {state.rolename = rolename},SET_BUTTS: (state, butts) => {state.butts = butts},SET_ROLES: (state, roles) => {state.roles = roles}
}
// get user info
getInfo({commit, state}) {return new Promise((resolve, reject) => {getInfo().then(response => {const {data} = responseif (!data) {reject('验证失败,请重新登录。')}const { butt, key, username, avatar, email, realname, department_title, grade_title, rolename } = dataif (!butt || butt.length <= 0) {reject('您权限不足,请联系系统管理员')}commit('SET_BUTTS', butt)commit('SET_ROLES', key)commit('SET_USERNAME', username)commit('SET_AVATAR', avatar)commit('SET_EMAIL', email)commit('SET_REALNAME', realname)commit('SET_DEPARTMENT_TITLE', department_title)commit('SET_GRADE_TITLE', grade_title)commit('SET_ROLENAME', rolename)resolve(key)}).catch(error => {reject(error)})})
},

三、获取登录账号菜单信息对接

       获取菜单这块,需要更改两部分,第一部分就是路由修改,第二部分才是菜单转换成路由

        1、路由修改

                在根目录下src文件夹下route文件夹下,修改index.js文件,代码如下

import Vue from 'vue'
import Router from 'vue-router'/* Layout */
import Layout from '@/layout'Vue.use(Router)/*** Note: sub-menu only appear when route children.length >= 1* Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html** hidden: true                   if set true, item will not show in the sidebar(default is false)* alwaysShow: true               if set true, will always show the root menu*                                if not set alwaysShow, when item has more than one children route,*                                it will becomes nested mode, otherwise not show the root menu* redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb* name:'router-name'             the name is used by <keep-alive> (must set!!!)* meta : {roles: ['admin','editor']    control the page roles (you can set multiple roles)title: 'title'               the name show in sidebar and breadcrumb (recommend set)icon: 'svg-name'/'el-icon-x' the icon show in the sidebarnoCache: true                if set true, the page will no be cached(default is false)affix: true                  if set true, the tag will affix in the tags-viewbreadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set}*//*** constantRoutes* a base page that does not have permission requirements* all roles can be accessed*/
export const constantRoutes = [{path: '/redirect',component: Layout,hidden: true,children: [{path: '/redirect/:path(.*)',component: () => import('@/views/redirect/index')}]},{path: '/login',component: () => import('@/views/login/index'),hidden: true},{path: '/404',component: () => import('@/views/error-page/404'),hidden: true},{path: '/401',component: () => import('@/views/error-page/401'),hidden: true},{path: '/',component: Layout,redirect: '/dashboard',children: [{path: 'dashboard',component: () => import('@/views/dashboard/index'),name: '首页',meta: { title: '首页', icon: 'dashboard', affix: true }}]},{path: '/profile',component: Layout,redirect: '/profile/index',hidden: true,children: [{path: 'index',component: () => import('@/views/profile/index'),name: 'Profile',meta: { title: 'Profile', icon: 'user', noCache: true }}]}
]/*** asyncRoutes* the routes that need to be dynamically loaded based on user roles*/
export const asyncRoutes = [// 404 page must be placed at the end !!!{ path: '*', redirect: '/404', hidden: true }
]const createRouter = () => new Router({// mode: 'history', // require service supportscrollBehavior: () => ({ y: 0 }),routes: constantRoutes
})const router = createRouter()// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {const newRouter = createRouter()router.matcher = newRouter.matcher // reset router
}export default router

        2、登录者菜单转换成路由

                在根目录下src文件夹下store文件夹下modules文件夹下,修改permission.js文件,代码如下

import {asyncRoutes, constantRoutes} from '@/router'
import {getPersonalMenu} from '@/api/common'
import {warn} from '@/utils/message'
import Layout from '@/layout'/*** Use meta.role to determine if the current user has permission* @param roles* @param route*/
function hasPermission(roles, route) {if (route.meta && route.meta.roles) {return roles.some(role => route.meta.roles.includes(role))} else {return true}
}/*** Filter asynchronous routing tables by recursion* @param routes asyncRoutes* @param roles*/
export function filterAsyncRoutes(routes, roles) {const res = []routes.forEach(route => {const tmp = {...route}if (hasPermission(roles, tmp)) {if (tmp.children) {tmp.children = filterAsyncRoutes(tmp.children, roles)}res.push(tmp)}})return res
}const state = {routes: [],addRoutes: []
}const mutations = {SET_ROUTES: (state, routes) => {state.addRoutes = routesstate.routes = constantRoutes.concat(routes)}
}/*** 后台查询的菜单数据拼装成路由格式的数据* @param routes*/
export function generaMenu(routes, data) {data.forEach(item => {const menu = {path: item.path === '#' ? item.id + '_key' : item.path,component: item.component === '#' ? Layout : resolve => require([`@/views/${item.component}`], resolve),hidden: item.is_hidden,redirect: item.redirect,children: [],name: 'menu_' + item.menuname,alwaysShow: item.always_show,meta: {title: item.title,id: item.id,icon: item.is_icon === 1 ? item.icon : '',/* affix: item.affix,*/noCache: item.is_cache}}// 一级路由if (!item.children && item.pid === 0) {menu.name = undefinedmenu.children = [{path: item.path,component: resolve => require([`@/views/${item.path}`], resolve),name: 'menu_' + item.menuname,meta: {title: item.title,icon: item.is_icon === 1 ? item.icon : '',noCache: item.is_cache,//affix: item.affix}}]}// 二级路由if (item.children) {generaMenu(menu.children, item.children)}routes.push(menu)})
}function filterMenus(localMenus, remoteMenus) {const res = []localMenus.forEach(local => {remoteMenus.forEach(remote => {if (remote.path === local.path) {local.meta.roles = remote.roleSlugsif (local.children && remote.children) {local.children = filterMenus(local.children, remote.children)}res.push(local)}})})return res
}const actions = {generateRoutes({commit, state}, key) {return new Promise(resolve => {const loadMenuData = []getPersonalMenu().then(res => {if (res.code === 50034) {reject(res.message)} else if (res.code === 50000) {warn(res.message)} else {const remoteRoutes = res.data.menuObject.assign(loadMenuData, remoteRoutes)const tempAsyncRoutes = Object.assign([], asyncRoutes)generaMenu(tempAsyncRoutes, loadMenuData)let accessedRoutes/*if (key == 'admin') {accessedRoutes = tempAsyncRoutes || []} else {accessedRoutes = filterAsyncRoutes(tempAsyncRoutes, key)}*/accessedRoutes = filterAsyncRoutes(tempAsyncRoutes, key)commit('SET_ROUTES', accessedRoutes)resolve(accessedRoutes)}}).catch(error => {reject(error)})})}
}export default {namespaced: true,state,mutations,actions
}

四、提前说明

        此时就已经可以登录到系统里面去了,结果如下图。明天将完成个人资料页面、退出及后端过期退出自动更新数据库的退出数据。

http://www.lryc.cn/news/484671.html

相关文章:

  • 动态规划技巧点
  • 深度学习之pytorch常见的学习率绘制
  • Spring Boot集成SQL Server快速入门Demo
  • 低代码牵手 AI 接口:开启智能化开发新征程
  • 【已解决】git push一直提示输入用户名及密码、fatal: Could not read from remote repository的问题
  • python语言基础-4 常用模块-4.13 其他模块
  • 微信小程序=》基础=》常见问题=》性能总结
  • JWT深度解析:Java Web中的安全传输与身份验证
  • 使用Java爬虫获取商品订单详情:从API到数据存储
  • Mybatis中批量插入foreach优化
  • Word VBA如何间隔选中多个(非连续)段落
  • Linux系统常用操作与命令指南
  • StructuredStreaming (一)
  • 由播客转向个人定制的音频频道(1)平台搭建
  • [自然语言处理] [AI]深入理解语言与情感分类:从基础到深度学习的进展
  • 【GPTs】Gif-PT:DALL·E制作创意动图与精灵动画
  • 云原生周刊:Istio 1.24.0 正式发布
  • Linux设置jar包开机启动
  • 计算机视觉和机器人技术中的下一个标记预测与视频扩散相结合
  • C语言之简单的获取命令行参数和环境变量
  • STL之vecor的使用(超详解)
  • SystemVerilog学习笔记(一):数据类型
  • Linux软件包管理与Vim编辑器使用指南
  • 每日一练 | 包过滤防火墙的工作原理
  • AR眼镜方案_AR智能眼镜阵列/衍射光波导显示方案
  • SpringBoot(十九)创建多模块Springboot项目(完整版)
  • Navicat 17 功能简介 | 单元格编辑器
  • MySQL【四】
  • 简单叙述 Spring Boot 启动过程
  • 微信小程序自定义tabbar;禁用某个tab;修改某个tab的样式