修改登录

This commit is contained in:
weiwei committed 2025-04-25 10:38:02 +08:00
1 parent 3287ba950f
commit 23ec18a8b1
7 files changed
+62 -38

No files matched your search

-1
View File
@@ -67,7 +67,6 @@
"luch-request": "^3.1.1",
"pinia": "^2.2.6",
"qrcode": "^1.5.4",
"qs": "^6.13.1",
"radash": "^12.1.0",
"vue": "^3.3.11",
"vue-i18n": "^9.1.9",
-11
View File
@@ -80,9 +80,6 @@ importers:
qrcode:
specifier: ^1.5.4
version: 1.5.4
qs:
specifier: ^6.13.1
version: 6.14.0
radash:
specifier: ^12.1.0
version: 12.1.0
@@ -3329,10 +3326,6 @@ packages:
resolution: {integrity: sha512-+38qI9SOr8tfZ4QmJNplMUxqjbe7LKvvZgWdExBOmd+egZTtjLB67Gu0HRX3u/XOq7UU2Nx6nsjvS16Z9uwfpg==}
engines: {node: '>=0.6'}
qs@6.14.0:
resolution: {integrity: sha512-YWWTjgABSKcvs/nWBi9PycY/JiPJqOD4JA6o9Sej2AtvSGarXxKC3OQSk4pAarbdQlKAh5D4FCQkJNkW+GAn3w==}
engines: {node: '>=0.6'}
querystringify@2.2.0:
resolution: {integrity: sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==}
@@ -8345,10 +8338,6 @@ snapshots:
dependencies:
side-channel: 1.1.0
qs@6.14.0:
dependencies:
side-channel: 1.1.0
querystringify@2.2.0: {}
queue-microtask@1.2.3: {}
+3 -3
View File
@@ -3,7 +3,7 @@
<view class="h-20rpx" />
<view class="flex-row items-center">
<image
v-if="state.userInfo?.sysUser?.avatar"
v-if="state.userInfo?.avatar"
class="w-100rpx h-100rpx rounded-full"
:src="filePath(state.userInfo.sysUser.avatar)"
mode="aspectFill"
@@ -11,9 +11,9 @@
<image v-else class="w-100rpx h-100rpx rounded-full" src="/static/icon/default-avatar.png" mode="aspectFill" />
<view class="m-l-30rpx" v-if="state.userInfo?.sysUser?.userId">
<view class="flex-row items-center">
<text class="sub-text-30">{{ state.userInfo?.sysUser?.name }}</text>
<text class="sub-text-30">{{ state.userInfo.nickName }}</text>
</view>
<text class="sub-text-26">ID {{ state.userInfo?.sysUser?.userId }}</text>
<text class="sub-text-26">ID {{ state.userInfo?.user_id }}</text>
</view>
<view v-else class="flex-row items-center m-l-30rpx" @tap="onTabLogin">
<text class="sub-text-32">请先登录</text>
+38 -10
View File
@@ -28,6 +28,7 @@ import { ref, reactive } from "vue"
import { constant, router } from "@@/index"
import { userApi } from "@@/api"
import request from "@/sheep/utils/request"
import { encryptionBase64 } from "@/sheep/utils/encryption"
let applyForm = reactive<any>({
username: "",
@@ -83,9 +84,34 @@ const getUserInfo = () => {
})
}
const basicAuth = "Basic " + encryptionBase64(import.meta.env.VITE_OAUTH2_APP_CLIENT)
const mnpLogin = (code: string) => {
const form = {
mobile: `APP-MINI@${code}`,
code: code,
grant_type: "mobile",
scope: "server",
}
return request({
url: "/auth/oauth2/token",
method: "POST",
params: form,
header: {
Authorization: basicAuth, //"mini:mini"
"content-type": "application/x-www-form-urlencoded",
},
custom: {
showLoading: false,
withToken: false,
},
})
}
// 登录
const login = async () => {
const result = await uni.login().catch((error) => error)
const result = await uni.login({ provider: "weixin" }).catch((error) => error)
if (result.errMsg === "login:ok") {
const params = {
mobile: "MINI@" + result.code,
@@ -94,15 +120,17 @@ const login = async () => {
console.log("code", result.code)
const res: any = await request({
url: "/auth/oauth2/token?grant_type=mobile",
method: "post",
data: params,
header: {
Authorization: "Basic bWluaTptaW5p",
"Content-Type": "application/x-www-form-urlencoded",
},
})
const res: any = await mnpLogin(result.code)
// const res: any = await request({
// url: "/auth/oauth2/token?grant_type=mobile",
// method: "post",
// data: params,
// header: {
// Authorization: "Basic bWluaTptaW5p",
// "Content-Type": "application/x-www-form-urlencoded",
// },
// })
console.log("res", res)
+2 -2
View File
@@ -1,8 +1,8 @@
import request from "@/sheep/utils/request"
import { encryption } from "@/sheep/utils/encryption"
import { encryption, encryptionBase64 } from "@/sheep/utils/encryption"
// 将 Basic Auth 字符串提取为常量
const BASIC_AUTH = "Basic " + window.btoa(import.meta.env.VITE_OAUTH2_APP_CLIENT)
const BASIC_AUTH = "Basic " + encryptionBase64(import.meta.env.VITE_OAUTH2_APP_CLIENT)
// 定义接口类型
interface LoginParams {
+17 -9
View File
@@ -1,15 +1,23 @@
import * as CryptoJS from "crypto-js";
import * as CryptoJS from "crypto-js"
/**
*加密处理
*/
export function encryption(src: string, keyWord: string) {
const key = CryptoJS.enc.Utf8.parse(keyWord);
// 加密
var encrypted = CryptoJS.AES.encrypt(src, key, {
iv: key,
mode: CryptoJS.mode.CFB,
padding: CryptoJS.pad.NoPadding,
});
return encrypted.toString();
const key = CryptoJS.enc.Utf8.parse(keyWord)
// 加密
var encrypted = CryptoJS.AES.encrypt(src, key, {
iv: key,
mode: CryptoJS.mode.CFB,
padding: CryptoJS.pad.NoPadding,
})
return encrypted.toString()
}
/**
*加密处理
*/
export function encryptionBase64(rawStr: string) {
let wordArray = CryptoJS.enc.Utf8.parse(rawStr)
return CryptoJS.enc.Base64.stringify(wordArray)
}
+2 -2
View File
@@ -77,8 +77,8 @@ function handleSuccessMessage(response: any) {
// 创建请求实例
const http = new Request({
baseURL: import.meta.env.VITE_API_URL,
// baseURL: import.meta.env.VITE_APP_PROD_SERVICE,
// baseURL: import.meta.env.VITE_API_URL,
baseURL: import.meta.env.VITE_APP_PROD_SERVICE,
timeout: 15000,
method: "GET",
header: {