This commit is contained in:
36
App.vue
36
App.vue
@@ -24,26 +24,26 @@
|
||||
|
||||
// 监听登录成功
|
||||
uni.$on("loginSuccess", () => {
|
||||
// NotifyPermission.ensurePermission(() => {
|
||||
// // 权限已开,执行你的逻辑
|
||||
// this.initWebSocket()
|
||||
// })
|
||||
this.initWebSocket()
|
||||
NotifyPermission.ensurePermission(() => {
|
||||
|
||||
})
|
||||
// // 仅在 Android 13+ 才需要
|
||||
if (plus.os.name === "Android" && parseInt(plus.os.version) >= 13) {
|
||||
var permission = "android.permission.POST_NOTIFICATIONS";
|
||||
// 请求权限
|
||||
plus.android.requestPermissions(
|
||||
[permission],
|
||||
(resultObj) => {
|
||||
this.initWebSocket()
|
||||
},
|
||||
(error) => {
|
||||
// if (plus.os.name === "Android" && parseInt(plus.os.version) >= 13) {
|
||||
// var permission = "android.permission.POST_NOTIFICATIONS";
|
||||
// // 请求权限
|
||||
// plus.android.requestPermissions(
|
||||
// [permission],
|
||||
// (resultObj) => {
|
||||
// this.initWebSocket()
|
||||
// },
|
||||
// (error) => {
|
||||
|
||||
}
|
||||
);
|
||||
} else {
|
||||
this.initWebSocket()
|
||||
}
|
||||
// }
|
||||
// );
|
||||
// } else {
|
||||
// this.initWebSocket()
|
||||
// }
|
||||
})
|
||||
//只有在基座运行的情况下才能打印看到
|
||||
const clientInfo = plus.push.getClientInfo()
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name" : "数字南川",
|
||||
"appid" : "__UNI__7AF1078",
|
||||
"appid" : "__UNI__DA9B8DE",
|
||||
"description" : "",
|
||||
"versionName" : "1.8.4",
|
||||
"versionCode" : "100",
|
||||
|
@@ -10,12 +10,12 @@
|
||||
<view class="login-form">
|
||||
<view class="input-row">
|
||||
<image class="iconfont" src="/static/ic_login_phone.png" />
|
||||
<input class="login-input" type="text" placeholder="输入手机号" v-model="username" />
|
||||
<input class="login-input" type="text" placeholder="请输入账号" v-model="username" />
|
||||
</view>
|
||||
<view class="input-row">
|
||||
<image class="iconfont2" src="/static/ic_login_code.png" />
|
||||
<input class="login-input" type="text" placeholder="请输入验证码" v-model="password" />
|
||||
<button class="code-btn">获取校验码</button>
|
||||
<input class="login-input" type="text" placeholder="请输入密码" v-model="password" />
|
||||
<!-- <button class="code-btn">获取校验码</button> -->
|
||||
</view>
|
||||
<view class="protocol-row">
|
||||
<label class="custom-checkbox-label">
|
||||
@@ -38,10 +38,12 @@
|
||||
import base64 from '@/common/base64.js';
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
return {
|
||||
// username: 'admin',
|
||||
// password: 'admin123',
|
||||
phoneNo: '',
|
||||
username: 'admin',
|
||||
password: 'admin123',
|
||||
username: '',
|
||||
password: '',
|
||||
loginType: 'currentPhone',
|
||||
showPassword: false,
|
||||
remember: true,
|
||||
@@ -62,7 +64,11 @@
|
||||
this.getUserInfo()
|
||||
},
|
||||
methods: {
|
||||
async submit() {
|
||||
async submit() {
|
||||
if(!this.checked){
|
||||
this.$u.toast('请先同意用户协议和隐私政策');
|
||||
return;
|
||||
}
|
||||
if (this.username.length == 0) {
|
||||
this.$u.toast('请输入账号');
|
||||
return;
|
||||
@@ -184,8 +190,8 @@
|
||||
.iconfont {
|
||||
font-size: 32rpx;
|
||||
margin-right: 16rpx;
|
||||
width: 27rpx;
|
||||
height: 43rpx;
|
||||
width: 35rpx;
|
||||
height: 35rpx;
|
||||
}
|
||||
|
||||
.iconfont2 {
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 847 B After Width: | Height: | Size: 6.2 KiB |
@@ -1,66 +1,73 @@
|
||||
// utils/notification-permission.js
|
||||
export default {
|
||||
// 检查通知权限
|
||||
checkPermission(callback) {
|
||||
if (plus.os.name !== "Android") {
|
||||
callback(true) // iOS 默认返回 true,另外可以用 APNs 检查
|
||||
return
|
||||
}
|
||||
// 检查通知权限
|
||||
checkPermission(callback) {
|
||||
if (plus.os.name !== "Android") {
|
||||
callback(true) // iOS 这里直接返回 true
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
let NotificationManagerCompat = plus.android.importClass("androidx.core.app.NotificationManagerCompat")
|
||||
let context = plus.android.runtimeMainActivity()
|
||||
let manager = NotificationManagerCompat.from(context)
|
||||
callback(manager.areNotificationsEnabled())
|
||||
} catch (e) {
|
||||
console.error("检查通知权限出错:", e)
|
||||
callback(false)
|
||||
}
|
||||
},
|
||||
try {
|
||||
let NotificationManagerCompat = plus.android.importClass("androidx.core.app.NotificationManagerCompat")
|
||||
let context = plus.android.runtimeMainActivity()
|
||||
let manager = NotificationManagerCompat.from(context)
|
||||
callback(manager.areNotificationsEnabled())
|
||||
} catch (e) {
|
||||
console.error("检查通知权限出错:", e)
|
||||
callback(false)
|
||||
}
|
||||
},
|
||||
|
||||
// 打开通知权限设置页面
|
||||
openPermissionSetting() {
|
||||
if (plus.os.name !== "Android") return
|
||||
// 打开通知权限设置页面
|
||||
openPermissionSetting() {
|
||||
if (plus.os.name !== "Android") return
|
||||
|
||||
try {
|
||||
let main = plus.android.runtimeMainActivity()
|
||||
let Intent = plus.android.importClass("android.content.Intent")
|
||||
let Settings = plus.android.importClass("android.provider.Settings")
|
||||
try {
|
||||
const main = plus.android.runtimeMainActivity()
|
||||
const Intent = plus.android.importClass('android.content.Intent')
|
||||
const Settings = plus.android.importClass('android.provider.Settings')
|
||||
const Uri = plus.android.importClass('android.net.Uri')
|
||||
const Build = plus.android.importClass('android.os.Build')
|
||||
|
||||
let intent = new Intent()
|
||||
if (parseInt(plus.device.sdkVersion) >= 33) {
|
||||
// Android 13 及以上
|
||||
intent.setAction(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
|
||||
intent.putExtra(Settings.EXTRA_APP_PACKAGE, main.getPackageName())
|
||||
} else {
|
||||
// Android 8 ~ 12
|
||||
intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS")
|
||||
intent.putExtra("app_package", main.getPackageName())
|
||||
intent.putExtra("app_uid", main.getApplicationInfo().uid)
|
||||
}
|
||||
main.startActivity(intent)
|
||||
} catch (e) {
|
||||
console.error("跳转通知设置页失败:", e)
|
||||
}
|
||||
},
|
||||
let intent
|
||||
if (Build.VERSION.SDK_INT >= 26) {
|
||||
// Android 8.0 及以上
|
||||
intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
|
||||
intent.putExtra(Settings.EXTRA_APP_PACKAGE, main.getPackageName())
|
||||
} else if (Build.VERSION.SDK_INT >= 21) {
|
||||
// Android 5.0 - 7.1
|
||||
intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
|
||||
intent.putExtra("app_package", main.getPackageName())
|
||||
intent.putExtra("app_uid", main.getApplicationInfo().uid)
|
||||
} else {
|
||||
// Android 4.4 及以下,跳转到应用详情页
|
||||
intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
|
||||
intent.setData(Uri.fromParts("package", main.getPackageName(), null))
|
||||
}
|
||||
|
||||
// 统一方法:检查并申请
|
||||
ensurePermission(next) {
|
||||
this.checkPermission((enabled) => {
|
||||
if (enabled) {
|
||||
next && next() // 已有权限,继续逻辑
|
||||
} else {
|
||||
uni.showModal({
|
||||
title: "通知权限未开启",
|
||||
content: "请开启通知权限以接收消息提醒",
|
||||
confirmText: "去开启",
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
this.openPermissionSetting()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
main.startActivity(intent)
|
||||
} catch (e) {
|
||||
console.error("跳转通知设置页失败:", e)
|
||||
}
|
||||
},
|
||||
|
||||
// 统一方法:检查并申请
|
||||
ensurePermission(next) {
|
||||
this.checkPermission((enabled) => {
|
||||
if (enabled) {
|
||||
next && next() // 已有权限,继续逻辑
|
||||
} else {
|
||||
uni.showModal({
|
||||
title: "通知权限未开启",
|
||||
content: "请开启通知权限以接收消息提醒",
|
||||
confirmText: "去开启",
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
console.log('t1', '11111111')
|
||||
this.openPermissionSetting()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user