| | |
| | | <template> |
| | | <web-view :src="src" @message="viewMessage"/> |
| | | <web-view :src="src" @message="viewMessage" :allow="allow"/> |
| | | </template> |
| | | |
| | | |
| | | <script setup> |
| | | |
| | | const src = defineModel('src') |
| | | const emit = defineEmits(['webMessage']) |
| | | |
| | | 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' |
| | | data: { |
| | | data: { |
| | | arg: event.detail.data[0], |
| | | }, |
| | | type: "WEB_INVOKE_APPSERVICE", |
| | | }, |
| | | }); |
| | | } |
| | | |
| | | // WEB_INVOKE_APPSERVICE |
| | | |
| | | |
| | | // 下载图片一次 |
| | | function oneImageDownload(url) { |
| | | return new Promise((resolve, reject) => { |
| | | wx.downloadFile({ |
| | | url, |
| | | success: (res) => { |
| | | wx.saveImageToPhotosAlbum({ |
| | | filePath: res.tempFilePath, |
| | | success: function (res) { |
| | | resolve() |
| | | }, |
| | | }); |
| | | }, |
| | | }); |
| | | }) |
| | | } |
| | | // WEB_INVOKE_APPSERVICE |
| | | function messageFun(e) { |
| | | if(e.data.type === 'WEB_INVOKE_APPSERVICE'){ |
| | | if (e.data.data.arg.type === 'tokenExpired'){ |
| | | return uni.redirectTo({ |
| | | url: '/pages/login/index' |
| | | }) |
| | | |
| | | // 多次图片下载 |
| | | function multipleImageDownloads(all){ |
| | | // const downloadUrlList = [ |
| | | // // 'https://wrj.shuixiongit.com/aiskyminioTwo/cloud-bucket//089a4039-9c98-4441-abb7-1f9ac56caa8c/DJI_202604270944_002_089a4039-9c98-4441-abb7-1f9ac56caa8c/%E8%BD%A6AI20260427100047007.jpeg', |
| | | // // 'https://aisky.org.cn/command-center-dashboard/assets/zhddpt-BgsJ8s7S.png', |
| | | // 'https://wrj.shuixiongit.com/aiskyminioTwo/cloud-bucket/8d9ba6b4-d255-4f49-b3f8-bdeaf99773b4/DJI_202602121039_002_8d9ba6b4-d255-4f49-b3f8-bdeaf99773b4-flyto/DJI_20260212104641_0003_V.mp4' |
| | | // ] |
| | | const downloadUrlList = all.map(item => { |
| | | return item.replace('aiskyminio', 'aiskyminioTwo') |
| | | }) |
| | | const async = ['https://aisky.org.cn/command-center-dashboard/assets/zhddpt-BgsJ8s7S.png'].map(item => oneImageDownload(item)) |
| | | return Promise.all(async) |
| | | } |
| | | |
| | | // 公共图片下载 |
| | | function publicImageDownloads(data) { |
| | | wx.getSetting({ |
| | | success(res) { |
| | | if (res?.authSetting?.['scope.writePhotosAlbum']) { |
| | | multipleImageDownloads(data.urlList) |
| | | }else{ |
| | | wx.authorize({ |
| | | scope: 'scope.writePhotosAlbum', |
| | | success() { |
| | | multipleImageDownloads(data.urlList) |
| | | } |
| | | }) |
| | | } |
| | | } |
| | | emit('webMessage', e.data.data.arg) |
| | | }) |
| | | } |
| | | |
| | | |
| | | // 公共定位 |
| | | function publicPosit(data) { |
| | | wx.openLocation({ |
| | | latitude: data.latitude, |
| | | longitude: data.longitude, |
| | | name: data.name, |
| | | address: data.name, |
| | | scale: 18 |
| | | }) |
| | | } |
| | | |
| | | |
| | | function messageFun(e) { |
| | | if (e.data.type === "WEB_INVOKE_APPSERVICE") { |
| | | const {type,data} = e.data.data.arg |
| | | if (type === "tokenExpired") { |
| | | uni.reLaunch({url: "/pages/login/index"}); |
| | | }else if(type === "wxImageDownload"){ |
| | | publicImageDownloads(data) |
| | | }else if(type === "wxOpenLocation"){ |
| | | publicPosit(data) |
| | | }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(() => { |
| | | window.addEventListener('message', messageFun) |
| | | }) |
| | | if (window && window.addEventListener) |
| | | window.addEventListener("message", messageFun); |
| | | }); |
| | | onHide(() => { |
| | | window.removeEventListener('message', messageFun) |
| | | }) |
| | | |
| | | |
| | | if (window && window.removeEventListener) |
| | | window.removeEventListener("message", messageFun); |
| | | }); |
| | | </script> |
| | | |
| | | <style scoped lang="scss"> |
| | | |
| | | </style> |
| | | <style scoped lang="scss"></style> |