修复app登陆的问题
This commit is contained in:
parent
2c4904c7d4
commit
eee75e1d71
4
App.vue
4
App.vue
@ -119,6 +119,10 @@ export default {
|
|||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
logOut();
|
logOut();
|
||||||
})
|
})
|
||||||
|
}else{
|
||||||
|
if(window.sf.isSfApp()){
|
||||||
|
shunfenLogin();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 清掉请求有优惠价的时间记录
|
// 清掉请求有优惠价的时间记录
|
||||||
|
|||||||
5
config.js
Normal file
5
config.js
Normal 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
33
hooks/useLoading.js
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
75
index.html
75
index.html
@ -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" /> -->
|
<!-- <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" />
|
<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>
|
<script>
|
||||||
function loadScript(url, retry = 3) {
|
const sf = new SFUIP.SfMicroservice(window?.config?.ENV??'sit')
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const script = document.createElement('script')
|
|
||||||
script.src = url
|
|
||||||
script.async = true
|
|
||||||
|
|
||||||
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('脚本加载失败'))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
window.sf = sf
|
||||||
}).catch(err => {
|
// function loadScript(url, retry = 3) {
|
||||||
console.error('最终加载失败', err)
|
// return new Promise((resolve, reject) => {
|
||||||
})
|
// const script = document.createElement('script')
|
||||||
|
// script.src = url
|
||||||
|
// script.async = true
|
||||||
|
|
||||||
|
// 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('脚本加载失败'))
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// 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>
|
||||||
<script>
|
<script>
|
||||||
|
|||||||
4
main.js
4
main.js
@ -2,8 +2,8 @@ import { createSSRApp } from "vue";
|
|||||||
import App from "./App";
|
import App from "./App";
|
||||||
import i18n from "./locale/index";
|
import i18n from "./locale/index";
|
||||||
import * as Pinia from "pinia";
|
import * as Pinia from "pinia";
|
||||||
// import VConsole from 'vconsole'
|
import VConsole from 'vconsole'
|
||||||
// new VConsole()
|
new VConsole()
|
||||||
// import '@/uni.scss'
|
// import '@/uni.scss'
|
||||||
// 引入uvUI
|
// 引入uvUI
|
||||||
import uvUI from "@/uni_modules/uv-ui-tools";
|
import uvUI from "@/uni_modules/uv-ui-tools";
|
||||||
|
|||||||
@ -75,7 +75,7 @@
|
|||||||
"vueVersion" : "3",
|
"vueVersion" : "3",
|
||||||
"h5" : {
|
"h5" : {
|
||||||
"router" : {
|
"router" : {
|
||||||
"base" : "./"
|
"base" : "/client/"
|
||||||
},
|
},
|
||||||
"devServer" : {
|
"devServer" : {
|
||||||
"port" : 8999,
|
"port" : 8999,
|
||||||
@ -100,8 +100,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"locale" : "en",
|
"locale" : "zh-Hans",
|
||||||
"fallbackLocale" : "en",
|
"fallbackLocale" : "zh-Hans",
|
||||||
"mp-xhs" : {
|
"mp-xhs" : {
|
||||||
"appid" : "6786436ac669e40001348567",
|
"appid" : "6786436ac669e40001348567",
|
||||||
"permission" : {
|
"permission" : {
|
||||||
|
|||||||
@ -499,7 +499,7 @@ const goOrder = async () => {
|
|||||||
payChannel: 'payByWeChat' // app微信支付
|
payChannel: 'payByWeChat' // app微信支付
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
const { channelType, status, message, channelResult } = res && res.result || {}
|
const { channelType, status, message, channelResult } = res && res.result || {}
|
||||||
if (state === 0) {
|
if (status === 0) {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: '支付成功',
|
title: '支付成功',
|
||||||
icon: 'none',
|
icon: 'none',
|
||||||
@ -1108,6 +1108,8 @@ function changeMove(event) {
|
|||||||
.info {
|
.info {
|
||||||
display: flex;
|
display: flex;
|
||||||
font-size: 28rpx;
|
font-size: 28rpx;
|
||||||
|
max-height: 60vh;
|
||||||
|
overflow-y: auto;
|
||||||
|
|
||||||
.list {
|
.list {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
@ -571,7 +571,7 @@ const goOrder = async () => {
|
|||||||
payChannel: 'payByWeChat' // app微信支付
|
payChannel: 'payByWeChat' // app微信支付
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
const { channelType, status, message, channelResult } = res && res.result || {}
|
const { channelType, status, message, channelResult } = res && res.result || {}
|
||||||
if (state === 0) {
|
if (status === 0) {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: '支付成功',
|
title: '支付成功',
|
||||||
icon: 'none',
|
icon: 'none',
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
import { projectInfo,OFFICIAL_URL} from "@/config/index.js";
|
import { projectInfo,OFFICIAL_URL} from "@/config/index.js";
|
||||||
import i18n from '../locale/index';
|
import i18n from '../locale/index';
|
||||||
|
import { useLoginApi } from "@/Apis/login.js";
|
||||||
|
import { useMainStore } from "@/store/index.js";
|
||||||
|
const getApi = useLoginApi();
|
||||||
const { t } = i18n.global;
|
const { t } = i18n.global;
|
||||||
|
|
||||||
export const onTabItemTap = (event)=>{
|
export const onTabItemTap = (event)=>{
|
||||||
@ -256,17 +259,47 @@ export const parseUrlParams = (url) => {
|
|||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
// 顺丰参数
|
// 顺丰参数
|
||||||
export const shunfenLogin = (code) => {
|
export const shunfenLogin = async (code) => {
|
||||||
// 授权参数(请根据实际情况修改)
|
// 授权参数(请根据实际情况修改)
|
||||||
const authOptions = {
|
const authOptions = {
|
||||||
appId: "202603041358374970", // 第三方接入ID
|
appId: window?.config?.SF_APP_ID ??"202603041358374970", // 第三方接入ID
|
||||||
scope: ["sf_userinfo", "sf_mobile", "sf_base", "sf_emp", "sf_channelId"],
|
scope: ["sf_userinfo", "sf_mobile", "sf_base", "sf_emp", "sf_channelId"],
|
||||||
successUrl: window?.config?.BACK_URL ?? "https://uat.kingkongcang.com/client/", // 当前页面地址
|
successUrl: window?.config?.BACK_URL ?? "https://uat.kingkongcang.com/client/", // 当前页面地址
|
||||||
};
|
};
|
||||||
window.sf.getAuthCode({
|
window.sf.getAuthCode({
|
||||||
...authOptions,
|
...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);
|
console.log('getAuthCode success',res);
|
||||||
})
|
})
|
||||||
.catch((err) => console.log('getAuthCode err',err));
|
.catch((err) => console.log('getAuthCode err',err));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user