|
@@ -1,7 +1,18 @@
|
|
|
<template>
|
|
|
<div class="camera-upload">
|
|
|
- <svg-icon icon-class="paizhao" size="80" @click="openMedia" />
|
|
|
- <svg-icon icon-class="bendishangchuan" size="80" @click="selectFile" />
|
|
|
+ <div class="row">
|
|
|
+ <svg-icon icon-class="paizhao" size="80" @click="openMedia" />
|
|
|
+ <svg-icon icon-class="bendishangchuan" size="80" @click="selectFile" />
|
|
|
+ </div>
|
|
|
+ <div class="row">
|
|
|
+ <svg-icon icon-class="paizhao" size="80" @click="clickReset" />
|
|
|
+ <svg-icon
|
|
|
+ icon-class="bendishangchuan"
|
|
|
+ size="80"
|
|
|
+ @click="clickDeleteAll"
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+
|
|
|
<input v-show="false" id="fileInput" accept="image/*" type="file" />
|
|
|
</div>
|
|
|
|
|
@@ -26,12 +37,11 @@
|
|
|
|
|
|
<script setup>
|
|
|
import { uploadFileApi } from "@/api/file";
|
|
|
-import * as uuidv4 from "uuid";
|
|
|
|
|
|
let mediaStreamTrack = null; // 视频对象(全局)
|
|
|
let video;
|
|
|
|
|
|
-const cameraEmit = defineEmits(["uploadFinish"]);
|
|
|
+const cameraEmit = defineEmits(["uploadFinish", "resetSelect", "deleteAll"]);
|
|
|
|
|
|
const openMedia = async () => {
|
|
|
visible.value = true;
|
|
@@ -81,7 +91,7 @@ function takePhoto() {
|
|
|
// toDataURL --- 可传入'image/png'---默认, 'image/jpeg'
|
|
|
let base64Data = document.getElementById("canvas").toDataURL();
|
|
|
let blob = dataURItoBlob(base64Data);
|
|
|
- let file = new File([blob], `${uuid()}.png`, { type: "image/png" });
|
|
|
+ let file = new File([blob], `photo.png`, { type: "image/png" });
|
|
|
|
|
|
uploadFileApi(file).then((res) => {
|
|
|
console.log("上传图片", res);
|
|
@@ -110,20 +120,28 @@ const selectFile = () => {
|
|
|
input.click();
|
|
|
input.onchange = function () {
|
|
|
let file = this.files[0];
|
|
|
- file.name = `${uuidv4()}${file.name.split(".")[1]}`;
|
|
|
+ console.log(file);
|
|
|
if (file) {
|
|
|
uploadFileApi(file).then((res) => {
|
|
|
- console.log("上传图片", res);
|
|
|
- cameraEmit("uploadFinish", res);
|
|
|
+ cameraEmit("uploadFinish", res.data);
|
|
|
});
|
|
|
}
|
|
|
};
|
|
|
};
|
|
|
+
|
|
|
+const clickReset = () => {
|
|
|
+ cameraEmit("resetSelect");
|
|
|
+};
|
|
|
+
|
|
|
+const clickDeleteAll = () => {
|
|
|
+ cameraEmit("deleteAll");
|
|
|
+};
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
.camera-upload {
|
|
|
display: flex;
|
|
|
+ flex-direction: column;
|
|
|
justify-content: space-evenly;
|
|
|
align-items: center;
|
|
|
width: 292px;
|
|
@@ -131,6 +149,13 @@ const selectFile = () => {
|
|
|
border-radius: 16px 16px 16px 16px;
|
|
|
border: 2px dashed rgba(0, 0, 0, 0.2);
|
|
|
|
|
|
+ .row {
|
|
|
+ width: 100%;
|
|
|
+ display: flex;
|
|
|
+ justify-content: space-evenly;
|
|
|
+ align-items: center;
|
|
|
+ }
|
|
|
+
|
|
|
.icon-back:nth-child(1) {
|
|
|
margin-right: 58px;
|
|
|
}
|