feat: 商城app 和中台通讯

This commit is contained in:
2025-11-04 01:14:33 +08:00
parent 350d1c410e
commit 9be1126016
5 changed files with 780 additions and 599 deletions
+1 -1
View File
@@ -4,7 +4,7 @@
{
"customPlaygroundType" : "local",
"packageName" : "com.trustbridge.mm",
"playground" : "custom",
"playground" : "standard",
"type" : "uni-app:app-android"
},
{
+656 -595
View File
File diff suppressed because it is too large Load Diff
+4 -1
View File
@@ -526,7 +526,10 @@ export default {
},
jumpToTrustBridge() {
// 跳转到指定的信任桥地址
plus.runtime.openURL("http://agent.outer.tbmall.xin:6880/");
console.log("跳转到指定的信任桥地址")
uni.navigateTo({
url:'/pages/mine_package/mild-shopping/mild-shopping'
})
},
/**
* 跳转到工具
@@ -0,0 +1,117 @@
<template>
<view class="mild-shopping">
<web-view
ref="webview"
:webview-styles="webviewStyles"
:src="webviewUrl"
@message="handlePostMessage"
@onPostMessage="handlePostMessage"
></web-view></view>
</template>
<script>
import { TOKEN_NAME, USER_DATA, getStorageFun } from "@/utils/auth.js";
// 全局变量
let wv; // 计划创建的webview
export default {
data() {
return {
webviewStyles: {
progress: {
color: "#333333",
},
},
wvNode: null,
webviewUrl:'http://agent.outer.tbmall.xin:6880/'
// webviewUrl: "http://192.168.0.101:8000/",
};
},
onShow() {
// #ifdef APP-PLUS
this.initWebview();
// #endif
},
methods: {
/**
* 初始化webview
*/
initWebview() {
const currentWebview = this.$scope.$getAppWebview();
setTimeout(() => {
wv = currentWebview.children()[0];
console.log(
"TOKEN_NAME-1",
getStorageFun(TOKEN_NAME),
getStorageFun(USER_DATA)
);
if (wv) {
// this.evalJSWithLog("onBridgeShowApp", {
// token: 'WnJyYmV5SmhiR2NpT2lKSVV6STFOaUo5LmV5SjFjMlZ5U1dRaU9qRTNNallzSW0xamFFbGtJam94TURBeUxDSnBjM01pT2lKb2MyMHRabkp2Ym5SbGJtUWlMQ0owSWpveE56WXlNVGczTURreE1qYzRmUS5Caml4VU8yS1ZoUHBmeHdjRDRPWE4tSmw5T1lBZnBlc3hCRUN6UUFzQUpzRkp2em4',
// userId: '1726',
// name: '陈俊兴',
// });
this.evalJSWithLog("onBridgeShowApp", {
token: getStorageFun(TOKEN_NAME),
userId: getStorageFun(USER_DATA).userId,
name: getStorageFun(USER_DATA).name,
});
}
}, 300);
// 支付成功,小程序跳回app
},
/**
* 处理来自webview的消息
*/
handlePostMessage(val) {
console.log("收到消息", val, val.detail.data);
const detail = val.detail.data[0];
const type = detail?.type;
console.log("收到消息-1", type);
// 使用策略模式处理不同类型消息
const handlers = {
/** 一键登录 **/
back: () => this.back(detail),
/** 默认 */
default: () => {
if (detail.userInfo) {
this.handleChatMessage(detail, type);
} else {
console.log("未知类型:", type);
}
},
};
(handlers[type] || handlers["default"])();
},
evalJSWithLog(callBackName, data) {
if (!wv) return;
const params = JSON.stringify(data);
console.log(`调用 evalJS: ${callBackName}(${params})`);
wv.evalJS(`${callBackName}(${params})`);
},
/**
* 开始录音
*/
back() {
uni.switchTab({
url: "/pages/mine/mine",
});
},
},
};
</script>
<style lang="scss" scoped>
.mild-shopping{
padding-top: var(--status-bar-height);
}
</style>
+2 -2
View File
@@ -2,9 +2,9 @@
// export const BASE_URL="https://frontend.jdns360.com/api"; // 正式环境
// export const BASE_URL="http://cl55un59859.vicp.fun:24346"; // 测试环境
export const BASE_URL = "https://api.tbmall.xin"; //生产
// export const BASE_URL = "https://api.tbmall.xin"; //生产
// export const BASE_URL ='http://api.hm.a-d.work:6880' // 测试
// export const BASE_URL ='http://api.outer.tbmall.xin:6880' // 本地测试
export const BASE_URL ='http://api.outer.tbmall.xin:6880' // 本地测试