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;
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 = () => {
// 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) => {
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;
// searchurl?platform=ccblife&ccbParamSJ=xxx
// searchurl?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中解析参数');
}
// hashUniApp使
@ -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,
});
// URLURL
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); // 1200msShoproAPI
} 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>

View File

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

View File

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

View File

@ -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';

View File

@ -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>

View File

@ -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

View File

@ -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,

View File

@ -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');