• 微信隐私协议弹窗uniapp组件


    1.在vuex里加入如下代码

    1. const state = {
    2. //微信隐私信息
    3. privacyProtocol:{
    4. needAuthorization:false,
    5. title:''
    6. }
    7. }
    8. const getters = {
    9. privacyProtocol: state => state.privacyProtocol,
    10. }
    11. const actions = {
    12. // 查询隐私协议接口
    13. checkUserPrivacyProtocol({
    14. commit,
    15. getters
    16. }) {
    17. if (wx.getPrivacySetting && !getters.privacyProtocol.title) {
    18. wx.getPrivacySetting({
    19. success: res => {
    20. // console.log(res)
    21. commit('privacyProtocol', {
    22. title:res.privacyContractName,
    23. needAuthorization: res.needAuthorization
    24. })
    25. }
    26. })
    27. }
    28. },
    29. // 同意隐私协议
    30. agreePrivacyProtocol({commit,getters}){
    31. let privacyProtocol = getters.privacyProtocol
    32. privacyProtocol.needAuthorization = false
    33. commit('privacyProtocol', privacyProtocol)
    34. }
    35. }
    36. const mutations = {
    37. privacyProtocol(state, data) {
    38. state.privacyProtocol = data;
    39. }
    40. }

    2.右键components新建组件privacy ,替换为以下代码

    1. <script>
    2. import { mapActions, mapGetters } from 'vuex';
    3. export default {
    4. name:"privacy",
    5. data() {
    6. return {
    7. };
    8. },
    9. computed: {
    10. ...mapGetters(['privacyProtocol']),
    11. showPrivacy:function () {
    12. return this.privacyProtocol.needAuthorization
    13. },
    14. privacyContractName:function () {
    15. return this.privacyProtocol.title
    16. },
    17. },
    18. methods: {
    19. ...mapActions(['agreePrivacyProtocol']),
    20. // 打开隐私协议页面
    21. openPrivacyContract() {
    22. wx.openPrivacyContract({
    23. fail: () => {
    24. uni.showToast({
    25. title: '遇到错误',
    26. icon: 'error'
    27. })
    28. }
    29. })
    30. },
    31. // 拒绝隐私协议
    32. exitMiniProgram() {
    33. // 直接退出小程序
    34. uni.exitMiniProgram()
    35. },
    36. // 同意隐私协议
    37. handleAgreePrivacyAuthorization() {
    38. this.agreePrivacyProtocol()
    39. this.$emit('agree')
    40. },
    41. }
    42. }
    43. script>
    44. <style>
    45. .privacy {
    46. position: fixed;
    47. top: 0;
    48. right: 0;
    49. bottom: 0;
    50. left: 0;
    51. background: rgba(0, 0, 0, .5);
    52. z-index: 9999999;
    53. display: flex;
    54. align-items: center;
    55. justify-content: center;
    56. }
    57. .content {
    58. width: 632rpx;
    59. padding: 48rpx;
    60. box-sizing: border-box;
    61. background: #fff;
    62. border-radius: 16rpx;
    63. }
    64. .content .title {
    65. text-align: center;
    66. color: #333;
    67. font-weight: bold;
    68. font-size: 32rpx;
    69. }
    70. .content .des {
    71. font-size: 26rpx;
    72. color: #666;
    73. margin-top: 40rpx;
    74. text-align: justify;
    75. line-height: 1.6;
    76. }
    77. .content .des .link {
    78. color: #07c160;
    79. text-decoration: underline;
    80. }
    81. .btns {
    82. margin-top: 48rpx;
    83. display: flex;
    84. }
    85. .btns .item {
    86. justify-content: space-between;
    87. width: 244rpx;
    88. height: 80rpx;
    89. display: flex;
    90. align-items: center;
    91. justify-content: center;
    92. border-radius: 16rpx;
    93. box-sizing: border-box;
    94. border: none;
    95. }
    96. .btns .reject {
    97. background: #f4f4f5;
    98. color: #909399;
    99. }
    100. .btns .agree {
    101. background: #07c160;
    102. color: #fff;
    103. }
    104. style>

    3.在需要弹出的隐私协议的页面引用组件

    1. <privacy @agree="getStoreList">privacy>

    4.onLaunch里面调用隐私协议接口

    1. // #ifdef MP-WEIXIN
    2. store.dispatch("checkUserPrivacyProtocol"); // 获取是否同意隐私协议,注意store要引入进来
    3. // #endif
  • 相关阅读:
    ECMAScript 6 入门 - 字符串的新增方法
    04-jQuery动画
    XSS 安全漏洞介绍及修复方案
    【springboot】8、静态资源访问
    顺丰面试,第二个问题把我劝退了!
    查阅trt engine
    OpenGL ES EGL eglGetDisplay
    【Java】解决Java报错:IllegalArgumentException
    深度学习——第1章 深度学习的概念及神经网络的工作原理
    SpringCloud-4-基础工程-创建服务提供者
  • 原文地址:https://blog.csdn.net/pkmowang/article/details/132887817