Files
lucky_shop/stub-app-projects/mp-quickapp/com.test.cc/src/Hello/hello.ux
ZF sun a32cedad9e feat(mp-quickapp): 配置统一域名与uniacid,优化缓存与页面刷新
1.  新增集中配置项管理BASE_URL和UNIACID
2.  动态生成带时间戳的加载URL与UA避免缓存
3.  后台切回前台时自动刷新web页面
4.  调整打包版本号与构建产物配置
2026-07-15 16:52:51 +08:00

118 lines
3.9 KiB
XML

<template>
<div class="doc-page">
<web class="web-page" src="{{loadUrl}}" trustedurl="{{list}}" onpagestart="onPageStart" onpagefinish="onPageFinish"
onmessage="onMessage" ontitlereceive="onTitleReceive" onerror="onError" id="web" supportzoom="{{supportZoom}}"
wideviewport="{{wideViewport}}" overviewmodeinload="{{overViewModeLoad}}" useragent="{{userAgent}}"
allowthirdpartycookies="{{allowThirdPartyCookies}}" multiwindow="{{multiwindow}}" jumppolicy="{{jumppolicy}}" xrequestedwithpolicy="{{packagename}}">
</web>
</div>
</template>
<style>
.doc-page {
flex-direction: column;
flex-direction: column;
justify-content: center;
align-content: center;
align-items: center;
width: 100%;
height: 100%;
position: fixed;
}
.web-page {
width: 100%;
height: 100%;
}
</style>
<script>
import router from "@system.router";
// === 集中配置:URL 域名与 uniacid 在这里统一修改 ===
const CONFIG = {
BASE_URL: "https://xcx.aigc-quickapp.com/hwappx/common",
UNIACID: "2482",
};
export default {
props: ['websrc'],
private: {
title: "",
// 启动时由 onInit 读取顶部 CONFIG 生成,实际值不要在这里改
nonce: '',
loadUrl: "",
allowThirdPartyCookies: true,
supportZoom: true,
wideViewport: true,
overViewModeLoad: true,
userAgent: "",
packagename:'coma',
list: ["new RegExp('https?.*')"],
multiwindow: false,
jumppolicy: 'default',
},
config: {
showNavigationBar: false,
navigationBar: {
titleText: '页面标题'
}
},
onMenuPress(){
},
onInit() {
this.$page.setTitleBar({ text: '自定义导航栏' })
// 集中配置 + 缓存穿透 nonce:URL 和 userAgent 都从顶部 CONFIG 拼出
this.nonce = String(Date.now());
this.loadUrl = CONFIG.BASE_URL + '?nocache=' + this.nonce;
this.userAgent = 'uniacid=' + CONFIG.UNIACID + '; nocache=' + this.nonce;
console.info('onInit: ', this.loadUrl, this.userAgent);
},
setCookie(){
},
onPageStart(e) {
console.info('pagestart: ' + e.url)
},
onPageFinish(e) {
console.info('pagefinish: ' + e.url, e.canBack, e.canForward);
},
onTitleReceive(e) {
this.title = e.title;
},
onError(e) {
console.info('pageError : ' + e.errorMsg)
},
onMessage(e) {
console.info('11223333'+'onmessage e = ' + e.message + ", url = " + e.url);
},
onShow: function () {
console.info(" onshow");
// 后台切回前台:重新刷新一次,确保拉取最新资源
var web = this.$element('web');
if (web && typeof web.reload === 'function') {
web.reload();
} else if (web && typeof web.refresh === 'function') {
web.refresh();
}
},
onHide: function () {
console.info(" onHide");
},
onBackPress() {
console.log('onBackPress')
this.$element('web').canBack({
callback: function (e) {
if (e) {
console.log('web back')
this.$element('web').back()
} else {
console.log('router back')
router.back()
}
}.bind(this)
})
return true
}
}
</script>