You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
205 lines
6.2 KiB
205 lines
6.2 KiB
|
2 years ago
|
<template>
|
||
|
|
<view class="container">
|
||
|
|
<view id="mapContrainer" style="width: 100wh; height: 100vh; background-color: red;"></view>
|
||
|
|
<view class="intro">本项目已包含uni ui组件,无需import和注册,可直接使用。在代码区键入字母u,即可通过代码助手列出所有可用组件。光标置于组件名称处按F1,即可查看组件文档。</view>
|
||
|
|
<text class="intro">详见:</text>
|
||
|
|
<!-- <navigator url="/pages/gisUpload/gisUpload" hover-class="navigator-hover" style="margin-bottom: 20upx;">
|
||
|
|
<button type="default">地图上报gis</button>
|
||
|
|
</navigator> -->
|
||
|
|
<navigator url="/pages/form/form" hover-class="navigator-hover" style="margin-bottom: 20upx;">
|
||
|
|
<button type="default">form组件</button>
|
||
|
|
</navigator>
|
||
|
|
<navigator url="/pages/form1/form1" hover-class="navigator-hover" style="margin-bottom: 20upx;">
|
||
|
|
<button type="default">form原生组件</button>
|
||
|
|
</navigator>
|
||
|
|
<button @click="onShowNotify" type="default" style="margin-bottom: 20upx;">常驻通知保活</button>
|
||
|
|
<button @click="onAutoStart" type="default" style="margin-bottom: 20upx;">设置自启动、后台运行</button>
|
||
|
|
<button @click="goIgnoreBattery" type="default">电池优化设置</button>
|
||
|
|
</view>
|
||
|
|
</template>
|
||
|
|
|
||
|
|
<script>
|
||
|
|
export default {
|
||
|
|
data() {
|
||
|
|
return {
|
||
|
|
keepAlive: null
|
||
|
|
}
|
||
|
|
},
|
||
|
|
onLoad() {
|
||
|
|
var map = new jsmapbase.JSMap({
|
||
|
|
container:'mapContainer',
|
||
|
|
mapServerURL:'./data/map'
|
||
|
|
});
|
||
|
|
console.log(map)
|
||
|
|
map.openMapById('0001');
|
||
|
|
this.keepAlive = uni.requireNativePlugin('Ba-KeepAliveSuit')
|
||
|
|
this.getPermis()
|
||
|
|
setTimeout(() => {
|
||
|
|
this.onKeep();
|
||
|
|
}, 5000);
|
||
|
|
setTimeout(() => {
|
||
|
|
this.onShowNotify();
|
||
|
|
}, 10000);
|
||
|
|
},
|
||
|
|
methods: {
|
||
|
|
getPermis() {
|
||
|
|
// // console.log("我是安卓", plus.android);
|
||
|
|
// var main = plus.android.runtimeMainActivity();
|
||
|
|
// var pkName = main.getPackageName();
|
||
|
|
// var uid = main.getApplicationInfo().plusGetAttribute("uid");
|
||
|
|
// var NotificationManagerCompat = plus.android.importClass(
|
||
|
|
// "android.support.v4.app.NotificationManagerCompat"
|
||
|
|
// );
|
||
|
|
// //android.support.v4升级为androidx
|
||
|
|
// if (NotificationManagerCompat == null) {
|
||
|
|
// NotificationManagerCompat = plus.android.importClass(
|
||
|
|
// "androidx.core.app.NotificationManagerCompat"
|
||
|
|
// );
|
||
|
|
// }
|
||
|
|
// var areNotificationsEnabled =
|
||
|
|
// NotificationManagerCompat.from(main).areNotificationsEnabled();
|
||
|
|
// // 未开通‘允许通知’权限,则弹窗提醒开通,并点击确认后,跳转到系统设置页面进行设置
|
||
|
|
// if (!areNotificationsEnabled) {
|
||
|
|
// uni.showModal({
|
||
|
|
// title: '提示',
|
||
|
|
// content: '请先打开APP通知权限',
|
||
|
|
// showCancel: false,
|
||
|
|
// success: () => {
|
||
|
|
// if (res.confirm) {
|
||
|
|
// var Intent = plus.android.importClass("android.content.Intent");
|
||
|
|
// var Build = plus.android.importClass("android.os.Build");
|
||
|
|
// //android 8.0引导
|
||
|
|
// if (Build.VERSION.SDK_INT >= 26) { //判断安卓系统版本
|
||
|
|
// var intent = new Intent("android.settings.APP_NOTIFICATION_SETTINGS");
|
||
|
|
// intent.putExtra("android.provider.extra.APP_PACKAGE", pkName);
|
||
|
|
// } else if (Build.VERSION.SDK_INT >= 21) { //判断安卓系统版本
|
||
|
|
// //android 5.0-7.0
|
||
|
|
// var intent = new Intent("android.settings.APP_NOTIFICATION_SETTINGS");
|
||
|
|
// intent.putExtra("app_package", pkName);
|
||
|
|
// intent.putExtra("app_uid", uid);
|
||
|
|
// } else {
|
||
|
|
// //(<21)其他--跳转到该应用管理的详情页
|
||
|
|
// intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||
|
|
// var uri = Uri.fromParts(
|
||
|
|
// "package",
|
||
|
|
// mainActivity.getPackageName(),
|
||
|
|
// null
|
||
|
|
// );
|
||
|
|
// intent.setData(uri);
|
||
|
|
// }
|
||
|
|
// // 跳转到该应用的系统通知设置页
|
||
|
|
// main.startActivity(intent);
|
||
|
|
// }
|
||
|
|
// }
|
||
|
|
// })
|
||
|
|
// }
|
||
|
|
},
|
||
|
|
onKeep() { //通用保活
|
||
|
|
this.keepAlive.onKeep({
|
||
|
|
//channelId: "Ba-KeepAlive",
|
||
|
|
//channelName: "Ba-KeepAlive",
|
||
|
|
title: "测试",
|
||
|
|
content: "常驻通知描述",
|
||
|
|
},
|
||
|
|
(res) => {
|
||
|
|
console.log(res);
|
||
|
|
uni.showToast({
|
||
|
|
title: res.msg,
|
||
|
|
icon: "none",
|
||
|
|
duration: 3000
|
||
|
|
})
|
||
|
|
});
|
||
|
|
},
|
||
|
|
onAutoStart() { //去设置自启动、后台运行
|
||
|
|
this.keepAlive.onAutoStart(
|
||
|
|
(res) => {
|
||
|
|
console.log(res);
|
||
|
|
uni.showToast({
|
||
|
|
title: res.msg,
|
||
|
|
icon: "none",
|
||
|
|
duration: 3000
|
||
|
|
})
|
||
|
|
});
|
||
|
|
},
|
||
|
|
requestIgnoreBattery() { //申请加入电池优化白名单
|
||
|
|
this.keepAlive.requestIgnoreBattery(
|
||
|
|
res => {
|
||
|
|
console.log(res);
|
||
|
|
uni.showToast({
|
||
|
|
title: res.msg,
|
||
|
|
icon: "none",
|
||
|
|
duration: 3000
|
||
|
|
})
|
||
|
|
});
|
||
|
|
},
|
||
|
|
goIgnoreBattery() { //跳转到电池优化设置页
|
||
|
|
this.keepAlive.goIgnoreBattery(
|
||
|
|
res => {
|
||
|
|
console.log(res);
|
||
|
|
uni.showToast({
|
||
|
|
title: res.msg,
|
||
|
|
icon: "none",
|
||
|
|
duration: 3000
|
||
|
|
})
|
||
|
|
});
|
||
|
|
},
|
||
|
|
isIgnoringBattery() { //是否加入电池优化白名单
|
||
|
|
this.keepAlive.isIgnoringBattery(
|
||
|
|
res => {
|
||
|
|
console.log(res);
|
||
|
|
// if (res.data) {
|
||
|
|
// this.msgList.unshift(JSON.stringify(res.data))
|
||
|
|
// this.msgList.unshift(dateUtil.now())
|
||
|
|
// }
|
||
|
|
uni.showToast({
|
||
|
|
title: res.msg,
|
||
|
|
icon: "none",
|
||
|
|
duration: 3000
|
||
|
|
})
|
||
|
|
});
|
||
|
|
},
|
||
|
|
onShowNotify() { //常驻通知保活
|
||
|
|
this.keepAlive.onShowNotify({
|
||
|
|
//channelId: "Ba-KeepAlive",
|
||
|
|
//channelName: "Ba-KeepAlive",
|
||
|
|
ID: 99,
|
||
|
|
title: "一楼202室无线入侵",
|
||
|
|
content: "一楼202室无线入侵报警",
|
||
|
|
},
|
||
|
|
(res) => {
|
||
|
|
console.log(res);
|
||
|
|
uni.showToast({
|
||
|
|
title: res.msg,
|
||
|
|
icon: "none",
|
||
|
|
duration: 3000
|
||
|
|
})
|
||
|
|
});
|
||
|
|
},
|
||
|
|
onCancelNotify() { //取消常驻通知保活
|
||
|
|
this.keepAlive.onCancelNotify({
|
||
|
|
//channelId: "Ba-KeepAlive",
|
||
|
|
//channelName: "Ba-KeepAlive",
|
||
|
|
//ID:99
|
||
|
|
//title: "测试",
|
||
|
|
//content: "常驻通知描述",
|
||
|
|
},
|
||
|
|
(res) => {
|
||
|
|
console.log(res);
|
||
|
|
uni.showToast({
|
||
|
|
title: res.msg,
|
||
|
|
icon: "none",
|
||
|
|
duration: 3000
|
||
|
|
})
|
||
|
|
});
|
||
|
|
},
|
||
|
|
}
|
||
|
|
}
|
||
|
|
</script>
|
||
|
|
|
||
|
|
<style>
|
||
|
|
.container {
|
||
|
|
padding: 20px;
|
||
|
|
font-size: 14px;
|
||
|
|
line-height: 24px;
|
||
|
|
}
|
||
|
|
</style>
|