mirror of
https://gitee.com/myxzgzs/boyue-ui-admin-uniapp
synced 2025-08-08 00:12:44 +08:00
code review:双 token 实现。
This commit is contained in:
parent
81596b568a
commit
b5ab025fc2
2
env/.env
vendored
2
env/.env
vendored
@ -1,4 +1,4 @@
|
|||||||
VITE_APP_TITLE = 'ruoyi-vue-pro'
|
VITE_APP_TITLE = '芋道管理系统'
|
||||||
VITE_APP_PORT = 9000
|
VITE_APP_PORT = 9000
|
||||||
|
|
||||||
VITE_UNI_APPID = 'H57F2ACE4'
|
VITE_UNI_APPID = 'H57F2ACE4'
|
||||||
|
@ -6,11 +6,11 @@
|
|||||||
*
|
*
|
||||||
* update 2024-10-09
|
* update 2024-10-09
|
||||||
* 登录之后,会进行页面跳转。在完成页面跳转之前,就需要获取到用户信息
|
* 登录之后,会进行页面跳转。在完成页面跳转之前,就需要获取到用户信息
|
||||||
* 并设置到userStore中。
|
* 并设置到 userStore 中。
|
||||||
*
|
*
|
||||||
* 如何设置当前页面需要校验登录状态?
|
* 如何设置当前页面需要校验登录状态?
|
||||||
* 在router块中设置
|
* 在 router 块中设置
|
||||||
*
|
*
|
||||||
* <route lang="json5">
|
* <route lang="json5">
|
||||||
{
|
{
|
||||||
layout: 'tabbar',
|
layout: 'tabbar',
|
||||||
@ -60,10 +60,10 @@ const navigateToInterceptor = {
|
|||||||
return option
|
return option
|
||||||
}
|
}
|
||||||
|
|
||||||
// 下面的逻辑跟PC端差不多
|
// 下面的逻辑跟 PC 端差不多
|
||||||
if (getAccessToken()) {
|
if (getAccessToken()) {
|
||||||
if (path === '/pages/login/index') {
|
if (path === '/pages/login/index') {
|
||||||
// 这里写死,避免在login页面中设置了needLogin,导致死循环
|
// 这里写死,避免在 login 页面中设置了 needLogin,导致死循环
|
||||||
return option
|
return option
|
||||||
} else {
|
} else {
|
||||||
// todo 获取字典数据并保存到本地
|
// todo 获取字典数据并保存到本地
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "ruoyi-vue-pro",
|
"name": "芋道管理系统",
|
||||||
"appid": "H57F2ACE4",
|
"appid": "H57F2ACE4",
|
||||||
"description": "",
|
"description": "",
|
||||||
"versionName": "1.0.0",
|
"versionName": "1.0.0",
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
<!-- 协作界面:用于 bpm 工作流 -->
|
||||||
<route lang="json5" type="page">
|
<route lang="json5" type="page">
|
||||||
{
|
{
|
||||||
layout: 'tabbar',
|
layout: 'tabbar',
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<!-- 通讯录item -->
|
<!-- 通讯录 item -->
|
||||||
<template>
|
<template>
|
||||||
<view class="flex justify-between w-full">
|
<view class="flex justify-between w-full">
|
||||||
<!-- 头像 -->
|
<!-- 头像 -->
|
||||||
@ -13,7 +13,7 @@
|
|||||||
<view
|
<view
|
||||||
class="h-100rpx grow-1 flex flex-col justify-center border-solid border-b-[0.5px] border-x-0 border-t-0 border-[#E3E2E2]"
|
class="h-100rpx grow-1 flex flex-col justify-center border-solid border-b-[0.5px] border-x-0 border-t-0 border-[#E3E2E2]"
|
||||||
>
|
>
|
||||||
<!-- 如果是个人 s -->
|
<!-- 如果是个人 -->
|
||||||
<view v-if="props.item.isLeaf">
|
<view v-if="props.item.isLeaf">
|
||||||
<view class="text-24rpx">{{ props.item.name }}</view>
|
<view class="text-24rpx">{{ props.item.name }}</view>
|
||||||
<view class="text-22rpx">
|
<view class="text-22rpx">
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
<!-- 通讯录界面:用于 im 聊天 -->
|
||||||
<route lang="json5" type="page">
|
<route lang="json5" type="page">
|
||||||
{
|
{
|
||||||
layout: 'tabbar',
|
layout: 'tabbar',
|
||||||
|
@ -73,7 +73,7 @@ import { login, getTenantIdByName } from '@/service/login/LoginAPI'
|
|||||||
import { useUserStore } from '@/store'
|
import { useUserStore } from '@/store'
|
||||||
import * as authUtil from '@/utils/auth'
|
import * as authUtil from '@/utils/auth'
|
||||||
|
|
||||||
// 提示组件
|
// 提示组件 TODO @ Qiksy 讨论:// 提示组件 这种,我们要不放在 useToast(),作为尾注释,简洁一点。
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
|
|
||||||
const focusInput = ref('')
|
const focusInput = ref('')
|
||||||
@ -102,7 +102,7 @@ const loginData = reactive({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
// 获取租户 ID
|
// 获取租户 ID // TODO @ Qiksy 讨论:这个方法注释,要不用 /** 获取租户 ID */ 高亮的更明显哈。
|
||||||
const getTenantId = async () => {
|
const getTenantId = async () => {
|
||||||
if (loginData.tenantEnable === 'true') {
|
if (loginData.tenantEnable === 'true') {
|
||||||
const res = (await getTenantIdByName(loginData.loginForm.tenantName)) as string
|
const res = (await getTenantIdByName(loginData.loginForm.tenantName)) as string
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
<view><text class="text-[64rpx] font-700">你好</text></view>
|
<view><text class="text-[64rpx] font-700">你好</text></view>
|
||||||
<view class="mt-[36rpx]"><text class="text-[36rpx]">欢迎登录芋道快速开发平台</text></view>
|
<view class="mt-[36rpx]"><text class="text-[36rpx]">欢迎登录芋道快速开发平台</text></view>
|
||||||
</view>
|
</view>
|
||||||
|
<!-- TODO @芋艿:后续把静态资源,放到 CDN -->
|
||||||
<image
|
<image
|
||||||
class="absolute w-full top-0 -z-1"
|
class="absolute w-full top-0 -z-1"
|
||||||
src="/static/images/login-bg.png"
|
src="/static/images/login-bg.png"
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
<!-- 消息列表组件 -->
|
<!-- 消息列表组件 -->
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<view class="w-full flex justify-between">
|
<view class="w-full flex justify-between">
|
||||||
<view class="w-100rpx h-100rpx flex items-center justify-center">
|
<view class="w-100rpx h-100rpx flex items-center justify-center">
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
<!-- 消息界面:用于 im 聊天 -->
|
||||||
<route lang="json5" type="page">
|
<route lang="json5" type="page">
|
||||||
{
|
{
|
||||||
layout: 'tabbar',
|
layout: 'tabbar',
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
<!-- 工作台图标 -->
|
<!-- 工作台图标 -->
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<view class="flex flex-col items-center gap-1" @click="handleClick">
|
<view class="flex flex-col items-center gap-1" @click="handleClick">
|
||||||
<view class="bg-blue-500 rounded-5px w-80rpx h-80rpx flex flex-col items-center justify-center">
|
<view class="bg-blue-500 rounded-5px w-80rpx h-80rpx flex flex-col items-center justify-center">
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
<!-- 工作台界面:用于各种 crud 管理操作 -->
|
||||||
<route lang="json5" type="home">
|
<route lang="json5" type="home">
|
||||||
{
|
{
|
||||||
layout: 'tabbar',
|
layout: 'tabbar',
|
||||||
|
2
src/types/system.d.ts
vendored
2
src/types/system.d.ts
vendored
@ -5,8 +5,8 @@ type UserVO = {
|
|||||||
deptId: number
|
deptId: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// USER 缓存
|
||||||
type UserInfoVO = {
|
type UserInfoVO = {
|
||||||
// USER 缓存
|
|
||||||
permissions: string[]
|
permissions: string[]
|
||||||
roles: string[]
|
roles: string[]
|
||||||
isSetUser: boolean
|
isSetUser: boolean
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* 显示模态弹窗
|
* 显示模态弹窗
|
||||||
|
*
|
||||||
* @param content 提示的标题
|
* @param content 提示的标题
|
||||||
*/
|
*/
|
||||||
export function showConfirm(content: string) {
|
export function showConfirm(content: string) {
|
||||||
@ -18,6 +19,7 @@ export function showConfirm(content: string) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 显示消息提示框
|
* 显示消息提示框
|
||||||
|
*
|
||||||
* @param content 提示的标题
|
* @param content 提示的标题
|
||||||
*/
|
*/
|
||||||
export function toast(content: string) {
|
export function toast(content: string) {
|
||||||
|
@ -6,11 +6,10 @@ import { getEvnBaseUrl } from '@/utils'
|
|||||||
import errorCode from './errorCode'
|
import errorCode from './errorCode'
|
||||||
|
|
||||||
/*
|
/*
|
||||||
双token刷新说明
|
双 token 刷新说明:
|
||||||
1. token和tenantId都是在拦截器中赋值
|
1. token 和 tenantId 都是在拦截器中赋值
|
||||||
2. 后端并不直接更改http statusCode,而是返回一个重新包装后的对象,
|
2. 后端并不直接更改 http statusCode,而是返回一个重新包装后的对象,所以不能使用失败回调函数就行判断token是否过期需要重新获取
|
||||||
所以不能使用失败回调函数就行判断token是否过期需要重新获取
|
3. 应该在 success 中,解析 res,如果 code 是 401,则说明 access token 过期,需要重新获取
|
||||||
3. 应该在success中,解析res,如果code是401,则说明token过期,需要重新获取
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// 是否正在刷新中
|
// 是否正在刷新中
|
||||||
@ -115,7 +114,7 @@ export const http = <T>(options: CustomRequestOptions) => {
|
|||||||
reject(errorCode['500'])
|
reject(errorCode['500'])
|
||||||
} else if (code !== 0) {
|
} else if (code !== 0) {
|
||||||
// 其他的错误
|
// 其他的错误
|
||||||
// ps:ruoyi-vue-pro 的success 的code,默认是0而不是200
|
// ps:yudao 的 success 的 code,默认是 0 而不是 200
|
||||||
toast(msg)
|
toast(msg)
|
||||||
reject(code)
|
reject(code)
|
||||||
}
|
}
|
||||||
|
@ -131,7 +131,7 @@ export const getEvnBaseUrl = () => {
|
|||||||
const {
|
const {
|
||||||
miniProgram: { envVersion },
|
miniProgram: { envVersion },
|
||||||
} = uni.getAccountInfoSync()
|
} = uni.getAccountInfoSync()
|
||||||
// 开发、体验、正式版 三种不同的小程序都可以配置不同的后端url
|
// 开发、体验、正式版 三种不同的小程序都可以配置不同的后端 url
|
||||||
switch (envVersion) {
|
switch (envVersion) {
|
||||||
case 'develop':
|
case 'develop':
|
||||||
baseUrl = 'http://localhost:48080/admin-api'
|
baseUrl = 'http://localhost:48080/admin-api'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user