|
@@ -1,106 +1,108 @@
|
|
<template>
|
|
<template>
|
|
- <!-- <img v-if="previewUrl?.length>0&&previewUrl!='[]'" :src="previewUrl" class="box" style="cursor: pointer" @click="clickImg"/> -->
|
|
|
|
- <el-image :preview-teleported="true" :preview-src-list="[previewUrl]" v-if="previewUrl?.length>0&&previewUrl!='[]'"
|
|
|
|
- :src="previewUrl" class="box"/>
|
|
|
|
- <el-upload class="box" action="#" :show-file-list="false" :http-request="upload" :accept="accept">
|
|
|
|
- <el-icon class="avatar-uploader-icon">
|
|
|
|
- <Plus/>
|
|
|
|
- </el-icon>
|
|
|
|
- </el-upload>
|
|
|
|
-
|
|
|
|
- <el-dialog v-model="watchImg" width="50%" :show-close="false">
|
|
|
|
- <img :src="previewUrl" style="width: 100%"/>
|
|
|
|
- </el-dialog>
|
|
|
|
|
|
+ <!-- <img v-if="previewUrl?.length>0&&previewUrl!='[]'" :src="previewUrl" class="box" style="cursor: pointer" @click="clickImg"/> -->
|
|
|
|
+ <el-image :preview-teleported="true" :preview-src-list="[previewUrl]" v-if="previewUrl?.length>0&&previewUrl!='[]'"
|
|
|
|
+ :src="previewUrl" class="box" />
|
|
|
|
+ <el-upload class="box" action="#" :show-file-list="false" :http-request="upload" :accept="accept">
|
|
|
|
+ <el-icon class="avatar-uploader-icon">
|
|
|
|
+ <Plus />
|
|
|
|
+ </el-icon>
|
|
|
|
+ </el-upload>
|
|
|
|
+
|
|
|
|
+ <el-dialog v-model="watchImg" width="50%" :show-close="false">
|
|
|
|
+ <img :src="previewUrl" style="width: 100%" />
|
|
|
|
+ </el-dialog>
|
|
|
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
|
<script setup lang="ts">
|
|
-import {onMounted, ref, watch} from 'vue'
|
|
|
|
-import {fileUpload} from '/@/api/common'
|
|
|
|
-import {Delete, Download, Plus, ZoomIn} from '@element-plus/icons-vue'
|
|
|
|
-import type {UploadInstance, UploadProps, UploadRawFile, UploadFile} from 'element-plus'
|
|
|
|
-import {genFileId} from 'element-plus'
|
|
|
|
-import {ElNotification} from "element-plus/es";
|
|
|
|
|
|
+import { onMounted, ref, watch } from "vue";
|
|
|
|
+import { fileUpload } from "/@/api/common";
|
|
|
|
+import { Delete, Download, Plus, ZoomIn } from "@element-plus/icons-vue";
|
|
|
|
+import type { UploadInstance, UploadProps, UploadRawFile, UploadFile } from "element-plus";
|
|
|
|
+import { genFileId } from "element-plus";
|
|
|
|
+import { ElNotification } from "element-plus/es";
|
|
|
|
+import { log } from "/@/api/backend/routine/AdminInfo";
|
|
|
|
|
|
|
|
|
|
-const dialogImageUrl = ref('')
|
|
|
|
-const dialogVisible = ref(false)
|
|
|
|
-const disabled = ref(false)
|
|
|
|
|
|
+const dialogImageUrl = ref("");
|
|
|
|
+const dialogVisible = ref(false);
|
|
|
|
+const disabled = ref(false);
|
|
|
|
|
|
const props = defineProps({
|
|
const props = defineProps({
|
|
- fileUrl: {
|
|
|
|
- type: String,
|
|
|
|
- default: ''
|
|
|
|
- },
|
|
|
|
- size: {
|
|
|
|
- type: Number,
|
|
|
|
- default: 1000000
|
|
|
|
- },
|
|
|
|
- accept: {
|
|
|
|
- type: String,
|
|
|
|
- default: '.jpg, .jpeg, .png'
|
|
|
|
- }
|
|
|
|
-})
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-watch(
|
|
|
|
- () => props.fileUrl,
|
|
|
|
- (newVal) => {
|
|
|
|
- previewUrl.value = props.fileUrl
|
|
|
|
- }
|
|
|
|
-)
|
|
|
|
|
|
+ modelValue: {
|
|
|
|
+ type: String,
|
|
|
|
+ default: ""
|
|
|
|
+ },
|
|
|
|
+ size: {//上传文件大小限制B
|
|
|
|
+ type: Number,
|
|
|
|
+ default: 1000000
|
|
|
|
+ },
|
|
|
|
+ accept: {//接收文件后缀
|
|
|
|
+ type: String,
|
|
|
|
+ default: ".jpg, .jpeg, .png"
|
|
|
|
+ }
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+watch(() => props.modelValue, (newVal) => {
|
|
|
|
+ console.log(newVal);
|
|
|
|
+ previewUrl.value = newVal;
|
|
|
|
+});
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
- previewUrl.value = props.fileUrl
|
|
|
|
-})
|
|
|
|
|
|
+ console.log(props.modelValue);
|
|
|
|
+ previewUrl.value = props.modelValue;
|
|
|
|
+});
|
|
|
|
|
|
-const emit = defineEmits(['update:fileUrl'])
|
|
|
|
|
|
+// const emit = defineEmits(["update:fileUrl"]);
|
|
|
|
+const emit = defineEmits(["input"]);
|
|
|
|
|
|
|
|
|
|
const handlePictureCardPreview = (file: UploadFile) => {
|
|
const handlePictureCardPreview = (file: UploadFile) => {
|
|
- dialogImageUrl.value = file.url!
|
|
|
|
- dialogVisible.value = true
|
|
|
|
-}
|
|
|
|
|
|
+ dialogImageUrl.value = file.url!;
|
|
|
|
+ dialogVisible.value = true;
|
|
|
|
+};
|
|
|
|
|
|
//上传图片路径
|
|
//上传图片路径
|
|
-let previewUrl = ref<string>('')
|
|
|
|
|
|
+let previewUrl = ref<string>("");
|
|
|
|
|
|
function upload(file: any) {
|
|
function upload(file: any) {
|
|
- //大小限制为0时为不限制
|
|
|
|
- if (file.file.size > props.size && props.size > 0) {
|
|
|
|
- ElNotification({
|
|
|
|
- type: 'error',
|
|
|
|
- message: "文件大小不能超过1MB",
|
|
|
|
- })
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- let fd = new FormData()
|
|
|
|
- fd.append('file', file.file)
|
|
|
|
- fileUpload(fd).then(res => {
|
|
|
|
- previewUrl.value = res.data.previewUrl
|
|
|
|
- emit('update:fileUrl', previewUrl.value)
|
|
|
|
- })
|
|
|
|
|
|
+ //大小限制为0时为不限制
|
|
|
|
+ if (file.file.size > props.size && props.size > 0) {
|
|
|
|
+ ElNotification({
|
|
|
|
+ type: "error",
|
|
|
|
+ message: "文件大小不能超过1MB"
|
|
|
|
+ });
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ let fd = new FormData();
|
|
|
|
+ fd.append("file", file.file);
|
|
|
|
+ fileUpload(fd).then(res => {
|
|
|
|
+ previewUrl.value = res.data.previewUrl;
|
|
|
|
+ // emit("update:fileUrl", previewUrl.value);
|
|
|
|
+ emit("input", previewUrl.value);
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
|
|
//图片预览
|
|
//图片预览
|
|
-let watchImg = ref(false)
|
|
|
|
-let showUrl = ref('')
|
|
|
|
|
|
+let watchImg = ref(false);
|
|
|
|
+let showUrl = ref("");
|
|
|
|
|
|
function clickImg() {
|
|
function clickImg() {
|
|
- watchImg.value = true
|
|
|
|
|
|
+ watchImg.value = true;
|
|
}
|
|
}
|
|
</script>
|
|
</script>
|
|
|
|
|
|
<style scoped>
|
|
<style scoped>
|
|
.box {
|
|
.box {
|
|
- height: 90px;
|
|
|
|
- width: 90px;
|
|
|
|
- border: #bfc0c2 1px dashed;
|
|
|
|
- border-radius: 10px;
|
|
|
|
- display: flex;
|
|
|
|
- justify-content: center;
|
|
|
|
- align-items: center;
|
|
|
|
- margin-right: 10px;
|
|
|
|
|
|
+ height: 90px;
|
|
|
|
+ width: 90px;
|
|
|
|
+ border: #bfc0c2 1px dashed;
|
|
|
|
+ border-radius: 10px;
|
|
|
|
+ display: flex;
|
|
|
|
+ justify-content: center;
|
|
|
|
+ align-items: center;
|
|
|
|
+ margin-right: 10px;
|
|
}
|
|
}
|
|
</style>
|
|
</style>
|