Merge branch 'main' of gitee.com:liuxioabin/fengketrade

This commit is contained in:
Billy 2025-10-21 15:03:45 +08:00
commit f3b259d9dc
9 changed files with 471 additions and 454 deletions

View File

@ -7,20 +7,51 @@
let isLoggingIn = false; let isLoggingIn = false;
onLaunch(() => { onLaunch(() => {
console.log('[App] 应用启动...');
// 使 // 使
uni.hideTabBar({ uni.hideTabBar({
fail: () => {}, fail: () => {},
}); });
// H5
// #ifdef H5
initVConsole();
// #endif
// Shopro // Shopro
ShoproInit(); ShoproInit();
// //
checkCCBLogin(); checkCCBLogin();
// JSBridge 10
// #ifdef H5
startJSBridgeMonitor();
// #endif
}); });
/**
* 初始化 vConsole 移动端调试控制台
* 在H5环境下提供类似Chrome DevTools的功能
*/
const initVConsole = () => {
// vConsoleH5
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) => { onError((err) => {
console.log('AppOnError:', err); console.log('AppOnError:', err);
}); });
@ -39,6 +70,59 @@
// #endif // #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格式url?platform=ccblife&channel=mbs&ccbParamSJ=xxx&CITYID=330100&USERCITYID=440100 * 建行跳转URL格式url?platform=ccblife&channel=mbs&ccbParamSJ=xxx&CITYID=330100&USERCITYID=440100
@ -51,22 +135,17 @@
*/ */
const checkCCBLogin = () => { const checkCCBLogin = () => {
// #ifdef H5 // #ifdef H5
console.log('[App] ========== 开始检测建行登录参数 ==========');
console.log('[App] 完整URL:', window.location.href);
console.log('[App] search:', window.location.search);
try { try {
let ccbParamSJ = null; let ccbParamSJ = null;
let platform = null; let platform = null;
let cityid = null; let cityid = null;
// searchurl?platform=ccblife&ccbParamSJ=xxx // searchurl?ccbParamSJ=xxx&CITYID=xxx
if (window.location.search) { if (window.location.search) {
const urlParams = new URLSearchParams(window.location.search); const urlParams = new URLSearchParams(window.location.search);
ccbParamSJ = urlParams.get('ccbParamSJ'); ccbParamSJ = urlParams.get('ccbParamSJ');
platform = urlParams.get('platform'); platform = urlParams.get('platform') || 'ccblife';
cityid = urlParams.get('CITYID') || urlParams.get('cityid'); cityid = urlParams.get('CITYID') || urlParams.get('cityid');
console.log('[App] 从search中解析参数');
} }
// hashUniApp使 // hashUniApp使
@ -75,128 +154,88 @@
if (hashParts.length > 1) { if (hashParts.length > 1) {
const hashParams = new URLSearchParams(hashParts[1]); const hashParams = new URLSearchParams(hashParts[1]);
ccbParamSJ = hashParams.get('ccbParamSJ'); ccbParamSJ = hashParams.get('ccbParamSJ');
platform = hashParams.get('platform'); platform = hashParams.get('platform') || 'ccblife';
cityid = hashParams.get('CITYID') || hashParams.get('cityid'); 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 // ccbParamSJ
const lastCcbParamSJ = uni.getStorageSync('lastCcbParamSJ') || null; const lastCcbParamSJ = uni.getStorageSync('lastCcbParamSJ') || null;
console.log('[App] 上次ccbParamSJ:', lastCcbParamSJ ? lastCcbParamSJ.substring(0, 50) + '...' : 'null');
// //
const isParamChanged = ccbParamSJ && (lastCcbParamSJ !== ccbParamSJ); const isParamChanged = ccbParamSJ && lastCcbParamSJ !== ccbParamSJ;
const isFirstTime = ccbParamSJ && !lastCcbParamSJ; const isFirstTime = ccbParamSJ && !lastCcbParamSJ;
console.log('[App] 是否首次登录:', isFirstTime); // ccbParamSJ
console.log('[App] 参数是否变化:', isParamChanged); if (ccbParamSJ) {
console.log('[App] ===========================');
//
if (ccbParamSJ && platform === 'ccblife') {
// //
if (!isParamChanged && !isFirstTime) { if (!isParamChanged && !isFirstTime) {
console.log('[App] ccbParamSJ未变化无需重新登录跳过'); console.log('[CCB] 参数未变化,跳过登录');
// URL const cleanUrl = window.location.origin + '/pages/index/index';
const cleanUrl = window.location.origin + window.location.pathname + '#/pages/index/index';
window.history.replaceState({}, '', cleanUrl); window.history.replaceState({}, '', cleanUrl);
console.log('[App] ========== 检测完成 ==========');
return; return;
} }
// console.log(`[CCB] ${isParamChanged ? '切换用户' : '首次登录'}`);
if (isParamChanged) {
console.log('[App] 🔄🔄🔄 检测到ccbParamSJ变化需要切换用户');
} else {
console.log('[App] 🆕 首次登录');
}
// 🔒 //
if (isLoggingIn) { if (isLoggingIn) {
console.log('[App] ⚠️ 已有登录流程正在执行,跳过重复调用'); console.log('[CCB] 登录进行中,跳过');
return; return;
} }
//
isLoggingIn = true; isLoggingIn = true;
console.log('[App] 🔒 设置登录锁定标志');
// //
setTimeout(async () => { setTimeout(async () => {
try { try {
console.log('[App] 开始执行登录流程...');
// 退 // 退
const userStore = sheep.$store('user'); const userStore = sheep.$store('user');
if (isParamChanged && userStore && userStore.isLogin) { if (isParamChanged && userStore && userStore.isLogin) {
console.log('[App] 退出当前用户,准备切换...');
await userStore.logout(); await userStore.logout();
uni.removeStorageSync('token'); uni.removeStorageSync('token');
uni.removeStorageSync('userInfo'); uni.removeStorageSync('userInfo');
console.log('[App] 当前用户已退出');
} }
// loading // loading
const loadingTitle = isParamChanged ? '切换用户中...' : '建行登录中...'; const loadingTitle = isParamChanged ? '切换用户中...' : '建行登录中...';
uni.showLoading({ uni.showLoading({
title: loadingTitle, title: loadingTitle,
mask: true mask: true,
});
// API
console.log('[App] 调用登录API参数:', {
ccbParamSJ: ccbParamSJ.substring(0, 30) + '...',
cityid: cityid || '360100',
CITYID: cityid || '360100'
}); });
// API
const result = await sheep.$api.third.ccbLogin({ const result = await sheep.$api.third.ccbLogin({
ccbParamSJ: ccbParamSJ, ccbParamSJ: ccbParamSJ,
cityid: cityid || '360100', cityid: cityid || '360100',
CITYID: cityid || '360100' CITYID: cityid || '360100',
}); });
console.log('[App] 登录API返回:', result);
uni.hideLoading(); uni.hideLoading();
if (result.code === 1) { if (result.code === 1) {
console.log('[App] ✅✅✅ 建行登录成功!'); console.log('[CCB] 登录成功');
console.log('[App] Token:', result.data.token?.substring(0, 20) + '...');
console.log('[App] 用户信息:', result.data.user_info);
// token // token
sheep.$store('user').setToken(result.data.token); sheep.$store('user').setToken(result.data.token);
uni.setStorageSync('userInfo', result.data.user_info); uni.setStorageSync('userInfo', result.data.user_info);
// 🔑 ccbParamSJ
uni.setStorageSync('lastCcbParamSJ', ccbParamSJ); uni.setStorageSync('lastCcbParamSJ', ccbParamSJ);
console.log('[App] ✅ 已保存ccbParamSJ到本地存储');
// //
uni.showToast({ uni.showToast({
title: `登录成功`, title: `登录成功`,
icon: 'success', icon: 'success',
duration: 2000 duration: 2000,
}); });
// URLURL // URL
const cleanUrl = window.location.origin + window.location.pathname + '#/pages/index/index'; const cleanUrl = window.location.origin + '/pages/index/index';
window.history.replaceState({}, '', cleanUrl); window.history.replaceState({}, '', cleanUrl);
console.log('[App] URL参数已清除');
} else { } else {
throw new Error(result.msg || '登录失败'); throw new Error(result.msg || '登录失败');
} }
} catch (error) { } catch (error) {
console.error('[App] ❌❌❌ 建行登录失败:', error); console.error('[CCB] 登录失败:', error.message || error.msg);
uni.hideLoading(); uni.hideLoading();
uni.showModal({ uni.showModal({
@ -204,27 +243,18 @@
content: error.message || error.msg || '请检查网络连接', content: error.message || error.msg || '请检查网络连接',
showCancel: false, showCancel: false,
complete: () => { complete: () => {
// URL const cleanUrl = window.location.origin + '/pages/index/index';
const cleanUrl = window.location.origin + window.location.pathname + '#/pages/index/index';
window.history.replaceState({}, '', cleanUrl); window.history.replaceState({}, '', cleanUrl);
} },
}); });
} finally { } finally {
// 🔓
isLoggingIn = false; isLoggingIn = false;
console.log('[App] 🔓 释放登录锁定标志');
}
}, 1200); // 1200msShoproAPI
} else {
console.log('[App] 未检测到建行登录参数');
if (ccbParamSJ && platform !== 'ccblife') {
console.warn('[App] ⚠️ 发现ccbParamSJ但platform不是ccblife:', platform);
} }
}, 1200);
} }
} catch (error) { } catch (error) {
console.error('[App] ❌ 参数解析错误:', error); console.error('[CCB] 参数解析错误:', error);
} }
console.log('[App] ========== 检测完成 ==========');
// #endif // #endif
}; };
</script> </script>
@ -232,4 +262,3 @@
<style lang="scss"> <style lang="scss">
@import '@/sheep/scss/index.scss'; @import '@/sheep/scss/index.scss';
</style> </style>

View File

@ -199,8 +199,8 @@
"h5" : { "h5" : {
"template" : "index.html", "template" : "index.html",
"router" : { "router" : {
"mode" : "hash", "mode" : "history",
"base" : "./" "base" : "/"
}, },
"sdkConfigs" : { "sdkConfigs" : {
"maps" : {} "maps" : {}

View File

@ -1,4 +1,5 @@
<template> <template>
<!-- 建行生活环境自动隐藏导航栏建行APP自带页头 -->
<s-layout title="建行生活" :bgStyle="{ color: 'rgb(245,28,19)' }"> <s-layout title="建行生活" :bgStyle="{ color: 'rgb(245,28,19)' }">
<!-- 顶部banner --> <!-- 顶部banner -->
<view class="ccb-banner"> <view class="ccb-banner">

View File

@ -93,7 +93,8 @@
<view class="copyright-text ss-m-b-10">{{ appInfo.copyright }}</view> <view class="copyright-text ss-m-b-10">{{ appInfo.copyright }}</view>
<view class="copyright-text">{{ appInfo.copytime }}</view> <view class="copyright-text">{{ appInfo.copytime }}</view>
</view> </view>
<su-fixed bottom placeholder> <!-- 退出登录按钮已暂时隐藏 -->
<su-fixed bottom placeholder v-if="false">
<view class="ss-p-x-20 ss-p-b-40"> <view class="ss-p-x-20 ss-p-b-40">
<button <button
class="loginout-btn ss-reset-button ui-BG-Main ui-Shadow-Main" class="loginout-btn ss-reset-button ui-BG-Main ui-Shadow-Main"

View File

@ -6,7 +6,7 @@
<view class="page-main" :style="[bgMain]"> <view class="page-main" :style="[bgMain]">
<!-- 默认通用顶部导航栏 --> <!-- 默认通用顶部导航栏 -->
<su-navbar <su-navbar
v-if="navbar === 'normal'" v-if="actualNavbar === 'normal'"
:title="title" :title="title"
statusBar statusBar
:color="color" :color="color"
@ -18,21 +18,21 @@
<!-- 装修组件导航栏-普通 --> <!-- 装修组件导航栏-普通 -->
<s-custom-navbar <s-custom-navbar
v-else-if="navbar === 'custom' && navbarMode === 'normal'" v-else-if="actualNavbar === 'custom' && navbarMode === 'normal'"
:data="navbarStyle" :data="navbarStyle"
:showLeftButton="showLeftButton" :showLeftButton="showLeftButton"
/> />
<view class="page-body" :style="[bgBody]"> <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 <view
v-if="navbar === 'inner'" v-if="actualNavbar === 'inner'"
:style="[{ paddingTop: sheep.$platform.navbar + 'px' }]" :style="[{ paddingTop: sheep.$platform.navbar + 'px' }]"
></view> ></view>
<!-- 装修组件导航栏-沉浸式 --> <!-- 装修组件导航栏-沉浸式 -->
<s-custom-navbar <s-custom-navbar
v-if="navbar === 'custom' && navbarMode === 'inner'" v-if="actualNavbar === 'custom' && navbarMode === 'inner'"
:data="navbarStyle" :data="navbarStyle"
:showLeftButton="showLeftButton" :showLeftButton="showLeftButton"
/> />
@ -80,6 +80,11 @@
type: String, type: String,
default: 'normal', default: 'normal',
}, },
//
hideNavbarInCcb: {
type: Boolean,
default: true, //
},
opacityBgUi: { opacityBgUi: {
type: String, type: String,
default: 'bg-white', default: 'bg-white',
@ -153,9 +158,40 @@
const modalStore = sheep.$store('modal'); const modalStore = sheep.$store('modal');
const sys = computed(() => sysStore); 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(() => { const navbarMode = computed(() => {
if (props.navbar === 'normal' || props.navbarStyle.mode === 'normal') { if (actualNavbar.value === 'normal' || props.navbarStyle.mode === 'normal') {
return 'normal'; return 'normal';
} }
return 'inner'; return 'inner';

View File

@ -28,9 +28,10 @@
</view> </view>
</view> </view>
<!-- 绑定手机号提示已隐藏 -->
<view <view
class="bind-mobile-box ss-flex ss-row-between ss-col-center" 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"> <view class="ss-flex">
<text class="cicon-mobile-o"></text> <text class="cicon-mobile-o"></text>

View File

@ -29,14 +29,14 @@ const CcbLifePlatform = {
// 是否在建行生活环境中 // 是否在建行生活环境中
isInCcbApp: false, isInCcbApp: false,
// JSBridge 对象 // JSBridge 对象(已禁用)
bridge: null, // bridge: null,
// 就绪状态 // 就绪状态(已禁用)
isReady: false, // isReady: false,
// 就绪回调队列 // 就绪回调队列(已禁用)
readyCallbacks: [], // readyCallbacks: [],
/** /**
* 初始化 * 初始化
@ -45,12 +45,10 @@ const CcbLifePlatform = {
// 检测环境 // 检测环境
this.detectEnvironment(); this.detectEnvironment();
// 如果在建行App内初始化JSBridge // ⚠️ JSBridge 已禁用,目前不需要
if (this.isInCcbApp) { // if (this.isInCcbApp) {
this.setupBridge(); // this.setupBridge();
// ⚠️ 自动登录已禁用改用App.vue中的checkCCBLogin统一处理 // }
// this.autoLogin();
}
console.log('[CcbLife] 初始化完成, 是否在建行App内:', this.isInCcbApp); console.log('[CcbLife] 初始化完成, 是否在建行App内:', this.isInCcbApp);
}, },
@ -75,11 +73,11 @@ const CcbLifePlatform = {
return; return;
} }
// 检查JSBridge // ⚠️ 已移除 JSBridge 检查(目前不需要)
if (window.WebViewJavascriptBridge || window.mbspay) { // if (window.WebViewJavascriptBridge || window.mbspay) {
this.isInCcbApp = true; // this.isInCcbApp = true;
return; // return;
} // }
// #endif // #endif
// #ifdef APP-PLUS // #ifdef APP-PLUS
@ -94,104 +92,83 @@ const CcbLifePlatform = {
}, },
/** /**
* 设置JSBridge * 设置JSBridge已禁用 - 目前不需要
*/ */
setupBridge() { // setupBridge() {
// #ifdef H5 // // #ifdef H5
const self = this; // const self = this;
let bridgeCheckCount = 0; // let bridgeCheckCount = 0;
const MAX_BRIDGE_CHECK = 20; // 最多检查20次 // const MAX_BRIDGE_CHECK = 20;
const BRIDGE_CHECK_INTERVAL = 500; // 每500ms检查一次,总共10秒 // const BRIDGE_CHECK_INTERVAL = 500;
//
// iOS WebViewJavascriptBridge // // iOS WebViewJavascriptBridge
if (window.WebViewJavascriptBridge) { // if (window.WebViewJavascriptBridge) {
self.bridge = window.WebViewJavascriptBridge; // self.bridge = window.WebViewJavascriptBridge;
self.onBridgeReady(); // self.onBridgeReady();
return; // return;
} // }
//
// 监听iOS Bridge就绪事件 // // 监听iOS Bridge就绪事件
document.addEventListener('WebViewJavascriptBridgeReady', function() { // document.addEventListener('WebViewJavascriptBridgeReady', function() {
self.bridge = window.WebViewJavascriptBridge; // self.bridge = window.WebViewJavascriptBridge;
self.onBridgeReady(); // self.onBridgeReady();
}, false); // }, false);
//
// Android 直接通过window对象 // // Android 直接通过window对象
if (window.mbspay) { // if (window.mbspay) {
self.bridge = window.mbspay; // self.bridge = window.mbspay;
self.onBridgeReady(); // self.onBridgeReady();
return; // return;
} // }
//
// 轮询检查Bridge是否已加载(建行App可能需要时间初始化) // // 轮询检查Bridge是否已加载
const bridgeCheckInterval = setInterval(() => { // const bridgeCheckInterval = setInterval(() => {
bridgeCheckCount++; // bridgeCheckCount++;
//
// 检查iOS Bridge // if (window.WebViewJavascriptBridge && !self.isReady) {
if (window.WebViewJavascriptBridge && !self.isReady) { // clearInterval(bridgeCheckInterval);
clearInterval(bridgeCheckInterval); // self.bridge = window.WebViewJavascriptBridge;
self.bridge = window.WebViewJavascriptBridge; // self.onBridgeReady();
self.onBridgeReady(); // console.log(`[CcbLife] iOS Bridge 已就绪(检查${bridgeCheckCount}次)`);
console.log(`[CcbLife] iOS Bridge 已就绪(检查${bridgeCheckCount}次)`); // return;
return; // }
} //
// if (window.mbspay && !self.isReady) {
// 检查Android Bridge // clearInterval(bridgeCheckInterval);
if (window.mbspay && !self.isReady) { // self.bridge = window.mbspay;
clearInterval(bridgeCheckInterval); // self.onBridgeReady();
self.bridge = window.mbspay; // console.log(`[CcbLife] Android Bridge 已就绪(检查${bridgeCheckCount}次)`);
self.onBridgeReady(); // return;
console.log(`[CcbLife] Android Bridge 已就绪(检查${bridgeCheckCount}次)`); // }
return; //
} // if (bridgeCheckCount >= MAX_BRIDGE_CHECK) {
// clearInterval(bridgeCheckInterval);
// 达到最大检查次数 // console.error('[CcbLife] ⚠️ JSBridge 初始化超时');
if (bridgeCheckCount >= MAX_BRIDGE_CHECK) { // }
clearInterval(bridgeCheckInterval); // }, BRIDGE_CHECK_INTERVAL);
console.error('[CcbLife] ⚠️ JSBridge 初始化超时,建行功能可能不可用'); // // #endif
// },
// 显示提示
if (self.isInCcbApp) {
uni.showModal({
title: '提示',
content: '建行环境初始化失败,部分功能可能无法使用。建议重新打开页面。',
showCancel: true,
cancelText: '关闭',
confirmText: '重新加载',
success: (res) => {
if (res.confirm) {
location.reload();
}
}
});
}
}
}, BRIDGE_CHECK_INTERVAL);
// #endif
},
/** /**
* Bridge就绪回调 * Bridge就绪回调已禁用
*/ */
onBridgeReady() { // onBridgeReady() {
this.isReady = true; // this.isReady = true;
console.log('[CcbLife] JSBridge 已就绪'); // console.log('[CcbLife] JSBridge 已就绪');
// this.readyCallbacks.forEach(callback => callback());
// 执行所有等待的回调 // this.readyCallbacks = [];
this.readyCallbacks.forEach(callback => callback()); // },
this.readyCallbacks = [];
},
/** /**
* 等待Bridge就绪 * 等待Bridge就绪已禁用
*/ */
ready(callback) { // ready(callback) {
if (this.isReady) { // if (this.isReady) {
callback(); // callback();
} else { // } else {
this.readyCallbacks.push(callback); // this.readyCallbacks.push(callback);
} // }
}, // },
/** /**
* 获取URL参数 * 获取URL参数
@ -214,266 +191,238 @@ const CcbLifePlatform = {
}, },
/** /**
* 获取建行用户信息 * 获取建行用户信息已禁用 - 依赖JSBridge
*/ */
async getUserInfo() { // async getUserInfo() {
return new Promise((resolve, reject) => { // return new Promise((resolve, reject) => {
if (!this.isInCcbApp) { // if (!this.isInCcbApp) {
reject({ // reject({
code: -1, // code: -1,
msg: '不在建行生活App内' // msg: '不在建行生活App内'
}); // });
return; // return;
} // }
//
this.ready(() => { // this.ready(() => {
this.callNative('getUserInfo', {}, (result) => { // this.callNative('getUserInfo', {}, (result) => {
if (result && result.userid) { // if (result && result.userid) {
resolve({ // resolve({
code: 0, // code: 0,
data: { // data: {
ccb_user_id: result.userid, // ccb_user_id: result.userid,
mobile: result.mobile || '', // mobile: result.mobile || '',
nickname: result.nickname || '', // nickname: result.nickname || '',
avatar: result.avatar || '' // avatar: result.avatar || ''
} // }
}); // });
} else { // } else {
reject({ // reject({
code: -1, // code: -1,
msg: '获取用户信息失败' // msg: '获取用户信息失败'
}); // });
} // }
}); // });
}); // });
}); // });
}, // },
/** /**
* 自动登录 * 自动登录已禁用 - 依赖JSBridge的getUserInfo
* 目前改用App.vue中的checkCCBLogin统一处理URL参数登录
* @param {Number} retryCount - 重试次数 * @param {Number} retryCount - 重试次数
*/ */
async autoLogin(retryCount = 0) { // async autoLogin(retryCount = 0) {
const MAX_RETRY = 2; // 最多重试2次 // const MAX_RETRY = 2;
const RETRY_DELAY = 2000; // 重试延迟2秒 // const RETRY_DELAY = 2000;
//
try { // try {
// 检查是否已登录 // const token = uni.getStorageSync('token');
const token = uni.getStorageSync('token'); // if (token) {
if (token) { // console.log('[CcbLife] 用户已登录,跳过自动登录');
console.log('[CcbLife] 用户已登录,跳过自动登录'); // try {
// 验证token有效性 // await sheep.$store('user').getInfo();
try { // console.log('[CcbLife] Token有效');
await sheep.$store('user').getInfo(); // return { success: true, cached: true };
console.log('[CcbLife] Token有效'); // } catch (e) {
return { success: true, cached: true }; // console.warn('[CcbLife] Token已失效,清除并重新登录');
} catch (e) { // uni.removeStorageSync('token');
console.warn('[CcbLife] Token已失效,清除并重新登录'); // uni.removeStorageSync('userInfo');
uni.removeStorageSync('token'); // }
uni.removeStorageSync('userInfo'); // }
} //
} // console.log('[CcbLife] 开始自动登录...');
//
console.log('[CcbLife] 开始自动登录...'); // // 获取用户信息
// const userResult = await this.getUserInfo();
// 获取用户信息 // if (userResult.code !== 0) {
const userResult = await this.getUserInfo(); // throw new Error(userResult.msg || '获取建行用户信息失败');
if (userResult.code !== 0) { // }
throw new Error(userResult.msg || '获取建行用户信息失败'); //
} // console.log('[CcbLife] 建行用户信息获取成功:', userResult.data);
//
console.log('[CcbLife] 建行用户信息获取成功:', userResult.data); // // 调用后端登录接口
// const loginResult = await ccbApi.autoLogin(userResult.data);
// 调用后端登录接口 //
const loginResult = await ccbApi.autoLogin(userResult.data); // if (loginResult.code === 1) {
// sheep.$store('user').setToken(loginResult.data.token);
if (loginResult.code === 1) { // uni.setStorageSync('userInfo', loginResult.data.user_info || loginResult.data.userInfo);
// 🔑 使用setToken方法更新登录状态(关键!) // console.log('[CcbLife] ✅ 自动登录成功');
// 这会自动:设置isLogin=true + 保存token + 调用loginAfter() // uni.$emit('ccb:login:success', loginResult.data);
sheep.$store('user').setToken(loginResult.data.token); // uni.showToast({
// title: '欢迎回来',
// 也保存userInfo到storage(setToken会自动获取最新的) // icon: 'success',
uni.setStorageSync('userInfo', loginResult.data.user_info || loginResult.data.userInfo); // duration: 1500
// });
console.log('[CcbLife] ✅ 自动登录成功'); // return { success: true, data: loginResult.data };
// } else {
// 触发登录成功事件 // throw new Error(loginResult.msg || '登录接口返回失败');
uni.$emit('ccb:login:success', loginResult.data); // }
// } catch (error) {
// 显示欢迎提示 // console.error(`[CcbLife] ❌ 自动登录失败(第${retryCount + 1}次):`, error.message || error);
uni.showToast({ //
title: '欢迎回来', // if (retryCount < MAX_RETRY) {
icon: 'success', // console.log(`[CcbLife] ${RETRY_DELAY / 1000}秒后进行第${retryCount + 2}次尝试...`);
duration: 1500 // return new Promise((resolve) => {
}); // setTimeout(() => {
// resolve(this.autoLogin(retryCount + 1));
return { success: true, data: loginResult.data }; // }, RETRY_DELAY);
} else { // });
throw new Error(loginResult.msg || '登录接口返回失败'); // }
} //
} catch (error) { // console.error('[CcbLife] 自动登录失败,已达最大重试次数');
console.error(`[CcbLife] ❌ 自动登录失败(第${retryCount + 1}次):`, error.message || error); // uni.showModal({
// title: '登录提示',
// 重试逻辑 // content: '自动登录失败,请点击登录按钮手动登录',
if (retryCount < MAX_RETRY) { // showCancel: false,
console.log(`[CcbLife] ${RETRY_DELAY / 1000}秒后进行第${retryCount + 2}次尝试...`); // confirmText: '知道了'
return new Promise((resolve) => { // });
setTimeout(() => { // return { success: false, error: error.message || '未知错误' };
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) { // async payment(options) {
return new Promise((resolve, reject) => { // return new Promise((resolve, reject) => {
if (!this.isInCcbApp) { // if (!this.isInCcbApp) {
reject({ // reject({
code: -1, // code: -1,
msg: '不在建行生活App内' // msg: '不在建行生活App内'
}); // });
return; // return;
} // }
//
// 必需参数检查 // if (!options.payment_string) {
if (!options.payment_string) { // reject({
reject({ // code: -1,
code: -1, // msg: '缺少支付串参数'
msg: '缺少支付串参数' // });
}); // return;
return; // }
} //
// this.ready(() => {
this.ready(() => { // // #ifdef H5
// #ifdef H5 // if (this.isIOS()) {
// 区分iOS和Android // this.paymentForIOS(options, resolve, reject);
if (this.isIOS()) { // } else {
// iOS使用URL Scheme // this.paymentForAndroid(options, resolve, reject);
this.paymentForIOS(options, resolve, reject); // }
} else { // // #endif
// Android使用JSBridge //
this.paymentForAndroid(options, resolve, reject); // // #ifdef APP-PLUS
} // this.paymentForApp(options, resolve, reject);
// #endif // // #endif
// });
// #ifdef APP-PLUS // });
// APP中调用原生插件 // },
this.paymentForApp(options, resolve, reject);
// #endif
});
});
},
/** /**
* iOS支付 * iOS支付已禁用
*/ */
paymentForIOS(options, resolve, reject) { // paymentForIOS(options, resolve, reject) {
// #ifdef H5 // // #ifdef H5
const paymentUrl = 'comccbpay://pay?' + options.payment_string; // const paymentUrl = 'comccbpay://pay?' + options.payment_string;
// window.location.href = paymentUrl;
// 尝试打开支付页面 // setTimeout(() => {
window.location.href = paymentUrl; // resolve({
// code: 0,
// 设置回调检查 // msg: '已调起支付请在建行App内完成支付'
setTimeout(() => { // });
resolve({ // }, 1000);
code: 0, // // #endif
msg: '已调起支付请在建行App内完成支付' // },
});
}, 1000);
// #endif
},
/** /**
* Android支付 * Android支付已禁用 - 依赖JSBridge
*/ */
paymentForAndroid(options, resolve, reject) { // paymentForAndroid(options, resolve, reject) {
this.callNative('payment', { // this.callNative('payment', {
payment_string: options.payment_string // payment_string: options.payment_string
}, (result) => { // }, (result) => {
if (result && result.success) { // if (result && result.success) {
resolve({ // resolve({
code: 0, // code: 0,
data: result // data: result
}); // });
} else { // } else {
reject({ // reject({
code: -1, // code: -1,
msg: result ? result.error : '支付失败' // msg: result ? result.error : '支付失败'
}); // });
} // }
}); // });
}, // },
/** /**
* APP支付 * APP支付已禁用
*/ */
paymentForApp(options, resolve, reject) { // paymentForApp(options, resolve, reject) {
// #ifdef APP-PLUS // // #ifdef APP-PLUS
// TODO: 调用建行SDK插件 // uni.showToast({
uni.showToast({ // title: 'APP支付暂未实现',
title: 'APP支付暂未实现', // icon: 'none'
icon: 'none' // });
}); // reject({
reject({ // code: -1,
code: -1, // msg: 'APP支付暂未实现'
msg: 'APP支付暂未实现' // });
}); // // #endif
// #endif // },
},
/** /**
* 调用原生方法 * 调用原生方法已禁用 - JSBridge相关
*/ */
callNative(method, params, callback) { // callNative(method, params, callback) {
// #ifdef H5 // // #ifdef H5
try { // try {
if (this.isIOS() && this.bridge && this.bridge.callHandler) { // if (this.isIOS() && this.bridge && this.bridge.callHandler) {
// iOS WebViewJavascriptBridge // this.bridge.callHandler(method, params, callback);
this.bridge.callHandler(method, params, callback); // } else if (window.mbspay && window.mbspay[method]) {
} else if (window.mbspay && window.mbspay[method]) { // const result = window.mbspay[method](JSON.stringify(params));
// Android直接调用 // if (callback) {
const result = window.mbspay[method](JSON.stringify(params)); // callback(typeof result === 'string' ? JSON.parse(result) : result);
if (callback) { // }
callback(typeof result === 'string' ? JSON.parse(result) : result); // } else {
} // console.warn('[CcbLife] 原生方法不存在:', method);
} else { // if (callback) {
console.warn('[CcbLife] 原生方法不存在:', method); // callback({
if (callback) { // success: false,
callback({ // error: '原生方法不存在'
success: false, // });
error: '原生方法不存在' // }
}); // }
} // } catch (e) {
} // console.error('[CcbLife] 调用原生方法失败:', e);
} catch (e) { // if (callback) {
console.error('[CcbLife] 调用原生方法失败:', e); // callback({
if (callback) { // success: false,
callback({ // error: e.message
success: false, // });
error: e.message // }
}); // }
} // // #endif
} // },
// #endif
},
/** /**
* 判断是否iOS * 判断是否iOS

View File

@ -51,7 +51,7 @@ const http = new Request({
header: { header: {
Accept: 'text/json', Accept: 'text/json',
'Content-Type': 'application/json;charset=UTF-8', 'Content-Type': 'application/json;charset=UTF-8',
platform: $platform.name, platform: 'H5',
}, },
// #ifdef APP-PLUS // #ifdef APP-PLUS
sslVerify: false, sslVerify: false,

View File

@ -132,10 +132,10 @@ const user = defineStore({
cart().getList(); cart().getList();
// 登录后设置全局分享参数 // 登录后设置全局分享参数
$share.getShareInfo(); $share.getShareInfo();
// 提醒绑定手机号 // 提醒绑定手机号 - 已禁用
if (app().platform.bind_mobile && !this.userInfo.verification?.mobile) { // if (app().platform.bind_mobile && !this.userInfo.verification?.mobile) {
showAuthModal('changeMobile'); // showAuthModal('changeMobile');
} // }
// 添加分享记录 // 添加分享记录
const shareLog = uni.getStorageSync('shareLog'); const shareLog = uni.getStorageSync('shareLog');