一些问题的修复
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import api from './index'
|
||||
|
||||
export const productLikeApi = {
|
||||
/**
|
||||
* 点赞作品
|
||||
* @param productId 作品ID
|
||||
*/
|
||||
likeProduct: (productId: number) => {
|
||||
return api.post<boolean>(`/product-like/like/${productId}`)
|
||||
},
|
||||
|
||||
/**
|
||||
* 取消点赞作品
|
||||
* @param productId 作品ID
|
||||
*/
|
||||
unlikeProduct: (productId: number) => {
|
||||
return api.post<boolean>(`/product-like/unlike/${productId}`)
|
||||
},
|
||||
|
||||
/**
|
||||
* 检查用户是否已点赞作品
|
||||
* @param productId 作品ID
|
||||
*/
|
||||
checkLikeStatus: (productId: number) => {
|
||||
return api.get<boolean>(`/product-like/check/${productId}`)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// API配置文件
|
||||
// 提取域名和端口,方便后续修改
|
||||
export const API_CONFIG = {
|
||||
domain: 'http://127.0.0.1',
|
||||
port: '8088',
|
||||
basePath: '/api',
|
||||
adminBasePath: '/admin/api'
|
||||
}
|
||||
|
||||
export const API_BASE_URL = `${API_CONFIG.domain}:${API_CONFIG.port}${API_CONFIG.basePath}`
|
||||
export const ADMIN_API_BASE_URL = `${API_CONFIG.domain}:${API_CONFIG.port}${API_CONFIG.adminBasePath}`
|
||||
@@ -0,0 +1,333 @@
|
||||
<template>
|
||||
<div class="mobile-container">
|
||||
<!-- 头部区域 -->
|
||||
<header class="header">
|
||||
<a-button class="back-btn" type="text" @click="handleBackClick">
|
||||
<LeftOutlined :style="{ fontSize: '20px' }" />
|
||||
</a-button>
|
||||
<h1>美甲师订单</h1>
|
||||
<div class="placeholder"></div>
|
||||
</header>
|
||||
|
||||
<!-- 订单列表 -->
|
||||
<div class="order-section">
|
||||
<a-empty v-if="orders.length === 0" description="暂无订单">
|
||||
<a-button type="primary" @click="handleRefresh">刷新</a-button>
|
||||
</a-empty>
|
||||
<div v-else class="order-list">
|
||||
<a-card v-for="order in orders" :key="order.id" class="order-card">
|
||||
<div class="order-header">
|
||||
<span class="order-no">订单号: {{ order.orderNo }}</span>
|
||||
<span :class="['order-status', order.status === 1 ? 'pending' : order.status === 2 ? 'completed' : 'cancelled']">
|
||||
{{ order.statusText }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="order-items">
|
||||
<div v-for="item in order.items" :key="item.id" class="order-item">
|
||||
<div class="item-image" v-if="item.productImage">
|
||||
<img :src="item.productImage" :alt="item.productTitle" />
|
||||
</div>
|
||||
<div class="item-image" v-else :style="{ backgroundColor: getRandomColor() }">
|
||||
<span>{{ item.productTitle[0] }}</span>
|
||||
</div>
|
||||
<div class="item-info">
|
||||
<div class="item-title">{{ item.productTitle }}</div>
|
||||
<div class="item-price">¥{{ item.price.toFixed(2) }} x {{ item.quantity }}</div>
|
||||
<div class="item-customer">
|
||||
<span>客户订单</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="order-footer">
|
||||
<div class="order-total">
|
||||
总计: <span class="total-price">¥{{ order.actualAmount.toFixed(2) }}</span>
|
||||
</div>
|
||||
<div class="order-actions">
|
||||
<a-button v-if="order.status === 1" size="small" type="primary" @click="handleCompleteOrder(order.id)">
|
||||
完成服务
|
||||
</a-button>
|
||||
</div>
|
||||
</div>
|
||||
</a-card>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { LeftOutlined } from '@ant-design/icons-vue'
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
import { orderApi } from '../api/order'
|
||||
import { fileApi } from '../api/index'
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
// 订单相关状态
|
||||
const orders = ref<any[]>([])
|
||||
const loading = ref(false)
|
||||
|
||||
// 图片缓存
|
||||
const imageIdCache = ref<Record<string, string>>({})
|
||||
|
||||
// 加载美甲师订单列表
|
||||
const loadOrders = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const response = await orderApi.getArtistOrders() as any
|
||||
orders.value = response || []
|
||||
|
||||
await loadProductImages(orders.value)
|
||||
} catch (error) {
|
||||
message.error('获取订单列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 加载作品图片
|
||||
const loadProductImages = async (orders: any[]) => {
|
||||
for (const order of orders) {
|
||||
if (order.items && order.items.length > 0) {
|
||||
for (const item of order.items) {
|
||||
if (item.productImage) {
|
||||
const cleanImageUrl = item.productImage.replace(/<[^>]*>/g, '')
|
||||
|
||||
const match = cleanImageUrl.match(/\/api\/file\/get\/(\d+)/)
|
||||
if (match && match[1]) {
|
||||
const imageId = match[1]
|
||||
try {
|
||||
if (!imageIdCache.value[imageId]) {
|
||||
const response = await fileApi.getSignedUrl(Number(imageId)) as any
|
||||
imageIdCache.value[imageId] = response
|
||||
}
|
||||
item.productImage = imageIdCache.value[imageId]
|
||||
} catch (error) {
|
||||
console.error('获取图片签名链接失败:', error)
|
||||
item.productImage = ''
|
||||
}
|
||||
} else {
|
||||
item.productImage = ''
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 处理完成服务
|
||||
const handleCompleteOrder = async (orderId: number) => {
|
||||
Modal.confirm({
|
||||
title: '确认完成服务',
|
||||
content: '确定要完成这个订单的服务吗?',
|
||||
onOk: async () => {
|
||||
try {
|
||||
await orderApi.processOrder(orderId, 2)
|
||||
message.success('订单已完成')
|
||||
loadOrders()
|
||||
} catch (error) {
|
||||
message.error('完成订单失败')
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 处理返回按钮点击
|
||||
const handleBackClick = () => {
|
||||
router.back()
|
||||
}
|
||||
|
||||
// 处理刷新
|
||||
const handleRefresh = () => {
|
||||
loadOrders()
|
||||
}
|
||||
|
||||
// 生成随机颜色
|
||||
const getRandomColor = () => {
|
||||
const colors = ['#ffe4d6', '#d6eaff', '#e2ffd6', '#fff2d6', '#d6ffe4', '#e4d6ff']
|
||||
return colors[Math.floor(Math.random() * colors.length)]
|
||||
}
|
||||
|
||||
// 页面加载时获取订单数据
|
||||
onMounted(() => {
|
||||
loadOrders()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.mobile-container {
|
||||
padding-top: 60px;
|
||||
min-height: 100vh;
|
||||
background: #f5f5f5;
|
||||
}
|
||||
|
||||
.header {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
z-index: 100;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 10px 15px;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
background: white;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.back-btn,
|
||||
.placeholder {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.order-section {
|
||||
padding: 15px;
|
||||
padding-bottom: 20px;
|
||||
}
|
||||
|
||||
.order-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.order-card {
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.order-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 15px;
|
||||
padding-bottom: 10px;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.order-no {
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.order-status {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
padding: 4px 12px;
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
.order-status.pending {
|
||||
background: #fff7e6;
|
||||
color: #fa8c16;
|
||||
}
|
||||
|
||||
.order-status.completed {
|
||||
background: #f6ffed;
|
||||
color: #52c41a;
|
||||
}
|
||||
|
||||
.order-status.cancelled {
|
||||
background: #fff1f0;
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
.order-items {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.order-item {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.item-image {
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
border-radius: 8px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
color: rgba(0,0,0,0.1);
|
||||
flex-shrink: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.item-image img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.item-info {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.item-title {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: #1a1a2e;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
}
|
||||
|
||||
.item-price {
|
||||
font-size: 13px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.item-customer {
|
||||
font-size: 12px;
|
||||
color: #1890ff;
|
||||
}
|
||||
|
||||
.order-footer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding-top: 10px;
|
||||
border-top: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.order-total {
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.total-price {
|
||||
font-size: 16px;
|
||||
font-weight: 700;
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
.order-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,149 @@
|
||||
# Frontend 项目详细总结
|
||||
|
||||
## 1. 项目定位
|
||||
|
||||
`Frontend` 是 YumiNail 系统的前端项目,采用 Vue 3 + TypeScript + Vite 构建,承担两类界面:
|
||||
|
||||
- 用户端:登录、首页、商品浏览、店铺详情、购物车、订单、收藏、优惠券、个人资料、账号设置。
|
||||
- 管理端:管理员登录、仪表盘、用户管理、商品管理、店铺管理、权限管理、订单管理、标签管理、优惠券管理、美甲师管理。
|
||||
|
||||
从代码结构看,这是一个单仓库内的独立 SPA 项目,通过不同路由承载 C 端和后台管理端。
|
||||
|
||||
## 2. 技术栈与依赖
|
||||
|
||||
- 框架:Vue 3.5、Vue Router 4、Pinia 3
|
||||
- 构建工具:Vite 7、TypeScript 5
|
||||
- UI 组件:Element Plus、Ant Design Vue
|
||||
- 网络层:Axios
|
||||
- 样式处理:Less、Sass
|
||||
- 工程插件:`unplugin-auto-import`、`unplugin-vue-components`
|
||||
|
||||
项目在 `package.json` 中定义的常用命令:
|
||||
|
||||
- `npm run dev`:本地开发
|
||||
- `npm run build`:类型检查并构建
|
||||
- `npm run preview`:预览构建产物
|
||||
|
||||
## 3. 目录与代码结构
|
||||
|
||||
当前 `src` 下约有 55 个文件,主要结构如下:
|
||||
|
||||
- `src/main.ts`
|
||||
负责创建应用、挂载 Pinia、Router、Element Plus、Ant Design Vue。
|
||||
- `src/router/index.ts`
|
||||
定义整套路由、前台/后台登录守卫、基于 `permissionCode` 的后台页面拦截。
|
||||
- `src/api/`
|
||||
封装所有接口调用,按模块拆分为 `auth`、`user`、`product`、`shop`、`order`、`coupon`、`tag`、`wishlist`、`admin` 等。
|
||||
- `src/views/`
|
||||
用户端页面。
|
||||
- `src/views/admin/`
|
||||
后台管理页面与后台布局。
|
||||
- `src/utils/permission.ts`
|
||||
拉取并缓存后台权限列表,供页面和路由守卫使用。
|
||||
- `src/config/api.ts`
|
||||
定义前台 API 基础地址与后台 API 基础地址。
|
||||
|
||||
用户端页面大致覆盖:
|
||||
|
||||
- 认证:`AuthView.vue`
|
||||
- 首页与商品:`HomeView.vue`、`ProductListView.vue`、`ProductDetailView.vue`
|
||||
- 店铺与订单:`ShopDetailView.vue`、`OrderView.vue`、`ArtistOrderView.vue`
|
||||
- 个人中心:`ProfileView.vue`、`SettingsView.vue`、`AccountSettingsView.vue`、`PasswordSettingsView.vue`
|
||||
- 购物与营销:`CartView.vue`、`WishlistView.vue`、`CouponView.vue`
|
||||
|
||||
后台管理页面大致覆盖:
|
||||
|
||||
- `AdminLoginView.vue`
|
||||
- `DashboardView.vue`
|
||||
- `UsersView.vue`
|
||||
- `ProductsView.vue`
|
||||
- `CouponsView.vue`
|
||||
- `ShopsView.vue`
|
||||
- `PermissionsView.vue`
|
||||
- `OrdersView.vue`
|
||||
- `TagsView.vue`
|
||||
- `NailArtistsView.vue`
|
||||
|
||||
## 4. 核心实现逻辑
|
||||
|
||||
### 4.1 路由与权限
|
||||
|
||||
路由集中定义在 `src/router/index.ts`:
|
||||
|
||||
- 用户端使用 `requiresAuth` 控制是否需要登录。
|
||||
- 管理端使用 `isAdmin` 区分,并额外基于 `permissionCode` 做权限守卫。
|
||||
- 后台登录成功后,会在本地存储保存:
|
||||
- `adminAccessToken`
|
||||
- `adminRefreshToken`
|
||||
- `adminUserInfo`
|
||||
- `userPermissions`
|
||||
|
||||
### 4.2 请求与 Token 刷新
|
||||
|
||||
前台请求封装在 `src/api/index.ts`,核心特征如下:
|
||||
|
||||
- 统一 Axios 实例,默认 `baseURL` 为 `http://127.0.0.1:8088/api`
|
||||
- 自动注入 `Authorization: Bearer <token>`
|
||||
- 401 时支持刷新 token
|
||||
- 通过队列机制串行处理并发刷新请求,避免同一时刻多次刷新
|
||||
- 区分前台 token 与后台 token
|
||||
|
||||
后台请求则在 `src/api/admin.ts` 中单独创建 Axios 实例,默认 `baseURL` 为 `http://127.0.0.1:8088/admin/api`。
|
||||
|
||||
### 4.3 页面职责分层
|
||||
|
||||
整体结构比较清晰:
|
||||
|
||||
- `views` 负责交互和状态组织
|
||||
- `api` 负责接口访问
|
||||
- `router` 负责导航与访问控制
|
||||
- `utils/permission.ts` 提供权限缓存与判断
|
||||
|
||||
这种结构适合继续扩展,但还没有进一步抽离成 composables、store 模块化或领域层。
|
||||
|
||||
## 5. 对接后端方式
|
||||
|
||||
从当前代码可确认前端依赖以下后端能力:
|
||||
|
||||
- 网关统一入口:`8088`
|
||||
- 用户端接口前缀:`/api`
|
||||
- 后台接口前缀:`/admin/api`
|
||||
- 文件访问:通过签名 URL 获取对象存储文件链接
|
||||
- 权限系统:后台页面依赖权限码判断是否可见/可访问
|
||||
|
||||
前端真实使用到的模块包括:
|
||||
|
||||
- 用户认证与资料
|
||||
- 商品、店铺、标签
|
||||
- 购物车、订单、收藏、点赞
|
||||
- 优惠券
|
||||
- 后台用户、商品、店铺、权限、订单、标签、仪表盘、美甲师管理
|
||||
|
||||
## 6. 当前状态评估
|
||||
|
||||
### 已实现能力
|
||||
|
||||
- C 端和后台端已经共存于同一前端项目
|
||||
- 登录态、Token 刷新、权限路由都有基础实现
|
||||
- 业务页面数量较多,说明项目已经进入可交互阶段
|
||||
- 文件上传、对象存储签名地址、管理员权限拉取等联动逻辑已接入
|
||||
|
||||
### 维护上值得注意的点
|
||||
|
||||
- `README.md` 仍然是默认 Vite 模板,未反映真实业务项目情况。
|
||||
- `src/config/api.ts` 使用 `127.0.0.1:8088`,而 `vite.config.ts` 的代理目标仍指向 `http://wcy111.top:8088`,存在环境配置漂移。
|
||||
- `vite.config.ts` 中 `/api` 代理配置会把 `/api` 前缀去掉,但当前 Axios 已经直接使用绝对地址,请求通常不会经过这个代理;即使经过,重写规则也与网关约定不完全一致。
|
||||
- 项目同时引入 Element Plus 和 Ant Design Vue,两套组件体系并存,后续在设计统一性、样式冲突、组件选择上会增加维护成本。
|
||||
- 当前没有前端自动化测试。
|
||||
- `src/views/admin/.AdminLayout.vue.swp` 是编辑器临时文件,建议清理。
|
||||
|
||||
## 7. 适合继续维护的方向
|
||||
|
||||
- 先统一环境配置来源,避免 `api.ts`、Vite 代理、历史文档分别指向不同地址。
|
||||
- 梳理 UI 组件体系,决定以 Element Plus 还是 Ant Design Vue 为主。
|
||||
- 给登录、Token 刷新、后台权限守卫补最基本的自动化测试或至少 E2E 用例。
|
||||
- 将 README 更新为真实业务说明,降低新接手人员的理解成本。
|
||||
|
||||
## 8. 一句话结论
|
||||
|
||||
这是一个功能面已经较完整的业务前端,前后台共仓、认证与权限逻辑基本成型;当前最明显的问题不是“缺页面”,而是环境配置漂移、组件体系混用以及缺少测试与正式项目文档。
|
||||
Reference in New Issue
Block a user