uniapp小程序中给web-view页面添加授权弹窗(使用cover-view组件覆盖实现该功能)

news/2024/7/20 3:34:04 标签: uni-app, 小程序, 前端
效果图:

在这里插入图片描述

web-view是承载网页的容器。会自动铺满整个小程序页面,个人类型的小程序暂不支持使用。

在这里插入图片描述
再看下面一个提示:
每个页面只能有一个 web-view,web-view 会自动铺满整个页面,并覆盖其他组件。
也就是说,小程序中使用web-view打开网页,在页面上写的其它组件会直接被网页给覆盖住
在这里插入图片描述


需求:在web-view页面添加弹窗

刚好有一个组件cover-view可以覆盖web-view

cover-view覆盖在原生组件上的文本视图。

app-vue和小程序框架,渲染引擎是webview的。但为了优化体验,部分组件如map、video、textarea、canvas通过原生控件实现,原生组件层级高于前端组件(类似flash层级高于div)。为了能正常覆盖原生组件,设计了cover-view。

cover-view功能描述:

可覆盖的原生组件包括 map、video、canvas、camera、live-player、live-pusher、web-view

cover-view只支持嵌套 cover-view、cover-image,可在 cover-view 中使用 button。组件属性的长度单位默认为px,2.4.0起支持传入单位(rpx/px)。

也就是在cover-view中只能使用cover-view、cover-image、button三个组件

代码示例:

注意:checkbox按钮是图片代替的,因为不能使用checkbox组件

<template>
	<view>
		<web-view :src="url">
			<cover-view class="my-cover" v-if="coverIsShow">
				<cover-view class="cover-box">
					<cover-view class="des">
						<cover-view class="des-text1">本服务将由{{corporateName}}提供,南洋商业银行(中国)将在您办理以下业务时将您的对应信息提供给该公司用于下述目的:</cover-view>
						<cover-view class="des-text">购买商品</cover-view>
						<cover-view class="des-text">手机号码:用于识别客户及查询订单</cover-view>
						<cover-view class="des-text1">{{corporateName}}服务热线{{phoneNum}},相关商品和服务(包括售后)均由该公司负责。</cover-view>
					</cover-view>
					<cover-view class="nav-select">
						<cover-view class="select-item" @click="checkBoxBtn">
							<cover-image @click="checkAllGouBox" class="image" src="@/static/applyAccont/check.png" v-if="chackBoxIsShow"></cover-image>
							<cover-image @click="checkAllGouBox" class="image" src="@/static/applyAccont/uncheck.png" v-else></cover-image>
							<cover-view>我已阅读并同意</cover-view>
						</cover-view>
						<cover-view class="nav-privacy" @click="userPrivacy">《用户协议》</cover-view>
						<cover-view></cover-view>
						<cover-view class="nav-privacy" @click="agreePrivacy">《隐私协议》</cover-view>
					</cover-view>
					<cover-view class="btns">
						<button class="reject" @click="goBack">不同意授权</button>
						<button type="primary" class="agree" @click="confirm">已知悉,同意授权</button>
						<!-- <button type="primary" class="agree" @click="confirm" :disabled="!chackBoxIsShow">已知悉,同意授权</button> -->
					</cover-view>
				</cover-view>
			</cover-view>
		</web-view>
	</view>
</template>

<script>
	import apiUrl from '@/utils/commonUrl.js';
	export default {
		data() {
			return {
				url: '',
				corporateName:'上海xxx科技有限公司',
				phoneNum: '999999999',
				coverIsShow: false,
				chackBoxIsShow: false,
			};
		},
		onLoad() {
			this.url = apiUrl.baseUrl+ "&t=" + new Date().getTime()
		},
		methods: {
			},
			// 复选框点击
			checkBoxBtn(){
				this.chackBoxIsShow = !this.chackBoxIsShow;
			},
			// 取消返回
			goBack(){
				uni.navigateBack({
					delta:1
				})
			},
			// 确认协议
			confirm(){
				this.$store.commit('SET_BEILIANPROVICY', '1');
				this.coverIsShow = false
			},
			// 用户协议
			userPrivacy(){
				uni.navigateTo({
					url:'/pages/home/beiLiAnUser'
				})
			},
			// 隐私协议
			agreePrivacy(){
				uni.navigateTo({
					url:'/pages/home/beiLiAnPrivacy'
				})
			}
		}
	}
</script>

<style lang="scss">
.my-cover{
	 position: fixed;
	 top: 0;
	 left: 0;
	 width: 100%;
	 height: 100%;
	 z-index: 100;
	 background-color: rgba(0,0,0,.3);
	 display: flex;
	 align-items: center;
	 justify-content: center;
	 z-index: 99999;
	
	.cover-box{
		width: 636rpx;
		box-sizing: border-box;
		background: #fff;
		border-radius: 16rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		
		.des {
			font-size: 26rpx;
			margin-top: 40rpx;
			width: 560rpx;
			
			.des-text{
				width: 560rpx;
				color: #666;
				line-height: 48rpx;
				white-space: pre-wrap;
				text-indent: 2em;
				word-break:break-all;
			}
			
			.des-text1{
				width: 560rpx;
				white-space:pre-wrap;
				line-height: 48rpx;
				color: #333;
				font-weight: bold;
				text-indent: 2em;
				word-break:break-all;
			}
		}
		
		.nav-select{
			margin-top: 28rpx;
			margin-left: 10rpx;
			margin-right: 10rpx;
			font-size: 26rpx;
			display: flex;
			
			.select-item{
				display: flex;
				
				.image {
					width: 30rpx;
					height: 30rpx;
					margin-right: 20rpx;
				}
			}
			
			.nav-privacy{
				color: #1989FF;
			}
		}
		
		.btns {
			margin-top: 32rpx;
			margin-bottom: 0;
			display: flex;
			
			.reject {
				color: #333;
				font-size: 28rpx;
				background: #fff;
				height: 100rpx;
				line-height: 100rpx;
				font-weight: 500;
				width: 320rpx;
				border-top: 2rpx solid #eee;
			}
			
			.agree {
				color: #1989ff;
				font-size: 28rpx;
				background: #fff;
				height: 100rpx;
				line-height: 100rpx;
				font-weight: 500;
				width: 320rpx;
				border-top: 2rpx solid #eee;
				margin-left: -2rpx;
			}
			
			:deep(button[disabled][type=primary]) {
				color: #8cc4fd !important;
				border-radius: 0!important;
			}
			button {
				border-radius: 0!important;
			}
		}
	}	
}
</style>

http://www.niftyadmin.cn/n/5086015.html

相关文章

攻防世界题目练习——Crypto密码新手+引导模式(二)(持续更新)

题目目录 1. 转轮机加密2. easychallenge 上一篇&#xff1a;攻防世界题目练习——Crypto密码新手引导模式&#xff08;一&#xff09;&#xff08;持续更新&#xff09; 1. 转轮机加密 首先了解一下轮转机加密吧。 传统密码学(三)——转轮密码机 题目内容如下&#xff1a; …

10.12按键中断

设置按键中断&#xff0c;按键1按下&#xff0c;LED亮&#xff0c;再按一次&#xff0c;灭 按键2按下&#xff0c;蜂鸣器响。再按一次&#xff0c;不响 按键3按下&#xff0c;风扇转&#xff0c;再按一次&#xff0c;风扇停 keyit.h: #ifndef __KEYIT_H__ #define __KEYIT_…

全民拼购:重新定义电商营销的新模式

随着电子商务的飞速发展&#xff0c;各种新型的电商模式应运而生。全民拼购作为一种全新的电商营销模式&#xff0c;正在被越来越多的企业家所关注。本文将详细介绍全民拼购的概念、规则、优势以及玩法&#xff0c;为企业家们提供全面的了解和参考。 一、全民拼购的概念和背景…

数据结构:链表(2),链表面试题

203. 移除链表元素 - 力扣&#xff08;LeetCode&#xff09; 给你一个链表的头节点 head 和一个整数 val &#xff0c;请你删除链表中所有满足 Node.val val 的节点&#xff0c;并返回 新的头节点 。 示例 1&#xff1a; 输入&#xff1a;head [1,2,6,3,4,5,6], val 6 输出…

【运维笔记】swow源码编译安装

swow的github网址 https://github.com/swow/swow 从github中拉取源码 git pull https://github.com/swow/swow.git 编译安装 github中readme文件讲述了安装方法 这里整理了命令&#xff0c;进入拉取项目的目录后依次执行命令即可 #pwd 确保自己在swow目录中&#xff0c;如…

TabLayout在平板未铺满全屏

具体的参数设置如下&#xff1a; 1. 宽度一定要设置成 match_parent, 即 android:layout_width"match_parent" 2. tabGravity设置成fill, 即 app:tabGravity"fill" 3. tabMaxWidth设置成 0dp, 即 app:tabMaxWidth"0dp" 4. tabMode设置成fix…

Python 机器学习入门之逻辑回归

系列文章目录 第一章 Python 机器学习入门之线性回归 第一章 Python 机器学习入门之梯度下降法 第一章 Python 机器学习入门之牛顿法 第二章 Python 机器学习入门之逻辑回归 逻辑回归 系列文章目录前言一、逻辑回归简介二、逻辑回归推导1、问题2、Sigmoid函数3、目标函数3.1 让…

RunnerGo测试平台,无代码玩转UI自动化测试

首先需要进入官网&#xff0c;RunnerGo支持开源&#xff0c;可以自行下载安装&#xff0c;也可以点击右上角体验企业版按钮快速体验 点击体验企业版进入工作台后可以点击页面上方的UI自动化 进入到测试页面 创建元素 我们可以在元素管理中创建我们测试时需要的元素 这里我们以…