oa-base/pages/index/index.vue

152 lines
5.1 KiB
Vue
Raw Normal View History

2024-06-18 07:55:32 +00:00
<template>
2024-12-04 08:33:24 +00:00
<web-view class="webview" @message="webLoad" style="flex: 1;" :src="config.h5Url"></web-view>
2024-06-18 07:55:32 +00:00
</template>
<script setup>
2024-09-02 06:36:30 +00:00
import { ref } from 'vue'
2024-12-04 08:33:24 +00:00
import { onExit, onShow } from "@dcloudio/uni-app";
2024-10-18 02:29:02 +00:00
import config from "../../config"
2024-10-28 07:31:46 +00:00
onShow(() => {
2024-12-04 08:33:24 +00:00
// const { statusBarHeight } = uni.getSystemInfoSync()
// const wv1 = plus.webview.getWebviewById("custom-webview");
// let wv = null;
// if (wv1) {
// wv = wv1;
// } else {
// wv = plus.webview.create(config.h5Url, "custom-webview", {
// top: statusBarHeight,
// bottom: 0,
// });
// }
// const currentPages = getCurrentPages()
// const currentWebview = currentPages[currentPages.length - 1].$getAppWebview()
// currentWebview.append(wv)
})
2024-12-04 08:33:24 +00:00
// 监听收到推送消息
2024-09-02 06:36:30 +00:00
import { Communication } from '../../utils/communication.js';
2024-10-28 07:31:46 +00:00
const commun = new Communication()
2024-12-04 08:33:24 +00:00
const share = () => {
uni.getProvider({
service: "share",
success: (res) => {
console.log(res)
}
})
uni.share({
provider: 'weixin',
scene: "WXSceneSession",
type: 5,// 5代表分享为小程序
imageUrl: 'https://th.bing.com/th?id=ORMS.41c34644e7e67f95a14620e77064b5d9&pid=Wdp&w=268&h=140&qlt=90&c=1&rs=1&dpr=1&p=0', // 必填
title: '分享的标题',
miniProgram: {
id: "gh_97094c34debd",
path: "/pages/index/index",
type: 0,
webUrl: '/#/pages/list/detail',
},
success: function (res) {
console.log("success:" + JSON.stringify(res));
},
fail: function (err) {
console.log("fail:" + JSON.stringify(err));
}
});
2024-10-28 07:31:46 +00:00
}
2024-12-04 08:33:24 +00:00
const shareH5 = () => {
uni.share({
provider: 'weixin',
scene: "WXSceneSession",
type: 0,// 5代表分享为小程序
imageUrl: 'https://th.bing.com/th?id=ORMS.41c34644e7e67f95a14620e77064b5d9&pid=Wdp&w=268&h=140&qlt=90&c=1&rs=1&dpr=1&p=0', // 必填
title: '分享的标题',
href: 'https://www.baidu.com/',
success: function (res) {
console.log("success:" + JSON.stringify(res));
},
fail: function (err) {
console.log("fail:" + JSON.stringify(err));
}
});
}
// import {
// registerRequestPermissionTipsListener,
// unregisterRequestPermissionTipsListener,
// setRequestPermissionTips
// } from "@/uni_modules/uni-registerRequestPermissionTips"
2024-08-28 06:07:51 +00:00
2024-12-04 08:33:24 +00:00
// const PermissionTips = {
// "android.permission.READ_PHONE_STATE": "<h4 style=\"font-size:40px;\">正在读取网络状态权限</h4><font color=#cccccc>通讯录权限不会获取任何信息,请注意通讯录权限不会获取任何信息,请注意通讯录权限不会获取任何信息,请注意</font>",
// "android.permission.CAMERA": "<h4 style=\"font-size:40px;\">正在访问相机权限</h4><font color=#cccccc>需要扫描二维码或拍照,是否允许打开相机?</font>",
// "android.permission.WRITE_EXTERNAL_STORAGE": "<h4 style=\"font-size:40px;\">正在读取相册权限</h4><font color=#cccccc>我们需要获取访问您设备相册的权限,以便您能够选择并上传图片或视频到我们的应用中。</font>"
// }
// onExit(() => {
// unregisterRequestPermissionTipsListener()
// })
2024-08-28 06:07:51 +00:00
2024-12-04 08:33:24 +00:00
// const brand = uni.getSystemInfoSync().deviceBrand
// setRequestPermissionTips(PermissionTips)
// registerRequestPermissionTipsListener({
// onRequest: (e) => {
// console.log('onRequest', e)
// },
// onConfirm: (e) => {
// commun.sendToH5('permission-application', { action: 'open-permission', data: e });
// },
// onComplete: (e) => {
// commun.sendToH5('permission-application', { action: 'close-permission', data: e });
// // 华为手机在权限禁止之后,再次申请权限不会出现权限申请框。此时应该引导用户去系统设置开启此权限,不应该频繁申请。
// if (brand.toLowerCase() === "huawei") {
// const tips = {}
// let hasDeniedPermission = false
// for (let k in PermissionTips) {
// if (e[k] !== "denied") {
// tips[k] = PermissionTips[k]
// } else {
// hasDeniedPermission = true
// }
// }
// setRequestPermissionTips(tips) // 更新弹框提醒,防止华为手机不出现权限申请框时权限提醒框闪烁的情况
// if (hasDeniedPermission)
// uni.showModal({
// content: "权限已经被拒绝,请前往设置中开启"
// })
// }
// }
// })
2024-09-02 06:36:30 +00:00
function initializeWebView() {
const currentWebview = getCurrentPages().pop().$getAppWebview()
commun.setWebView(currentWebview.children()[0])
}
//load-complete 注册函数
2024-10-28 07:31:46 +00:00
commun.registerHandler('load-complete', () => {
2024-09-02 06:36:30 +00:00
initializeWebView()
2024-10-28 07:31:46 +00:00
const { statusBarHeight } = uni.getSystemInfoSync()
2024-09-02 06:36:30 +00:00
commun.webViewObj.setStyle({
top: statusBarHeight,
bottom: 0,
})
2024-08-28 06:07:51 +00:00
2024-09-02 06:36:30 +00:00
})
2024-10-28 07:31:46 +00:00
commun.registerHandler('getLocation', (data) => {
2024-09-02 06:36:30 +00:00
uni.getLocation({
2024-10-28 07:31:46 +00:00
type: 'gcj02',
geocode: true,
isHighAccuracy: true,
2024-09-02 06:36:30 +00:00
...data,
success: (res) => {
2024-10-28 07:31:46 +00:00
console.log('getLocation', res)
commun.sendToH5('getLocation', res);
2024-09-02 06:36:30 +00:00
},
})
})
const webLoad = (e) => {
const message = e.detail.data?.[0] || '';
commun.handleMessage(message);
};
2024-06-18 07:55:32 +00:00
</script>
2024-10-28 07:31:46 +00:00
<style></style>