addnetconfirm
This commit is contained in:
parent
a7bc5506de
commit
951aabfe55
102
App.vue
102
App.vue
@ -1,40 +1,76 @@
|
||||
<script>
|
||||
export default {
|
||||
methods:{
|
||||
networkStatusChange(res){
|
||||
if(res.isConnected){
|
||||
uni.redirectTo({
|
||||
url:'/pages/index/index'
|
||||
})
|
||||
}else{
|
||||
uni.redirectTo({
|
||||
url:'/pages/networko/index'
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
onLaunch: function() {
|
||||
},
|
||||
onShow: function() {
|
||||
uni.getNetworkType({
|
||||
success:(res)=> {
|
||||
if(res.networkType==='none') {
|
||||
uni.redirectTo({
|
||||
url: '/pages/networko/index'
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
})
|
||||
uni.onNetworkStatusChange(this.networkStatusChange);
|
||||
},
|
||||
onHide: function() {
|
||||
uni.offNetworkStatusChange(this.networkStatusChange)
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
// 上一次网络状态
|
||||
lastNetworkStatus: null
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
// 判断是否是第一次安装APP并且打开
|
||||
isFirstOpen(){
|
||||
let isFirstOpen = uni.getStorageSync('isFirstOpen')
|
||||
if (!isFirstOpen) {
|
||||
uni.setStorageSync('isFirstOpen', true)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
},
|
||||
networkStatusChange(res) {
|
||||
if (res.isConnected) {
|
||||
// 如果是第一次安装进入,并且网络状态为有网络,则跳转到主页
|
||||
if (this.isFirstOpen()) {
|
||||
uni.redirectTo({
|
||||
url: '/pages/index/index'
|
||||
})
|
||||
}
|
||||
// 如果上一次网络状态为无网络,且当前网络状态为有网络,则跳转到首页
|
||||
if (this.lastNetworkStatus === false) {
|
||||
uni.showModal({
|
||||
title: "提示",
|
||||
content: "当前设备网络发生更改,是否刷新页面?",
|
||||
success: function (res) {
|
||||
if (res.confirm) {
|
||||
uni.redirectTo({
|
||||
url: '/pages/index/index'
|
||||
})
|
||||
} else if (res.cancel) {
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
} else {
|
||||
uni.redirectTo({
|
||||
url: '/pages/networko/index'
|
||||
})
|
||||
}
|
||||
this.lastNetworkStatus = res.isConnected
|
||||
|
||||
}
|
||||
},
|
||||
onLaunch: function () {
|
||||
},
|
||||
onShow: function () {
|
||||
uni.onNetworkStatusChange(this.networkStatusChange);
|
||||
uni.getNetworkType({
|
||||
success: (res) => {
|
||||
if (res.networkType === 'none') {
|
||||
uni.redirectTo({
|
||||
url: '/pages/networko/index'
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
},
|
||||
onHide: function () {
|
||||
uni.offNetworkStatusChange(this.networkStatusChange)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
/*每个页面公共css */
|
||||
/*每个页面公共css */
|
||||
</style>
|
||||
|
@ -2,7 +2,7 @@ const env = 'prod';
|
||||
const configs = {
|
||||
LocalTest: {
|
||||
apiBaseUrl: 'https://warehouse.szjixun.cn/oa_backend',
|
||||
h5Url:'http://192.168.88.29:8080/#/'
|
||||
h5Url:'http://192.168.88.30:8080/#/'
|
||||
},
|
||||
dev: {
|
||||
apiBaseUrl: 'https://warehouse.szjixun.cn/oa_backend',
|
||||
|
@ -4,89 +4,96 @@
|
||||
</template>
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import {onExit } from "@dcloudio/uni-app";
|
||||
import { onExit, onShow, onLoad } from "@dcloudio/uni-app";
|
||||
import config from "../../config"
|
||||
const wv = plus.webview.create(config.h5Url,"custom-webview")
|
||||
const currentPages=getCurrentPages()
|
||||
const currentWebview = currentPages[currentPages.length-1].$getAppWebview()
|
||||
currentWebview.append(wv)
|
||||
const {statusBarHeight} = uni.getSystemInfoSync()
|
||||
wv.setStyle({
|
||||
top: statusBarHeight,
|
||||
bottom: 0,
|
||||
onShow(() => {
|
||||
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)
|
||||
})
|
||||
import { Communication } from '../../utils/communication.js';
|
||||
const commun=new Communication()
|
||||
const commun = new Communication()
|
||||
|
||||
import {
|
||||
registerRequestPermissionTipsListener,
|
||||
unregisterRequestPermissionTipsListener,
|
||||
setRequestPermissionTips
|
||||
} from "@/uni_modules/uni-registerRequestPermissionTips"
|
||||
import {
|
||||
registerRequestPermissionTipsListener,
|
||||
unregisterRequestPermissionTipsListener,
|
||||
setRequestPermissionTips
|
||||
} from "@/uni_modules/uni-registerRequestPermissionTips"
|
||||
|
||||
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(()=>{
|
||||
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()
|
||||
})
|
||||
|
||||
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});
|
||||
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: "权限已经被拒绝,请前往设置中开启"
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
// 华为手机在权限禁止之后,再次申请权限不会出现权限申请框。此时应该引导用户去系统设置开启此权限,不应该频繁申请。
|
||||
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: "权限已经被拒绝,请前往设置中开启"
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
function initializeWebView() {
|
||||
const currentWebview = getCurrentPages().pop().$getAppWebview()
|
||||
commun.setWebView(currentWebview.children()[0])
|
||||
}
|
||||
//load-complete 注册函数
|
||||
commun.registerHandler('load-complete',()=>{
|
||||
commun.registerHandler('load-complete', () => {
|
||||
initializeWebView()
|
||||
const {statusBarHeight} = uni.getSystemInfoSync()
|
||||
const { statusBarHeight } = uni.getSystemInfoSync()
|
||||
commun.webViewObj.setStyle({
|
||||
top: statusBarHeight,
|
||||
bottom: 0,
|
||||
})
|
||||
|
||||
})
|
||||
commun.registerHandler('getLocation',(data)=>{
|
||||
commun.registerHandler('getLocation', (data) => {
|
||||
uni.getLocation({
|
||||
type:'gcj02',
|
||||
geocode:true,
|
||||
isHighAccuracy:true,
|
||||
type: 'gcj02',
|
||||
geocode: true,
|
||||
isHighAccuracy: true,
|
||||
...data,
|
||||
success: (res) => {
|
||||
console.log('getLocation',res)
|
||||
commun.sendToH5('getLocation',res);
|
||||
console.log('getLocation', res)
|
||||
commun.sendToH5('getLocation', res);
|
||||
},
|
||||
})
|
||||
})
|
||||
@ -96,6 +103,4 @@ const webLoad = (e) => {
|
||||
};
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
||||
</style>
|
||||
<style></style>
|
||||
|
Loading…
Reference in New Issue
Block a user