feat: add subscribe message authorization before appointment submit
This commit is contained in:
@@ -3,6 +3,9 @@ const { formatDate } = require('../../utils/util')
|
|||||||
const { appointmentDB } = require('../../utils/api')
|
const { appointmentDB } = require('../../utils/api')
|
||||||
const app = getApp()
|
const app = getApp()
|
||||||
|
|
||||||
|
// 订阅消息模板ID
|
||||||
|
const SUBSCRIBE_TEMPLATE_ID = 'Csf_dJU7DhvVFt_03sphPPBCGlnmcWQSPhgqfxHZ5RQ'
|
||||||
|
|
||||||
Page({
|
Page({
|
||||||
data: {
|
data: {
|
||||||
form: {
|
form: {
|
||||||
@@ -106,10 +109,19 @@ Page({
|
|||||||
if (!this.validateForm()) return
|
if (!this.validateForm()) return
|
||||||
if (this.data.submitting) return
|
if (this.data.submitting) return
|
||||||
|
|
||||||
|
// 先请求订阅消息授权,再提交预约
|
||||||
|
try {
|
||||||
|
await wx.requestSubscribeMessage({
|
||||||
|
tmplIds: [SUBSCRIBE_TEMPLATE_ID]
|
||||||
|
})
|
||||||
|
} catch (e) {
|
||||||
|
// 用户拒绝授权也允许继续提交,只是收不到通知
|
||||||
|
console.warn('订阅消息授权失败或用户拒绝', e)
|
||||||
|
}
|
||||||
|
|
||||||
this.setData({ submitting: true })
|
this.setData({ submitting: true })
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 通过后端API创建预约
|
|
||||||
const openid = app.globalData.userInfo.openid
|
const openid = app.globalData.userInfo.openid
|
||||||
await appointmentDB.create({ ...this.data.form, openid })
|
await appointmentDB.create({ ...this.data.form, openid })
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user