h5相機功能

h5相機功能

利用vant + input file

<template><div class="mb10"><divv-for="(item, index) in info.imgList":key="index"class="imgItem f32 mr20"@click="preview(item, index)"><img :src="doFileUrl(item)" alt="" srcset="" /><van-iconv-if="!disabled"class="close f34 txt-f6"name="close"@click.stop="deleteImg(item, index)"/></div><divv-show="info.imgList.length < maxCount && !disabled"class="btnUpload f32 mr10"@click="clickUpload"><van-icon name="plus" /><inputref="camera"class="cameraInput"type="file"name="file"accept="image/*"capture="camera"@change="uploadImg"/></div></div><!-- 底部彈出 --><van-action-sheetv-model:show="showChoose":actions="info.actions"cancel-text="取消"close-on-click-action@cancel="onCancel"@select="selectAction"/>
</template><script lang="ts" setup>
import { ref, getCurrentInstance, reactive, onMounted, defineExpose } from 'vue'
import { Action, InfoInterface } from './config'
import { fileUpload } from '@/utils/fileHttp'const emit = defineEmits(['chooseFIle'])
/*** @description: 傳參* @return {*}* @Date Changed:*/
interface Props {// 文件listfileList: string | null | any[]// 上傳數量maxCount?: number//尺寸  這個暫時沒用maxSize?: number// 縮略圖大小 px 和 remdisabled?: boolean// 圖片類型accept?: string[]type?: number[]// 是否全部允許allowAllAccept?: booleanisRequire?: boolean//
}
const props = withDefaults(defineProps<Props>(), {fileList: () => [],maxCount: 1,maxSize: 5 * 1024 * 1024,disabled: false,accept: () => ['image'],type: () => [0],allowAllAccept: false,isRequire: false
})/*** @description: 通用參數* @return {*}* @Date Changed:*/
const { proxy }: any = getCurrentInstance()
const router = proxy.commond.router()
const route = proxy.commond.route()
const { Toast } = proxy.commondconst info = reactive<InfoInterface>({imgList: [],actions: []// aaaaaa: []
})
let toastLoading: any = null
const token = proxy.commond.getToken()/*** @description: 生命周期* @return {*}* @Date Changed:*/
onMounted(() => {init()
})
const init = () => {// 拍照模式const arr: Action[] = []props.type.forEach((item: number) => {arr.push(list[item])})info.actions = arr
}//----------------------------------------------------------- 底部彈出選擇拍照模式
const showChoose = ref(false)
const list: Action[] = [{name: '拍照',type: 'ShowView',value: 'CameraView'},{name: '相冊',type: 'ShowView',value: 'PhotoView'},{name: '文件上傳',type: 'uploadFile',value: 'fileView'}
]
const clickUpload = () => {showChoose.value = true
}
const onCancel = () => {showChoose.value = false
}
const selectAction = async (action: Action, index: number) => {if (action.value === 'CameraView') {// 拍照console.log(proxy.$refs.camera)proxy.$refs.camera.click()showChoose.value = false}// if (res.length > 0) {// 	const arr = proxy.commond.deepClone(info.imgList)// 	res.map((ele) => {// 		arr.push(`OSS_FILE_${ele.resourcesId}/${ele.fullFileName}`)// 	})// 	emit('success', arr)// 	showChoose.value = false// }
}/*** @description: 上傳文件* @return {*}*/const uploadImg = (e: any) => {// 這里可以做一些限制 比如 文件大小 文件類型等// ----------const file = e.target.files[0]// 原生請求toastLoading = proxy.commond.Toast.loading({duration: 0,forbidClick: true,message: '開始上傳...'})fileUpload(file).then((data: any) => {const url = `OSS_FILE_${data.result.resourcesId}/${data.result.fullFileName}`info.imgList.push(url)emit('chooseFIle', info.imgList, file)toastLoading.clear()proxy.$refs.camera.value = ''}).catch((err) => {toastLoading.clear()proxy.commond.Toast(err.message)proxy.$refs.camera.value = ''})
}const doFileUrl = (resourcesId: string): string => {return proxy.commond.doFileUrl(resourcesId)
}/*** @description: 刪除照片* @param {*} val* @param {*} index* @return {*}*/
const deleteImg = (val: string, index: number) => {info.imgList.splice(index, 1)emit('chooseFIle', info.imgList, '')
}/*** @description: 圖片預覽* @param {*} val* @param {*} index* @return {*}*/
const preview = (val: string, index: number) => {const arr: string[] = []info.imgList.forEach((ele) => {arr.push(doFileUrl(ele))})proxy.commond.ImagePreview({images: arr,startPosition: index})
}defineExpose({selectAction,preview
})
</script><style lang="scss" scoped>
.cameraInput {position: absolute;left: 0;right: 0;bottom: 0;top: 0;display: none;
}.btnUpload {position: relative;text-align: center;background-color: #fbfdff;border: 1px dashed #c0ccda;border-radius: 6px;box-sizing: border-box;display: inline-block;width: 148px;height: 148px;cursor: pointer;line-height: 146px;vertical-align: top;
}.imgItem {display: inline-block;position: relative;border: 1px dashed #c0ccda;width: 148px;height: 148px;cursor: pointer;img {margin-top: 4px;width: 140px;height: 140px;}.close {position: absolute;right: -14px;top: -10px;background: #fff;border-radius: 100px;color: $danger;}
}
</style>
/*** @description: 上傳文件景天參數* @return {*}* @Date Changed:*/
export interface Action {name: stringtype: stringvalue: string
}/*** @description:圖片返回值處理* @return {*}* @Date Changed:*/
export interface ImgFace {resourcesId: stringresourceUrl: stringfullFileName: stringfileName: stringid: string
}/*** @descriptioninfo* @return {*}* @Date Changed:*/
export interface InfoInterface {imgList: string[]actions: Action[]
}export interface fileBox {show: booleanurl: string
}

使用

// 調用相機<GlFace ref="face" :file-list="[]" @chooseFIle="chooseFIle"></GlFace>
const face = ref(null)face.value.selectAction({ value: 'CameraView' })

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/bicheng/22171.shtml
繁體地址,請注明出處:http://hk.pswp.cn/bicheng/22171.shtml
英文地址,請注明出處:http://en.pswp.cn/bicheng/22171.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

<sa8650>QCX Usecase 使用詳解—如何在管道中添加多個 IPE 實例

<sa8650>QCX Usecase 使用詳解—如何在管道中添加多個 IPE 實例 一、前言二、UsecaseSRV添加新格式三、更新usecase.xml四、定義 IPE 的新實例五、添加新鏈接六、QCarcam測試XML一、前言 本節說明在使用Usecase/Pipeline XML 中添加多個 IPE 實例所需的更改。以下示例解釋了…

使用Spring Boot和MybatisPlus的Java CRM客戶關系管理系統源碼

項目名稱&#xff1a;CRM客戶關系管理系統 功能模塊及描述&#xff1a; 一、待辦事項 今日需聯系客戶&#xff1a;顯示當日需跟進的客戶列表&#xff0c;支持查詢和篩選。 分配給我的線索&#xff1a;管理分配給用戶的線索&#xff0c;包括線索列表和查詢功能。 分配給我的客…

導彈研究中常用坐標系及坐標系之間的變換

在導彈飛行控制過程中&#xff0c;需要時刻掌握導彈的飛行狀態 &#xff08;速度、位置、姿態角等&#xff09;&#xff0c;這就有賴于描述導彈飛行狀態的坐標系。除了大地坐標系和地心大地直角坐標系外&#xff0c;導彈常用的坐標系還有很多&#xff0c;合理而恰當地選擇參考系…

golang調用外部程序包os/exec中的 Command和CommandContext 函數創建的Cmd對象的區別

在go語言中&#xff0c;我們可以通過os/exec包中的Command和CommandContext 函數創建對應的外部程序執行Cmd對象&#xff0c; 這2個函數創建的cmd命令執行對象是有區別的&#xff0c;CommandContext創建的對象可以攜帶上下文&#xff0c;這個主要用于我們通過cancel函數給對應的…

37【透視】兩點透視

1 兩點透視比較合適表現物體的結構 用兩點透視繪制比較小的、箱子之類的物體 2 一點透視和兩點透視的共存關系

【Binaryen】partiallyPrecompute函數梳理

在Binaryen中有一個優化名為Precompute&#xff0c;作用是進行一些提前計算&#xff0c;類似于LLVM中的常量折疊類似的操作。 涉及的提交文件在此。 首先放一下全部的代碼&#xff1a; // To partially precompute selects we walk up the stack from them, like this://// …

vs - vs2013/vs2019工程文件的區別

文章目錄 vs - vs2013/vs2019工程文件的區別概述筆記sln文件的區別VisualStudioVersion vcxproj文件的區別ToolsVersionPlatformToolset 備注更方便的方法END vs - vs2013/vs2019工程文件的區別 概述 為了避免安裝UCRT的問題&#xff0c;想將手頭的vs2019工程降級為vs2013工程…

VLM MobileVLM 部署筆記

目錄 模型是自動下載的 在1060顯卡上能跑 LLaMA Meta MobileVLM V2 MobileLLaMA-1.4B 調錯 開源項目地址&#xff1a; GitHub - Meituan-AutoML/MobileVLM: Strong and Open Vision Language Assistant for Mobile Devices 模型是自動下載的 路徑&#xff1a; C:\User…

解決Mac ~/.bash_profile 配置的環境變量重啟終端后失效問題

在Mac系統中&#xff0c;配置環境變量通常是在~/.bash_profile文件中進行。然而&#xff0c;有時會遇到配置的環境變量在重啟終端后失效的問題。 解決辦法&#xff1a; 在~/.zshrc文件最后或最前面&#xff0c;增加一行 source ~/.bash_profile

SARscape雷達圖像處理軟件簡介

合成孔徑雷達&#xff08;SAR&#xff09;擁有獨特的技術魅力和優勢&#xff0c;漸成為國際上的研究熱點之一&#xff0c;其應用領域越來越廣泛。SAR數據可以全天候對研究區域進行量測、分析以及獲取目標信息。高級雷達圖像處理工具SARscape&#xff0c;能讓您輕松將原始SAR數據…

Leetcode 第 131 場雙周賽題解

Leetcode 第 131 場雙周賽題解 Leetcode 第 131 場雙周賽題解題目1&#xff1a;3158. 求出出現兩次數字的 XOR 值思路代碼復雜度分析 題目2&#xff1a;3159. 查詢數組中元素的出現位置思路代碼復雜度分析 題目3&#xff1a;3160. 所有球里面不同顏色的數目思路代碼復雜度分析 …

AI 時代,產品經理該如何進化

前言 傳統的互聯網業務或者游戲業務&#xff0c;產品或者業務輸出需求&#xff0c;技術人員只需要指哪打哪就好了。而人工智能發展到當下這個尷尬的階段&#xff0c;仿佛它能干很多事&#xff0c;但是真把它往業務里擱就發現&#xff0c;這個叛逆的小東西不一定勝任的了這些有…

AI大模型學習筆記之四:生成式人工智能是如何工作的?

OpenAI 發布 ChatGPT 已經1年多了&#xff0c;生成式人工智能&#xff08;AIGC&#xff09;也已經廣為人知&#xff0c;我們常常津津樂道于 ChatGPT 和 Claude 這樣的人工智能系統能夠神奇地生成文本與我們對話&#xff0c;并且能夠記憶上下文情境。 GPT-4多模態分析對話 Midj…

數字機頂盒、顯示器方案DCDC芯片OC5816 2A,18V同步降壓DC-DC

概述 OC5816 是一款 2A 的高集成度、高效率同步整流降壓轉換器。在一個相當寬的輸出電流負載范圍內&#xff0c;OC5816 可以高效工作。 OC5816 的兩種工作模式&#xff0c;固定頻率PWM 峰值電流控制和輕載 PFM 開關模式&#xff0c;允許系統高效工作在一個相當寬的輸出電流…

i 人 聊 天 手 冊(e人禁止入內)

在之前的讀書筆記-《蔡康永的說話之道》中&#xff0c;作者給大家分享了很多具體的要點&#xff0c;其更偏向于戰術層面&#xff0c;我更想要的是一個類似聊天手冊的東西&#xff0c;就讓我自己來總結下吧。 雖然在 MBTI 中&#xff0c;按照獲取能量的方式定義了 i 人、e 人&a…

【面試干貨】如何選擇MySQL數據庫存儲引擎(MyISAM 或 InnoDB)

【面試干貨】如何選擇MySQL數據庫存儲引擎(MyISAM 或 InnoDB&#xff09; &#x1f496;The Begin&#x1f496;點點關注&#xff0c;收藏不迷路&#x1f496; MySQL數據庫存儲引擎是一個 關鍵 的考慮因素。MySQL提供了多種存儲引擎&#xff0c;其中最常用的是 MyISAM 和 InnoD…

封裝一個頁面自適應方法

封裝一個頁面自適應方法 在 Vue 中&#xff0c;你可以封裝一個頁面自適應的方法來根據屏幕大小動態調整頁面的布局和樣式。以下是一個示例代碼&#xff1a; export const getPageSize () > {const { innerWidth, innerHeight } window;const width innerWidth > 192…

攻防世界---misc---a_good_idea

1、下載附件得到一張圖片&#xff0c;winhex分析&#xff0c;發現有壓縮包 2、在kali中用普通用戶對jpg進行binwalk 3、得到兩張圖片和一個文本&#xff0c;查看文本信息&#xff1a;提示試著找到像素的秘密 4、提到像素就想到了Stegsolve這個工具&#xff0c;將這兩張圖片用該…

rpm打包 postgres14.9 repmgr pgpool

rpm打包 postgres14.9 repmgr pgpool 上一篇講解了rpm打包的基礎知識之后&#xff0c;我們就可以根據實際業務自行打包了&#xff0c;需要注意的是依賴問題&#xff0c;需要提前講依賴準備好&#xff0c;對于各種系統需要的依賴的依賴也不一致&#xff0c;可以根據具體報錯去相…

Python項目開發實戰:二手房數據分析預測系統(案例教程)

一、項目背景與意義 在房地產市場日益繁榮的今天,二手房市場占據了重要地位。對于購房者、房地產中介和開發商來說,了解二手房市場的動態、價格趨勢以及潛在價值至關重要。因此,開發一個基于Python的二手房數據分析預測系統具有實際應用價值和商業意義。本項目旨在利用Pytho…