2025-08-01 14:30:51 +08:00
|
|
|
|
<template>
|
2025-08-02 20:41:02 +08:00
|
|
|
|
<web-view
|
|
|
|
|
|
ref="webviewRef"
|
|
|
|
|
|
:src="iframeUrl"
|
|
|
|
|
|
@message="handleMessage"
|
|
|
|
|
|
:fullscreen="true"
|
|
|
|
|
|
></web-view>
|
2025-08-01 14:30:51 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
2025-08-02 16:31:59 +08:00
|
|
|
|
import { getTopSafeAreaHeightAsync } from '@utils/common';
|
2025-08-29 17:09:47 +08:00
|
|
|
|
import { checkUpdate, downloadAndInstallUpdate, showUpdateDialog } from '@utils/updateService';
|
2025-08-02 19:52:12 +08:00
|
|
|
|
const TYPE_EMUE = {
|
|
|
|
|
|
CONNECT: 0,
|
|
|
|
|
|
DATA: 1,
|
|
|
|
|
|
FUNCTION: 2,
|
2025-08-02 19:58:49 +08:00
|
|
|
|
CONFIG: 3,
|
2025-08-02 19:52:12 +08:00
|
|
|
|
}
|
2025-08-01 14:30:51 +08:00
|
|
|
|
export default {
|
|
|
|
|
|
data() {
|
|
|
|
|
|
return {
|
2025-08-02 17:10:41 +08:00
|
|
|
|
baseUrl: 'https://kr-op.quwanzhi.com/init',
|
2025-08-02 11:32:04 +08:00
|
|
|
|
iframeUrl: '', // 动态构建的 URL
|
2025-08-01 16:29:34 +08:00
|
|
|
|
receivedMessages: [],
|
|
|
|
|
|
messageId: 0,
|
2025-08-29 17:09:47 +08:00
|
|
|
|
urlParams: {},
|
|
|
|
|
|
appVersion: '1.0.0',
|
|
|
|
|
|
updateApiUrl: 'https://ckbapi.quwanzhi.com/app/update?type=ckb' // 更新检查API地址
|
2025-08-01 14:30:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
onLoad() {
|
2025-08-02 19:58:49 +08:00
|
|
|
|
this.sendBaseConfig()
|
2025-08-29 17:09:47 +08:00
|
|
|
|
// 检查更新
|
|
|
|
|
|
this.checkAppUpdate()
|
2025-08-01 14:30:51 +08:00
|
|
|
|
},
|
|
|
|
|
|
methods: {
|
2025-08-02 11:32:04 +08:00
|
|
|
|
// 构建 iframe URL,包含参数
|
|
|
|
|
|
buildIframeUrl() {
|
2025-08-02 16:31:59 +08:00
|
|
|
|
const params = [];
|
2025-08-02 11:32:04 +08:00
|
|
|
|
Object.keys(this.urlParams).forEach(key => {
|
|
|
|
|
|
const value = this.urlParams[key];
|
|
|
|
|
|
if (value !== null && value !== undefined) {
|
|
|
|
|
|
const encodedKey = encodeURIComponent(key);
|
|
|
|
|
|
const encodedValue = encodeURIComponent(String(value));
|
|
|
|
|
|
params.push(`${encodedKey}=${encodedValue}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
const queryString = params.join('&');
|
|
|
|
|
|
this.iframeUrl = queryString ? `${this.baseUrl}?${queryString}` : this.baseUrl;
|
|
|
|
|
|
},
|
2025-08-02 14:43:08 +08:00
|
|
|
|
// 发送消息到 iframe(通过URL传参)
|
2025-08-02 19:58:49 +08:00
|
|
|
|
async sendBaseConfig() {
|
2025-08-02 19:52:12 +08:00
|
|
|
|
const message = {
|
2025-08-02 19:58:49 +08:00
|
|
|
|
type: TYPE_EMUE.CONFIG,
|
2025-08-02 19:52:12 +08:00
|
|
|
|
data: {
|
2025-08-02 19:58:49 +08:00
|
|
|
|
paddingTop: await getTopSafeAreaHeightAsync(),
|
|
|
|
|
|
appId: '1234567890',
|
|
|
|
|
|
appName: '存客宝',
|
2025-08-29 17:09:47 +08:00
|
|
|
|
appVersion: this.appVersion,
|
2025-08-05 11:59:18 +08:00
|
|
|
|
isAppMode:true
|
2025-08-02 19:52:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 将消息添加到URL参数中
|
|
|
|
|
|
this.urlParams.message = encodeURIComponent(JSON.stringify(message));
|
|
|
|
|
|
this.buildIframeUrl();
|
|
|
|
|
|
console.log('[App]SendMessage=>\n' + JSON.stringify(message));
|
|
|
|
|
|
},
|
2025-08-01 16:29:34 +08:00
|
|
|
|
// 接收 web-view 发送的消息
|
|
|
|
|
|
handleMessage(event) {
|
2025-08-02 19:52:12 +08:00
|
|
|
|
console.log("event", event);
|
2025-08-02 16:31:59 +08:00
|
|
|
|
const [ResDetail] = event.detail.data;
|
|
|
|
|
|
this.receivedMessages.push(`[${new Date().toLocaleTimeString()}] ${JSON.stringify(ResDetail)}`);
|
2025-08-02 19:52:12 +08:00
|
|
|
|
|
|
|
|
|
|
switch (ResDetail.type) {
|
|
|
|
|
|
case TYPE_EMUE.DATA:
|
|
|
|
|
|
console.log('[App]ReceiveMessage=>\n' + JSON.stringify(ResDetail.data));
|
|
|
|
|
|
break;
|
|
|
|
|
|
case TYPE_EMUE.FUNCTION:
|
|
|
|
|
|
console.log('[App]ReceiveMessage=>\n' + JSON.stringify(ResDetail.data));
|
2025-08-05 11:59:18 +08:00
|
|
|
|
if (ResDetail.data.action === 'clearCache') {
|
|
|
|
|
|
this.clearCache();
|
|
|
|
|
|
}
|
2025-08-02 19:52:12 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
2025-08-02 11:32:04 +08:00
|
|
|
|
}
|
2025-08-05 11:59:18 +08:00
|
|
|
|
},
|
|
|
|
|
|
clearCache() {
|
|
|
|
|
|
// 清除 webview 缓存
|
|
|
|
|
|
if (this.$refs.webviewRef) {
|
|
|
|
|
|
// 重新加载 webview
|
|
|
|
|
|
this.$refs.webviewRef.reload();
|
|
|
|
|
|
}
|
|
|
|
|
|
// 清除 webview 缓存数据
|
|
|
|
|
|
uni.clearStorage({
|
|
|
|
|
|
success: () => {
|
|
|
|
|
|
console.log('Webview 缓存已清除');
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2025-08-29 17:09:47 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 检查应用更新
|
|
|
|
|
|
*/
|
|
|
|
|
|
checkAppUpdate() {
|
|
|
|
|
|
console.log('检查应用更新...');
|
|
|
|
|
|
checkUpdate({
|
|
|
|
|
|
currentVersion: this.appVersion,
|
|
|
|
|
|
apiUrl: this.updateApiUrl,
|
|
|
|
|
|
onSuccess: (result) => {
|
|
|
|
|
|
if (result.hasUpdate) {
|
|
|
|
|
|
console.log(`发现新版本: ${result.version}`);
|
|
|
|
|
|
// 显示更新对话框
|
|
|
|
|
|
showUpdateDialog(result, () => {
|
|
|
|
|
|
this.downloadUpdate(result.downloadUrl);
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
console.log('当前已是最新版本');
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
onError: (errorMsg, error) => {
|
|
|
|
|
|
console.error(`检查更新失败: ${errorMsg}`, error);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
2025-08-05 11:59:18 +08:00
|
|
|
|
|
2025-08-29 17:09:47 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 下载并安装更新
|
|
|
|
|
|
* @param {String} downloadUrl 下载地址
|
|
|
|
|
|
*/
|
|
|
|
|
|
downloadUpdate(downloadUrl) {
|
|
|
|
|
|
// 显示下载进度
|
|
|
|
|
|
uni.showLoading({
|
|
|
|
|
|
title: '正在下载更新...',
|
|
|
|
|
|
mask: true
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
downloadAndInstallUpdate({
|
|
|
|
|
|
downloadUrl,
|
|
|
|
|
|
onProgress: (progress) => {
|
|
|
|
|
|
uni.showLoading({
|
|
|
|
|
|
title: `正在下载更新...${progress}%`,
|
|
|
|
|
|
mask: true
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
|
|
|
|
|
onSuccess: () => {
|
|
|
|
|
|
uni.hideLoading();
|
|
|
|
|
|
// 安装成功或跳转到应用商店成功
|
|
|
|
|
|
console.log('更新下载成功,准备安装');
|
|
|
|
|
|
},
|
|
|
|
|
|
onError: (errorMsg, error) => {
|
|
|
|
|
|
uni.hideLoading();
|
|
|
|
|
|
console.error(`更新失败: ${errorMsg}`, error);
|
|
|
|
|
|
uni.showToast({
|
|
|
|
|
|
title: `更新失败: ${errorMsg}`,
|
|
|
|
|
|
icon: 'none',
|
|
|
|
|
|
duration: 2000
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2025-08-01 16:29:34 +08:00
|
|
|
|
}
|
2025-08-02 14:43:08 +08:00
|
|
|
|
}
|
2025-08-01 14:30:51 +08:00
|
|
|
|
}
|
2025-08-02 20:41:02 +08:00
|
|
|
|
</script>
|