Files
JayuCloud/Frontend/src/views/admin/ShopsView.vue
T

249 lines
6.9 KiB
Vue
Raw Normal View History

2026-02-25 10:37:16 +08:00
<template>
<div class="shops">
<a-page-header title="店铺管理" sub-title="管理美甲店铺" />
<a-card :bordered="false">
<template #extra>
<a-space>
<a-input-search
v-model:value="searchText"
placeholder="搜索店铺名称"
style="width: 250px"
@search="handleSearch"
/>
<a-button type="primary" @click="showAddModal">
<template #icon>
<PlusOutlined />
</template>
新增店铺
</a-button>
</a-space>
</template>
<a-table
:columns="columns"
:data-source="shopList"
:loading="loading"
:pagination="pagination"
@change="handleTableChange"
row-key="id"
>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'image'">
<a-image
:width="60"
:height="60"
2026-02-25 14:44:50 +08:00
:src="record.coverImageUrl || DEFAULT_SHOP_IMAGE"
2026-02-25 10:37:16 +08:00
style="object-fit: cover; border-radius: 4px;"
/>
</template>
<template v-else-if="column.key === 'actions'">
<a-space>
<a-button type="link" size="small" @click="showEditModal(record)">
编辑
</a-button>
<a-popconfirm
title="确定要删除这个店铺吗?"
@confirm="handleDelete(record)"
>
<a-button type="link" size="small" danger>
删除
</a-button>
</a-popconfirm>
</a-space>
</template>
</template>
</a-table>
</a-card>
<a-modal
v-model:open="modalVisible"
:title="isEdit ? '编辑店铺' : '新增店铺'"
width="600px"
@ok="handleModalOk"
@cancel="handleModalCancel"
:confirmLoading="modalLoading"
>
<a-form
ref="formRef"
:model="formState"
:rules="formRules"
:label-col="{ span: 5 }"
:wrapper-col="{ span: 18 }"
>
2026-02-25 14:44:50 +08:00
<a-form-item label="店铺名称" name="shopName">
<a-input v-model:value="formState.shopName" placeholder="请输入店铺名称" />
2026-02-25 10:37:16 +08:00
</a-form-item>
<a-form-item label="店铺描述" name="description">
<a-textarea
v-model:value="formState.description"
placeholder="请输入店铺描述"
:rows="3"
/>
</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>
2026-02-25 14:44:50 +08:00
<a-form-item label="封面图文件ID" name="coverImageFileId">
<a-input v-model:value="formState.coverImageFileId" placeholder="请输入封面图文件ID" />
2026-02-25 10:37:16 +08:00
</a-form-item>
</a-form>
</a-modal>
</div>
</template>
<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
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'
2026-02-25 14:44:50 +08:00
import { adminShopApi, type Shop } from '@/api/admin'
2026-02-25 10:37:16 +08:00
const loading = ref(false)
const searchText = ref('')
2026-02-25 14:44:50 +08:00
const shopList = ref<Shop[]>([])
2026-02-25 10:37:16 +08:00
const modalVisible = ref(false)
const modalLoading = ref(false)
const isEdit = ref(false)
const formRef = ref<FormInstance>()
2026-02-25 14:44:50 +08:00
const currentShop = ref<Shop | null>(null)
2026-02-25 10:37:16 +08:00
const pagination = reactive({
current: 1,
pageSize: 10,
total: 0,
showSizeChanger: true,
showQuickJumper: true,
showTotal: (total: number) => `共 ${total} 条`
})
const formState = reactive({
2026-02-25 14:44:50 +08:00
shopName: '',
2026-02-25 10:37:16 +08:00
description: '',
address: '',
businessHours: '',
2026-02-25 14:44:50 +08:00
coverImageFileId: ''
2026-02-25 10:37:16 +08:00
})
const formRules = {
2026-02-25 14:44:50 +08:00
shopName: [{ required: true, message: '请输入店铺名称', trigger: 'blur' }],
2026-02-25 10:37:16 +08:00
description: [{ required: true, message: '请输入店铺描述', trigger: 'blur' }],
address: [{ required: true, message: '请输入店铺地址', trigger: 'blur' }],
businessHours: [{ required: true, message: '请输入营业时间', trigger: 'blur' }]
}
const columns = [
{ title: '图片', key: 'image', width: 100 },
2026-02-25 14:44:50 +08:00
{ title: '店铺名称', dataIndex: 'shopName', key: 'shopName' },
{ title: '店铺描述', dataIndex: 'description', key: 'description' },
2026-02-25 10:37:16 +08:00
{ title: '店铺地址', dataIndex: 'address', key: 'address' },
{ title: '营业时间', dataIndex: 'businessHours', key: 'businessHours' },
{ title: '创建时间', dataIndex: 'createTime', key: 'createTime' },
{ title: '操作', key: 'actions', width: 150, fixed: 'right' as const }
]
const fetchShopList = async () => {
loading.value = true
try {
2026-02-25 14:44:50 +08:00
const res = await adminShopApi.listShops({
2026-02-25 10:37:16 +08:00
page: pagination.current,
size: pagination.pageSize,
keyword: searchText.value
})
shopList.value = res.list || []
pagination.total = res.total || 0
} catch (error) {
message.error('获取店铺列表失败')
} finally {
loading.value = false
}
}
const handleSearch = () => {
pagination.current = 1
fetchShopList()
}
const handleTableChange = (pag: any) => {
pagination.current = pag.current
pagination.pageSize = pag.pageSize
fetchShopList()
}
const showAddModal = () => {
isEdit.value = false
Object.assign(formState, {
2026-02-25 14:44:50 +08:00
shopName: '',
2026-02-25 10:37:16 +08:00
description: '',
address: '',
businessHours: '',
2026-02-25 14:44:50 +08:00
coverImageFileId: ''
2026-02-25 10:37:16 +08:00
})
modalVisible.value = true
}
2026-02-25 14:44:50 +08:00
const showEditModal = (record: Shop) => {
2026-02-25 10:37:16 +08:00
isEdit.value = true
currentShop.value = record
Object.assign(formState, {
2026-02-25 14:44:50 +08:00
shopName: record.shopName,
2026-02-25 10:37:16 +08:00
description: record.description,
address: record.address,
businessHours: record.businessHours,
2026-02-25 14:44:50 +08:00
coverImageFileId: record.coverImageFileId
2026-02-25 10:37:16 +08:00
})
modalVisible.value = true
}
const handleModalOk = async () => {
try {
await formRef.value?.validate()
modalLoading.value = true
if (isEdit.value && currentShop.value) {
2026-02-25 14:44:50 +08:00
await adminShopApi.updateShop(currentShop.value.id, formState)
2026-02-25 10:37:16 +08:00
message.success('更新成功')
} else {
2026-02-25 14:44:50 +08:00
await adminShopApi.createShop(formState)
2026-02-25 10:37:16 +08:00
message.success('创建成功')
}
modalVisible.value = false
fetchShopList()
} catch (error) {
console.error(error)
} finally {
modalLoading.value = false
}
}
const handleModalCancel = () => {
modalVisible.value = false
formRef.value?.resetFields()
}
2026-02-25 14:44:50 +08:00
const handleDelete = async (record: Shop) => {
2026-02-25 10:37:16 +08:00
try {
2026-02-25 14:44:50 +08:00
await adminShopApi.deleteShop(record.id)
2026-02-25 10:37:16 +08:00
message.success('删除成功')
fetchShopList()
} catch (error) {
message.error('删除失败')
}
}
onMounted(() => {
fetchShopList()
})
</script>
<style scoped>
.shops {
padding: 0;
}
</style>