封装微信小程序隐私信息授权

隐私 代码 html (modal 组件再后面封装有提供)

html 复制代码
<modal isShow="{{show}}">
    <view class="privacy-auth-dialog">
        <view class="title">温馨提示</view>
        <view class="content">
            <view>
                为切实保护用户隐私,优化用户体验,我们更新了
                <view class="active" bindtap="openPrivacyContract"> 《 XXXX你的产品名 隐私保护指引》 </view>,
                您可点击了解详情。
            </view>
            <view>
                为向您提供服务,您需要同意更新后的
                <view class="active" bindtap="openPrivacyContract"> 《XXXX你的产品名 隐私保护指引》 </view>
                。我们将严格按照法律法规采取一切必要措施,以保障您的信息安全。
            </view>
        </view>
        <view class="footer">
            <view class="reject" hover-class="hover-style-3" hover-stay-time="100" bindtap="handleReject">
                拒绝并退出
            </view>
            <button id="argee-btn" open-type="agreePrivacyAuthorization" class="btn" bindtap="handleAgree">同意</button>
        </view>
    </view>
</modal>

隐私 代码 css

css 复制代码
.privacy-auth-dialog {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: #fff;
    border-radius: 32rpx;
    width: 650rpx;
    height: auto;
    overflow: hidden;
    .title {
        padding: 32rpx;
        font-size: 30rpx;
        font-weight: bold;
        border-bottom: 1rpx solid #eee;
        text-align: center;
    }
    .content {
        padding: 32rpx;
        font-size: 28rpx;
        word-break: break-all;
        word-wrap: break-word;
        .active {
            display: inline-block;
            color: $default-color;
        }
        border-bottom: 1rpx solid #eee;
    }
    .footer {
        display: flex;
        justify-content: space-between;
        align-items: center;
        .reject {
            flex: 1;
            height: 92rpx;
            line-height: 92rpx;
            text-align: center;
            font-size: 32rpx;
            border-right: 1rpx solid #eee;
        }
        .btn {
            flex: 1;
            color: $default-color;
        }
    }
}

// 初始化按钮样式
button::after {
    border: none !important;
}
button {
    border-radius: 0;
    background-color: transparent;
    padding-top: 0;
    padding-right: 0;
    padding-bottom: 0;
    padding-left: 0;
}

隐私 js 代码

javascript 复制代码
Component({
    // 组件的属性列表
    properties: {
        isDirectHandle: {
            type: Boolean,
            value: false,
            observer(val) {
                if (!val || !wx.getPrivacySetting) return
                wx.getPrivacySetting({
                    success: (res) => {
                        if (res.needAuthorization) {
                            this.showDialog()
                        }
                    },
                })
            },
        },
    },

    // 组件的初始数据
    data: {
        show: false,
    },
    //  全局样式生效
    options: {
        addGlobalClass: true,
    },
    // 组件的生命周期
    lifetimes: {
        // 在组件实例刚刚被创建时执行
        created() {
            if (wx.onNeedPrivacyAuthorization) {
                wx.onNeedPrivacyAuthorization((resolve) => {
                    this.resolve = resolve
                    this.showDialog()
                })
            }
        },
        // 在组件实例进入页面节点树时执行
        attached() {},
        // 在组件在视图层布局完成后执行
        ready() {},
        // 在组件实例被从页面节点树移除时执行
        detached() {},
    },

    // 组件的方法列表
    methods: {
        showDialog() {
            this.setData({ show: true })
        },
        hideDialog() {
            this.setData({ show: false })
        },

        // 跳转至隐私协议页面。
        openPrivacyContract() {
            wx.openPrivacyContract()
        },
        // 拒绝
        handleReject() {
            this.hideDialog()
            this.resolve && this.resolve({ event: "disagree" })
            this.triggerEvent("handlePrivacy", { event: "disagree" })
        },
        // 同意
        handleAgree() {
            this.hideDialog()
            this.resolve && this.resolve({ buttonId: "argee-btn", event: "agree" })
            this.triggerEvent("handlePrivacy", { event: "agree" })
        },
    },
})

使用方法

html 复制代码
<privacy-auth-dialog isDirectHandle="{{true}}" bind:handlePrivacy="handlePrivacy"></privacy-auth-dialog>

// handlePrivacy 会返回用户的操作结果

model 的封装

html

html 复制代码
<view class="container" catch:touchmove="" catch:tap="handleClickMask" wx:if="{{isShow}}">
    <view catch:tap>
        <slot></slot>
    </view>
</view>

css

css 复制代码
.container {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 10086;
    animation: showModal ease 0.3s;
    background: rgba(0, 0, 0, 0.7);
}

@keyframes showModal {
    0% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}

js

javascript 复制代码
Component({
    data: {},
    properties: {
        isShow: {
            type: Boolean,
            value: false,
        },
        canClose: {
            type: Boolean,
            value: true,
        },
    },
    observers: {},
    methods: {
        handleClickMask() {
            if (!this.data.canClose) return
            this.setData({
                isShow: false,
            })
            this.triggerEvent("close")
        },
    },
})

拿走不谢

相关推荐
小咕聊编程1 小时前
【含文档+PPT+源码】基于微信小程序农家乐美食餐厅预约推广系统
微信小程序·小程序·美食
计算机-秋大田10 小时前
基于微信小程序的电子竞技信息交流平台设计与实现(LW+源码+讲解)
spring boot·后端·微信小程序·小程序·课程设计
Stanford_110617 小时前
C++中常用的十大排序方法之4——希尔排序
c++·算法·微信小程序·排序算法·微信公众平台·twitter·微信开放平台
Colinnian21 小时前
微信小程序中在一个大边框里给每个小边框均匀分配空间
微信小程序·小程序·notepad++
一 乐1 天前
基于微信小程序的酒店管理系统设计与实现(源码+数据库+文档)
java·数据库·vue.js·spring boot·微信小程序·酒店管理系统
曾经的三心草2 天前
小程序-基础加强-自定义组件
微信小程序·自定义组件·基础加强
你爱写程序吗(新H)2 天前
基于微信小程序的停车场管理系统设计 停车场微信小程序的设计与实现 (源码+文档)
java·spring boot·微信小程序·小程序
baby_hua3 天前
2021版小程序开发4——基础加强
微信小程序
Stanford_11063 天前
物联网智能项目之——智能家居项目的实现!
物联网·学习·微信小程序·智能家居·微信公众平台·twitter·微信开放平台
Stanford_11063 天前
C++中常用的排序方法之——冒泡排序
java·学习·算法·微信小程序·排序算法·微信公众平台·微信开放平台