修复app登陆的问题

This commit is contained in:
有果 2026-03-18 13:51:52 +08:00
parent 2c4904c7d4
commit eee75e1d71
9 changed files with 124 additions and 44 deletions

View File

@ -119,6 +119,10 @@ export default {
}).catch((err) => {
logOut();
})
}else{
if(window.sf.isSfApp()){
shunfenLogin();
}
}
//

5
config.js Normal file
View File

@ -0,0 +1,5 @@
window.config = {
BACK_URL: "https://uat.kingkongcang.com/client/",
ENV: "sit",
SF_APP_ID: "202603041358374970",
}

33
hooks/useLoading.js Normal file
View File

@ -0,0 +1,33 @@
// /hooks/useLoading.js
const loadingMap = new Set()
export function useLoading() {
const openLoading = (key = 'default', loadingObj) => {
loadingMap.add(key)
uni.showLoading({
...loadingObj
})
}
const closeLoading = (key = 'default') => {
loadingMap.delete(key)
if (loadingMap.size === 0) {
uni.hideLoading()
}
}
const clearLoading = () => {
loadingMap.clear()
uni.hideLoading()
}
return {
openLoading,
closeLoading,
clearLoading
}
}

View File

@ -12,44 +12,47 @@
<!-- <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover" /> -->
<link rel="icon" href="/favicon.ico" />
<script src="./config.js"></script>
<script src="/client/config.js"></script>
<script src="https://ucmp-static.sf-express.com/assets/sdks/microservice-1.0.4.min.js"></script>
<script>
function loadScript(url, retry = 3) {
return new Promise((resolve, reject) => {
const script = document.createElement('script')
script.src = url
script.async = true
const sf = new SFUIP.SfMicroservice(window?.config?.ENV??'sit')
window.sf = sf
// function loadScript(url, retry = 3) {
// return new Promise((resolve, reject) => {
// const script = document.createElement('script')
// script.src = url
// script.async = true
script.onload = () => {
resolve()
}
// script.onload = () => {
// resolve()
// }
script.onerror = () => {
if (retry > 0) {
console.warn('脚本加载失败,重试中...', retry)
setTimeout(() => {
loadScript(url, retry - 1)
.then(resolve)
.catch(reject)
}, 1000)
} else {
reject(new Error('脚本加载失败'))
}
}
// script.onerror = () => {
// if (retry > 0) {
// console.warn('脚本加载失败,重试中...', retry)
// setTimeout(() => {
// loadScript(url, retry - 1)
// .then(resolve)
// .catch(reject)
// }, 1000)
// } else {
// reject(new Error('脚本加载失败'))
// }
// }
document.head.appendChild(script)
})
}
loadScript(
'https://ucmp-static.sf-express.com/assets/sdks/microservice-1.0.4.min.js',
3
).then(() => {
console.log('SDK加载成功')
const sf = new SFUIP.SfMicroservice( window?.config?.ENV??'sit')
window.sf = sf
}).catch(err => {
console.error('最终加载失败', err)
})
// document.head.appendChild(script)
// })
// }
// loadScript(
// 'https://ucmp-static.sf-express.com/assets/sdks/microservice-1.0.4.min.js',
// 3
// ).then(() => {
// console.log('SDK加载成功')
// const sf = new SFUIP.SfMicroservice(window?.config?.ENV??'sit')
// window.sf = sf
// }).catch(err => {
// console.error('最终加载失败', err)
// })
</script>
<script>

View File

@ -2,8 +2,8 @@ import { createSSRApp } from "vue";
import App from "./App";
import i18n from "./locale/index";
import * as Pinia from "pinia";
// import VConsole from 'vconsole'
// new VConsole()
import VConsole from 'vconsole'
new VConsole()
// import '@/uni.scss'
// 引入uvUI
import uvUI from "@/uni_modules/uv-ui-tools";

View File

@ -75,7 +75,7 @@
"vueVersion" : "3",
"h5" : {
"router" : {
"base" : "./"
"base" : "/client/"
},
"devServer" : {
"port" : 8999,
@ -100,8 +100,8 @@
}
}
},
"locale" : "en",
"fallbackLocale" : "en",
"locale" : "zh-Hans",
"fallbackLocale" : "zh-Hans",
"mp-xhs" : {
"appid" : "6786436ac669e40001348567",
"permission" : {

View File

@ -499,7 +499,7 @@ const goOrder = async () => {
payChannel: 'payByWeChat' // app
}).then(res => {
const { channelType, status, message, channelResult } = res && res.result || {}
if (state === 0) {
if (status === 0) {
uni.showToast({
title: '支付成功',
icon: 'none',
@ -1108,6 +1108,8 @@ function changeMove(event) {
.info {
display: flex;
font-size: 28rpx;
max-height: 60vh;
overflow-y: auto;
.list {
display: flex;

View File

@ -571,7 +571,7 @@ const goOrder = async () => {
payChannel: 'payByWeChat' // app
}).then(res => {
const { channelType, status, message, channelResult } = res && res.result || {}
if (state === 0) {
if (status === 0) {
uni.showToast({
title: '支付成功',
icon: 'none',

View File

@ -1,5 +1,8 @@
import { projectInfo,OFFICIAL_URL} from "@/config/index.js";
import i18n from '../locale/index';
import { useLoginApi } from "@/Apis/login.js";
import { useMainStore } from "@/store/index.js";
const getApi = useLoginApi();
const { t } = i18n.global;
export const onTabItemTap = (event)=>{
@ -256,17 +259,47 @@ export const parseUrlParams = (url) => {
return params;
}
// 顺丰参数
export const shunfenLogin = (code) => {
export const shunfenLogin = async (code) => {
// 授权参数(请根据实际情况修改)
const authOptions = {
appId: "202603041358374970", // 第三方接入ID
appId: window?.config?.SF_APP_ID ??"202603041358374970", // 第三方接入ID
scope: ["sf_userinfo", "sf_mobile", "sf_base", "sf_emp", "sf_channelId"],
successUrl: window?.config?.BACK_URL ?? "https://uat.kingkongcang.com/client/", // 当前页面地址
};
window.sf.getAuthCode({
...authOptions,
})
.then((res) => {
.then(async(res) => {
if (window.sf.isSfApp()) {
const authCode = res.authCode;
if(authCode){
let source = window.sf.isSfApp() ? 2 : 1;
uni.showLoading({
mask:true,
});
getApi.ShunFengLogin({
code:authCode,
source,
})
.then(async(res) => {
uni.hideLoading();
if (res.code == 200) {
const store = useMainStore(); // ✅ 在这里调用
store.storeState.token = res.data.token;
store.storeState.hasTrytoLogin = true;
await store.getUserInfo();
console.log("token", res.data.token);
uni.setStorageSync("token", res.data.token);
uni.setStorageSync("openId", res.data.openId);
console.log("登陆成功", res.data.openId);
}
}).catch((err) => {
})
}else{
shunfenLogin()
}
}
console.log('getAuthCode success',res);
})
.catch((err) => console.log('getAuthCode err',err));