收藏
回答

wx.NeedPrivacyAuthorization监听授权成功还弹隐私接口拒绝的框?

1 微信小程序隐私协议通过在app.js 处通过onNeedPrivacyAuthorization全局监听隐私接口调用,因为小程序无法自定义全局弹窗,于是统一跳转自定义隐私协议页面,在自定义页面里点击<button id="agree-btn" open-type="agreePrivacyAuthorization" bindagreeprivacyauthorization="handleAgreePrivacyAuthorization">同意</button>按钮,授权成功后,会先谈一个隐私接口拒绝的弹窗,但是返回上一页刷新页面,隐私接口是能正常调用的。这个是为啥,难道只能在触发的当前页面弹窗,不能跳转页面去同意隐私协议么?


app.tsx

componentDidMount() {
    ezrTrack.gioAppStart();
    if (process.env.TARO_ENV === 'weapp') {
      onNeedPrivacyAuthorization((resolve: any) => {
        setGlobalData('privacyAuthorization', resolve);
        navigateTo({
          url:'/pages/privacy-agreenment/index'
        })
        console.log('xxx还未授权请先授权:', resolve);
      });
   }
  }



/pages/privacy-agreenment/index.tsx

import React, { Component } from 'react';
import { View, Image } from '@tarojs/components';
import { get as getGlobalData } from '@/utils/global-data';
import {
  showToast,
  navigateBack,
  getCurrentPages,
  openPrivacyContract,
} from '@ezr-core/uniapi';
import {
  EzrModal,
  EzrModalHeader,
  EzrModalContent,
  EzrModalAction,
} from '@ezr/pebble';


interface IndexProps {}
interface IndexState {
  openPrivace: boolean;
}
export default class PrivacyAgreenment extends Component<
  IndexProps,
  IndexState
> {
  constructor(props) {
    super(props);
  }
  componentDidMount(): void {}


  handleConfirm = () => {
    console.log('拒绝请求');
  };


  handleCancel = () => {};


  handleAgree = () => {
    const resolve = getGlobalData('privacyAuthorization');
    resolve({ buttonId: 'agree-btn', event: 'agree' });
    setTimeout(() => {
      let pages = getCurrentPages();
      let prevPage = pages.pageStack[pages.length - 2];
      prevPage?.onLoad();
      navigateBack();
    }, 1000);
  };


  handleDisagree = () => {
    const resolve = getGlobalData('privacyAuthorization');
    resolve({ event: 'disagree' });
    showToast({
      icon: 'none',
      title: '您已拒绝,相关功能可能将无法使用',
    });
    setTimeout(() => {
      navigateBack();
    }, 500);
  };


  render(): React.ReactNode {
    return (
      <>
        <EzrModal isOpened onClose={this.handleCancel}>
          <EzrModalHeader isSimplified>
            <Image
              style={{ width: '100%' }}
              mode="widthFix"
              src="https://assets-img.ezrpro.com/mobile/img/wx/hdq.png"
            ></Image>
          </EzrModalHeader>
          <EzrModalContent>
            <View className="modal-content">
              <View>隐私协议</View>
              <View>阅读隐私协议接受请点击同意</View>
              <View
                onClick={() => {
                  openPrivacyContract();
                }}
                style={{ color: 'blue' }}
              >
                《商城小程序协议详情》
              </View>
            </View>
          </EzrModalContent>
          <EzrModalAction isSimplified>
            <View
              style={{
                display: 'flex',
                flexDirection: 'row',
                justifyContent: 'space-between',
                padding: '20px 0',
              }}
            >
              <button
                id="agree-btn"
                style={{
                  height: '30px',
                  lineHeight: '30px',
                  fontSize: '14px',
                  width: '100px',
                }}
                open-type="agreePrivacyAuthorization"
                bindagreeprivacyauthorization={this.handleAgree}
                onClick={this.handleAgree}
              >
                同意
              </button>
              <button
                id="disagree-btn"
                style={{
                  height: '30px',
                  lineHeight: '30px',
                  fontSize: '14px',
                  width: '100px',
                }}
                onClick={this.handleDisagree}
              >
                拒绝
              </button>
            </View>
          </EzrModalAction>
        </EzrModal>
      </>
    );
  }
}


最后一次编辑于  2023-09-05
回答关注问题邀请回答
收藏

5 个回答

  • 夏味
    夏味
    2023-09-05

    要弹的,本次新增的是隐私协议的弹窗,原来的功能授权的弹窗依然会弹,1 +1 = 2

    隐私协议开发指南,看我笔记

    2023-09-05
    有用
    回复
  • 明月
    明月
    2023-09-05

    2023-09-05
    有用
    回复
  • 浅忆
    浅忆
    2023-09-05

    为什么调用了getPrivacySetting接口后,获取用户的收货地址这个API----(uni.chooseAddress就失效了呢?)

    2023-09-05
    有用
    回复
  • Jerry
    Jerry
    2023-09-04

    贴代码吧

    2023-09-04
    有用
    回复 1
    • 明月
      明月
      2023-09-05
      代码已贴,感谢给看下
      2023-09-05
      回复
  • showms
    showms
    2023-09-04

    好像没有出现你说的问题,可以把能复现的代码贴出来看下

    2023-09-04
    有用
    回复 1
    • 明月
      明月
      2023-09-05
      代码已贴,感谢给看下
      2023-09-05
      回复
登录 后发表内容