feat:设备授权问题

This commit is contained in:
dzc committed 2026-04-28 20:36:27 +08:00
1 parent 50b7ba4601
commit c9c9c365dd
19 files changed
+196 -138

No files matched your search

+3 -3
View File
@@ -112,15 +112,15 @@ export default {
}),
// 设备认证
verifyDevice: (data: { mobilePhone: string; code: string }) =>
verifyDevice: (data: { mobilePhone: string; code: string, uniqueCode?: string, deviceJson?: string }) =>
request({
url: "/thirdparty/thirdPartyOAth2/verify-device",
url: "/thirdparty/thirdPartyOAth2/mini-app/verify-device",
method: "POST",
data,
}),
// 判断该设备是否被验证
isVerifyDevice: (data: { mobile: string; userId: string }) =>
isVerifyDevice: (data: { mobile: string; userId: string, uniqueCode?: string, deviceJson?: string }) =>
request({
url: "/thirdparty/thirdPartyOAth2/is-verify-device",
method: "POST",
@@ -64,7 +64,7 @@ function doToDashboard() {
.navbar {
position: absolute;
left: 20rpx;
height: 44px;
height: 56rpx;
display: flex;
justify-content: center;
align-items: center;
@@ -72,8 +72,8 @@ function doToDashboard() {
&_center {
display: flex;
align-items: center;
height: 56rpx;
border-radius: 28rpx;
height: 68rpx;
border-radius: 34rpx;
background: #fff;
box-shadow: 0px 0px 4rpx rgba(51, 51, 51, 0.08), 0px 4rpx 6rpx 2rpx rgba(102, 102, 102, 0.12);
z-index: 100;
@@ -88,7 +88,8 @@ function doToDashboard() {
display: flex;
justify-content: center;
align-items: center;
width: 56rpx;
font-size: 36rpx;
width: 68rpx;
}
}
}
@@ -67,7 +67,7 @@ function doToDashboard() {
<style lang="scss" scoped>
.navbar {
position: relative;
height: 44px;
height: 56rpx;
display: flex;
justify-content: center;
align-items: center;
@@ -77,8 +77,8 @@ function doToDashboard() {
left: 20rpx;
display: flex;
align-items: center;
height: 56rpx;
border-radius: 28rpx;
height: 68rpx;
border-radius: 34rpx;
background: #fff;
box-shadow: 0px 0px 4rpx rgba(51, 51, 51, 0.08), 0px 4rpx 6rpx 2rpx rgba(102, 102, 102, 0.12);
@@ -92,7 +92,8 @@ function doToDashboard() {
display: flex;
justify-content: center;
align-items: center;
width: 56rpx;
font-size: 36rpx;
width: 68rpx;
}
}
@@ -101,9 +102,9 @@ function doToDashboard() {
right: 20rpx;
background: #fff;
box-shadow: 0px 0px 4rpx rgba(51, 51, 51, 0.08), 0px 4rpx 6rpx 2rpx rgba(102, 102, 102, 0.12);
border-radius: 28rpx;
width: 56rpx;
height: 56rpx;
border-radius: 34rpx;
width: 68rpx;
height: 68rpx;
display: flex;
justify-content: center;
align-items: center;
@@ -16,6 +16,9 @@ function getHeight() {
return bottom + "px"
}
if (props.type && props.type === "top") {
if (top < 22) {
return "22px"
}
return top + "px"
}
return 22 + "px"
@@ -7,6 +7,7 @@ import { jump } from "@/sheep/router";
import { userApi } from "@@/api/index"
import VerifyDeviceImpModel from "../../verify-device-imp-model.vue"
import { getMiniUniqueCode, getDeviceKey } from "@@/utils/mini-tool"
const tabbarStore = useTabbarStore()
@@ -99,9 +100,11 @@ async function checkVerifyDevice() {
const userInfo = uni.getStorageSync(constant.storageConstant.USERINFO)
if (!userInfo || !userInfo.sysUser || !userInfo.sysUser.userId) return
// 是否在白名单中
if (constant.DEVICE_VERIFY_WRITE_LIST.includes(userInfo.sysUser.phone)) {
return
}
// if (constant.DEVICE_VERIFY_WRITE_LIST.includes(userInfo.sysUser.phone)) {
// return
// }
const uniqueCode = await getMiniUniqueCode()
const deviceKey = await getDeviceKey()
const _params = {
mobile: userInfo.sysUser.phone,
userId: userInfo.sysUser.userId,
@@ -154,7 +157,8 @@ defineExpose({
<view v-if="tabbarStore.isTabbar" class="layout_foot">
<tm-tabbar class="layout_foot" :activeIndex="tabbarStore.activeIndex" :list="tabbarStore.pageTabbarList"
:outIndex="-1" fontSize="12px" iconSize="24px" bgColor="#F6F5FA" :zIndex="99999" darkBgColor="#F6F5FA"
borderColor="#DBDDDE" color="#8E8E8E" selected-color="#0094ff" position="fixed" @change="tabbarChange">
borderColor="#DBDDDE" color="#8E8E8E" selected-color="#0094ff" position="relative"
@change="tabbarChange">
</tm-tabbar>
</view>
<VerifyDeviceImpModel ref="verifyDeviceImpModelRef" :close="verifyDeviceImpModelClose" />
@@ -27,7 +27,10 @@
<script setup lang="ts">
import { ref, reactive, watch, onUnmounted } from "vue"
import { constant } from "@@/index"
import { userApi } from "@@/api"
import { getMiniUniqueCode, getDeviceKey } from "@@/utils/mini-tool"
const props = withDefaults(
defineProps<{
@@ -106,7 +109,11 @@ const doSubmit = async () => {
if (!isPass) return
uni.showLoading({ title: "验证中...", mask: true })
const res: any = await userApi.verifyDevice({ mobilePhone: form.mobilePhone, code: form.code })
const params = {
mobilePhone: form.mobilePhone,
code: form.code,
}
const res: any = await userApi.verifyDevice(params)
if (res.code != 0) {
uni.showToast({ title: res.msg || "验证失败", icon: "none" })
return
+2
View File
@@ -7,4 +7,6 @@ export const SERVICE_IMAGE = {
blueBg: "/admin/sys-file/oss/file?fileName=ab8823b0abb045a7b9ce7a52d91eea8f.png",
// 生日海报
birthdayCoupon: "/admin/sys-file/oss/file?fileName=d723089fccec4f598e86459e8899b0de.jpg",
// 小程序logo
logo: "/admin/sys-file/oss/file?fileName=df4f93c63f3b431ea661e9c0031e6450.jpeg",
}
+16
View File
@@ -48,3 +48,19 @@ export const getUrlParamsObj = (url?: string): Record<string, any> => {
const params = getUrlParams(url)
return params
}
export const createCooldown = (cooldownMs: number = 300) => {
let locked = false
let timer: any = null
return (fn: () => void) => {
if (locked) return false
locked = true
clearTimeout(timer)
timer = setTimeout(() => {
locked = false
}, cooldownMs)
fn()
return true
}
}
+8 -3
View File
@@ -11,9 +11,7 @@ export async function getMiniUniqueCode(forceGet = false) {
}
const appEnv = await getAppInfo()
try {
const res = await uni.login({
provider: "weixin",
})
const res = await uni.login({ provider: "weixin" });
if (!res?.code) {
throw new Error("登录失败")
}
@@ -36,3 +34,10 @@ export async function getMiniUniqueCode(forceGet = false) {
console.log("获取小程序唯一编码失败", error)
}
}
// 获取设备唯一编码
export async function getDeviceKey() {
const sysInfo = await uni.getSystemInfo()
const sysKey = sysInfo.deviceId + "-" + sysInfo.brand + sysInfo.deviceModel + "-" + sysInfo.deviceType + "-" + sysInfo.platform
return sysKey
}
+16 -7
View File
@@ -2,7 +2,7 @@ import Request from "luch-request"
import { isEmpty } from "radash"
import { router, constant } from "@@/index"
import { getBaseApiUrl, getAppInfo, isDevEnv } from "@@/utils/app"
import { createCooldown, getBaseApiUrl, getAppInfo, isDevEnv } from "@@/utils/app"
import { userApi } from "../api"
import { APPENV } from "../constant"
@@ -19,12 +19,13 @@ const SKIP_AUTH_URLS = [
const SKIP_REFRESH_TOKEN = ["/sys/auth/refresh-token", "/auth/token/check_token"]
let refreshTokenLock = true
const runLoginRedirect = createCooldown(1500)
console.log("getBaseApiUrl:", getBaseApiUrl())
const https = new Request({
baseURL: getBaseApiUrl(),
timeout: 15000,
timeout: 10 * 1000,
method: "GET",
header: {
Accept: "*/*",
@@ -84,13 +85,21 @@ https.interceptors.response.use(
return Promise.resolve(response.data)
},
async (error) => {
uni.hideLoading()
// 处理 424 错误(token过期)
if (error.statusCode === 424) {
// 开发环境直接清除token并跳转登录
uni.removeStorageSync(TOKEN_KEY)
uni.removeStorageSync(USER_INFO_KEY)
uni.showToast({ title: "登录已过期,请重新登录", icon: "none" })
router.jump("/pages/root/login")
// 判断是否在登录页面
const currentPage = router.getCurrentPage()
const currentRoute = currentPage?.route
if (currentRoute === "pages/root/login" || currentRoute === "/pages/root/login") {
return
}
runLoginRedirect(() => {
uni.removeStorageSync(TOKEN_KEY)
uni.removeStorageSync(USER_INFO_KEY)
uni.showToast({ title: "登录已过期,请重新登录", icon: "none" })
uni.navigateTo({ url: "/pages/root/login" })
})
}
// 显示错误信息
else if (error?.data?.msg) {