feat(custom): i
This commit is contained in:
67
src/components/Upload.vue
Normal file
67
src/components/Upload.vue
Normal file
@@ -0,0 +1,67 @@
|
||||
<template>
|
||||
<n-upload
|
||||
v-model:file-list="List"
|
||||
action="/admin/upload"
|
||||
:headers="headers"
|
||||
:max="max"
|
||||
list-type="image-card"
|
||||
@before-upload="beforeUpload"
|
||||
@finish="handleFinish"
|
||||
@error="handleError"
|
||||
>
|
||||
点击上传
|
||||
</n-upload>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { getToken } from '@/utils'
|
||||
|
||||
const token = getToken()
|
||||
|
||||
const prop = defineProps({
|
||||
list: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
max: {
|
||||
type: Number,
|
||||
default: 1,
|
||||
},
|
||||
})
|
||||
|
||||
const emit = defineEmits(['update:list'])
|
||||
|
||||
const headers = ref({
|
||||
Authorization: `Bearer ${token}`,
|
||||
})
|
||||
|
||||
const List = computed({
|
||||
get() {
|
||||
return prop.list
|
||||
},
|
||||
set(val) {
|
||||
emit('update:list', val)
|
||||
},
|
||||
})
|
||||
|
||||
const handleFinish = ({ file, event }) => {
|
||||
const res = JSON.parse(event.target.response)
|
||||
file.url = res.data.data
|
||||
return file
|
||||
}
|
||||
|
||||
const handleError = () => {
|
||||
$message.error('上传失败')
|
||||
}
|
||||
|
||||
// 图片上传限制
|
||||
const beforeUpload = (data) => {
|
||||
if (!(data.file.file?.type === 'image/png' || data.file.file?.type === 'image/jpeg')) {
|
||||
$message.error('只能上传png或jpg格式的图片文件,请重新上传')
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped></style>
|
||||
@@ -2,7 +2,7 @@
|
||||
<transition name="fade-slide" mode="out-in" appear>
|
||||
<section class="cus-scroll-y wh-full flex-col bg-[#f5f6fb] p-15 dark:bg-hex-121212">
|
||||
<slot />
|
||||
<AppFooter v-if="showFooter" mt-15 />
|
||||
<!-- <AppFooter v-if="showFooter" mt-15 /> -->
|
||||
<n-back-top :bottom="20" />
|
||||
</section>
|
||||
</transition>
|
||||
|
||||
Reference in New Issue
Block a user