fix(custom): 修复上传组件上传失败以及补全商户分类icon
This commit is contained in:
12
package.json
12
package.json
@@ -32,8 +32,8 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sentry/vite-plugin": "^2.10.1",
|
"@sentry/vite-plugin": "^2.10.2",
|
||||||
"@sentry/vue": "^7.81.0",
|
"@sentry/vue": "^7.83.0",
|
||||||
"@unocss/eslint-config": "^0.55.7",
|
"@unocss/eslint-config": "^0.55.7",
|
||||||
"@vueuse/core": "^10.6.1",
|
"@vueuse/core": "^10.6.1",
|
||||||
"@wangeditor/editor": "^5.1.23",
|
"@wangeditor/editor": "^5.1.23",
|
||||||
@@ -54,11 +54,11 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@commitlint/cli": "^17.8.1",
|
"@commitlint/cli": "^17.8.1",
|
||||||
"@commitlint/config-conventional": "^17.8.1",
|
"@commitlint/config-conventional": "^17.8.1",
|
||||||
"@iconify/json": "^2.2.144",
|
"@iconify/json": "^2.2.149",
|
||||||
"@iconify/vue": "^4.1.1",
|
"@iconify/vue": "^4.1.1",
|
||||||
"@unocss/preset-rem-to-px": "^0.55.7",
|
"@unocss/preset-rem-to-px": "^0.55.7",
|
||||||
"@vitejs/plugin-vue": "^4.5.0",
|
"@vitejs/plugin-vue": "^4.5.0",
|
||||||
"@vue/compiler-sfc": "^3.3.8",
|
"@vue/compiler-sfc": "^3.3.9",
|
||||||
"@zclzone/eslint-config": "^0.0.4",
|
"@zclzone/eslint-config": "^0.0.4",
|
||||||
"chalk": "^5.3.0",
|
"chalk": "^5.3.0",
|
||||||
"commitizen": "^4.3.0",
|
"commitizen": "^4.3.0",
|
||||||
@@ -66,11 +66,11 @@
|
|||||||
"cz-customizable": "^7.0.0",
|
"cz-customizable": "^7.0.0",
|
||||||
"dotenv": "^16.3.1",
|
"dotenv": "^16.3.1",
|
||||||
"esno": "^0.17.0",
|
"esno": "^0.17.0",
|
||||||
"fs-extra": "^11.1.1",
|
"fs-extra": "^11.2.0",
|
||||||
"husky": "^8.0.3",
|
"husky": "^8.0.3",
|
||||||
"lint-staged": "^13.3.0",
|
"lint-staged": "^13.3.0",
|
||||||
"naive-ui": "^2.35.0",
|
"naive-ui": "^2.35.0",
|
||||||
"rollup-plugin-visualizer": "^5.9.2",
|
"rollup-plugin-visualizer": "^5.9.3",
|
||||||
"sass": "^1.69.5",
|
"sass": "^1.69.5",
|
||||||
"unocss": "0.55.0",
|
"unocss": "0.55.0",
|
||||||
"unplugin-auto-import": "^0.16.7",
|
"unplugin-auto-import": "^0.16.7",
|
||||||
|
|||||||
6589
pnpm-lock.yaml
generated
6589
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -1,22 +1,17 @@
|
|||||||
<template>
|
<template>
|
||||||
<n-upload
|
<n-upload
|
||||||
v-model:file-list="List"
|
v-model:file-list="List"
|
||||||
action="/admin/upload"
|
|
||||||
:headers="headers"
|
|
||||||
:max="max"
|
:max="max"
|
||||||
list-type="image-card"
|
list-type="image-card"
|
||||||
|
:custom-request="customRequest"
|
||||||
@before-upload="beforeUpload"
|
@before-upload="beforeUpload"
|
||||||
@finish="handleFinish"
|
|
||||||
@error="handleError"
|
|
||||||
>
|
>
|
||||||
点击上传
|
点击上传
|
||||||
</n-upload>
|
</n-upload>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { getToken } from '@/utils'
|
import api from '@/api'
|
||||||
|
|
||||||
const token = getToken()
|
|
||||||
|
|
||||||
const prop = defineProps({
|
const prop = defineProps({
|
||||||
list: {
|
list: {
|
||||||
@@ -31,10 +26,6 @@ const prop = defineProps({
|
|||||||
|
|
||||||
const emit = defineEmits(['update:list'])
|
const emit = defineEmits(['update:list'])
|
||||||
|
|
||||||
const headers = ref({
|
|
||||||
Authorization: `Bearer ${token}`,
|
|
||||||
})
|
|
||||||
|
|
||||||
const List = computed({
|
const List = computed({
|
||||||
get() {
|
get() {
|
||||||
return prop.list
|
return prop.list
|
||||||
@@ -44,24 +35,28 @@ const List = computed({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
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) => {
|
const beforeUpload = ({ file }) => {
|
||||||
if (!(data.file.file?.type === 'image/png' || data.file.file?.type === 'image/jpeg')) {
|
if (!(file.file?.type === 'image/png' || file.file?.type === 'image/jpeg')) {
|
||||||
$message.error('只能上传png或jpg格式的图片文件,请重新上传')
|
$message.error('只能上传png或jpg格式的图片文件,请重新上传')
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const customRequest = async ({ file, onFinish, onError }) => {
|
||||||
|
try {
|
||||||
|
const formData = new FormData()
|
||||||
|
formData.append('file', file.file)
|
||||||
|
const res = await api.uploadImg(formData)
|
||||||
|
$message.success(res.msg)
|
||||||
|
file.url = res.data.data
|
||||||
|
onFinish()
|
||||||
|
} catch (error) {
|
||||||
|
onError()
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped></style>
|
<style lang="scss" scoped></style>
|
||||||
|
|||||||
@@ -24,6 +24,9 @@
|
|||||||
aria-modal="true"
|
aria-modal="true"
|
||||||
>
|
>
|
||||||
<n-form ref="formRef" label-placement="left" :model="formValue" :rules="rules">
|
<n-form ref="formRef" label-placement="left" :model="formValue" :rules="rules">
|
||||||
|
<n-form-item label="分类图标:" path="icon">
|
||||||
|
<Upload v-model:list="formValue.icon" />
|
||||||
|
</n-form-item>
|
||||||
<n-form-item label="分类名称:" path="name">
|
<n-form-item label="分类名称:" path="name">
|
||||||
<n-input v-model:value="formValue.name" placeholder="请输入商户分类名称" />
|
<n-input v-model:value="formValue.name" placeholder="请输入商户分类名称" />
|
||||||
</n-form-item>
|
</n-form-item>
|
||||||
@@ -53,6 +56,8 @@
|
|||||||
import { onMounted, h, withDirectives, resolveDirective } from 'vue'
|
import { onMounted, h, withDirectives, resolveDirective } from 'vue'
|
||||||
import api from './api'
|
import api from './api'
|
||||||
import { NButton } from 'naive-ui'
|
import { NButton } from 'naive-ui'
|
||||||
|
import Upload from '@/components/Upload.vue'
|
||||||
|
|
||||||
const vPerms = resolveDirective('perms')
|
const vPerms = resolveDirective('perms')
|
||||||
|
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
@@ -93,7 +98,19 @@ const columns = ref([
|
|||||||
type: 'primary',
|
type: 'primary',
|
||||||
size: 'small',
|
size: 'small',
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
formValue.value = row
|
formValue.value = {
|
||||||
|
...row,
|
||||||
|
icon:
|
||||||
|
row.icon.length > 0
|
||||||
|
? [
|
||||||
|
{
|
||||||
|
url: row.icon,
|
||||||
|
name: '图片',
|
||||||
|
status: 'finished',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
: [],
|
||||||
|
}
|
||||||
handleAdd(2)
|
handleAdd(2)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -115,12 +132,18 @@ const rules = {
|
|||||||
required: true,
|
required: true,
|
||||||
message: '请输入商户分类名称',
|
message: '请输入商户分类名称',
|
||||||
},
|
},
|
||||||
|
icon: {
|
||||||
|
required: true,
|
||||||
|
type: 'array',
|
||||||
|
message: '请上传分类图标',
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
const formValue = ref({
|
const formValue = ref({
|
||||||
ID: 0,
|
ID: 0,
|
||||||
name: '',
|
name: '',
|
||||||
status: 1,
|
status: 1,
|
||||||
|
icon: [],
|
||||||
})
|
})
|
||||||
|
|
||||||
const showModal = ref(false)
|
const showModal = ref(false)
|
||||||
@@ -171,6 +194,7 @@ const clear = () => {
|
|||||||
ID: 0,
|
ID: 0,
|
||||||
name: '',
|
name: '',
|
||||||
status: 1,
|
status: 1,
|
||||||
|
icon: [],
|
||||||
}
|
}
|
||||||
showModal.value = false
|
showModal.value = false
|
||||||
}
|
}
|
||||||
@@ -180,7 +204,10 @@ const handleValidateClick = async (e) => {
|
|||||||
formRef.value?.validate(async (errors) => {
|
formRef.value?.validate(async (errors) => {
|
||||||
if (!errors) {
|
if (!errors) {
|
||||||
try {
|
try {
|
||||||
await api.addClass(formValue.value)
|
await api.addClass({
|
||||||
|
...formValue.value,
|
||||||
|
icon: formValue.value.icon[0].url,
|
||||||
|
})
|
||||||
$message.success('成功')
|
$message.success('成功')
|
||||||
clear()
|
clear()
|
||||||
getList()
|
getList()
|
||||||
|
|||||||
Reference in New Issue
Block a user