罗广辉
2026-04-27 4a17f2242c6cfcf0ca3f3056f0b53ff15235bdf9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<template>
  <web-view :src="src" @message="viewMessage" :allow="allow"/>
</template>
 
 
<script setup>
 
 
const allow = "accelerometer;ambient-light-sensor;autoplay;battery;camera;clipboard-read;clipboard-write;cross-origin-isolated;display-capture;document-domain;encrypted-media;execution-while-not-rendered;execution-while-out-of-viewport;fullscreen;gamepad;geolocation;gyroscope;hid;idle-detection;local-fonts;magnetometer;microphone;midi;payment;picture-in-picture;publickey-credentials-get;screen-wake-lock;serial;speaker-selection;storage-access;sync-xhr;usb;web-share;xr-spatial-tracking"
const src = defineModel("src");
const emit = defineEmits(["webMessage"]);
 
function viewMessage(event) {
  messageFun({
    data: {
      data: {
        arg: event.detail.data[0],
      },
      type: "WEB_INVOKE_APPSERVICE",
    },
  });
}
 
// WEB_INVOKE_APPSERVICE
function messageFun(e) {
  if (e.data.type === "WEB_INVOKE_APPSERVICE") {
    const {type,data} = e.data.data.arg
    if (type === "tokenExpired") {
      return uni.reLaunch({url: "/pages/login/index"});
    }else if(type === "wxOpenLocation"){
      return wx.openLocation({
        latitude: data.latitude,
        longitude: data.longitude,
        name: data.name,
        address: data.name,
        scale: 18
      })
    }else{
      emit("webMessage", e.data.data.arg);
    }
  }
}
 
 
onLoad((obj) => {
  // const h5Params = obj?.cs && JSON.parse(obj?.cs)
  // console.log('h5Params', h5Params)
  // h5Params && viewMessage({detail: {data: [h5Params.data]}})
})
 
onShow(() => {
  if (window && window.addEventListener)
    window.addEventListener("message", messageFun);
});
onHide(() => {
  if (window && window.removeEventListener)
    window.removeEventListener("message", messageFun);
});
</script>
 
<style scoped lang="scss"></style>