|
@@ -20,6 +20,24 @@
|
|
|
</view>
|
|
</view>
|
|
|
</view>
|
|
</view>
|
|
|
</view>
|
|
</view>
|
|
|
|
|
+
|
|
|
|
|
+ <!-- 权限引导弹窗 -->
|
|
|
|
|
+ <view class="permission-modal" v-if="showPermissionGuide">
|
|
|
|
|
+ <view class="modal-mask" @click="closePermissionGuide"></view>
|
|
|
|
|
+ <view class="modal-content">
|
|
|
|
|
+ <view class="modal-header">
|
|
|
|
|
+ <text class="modal-title">开启消息通知</text>
|
|
|
|
|
+ </view>
|
|
|
|
|
+ <view class="modal-body">
|
|
|
|
|
+ <view class="modal-text">为了更好地为您提供健康提醒服务,请您按以下步骤开启消息通知权限:{{ '\n\n' }}1. 点击下方【去开启】按钮{{ '\n' }}2. 进入【通知管理】选项{{ '\n' }}3. 开启【接收通知】开关{{ '\n' }}4. 确保各项健康提醒均为【接收】状态{{ '\n\n' }}开启后,您将及时收到血压、血糖等重要健康提醒</view>
|
|
|
|
|
+ </view>
|
|
|
|
|
+ <view class="modal-footer">
|
|
|
|
|
+ <button class="modal-button cancel" @click="closePermissionGuide">取消</button>
|
|
|
|
|
+ <button class="modal-button confirm" @click="openSettings">去开启</button>
|
|
|
|
|
+ </view>
|
|
|
|
|
+ </view>
|
|
|
|
|
+ </view>
|
|
|
|
|
+
|
|
|
<TabBar />
|
|
<TabBar />
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
@@ -50,6 +68,9 @@ const TEMPLATE_NO = '7536'
|
|
|
// 全局消息开关
|
|
// 全局消息开关
|
|
|
const notificationsEnabled = ref<boolean>(false)
|
|
const notificationsEnabled = ref<boolean>(false)
|
|
|
|
|
|
|
|
|
|
+// 是否显示权限引导
|
|
|
|
|
+const showPermissionGuide = ref<boolean>(false)
|
|
|
|
|
+
|
|
|
// 记录页面进入来源:'healthIndex' | 'subscribe' | 'unknown'
|
|
// 记录页面进入来源:'healthIndex' | 'subscribe' | 'unknown'
|
|
|
const entrySource = ref<'healthIndex' | 'subscribe' | 'unknown'>('unknown')
|
|
const entrySource = ref<'healthIndex' | 'subscribe' | 'unknown'>('unknown')
|
|
|
const entrySourceText = computed(() => {
|
|
const entrySourceText = computed(() => {
|
|
@@ -174,6 +195,8 @@ const checkSubscriptionStatus = () => {
|
|
|
if (mainSwitch === false || templateStatus === 'reject' || templateStatus === 'ban') {
|
|
if (mainSwitch === false || templateStatus === 'reject' || templateStatus === 'ban') {
|
|
|
console.log('用户关闭了订阅设置,正在更新本地状态')
|
|
console.log('用户关闭了订阅设置,正在更新本地状态')
|
|
|
notificationsEnabled.value = false
|
|
notificationsEnabled.value = false
|
|
|
|
|
+ // 显示权限引导
|
|
|
|
|
+ showPermissionGuide.value = (mainSwitch === false)
|
|
|
try {
|
|
try {
|
|
|
(uni as any).setStorageSync('notificationsEnabled', false)
|
|
(uni as any).setStorageSync('notificationsEnabled', false)
|
|
|
} catch (e) {
|
|
} catch (e) {
|
|
@@ -184,6 +207,7 @@ const checkSubscriptionStatus = () => {
|
|
|
else if (mainSwitch === true && templateStatus === 'accept') {
|
|
else if (mainSwitch === true && templateStatus === 'accept') {
|
|
|
console.log('用户开启了订阅设置,正在更新本地状态')
|
|
console.log('用户开启了订阅设置,正在更新本地状态')
|
|
|
notificationsEnabled.value = true
|
|
notificationsEnabled.value = true
|
|
|
|
|
+ showPermissionGuide.value = false
|
|
|
try {
|
|
try {
|
|
|
(uni as any).setStorageSync('notificationsEnabled', true)
|
|
(uni as any).setStorageSync('notificationsEnabled', true)
|
|
|
} catch (e) {
|
|
} catch (e) {
|
|
@@ -203,6 +227,37 @@ const checkSubscriptionStatus = () => {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * 打开微信设置页面
|
|
|
|
|
+ */
|
|
|
|
|
+const openSettings = () => {
|
|
|
|
|
+ console.log('用户点击前往设置')
|
|
|
|
|
+ showPermissionGuide.value = false
|
|
|
|
|
+ if (typeof (uni as any).openSetting === 'function') {
|
|
|
|
|
+ (uni as any).openSetting({
|
|
|
|
|
+ success: (res: any) => {
|
|
|
|
|
+ console.log('打开设置成功:', res)
|
|
|
|
|
+ // 重新检查订阅状态
|
|
|
|
|
+ checkSubscriptionStatus()
|
|
|
|
|
+ },
|
|
|
|
|
+ fail: (err: any) => {
|
|
|
|
|
+ console.error('打开设置失败:', err)
|
|
|
|
|
+ uni.showToast({ title: '打开设置失败', icon: 'none' })
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ } else {
|
|
|
|
|
+ uni.showToast({ title: '当前环境不支持打开设置', icon: 'none' })
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 关闭权限引导弹窗
|
|
|
|
|
+ */
|
|
|
|
|
+const closePermissionGuide = () => {
|
|
|
|
|
+ console.log('用户关闭权限引导')
|
|
|
|
|
+ showPermissionGuide.value = false
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 顶部总开关变更
|
|
* 顶部总开关变更
|
|
|
* - 打开时:调用 uni.requestSubscribeMessage 请求用户同意订阅 TEMPLATE_ID
|
|
* - 打开时:调用 uni.requestSubscribeMessage 请求用户同意订阅 TEMPLATE_ID
|
|
@@ -232,6 +287,8 @@ const onNotificationChange = (e: any) => {
|
|
|
// 忽略存储错误
|
|
// 忽略存储错误
|
|
|
}
|
|
}
|
|
|
uni.showToast({ title: '订阅成功', icon: 'success' })
|
|
uni.showToast({ title: '订阅成功', icon: 'success' })
|
|
|
|
|
+ // 隐藏权限引导
|
|
|
|
|
+ showPermissionGuide.value = false
|
|
|
} else {
|
|
} else {
|
|
|
console.log('用户未接受订阅,结果:', result)
|
|
console.log('用户未接受订阅,结果:', result)
|
|
|
// 用户拒绝或关闭了弹窗
|
|
// 用户拒绝或关闭了弹窗
|
|
@@ -240,6 +297,8 @@ const onNotificationChange = (e: any) => {
|
|
|
;(uni as any).setStorageSync('notificationsEnabled', false)
|
|
;(uni as any).setStorageSync('notificationsEnabled', false)
|
|
|
} catch (err) {}
|
|
} catch (err) {}
|
|
|
uni.showToast({ title: '订阅被拒绝', icon: 'none' })
|
|
uni.showToast({ title: '订阅被拒绝', icon: 'none' })
|
|
|
|
|
+ // 显示权限引导
|
|
|
|
|
+ showPermissionGuide.value = true
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
fail(err: any) {
|
|
fail(err: any) {
|
|
@@ -251,6 +310,8 @@ const onNotificationChange = (e: any) => {
|
|
|
// 根据错误类型显示不同的提示信息
|
|
// 根据错误类型显示不同的提示信息
|
|
|
if (err.errCode === 20004) {
|
|
if (err.errCode === 20004) {
|
|
|
uni.showToast({ title: '推送权限已关闭', icon: 'none' })
|
|
uni.showToast({ title: '推送权限已关闭', icon: 'none' })
|
|
|
|
|
+ // 显示权限引导
|
|
|
|
|
+ showPermissionGuide.value = true
|
|
|
} else {
|
|
} else {
|
|
|
uni.showToast({ title: '订阅请求失败', icon: 'none' })
|
|
uni.showToast({ title: '订阅请求失败', icon: 'none' })
|
|
|
}
|
|
}
|
|
@@ -264,6 +325,8 @@ const onNotificationChange = (e: any) => {
|
|
|
;(uni as any).setStorageSync('notificationsEnabled', false)
|
|
;(uni as any).setStorageSync('notificationsEnabled', false)
|
|
|
} catch (err) {}
|
|
} catch (err) {}
|
|
|
uni.showToast({ title: '已关闭通知', icon: 'none' })
|
|
uni.showToast({ title: '已关闭通知', icon: 'none' })
|
|
|
|
|
+ // 隐藏权限引导
|
|
|
|
|
+ showPermissionGuide.value = false
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -345,4 +408,85 @@ const toggleReminder = (index: number) => {
|
|
|
color: #8a8a8a;
|
|
color: #8a8a8a;
|
|
|
margin-top: 6rpx;
|
|
margin-top: 6rpx;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+/* 权限引导弹窗样式 */
|
|
|
|
|
+.permission-modal {
|
|
|
|
|
+ position: fixed;
|
|
|
|
|
+ top: 0;
|
|
|
|
|
+ left: 0;
|
|
|
|
|
+ right: 0;
|
|
|
|
|
+ bottom: 0;
|
|
|
|
|
+ z-index: 9999;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.modal-mask {
|
|
|
|
|
+ position: absolute;
|
|
|
|
|
+ top: 0;
|
|
|
|
|
+ left: 0;
|
|
|
|
|
+ right: 0;
|
|
|
|
|
+ bottom: 0;
|
|
|
|
|
+ background-color: rgba(0, 0, 0, 0.6);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.modal-content {
|
|
|
|
|
+ position: absolute;
|
|
|
|
|
+ top: 50%;
|
|
|
|
|
+ left: 50%;
|
|
|
|
|
+ transform: translate(-50%, -50%);
|
|
|
|
|
+ width: 80%;
|
|
|
|
|
+ background-color: #fff;
|
|
|
|
|
+ border-radius: 12rpx;
|
|
|
|
|
+ overflow: hidden;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.modal-header {
|
|
|
|
|
+ padding: 30rpx;
|
|
|
|
|
+ text-align: center;
|
|
|
|
|
+ border-bottom: 1rpx solid #eee;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.modal-title {
|
|
|
|
|
+ font-size: 32rpx;
|
|
|
|
|
+ color: #333;
|
|
|
|
|
+ font-weight: bold;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.modal-body {
|
|
|
|
|
+ padding: 30rpx;
|
|
|
|
|
+ text-align: center;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.modal-text {
|
|
|
|
|
+ font-size: 28rpx;
|
|
|
|
|
+ color: #666;
|
|
|
|
|
+ line-height: 1.5;
|
|
|
|
|
+ white-space: pre-line; /* 添加这行来支持换行 */
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.modal-footer {
|
|
|
|
|
+ display: flex;
|
|
|
|
|
+ border-top: 1rpx solid #eee;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.modal-button {
|
|
|
|
|
+ flex: 1;
|
|
|
|
|
+ border: none;
|
|
|
|
|
+ padding: 20rpx 0;
|
|
|
|
|
+ font-size: 28rpx;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.modal-button.cancel {
|
|
|
|
|
+ background-color: #f5f5f5;
|
|
|
|
|
+ color: #666;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.modal-button.confirm {
|
|
|
|
|
+ background-color: #07c160;
|
|
|
|
|
+ color: #fff;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.modal-button:after {
|
|
|
|
|
+ border: none;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
</style>
|
|
</style>
|