1、UniMp下载逻辑优化
2、UniMpManager管理加载类型
This commit is contained in:
shenzuqiang 2026-05-13 13:35:23 +08:00
parent 833f229bd4
commit e6a26c4c5f
12 changed files with 504 additions and 482 deletions

View File

@ -43,12 +43,12 @@
"arkOptions": { "arkOptions": {
"buildProfileFields": { "buildProfileFields": {
"CHANNEL": "harmony", "CHANNEL": "harmony",
"BUILD_TIME": "2605120917" "BUILD_TIME": "2605131158"
} }
} }
}, },
"output": { "output": {
"artifactName": "rabbit_harmony_debug_v1.0.0_2605120917" "artifactName": "rabbit_harmony_debug_v1.0.0_2605131158"
} }
} }
], ],

View File

@ -6,7 +6,7 @@ export const BUILD_MODE_NAME = 'debug';
export const DEBUG = true; export const DEBUG = true;
export const TARGET_NAME = 'default'; export const TARGET_NAME = 'default';
export const CHANNEL = 'harmony'; export const CHANNEL = 'harmony';
export const BUILD_TIME = '2605120914'; export const BUILD_TIME = '2605131158';
/** /**
* BuildProfile Class is used only for compatibility purposes. * BuildProfile Class is used only for compatibility purposes.

View File

@ -2,7 +2,7 @@
export struct GlobalDownloadingDialog { export struct GlobalDownloadingDialog {
controller: CustomDialogController; controller: CustomDialogController;
@State show: boolean = false; @State show: boolean = false;
@State progress: number = 0; @Link progress: number;
build() { build() {
Stack() { Stack() {

View File

@ -3,7 +3,7 @@ import { AESDecrypt, PLATFORM, RELEASE_BASE_URL, Signature, TOKEN } from '../con
import { ToastUtils } from '../dialog/ToastUtils' import { ToastUtils } from '../dialog/ToastUtils'
import { UniVersionEntity,TradeData, UniIconEntity } from '../viewmodel/DataBean' import { UniVersionEntity,TradeData, UniIconEntity } from '../viewmodel/DataBean'
import { downloadFile } from './DownloaderUtils' import { downloadFile } from './DownloaderUtils'
import { isUniMpNeedDownload, isUniMpNeedDownloadForPath } from './KVManager' import { isUniMpNeedDownload, isUniMpNeedDownloadForPath, setUniMpNeedDownload } from './KVManager'
import { KVStore } from './KVStore' import { KVStore } from './KVStore'
import { Logger } from './Logger' import { Logger } from './Logger'
import { bundleManager, common } from '@kit.AbilityKit' import { bundleManager, common } from '@kit.AbilityKit'
@ -29,37 +29,37 @@ export function downStartUp(context: UIContext, entity: UniVersionEntity, callba
callback(1, 0) callback(1, 0)
//需要更新则删除旧文件重新下载wgt文件 //需要更新则删除旧文件重新下载wgt文件
if(!uniMpId){ if(!uniMpId){
ToastUtils.showToast(context, '加载失败,请重试或联系客服!') ToastUtils.showToast(context, '加载失败,请重试或联系客服!');
callback(-1, 0) callback(-1, 0);
return return
} }
//下载模拟器 //下载模拟器
downloadFile(getContext(), uniMpUrl??'', uniMpId + '.wgt', (status, progress, path) => { downloadFile(getContext(), uniMpUrl??'', uniMpId + '.wgt', (status, progress, path) => {
if(status == 2){ if(status == 2){
callback(status, progress, path) callback(status, progress, path);
//已下载完成,释放并启动 //已下载完成,释放并启动
releaseRunUniMp(context, uniMpId??'', '', (status) => { releaseRunUniMp(context, uniMpId??'', '', (status) => {
callback(status, progress, path) callback(status, progress, path);
}) })
}else if(status == -1){ }else if(status == -1){
ToastUtils.showToast(context, '加载失败,请重试或联系客服!') ToastUtils.showToast(context, '加载失败,请重试或联系客服!');
callback(status, progress, path) callback(status, progress, path);
}else{ }else{
callback(status, progress, path) callback(status, progress, path);
} }
Logger.info('UniMp','downloadFile status:' + status + ', progress:' + progress) Logger.info('UniMp','downloadFile status:' + status + ', progress:' + progress);
}) })
}else{ }else{
//不需要更新,已释放则直接打开模拟器,否则先释放,再打开 //不需要更新,已释放则直接打开模拟器,否则先释放,再打开
runUniMp(context, uniMpId??'', '', (status) => { runUniMp(context, uniMpId??'', '', (status) => {
callback(status, 100) callback(status, 100);
}) })
} }
}); });
} }
Logger.info('UniMp','uniMpId:'+uniMpId+ ', uniMpType:' + uniMpType + ', uniMpUrl:' + uniMpUrl + ', uniMpVersion:' + uniVersion) Logger.info('UniMp','uniMpId:'+uniMpId+ ', uniMpType:' + uniMpType + ', uniMpUrl:' + uniMpUrl + ', uniMpVersion:' + uniVersion);
} }
export function downStartUpForPath(context: UIContext, uniMpVersions: UniVersionEntity[], uniIconEntity: UniIconEntity, callback: (status: number, progress: number, path?: string) => void) { export function downStartUpForPath(context: UIContext, uniMpVersions: UniVersionEntity[], uniIconEntity: UniIconEntity, callback: (status: number, progress: number, path?: string) => void) {
@ -68,31 +68,34 @@ export function downStartUpForPath(context: UIContext, uniMpVersions: UniVersion
return item.unimp_type === uniMpType; return item.unimp_type === uniMpType;
}); });
const targetPath = uniIconEntity.url??'' const targetPath = uniIconEntity.url??'';
const uniMpUrl = uniMpEntity?.url??''//'https://cdn.batiao8.com/flaunt/uni_mp/wgt/alipay/__UNI__D535736_2026-4-20-test4.wgt'; const uniMpUrl = uniMpEntity?.url??'';//'https://cdn.batiao8.com/flaunt/uni_mp/wgt/alipay/__UNI__D535736_2026-4-20-test4.wgt';
const uniMpId = uniMpEntity?.unimp_id??'' const uniMpId = uniMpEntity?.unimp_id??'';
const uniMpversion = uniMpEntity?.version??'';
isUniMpNeedDownloadForPath(uniMpId).then(res => { isUniMpNeedDownloadForPath(uniMpId).then(res => {
if(res == true){ if(res == true){
// 已释放,直接运行 // 已释放,直接运行
runUniMp(context, uniMpId??'', '', (status) => { runUniMp(context, uniMpId??'', '', (status) => {
callback(status, 100) callback(status, 100);
}) })
}else{ }else{
// 未下载,先下载释放,再运行 // 未下载,先下载释放,再运行
downloadFile(getContext(), uniMpUrl??'', uniMpId + '.wgt', (status, progress, path) => { downloadFile(getContext(), uniMpUrl??'', uniMpId + '.wgt', (status, progress, path) => {
if(status == 2){ if(status == 2){
callback(status, progress, path) // 设置下载的版本信信
setUniMpNeedDownload(uniMpId??'', uniMpType??'', uniMpversion??'', path??'');
callback(status, progress, path);
// 已下载完成,释放并启动 // 已下载完成,释放并启动
releaseRunUniMp(context, uniMpId??'', targetPath, (status) => { releaseRunUniMp(context, uniMpId??'', targetPath, (status) => {
callback(status, progress, path) callback(status, progress, path);
}) })
}else if(status == -1){ }else if(status == -1){
ToastUtils.showToast(context, '加载失败,请重试或联系客服!') ToastUtils.showToast(context, '加载失败,请重试或联系客服!')
callback(status, progress, path) callback(status, progress, path);
}else{ }else{
callback(status, progress, path) callback(status, progress, path);
} }
Logger.info('UniMp','downloadFile status:' + status + ', progress:' + progress) Logger.info('UniMp','downloadFile status:' + status + ', progress:' + progress);
}) })
} }
}); });
@ -144,7 +147,9 @@ export function releaseRunUniMp(context: UIContext, uniMpId: string, targetPath:
mp.on('uniMPEvent', (event: string, data: object, _notify: boolean) => { mp.on('uniMPEvent', (event: string, data: object, _notify: boolean) => {
Logger.info('UniMp', 'uniMPEvent:' + event + ', data:' + data) Logger.info('UniMp', 'uniMPEvent:' + event + ', data:' + data)
if(event === 'start_combo_pay'){ if(event === 'openUniAPP'){
//渲染完成
}else if(event === 'start_combo_pay'){
const jsonStr = typeof data === 'string' ? data : JSON.stringify(data); const jsonStr = typeof data === 'string' ? data : JSON.stringify(data);
const obj = JSON.parse(jsonStr) as TradeData; const obj = JSON.parse(jsonStr) as TradeData;

View File

@ -1,3 +1,4 @@
// entry/src/main/ets/view/SplashWxUniMpView.ets
@Component @Component
export struct SplashWxUniMpView { export struct SplashWxUniMpView {
build() { build() {
@ -5,6 +6,8 @@ export struct SplashWxUniMpView {
Image($r('app.media.ic_splash_wx_unimp')) Image($r('app.media.ic_splash_wx_unimp'))
.width('100%') .width('100%')
.height('100%') .height('100%')
.objectFit(ImageFit.Cover) // 建议使用 Cover 保持无白边拉伸
.syncLoad(true) // 关键:强制同步解码,防止在窗口出现时闪烁白屏
} }
.width('100%') .width('100%')
.height('100%') .height('100%')

View File

@ -6,7 +6,7 @@ export const BUILD_MODE_NAME = 'debug';
export const DEBUG = true; export const DEBUG = true;
export const TARGET_NAME = 'default'; export const TARGET_NAME = 'default';
export const CHANNEL = 'harmony'; export const CHANNEL = 'harmony';
export const BUILD_TIME = '2605120914'; export const BUILD_TIME = '2605131158';
/** /**
* BuildProfile Class is used only for compatibility purposes. * BuildProfile Class is used only for compatibility purposes.

View File

@ -6,7 +6,7 @@ export const BUILD_MODE_NAME = 'debug';
export const DEBUG = true; export const DEBUG = true;
export const TARGET_NAME = 'default'; export const TARGET_NAME = 'default';
export const CHANNEL = 'harmony'; export const CHANNEL = 'harmony';
export const BUILD_TIME = '2605120914'; export const BUILD_TIME = '2605131158';
/** /**
* BuildProfile Class is used only for compatibility purposes. * BuildProfile Class is used only for compatibility purposes.

View File

@ -3,7 +3,7 @@ import { AESDecrypt, PLATFORM, RELEASE_BASE_URL, Signature, TOKEN } from '../con
import { ToastUtils } from '../dialog/ToastUtils' import { ToastUtils } from '../dialog/ToastUtils'
import { UniVersionEntity,TradeData, UniIconEntity } from '../viewmodel/DataBean' import { UniVersionEntity,TradeData, UniIconEntity } from '../viewmodel/DataBean'
import { downloadFile } from './DownloaderUtils' import { downloadFile } from './DownloaderUtils'
import { isUniMpNeedDownload, isUniMpNeedDownloadForPath } from './KVManager' import { isUniMpNeedDownload, isUniMpNeedDownloadForPath, setUniMpNeedDownload } from './KVManager'
import { KVStore } from './KVStore' import { KVStore } from './KVStore'
import { Logger } from './Logger' import { Logger } from './Logger'
import { bundleManager, common } from '@kit.AbilityKit' import { bundleManager, common } from '@kit.AbilityKit'
@ -29,37 +29,37 @@ export function downStartUp(context: UIContext, entity: UniVersionEntity, callba
callback(1, 0) callback(1, 0)
//需要更新则删除旧文件重新下载wgt文件 //需要更新则删除旧文件重新下载wgt文件
if(!uniMpId){ if(!uniMpId){
ToastUtils.showToast(context, '加载失败,请重试或联系客服!') ToastUtils.showToast(context, '加载失败,请重试或联系客服!');
callback(-1, 0) callback(-1, 0);
return return
} }
//下载模拟器 //下载模拟器
downloadFile(getContext(), uniMpUrl??'', uniMpId + '.wgt', (status, progress, path) => { downloadFile(getContext(), uniMpUrl??'', uniMpId + '.wgt', (status, progress, path) => {
if(status == 2){ if(status == 2){
callback(status, progress, path) callback(status, progress, path);
//已下载完成,释放并启动 //已下载完成,释放并启动
releaseRunUniMp(context, uniMpId??'', '', (status) => { releaseRunUniMp(context, uniMpId??'', '', (status) => {
callback(status, progress, path) callback(status, progress, path);
}) })
}else if(status == -1){ }else if(status == -1){
ToastUtils.showToast(context, '加载失败,请重试或联系客服!') ToastUtils.showToast(context, '加载失败,请重试或联系客服!');
callback(status, progress, path) callback(status, progress, path);
}else{ }else{
callback(status, progress, path) callback(status, progress, path);
} }
Logger.info('UniMp','downloadFile status:' + status + ', progress:' + progress) Logger.info('UniMp','downloadFile status:' + status + ', progress:' + progress);
}) })
}else{ }else{
//不需要更新,已释放则直接打开模拟器,否则先释放,再打开 //不需要更新,已释放则直接打开模拟器,否则先释放,再打开
runUniMp(context, uniMpId??'', '', (status) => { runUniMp(context, uniMpId??'', '', (status) => {
callback(status, 100) callback(status, 100);
}) })
} }
}); });
} }
Logger.info('UniMp','uniMpId:'+uniMpId+ ', uniMpType:' + uniMpType + ', uniMpUrl:' + uniMpUrl + ', uniMpVersion:' + uniVersion) Logger.info('UniMp','uniMpId:'+uniMpId+ ', uniMpType:' + uniMpType + ', uniMpUrl:' + uniMpUrl + ', uniMpVersion:' + uniVersion);
} }
export function downStartUpForPath(context: UIContext, uniMpVersions: UniVersionEntity[], uniIconEntity: UniIconEntity, callback: (status: number, progress: number, path?: string) => void) { export function downStartUpForPath(context: UIContext, uniMpVersions: UniVersionEntity[], uniIconEntity: UniIconEntity, callback: (status: number, progress: number, path?: string) => void) {
@ -68,31 +68,34 @@ export function downStartUpForPath(context: UIContext, uniMpVersions: UniVersion
return item.unimp_type === uniMpType; return item.unimp_type === uniMpType;
}); });
const targetPath = uniIconEntity.url??'' const targetPath = uniIconEntity.url??'';
const uniMpUrl = uniMpEntity?.url??''//'https://cdn.batiao8.com/flaunt/uni_mp/wgt/alipay/__UNI__D535736_2026-4-20-test4.wgt'; const uniMpUrl = uniMpEntity?.url??'';//'https://cdn.batiao8.com/flaunt/uni_mp/wgt/alipay/__UNI__D535736_2026-4-20-test4.wgt';
const uniMpId = uniMpEntity?.unimp_id??'' const uniMpId = uniMpEntity?.unimp_id??'';
const uniMpversion = uniMpEntity?.version??'';
isUniMpNeedDownloadForPath(uniMpId).then(res => { isUniMpNeedDownloadForPath(uniMpId).then(res => {
if(res == true){ if(res == true){
// 已释放,直接运行 // 已释放,直接运行
runUniMp(context, uniMpId??'', '', (status) => { runUniMp(context, uniMpId??'', '', (status) => {
callback(status, 100) callback(status, 100);
}) })
}else{ }else{
// 未下载,先下载释放,再运行 // 未下载,先下载释放,再运行
downloadFile(getContext(), uniMpUrl??'', uniMpId + '.wgt', (status, progress, path) => { downloadFile(getContext(), uniMpUrl??'', uniMpId + '.wgt', (status, progress, path) => {
if(status == 2){ if(status == 2){
callback(status, progress, path) // 设置下载的版本信信
setUniMpNeedDownload(uniMpId??'', uniMpType??'', uniMpversion??'', path??'');
callback(status, progress, path);
// 已下载完成,释放并启动 // 已下载完成,释放并启动
releaseRunUniMp(context, uniMpId??'', targetPath, (status) => { releaseRunUniMp(context, uniMpId??'', targetPath, (status) => {
callback(status, progress, path) callback(status, progress, path);
}) })
}else if(status == -1){ }else if(status == -1){
ToastUtils.showToast(context, '加载失败,请重试或联系客服!') ToastUtils.showToast(context, '加载失败,请重试或联系客服!')
callback(status, progress, path) callback(status, progress, path);
}else{ }else{
callback(status, progress, path) callback(status, progress, path);
} }
Logger.info('UniMp','downloadFile status:' + status + ', progress:' + progress) Logger.info('UniMp','downloadFile status:' + status + ', progress:' + progress);
}) })
} }
}); });
@ -144,7 +147,9 @@ export function releaseRunUniMp(context: UIContext, uniMpId: string, targetPath:
mp.on('uniMPEvent', (event: string, data: object, _notify: boolean) => { mp.on('uniMPEvent', (event: string, data: object, _notify: boolean) => {
Logger.info('UniMp', 'uniMPEvent:' + event + ', data:' + data) Logger.info('UniMp', 'uniMPEvent:' + event + ', data:' + data)
if(event === 'start_combo_pay'){ if(event === 'openUniAPP'){
//渲染完成
}else if(event === 'start_combo_pay'){
const jsonStr = typeof data === 'string' ? data : JSON.stringify(data); const jsonStr = typeof data === 'string' ? data : JSON.stringify(data);
const obj = JSON.parse(jsonStr) as TradeData; const obj = JSON.parse(jsonStr) as TradeData;

View File

@ -1,3 +1,4 @@
// entry/src/main/ets/view/SplashWxUniMpView.ets
@Component @Component
export struct SplashWxUniMpView { export struct SplashWxUniMpView {
build() { build() {
@ -5,6 +6,8 @@ export struct SplashWxUniMpView {
Image($r('app.media.ic_splash_wx_unimp')) Image($r('app.media.ic_splash_wx_unimp'))
.width('100%') .width('100%')
.height('100%') .height('100%')
.objectFit(ImageFit.Cover) // 建议使用 Cover 保持无白边拉伸
.syncLoad(true) // 关键:强制同步解码,防止在窗口出现时闪烁白屏
} }
.width('100%') .width('100%')
.height('100%') .height('100%')

View File

@ -26,7 +26,7 @@
{ {
"name": "default", "name": "default",
"output": { "output": {
"artifactName": "rabbit_harmony_v1.0.0_26512917" "artifactName": "rabbit_harmony_v1.0.0_265131158"
} }
}, },
{ {

View File

@ -54,8 +54,10 @@ struct Index {
} }
build() { build() {
Column() { Stack() {
NavigationPage(); NavigationPage();
} }
.width('100%')
.height('100%')
} }
} }

View File

@ -120,6 +120,7 @@ export struct HomeComponent {
build() { build() {
// 父容器 Column 默认从顶部开始排列 // 父容器 Column 默认从顶部开始排列
Stack(){
Column() { Column() {
List() { List() {
// 顶部图片 // 顶部图片
@ -573,6 +574,9 @@ export struct HomeComponent {
.width('100%') .width('100%')
.height('100%') .height('100%')
.justifyContent(FlexAlign.Start) // 确保在父容器中靠顶 .justifyContent(FlexAlign.Start) // 确保在父容器中靠顶
}
} }
// 计算 Grid 需要的高度:(行数 * 每行高度) + (行数-1 * 间距) // 计算 Grid 需要的高度:(行数 * 每行高度) + (行数-1 * 间距)