后台管理页面店铺管理初版
This commit is contained in:
@@ -160,4 +160,46 @@ export const adminProductApi = {
|
||||
}
|
||||
}
|
||||
|
||||
export interface Shop {
|
||||
id: number
|
||||
shopName: string
|
||||
description: string
|
||||
address: string
|
||||
businessHours: string
|
||||
coverImageFileId: string
|
||||
coverImageUrl?: string
|
||||
createTime: string
|
||||
updateTime: string
|
||||
}
|
||||
|
||||
export interface ShopListResponse {
|
||||
list: Shop[]
|
||||
total: number
|
||||
page: number
|
||||
size: number
|
||||
}
|
||||
|
||||
export interface CreateShopRequest {
|
||||
shopName: string
|
||||
description: string
|
||||
address: string
|
||||
businessHours: string
|
||||
coverImageFileId: string
|
||||
}
|
||||
|
||||
export const adminShopApi = {
|
||||
listShops: (params: { page: number; size: number; keyword?: string }) => {
|
||||
return adminApi.get<ShopListResponse>('/admin/shops/list', { params })
|
||||
},
|
||||
createShop: (data: CreateShopRequest) => {
|
||||
return adminApi.post<number>('/admin/shops/create', data)
|
||||
},
|
||||
updateShop: (id: number, data: CreateShopRequest) => {
|
||||
return adminApi.put<boolean>(`/admin/shops/update/${id}`, data)
|
||||
},
|
||||
deleteShop: (id: number) => {
|
||||
return adminApi.delete<boolean>(`/admin/shops/delete/${id}`)
|
||||
}
|
||||
}
|
||||
|
||||
export default adminApi
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.xiaowang.yuminailcore.service;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.xiaowang.yuminailcore.entity.ShopDO;
|
||||
import com.xiaowang.yuminailcore.dto.ShopDTO;
|
||||
import com.xiaowang.yuminailcore.vo.PageResultVO;
|
||||
import com.xiaowang.yuminailcore.vo.ShopVO;
|
||||
|
||||
import java.util.List;
|
||||
@@ -63,4 +64,14 @@ public interface ShopService extends IService<ShopDO> {
|
||||
* @return 店铺VO列表
|
||||
*/
|
||||
List<ShopVO> listShopsByShopName(String shopName);
|
||||
|
||||
/**
|
||||
* 分页查询店铺
|
||||
*
|
||||
* @param page 页码
|
||||
* @param size 每页大小
|
||||
* @param keyword 搜索关键词
|
||||
* @return 分页结果
|
||||
*/
|
||||
PageResultVO<ShopVO> pageShops(Integer page, Integer size, String keyword);
|
||||
}
|
||||
|
||||
+27
@@ -1,14 +1,18 @@
|
||||
package com.xiaowang.yuminailcore.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.xiaowang.yuminailcore.dto.ShopDTO;
|
||||
import com.xiaowang.yuminailcore.entity.ShopDO;
|
||||
import com.xiaowang.yuminailcore.mapper.ShopMapper;
|
||||
import com.xiaowang.yuminailcore.service.ShopService;
|
||||
import com.xiaowang.yuminailcore.vo.PageResultVO;
|
||||
import com.xiaowang.yuminailcore.vo.ShopVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -90,6 +94,29 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, ShopDO> implements
|
||||
.map(this::convertToVO)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResultVO<ShopVO> pageShops(Integer page, Integer size, String keyword) {
|
||||
Page<ShopDO> pageParam = new Page<>(page, size);
|
||||
|
||||
LambdaQueryWrapper<ShopDO> wrapper = Wrappers.lambdaQuery(ShopDO.class);
|
||||
if (StringUtils.hasText(keyword)) {
|
||||
wrapper.and(w -> w.like(ShopDO::getShopName, keyword)
|
||||
.or().like(ShopDO::getDescription, keyword)
|
||||
.or().like(ShopDO::getAddress, keyword));
|
||||
}
|
||||
wrapper.orderByDesc(ShopDO::getCreateTime);
|
||||
|
||||
Page<ShopDO> shopPage = shopMapper.selectPage(pageParam, wrapper);
|
||||
|
||||
PageResultVO<ShopVO> result = new PageResultVO<>();
|
||||
result.setList(shopPage.getRecords().stream().map(this::convertToVO).collect(Collectors.toList()));
|
||||
result.setTotal(shopPage.getTotal());
|
||||
result.setPage(page);
|
||||
result.setSize(size);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 DO 转换为 VO
|
||||
|
||||
Reference in New Issue
Block a user