后台管理页面初版

This commit is contained in:
xiaowang
2026-02-25 10:37:16 +08:00
parent f946f9d31a
commit efe172793c
42 changed files with 3338 additions and 459 deletions
+272
View File
@@ -0,0 +1,272 @@
<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"
:src="record.image || 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)">
编辑
</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 }"
>
<a-form-item label="店铺名称" name="name">
<a-input v-model:value="formState.name" placeholder="请输入店铺名称" />
</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="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>
</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'
import { shopApi, type ShopVO } from '@/api/shop'
const loading = ref(false)
const searchText = ref('')
const shopList = ref<ShopVO[]>([])
const modalVisible = ref(false)
const modalLoading = ref(false)
const isEdit = ref(false)
const formRef = ref<FormInstance>()
const currentShop = ref<ShopVO | null>(null)
const pagination = reactive({
current: 1,
pageSize: 10,
total: 0,
showSizeChanger: true,
showQuickJumper: true,
showTotal: (total: number) => `共 ${total} 条`
})
const formState = reactive({
name: '',
description: '',
image: '',
phone: '',
address: '',
businessHours: '',
status: true
})
const formRules = {
name: [{ 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: '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 }
]
const fetchShopList = async () => {
loading.value = true
try {
const res = await shopApi.listShops({
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, {
name: '',
description: '',
image: '',
phone: '',
address: '',
businessHours: '',
status: true
})
modalVisible.value = true
}
const showEditModal = (record: ShopVO) => {
isEdit.value = true
currentShop.value = record
Object.assign(formState, {
name: record.name,
description: record.description,
image: record.image,
phone: record.phone,
address: record.address,
businessHours: record.businessHours,
status: record.status === 1
})
modalVisible.value = true
}
const handleModalOk = async () => {
try {
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)
message.success('更新成功')
} else {
await shopApi.createShop(data)
message.success('创建成功')
}
modalVisible.value = false
fetchShopList()
} catch (error) {
console.error(error)
} finally {
modalLoading.value = false
}
}
const handleModalCancel = () => {
modalVisible.value = false
formRef.value?.resetFields()
}
const handleDelete = async (record: ShopVO) => {
try {
await shopApi.deleteShop(record.id)
message.success('删除成功')
fetchShopList()
} catch (error) {
message.error('删除失败')
}
}
onMounted(() => {
fetchShopList()
})
</script>
<style scoped>
.shops {
padding: 0;
}
</style>