后台管理页面店铺管理初版
This commit is contained in:
@@ -33,15 +33,10 @@
|
||||
<a-image
|
||||
:width="60"
|
||||
:height="60"
|
||||
:src="record.image || DEFAULT_SHOP_IMAGE"
|
||||
:src="record.coverImageUrl || DEFAULT_SHOP_IMAGE"
|
||||
style="object-fit: cover; border-radius: 4px;"
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'status'">
|
||||
<a-tag :color="record.status === 1 ? 'green' : 'default'">
|
||||
{{ record.status === 1 ? '营业中' : '已关闭' }}
|
||||
</a-tag>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-space>
|
||||
<a-button type="link" size="small" @click="showEditModal(record)">
|
||||
@@ -76,8 +71,8 @@
|
||||
:label-col="{ span: 5 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<a-form-item label="店铺名称" name="name">
|
||||
<a-input v-model:value="formState.name" placeholder="请输入店铺名称" />
|
||||
<a-form-item label="店铺名称" name="shopName">
|
||||
<a-input v-model:value="formState.shopName" placeholder="请输入店铺名称" />
|
||||
</a-form-item>
|
||||
<a-form-item label="店铺描述" name="description">
|
||||
<a-textarea
|
||||
@@ -86,20 +81,14 @@
|
||||
:rows="3"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="店铺图片" name="image">
|
||||
<a-input v-model:value="formState.image" placeholder="请输入图片URL" />
|
||||
</a-form-item>
|
||||
<a-form-item label="联系电话" name="phone">
|
||||
<a-input v-model:value="formState.phone" placeholder="请输入联系电话" />
|
||||
</a-form-item>
|
||||
<a-form-item label="店铺地址" name="address">
|
||||
<a-input v-model:value="formState.address" placeholder="请输入店铺地址" />
|
||||
</a-form-item>
|
||||
<a-form-item label="营业时间" name="businessHours">
|
||||
<a-input v-model:value="formState.businessHours" placeholder="例如:09:00-21:00" />
|
||||
</a-form-item>
|
||||
<a-form-item label="状态" name="status">
|
||||
<a-switch v-model:checked="formState.status" checked-children="营业中" un-checked-children="已关闭" />
|
||||
<a-form-item label="封面图文件ID" name="coverImageFileId">
|
||||
<a-input v-model:value="formState.coverImageFileId" placeholder="请输入封面图文件ID" />
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
@@ -112,16 +101,16 @@ import { message } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import { PlusOutlined } from '@ant-design/icons-vue'
|
||||
import { DEFAULT_SHOP_IMAGE } from '@/constants'
|
||||
import { shopApi, type ShopVO } from '@/api/shop'
|
||||
import { adminShopApi, type Shop } from '@/api/admin'
|
||||
|
||||
const loading = ref(false)
|
||||
const searchText = ref('')
|
||||
const shopList = ref<ShopVO[]>([])
|
||||
const shopList = ref<Shop[]>([])
|
||||
const modalVisible = ref(false)
|
||||
const modalLoading = ref(false)
|
||||
const isEdit = ref(false)
|
||||
const formRef = ref<FormInstance>()
|
||||
const currentShop = ref<ShopVO | null>(null)
|
||||
const currentShop = ref<Shop | null>(null)
|
||||
|
||||
const pagination = reactive({
|
||||
current: 1,
|
||||
@@ -133,30 +122,26 @@ const pagination = reactive({
|
||||
})
|
||||
|
||||
const formState = reactive({
|
||||
name: '',
|
||||
shopName: '',
|
||||
description: '',
|
||||
image: '',
|
||||
phone: '',
|
||||
address: '',
|
||||
businessHours: '',
|
||||
status: true
|
||||
coverImageFileId: ''
|
||||
})
|
||||
|
||||
const formRules = {
|
||||
name: [{ required: true, message: '请输入店铺名称', trigger: 'blur' }],
|
||||
shopName: [{ required: true, message: '请输入店铺名称', trigger: 'blur' }],
|
||||
description: [{ required: true, message: '请输入店铺描述', trigger: 'blur' }],
|
||||
phone: [{ required: true, message: '请输入联系电话', trigger: 'blur' }],
|
||||
address: [{ required: true, message: '请输入店铺地址', trigger: 'blur' }],
|
||||
businessHours: [{ required: true, message: '请输入营业时间', trigger: 'blur' }]
|
||||
}
|
||||
|
||||
const columns = [
|
||||
{ title: '图片', key: 'image', width: 100 },
|
||||
{ title: '店铺名称', dataIndex: 'name', key: 'name' },
|
||||
{ title: '联系电话', dataIndex: 'phone', key: 'phone' },
|
||||
{ title: '店铺名称', dataIndex: 'shopName', key: 'shopName' },
|
||||
{ title: '店铺描述', dataIndex: 'description', key: 'description' },
|
||||
{ title: '店铺地址', dataIndex: 'address', key: 'address' },
|
||||
{ title: '营业时间', dataIndex: 'businessHours', key: 'businessHours' },
|
||||
{ title: '状态', key: 'status', width: 100 },
|
||||
{ title: '创建时间', dataIndex: 'createTime', key: 'createTime' },
|
||||
{ title: '操作', key: 'actions', width: 150, fixed: 'right' as const }
|
||||
]
|
||||
@@ -164,7 +149,7 @@ const columns = [
|
||||
const fetchShopList = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await shopApi.listShops({
|
||||
const res = await adminShopApi.listShops({
|
||||
page: pagination.current,
|
||||
size: pagination.pageSize,
|
||||
keyword: searchText.value
|
||||
@@ -192,28 +177,24 @@ const handleTableChange = (pag: any) => {
|
||||
const showAddModal = () => {
|
||||
isEdit.value = false
|
||||
Object.assign(formState, {
|
||||
name: '',
|
||||
shopName: '',
|
||||
description: '',
|
||||
image: '',
|
||||
phone: '',
|
||||
address: '',
|
||||
businessHours: '',
|
||||
status: true
|
||||
coverImageFileId: ''
|
||||
})
|
||||
modalVisible.value = true
|
||||
}
|
||||
|
||||
const showEditModal = (record: ShopVO) => {
|
||||
const showEditModal = (record: Shop) => {
|
||||
isEdit.value = true
|
||||
currentShop.value = record
|
||||
Object.assign(formState, {
|
||||
name: record.name,
|
||||
shopName: record.shopName,
|
||||
description: record.description,
|
||||
image: record.image,
|
||||
phone: record.phone,
|
||||
address: record.address,
|
||||
businessHours: record.businessHours,
|
||||
status: record.status === 1
|
||||
coverImageFileId: record.coverImageFileId
|
||||
})
|
||||
modalVisible.value = true
|
||||
}
|
||||
@@ -223,16 +204,11 @@ const handleModalOk = async () => {
|
||||
await formRef.value?.validate()
|
||||
modalLoading.value = true
|
||||
|
||||
const data = {
|
||||
...formState,
|
||||
status: formState.status ? 1 : 0
|
||||
}
|
||||
|
||||
if (isEdit.value && currentShop.value) {
|
||||
await shopApi.updateShop(currentShop.value.id, data)
|
||||
await adminShopApi.updateShop(currentShop.value.id, formState)
|
||||
message.success('更新成功')
|
||||
} else {
|
||||
await shopApi.createShop(data)
|
||||
await adminShopApi.createShop(formState)
|
||||
message.success('创建成功')
|
||||
}
|
||||
|
||||
@@ -250,9 +226,9 @@ const handleModalCancel = () => {
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
|
||||
const handleDelete = async (record: ShopVO) => {
|
||||
const handleDelete = async (record: Shop) => {
|
||||
try {
|
||||
await shopApi.deleteShop(record.id)
|
||||
await adminShopApi.deleteShop(record.id)
|
||||
message.success('删除成功')
|
||||
fetchShopList()
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user