quanyawei
2023-11-06 1e61215b48e59e94c1ed98e4ef956227d689d6bc
fix:小程序订阅消息
1 files added
3 files modified
73 ■■■■■ changed files
pages/actionChange/agencyPage/index.vue 4 ●●●● patch | view | raw | blame | history
pages/actionChange/workOrderDetails/index.vue 1 ●●●● patch | view | raw | blame | history
pages/login/login.vue 13 ●●●●● patch | view | raw | blame | history
utils/subscribe.js 55 ●●●●● patch | view | raw | blame | history
pages/actionChange/agencyPage/index.vue
@@ -15,7 +15,7 @@
            </view>
        </view>
        <view>
            <u-tabs :list="list" :scrollable="scrollable" lineWidth="60" @change="changeTap" />
            <u-tabs :list="list" :scrollable="scrollable" lineWidth="60" :current='current' @change="changeTap" />
        </view>
        <view class="" v-if="userName">
            <view class="dataRangeSerch" v-if="current===3">
@@ -161,7 +161,7 @@
                    value: 3,
                }, ],
                showeEscalationTime: false,
                current: 0,
                current: 1,
                startTime: '',
                endTime: '',
                workOderList: [],
pages/actionChange/workOrderDetails/index.vue
@@ -56,7 +56,6 @@
                    userId: this.userInfor.userId
                }
                this.$http.httpGet('/allocationApp/authority', params).then(res => {
                    res.data = false
                    if (!res.data) {
                        uni.showModal({
                            content: '您暂无操作权限,请联系管理员!',
pages/login/login.vue
@@ -42,6 +42,9 @@
        httpGet
    } from '@/utils/http.js'
    import store from '@/store/index.js'
    import {
        subScribeMsg
    } from '@/utils/subscribe.js'
    export default {
        data() {
            return {
@@ -83,6 +86,15 @@
            uni.hideHomeButton()
        },
        methods: {
            // 点击时触发订阅信息
            async aClick() {
                let data = await subScribeMsg()
                console.log('data', data)
                if (data['YNqUZ1MgMvwY3G-NENVbcmIBR5dUotSdnwcz96CWrho'] === 'accept') { // 用户点击确定后
                } else {
                    console.log('拒绝')
                }
            },
            doRequire() {
                uni.requirePrivacyAuthorize({
                    success: () => {
@@ -107,6 +119,7 @@
                const value = uni.getStorageSync('openId')
                console.log('openId', value)
                if (value) {
                    this.aClick()
                    this.logining(value)
                }
            },
utils/subscribe.js
New file
@@ -0,0 +1,55 @@
function subScribeMsg() {
    return new Promise((resolve, reject) => {
        let that = this
        uni.getSetting({
            withSubscriptions: true,
            success(res) {
                console.log('1', res, '订阅信息', res.subscriptionsSetting)
                if (!res.subscriptionsSetting.mainSwitch) {
                    uni.showModal({
                        title: '是否重新授权消息订阅功能',
                        success(res) {
                            if (res.confirm) {
                                uni.openSetting({
                                    success(res) {
                                        if (res.subscriptionsSetting) {
                                            uni.showToast({
                                                title: '开启权限成功',
                                                icon: 'none',
                                            })
                                        }
                                    },
                                    fail() {
                                        uni.showToast({
                                            title: '开启权限失败',
                                            icon: 'none',
                                        })
                                    },
                                })
                            } else if (res.cancel) {
                                uni.showToast({
                                    title: '拒绝开启开启权限',
                                    icon: 'none',
                                })
                            }
                        },
                    })
                } else {
                    uni.requestSubscribeMessage({
                        tmplIds: ['YNqUZ1MgMvwY3G-NENVbcmIBR5dUotSdnwcz96CWrho'],
                        success(res) {
                            console.log('requestSubscribeMessage 订阅信息', res)
                            resolve(res)
                        },
                        fail(errMessage) {
                            reject(errMessage)
                            console.log('订阅消息 失败 ', errMessage)
                        },
                        complete() {}
                    })
                }
            },
        })
    })
}
module.exports = { subScribeMsg }