|
@@ -1,6 +1,6 @@
|
|
|
import web_webview from '@ohos.web.webview';
|
|
|
import webview from '@ohos.web.webview';
|
|
|
-import { router } from '@kit.ArkUI';
|
|
|
+import { router, WebHeader } from '@kit.ArkUI';
|
|
|
import { XDialogController } from '../dialog/XDialogController';
|
|
|
import { XDialogList } from '../dialog/XDialogList';
|
|
|
import { picker } from '@kit.CoreFileKit';
|
|
@@ -16,6 +16,7 @@ import { XWebManager } from '../utils/XWebManager';
|
|
|
@Component
|
|
|
export struct XWebview {
|
|
|
// 手机号
|
|
|
+ @State headers?: Array<WebHeader> = (router.getParams() as XWebParams).headers
|
|
|
@State url?: string = (router.getParams() as XWebParams).url
|
|
|
@State zoomAccess?: boolean = (router.getParams() as XWebParams).zoomAccess
|
|
|
@State content?: string = (router.getParams() as XWebParams).content
|
|
@@ -35,23 +36,6 @@ export struct XWebview {
|
|
|
SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.XWebViewCLose, undefined)
|
|
|
webview.WebviewController.setWebDebuggingAccess(true);
|
|
|
|
|
|
- if (this.content) {
|
|
|
- try {
|
|
|
- this.controller.loadData(this.content,
|
|
|
- "text/html",
|
|
|
- "UTF-8", '', '')
|
|
|
- } catch (e) {
|
|
|
- ToolsHelper.showAlertDialog({
|
|
|
- title: '警告',
|
|
|
- msg: e.message ?? '加载内容失败',
|
|
|
- action: {
|
|
|
- onClick: () => {
|
|
|
- router.back()
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- }
|
|
|
if (this._uuidToHtml) {
|
|
|
XWebManager.addOnMessageToHtml(this._uuidToHtml, (msg) => {
|
|
|
if (this.ports && this.ports[1]) {
|
|
@@ -208,10 +192,42 @@ export struct XWebview {
|
|
|
this.controller.postMessage('__init_port__', [this.ports[0]], '*');
|
|
|
})
|
|
|
.onControllerAttached(() => {
|
|
|
+ if (this.content) {
|
|
|
+ try {
|
|
|
+ this.controller.loadData(this.content,
|
|
|
+ "text/html",
|
|
|
+ "UTF-8", '', '')
|
|
|
+ } catch (e) {
|
|
|
+ ToolsHelper.showAlertDialog({
|
|
|
+ title: '警告',
|
|
|
+ msg: e.message ?? '加载内容失败',
|
|
|
+ action: {
|
|
|
+ onClick: () => {
|
|
|
+ router.back()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ } else if (this.url) {
|
|
|
+ if (this.headers) {
|
|
|
+ this.controller.loadUrl(this.url, this.headers);
|
|
|
+ } else {
|
|
|
+ this.controller.loadUrl(this.url);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ToolsHelper.showAlertDialog({
|
|
|
+ title: '警告',
|
|
|
+ msg: '请传入url或content',
|
|
|
+ action: {
|
|
|
+ onClick: () => {
|
|
|
+ router.back()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
try {
|
|
|
let userAgent = this.controller.getUserAgent() + '/szyx_sdk';
|
|
|
this.controller.setCustomUserAgent(userAgent);
|
|
|
- // this.controller.runJavaScript('window.SZYX_YWX_WebViewBridge.onIsYwxApp()');
|
|
|
|
|
|
} catch (error) {
|
|
|
console.error(`ErrorCode: ${(error as BusinessError).code}, Message: ${(error as BusinessError).message}`);
|