当前位置: 首页 > news >正文

微信小程序拍照页面自定义demo

api文档

<template><div><imagemode="widthFix"style="width: 100%; height: 300px":src="imageSrc"v-if="imageSrc"></image><camerav-else:device-position="devicePosition":flash="flash"@error="cameraError"style="width: 100%; height: 300px"></camera><div class="buttons flex justify-between" v-if="!imageSrc"><div class="button" @click="openFlash">{{ flash === "off" ? "闪光关闭" : "闪光打开" }}</div><div class="button cameral" @click="takePhoto"></div><div class="button" @click="frontAndAfter">{{ devicePosition === "back" ? "后置" : "前置" }}</div></div><div class="buttons flex justify-between" v-else><div class="resetPhoto" @click="resetPhoto">重新拍照</div><div class="confirmPhoto" @click="confirmPhoto">确认</div></div></div>
</template>
<script>
import meServiceApi from "@/service/me.js";export default {data() {return {imageSrc: "",flash: "off",devicePosition: "back",};},methods: {takePhoto() {const ctx = wx.createCameraContext();const that = this;ctx.takePhoto({quality: "high",success: (res) => {that.imageSrc = res.tempImagePath;console.log("拍照的路径", res.tempImagePath);},});},cameraError(e) {console.log(e.detail);},openFlash() {switch (this.flash) {case "off":this.flash = "on";break;default:this.flash = "off";break;}},frontAndAfter() {switch (this.devicePosition) {case "back":this.devicePosition = "front";break;default:this.devicePosition = "back";break;}},async confirmPhoto() {// 上传到服务器console.log(this.imageSrc, "this.imageSrc");const res = await meServiceApi.upFileImg(this.imageSrc);console.log("上传的图片", res);},resetPhoto() {this.imageSrc = "";},},mounted() {},
};
</script>
<style scoped lang='scss'>
.buttons {position: fixed;bottom: 20rpx;left: 0;width: 100%;height: 144rpx;padding: 20rpx 0;color: #fff;background-color: #000;.cameral {position: absolute;top: 10rpx;left: 40%;width: 144rpx;height: 140rpx;border-radius: 50%;border: 3px solid #f5222d;}
}
</style>
http://www.lryc.cn/news/212338.html

相关文章:

  • 单目标应用:进化场优化算法(Evolutionary Field Optimization,EFO)求解微电网优化MATLAB
  • 推荐算法面试
  • 长图切图怎么切
  • 动手学深度学习 - 学习环境配置
  • 洛谷 B2004 对齐输出 C++代码
  • seccomp学习 (1)
  • Linux指令【上】
  • RK3568-clock
  • 新恶意软件使用 MSIX 软件包来感染 Windows
  • 干货!数字IC后端入门学习笔记
  • 力扣:144. 二叉树的前序遍历(Python3)
  • 【数据挖掘 | 数据预处理】缺失值处理 重复值处理 文本处理 确定不来看看?
  • 二叉树问题——前/中/后/层遍历(递归与栈)
  • Nor Flash和Nand Flash的区别——笔记
  • 7+共病思路。WGCNA+多机器学习+实验简单验证,易操作
  • 开发者看亚马逊云科技1024【文末有福利~】
  • 操作系统(Linux)外壳程序shell 、用户、权限
  • C文件操作
  • drawio特性
  • LLM-Embedder
  • xsync 集群远程同步脚本
  • 30秒get视频号视频如何下载,保存视频号视频到本地方法!
  • 优化改进YOLOv5算法:加入SPD-Conv模块,让小目标无处遁形——(超详细)
  • 【数据结构】搜索树 与 Java集合框架中的Set,Map
  • 掌握组件缓存:解开Vue.js中<keep-alive>的奥秘
  • Ajax学习笔记第5天
  • 20.1 OpenSSL 字符BASE64压缩算法
  • Panda3d 教程
  • 除自身以外数组的乘积
  • 干洗店小程序上门洗鞋店管理软件功能介绍;