unapp写微信小程序封装水印相机组件怎么实现?

news2024/9/25 9:30:19
<template>
	<view>
		<!-- <cu-custom bgColor="bg-gradual-blue" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">编辑资料</block>
		</cu-custom> -->
		<view>
			<camera :device-position="device" :flash="flash" @error="error"
				:style="{ width: '100%', position: 'relative', height: getHeight + 'px' }">
				<cover-view class="topBox">
					<cover-view class="topItem text-bold text-xl">你的美丽你知道!</cover-view>
					<cover-view class="topItem">{{ nowTime2 }}</cover-view>
					<cover-view class="topItem">{{ nowTime }}</cover-view>
					<cover-view class="topItem">{{ address }}</cover-view>
				</cover-view>

				<cover-image @click="xzBtn" class="xzImg" src="https://cdn.zhoukaiwen.com/xz.png"></cover-image>
				<cover-image @click="sgdBtn" class="sgdImg" :src="sgdUrl"></cover-image>

				<cover-view class="cameraBtn" @click="takePhoto">
					<cover-view class="cameraBtn2"></cover-view>
				</cover-view>


				<cover-view class="bottomBtn" v-if="imgList.length < 1">
					<cover-view @click="history" class="btn">历史</cover-view>
					<cover-view class="btn" @click="goBack">取消</cover-view>
				</cover-view>

				<cover-view class="bottomBg" v-if="imgList.length > 0">
					<cover-view>
						<cover-view @click="ViewImage(index)" class="imgBox" v-for="(item, index) in imgList"
							:key="index">
							<cover-image class="imgItem" :src="item.src" mode="aspectFill"></cover-image>
							<cover-view class="cu-tag" @tap.stop="DelImg" :data-index="index">
								<cover-image class="iconClose" src="https://cdn.zhoukaiwen.com/icon_close.png"
									mode="aspectFill"></cover-image>
							</cover-view>
						</cover-view>
					</cover-view>

					<cover-view @click="reportBtn" class="report">上报({{ imgList.length }})</cover-view>
				</cover-view>



				<cover-view v-if="rreportShow" class="reportBox animation-slide-bottom">
					<cover-view class="text-lg margin-left-sm margin-bottom-sm"
						style="height:78rpx;line-height: 78rpx;">请选择照片备注内容</cover-view>

					<cover-view class="listBox">
						<cover-view class="item active">韩系淡妆</cover-view>
						<cover-view class="item">幼态短中庭</cover-view>
						<cover-view class="item">淡颜减龄</cover-view>
						<cover-view class="item">证件照装</cover-view>
						<cover-view class="item">国泰民安</cover-view>
						<cover-view class="item">阳光青梅</cover-view>
						<cover-view class="item">韩系女主</cover-view>
						<cover-view class="item">贵气中国风</cover-view>
					</cover-view>

					<cover-view @click="endBtn" class="repBtn">上传</cover-view>

				</cover-view>

			</camera>

			<view style="position: absolute;top: -999999px;">
				<view><canvas :style="{ width: w, height: h }" canvas-id="firstCanvas"></canvas></view>
			</view>

		</view>
	</view>


</template>

<script>
import QQMapWX from "../../common/qqmap-wx-jssdk.js";
export default {
	data() {
		return {
			getHeight: '200',
			device: 'back', //前置或后置摄像头,值为front, back
			flash: 'off', //闪光灯,值为auto, on, off
			nowTime: '', //日期
			nowTime2: '', //时间
			address: '',	//当前地址信息
			sgdUrl: 'https://cdn.zhoukaiwen.com/sgd.png',
			imgList: [
				// {
				// 	src: "https://cdn.zhoukaiwen.com/angular.jpg"
				// }
			],
			imgListData: '',

			rreportShow: false, //选择照片备注内容弹窗

			src: '',
			w: '',
			h: ''
		}
	},
	onLoad() {
		const that = this;
		var qqmapsdk;
		uni.getSystemInfo({
			success: function (res) {
				that.getHeight = res.windowHeight;
			}
		});

		uni.showModal({
			title: '你的美丽你知道!',
			content: '留下你的美🌹,世界因你而美丽!🌍',
			showCancel: false,
			confirmText: '最美不过我自己,🌺!',
			confirmColor: '#3056F6',
			success: function (res) {
				if (res.confirm) {
					console.log('用户点击确定');
				}
			}
		});

		this.getTime();

		uni.getLocation({
			type: 'wgs84',
			success: function (res) {
				console.log('当前位置的经度:' + res.longitude);
				console.log('当前位置的纬度:' + res.latitude);

				qqmapsdk = new QQMapWX({
					key: "HMUBZ-PQLEG-6I3QM-Q67MV-7FXK3-FTF6H" //自己申请的key
				});
				qqmapsdk.reverseGeocoder({
					location: {
						latitude: res.latitude,
						longitude: res.longitude
					},
					success(addressRes) {
						console.log(addressRes)
						that.address = addressRes.result.formatted_addresses.standard_address;
						console.log('当前位置的详细地址:' + addressRes.result.formatted_addresses.standard_address);
					},
					fail(res) { }
				});
			}
		});

	},
	methods: {
		// 上报:最终上报
		endBtn() {
			this.rreportShow = false;
			this.imgList = [];

		},
		// 上报:选择类型
		reportBtn() {
			this.rreportShow = true;

			var str = this.imgListData;
			var newImgData = this.imgListData.substr(0, this.imgListData.length - 1);
			console.log(newImgData,'上报的图片')
		},
		xzBtn() {
			if (this.device == 'front') {
				this.device = 'back'
			} else {
				this.device = 'front'
			}
		},
		sgdBtn() {
			if (this.flash == 'off') {
				this.flash = 'on'
				this.sgdUrl = 'https://cdn.zhoukaiwen.com/sgd_on.png'
			} else {
				this.flash = 'off'
				this.sgdUrl = 'https://cdn.zhoukaiwen.com/sgd.png'
			}
		},
		DelImg(e) {
			uni.showModal({
				// title: '异常照片',
				content: '确定要删除这张照片吗?',
				cancelText: '取消',
				confirmText: '确认',
				success: res => {
					if (res.confirm) {
						console.log(e)
						this.imgList.splice(e.currentTarget.dataset.index, 1)
						console.log(this.imgList)

						var arr = this.imgList;
						var str = '';
						for (var i = 0; i < arr.length; i++) {
							str += arr[i].src + ",";
						}
						this.imgListData = str;
						console.log(this.imgListData)
					}
				}
			})
		},
		// 查看照片
		ViewImage(index) {
			const imgList = [this.imgList[index].src];
			console.log(imgList,'拍的照片查看')
			uni.previewImage({
				urls: imgList
			});
		},
		// 点击拍照
		takePhoto() {
			var that = this;
			if (this.imgList.length < 1) {
				const ctx = uni.createCameraContext();
				ctx.takePhoto({
					quality: 'high',
					success: (res) => {
						var tempImagePath = res.tempImagePath;
						// 获取图片信息
						uni.getImageInfo({
							src: res.tempImagePath,
							success: ress => {
								that.w = ress.width / 3 + 'px';
								that.h = ress.height / 3.01 + 'px';
								let ctx = uni.createCanvasContext('firstCanvas'); /** 创建画布 */
								//将图片src放到cancas内,宽高为图片大小
								ctx.drawImage(res.tempImagePath, 0, 0, ress.width / 3, ress.height / 3);
								ctx.setFontSize(12);
								ctx.setFillStyle('#FFFFFF');
								// ctx.rotate(30 * Math.PI / 180);
								let textToWidth = (ress.width / 3) * 0.03;

								let textToHeight = (ress.height / 3) * 0.9;
								ctx.fillText('最美我自己!🌹', textToWidth, textToHeight);

								ctx.setFontSize(10);
								let textToHeight2 = (ress.height / 3) * 0.94;
								ctx.fillText(that.nowTime + ' ' + that.nowTime2, textToWidth, textToHeight2);

								let textToHeight3 = (ress.height / 3) * 0.98;
								ctx.fillText(that.address, textToWidth, textToHeight3);

								ctx.draw(false, () => {
									setTimeout(() => {
										uni.canvasToTempFilePath({
											canvasId: 'firstCanvas',
											success: res1 => {
												tempImagePath = res1.tempFilePath;
												console.log('----------', tempImagePath);
												this.imgList.push({
													src: tempImagePath
												})
												console.log(this.imgList,'拍的图片数组');

												var arr = this.imgList
												var str = '';
												for (var i = 0; i < arr.length; i++) {
													str += arr[i].src + ",";
												}
												this.imgListData = str;
												console.log(this.imgListData,"拍的图片")
											}
										});
									}, 1000);
								});
							}
						});
					}
				});
			} else {
				uni.showToast({
					title: '最大上传1张照片',
					duration: 2000,
					icon: 'none'
				});
			}

		},
		error(e) {
			console.log(e.detail);
		},
		getTime: function () {
			var date = new Date(),
				year = date.getFullYear(),
				month = date.getMonth() + 1,
				day = date.getDate(),
				hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(),
				minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes(),
				second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
			month >= 1 && month <= 9 ? (month = "0" + month) : "";
			day >= 0 && day <= 9 ? (day = "0" + day) : "";
			var timer = year + '年' + month + '月' + day + '日';
			var timer2 = hour + ':' + minute + ':' + second;
			this.nowTime = timer;
			this.nowTime2 = timer2;

			console.log(this.nowTime);
			console.log(this.nowTime2);
		},
		goBack() {
			uni.navigateBack({
				delta: 1
			});
		},
		history() {
			uni.navigateTo({
				url: 'timeline'
			})
		}
	}
}
</script>

<style lang="scss">
.topBox {
	width: 750rpx;
	box-sizing: border-box;
	padding: 30rpx;
	color: #EEEEEE;
	font-size: 34rpx;

	.topItem {
		width: 100%;
		white-space: pre-wrap;
		margin-bottom: 15rpx;
	}
}

.cameraBtn {
	width: 120rpx;
	height: 120rpx;
	line-height: 120rpx;
	border: 6rpx #FFFFFF solid;
	border-radius: 50%;
	padding: 8rpx;
	position: absolute;
	left: calc(50% - 60rpx);
	bottom: 210rpx;
}

.cameraBtn2 {
	width: 100%;
	height: 100%;
	border-radius: 50%;
	background-color: #FFFFFF;
	text-align: center;
	color: #007AFF;
}

.xzImg {
	width: 52rpx;
	height: auto;
	position: absolute;
	right: 44rpx;
	bottom: 580rpx;
}

.sgdImg {
	width: 40rpx;
	height: auto;
	position: absolute;
	right: 50rpx;
	bottom: 450rpx;
}

.bottomBtn {
	width: 100%;
	height: 150rpx;
	padding-bottom: 15rpx;
	position: absolute;
	bottom: 0;
	left: 0;
	text-align: center;
	display: flex;
	justify-content: space-between;

	.btn {
		width: 30%;
		height: 150rpx;
		font-size: 34rpx;
		color: #FFFFFF;
		line-height: 150rpx;
	}
}

.bottomBg {
	width: 100%;
	height: 170rpx;
	box-sizing: border-box;
	padding: 20rpx 30rpx 40rpx;
	position: absolute;
	bottom: 0;
	left: 0;
	background-color: rgba(0, 0, 0, .8);
	display: flex;
	justify-content: space-between;
	align-items: center;

	.imgBox {
		width: 110rpx;
		height: 110rpx;
		float: left;
		margin-right: 40rpx;
		position: relative;

		.cu-tag {
			position: absolute;
			right: 0;
			top: 0;
			border-bottom-left-radius: 2px;
			padding: 3px 5px;
			height: auto;
			background-color: rgba(0, 0, 0, 0.5);
			font-size: 10px;
			vertical-align: middle;
			font-family: Helvetica Neue, Helvetica, sans-serif;
			white-space: nowrap;
			color: #ffffff;
		}
	}

	.imgItem {
		width: 110rpx;
		height: 110rpx;
	}
}

.report {
	height: 68rpx;
	line-height: 68rpx;
	text-align: center;
	color: #FFFFFF;
	box-sizing: border-box;
	padding: 0rpx 20rpx;
	border-radius: 10rpx;
	background-color: #2157FF;
}

.iconClose {
	width: 20rpx;
	height: 20rpx;
}

.reportBox {
	width: 750rpx;
	height: auto;
	box-sizing: border-box;
	padding: 10rpx 20rpx;
	background-color: #FFFFFF;
	position: absolute;
	bottom: 0;
}

.listBox {
	display: flex;
	flex-wrap: wrap;
	justify-content: space-around;

}

.item {
	width: 160rpx;
	height: 68rpx;
	line-height: 68rpx;
	text-align: center;
	background: #F7F7F9;
	margin-bottom: 40rpx;
	color: #888888;

}

.active {
	background-color: #F1F7FF;
	color: #025ADD;
}

.repBtn {
	width: 680rpx;
	height: 78rpx;
	line-height: 78rpx;
	background-color: #025ADD;
	color: #FFFFFF;
	font-size: 33rpx;
	text-align: center;
	border-radius: 10rpx;
	margin: 5rpx auto 20rpx;
}
</style>

 

上述组件中首先我用到了定位,大家可以在腾讯地图控制台中配置相关所需,具体配置的大家可以查看我往期的文档我都有编写,这里只是给大家分享一个组件,具体的功能还得大家自己实现、

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1677624.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

让大模型更贴近人类认知水平,上海AI实验室发布首个因果推理评测体系CaLM

近日&#xff0c;上海人工智能实验室&#xff08;上海AI实验室&#xff09;联合同济大学、上海交通大学、北京大学及商汤科技发布首个大模型因果推理开放评测体系及开放平台CaLM&#xff08;Causal Evaluation of Language Models&#xff0c;以下简称“CaLM”&#xff09;。首…

MySQL:MySQL索引结构为什么选用B+树?

一、前言 当我们发现SQL执行很慢的时候&#xff0c;自然而然想到的就是加索引。在MySQL中&#xff0c;无论是Innodb还是MyIsam&#xff0c;都使用了B树作索引结构。我们知道树的分类有很多&#xff0c;MySQL中使用了B树作索引结构&#xff0c;这是为什么呢&#xff1f; 本文将从…

HOJ 修改首页 和后端logo图片 网页收藏标识ico 小白也会的方法

HOJ 是一款优雅知性的在线评测系统&#xff0c;像一位温文尔雅的女性&#xff0c;你会慢慢喜欢上她的。 制作图片素材 用图像编辑软件 比如 **光影魔术手4.0** 制作以下素材 logo.a0924d7d.png 为前台导航栏左边的logo&#xff0c; 600*200 backstage.8bce8c6e.png 为后台侧…

虚拟化技术 在vCenter Server创建数中心、添加主机

一、实验内容 1.安装Flash 2.在vCenter Server创建数中心、添加主机 二、实验主要仪器设备及器材 1.安装有64位Windows操作系统的台式电脑或笔记本电脑&#xff0c;建议4C8G或以上配置 2.在Windows Server 2008 R2已安装vCenter Server 3.Adobe Flash Player 12.0.0.70.e…

数据结构【顺序表】

文章目录 1.顺序表的概念线性表物理结构逻辑结构 2.顺序表的分类2.1静态顺序表2.2动态顺序表 3.顺序表接口的实现头文件(SQList.h)如下源文件初始化顺序表销毁顺序表插入扩容尾插头插 封装扩容函数删除尾删头删 查找元素在指定位置前插入数据情况一(指定的位置不是首元素)情况二…

CMF认证是什么?怎么报名?考试费用多少?有必要参加培训吗?

CMF认证是由国际变革管理学院&#xff08;CMI&#xff09;颁发的一种认证&#xff0c;旨在评估个人在变革管理领域的知识和技能&#xff0c;并确认其在该领域具备专业能力。通过学习和理解变革管理知识体系&#xff08;CMBoK&#xff09;&#xff0c;参与者可以掌握变革管理的理…

4 特征构造

4 特征构造 学习目标 知道未来信息的概念,及处理未来信息的方法掌握从原始数据构造出新特征的方法掌握特征变换的方法掌握缺失值处理的方法1 数据准备 1.1 梳理数据的内在逻辑 关系种类 一对一:一个用户有一个注册手机号 一对多:一个用户多笔借款 多对多:一个用户可以…

第1章 初始Spring Boot【仿牛客网社区论坛项目】

第1章 初始Spring Boot【仿牛客网社区论坛项目】 前言推荐项目总结第1章初识Spring Boot&#xff0c;开发社区首页1.课程介绍2.搭建开发环境3.Spring入门体验IOC容器体验Bean的生命周期体验配置类体验依赖注入体验三层架构 4.SpringMVC入门配置体验响应数据体验响应Get请求体验…

【原创】java+springboot+mysql企业邮件管理系统设计与实现

个人主页&#xff1a;程序猿小小杨 个人简介&#xff1a;从事开发多年&#xff0c;Java、Php、Python、前端开发均有涉猎 博客内容&#xff1a;Java项目实战、项目演示、技术分享 文末有作者名片&#xff0c;希望和大家一起共同进步&#xff0c;你只管努力&#xff0c;剩下的交…

jar包安装成Windows服务

一、前言 很多年前写过一篇《使用java service wrapper把windows flume做成服务》的文章&#xff0c;也是把jar包安装成windows服务&#xff0c;今天介绍另外一种更简便的方案。 二、正片 这次使用的工具是 winsw&#xff0c;一个Windows服务包装器。下面看详细介绍 首先从g…

QT状态机8-使用恢复策略自动恢复属性

当状态分配的属性不再活动时,可能希望将其恢复到初始值,通过设置全局的恢复策略可以使状态机进入一个状态而不用明确制定属性的值。 QStateMachine machine; machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);当设置了恢复策略以后,状态机将自动恢复所有…

神策数据付力力入选福布斯中国 30 Under 30 十周年名人堂

福布斯中国 30 UNDER 30&#xff08;U30&#xff09; 持续关注青年才俊。在 U30 十周年之际&#xff0c;福布斯中国通过跟踪、梳理、比较历年 U30 们入选后的表现、社会影响力事件&#xff0c;以及创业精神诠释&#xff0c;编制了福布斯中国首期 U30 名人堂名单。神策数据联合创…

低代码开发平台在城市数字化转型中的技术实现与案例分析

城市数字化转型需要政策引导、技术创新、基础设施建设、人才培养、多方合作以及安全保障等全方位的支持与助力&#xff0c;共同推动城市的数字化进程&#xff0c;提升其竞争力和可持续发展能力。 其中&#xff0c;技术创新是推动数字化转型的核心动力&#xff0c;需要不断加强…

从零开始详解OpenCV条形码区域分割

前言 在识别二维码之前&#xff0c;首先要划分出二维码的区域&#xff0c;在本篇文章中将从零开始实现二维码分割的功能&#xff0c;并详细介绍用到的方法。 我们需要处理的图像如下&#xff1a; 完整代码 首先我们先放出完整代码&#xff0c;然后根据整个分割流程介绍用到…

英伟达的GDS

英伟达的GDS&#xff0c;即GPUDirect Storage&#xff0c;是英伟达开发的一种技术&#xff0c;它允许GPU直接访问存储设备&#xff0c;从而显著提高数据传输效率和性能。 以下是对英伟达GDS的详细介绍&#xff1a; 一、GDS技术的主要特点和优势 直接内存存取&#xff1a;GDS通…

【设计模式】JAVA Design Patterns——Acyclic Visitor(非循环访问者模式)

&#x1f50d;目的 允许将新功能添加到现有的类层次结构中&#xff0c;而不会影响这些层次结构&#xff0c;也不会有四人帮访客模式中那样循环依赖的问题。 &#x1f50d;解释 真实世界例子 我们有一个调制解调器类的层次结构。 需要使用基于过滤条件的外部算法&#xff08;是…

使用 python 整理 latex 的 bib 文献列表

目录 bib 文献整理脚本前提条件与主要功能原理编程语言与宏包基础完整程序 bib 文献整理脚本 本文主要用于解决 Latex 写作过程中遇到的 bib 文献整理问题&#xff0c;可处理中文文献。 LaTeX是一种基于ΤΕΧ的排版系统&#xff0c;它非常适用于生成高印刷质量的科技和数学类…

八大设计模式:适配器模式实现栈的泛型编程 | 通用数据结构接口的秘诀(文末送书)

&#x1f3ac; 鸽芷咕&#xff1a;个人主页 &#x1f525; 个人专栏: 《C干货基地》《粉丝福利》 ⛺️生活的理想&#xff0c;就是为了理想的生活! 引入 哈喽各位铁汁们好啊&#xff0c;我是博主鸽芷咕《C干货基地》是由我的襄阳家乡零食基地有感而发&#xff0c;不知道各位的…

pyautogui 基本用法

pyautogui 是一个 Python 库&#xff0c;可以让你用 Python 脚本控制鼠标和键盘。它适用于自动化桌面图形用户界面&#xff08;GUI&#xff09;的任务&#xff0c;比如自动化测试、游戏脚本或任何需要模拟用户输入的程序。 以下是使用 pyautogui 的一些基础示例&#xff1a; 安…

地平线旭日X3开发板编译USB网卡驱动 AX88772B

由于使用的激光雷达是网口输出的&#xff0c; 为了不占用X3派已有的网口&#xff0c;接上去了一个绿联的usb网卡&#xff0c; 发现系统没有驱动&#xff0c;所以动手看看能不能自己编译一个 首先lsusb查看一下网卡型号 发现型号是AX88772B&#xff0c;去官网看了一下&#x…