hookehuyr

✨ feat: 处理授权从定向问题

/*
* @Date: 2022-09-19 14:11:05
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2022-11-01 11:49:42
* @LastEditTime: 2022-11-01 13:28:38
* @FilePath: /swx/src/app.js
* @Description: 文件描述
*/
......@@ -11,7 +11,7 @@ import './app.less'
import '@/components/vant-weapp/common/index.wxss'
import request from './utils/request';
import Taro from '@tarojs/taro'
import { getCurrentPageUrl } from "@/utils/weapp";
import { routerStore } from '@/stores/router'
const App = createApp({
// 可以使用所有的 Vue 生命周期方法
......@@ -22,6 +22,9 @@ const App = createApp({
onLaunch(options) {
// 未授权状态跳转授权页面,首页不需要权限
const path = options.path;
// 缓存没有权限的地址
const router = routerStore();
router.add(path);
if (path !== 'pages/index/index' && !wx.getStorageSync("sessionid")) {
wx.navigateTo({
url: './pages/auth/index'
......
<!--
* @Date: 2022-09-19 14:11:06
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2022-10-21 17:24:06
* @LastEditTime: 2022-11-01 13:32:00
* @FilePath: /swx/src/pages/auth/index.vue
* @Description: 文件描述
-->
......@@ -21,6 +21,8 @@ import request from '@/utils/request';
<script>
import "./index.less";
import { getCurrentPageParam } from "@/utils/weapp";
export default {
name: "authPage",
mounted () {
......@@ -42,9 +44,9 @@ export default {
// 修改请求头
request.defaults.headers.cookie = res.cookies[0];
if (res.data.data.avatar) {
Taro.navigateBack({
delta: 1 // 返回上一级页面。
});
Taro.redirectTo({
url: '../../' + getCurrentPageParam().url
})
} else { // 头像没有设置跳转完善信息页面
Taro.redirectTo({
url: '../apxUserInfo/index'
......
/*
* @Date: 2022-10-28 14:34:22
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2022-11-01 13:27:09
* @FilePath: /swx/src/stores/router.js
* @Description: 缓存路由信息
*/
import { defineStore } from 'pinia'
export const routerStore = defineStore('router', {
state: () => {
return {
url: '',
}
},
actions: {
add (path) {
this.url = path
},
remove () {
this.url = ''
},
},
})
/*
* @Date: 2022-09-19 14:11:06
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2022-10-18 15:02:01
* @LastEditTime: 2022-11-01 13:29:19
* @FilePath: /swx/src/utils/request.js
* @Description: 简单axios封装,后续按实际处理
*/
......@@ -11,6 +11,7 @@ import Taro from '@tarojs/taro'
import Toast from '../components/vant-weapp/toast/toast';
import { strExist } from './tools'
import qs from 'Qs'
import { routerStore } from '@/stores/router'
// import { ProgressStart, ProgressEnd } from '@/components/axios-progress/progress';
// import store from '@/store'
......@@ -94,7 +95,7 @@ service.interceptors.response.use(
* 授权完成后 返回当前页面
*/
Taro.navigateTo({
url: '../../pages/auth/index'
url: '../../pages/auth/index?url=' + routerStore().url
})
}
return response
......