Commit 9cd08123 by jianan

feat(统一身份): CFFP H5 sso 登录态适配——票据通道落地与第三种登录方式贯通

- util/interceptor.ts:/sso/ticket/consume 加白名单;sso 模式下 custom.token 注入
  Casdoor 令牌;401/T001 走 sso 重登闭环(销毁 web-view 回原生重走票据)
- pages/lanch:isSsoMode+内存令牌在 → 按 landingPage 直达,不换 code、不建 HS 会话;
  锚点跳转函数抽出与 reLogin(HS) 链路共用
- 45 个业务页:登录判定 codelogin → !=visitor,使 loginType='sso' 被全站识别为已登录
  (web-view 回收重载后可凭 sso 标志交原生重走票据,绝不静默降级游客)
- 配套已提交:util/sso.ts + openWorkbench 接力(3cece355)、/pages/auth/ticket 落地页
parent 3cece355
......@@ -62,7 +62,7 @@
</view>
</view>
<view class="btnBox" @click="gotoApply">
{{loginType=='codelogin'?'确认加盟':'注册并加盟'}}
{{loginType!='visitor'?'确认加盟':'注册并加盟'}}
</view>
</view>
</view>
......@@ -164,17 +164,17 @@
this.checkToken()
}
// 非邀请状态
if (!this.shareId && this.loginType == 'codelogin' && this.userInfo.mobile) {
if (!this.shareId && this.loginType != 'visitor' && this.userInfo.mobile) {
this.form.mobile = this.userInfo.mobile
this.editMobile = true
this.showVerificationCode = false
}
// 非邀请状态
if (!this.shareId && this.loginType == 'codelogin' && !this.form.nickName) {
if (!this.shareId && this.loginType != 'visitor' && !this.form.nickName) {
this.queryInfo()
}
// 登录状态 非邀请
if (this.loginType == 'codelogin' && !this.shareId) {
if (this.loginType != 'visitor' && !this.shareId) {
// #ifdef H5
initJssdkShare(() => {
setWechatShare();
......@@ -233,7 +233,7 @@
this.loginType = 'visitor'
return
}
if (res.data.data.isPartner && this.loginType == 'codelogin') {
if (res.data.data.isPartner && this.loginType != 'visitor') {
this.$refs.successJoinPopup.open()
}
})
......@@ -306,7 +306,7 @@
}
console.log('this.sharePosterObj', this.sharePosterObj)
// 登录并且是禁用状态
if (this.loginType == 'codelogin' && this.userInfo.userIsActive == 2) {
if (this.loginType != 'visitor' && this.userInfo.userIsActive == 2) {
this.showCode = true
this.$refs.restrictedOrCanelTip.open('您的账号处在不可用状态,请扫码添加客服咨询情况')
return
......@@ -347,7 +347,7 @@
...this.form,
visitorUuid:uni.getStorageSync('visitorUuid')?uni.getStorageSync('visitorUuid'):dataHandling.uuid()
}
if (this.loginType == 'codelogin') {
if (this.loginType != 'visitor') {
this.getApply()
uni.hideLoading()
return
......
......@@ -103,7 +103,7 @@
onLoad(options){
},
onShow() {
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
this.queryInfo()
}
// #ifdef H5
......
......@@ -418,7 +418,7 @@
},
onShow() {
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
this.queryInfo()
}
// #ifdef H5
......
......@@ -58,7 +58,7 @@ export default {
}
},
onShow() {
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
this.queryInfo()
}
this.userInfo = JSON.parse(uni.getStorageSync('cffp_userInfo'))
......
......@@ -221,7 +221,7 @@ const queryInfo = () => {
});
};
onShow(()=>{
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
queryInfo()
}
})
......
......@@ -145,7 +145,7 @@ const fetchProducts = async (type=0) => {
}
}
onShow(()=>{
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
queryInfo()
}
})
......
......@@ -335,7 +335,7 @@ const queryInfo = () => {
});
};
onShow(()=>{
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
queryInfo()
}
})
......
......@@ -151,7 +151,7 @@ export default {
},
},
onShow(){
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
this.queryInfo()
}
// #ifdef H5
......
......@@ -306,7 +306,7 @@
this.isBack = options.isBack
},
onShow(){
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
this.queryInfo()
}
// #ifdef H5
......
......@@ -70,7 +70,7 @@
},
components:{restrictedTip,},
onShow(){
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
this.queryInfo()
}
// #ifdef H5
......
......@@ -171,7 +171,7 @@
this.userInfo = JSON.parse(uni.getStorageSync('cffp_userInfo'))
}
this.getSalaryData()
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
this.queryInfo()
}
// #ifdef H5
......
......@@ -103,7 +103,7 @@
},
onShow(){
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
this.queryInfo()
}
let dataForm = JSON.parse(uni.getStorageSync('cffp_userInfo'))
......
......@@ -592,6 +592,14 @@
"navigationBarTitleText": "启动页"
},
"lazyLoad": true
},
{
"path": "pages/auth/ticket",
"style": {
"topWindow": false,
"navigationBarTitleText": "登录中"
},
"lazyLoad": true
}
],
"subPackages": [
......
......@@ -179,7 +179,7 @@
this.userAfterSalesDtl()
},
onShow() {
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
this.queryInfo()
}
// #ifdef H5
......
......@@ -104,7 +104,7 @@
this.userAfterSales()
},
onShow() {
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
this.queryInfo()
}
// #ifdef H5
......
......@@ -257,7 +257,7 @@
this.dropOptionsQuery()
},
onShow() {
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
this.queryInfo()
}
this.userRefundCourseDtl();
......
......@@ -114,7 +114,7 @@
this.queryDate = option.queryDate;
},
onShow() {
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
this.queryInfo()
}
// #ifdef H5
......
......@@ -865,7 +865,7 @@
isSaveShare: '1', //是否存贮分享便于统计分享数据
fileId: this.fileId,
}
if (uni.getStorageSync('loginType') == 'codelogin') {
if (uni.getStorageSync('loginType') != 'visitor') {
shareInfo.userId = this.userId
newLink =
`${shareURL}/pages/lanch/index?fileId=${this.fileId}&coursesharing=1&serialsNo=${nanoid()}&shareCode=${shareCode}&shareUserId=${this.userId}&jumpUrl=${jumptime}&landingPage=courseDetail&miniShare=1`
......@@ -1510,7 +1510,7 @@
this.userInfo = JSON.parse(uni.getStorageSync('cffp_userInfo'))
}
this.userId = uni.getStorageSync('cffp_userId')
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
this.queryInfo()
}
// #ifdef H5
......
......@@ -244,7 +244,7 @@
this.userInfo = JSON.parse(uni.getStorageSync('cffp_userInfo'))
}
this.userId = uni.getStorageSync('cffp_userId')
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
this.queryInfo()
}
// #ifdef H5
......@@ -305,7 +305,7 @@
this.shareItem = JSON.parse(JSON.stringify(item))
// return
// 未登录去登录
if (uni.getStorageSync('loginType') !== 'codelogin') {
if (uni.getStorageSync('loginType') == 'visitor') {
dataHandling.pocessTracking(
'点击',
`用户在产品中心未登录时点击产品分享按钮`,
......
......@@ -200,7 +200,7 @@
this.isLoading = false
this.posterImg = ''
this.generatedImage = ''
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
this.queryInfo()
}
// #ifdef H5
......
......@@ -20,16 +20,22 @@
import * as environment from '@/environments/environment'
import dataHandling from "@/util/dataHandling";
import wx from 'weixin-js-sdk'
import * as sso from '@/util/sso'
import restrictedTip from '@/components/commonPopup/restrictedTip.vue';
let jumpInfo = ref({})
let dataToken = ref()
let restrictedTipRef = ref()
onLoad((options) => {
jumpInfo.value = JSON.parse(JSON.stringify(options))
if(options.backFlag){
uni.setStorageSync('backFlag',options.backFlag)
}
// Casdoor 票据通道:登录态已在内存,按 landingPage 直达,不换 code、不建 HS 会话
if (sso.isSsoMode() && sso.getSsoToken()) {
gotoLandingPage(options.landingPage || 'index')
return
}
// 参数带token了重新登录
if (options.dataToken) {
console.log('jumpInfo.value', jumpInfo.value);
......@@ -86,6 +92,56 @@
})
// 按 landingPage 锚点跳转:reLogin(HS code 登录)与 sso(Casdoor 票据)共用
const gotoLandingPage = (landingPage) => {
if (landingPage == 'sfpHousePurchase') {
uni.reLaunch({ url: `/sfp/housePurchase/housePurchase` })
} else if (landingPage == 'sfpIndex') {
uni.reLaunch({ url: `/sfp/index/index` })
} else if (landingPage == 'courseDetail') {
if(jumpInfo.value.noShare){
uni.reLaunch({ url: `/pages/courseDetail/courseDetail?fileId=${jumpInfo.value.fileId}&noShare=1`})
} else {
if(jumpInfo.value.shareUserId){
uni.reLaunch({ url: `/pages/courseDetail/courseDetail?fileId=${jumpInfo.value.fileId}&coursesharing=1&serialsNo=${jumpInfo.value.serialsNo}&shareCode=${jumpInfo.value.shareCode}&shareUserId=${jumpInfo.value.shareUserId}&jumpUrl=${jumpInfo.value.jumpUrl}&miniShare=1` })
}else {
uni.reLaunch({ url: `/pages/courseDetail/courseDetail?fileId=${jumpInfo.value.fileId}&miniShare=1` })
}
}
return
} else if (landingPage == 'businessCard') {
uni.reLaunch({ url: `/myPackageA/businessCard/businessCard?userId=${jumpInfo.value.userId}&isShareCard=1&cardId=${jumpInfo.value.cardId}&miniShare=1` })
} else if (landingPage == 'applyFranchise') {
uni.reLaunch({ url: `/myPackageA/applyFranchise/applyFranchise?shareId=${jumpInfo.value.shareId}&invitationCode=${jumpInfo.value.invitationCode}&inviteUserId=${jumpInfo.value.inviteUserId}&miniShare=1` })
}else if(landingPage == 'index'){
if(jumpInfo.value.miniShare){
uni.reLaunch({
url:'/pages/index/index?miniShare=1'
})
}else {
console.log('走到这里了');
uni.reLaunch({
url:'/pages/index/index'
})
}
}else if(landingPage == 'courselist'){
uni.reLaunch({
url:'/pages/courselist/courselist'
})
}else if(landingPage == 'personalCenter'){
uni.reLaunch({
url:'/pages/personalCenter/personalCenter'
})
}else if(landingPage == 'orderStatus'){
const userId = jumpInfo.value.userId || uni.getStorageSync('cffp_userId')
uni.reLaunch({
url:`/pages/orderStatus/orderStatus?orderId=${jumpInfo.value.orderId}&fileId=${jumpInfo.value.fileId}&orderStatus=2&userId=${userId}&backMySelf=1`
})
}
}
const reLogin = (landingPage) => {
uni.showLoading({
title: '加载中...'
......@@ -118,52 +174,7 @@
uni.setStorageSync('cffp_userId', res.data.userId);
uni.setStorageSync('uni-token', res.data['token']);
uni.setStorageSync('visitorUuid', res.data['visitorUuid']);
if (landingPage == 'sfpHousePurchase') {
uni.reLaunch({ url: `/sfp/housePurchase/housePurchase` })
} else if (landingPage == 'sfpIndex') {
uni.reLaunch({ url: `/sfp/index/index` })
} else if (landingPage == 'courseDetail') {
if(jumpInfo.value.noShare){
uni.reLaunch({ url: `/pages/courseDetail/courseDetail?fileId=${jumpInfo.value.fileId}&noShare=1`})
} else {
if(jumpInfo.value.shareUserId){
uni.reLaunch({ url: `/pages/courseDetail/courseDetail?fileId=${jumpInfo.value.fileId}&coursesharing=1&serialsNo=${jumpInfo.value.serialsNo}&shareCode=${jumpInfo.value.shareCode}&shareUserId=${jumpInfo.value.shareUserId}&jumpUrl=${jumpInfo.value.jumpUrl}&miniShare=1` })
}else {
uni.reLaunch({ url: `/pages/courseDetail/courseDetail?fileId=${jumpInfo.value.fileId}&miniShare=1` })
}
// uni.reLaunch({ url: `/pages/courseDetail/courseDetail?fileId=${jumpInfo.value.fileId}&coursesharing=1&serialsNo=${jumpInfo.value.serialsNo}&shareCode=${jumpInfo.value.shareCode}&shareUserId=${jumpInfo.value.shareUserId}&jumpUrl=${jumpInfo.value.jumpUrl}&miniShare=1` })
}
return
} else if (landingPage == 'businessCard') {
uni.reLaunch({ url: `/myPackageA/businessCard/businessCard?userId=${jumpInfo.value.userId}&isShareCard=1&cardId=${jumpInfo.value.cardId}&miniShare=1` })
} else if (landingPage == 'applyFranchise') {
uni.reLaunch({ url: `/myPackageA/applyFranchise/applyFranchise?shareId=${jumpInfo.value.shareId}&invitationCode=${jumpInfo.value.invitationCode}&inviteUserId=${jumpInfo.value.inviteUserId}&miniShare=1` })
}else if(landingPage == 'index'){
if(jumpInfo.value.miniShare){
uni.reLaunch({
url:'/pages/index/index?miniShare=1'
})
}else {
console.log('走到这里了');
uni.reLaunch({
url:'/pages/index/index'
})
}
}else if(landingPage == 'courselist'){
uni.reLaunch({
url:'/pages/courselist/courselist'
})
}else if(landingPage == 'personalCenter'){
uni.reLaunch({
url:'/pages/personalCenter/personalCenter'
})
}else if(landingPage == 'orderStatus'){
uni.reLaunch({
url:`/pages/orderStatus/orderStatus?orderId=${jumpInfo.value.orderId}&fileId=${jumpInfo.value.fileId}&orderStatus=2&userId=${res.data.userId}&backMySelf=1`
})
}
gotoLandingPage(landingPage)
} else {
//内嵌带的code失效了,用户需要重新登录
if(res.data.commonResult&&res.data.commonResult.errorCode=='1101'){
......
......@@ -265,7 +265,7 @@
this.userShareQuery();
},
onShow() {
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
this.queryInfo()
}
// #ifdef H5
......
......@@ -668,7 +668,7 @@
},
onShow() {
if (uni.getStorageSync('loginType') == 'codelogin') {
if (uni.getStorageSync('loginType') != 'visitor') {
this.queryInfo()
}
// #ifdef H5
......
......@@ -267,7 +267,7 @@
this.commissionType = option.commissionType;
},
onShow() {
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
this.queryInfo()
}
// #ifdef H5
......
......@@ -78,7 +78,7 @@
};
},
onShow() {
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
this.queryInfo()
}
// #ifdef H5
......
......@@ -68,7 +68,7 @@
}
},
onShow() {
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
this.queryInfo()
}
if(this.companyType == '1'){
......
......@@ -355,7 +355,7 @@
queryUserInfoAndPermission();
});
onShow(()=>{
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
queryInfo()
}
})
......
......@@ -74,7 +74,7 @@
}
},
onShow() {
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
this.queryInfo()
}
// #ifdef H5
......
......@@ -285,7 +285,7 @@
},
onShow() {
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
this.queryInfo()
}
// #ifdef H5
......
......@@ -212,7 +212,7 @@
this.getqueryTeamAchievement()
},
onShow() {
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
this.queryInfo()
}
// #ifdef H5
......
......@@ -55,7 +55,7 @@
}
},
onShow() {
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
this.queryInfo()
}
this.userInfo = JSON.parse(uni.getStorageSync('cffp_userInfo'))
......
......@@ -37,7 +37,7 @@
return {}
},
onShow() {
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
this.queryInfo()
}
// #ifdef H5
......
......@@ -26,6 +26,10 @@
import { initJssdkShare, setWechatShare } from '@/util/fiveshare';
import api from "@/api/api";
import restrictedTip from '@/components/commonPopup/restrictedTip.vue';
// #ifdef H5
import wx from 'weixin-js-sdk'
import * as sso from '@/util/sso'
// #endif
export default {
components:{ MenuList,restrictedTip, },
data() {
......@@ -59,7 +63,7 @@
}
},
onShow() {
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
this.queryInfo()
}
// #ifdef H5
......@@ -115,6 +119,23 @@
});
},
outLing(){
// #ifdef H5
// SSO(小程序票据)会话:销毁 web-view 回小程序原生;
// IdP(unionid)会话在原生侧,H5 登录页在小程序内不可用
if (sso.isSsoMode()) {
uni.showModal({
title: '退出登录',
content: '确定退出工作台吗?',
showCancel: true,
success: (res) => {
if (res.confirm) {
wx.miniProgram.reLaunch({ url: '/pages/index/mySelf' })
}
}
})
return
}
// #endif
uni.showModal({
title: '退出登录',
content: '确定要退出登录吗?',
......
......@@ -178,7 +178,7 @@
// this.optionForm = this.tempInfo.optionForm = JSON.parse(options.customerBasicInfo)
},
onShow() {
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
this.queryInfo()
}
// #ifdef H5
......
......@@ -186,7 +186,7 @@
this.queryByUserIdFortuneStatistic();
this.getCommissionType()
this.getDetail()
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
this.queryInfo()
}
// #ifdef H5
......
......@@ -79,7 +79,7 @@
restrictedTip
},
onShow() {
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
this.queryInfo()
}
// #ifdef H5
......
......@@ -297,7 +297,7 @@
let app22 = getCurrentPages().length
this.userCourseCount()
this.userCourseList()
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
this.queryInfo()
}
// #ifdef H5
......
......@@ -55,7 +55,7 @@
this.querySystemMessage();
},
onShow(){
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
this.queryInfo()
}
this.querySystemMessage();
......
......@@ -47,7 +47,7 @@
this.getSystemMsgDetail();
},
onShow() {
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
this.queryInfo()
}
// #ifdef H5
......
......@@ -72,7 +72,7 @@
}
},
onShow(){
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
this.queryInfo()
}
// #ifdef H5
......
......@@ -99,7 +99,7 @@
this.goFortuneWithdrawal()
},
onShow() {
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
this.queryInfo()
}
// #ifdef H5
......
......@@ -229,7 +229,7 @@
}
},
onShow() {
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
this.queryInfo()
}
// #ifdef H5
......
......@@ -116,7 +116,7 @@
this.calcuteData = uni.getStorageSync('calcuteData') ? JSON.parse(uni.getStorageSync('calcuteData')) : null;
},
onShow() {
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
this.queryInfo()
}
// #ifdef H5
......
......@@ -377,7 +377,7 @@
this.provCityQry();
},
onShow() {
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
this.queryInfo()
}
// #ifdef H5
......
......@@ -98,7 +98,7 @@
restrictedTip,
},
onShow() {
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
this.queryInfo()
}
// #ifdef H5
......
......@@ -65,7 +65,7 @@
restrictedTip,
},
onShow(){
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
this.queryInfo()
}
// #ifdef H5
......
......@@ -664,7 +664,7 @@
},
},
onShow() {
if(uni.getStorageSync('loginType')=='codelogin'){
if(uni.getStorageSync('loginType')!='visitor'){
this.queryInfo()
}
if(uni.getStorageSync('resIrrAndSimpleResInfos')){
......
......@@ -93,15 +93,16 @@
// };
// }
// });
// }
// 旧版的拦截器
// }
// 旧版的拦截器
import {apiURL,cffpURL,sfpUrl} from "../environments/environment";
import api from "@/api/api";
import * as sso from "@/util/sso";
// 白名单,不需要携带token就允许被访问的接口
const whiteApiList = [`${apiURL}/authorize/obtainToken`,
`${apiURL}/authorize/checkToken`,
const whiteApiList = [`${apiURL}/authorize/obtainToken`,
`${apiURL}/authorize/checkToken`,
`${cffpURL}/user/loginVerification`,
`${apiURL}/appVersion/checkIsUpdate`,
`${cffpURL}/accessLog/accessLogSave`,
......@@ -110,12 +111,34 @@ const whiteApiList = [`${apiURL}/authorize/obtainToken`,
`${apiURL}/verificationCode`,
`${sfpUrl}/sfp/sfpMain/pocessTracking`,
`${cffpURL}/partner/queryById`,
`${apiURL}/sso/ticket/consume`, // Casdoor 票据消费:匿名,唯一凭据是 ticket
];
export const interceptor = () => {
uni.addInterceptor('request', {
// 请求拦截器
invoke(args) {
invoke(args) {
// alert(JSON.stringify(args))
// Casdoor SSO 匿名端点(票据消费带 query,精确白名单匹配不上,按前缀放行)
if (typeof args.url === 'string' && args.url.indexOf('/sso/') !== -1) {
args.header = {
'content-type': args.method === 'POST' ? 'application/json' : 'application/x-www-form-urlencoded',
}
return
}
// Casdoor 票据通道(小程序 web-view):令牌只在内存,绝不走 obtainToken 游客降级
if (sso.isSsoMode()) {
const ssoToken = sso.getSsoToken()
if (!ssoToken) {
// 会话应在但内存令牌丢失(web-view 被系统回收后重载业务页):交原生重走票据,拦掉本次无令牌请求
sso.reloginViaMiniprogram()
return
}
args.header = {
'content-type': args.method === 'POST' ? 'application/json' : 'application/x-www-form-urlencoded',
'X-Authorization': ssoToken,
}
return
}
// 当本地没有token,并且接口地址没在白名单内,需要重新获取token
if (!uni.getStorageSync('uni-token') && !whiteApiList.includes(args.url)) {
......@@ -153,9 +176,19 @@ export const interceptor = () => {
},
// 响应拦截器,可以对数据进行预处理
success(args) {
if(args && args.data && args.data.errorCode && "T001"==args.data.errorCode){
const bodyT001 = args && args.data && args.data.errorCode && "T001" == args.data.errorCode
// Casdoor 分支失败:sso 模式接受纯 HTTP 401;非 sso 模式严格维持老条件(仅 body T001),行为不变
const unauthorized = sso.isSsoMode()
? (bodyT001 || args.statusCode === 401)
: bodyT001
if(unauthorized){
if (sso.isSsoMode()) {
// 不回 H5 首页/登录页:销毁 web-view,原生强制重走 wx.login→票据
sso.reloginViaMiniprogram()
return
}
uni.removeStorageSync('isLogin');
uni.removeStorageSync('uni-token');
uni.removeStorageSync('uni-token');
uni.setStorageSync('loginType','visitor')
uni.switchTab({
url:'/pages/index/index'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment