2023-03-15 10:35:06 +08:00
|
|
|
|
import Vue from 'vue'
|
|
|
|
|
|
import Vuex from 'vuex'
|
|
|
|
|
|
Vue.use(Vuex)
|
2023-03-16 09:14:57 +08:00
|
|
|
|
import {
|
|
|
|
|
|
insertSubscribeMessageRecord
|
|
|
|
|
|
} from '@/api/store/index.js'
|
2023-03-15 10:35:06 +08:00
|
|
|
|
const store = new Vuex.Store({
|
|
|
|
|
|
state: {
|
|
|
|
|
|
//公共的变量,这里的变量不能随便修改,只能通过触发mutations的方法才能改变
|
|
|
|
|
|
},
|
|
|
|
|
|
mutations: {
|
|
|
|
|
|
//相当于同步的操作
|
2023-03-16 09:14:57 +08:00
|
|
|
|
//点击确认
|
|
|
|
|
|
subscribesuccess(state) {
|
2023-03-16 10:40:15 +08:00
|
|
|
|
const openids = uni.getStorageSync('openid');
|
|
|
|
|
|
const patientIds = uni.getStorageSync('patientId');
|
|
|
|
|
|
wx.requestSubscribeMessage({
|
|
|
|
|
|
tmplIds: [
|
|
|
|
|
|
'-IxZeEkkXFhoSwGtBHbipKQ6kjEmkdTkswKeOypSsNQ',
|
|
|
|
|
|
'e1JRZaw1OfTz2b6X9DTqqaJtV4rXEt7uhwXoZLDb_eA',
|
|
|
|
|
|
'nUB9HRbqQXOVuTpkKBIHMgzWlNq6touzxf5QYBiMkbU'
|
|
|
|
|
|
],
|
|
|
|
|
|
success(res) {
|
|
|
|
|
|
var list = {
|
|
|
|
|
|
"subscribeMessageRecordList": [{
|
|
|
|
|
|
templateId: '-IxZeEkkXFhoSwGtBHbipKQ6kjEmkdTkswKeOypSsNQ',
|
|
|
|
|
|
subscribeStatus: res[
|
|
|
|
|
|
'-IxZeEkkXFhoSwGtBHbipKQ6kjEmkdTkswKeOypSsNQ'],
|
|
|
|
|
|
openid: openids,
|
|
|
|
|
|
patientId: patientIds,
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
templateId: 'e1JRZaw1OfTz2b6X9DTqqaJtV4rXEt7uhwXoZLDb_eA',
|
|
|
|
|
|
subscribeStatus: res[
|
|
|
|
|
|
'e1JRZaw1OfTz2b6X9DTqqaJtV4rXEt7uhwXoZLDb_eA'],
|
|
|
|
|
|
openid: openids,
|
|
|
|
|
|
patientId: patientIds,
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
templateId: 'nUB9HRbqQXOVuTpkKBIHMgzWlNq6touzxf5QYBiMkbU',
|
|
|
|
|
|
subscribeStatus: res[
|
|
|
|
|
|
'nUB9HRbqQXOVuTpkKBIHMgzWlNq6touzxf5QYBiMkbU'],
|
|
|
|
|
|
openid: openids,
|
|
|
|
|
|
patientId: patientIds,
|
|
|
|
|
|
},
|
|
|
|
|
|
]
|
|
|
|
|
|
}
|
|
|
|
|
|
if (openids && patientId) {
|
|
|
|
|
|
insertSubscribeMessageRecord(list).then(ress => {
|
|
|
|
|
|
console.log(ress)
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
fail(err) {
|
|
|
|
|
|
console.log(err)
|
|
|
|
|
|
},
|
|
|
|
|
|
complete(scc) {}
|
2023-03-16 09:14:57 +08:00
|
|
|
|
})
|
|
|
|
|
|
},
|
2023-03-15 10:35:06 +08:00
|
|
|
|
},
|
|
|
|
|
|
actions: {
|
|
|
|
|
|
//相当于异步的操作,不能直接改变state的值,只能通过触发mutations的方法才能改变
|
|
|
|
|
|
// 是否设置过授权
|
|
|
|
|
|
openPopup(contxt) {
|
|
|
|
|
|
// 获取用户的当前设置,判断是否点击了“总是保持以上,不在询问”
|
|
|
|
|
|
wx.getSetting({
|
|
|
|
|
|
withSubscriptions: true, // 是否获取用户订阅消息的订阅状态,默认false不返回
|
|
|
|
|
|
success(res) {
|
|
|
|
|
|
console.log('res.authSetting', res.authSetting)
|
2023-03-16 09:14:57 +08:00
|
|
|
|
if (res.authSetting['scope.subscribeMessage']) {} else {
|
2023-03-15 10:35:06 +08:00
|
|
|
|
//因为没有选择总是保持,所以需要调起授权弹窗再次授权
|
2023-03-16 10:40:15 +08:00
|
|
|
|
contxt.commit('subscribesuccess')
|
2023-03-15 10:35:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
export default store
|