This commit is contained in:
王子琦
2026-01-13 17:32:13 +08:00
parent 8572733b2e
commit f567e733d3
11 changed files with 1301 additions and 4 deletions

1161
frontend/pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,11 @@
<template>
<a-card title="轮播图管理">
<a-form layout="inline">
<a-form-item label="图片">
<a-upload :action="uploadUrl" :headers="headers" @change="onUpload" :showUploadList="false">
<a-button>上传图片</a-button>
</a-upload>
</a-form-item>
<a-form-item label="图片URL"><a-input v-model:value="form.imageUrl" /></a-form-item>
<a-form-item label="链接"><a-input v-model:value="form.linkUrl" /></a-form-item>
<a-form-item label="排序"><a-input-number v-model:value="form.sortOrder" /></a-form-item>
@@ -22,6 +27,8 @@ import api from '../../api'
const list = ref([])
const form = reactive({ imageUrl: '', linkUrl: '', sortOrder: 0 })
const uploadUrl = 'http://localhost:8080/api/admin/upload'
const headers = { Authorization: `Bearer ${localStorage.getItem('token') || ''}` }
const columns = [
{ title: '图片', dataIndex: 'imageUrl' },
{ title: '链接', dataIndex: 'linkUrl' },
@@ -42,6 +49,15 @@ const create = async () => {
load()
}
const onUpload = (info) => {
if (info.file.status === 'done') {
const res = info.file.response
if (res && res.success) {
form.imageUrl = res.data
}
}
}
const remove = async (record) => {
await api.delete(`/api/admin/carousels/${record.id}`)
load()

View File

@@ -20,7 +20,10 @@
</template>
</a-table>
<a-modal v-model:open="imgVisible" title="新增图片" @ok="saveImage">
<a-input v-model:value="imgForm.url" placeholder="图片URL" />
<a-upload :action="uploadUrl" :headers="headers" @change="onUpload" :showUploadList="false">
<a-button>上传图片</a-button>
</a-upload>
<a-input v-model:value="imgForm.url" placeholder="图片URL" style="margin-top: 8px" />
<a-input-number v-model:value="imgForm.sortOrder" style="margin-top: 8px" />
</a-modal>
</a-card>
@@ -42,6 +45,8 @@ const columns = [
const imgVisible = ref(false)
const imgForm = reactive({ productId: null, url: '', sortOrder: 0 })
const uploadUrl = 'http://localhost:8080/api/admin/upload'
const headers = { Authorization: `Bearer ${localStorage.getItem('token') || ''}` }
const load = async () => {
const res = await api.get('/api/admin/products')
@@ -76,5 +81,14 @@ const saveImage = async () => {
imgVisible.value = false
}
const onUpload = (info) => {
if (info.file.status === 'done') {
const res = info.file.response
if (res && res.success) {
imgForm.url = res.data
}
}
}
onMounted(load)
</script>