feat(custom): i

This commit is contained in:
2023-09-06 03:48:46 +08:00
parent 3b3cb7ba34
commit a9707c6d94
51 changed files with 2273 additions and 87 deletions

67
src/components/Upload.vue Normal file
View 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>

View File

@@ -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>