|
|
@@ -0,0 +1,225 @@
|
|
|
+/**
|
|
|
+ * 在线更新日志弹窗组件
|
|
|
+ * 参考WebIndex.ets的成功实现,确保WebView正常工作
|
|
|
+ */
|
|
|
+import { webview } from '@kit.ArkWeb';
|
|
|
+import { UpdateConstants } from '../common/constants/UpdateConstants';
|
|
|
+import { UpdateLogManager } from '../common/util/UpdateLogManager';
|
|
|
+import { ConfigurationConstant } from '@kit.AbilityKit';
|
|
|
+import { AppUtil } from '@pura/harmony-utils';
|
|
|
+
|
|
|
+@CustomDialog
|
|
|
+export default struct OnlineUpdateLogDialog {
|
|
|
+ /** 弹窗控制器 */
|
|
|
+ controller: CustomDialogController;
|
|
|
+ /** 更新日志URL */
|
|
|
+ @State updateLogUrl: string = '';
|
|
|
+ /** 当前应用版本 */
|
|
|
+ @State currentVersion: string = '';
|
|
|
+ /** WebView控制器 */
|
|
|
+ private webViewController: webview.WebviewController = new webview.WebviewController();
|
|
|
+ /** 是否加载完成 */
|
|
|
+ @State isLoading: boolean = true;
|
|
|
+ /** 加载错误信息 */
|
|
|
+ @State errorMessage: string = '';
|
|
|
+ /** 加载进度 */
|
|
|
+ @State progressValue: number = 0;
|
|
|
+ /** 进度条是否可见 */
|
|
|
+ @State progressVisible: boolean = true;
|
|
|
+ /** 深色模式 */
|
|
|
+ @State isDarkMode: boolean = false;
|
|
|
+ @StorageProp('currentColorMode') currentMode: number = ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT;
|
|
|
+
|
|
|
+ aboutToAppear() {
|
|
|
+ // 获取当前应用版本
|
|
|
+ this.getCurrentVersion();
|
|
|
+ // 设置更新日志URL - 直接使用在线URL
|
|
|
+ this.updateLogUrl = UpdateConstants.UPDATE_LOG_URL;
|
|
|
+ // 检查深色模式
|
|
|
+ this.isDarkMode = this.currentMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK;
|
|
|
+
|
|
|
+ console.info('OnlineUpdateLogDialog URL:', this.updateLogUrl);
|
|
|
+ console.info('OnlineUpdateLogDialog 开始加载在线更新日志');
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取当前应用版本号
|
|
|
+ */
|
|
|
+ private getCurrentVersion() {
|
|
|
+ try {
|
|
|
+ this.currentVersion = AppUtil.getVersionName()//UpdateConstants.APP_VERSION;
|
|
|
+ } catch (error) {
|
|
|
+ this.currentVersion = '1.0.0';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 记录已显示的版本,避免重复显示
|
|
|
+ */
|
|
|
+ private markVersionShown() {
|
|
|
+ UpdateLogManager.markCurrentVersionShown();
|
|
|
+ }
|
|
|
+
|
|
|
+ build() {
|
|
|
+ Column() {
|
|
|
+ // 标题栏
|
|
|
+ Row() {
|
|
|
+ Text('更新日志')
|
|
|
+ .fontSize(18)
|
|
|
+ .fontWeight(FontWeight.Bold)
|
|
|
+ .fontColor(Color.White)
|
|
|
+ .layoutWeight(1)
|
|
|
+
|
|
|
+ Text('关闭')
|
|
|
+ .fontSize(14)
|
|
|
+ .fontColor(Color.White)
|
|
|
+ .padding({ left: 12, right: 12, top: 6, bottom: 6 })
|
|
|
+ .borderRadius(4)
|
|
|
+ .backgroundColor('rgba(255,255,255,0.2)')
|
|
|
+ .onClick(() => {
|
|
|
+ this.markVersionShown();
|
|
|
+ this.controller.close();
|
|
|
+ })
|
|
|
+ }
|
|
|
+ .width('100%')
|
|
|
+ .height(48)
|
|
|
+ .padding({ left: 20, right: 20 })
|
|
|
+ .backgroundColor('#2196F3')
|
|
|
+ .justifyContent(FlexAlign.SpaceBetween)
|
|
|
+ .alignItems(VerticalAlign.Center)
|
|
|
+
|
|
|
+ // 版本信息和进度条
|
|
|
+ Column() {
|
|
|
+ Text(`当前版本:v${this.currentVersion}`)
|
|
|
+ .fontSize(12)
|
|
|
+ .fontColor(Color.Gray)
|
|
|
+ .alignSelf(ItemAlign.Start)
|
|
|
+ .margin({ bottom: 8 })
|
|
|
+
|
|
|
+ // 进度条 - 参考WebIndex.ets的实现
|
|
|
+ if (this.progressVisible && this.progressValue < 100) {
|
|
|
+ Progress({ value: this.progressValue, total: 100, type: ProgressType.Linear })
|
|
|
+ .width('100%')
|
|
|
+ .height(3)
|
|
|
+ .color('#2196F3')
|
|
|
+ .backgroundColor('#E0E0E0')
|
|
|
+ }
|
|
|
+ }
|
|
|
+ .width('100%')
|
|
|
+ .padding({ left: 20, right: 20, top: 12, bottom: 8 })
|
|
|
+
|
|
|
+ // WebView内容区域 - 完全参考WebIndex.ets的实现
|
|
|
+ if (this.errorMessage) {
|
|
|
+ // 错误状态
|
|
|
+ Column() {
|
|
|
+ Text('❌')
|
|
|
+ .fontSize(48)
|
|
|
+
|
|
|
+ Text('加载失败')
|
|
|
+ .fontSize(16)
|
|
|
+ .fontColor(Color.Black)
|
|
|
+ .margin({ top: 12 })
|
|
|
+
|
|
|
+ Text(this.errorMessage)
|
|
|
+ .fontSize(12)
|
|
|
+ .fontColor(Color.Gray)
|
|
|
+ .margin({ top: 4 })
|
|
|
+ .textAlign(TextAlign.Center)
|
|
|
+
|
|
|
+ Button('重试')
|
|
|
+ .fontSize(14)
|
|
|
+ .backgroundColor('#2196F3')
|
|
|
+ .margin({ top: 16 })
|
|
|
+ .onClick(() => {
|
|
|
+ this.errorMessage = '';
|
|
|
+ this.isLoading = true;
|
|
|
+ this.progressValue = 0;
|
|
|
+ this.progressVisible = true;
|
|
|
+ // 重新加载
|
|
|
+ this.webViewController.refresh();
|
|
|
+ })
|
|
|
+ }
|
|
|
+ .width('100%')
|
|
|
+ .height(350)
|
|
|
+ .justifyContent(FlexAlign.Center)
|
|
|
+ .alignItems(HorizontalAlign.Center)
|
|
|
+ .padding(20)
|
|
|
+ } else {
|
|
|
+ // WebView内容 - 完全按照WebIndex.ets的方式实现
|
|
|
+ Web({
|
|
|
+ src: this.updateLogUrl,
|
|
|
+ controller: this.webViewController
|
|
|
+ })
|
|
|
+ .width('100%')
|
|
|
+ .height(350)
|
|
|
+ .darkMode(this.isDarkMode ? WebDarkMode.On : WebDarkMode.Off)
|
|
|
+ .forceDarkAccess(this.isDarkMode)
|
|
|
+ .onProgressChange((event) => {
|
|
|
+ if (event) {
|
|
|
+ console.info('OnlineUpdateLogDialog WebView进度:', event.newProgress);
|
|
|
+ this.progressValue = event.newProgress;
|
|
|
+
|
|
|
+ // 进度完成时隐藏进度条
|
|
|
+ if (event.newProgress >= 100) {
|
|
|
+ setTimeout(() => {
|
|
|
+ this.progressVisible = false;
|
|
|
+ this.isLoading = false;
|
|
|
+ }, 500);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .onPageBegin(() => {
|
|
|
+ console.info('OnlineUpdateLogDialog WebView开始加载:', this.updateLogUrl);
|
|
|
+ this.isLoading = true;
|
|
|
+ this.errorMessage = '';
|
|
|
+ this.progressValue = 0;
|
|
|
+ this.progressVisible = true;
|
|
|
+ })
|
|
|
+ .onPageEnd(() => {
|
|
|
+ console.info('OnlineUpdateLogDialog WebView加载完成');
|
|
|
+ this.isLoading = false;
|
|
|
+ setTimeout(() => {
|
|
|
+ this.progressVisible = false;
|
|
|
+ }, 1000);
|
|
|
+ })
|
|
|
+ .onErrorReceive((event) => {
|
|
|
+ const errorInfo = event?.error?.getErrorInfo() || '网络错误';
|
|
|
+ console.error('OnlineUpdateLogDialog WebView加载错误:', errorInfo);
|
|
|
+ this.isLoading = false;
|
|
|
+ this.progressVisible = false;
|
|
|
+ this.errorMessage = `加载失败:${errorInfo}`;
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ // 底部按钮
|
|
|
+ Row() {
|
|
|
+ Button('稍后查看')
|
|
|
+ .fontSize(14)
|
|
|
+ .backgroundColor('#9E9E9E')
|
|
|
+ .fontColor(Color.White)
|
|
|
+ .layoutWeight(1)
|
|
|
+ .onClick(() => {
|
|
|
+ this.controller.close();
|
|
|
+ })
|
|
|
+
|
|
|
+ Blank().width(12)
|
|
|
+
|
|
|
+ Button('知道了')
|
|
|
+ .fontSize(14)
|
|
|
+ .backgroundColor('#2196F3')
|
|
|
+ .fontColor(Color.White)
|
|
|
+ .layoutWeight(1)
|
|
|
+ .onClick(() => {
|
|
|
+ this.markVersionShown();
|
|
|
+ this.controller.close();
|
|
|
+ })
|
|
|
+ }
|
|
|
+ .width('100%')
|
|
|
+ .padding({ left: 20, right: 20, top: 16, bottom: 16 })
|
|
|
+ }
|
|
|
+ .backgroundColor(Color.White)
|
|
|
+ .borderRadius(12)
|
|
|
+ .width('92%')
|
|
|
+ .constraintSize({ maxHeight: '85%' })
|
|
|
+ }
|
|
|
+}
|