微信小程序-增加隐私协议弹窗

真的加了非常之久,非常简单的一个功能,但是因为之前没弄过,加上系统有点bug,软件也有点抽风......

  1. 在微信后台配置-更新用户隐私协议信息
    微信小程序-增加隐私协议弹窗_第1张图片
  2. 增加 "__usePrivacyCheck__" : true, 9月15号之后不加也行,好象今天刚刚好9月15
     "mp-weixin" : {
            "appid" : "xxxxxxxxxx",
            "__usePrivacyCheck__" : true,
    
    
    "permission": {
        "scope.userLocation": {
            "desc": "提供准确的定位服务"
        }
    },
    "requiredPrivateInfos": [
        "getLocation"
    ]

    微信小程序-增加隐私协议弹窗_第2张图片
  3. 微信开发者工具的基础库切换到>3.0(本地运行和发布时都要改,不改不弹窗)
    微信小程序-增加隐私协议弹窗_第3张图片
  4. 首页增加隐私协议弹窗控件,加在最后一个view的上边
    
    
    

    微信小程序-增加隐私协议弹窗_第4张图片

  5. 增加隐私协议组件,增加到components文件夹下
    微信小程序-增加隐私协议弹窗_第5张图片
    微信小程序-增加隐私协议弹窗_第6张图片

  6. ws-wx-privacy.vue代码:
     

    
    
    

  7. util.js文件代码:
     

    /**
     * 获取当前页面上下文
     * @returns 页面对象
     */
    export function getContext() {
    	// eslint-disable-next-line no-undef
    	const pages = getCurrentPages()
    	return pages[pages.length - 1]
    }
    
    /**
     * 获取上下文中指定节点组件
     * @param context 选择器的选择范围,可以传入自定义组件的 this 作为上下文
     * @param selector 自定义节点选择器
     */
    export function getComponent(context, selector ) {
    	let component = null
    	// #ifdef H5
    	context.$children.forEach((child) => {
    		if (`#${child.$attrs.id}` === selector) {
    			component = child
    		} else if (child.$children && child.$children.length) {
    			if (getComponent(child, selector)) {
    				component = getComponent(child, selector)
    			}
    		}
    		if (component) {
    			return component
    		}
    	})
    	// #endif
    	// #ifdef MP-WEIXIN
    	component = context.selectComponent && context.selectComponent(selector) && context.selectComponent(selector).$vm
    	// #endif
    
    	// #ifdef MP-ALIPAY
    	const alipay = context.$children ? context.$children : context.$vm && context.$vm.$children ? context.$vm
    		.$children : []
    	component = alipay.find((component) => {
    		return `#${component.$scope.props.id}` === selector
    	})
    	// #endif
    	// #ifdef APP-PLUS
    	const app = context.$children ? context.$children : context.$vm && context.$vm.$children ? context.$vm.$children :
    	[]
    	component = app.find((component) => {
    		return `#${component.$attrs.id}` === selector
    	})
    	// #endif
    	return component
    }

  8. 一般到这里再次运行就可以成功了,成功的隐私弹窗:
    微信小程序-增加隐私协议弹窗_第7张图片

  9. 如果到这里了还没有成功!!!再来,检查一下弹窗控件对不对
    看一下components 文件夹下边有没有uni-popup文件夹,如果有,一定要删掉!!!
    否则会报错,​easycom组件冲突:[@/components/uni-popup/uni-popup.vue,@/uni_modules/uni-popup/components/uni-popup/uni-popup.vue]​
    如果有页面引用到了,引用的代码也删掉
    微信小程序-增加隐私协议弹窗_第8张图片
    微信小程序-增加隐私协议弹窗_第9张图片

  10. Hbuilder x 工具更新到最新版本,导入最新版本uni-popup组件
    点击插件安装:
    微信小程序-增加隐私协议弹窗_第10张图片

  11. 找到 uni-popup插件,点击安装
    微信小程序-增加隐私协议弹窗_第11张图片
    微信小程序-增加隐私协议弹窗_第12张图片

  12. 再次运行,就会弹隐私协议的窗口啦

     

你可能感兴趣的:(uni-app)