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

<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, backflash: 'off', //闪光灯,值为auto, on, offnowTime: '', //日期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.imgListvar 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.hqwc.cn/news/702618.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

如何使用AzurEnum快速枚举Microsoft Entra ID(Azure AD)

AzurEnum是一款针对Azure的安全工具&#xff0c;在该工具的帮助下&#xff0c;广大研究人员可以轻松快速地枚举Microsoft Entra ID&#xff08;Azure AD&#xff09;。 该工具基于纯Python 3开发&#xff0c;可以在Windows和Linux系统上运行&#xff0c;但考虑到性能和稳定性&a…

网易云如何改ip地址到另外城市

在数字化时代&#xff0c;网络音乐平台已经成为我们日常生活中不可或缺的一部分。然而&#xff0c;有时候我们可能会因为某些原因想要改变自己的IP地址&#xff0c;网易云音乐作为国内领先的音乐平台&#xff0c;其强大的功能和丰富的音乐资源吸引了大量用户。那么&#xff0c;…

地平线旭日X3开发板Object Detection测试调试

旭日X3派具有最高5TOPS的等效算力 (X3M BPU主频1.2GHz、算力5TOS; X3E BPU 主频0.6GHZ&#xff0c;算力3TOPS)&#xff0c; 因此在开发板上可以运行丰富的AI算法。 在系统/app/ai_inference目录下提供了基础算法示例&#xff1a; 01_basic_sample 系统给出的测试程序只能对给…

【启明智显技术分享】工业级HMI芯片--Model系列(Model3C/Model3/Model4)烧录操作指南

前言 「Model系列」芯片是启明智显针对工业、行业以及车载产品市场推出的系列HMI芯片&#xff0c;主要应用于工业自动化、智能终端HMI、车载仪表盘、串口屏、智能中控、智能家居、充电桩显示屏、储能显示屏、工业触摸屏等领域。此系列具有高性能、低成本的特点&#xff0c;支持…

嵌入式—STC芯片开发板点亮第一盏灯

&#x1f3ac; 秋野酱&#xff1a;《个人主页》 &#x1f525; 个人专栏:《Java专栏》《Python专栏》 ⛺️心若有所向往,何惧道阻且长 文章目录 一&#xff1a; 原理图二&#xff1a; 需求实现三&#xff1a;编码实现四&#xff1a;代码实现五&#xff1a;编译烧录运行 一&…

OpenAI 重磅发布:ChatGPT Mac 桌面应用震撼上线!

OpenAI 重磅发布&#xff1a;ChatGPT Mac 桌面应用震撼上线&#xff01; 博主猫头虎的技术世界 &#x1f31f; 欢迎来到猫头虎的博客 — 探索技术的无限可能&#xff01; 专栏链接&#xff1a; &#x1f517; 精选专栏&#xff1a; 《面试题大全》 — 面试准备的宝典&#xff0…

1000平米气膜羽毛球馆造价多少钱—轻空间

羽毛球作为大众喜爱的运动方式&#xff0c;吸引了众多爱好者。因此&#xff0c;投资羽毛球场地有着广阔的市场前景。气膜建筑&#xff0c;作为一种时下最流行、最环保的绿色建筑&#xff0c;以其美观性和实用性&#xff0c;逐渐在国内普及。那么&#xff0c;投资一个1000平米的…

为Akamai 云平台上部署的资源配置2FA跳板机-上

为重要账户启用2FA&#xff0c;这几乎已经成为保护账户和数据安全的一种标准做法。无论登录常见应用或服务&#xff0c;或是访问企业内部资源&#xff0c;时不时都会需要进行2FA验证。那么当你在Akamai Connected Cloud云平台中部署了各类资源&#xff08;云计算、云存储、SaaS…

CTFshow 爆破

第一题0 抓包发现输入账号密码后数据包会多一个base64编码 所有推出用户密码在传输的时候进行了加密 所以爆破时也用base64加密 设置paylod 用题目给的字典 在添加两条规则 第一个是增加前缀 admin: 第二个是使得payload进行base64编码 取消URL编码字符 因为会把号编码了 开…

AI绘画入门指南:完备的AI绘画学习路线,十分钟把你领进门

2024新风口大揭秘&#xff01;不是直播&#xff0c;也不是短视频&#xff0c;而是AI绘本&#xff01; 有一句话说得好&#xff1a;站在风口上&#xff0c;猪都能飞起来&#xff01;想要用AI拿到大结果&#xff0c;一定要选对大的垂类赛道。 那么&#xff0c;为什么是AI绘本呢…

HBase无法给用户赋权的解决方案

建表之后&#xff0c;在赋权的时候&#xff0c;发现有错误 2.以开始以为语法有错误&#xff0c;不会啊&#xff0c;很简单的语法。经过测试几个命令发现&#xff0c;但凡和权限相关的命令&#xff0c;都失败了 百度到一些建议&#xff0c;需要检查参数&#xff0c;在确认下面…

OpenAI将最强人工智能拉入现实:GPT-4o情感交互颠覆认知——钢铁侠的“贾维斯”出生了,还是个女娃!

在科技飞速发展的今天&#xff0c;人工智能&#xff08;AI&#xff09;已不再是遥不可及的科幻概念&#xff0c;而是逐渐渗透进我们的日常生活。近期&#xff0c;OpenAI公司宣布推出其最新的人工智能模型GPT-4o&#xff0c;这一模型以其卓越的情感交互能力和高度的智能化水平&a…