From e61f720f96b379d691f67d2051cb6b6b958f6bcc Mon Sep 17 00:00:00 2001 From: zhangdi <15053473693@163.com> Date: Tue, 20 Jan 2026 15:16:25 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=B3=E8=BD=AC=E9=80=BB=E8=BE=91=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/system/menu.js | 6 +-- src/page/index/index.vue | 6 ++- src/page/login/authorization.vue | 12 +++-- src/permission.js | 93 ++++++++++++++++---------------- src/router/axios.js | 19 ++++--- src/store/modules/user.js | 10 ++-- 6 files changed, 77 insertions(+), 69 deletions(-) diff --git a/src/api/system/menu.js b/src/api/system/menu.js index 69e7792..e918b08 100644 --- a/src/api/system/menu.js +++ b/src/api/system/menu.js @@ -97,11 +97,9 @@ export const getTopMenu = () => request({ method: 'get' }); -export const getRoutes = (roleId) => request({ +export const getRoutes = (params) => request({ url: '/smartpark/menu/routes', method: 'get', - params: { - roleId, - } + params: params }); diff --git a/src/page/index/index.vue b/src/page/index/index.vue index 3a51591..2a79a49 100644 --- a/src/page/index/index.vue +++ b/src/page/index/index.vue @@ -69,7 +69,7 @@ mounted() { this.init(); }, - computed: mapGetters(["isMenu", "isLock", "isCollapse", "website", "menu"]), + computed: mapGetters(["isMenu", "isLock", "isCollapse", "website", "menu","userInfo"]), props: [], methods: { showCollapse() { @@ -88,8 +88,10 @@ }, //打开菜单 openMenu(item = {}) { - console.log("itemitemitemopenMenu", item) + console.log("itemitemitemopenMenu", this.userInfo) + this.$store.dispatch("GetMenu", item.id).then(data => { + console.log("每次刷新调用", data); if (data.length !== 0) { this.$router.$avueRouter.formatRoutes(data, true); } diff --git a/src/page/login/authorization.vue b/src/page/login/authorization.vue index adea52e..60eeb32 100644 --- a/src/page/login/authorization.vue +++ b/src/page/login/authorization.vue @@ -8,7 +8,9 @@ import { mapGetters } from "vuex"; export default { name: "authorization", - +computed: { + ...mapGetters(["tagWel", "userInfo"]) + }, data() { return {}; }, @@ -28,13 +30,15 @@ export default { this.$store .dispatch("AuthLoginByUsername", res.data.result) .then(() => { - console.log("登录成功"); - this.$router.push({ path: '/firstOrder/list' }); + console.log("登录成功", res.data.result); + console.log("获取用户信息", this.tagWel.value); + // this.$router.push({ path: "/firstOrder/list" }); + this.$router.push({path: this.tagWel.value}); loading.close(); }) .catch(() => { loading.close(); - this.refreshCode(); + // this.refreshCode(); }); }); }, diff --git a/src/permission.js b/src/permission.js index 2f88c34..0f3f807 100644 --- a/src/permission.js +++ b/src/permission.js @@ -14,52 +14,53 @@ router.beforeEach((to, from, next) => { const meta = to.meta || {}; const isMenu = meta.menu === undefined ? to.query.menu : meta.menu; store.commit('SET_IS_MENU', isMenu === undefined); - if (getToken()) { - if (store.getters.isLock && to.path !== lockPage) { //如果系统激活锁屏,全部跳转到锁屏页 - next({path: lockPage}) - } else if (to.path === '/login') { //如果登录成功访问登录页跳转到主页 - next({path: '/'}) - } else { - //如果用户信息为空则获取用户信息,获取用户信息失败,跳转到登录页 - if (store.getters.token.length === 0) { - store.dispatch('FedLogOut').then(() => { - next({path: '/login'}) - }) - } else { - const value = to.query.src || to.fullPath; - const label = to.query.name || to.name; - const meta = to.meta || router.$avueRouter.meta || {}; - const i18n = to.query.i18n; - if (to.query.target) { - window.open(value) - } else if (meta.isTab !== false && !validatenull(value) && !validatenull(label)) { - store.commit('ADD_TAG', { - label: label, - value: value, - params: to.params, - query: to.query, - meta: (() => { - if (!i18n) { - return meta - } - return { - i18n: i18n - } - })(), - group: router.$avueRouter.group || [] - }); - } - next() - } - } - } else { - //判断是否需要认证,没有登录访问去登录页 - if (meta.isAuth === false) { - next() - } else { - next('/login') - } - } + // if (getToken()) { + // if (store.getters.isLock && to.path !== lockPage) { //如果系统激活锁屏,全部跳转到锁屏页 + // next({path: lockPage}) + // } else if (to.path === '/login') { //如果登录成功访问登录页跳转到主页 + // next({path: '/'}) + // } else { + // //如果用户信息为空则获取用户信息,获取用户信息失败,跳转到登录页 + // if (store.getters.token.length === 0) { + // store.dispatch('FedLogOut').then(() => { + // next({path: '/login'}) + // }) + // } else { + // const value = to.query.src || to.fullPath; + // const label = to.query.name || to.name; + // const meta = to.meta || router.$avueRouter.meta || {}; + // const i18n = to.query.i18n; + // if (to.query.target) { + // window.open(value) + // } else if (meta.isTab !== false && !validatenull(value) && !validatenull(label)) { + // store.commit('ADD_TAG', { + // label: label, + // value: value, + // params: to.params, + // query: to.query, + // meta: (() => { + // if (!i18n) { + // return meta + // } + // return { + // i18n: i18n + // } + // })(), + // group: router.$avueRouter.group || [] + // }); + // } + // next() + // } + // } + // } else { + // //判断是否需要认证,没有登录访问去登录页 + // if (meta.isAuth === false) { + // next() + // } else { + // next('/login') + // } + // } + next() }) router.afterEach(() => { diff --git a/src/router/axios.js b/src/router/axios.js index 48281fe..4e8cafe 100644 --- a/src/router/axios.js +++ b/src/router/axios.js @@ -53,7 +53,6 @@ axios.interceptors.request.use(config => { }else{ config.url = baseUrl + config.url; } - console.log(99999,config.url.indexOf('smartpark')>0,baseUrl,config.url) } //安全请求header @@ -71,11 +70,11 @@ axios.interceptors.request.use(config => { //判断传递数据是否加密 const cryptoData = config.cryptoData === true; const token = getToken(); - if (token && !isToken) { - config.headers[website.tokenHeader] = cryptoToken - ? 'crypto ' + crypto.encryptAES(token, crypto.cryptoKey) - : 'bearer ' + token; - } + // if (token && !isToken) { + // config.headers[website.tokenHeader] = cryptoToken + // ? 'crypto ' + crypto.encryptAES(token, crypto.cryptoKey) + // : 'bearer ' + token; + // } // 开启报文加密 if (cryptoData) { if (config.params) { @@ -92,9 +91,9 @@ axios.interceptors.request.use(config => { config.headers["Content-Type"] = "text/plain"; } //headers中配置serialize为true开启序列化 - if (config.method === 'post' && meta.isSerialize === true) { - config.data = serialize(config.data); - } + // if (config.method === 'post' && meta.isSerialize === true) { + // config.data = serialize(config.data); + // } return config; }, error => { return Promise.reject(error); @@ -115,7 +114,7 @@ axios.interceptors.response.use(res => { //获取状态信息 const status = res.data.error_code || res.data.code || res.status; const statusWhiteList = website.statusWhiteList || []; - const message = res.data.msg || res.data.error_description || '系统错误'; + const message = res.data.message || res.data.error_description || '系统错误'; //如果在白名单里则自行catch逻辑处理 if (statusWhiteList.includes(status)) return Promise.reject(res); // 如果是401并且没有重试过,尝试刷新token diff --git a/src/store/modules/user.js b/src/store/modules/user.js index d56ea83..536e6f6 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -279,10 +279,14 @@ const user = { }) }, //获取系统菜单 - GetMenu({ commit, dispatch }, topMenuId) { + GetMenu({ commit, dispatch }, userId) { return new Promise(resolve => { //传roleId - getRoutes().then((res) => { + // 从浏览器中获取角色id + // let roleId = uni.getStorageSync('roleId'); + // console.log(8888,'获取userid',state.userInfo) + + getRoutes(userId).then((res) => { const data = res.data.result let menu = deepClone(data); menu.forEach(ele => { @@ -290,7 +294,7 @@ const user = { }); commit('SET_MENU_ALL', menu) commit('SET_MENU', menu) - dispatch('GetButtons'); + // dispatch('GetButtons'); resolve(menu) })