当前位置: 首页 > news >正文

Arkts加载网页url的pdf发票黑屏问题

使用模拟器会闪退,连接真机预览正常

import { HMRouter, HMRouterMgr, HMParamType, HMPageParam } from "@hadss/hmrouter";
import { BaseTitle, RouterConstants } from "commonlib";
import { webview } from '@kit.ArkWeb';
import { PDFView } from '@hjm/pdfview'
import { ImagePreview } from "@rv/image-preview";/*发票PDF查看界面*/
@HMRouter({ pageUrl: RouterConstants.INVOICE_PDF_PAGE})
@ComponentV2
export struct InvoicePDFPage {@Local invoiceUrl: string = ''; // 直接存储URLprivate webviewController: WebviewController = new webview.WebviewController()private scroller: Scroller = new Scroller()aboutToAppear(): void {// 获取传递的参数let param = HMRouterMgr.getCurrentParam(HMParamType.all);// 安全地访问参数try {const paramStr = JSON.stringify(param);console.log('接收到的参数:', paramStr);// 使用字符串匹配提取URLconst match = paramStr.match(/"invoiceUrl"\s*:\s*"([^"]+)"/);if (match && match[1]) {this.invoiceUrl = match[1];// 解码可能的URL转义字符try {this.invoiceUrl = decodeURIComponent(this.invoiceUrl);} catch (e) {// 如果解码失败,使用原始URL}console.log('提取到的发票URL:', this.invoiceUrl);} else {console.log('未找到invoiceUrl字段');}} catch (e) {console.log('参数处理失败:', e);}}build() {Column() {BaseTitle({showBackBtn: true,customTitle: this.titleBuilder,bgColor: $r('app.color.title_primary_bg'),onBack: () => {HMRouterMgr.pop()}})Scroll(this.scroller){Column(){if (this.invoiceUrl && this.invoiceUrl.length > 0) {ImagePreview() {PDFView({/* 数据源 */pdfUrl: this.invoiceUrl,})}// 不使用任何可能不存在的额外属性} else {Column() {Text("发票链接无效").fontSize($r('app.float.16_font')).fontColor($r('app.color.tips_font'))}.width('100%').height('100%').justifyContent(FlexAlign.Center)}}}}.width('100%').height('100%')}@BuildertitleBuilder() {Row() {Text($r('app.string.invoice_pdf_title')).fontSize($r('app.float.20_font')).fontColor($r('app.color.title_primary_font'))}.width('100%').justifyContent(FlexAlign.Center)}
}

http://www.dtcms.com/a/337060.html

相关文章:

  • vscode wsl解决需要用别的用户调试的问题
  • 国产化Excel处理组件Spire.XLS教程:使用 C# 从数据库导出数据到 Excel(含 SQL 示例)
  • Android使用Kotlin协程+Flow实现打字机效果
  • 【内网渗透】CVE-2020-0796 永恒之黑 复现
  • 19.8 《3步实现OPT-6.7B无损量化:用自定义数据集省70%显存,精度仅跌2.3%》
  • (Arxiv-2025)OPENS2V-NEXUS:一个面向主体到视频生成的详细基准与百万规模数据集
  • 设计模式笔记_行为型_迭代器模式
  • 云计算核心技术之容器技术
  • Linux设备树简介
  • LINUX 818 shell:random;for for
  • 电子元器件-电阻终篇:基本原理,电阻分类及特点,参数/手册详解,电阻作用及应用场景,电阻选型及实战案例
  • Docker常见指令速查
  • 矿物分类案例(二)数据填充后使用6种模型训练
  • Docker学习--认识Docker
  • 遥感机器学习入门实战教程 | Sklearn 案例②:PCA + k-NN 分类与评估
  • AWS Neptune:图数据库的强大潜力
  • 【LLM1】大型语言模型的基本生成机制
  • 将 iPhone 连接到 Windows 11 的完整指南
  • Chromium base 库中的 Observer 模式实现:ObserverList 与 ObserverListThreadSafe 深度解析
  • AI 在金融领域的落地案例
  • 强化学习-CH2 状态价值和贝尔曼等式
  • 算法详细讲解:数据结构 - 单链表与双链表
  • Nacos-6--Naco的QUIC协议实现高可用的工作原理
  • cesium中实时获取鼠标精确坐标和高度
  • IB数学课程知识点有哪些?IB数学课程辅导机构怎么选?
  • GitLab 安全漏洞 CVE-2025-7739 解决方案
  • GitLab 安全漏洞 CVE-2025-6186 解决方案
  • AI全链路赋能:smardaten2.0实现软件开发全流程智能化突破
  • Leetcode 3651. Minimum Cost Path with Teleportations
  • 嵌入式 C++ 语言编程规范文档个人学习版(参考《Google C++ 编码规范中文版》)