Skip to content

Commit

Permalink
refactor(harmony): 调整webview使用新通讯方式和view层交互
Browse files Browse the repository at this point in the history
  • Loading branch information
Wangyaqi committed Sep 9, 2024
1 parent 4f03008 commit 03f1b67
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions packages/uni-app-harmony/src/view/components/web-view/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
useContextInfo,
useSubscribe,
} from '@dcloudio/uni-components'
import { capitalize, extend, isFunction } from '@vue/shared'
import { extend, isFunction } from '@vue/shared'
import { getCurrentPageId } from '@dcloudio/uni-core'
import { type Ref, onBeforeUnmount, onMounted, ref } from 'vue'
import { getRealPath } from '../../../platform/getRealPath'
Expand All @@ -30,20 +30,12 @@ function useMethods(embedRef: Ref<InstanceType<typeof Embed> | null>) {
data: any,
resolve: (res: any) => void
) {
// @ts-expect-error
const elId = embedRef.value!.elId
const pageId = getCurrentPageId() + ''
UniViewJSBridge.invokeServiceMethod(
'webview' + capitalize(methodName),
{
pageId,
elId,
data,
},
(res) => {
resolve(res)
}
)
const embed = embedRef.value!
if (methodName === 'evalJs') {
return resolve(embed['runJavaScript']((data || {}).jsCode || ''))
} else {
resolve(embed[methodName]())
}
}
}
function _handleSubscribe(
Expand Down Expand Up @@ -125,6 +117,7 @@ export default /*#__PURE__*/ defineBuiltInComponent({
updateTitle: props.updateTitle,
webviewStyles: props.webviewStyles,
}}
methods={['runJavaScript', 'back', 'forward', 'reload', 'stop']}
style="width:100%;height:100%"
/>
</uni-web-view>
Expand Down

0 comments on commit 03f1b67

Please sign in to comment.