mirror of
https://gitee.com/liuxioabin/fengketrade.git
synced 2026-04-17 21:03:17 +08:00
'登录调试'
This commit is contained in:
parent
037ada5e61
commit
eaa7c7ba55
211
frontend/App.vue
211
frontend/App.vue
@ -7,20 +7,51 @@
|
||||
let isLoggingIn = false;
|
||||
|
||||
onLaunch(() => {
|
||||
console.log('[App] 应用启动...');
|
||||
|
||||
// 隐藏原生导航栏 使用自定义底部导航
|
||||
uni.hideTabBar({
|
||||
fail: () => {},
|
||||
});
|
||||
|
||||
// 初始化移动端调试控制台(仅H5环境)
|
||||
// #ifdef H5
|
||||
initVConsole();
|
||||
// #endif
|
||||
|
||||
// 加载Shopro底层依赖
|
||||
ShoproInit();
|
||||
|
||||
// 检测建行生活登录参数
|
||||
checkCCBLogin();
|
||||
|
||||
// 启动 JSBridge 监控(每10秒打印一次)
|
||||
// #ifdef H5
|
||||
startJSBridgeMonitor();
|
||||
// #endif
|
||||
});
|
||||
|
||||
/**
|
||||
* 初始化 vConsole 移动端调试控制台
|
||||
* 在H5环境下提供类似Chrome DevTools的功能
|
||||
*/
|
||||
const initVConsole = () => {
|
||||
// 动态导入vConsole,避免打包到非H5平台
|
||||
import('vconsole')
|
||||
.then((module) => {
|
||||
const VConsole = module.default;
|
||||
const vConsole = new VConsole({
|
||||
defaultPlugins: ['system', 'network', 'element', 'storage'],
|
||||
maxLogNumber: 1000,
|
||||
disableLogScrolling: false,
|
||||
});
|
||||
|
||||
// 保存实例供后续使用
|
||||
window.vConsole = vConsole;
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('[App] vConsole加载失败:', err);
|
||||
});
|
||||
};
|
||||
|
||||
onError((err) => {
|
||||
console.log('AppOnError:', err);
|
||||
});
|
||||
@ -39,10 +70,63 @@
|
||||
// #endif
|
||||
});
|
||||
|
||||
/**
|
||||
* JSBridge 注入情况监控
|
||||
* 每10秒打印一次所有建行相关 JSBridge 对象的状态,打印15次后自动停止
|
||||
*/
|
||||
const startJSBridgeMonitor = () => {
|
||||
let count = 0;
|
||||
const maxCount = 15;
|
||||
|
||||
// 立即执行一次
|
||||
printJSBridgeStatus(++count, maxCount);
|
||||
|
||||
// 每10秒执行一次
|
||||
const timer = setInterval(() => {
|
||||
printJSBridgeStatus(++count, maxCount);
|
||||
|
||||
// 达到15次后清除定时器
|
||||
if (count >= maxCount) {
|
||||
clearInterval(timer);
|
||||
console.log('[JSBridge] 监控已停止(已打印15次)');
|
||||
}
|
||||
}, 10000);
|
||||
};
|
||||
|
||||
/**
|
||||
* 打印 JSBridge 注入状态(精简版)
|
||||
*/
|
||||
const printJSBridgeStatus = (count, maxCount) => {
|
||||
const timestamp = new Date().toLocaleTimeString('zh-CN', { hour12: false });
|
||||
const isIOS = /iPhone|iPad|iPod/i.test(navigator.userAgent);
|
||||
const isAndroid = /Android/i.test(navigator.userAgent);
|
||||
|
||||
// 检测各个 Bridge 对象
|
||||
const hasMbspay =
|
||||
typeof window.mbspay !== 'undefined' && typeof window.mbspay.directpay === 'function';
|
||||
const hasCCBBridge = typeof window.CCBBridge !== 'undefined';
|
||||
const hasWebViewBridge = typeof window.WebViewJavascriptBridge !== 'undefined';
|
||||
const hasAnyBridge = hasMbspay || hasCCBBridge || hasWebViewBridge;
|
||||
|
||||
// 支付能力
|
||||
const canPay = isIOS || (isAndroid && hasMbspay);
|
||||
|
||||
// 一行输出所有状态(包含计数)
|
||||
console.log(
|
||||
`[JSBridge ${timestamp}] (${count}/${maxCount}) ` +
|
||||
`设备:${isIOS ? 'iOS' : isAndroid ? 'Android' : 'PC'} | ` +
|
||||
`mbspay:${hasMbspay ? '✅' : '❌'} | ` +
|
||||
`CCBBridge:${hasCCBBridge ? '✅' : '❌'} | ` +
|
||||
`WebViewBridge:${hasWebViewBridge ? '✅' : '❌'} | ` +
|
||||
`支付能力:${canPay ? '✅' : '❌'} | ` +
|
||||
`Bridge状态:${hasAnyBridge ? '✅就绪' : '❌未就绪'}`,
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* 检测URL中的建行登录参数并自动登录
|
||||
* 建行跳转URL格式:url?platform=ccblife&channel=mbs&ccbParamSJ=xxx&CITYID=330100&USERCITYID=440100
|
||||
*
|
||||
*
|
||||
* 逻辑:
|
||||
* 1. 解析URL参数获取ccbParamSJ
|
||||
* 2. 与本地存储的lastCcbParamSJ比较
|
||||
@ -51,22 +135,17 @@
|
||||
*/
|
||||
const checkCCBLogin = () => {
|
||||
// #ifdef H5
|
||||
console.log('[App] ========== 开始检测建行登录参数 ==========');
|
||||
console.log('[App] 完整URL:', window.location.href);
|
||||
console.log('[App] search:', window.location.search);
|
||||
|
||||
try {
|
||||
let ccbParamSJ = null;
|
||||
let platform = null;
|
||||
let cityid = null;
|
||||
|
||||
// 优先从search中提取参数(建行标准格式:url?platform=ccblife&ccbParamSJ=xxx)
|
||||
// 优先从search中提取参数(建行标准格式:url?ccbParamSJ=xxx&CITYID=xxx)
|
||||
if (window.location.search) {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
ccbParamSJ = urlParams.get('ccbParamSJ');
|
||||
platform = urlParams.get('platform');
|
||||
platform = urlParams.get('platform') || 'ccblife';
|
||||
cityid = urlParams.get('CITYID') || urlParams.get('cityid');
|
||||
console.log('[App] 从search中解析参数');
|
||||
}
|
||||
|
||||
// 备用:从hash中提取参数(UniApp内部跳转可能使用)
|
||||
@ -75,156 +154,107 @@
|
||||
if (hashParts.length > 1) {
|
||||
const hashParams = new URLSearchParams(hashParts[1]);
|
||||
ccbParamSJ = hashParams.get('ccbParamSJ');
|
||||
platform = hashParams.get('platform');
|
||||
platform = hashParams.get('platform') || 'ccblife';
|
||||
cityid = hashParams.get('CITYID') || hashParams.get('cityid');
|
||||
console.log('[App] 从hash中解析参数');
|
||||
}
|
||||
}
|
||||
|
||||
console.log('[App] ====== 参数解析结果 ======');
|
||||
console.log('[App] platform:', platform);
|
||||
console.log('[App] CITYID:', cityid);
|
||||
console.log('[App] 当前ccbParamSJ:', ccbParamSJ ? ccbParamSJ.substring(0, 50) + '...' : 'null');
|
||||
|
||||
// 获取上次保存的ccbParamSJ
|
||||
const lastCcbParamSJ = uni.getStorageSync('lastCcbParamSJ') || null;
|
||||
console.log('[App] 上次ccbParamSJ:', lastCcbParamSJ ? lastCcbParamSJ.substring(0, 50) + '...' : 'null');
|
||||
|
||||
// 判断参数是否变化
|
||||
const isParamChanged = ccbParamSJ && (lastCcbParamSJ !== ccbParamSJ);
|
||||
const isFirstTime = ccbParamSJ && !lastCcbParamSJ;
|
||||
|
||||
console.log('[App] 是否首次登录:', isFirstTime);
|
||||
console.log('[App] 参数是否变化:', isParamChanged);
|
||||
console.log('[App] ===========================');
|
||||
|
||||
// 如果有建行参数
|
||||
if (ccbParamSJ && platform === 'ccblife') {
|
||||
|
||||
// 判断参数是否变化
|
||||
const isParamChanged = ccbParamSJ && lastCcbParamSJ !== ccbParamSJ;
|
||||
const isFirstTime = ccbParamSJ && !lastCcbParamSJ;
|
||||
|
||||
// 如果有建行参数(固定建行生活环境,只要有ccbParamSJ就执行登录)
|
||||
if (ccbParamSJ) {
|
||||
// 如果参数未变化,无需重新登录
|
||||
if (!isParamChanged && !isFirstTime) {
|
||||
console.log('[App] ℹ️ ccbParamSJ未变化,无需重新登录,跳过');
|
||||
// 清除URL参数
|
||||
const cleanUrl = window.location.origin + window.location.pathname + '#/pages/index/index';
|
||||
console.log('[CCB] 参数未变化,跳过登录');
|
||||
const cleanUrl = window.location.origin + '/pages/index/index';
|
||||
window.history.replaceState({}, '', cleanUrl);
|
||||
console.log('[App] ========== 检测完成 ==========');
|
||||
return;
|
||||
}
|
||||
|
||||
// 参数变化了,需要切换用户
|
||||
if (isParamChanged) {
|
||||
console.log('[App] 🔄🔄🔄 检测到ccbParamSJ变化,需要切换用户!');
|
||||
} else {
|
||||
console.log('[App] 🆕 首次登录');
|
||||
}
|
||||
|
||||
// 🔒 防止重复调用:检查是否正在登录中
|
||||
if (isLoggingIn) {
|
||||
console.log('[App] ⚠️ 已有登录流程正在执行,跳过重复调用');
|
||||
return;
|
||||
}
|
||||
|
||||
// 设置登录中标志
|
||||
console.log(`[CCB] ${isParamChanged ? '切换用户' : '首次登录'}`);
|
||||
|
||||
// 防止重复调用
|
||||
if (isLoggingIn) {
|
||||
console.log('[CCB] 登录进行中,跳过');
|
||||
return;
|
||||
}
|
||||
|
||||
isLoggingIn = true;
|
||||
console.log('[App] 🔒 设置登录锁定标志');
|
||||
|
||||
|
||||
// 延迟执行登录,确保依赖已初始化
|
||||
setTimeout(async () => {
|
||||
try {
|
||||
console.log('[App] 开始执行登录流程...');
|
||||
|
||||
// 如果是切换用户,先退出当前用户
|
||||
const userStore = sheep.$store('user');
|
||||
if (isParamChanged && userStore && userStore.isLogin) {
|
||||
console.log('[App] 退出当前用户,准备切换...');
|
||||
await userStore.logout();
|
||||
uni.removeStorageSync('token');
|
||||
uni.removeStorageSync('userInfo');
|
||||
console.log('[App] 当前用户已退出');
|
||||
}
|
||||
|
||||
// 显示loading
|
||||
const loadingTitle = isParamChanged ? '切换用户中...' : '建行登录中...';
|
||||
uni.showLoading({
|
||||
title: loadingTitle,
|
||||
mask: true
|
||||
});
|
||||
|
||||
// 调用建行登录API(只传三个参数)
|
||||
console.log('[App] 调用登录API,参数:', {
|
||||
ccbParamSJ: ccbParamSJ.substring(0, 30) + '...',
|
||||
cityid: cityid || '360100',
|
||||
CITYID: cityid || '360100'
|
||||
mask: true,
|
||||
});
|
||||
|
||||
// 调用建行登录API
|
||||
const result = await sheep.$api.third.ccbLogin({
|
||||
ccbParamSJ: ccbParamSJ,
|
||||
cityid: cityid || '360100',
|
||||
CITYID: cityid || '360100'
|
||||
CITYID: cityid || '360100',
|
||||
});
|
||||
|
||||
console.log('[App] 登录API返回:', result);
|
||||
|
||||
uni.hideLoading();
|
||||
|
||||
if (result.code === 1) {
|
||||
console.log('[App] ✅✅✅ 建行登录成功!');
|
||||
console.log('[App] Token:', result.data.token?.substring(0, 20) + '...');
|
||||
console.log('[App] 用户信息:', result.data.user_info);
|
||||
console.log('[CCB] 登录成功');
|
||||
|
||||
// 设置token和用户信息
|
||||
sheep.$store('user').setToken(result.data.token);
|
||||
uni.setStorageSync('userInfo', result.data.user_info);
|
||||
|
||||
// 🔑 关键:保存当前的ccbParamSJ到本地存储
|
||||
uni.setStorageSync('lastCcbParamSJ', ccbParamSJ);
|
||||
console.log('[App] ✅ 已保存ccbParamSJ到本地存储');
|
||||
|
||||
// 显示欢迎提示
|
||||
uni.showToast({
|
||||
title: `登录成功`,
|
||||
icon: 'success',
|
||||
duration: 2000
|
||||
duration: 2000,
|
||||
});
|
||||
|
||||
// 清除URL中的敏感参数,保留干净的URL
|
||||
const cleanUrl = window.location.origin + window.location.pathname + '#/pages/index/index';
|
||||
// 清除URL中的敏感参数
|
||||
const cleanUrl = window.location.origin + '/pages/index/index';
|
||||
window.history.replaceState({}, '', cleanUrl);
|
||||
console.log('[App] URL参数已清除');
|
||||
|
||||
} else {
|
||||
throw new Error(result.msg || '登录失败');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[App] ❌❌❌ 建行登录失败:', error);
|
||||
console.error('[CCB] 登录失败:', error.message || error.msg);
|
||||
uni.hideLoading();
|
||||
|
||||
|
||||
uni.showModal({
|
||||
title: isParamChanged ? '切换用户失败' : '登录失败',
|
||||
content: error.message || error.msg || '请检查网络连接',
|
||||
showCancel: false,
|
||||
complete: () => {
|
||||
// 登录失败后也清除URL参数
|
||||
const cleanUrl = window.location.origin + window.location.pathname + '#/pages/index/index';
|
||||
const cleanUrl = window.location.origin + '/pages/index/index';
|
||||
window.history.replaceState({}, '', cleanUrl);
|
||||
}
|
||||
},
|
||||
});
|
||||
} finally {
|
||||
// 🔓 无论成功失败,都释放登录锁
|
||||
isLoggingIn = false;
|
||||
console.log('[App] 🔓 释放登录锁定标志');
|
||||
}
|
||||
}, 1200); // 延迟1200ms,确保Shopro和API已加载完成
|
||||
} else {
|
||||
console.log('[App] ℹ️ 未检测到建行登录参数');
|
||||
if (ccbParamSJ && platform !== 'ccblife') {
|
||||
console.warn('[App] ⚠️ 发现ccbParamSJ但platform不是ccblife:', platform);
|
||||
}
|
||||
}, 1200);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[App] ❌ 参数解析错误:', error);
|
||||
console.error('[CCB] 参数解析错误:', error);
|
||||
}
|
||||
console.log('[App] ========== 检测完成 ==========');
|
||||
// #endif
|
||||
};
|
||||
</script>
|
||||
@ -232,4 +262,3 @@
|
||||
<style lang="scss">
|
||||
@import '@/sheep/scss/index.scss';
|
||||
</style>
|
||||
|
||||
|
||||
@ -199,8 +199,8 @@
|
||||
"h5" : {
|
||||
"template" : "index.html",
|
||||
"router" : {
|
||||
"mode" : "hash",
|
||||
"base" : "./"
|
||||
"mode" : "history",
|
||||
"base" : "/"
|
||||
},
|
||||
"sdkConfigs" : {
|
||||
"maps" : {}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
<template>
|
||||
<!-- 建行生活环境自动隐藏导航栏(建行APP自带页头) -->
|
||||
<s-layout title="建行生活" :bgStyle="{ color: 'rgb(245,28,19)' }">
|
||||
<!-- 顶部banner -->
|
||||
<view class="ccb-banner">
|
||||
|
||||
@ -93,7 +93,8 @@
|
||||
<view class="copyright-text ss-m-b-10">{{ appInfo.copyright }}</view>
|
||||
<view class="copyright-text">{{ appInfo.copytime }}</view>
|
||||
</view>
|
||||
<su-fixed bottom placeholder>
|
||||
<!-- 退出登录按钮已暂时隐藏 -->
|
||||
<su-fixed bottom placeholder v-if="false">
|
||||
<view class="ss-p-x-20 ss-p-b-40">
|
||||
<button
|
||||
class="loginout-btn ss-reset-button ui-BG-Main ui-Shadow-Main"
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
<view class="page-main" :style="[bgMain]">
|
||||
<!-- 默认通用顶部导航栏 -->
|
||||
<su-navbar
|
||||
v-if="navbar === 'normal'"
|
||||
v-if="actualNavbar === 'normal'"
|
||||
:title="title"
|
||||
statusBar
|
||||
:color="color"
|
||||
@ -18,21 +18,21 @@
|
||||
|
||||
<!-- 装修组件导航栏-普通 -->
|
||||
<s-custom-navbar
|
||||
v-else-if="navbar === 'custom' && navbarMode === 'normal'"
|
||||
v-else-if="actualNavbar === 'custom' && navbarMode === 'normal'"
|
||||
:data="navbarStyle"
|
||||
:showLeftButton="showLeftButton"
|
||||
/>
|
||||
<view class="page-body" :style="[bgBody]">
|
||||
<!-- 沉浸式头部 -->
|
||||
<su-inner-navbar v-if="navbar === 'inner'" :title="title" />
|
||||
<su-inner-navbar v-if="actualNavbar === 'inner'" :title="title" />
|
||||
<view
|
||||
v-if="navbar === 'inner'"
|
||||
v-if="actualNavbar === 'inner'"
|
||||
:style="[{ paddingTop: sheep.$platform.navbar + 'px' }]"
|
||||
></view>
|
||||
|
||||
<!-- 装修组件导航栏-沉浸式 -->
|
||||
<s-custom-navbar
|
||||
v-if="navbar === 'custom' && navbarMode === 'inner'"
|
||||
v-if="actualNavbar === 'custom' && navbarMode === 'inner'"
|
||||
:data="navbarStyle"
|
||||
:showLeftButton="showLeftButton"
|
||||
/>
|
||||
@ -80,6 +80,11 @@
|
||||
type: String,
|
||||
default: 'normal',
|
||||
},
|
||||
// 是否在建行生活环境中隐藏导航栏
|
||||
hideNavbarInCcb: {
|
||||
type: Boolean,
|
||||
default: true, // 默认在建行生活环境隐藏导航栏
|
||||
},
|
||||
opacityBgUi: {
|
||||
type: String,
|
||||
default: 'bg-white',
|
||||
@ -153,9 +158,40 @@
|
||||
const modalStore = sheep.$store('modal');
|
||||
const sys = computed(() => sysStore);
|
||||
|
||||
// 检测是否在建行生活环境
|
||||
const isInCcbLife = computed(() => {
|
||||
// #ifdef H5
|
||||
const result = sheep.$platform.provider === 'ccb' || sheep.$platform.name === 'CcbLife';
|
||||
console.log('[s-layout] 建行生活环境检测:', {
|
||||
provider: sheep.$platform.provider,
|
||||
name: sheep.$platform.name,
|
||||
isInCcbLife: result
|
||||
});
|
||||
return result;
|
||||
// #endif
|
||||
// #ifndef H5
|
||||
return false;
|
||||
// #endif
|
||||
});
|
||||
|
||||
// 计算实际的navbar值(建行生活环境下可能需要隐藏)
|
||||
const actualNavbar = computed(() => {
|
||||
// 全局隐藏导航栏
|
||||
console.log('[s-layout] 导航栏已全局隐藏');
|
||||
return '';
|
||||
|
||||
// 如果在建行生活环境且允许隐藏,则返回空字符串隐藏导航栏
|
||||
// if (isInCcbLife.value && props.hideNavbarInCcb) {
|
||||
// console.log('[s-layout] 建行生活环境:隐藏导航栏');
|
||||
// return '';
|
||||
// }
|
||||
// console.log('[s-layout] 使用导航栏:', props.navbar);
|
||||
// return props.navbar;
|
||||
});
|
||||
|
||||
// 导航栏模式(因为有自定义导航栏 需要计算)
|
||||
const navbarMode = computed(() => {
|
||||
if (props.navbar === 'normal' || props.navbarStyle.mode === 'normal') {
|
||||
if (actualNavbar.value === 'normal' || props.navbarStyle.mode === 'normal') {
|
||||
return 'normal';
|
||||
}
|
||||
return 'inner';
|
||||
|
||||
@ -28,9 +28,10 @@
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 绑定手机号提示已隐藏 -->
|
||||
<view
|
||||
class="bind-mobile-box ss-flex ss-row-between ss-col-center"
|
||||
v-if="isLogin && !userInfo.verification?.mobile"
|
||||
v-if="false"
|
||||
>
|
||||
<view class="ss-flex">
|
||||
<text class="cicon-mobile-o"></text>
|
||||
|
||||
@ -29,14 +29,14 @@ const CcbLifePlatform = {
|
||||
// 是否在建行生活环境中
|
||||
isInCcbApp: false,
|
||||
|
||||
// JSBridge 对象
|
||||
bridge: null,
|
||||
// JSBridge 对象(已禁用)
|
||||
// bridge: null,
|
||||
|
||||
// 就绪状态
|
||||
isReady: false,
|
||||
// 就绪状态(已禁用)
|
||||
// isReady: false,
|
||||
|
||||
// 就绪回调队列
|
||||
readyCallbacks: [],
|
||||
// 就绪回调队列(已禁用)
|
||||
// readyCallbacks: [],
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
@ -45,12 +45,10 @@ const CcbLifePlatform = {
|
||||
// 检测环境
|
||||
this.detectEnvironment();
|
||||
|
||||
// 如果在建行App内,初始化JSBridge
|
||||
if (this.isInCcbApp) {
|
||||
this.setupBridge();
|
||||
// ⚠️ 自动登录已禁用,改用App.vue中的checkCCBLogin统一处理
|
||||
// this.autoLogin();
|
||||
}
|
||||
// ⚠️ JSBridge 已禁用,目前不需要
|
||||
// if (this.isInCcbApp) {
|
||||
// this.setupBridge();
|
||||
// }
|
||||
|
||||
console.log('[CcbLife] 初始化完成, 是否在建行App内:', this.isInCcbApp);
|
||||
},
|
||||
@ -75,11 +73,11 @@ const CcbLifePlatform = {
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查JSBridge
|
||||
if (window.WebViewJavascriptBridge || window.mbspay) {
|
||||
this.isInCcbApp = true;
|
||||
return;
|
||||
}
|
||||
// ⚠️ 已移除 JSBridge 检查(目前不需要)
|
||||
// if (window.WebViewJavascriptBridge || window.mbspay) {
|
||||
// this.isInCcbApp = true;
|
||||
// return;
|
||||
// }
|
||||
// #endif
|
||||
|
||||
// #ifdef APP-PLUS
|
||||
@ -94,104 +92,83 @@ const CcbLifePlatform = {
|
||||
},
|
||||
|
||||
/**
|
||||
* 设置JSBridge
|
||||
* 设置JSBridge(已禁用 - 目前不需要)
|
||||
*/
|
||||
setupBridge() {
|
||||
// #ifdef H5
|
||||
const self = this;
|
||||
let bridgeCheckCount = 0;
|
||||
const MAX_BRIDGE_CHECK = 20; // 最多检查20次
|
||||
const BRIDGE_CHECK_INTERVAL = 500; // 每500ms检查一次,总共10秒
|
||||
|
||||
// iOS WebViewJavascriptBridge
|
||||
if (window.WebViewJavascriptBridge) {
|
||||
self.bridge = window.WebViewJavascriptBridge;
|
||||
self.onBridgeReady();
|
||||
return;
|
||||
}
|
||||
|
||||
// 监听iOS Bridge就绪事件
|
||||
document.addEventListener('WebViewJavascriptBridgeReady', function() {
|
||||
self.bridge = window.WebViewJavascriptBridge;
|
||||
self.onBridgeReady();
|
||||
}, false);
|
||||
|
||||
// Android 直接通过window对象
|
||||
if (window.mbspay) {
|
||||
self.bridge = window.mbspay;
|
||||
self.onBridgeReady();
|
||||
return;
|
||||
}
|
||||
|
||||
// 轮询检查Bridge是否已加载(建行App可能需要时间初始化)
|
||||
const bridgeCheckInterval = setInterval(() => {
|
||||
bridgeCheckCount++;
|
||||
|
||||
// 检查iOS Bridge
|
||||
if (window.WebViewJavascriptBridge && !self.isReady) {
|
||||
clearInterval(bridgeCheckInterval);
|
||||
self.bridge = window.WebViewJavascriptBridge;
|
||||
self.onBridgeReady();
|
||||
console.log(`[CcbLife] iOS Bridge 已就绪(检查${bridgeCheckCount}次)`);
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查Android Bridge
|
||||
if (window.mbspay && !self.isReady) {
|
||||
clearInterval(bridgeCheckInterval);
|
||||
self.bridge = window.mbspay;
|
||||
self.onBridgeReady();
|
||||
console.log(`[CcbLife] Android Bridge 已就绪(检查${bridgeCheckCount}次)`);
|
||||
return;
|
||||
}
|
||||
|
||||
// 达到最大检查次数
|
||||
if (bridgeCheckCount >= MAX_BRIDGE_CHECK) {
|
||||
clearInterval(bridgeCheckInterval);
|
||||
console.error('[CcbLife] ⚠️ JSBridge 初始化超时,建行功能可能不可用');
|
||||
|
||||
// 显示提示
|
||||
if (self.isInCcbApp) {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '建行环境初始化失败,部分功能可能无法使用。建议重新打开页面。',
|
||||
showCancel: true,
|
||||
cancelText: '关闭',
|
||||
confirmText: '重新加载',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
location.reload();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}, BRIDGE_CHECK_INTERVAL);
|
||||
// #endif
|
||||
},
|
||||
// setupBridge() {
|
||||
// // #ifdef H5
|
||||
// const self = this;
|
||||
// let bridgeCheckCount = 0;
|
||||
// const MAX_BRIDGE_CHECK = 20;
|
||||
// const BRIDGE_CHECK_INTERVAL = 500;
|
||||
//
|
||||
// // iOS WebViewJavascriptBridge
|
||||
// if (window.WebViewJavascriptBridge) {
|
||||
// self.bridge = window.WebViewJavascriptBridge;
|
||||
// self.onBridgeReady();
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// // 监听iOS Bridge就绪事件
|
||||
// document.addEventListener('WebViewJavascriptBridgeReady', function() {
|
||||
// self.bridge = window.WebViewJavascriptBridge;
|
||||
// self.onBridgeReady();
|
||||
// }, false);
|
||||
//
|
||||
// // Android 直接通过window对象
|
||||
// if (window.mbspay) {
|
||||
// self.bridge = window.mbspay;
|
||||
// self.onBridgeReady();
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// // 轮询检查Bridge是否已加载
|
||||
// const bridgeCheckInterval = setInterval(() => {
|
||||
// bridgeCheckCount++;
|
||||
//
|
||||
// if (window.WebViewJavascriptBridge && !self.isReady) {
|
||||
// clearInterval(bridgeCheckInterval);
|
||||
// self.bridge = window.WebViewJavascriptBridge;
|
||||
// self.onBridgeReady();
|
||||
// console.log(`[CcbLife] iOS Bridge 已就绪(检查${bridgeCheckCount}次)`);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// if (window.mbspay && !self.isReady) {
|
||||
// clearInterval(bridgeCheckInterval);
|
||||
// self.bridge = window.mbspay;
|
||||
// self.onBridgeReady();
|
||||
// console.log(`[CcbLife] Android Bridge 已就绪(检查${bridgeCheckCount}次)`);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// if (bridgeCheckCount >= MAX_BRIDGE_CHECK) {
|
||||
// clearInterval(bridgeCheckInterval);
|
||||
// console.error('[CcbLife] ⚠️ JSBridge 初始化超时');
|
||||
// }
|
||||
// }, BRIDGE_CHECK_INTERVAL);
|
||||
// // #endif
|
||||
// },
|
||||
|
||||
/**
|
||||
* Bridge就绪回调
|
||||
* Bridge就绪回调(已禁用)
|
||||
*/
|
||||
onBridgeReady() {
|
||||
this.isReady = true;
|
||||
console.log('[CcbLife] JSBridge 已就绪');
|
||||
|
||||
// 执行所有等待的回调
|
||||
this.readyCallbacks.forEach(callback => callback());
|
||||
this.readyCallbacks = [];
|
||||
},
|
||||
// onBridgeReady() {
|
||||
// this.isReady = true;
|
||||
// console.log('[CcbLife] JSBridge 已就绪');
|
||||
// this.readyCallbacks.forEach(callback => callback());
|
||||
// this.readyCallbacks = [];
|
||||
// },
|
||||
|
||||
/**
|
||||
* 等待Bridge就绪
|
||||
* 等待Bridge就绪(已禁用)
|
||||
*/
|
||||
ready(callback) {
|
||||
if (this.isReady) {
|
||||
callback();
|
||||
} else {
|
||||
this.readyCallbacks.push(callback);
|
||||
}
|
||||
},
|
||||
// ready(callback) {
|
||||
// if (this.isReady) {
|
||||
// callback();
|
||||
// } else {
|
||||
// this.readyCallbacks.push(callback);
|
||||
// }
|
||||
// },
|
||||
|
||||
/**
|
||||
* 获取URL参数
|
||||
@ -214,266 +191,238 @@ const CcbLifePlatform = {
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取建行用户信息
|
||||
* 获取建行用户信息(已禁用 - 依赖JSBridge)
|
||||
*/
|
||||
async getUserInfo() {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!this.isInCcbApp) {
|
||||
reject({
|
||||
code: -1,
|
||||
msg: '不在建行生活App内'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
this.ready(() => {
|
||||
this.callNative('getUserInfo', {}, (result) => {
|
||||
if (result && result.userid) {
|
||||
resolve({
|
||||
code: 0,
|
||||
data: {
|
||||
ccb_user_id: result.userid,
|
||||
mobile: result.mobile || '',
|
||||
nickname: result.nickname || '',
|
||||
avatar: result.avatar || ''
|
||||
}
|
||||
});
|
||||
} else {
|
||||
reject({
|
||||
code: -1,
|
||||
msg: '获取用户信息失败'
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
// async getUserInfo() {
|
||||
// return new Promise((resolve, reject) => {
|
||||
// if (!this.isInCcbApp) {
|
||||
// reject({
|
||||
// code: -1,
|
||||
// msg: '不在建行生活App内'
|
||||
// });
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// this.ready(() => {
|
||||
// this.callNative('getUserInfo', {}, (result) => {
|
||||
// if (result && result.userid) {
|
||||
// resolve({
|
||||
// code: 0,
|
||||
// data: {
|
||||
// ccb_user_id: result.userid,
|
||||
// mobile: result.mobile || '',
|
||||
// nickname: result.nickname || '',
|
||||
// avatar: result.avatar || ''
|
||||
// }
|
||||
// });
|
||||
// } else {
|
||||
// reject({
|
||||
// code: -1,
|
||||
// msg: '获取用户信息失败'
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
// },
|
||||
|
||||
/**
|
||||
* 自动登录
|
||||
* 自动登录(已禁用 - 依赖JSBridge的getUserInfo)
|
||||
* 目前改用App.vue中的checkCCBLogin统一处理URL参数登录
|
||||
* @param {Number} retryCount - 重试次数
|
||||
*/
|
||||
async autoLogin(retryCount = 0) {
|
||||
const MAX_RETRY = 2; // 最多重试2次
|
||||
const RETRY_DELAY = 2000; // 重试延迟2秒
|
||||
|
||||
try {
|
||||
// 检查是否已登录
|
||||
const token = uni.getStorageSync('token');
|
||||
if (token) {
|
||||
console.log('[CcbLife] 用户已登录,跳过自动登录');
|
||||
// 验证token有效性
|
||||
try {
|
||||
await sheep.$store('user').getInfo();
|
||||
console.log('[CcbLife] Token有效');
|
||||
return { success: true, cached: true };
|
||||
} catch (e) {
|
||||
console.warn('[CcbLife] Token已失效,清除并重新登录');
|
||||
uni.removeStorageSync('token');
|
||||
uni.removeStorageSync('userInfo');
|
||||
}
|
||||
}
|
||||
|
||||
console.log('[CcbLife] 开始自动登录...');
|
||||
|
||||
// 获取用户信息
|
||||
const userResult = await this.getUserInfo();
|
||||
if (userResult.code !== 0) {
|
||||
throw new Error(userResult.msg || '获取建行用户信息失败');
|
||||
}
|
||||
|
||||
console.log('[CcbLife] 建行用户信息获取成功:', userResult.data);
|
||||
|
||||
// 调用后端登录接口
|
||||
const loginResult = await ccbApi.autoLogin(userResult.data);
|
||||
|
||||
if (loginResult.code === 1) {
|
||||
// 🔑 使用setToken方法更新登录状态(关键!)
|
||||
// 这会自动:设置isLogin=true + 保存token + 调用loginAfter()
|
||||
sheep.$store('user').setToken(loginResult.data.token);
|
||||
|
||||
// 也保存userInfo到storage(setToken会自动获取最新的)
|
||||
uni.setStorageSync('userInfo', loginResult.data.user_info || loginResult.data.userInfo);
|
||||
|
||||
console.log('[CcbLife] ✅ 自动登录成功');
|
||||
|
||||
// 触发登录成功事件
|
||||
uni.$emit('ccb:login:success', loginResult.data);
|
||||
|
||||
// 显示欢迎提示
|
||||
uni.showToast({
|
||||
title: '欢迎回来',
|
||||
icon: 'success',
|
||||
duration: 1500
|
||||
});
|
||||
|
||||
return { success: true, data: loginResult.data };
|
||||
} else {
|
||||
throw new Error(loginResult.msg || '登录接口返回失败');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`[CcbLife] ❌ 自动登录失败(第${retryCount + 1}次):`, error.message || error);
|
||||
|
||||
// 重试逻辑
|
||||
if (retryCount < MAX_RETRY) {
|
||||
console.log(`[CcbLife] ${RETRY_DELAY / 1000}秒后进行第${retryCount + 2}次尝试...`);
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve(this.autoLogin(retryCount + 1));
|
||||
}, RETRY_DELAY);
|
||||
});
|
||||
}
|
||||
|
||||
// 重试失败后的处理
|
||||
console.error('[CcbLife] 自动登录失败,已达最大重试次数');
|
||||
|
||||
// 显示友好提示
|
||||
uni.showModal({
|
||||
title: '登录提示',
|
||||
content: '自动登录失败,请点击登录按钮手动登录',
|
||||
showCancel: false,
|
||||
confirmText: '知道了'
|
||||
});
|
||||
|
||||
return { success: false, error: error.message || '未知错误' };
|
||||
}
|
||||
},
|
||||
// async autoLogin(retryCount = 0) {
|
||||
// const MAX_RETRY = 2;
|
||||
// const RETRY_DELAY = 2000;
|
||||
//
|
||||
// try {
|
||||
// const token = uni.getStorageSync('token');
|
||||
// if (token) {
|
||||
// console.log('[CcbLife] 用户已登录,跳过自动登录');
|
||||
// try {
|
||||
// await sheep.$store('user').getInfo();
|
||||
// console.log('[CcbLife] Token有效');
|
||||
// return { success: true, cached: true };
|
||||
// } catch (e) {
|
||||
// console.warn('[CcbLife] Token已失效,清除并重新登录');
|
||||
// uni.removeStorageSync('token');
|
||||
// uni.removeStorageSync('userInfo');
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// console.log('[CcbLife] 开始自动登录...');
|
||||
//
|
||||
// // 获取用户信息
|
||||
// const userResult = await this.getUserInfo();
|
||||
// if (userResult.code !== 0) {
|
||||
// throw new Error(userResult.msg || '获取建行用户信息失败');
|
||||
// }
|
||||
//
|
||||
// console.log('[CcbLife] 建行用户信息获取成功:', userResult.data);
|
||||
//
|
||||
// // 调用后端登录接口
|
||||
// const loginResult = await ccbApi.autoLogin(userResult.data);
|
||||
//
|
||||
// if (loginResult.code === 1) {
|
||||
// sheep.$store('user').setToken(loginResult.data.token);
|
||||
// uni.setStorageSync('userInfo', loginResult.data.user_info || loginResult.data.userInfo);
|
||||
// console.log('[CcbLife] ✅ 自动登录成功');
|
||||
// uni.$emit('ccb:login:success', loginResult.data);
|
||||
// uni.showToast({
|
||||
// title: '欢迎回来',
|
||||
// icon: 'success',
|
||||
// duration: 1500
|
||||
// });
|
||||
// return { success: true, data: loginResult.data };
|
||||
// } else {
|
||||
// throw new Error(loginResult.msg || '登录接口返回失败');
|
||||
// }
|
||||
// } catch (error) {
|
||||
// console.error(`[CcbLife] ❌ 自动登录失败(第${retryCount + 1}次):`, error.message || error);
|
||||
//
|
||||
// if (retryCount < MAX_RETRY) {
|
||||
// console.log(`[CcbLife] ${RETRY_DELAY / 1000}秒后进行第${retryCount + 2}次尝试...`);
|
||||
// return new Promise((resolve) => {
|
||||
// setTimeout(() => {
|
||||
// resolve(this.autoLogin(retryCount + 1));
|
||||
// }, RETRY_DELAY);
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// console.error('[CcbLife] 自动登录失败,已达最大重试次数');
|
||||
// uni.showModal({
|
||||
// title: '登录提示',
|
||||
// content: '自动登录失败,请点击登录按钮手动登录',
|
||||
// showCancel: false,
|
||||
// confirmText: '知道了'
|
||||
// });
|
||||
// return { success: false, error: error.message || '未知错误' };
|
||||
// }
|
||||
// },
|
||||
|
||||
/**
|
||||
* 调起建行支付
|
||||
* 调起建行支付(已禁用 - 依赖JSBridge)
|
||||
*/
|
||||
async payment(options) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!this.isInCcbApp) {
|
||||
reject({
|
||||
code: -1,
|
||||
msg: '不在建行生活App内'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// 必需参数检查
|
||||
if (!options.payment_string) {
|
||||
reject({
|
||||
code: -1,
|
||||
msg: '缺少支付串参数'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
this.ready(() => {
|
||||
// #ifdef H5
|
||||
// 区分iOS和Android
|
||||
if (this.isIOS()) {
|
||||
// iOS使用URL Scheme
|
||||
this.paymentForIOS(options, resolve, reject);
|
||||
} else {
|
||||
// Android使用JSBridge
|
||||
this.paymentForAndroid(options, resolve, reject);
|
||||
}
|
||||
// #endif
|
||||
|
||||
// #ifdef APP-PLUS
|
||||
// APP中调用原生插件
|
||||
this.paymentForApp(options, resolve, reject);
|
||||
// #endif
|
||||
});
|
||||
});
|
||||
},
|
||||
// async payment(options) {
|
||||
// return new Promise((resolve, reject) => {
|
||||
// if (!this.isInCcbApp) {
|
||||
// reject({
|
||||
// code: -1,
|
||||
// msg: '不在建行生活App内'
|
||||
// });
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// if (!options.payment_string) {
|
||||
// reject({
|
||||
// code: -1,
|
||||
// msg: '缺少支付串参数'
|
||||
// });
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// this.ready(() => {
|
||||
// // #ifdef H5
|
||||
// if (this.isIOS()) {
|
||||
// this.paymentForIOS(options, resolve, reject);
|
||||
// } else {
|
||||
// this.paymentForAndroid(options, resolve, reject);
|
||||
// }
|
||||
// // #endif
|
||||
//
|
||||
// // #ifdef APP-PLUS
|
||||
// this.paymentForApp(options, resolve, reject);
|
||||
// // #endif
|
||||
// });
|
||||
// });
|
||||
// },
|
||||
|
||||
/**
|
||||
* iOS支付
|
||||
* iOS支付(已禁用)
|
||||
*/
|
||||
paymentForIOS(options, resolve, reject) {
|
||||
// #ifdef H5
|
||||
const paymentUrl = 'comccbpay://pay?' + options.payment_string;
|
||||
|
||||
// 尝试打开支付页面
|
||||
window.location.href = paymentUrl;
|
||||
|
||||
// 设置回调检查
|
||||
setTimeout(() => {
|
||||
resolve({
|
||||
code: 0,
|
||||
msg: '已调起支付,请在建行App内完成支付'
|
||||
});
|
||||
}, 1000);
|
||||
// #endif
|
||||
},
|
||||
// paymentForIOS(options, resolve, reject) {
|
||||
// // #ifdef H5
|
||||
// const paymentUrl = 'comccbpay://pay?' + options.payment_string;
|
||||
// window.location.href = paymentUrl;
|
||||
// setTimeout(() => {
|
||||
// resolve({
|
||||
// code: 0,
|
||||
// msg: '已调起支付,请在建行App内完成支付'
|
||||
// });
|
||||
// }, 1000);
|
||||
// // #endif
|
||||
// },
|
||||
|
||||
/**
|
||||
* Android支付
|
||||
* Android支付(已禁用 - 依赖JSBridge)
|
||||
*/
|
||||
paymentForAndroid(options, resolve, reject) {
|
||||
this.callNative('payment', {
|
||||
payment_string: options.payment_string
|
||||
}, (result) => {
|
||||
if (result && result.success) {
|
||||
resolve({
|
||||
code: 0,
|
||||
data: result
|
||||
});
|
||||
} else {
|
||||
reject({
|
||||
code: -1,
|
||||
msg: result ? result.error : '支付失败'
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
// paymentForAndroid(options, resolve, reject) {
|
||||
// this.callNative('payment', {
|
||||
// payment_string: options.payment_string
|
||||
// }, (result) => {
|
||||
// if (result && result.success) {
|
||||
// resolve({
|
||||
// code: 0,
|
||||
// data: result
|
||||
// });
|
||||
// } else {
|
||||
// reject({
|
||||
// code: -1,
|
||||
// msg: result ? result.error : '支付失败'
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
// },
|
||||
|
||||
/**
|
||||
* APP支付
|
||||
* APP支付(已禁用)
|
||||
*/
|
||||
paymentForApp(options, resolve, reject) {
|
||||
// #ifdef APP-PLUS
|
||||
// TODO: 调用建行SDK插件
|
||||
uni.showToast({
|
||||
title: 'APP支付暂未实现',
|
||||
icon: 'none'
|
||||
});
|
||||
reject({
|
||||
code: -1,
|
||||
msg: 'APP支付暂未实现'
|
||||
});
|
||||
// #endif
|
||||
},
|
||||
// paymentForApp(options, resolve, reject) {
|
||||
// // #ifdef APP-PLUS
|
||||
// uni.showToast({
|
||||
// title: 'APP支付暂未实现',
|
||||
// icon: 'none'
|
||||
// });
|
||||
// reject({
|
||||
// code: -1,
|
||||
// msg: 'APP支付暂未实现'
|
||||
// });
|
||||
// // #endif
|
||||
// },
|
||||
|
||||
/**
|
||||
* 调用原生方法
|
||||
* 调用原生方法(已禁用 - JSBridge相关)
|
||||
*/
|
||||
callNative(method, params, callback) {
|
||||
// #ifdef H5
|
||||
try {
|
||||
if (this.isIOS() && this.bridge && this.bridge.callHandler) {
|
||||
// iOS WebViewJavascriptBridge
|
||||
this.bridge.callHandler(method, params, callback);
|
||||
} else if (window.mbspay && window.mbspay[method]) {
|
||||
// Android直接调用
|
||||
const result = window.mbspay[method](JSON.stringify(params));
|
||||
if (callback) {
|
||||
callback(typeof result === 'string' ? JSON.parse(result) : result);
|
||||
}
|
||||
} else {
|
||||
console.warn('[CcbLife] 原生方法不存在:', method);
|
||||
if (callback) {
|
||||
callback({
|
||||
success: false,
|
||||
error: '原生方法不存在'
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[CcbLife] 调用原生方法失败:', e);
|
||||
if (callback) {
|
||||
callback({
|
||||
success: false,
|
||||
error: e.message
|
||||
});
|
||||
}
|
||||
}
|
||||
// #endif
|
||||
},
|
||||
// callNative(method, params, callback) {
|
||||
// // #ifdef H5
|
||||
// try {
|
||||
// if (this.isIOS() && this.bridge && this.bridge.callHandler) {
|
||||
// this.bridge.callHandler(method, params, callback);
|
||||
// } else if (window.mbspay && window.mbspay[method]) {
|
||||
// const result = window.mbspay[method](JSON.stringify(params));
|
||||
// if (callback) {
|
||||
// callback(typeof result === 'string' ? JSON.parse(result) : result);
|
||||
// }
|
||||
// } else {
|
||||
// console.warn('[CcbLife] 原生方法不存在:', method);
|
||||
// if (callback) {
|
||||
// callback({
|
||||
// success: false,
|
||||
// error: '原生方法不存在'
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// } catch (e) {
|
||||
// console.error('[CcbLife] 调用原生方法失败:', e);
|
||||
// if (callback) {
|
||||
// callback({
|
||||
// success: false,
|
||||
// error: e.message
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// // #endif
|
||||
// },
|
||||
|
||||
/**
|
||||
* 判断是否iOS
|
||||
|
||||
@ -51,7 +51,7 @@ const http = new Request({
|
||||
header: {
|
||||
Accept: 'text/json',
|
||||
'Content-Type': 'application/json;charset=UTF-8',
|
||||
platform: $platform.name,
|
||||
platform: 'H5',
|
||||
},
|
||||
// #ifdef APP-PLUS
|
||||
sslVerify: false,
|
||||
|
||||
@ -132,10 +132,10 @@ const user = defineStore({
|
||||
cart().getList();
|
||||
// 登录后设置全局分享参数
|
||||
$share.getShareInfo();
|
||||
// 提醒绑定手机号
|
||||
if (app().platform.bind_mobile && !this.userInfo.verification?.mobile) {
|
||||
showAuthModal('changeMobile');
|
||||
}
|
||||
// 提醒绑定手机号 - 已禁用
|
||||
// if (app().platform.bind_mobile && !this.userInfo.verification?.mobile) {
|
||||
// showAuthModal('changeMobile');
|
||||
// }
|
||||
|
||||
// 添加分享记录
|
||||
const shareLog = uni.getStorageSync('shareLog');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user