From 8033cabff97f477e87da06ba3b040fa03906446e Mon Sep 17 00:00:00 2001 From: que01 Date: Sat, 19 Sep 2026 18:46:26 +0800 Subject: [PATCH] =?UTF-8?q?style:=20=E7=BB=9F=E4=B8=80=E5=85=A8=E4=BB=93?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/admin/index.html | 13 +- apps/admin/tsconfig.json | 10 +- apps/api/prisma/seed.ts | 52 ++++---- apps/api/src/booking.dto.ts | 3 +- apps/api/src/http.ts | 16 ++- apps/api/src/wechat-auth.ts | 5 +- apps/api/test/booking.service.test.ts | 5 +- apps/miniapp/app.js | 2 +- apps/miniapp/app.json | 45 ++++++- apps/miniapp/package.json | 5 +- apps/miniapp/pages/booking/index.js | 109 ++++++++++++---- apps/miniapp/pages/booking/index.json | 6 +- apps/miniapp/pages/booking/index.wxss | 140 +++++++++++++++++++- apps/miniapp/pages/bookings/index.js | 78 ++++++++++-- apps/miniapp/pages/bookings/index.json | 6 +- apps/miniapp/pages/bookings/index.wxss | 160 ++++++++++++++++++++++- apps/miniapp/pages/index/index.js | 59 ++++++--- apps/miniapp/pages/index/index.wxss | 162 ++++++++++++++++++++++- apps/miniapp/pages/services/index.js | 46 ++++++- apps/miniapp/pages/services/index.json | 6 +- apps/miniapp/pages/services/index.wxss | 163 +++++++++++++++++++++++- apps/miniapp/project.config.json | 2 +- apps/miniapp/src/index.ts | 30 ++++- apps/miniapp/utils/config.js | 8 +- apps/miniapp/utils/labels.js | 19 ++- apps/miniapp/utils/request.js | 15 ++- apps/miniapp/utils/templates.js | 78 +++++++++++- docs/openapi.yaml | 106 +++++++-------- packages/api-client/package.json | 7 +- packages/api-client/test/client.test.ts | 14 +- 30 files changed, 1183 insertions(+), 187 deletions(-) diff --git a/apps/admin/index.html b/apps/admin/index.html index 15bb0b5..c7eb59c 100644 --- a/apps/admin/index.html +++ b/apps/admin/index.html @@ -1 +1,12 @@ -个人品牌后台
+ + + + + + 个人品牌后台 + + +
+ + + diff --git a/apps/admin/tsconfig.json b/apps/admin/tsconfig.json index 86ca382..f2de0df 100644 --- a/apps/admin/tsconfig.json +++ b/apps/admin/tsconfig.json @@ -1,5 +1,13 @@ { "extends": "../../tsconfig.base.json", - "compilerOptions": { "outDir": "dist", "rootDir": "src", "lib": ["ES2022", "DOM"], "jsx": "react-jsx", "module": "ESNext", "moduleResolution": "Bundler", "allowImportingTsExtensions": true }, + "compilerOptions": { + "outDir": "dist", + "rootDir": "src", + "lib": ["ES2022", "DOM"], + "jsx": "react-jsx", + "module": "ESNext", + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true + }, "include": ["src/**/*.ts"] } diff --git a/apps/api/prisma/seed.ts b/apps/api/prisma/seed.ts index 1da8fa7..bf4b3bb 100644 --- a/apps/api/prisma/seed.ts +++ b/apps/api/prisma/seed.ts @@ -20,33 +20,35 @@ async function main(): Promise { }); const services = [ - { - brandId: brand.id, - name: "红烧肉双拼套餐", - description: "红烧肉、时蔬、米饭", - priceText: "¥28 / 份", - priceAmount: 2800, - sortOrder: 1, - }, - { - brandId: brand.id, - name: "小炒鸡套餐", - description: "现炒鸡块、时蔬、米饭", - priceText: "¥25 / 份", - priceAmount: 2500, - sortOrder: 2, - }, - { - brandId: brand.id, - name: "家庭聚餐私厨", - description: "根据人数、地点和口味人工沟通报价", - priceText: "面议", - bookingEnabled: true, - sortOrder: 3, - }, + { + brandId: brand.id, + name: "红烧肉双拼套餐", + description: "红烧肉、时蔬、米饭", + priceText: "¥28 / 份", + priceAmount: 2800, + sortOrder: 1, + }, + { + brandId: brand.id, + name: "小炒鸡套餐", + description: "现炒鸡块、时蔬、米饭", + priceText: "¥25 / 份", + priceAmount: 2500, + sortOrder: 2, + }, + { + brandId: brand.id, + name: "家庭聚餐私厨", + description: "根据人数、地点和口味人工沟通报价", + priceText: "面议", + bookingEnabled: true, + sortOrder: 3, + }, ]; for (const service of services) { - const existing = await prisma.service.findFirst({ where: { brandId: brand.id, name: service.name } }); + const existing = await prisma.service.findFirst({ + where: { brandId: brand.id, name: service.name }, + }); if (existing) await prisma.service.update({ where: { id: existing.id }, data: service }); else await prisma.service.create({ data: service }); } diff --git a/apps/api/src/booking.dto.ts b/apps/api/src/booking.dto.ts index 3dea9f3..3592a7e 100644 --- a/apps/api/src/booking.dto.ts +++ b/apps/api/src/booking.dto.ts @@ -17,7 +17,8 @@ export class BookingItemDto { } export class CreateBookingDto { - @IsIn(["package", "private_chef", "inquiry"]) requestType!: "package" | "private_chef" | "inquiry"; + @IsIn(["package", "private_chef", "inquiry"]) requestType!: + "package" | "private_chef" | "inquiry"; @IsString() customerName!: string; @IsOptional() @IsString() phone?: string; @IsOptional() @IsString() wechatId?: string; diff --git a/apps/api/src/http.ts b/apps/api/src/http.ts index d1b9c53..38de765 100644 --- a/apps/api/src/http.ts +++ b/apps/api/src/http.ts @@ -31,18 +31,22 @@ export class ApiExceptionFilter implements ExceptionFilter { const request = context.getRequest(); const status = exception instanceof HttpException ? exception.getStatus() : 500; if (!(exception instanceof HttpException)) console.error("api unhandled error", exception); - const detail = exception instanceof HttpException - ? exception.getResponse() - : process.env.NODE_ENV === "development" && exception instanceof Error - ? exception.message - : "服务器内部错误"; + const detail = + exception instanceof HttpException + ? exception.getResponse() + : process.env.NODE_ENV === "development" && exception instanceof Error + ? exception.message + : "服务器内部错误"; response.status(status).send({ data: null, error: { code: `HTTP_${status}`, message: typeof detail === "string" ? detail : "请求失败", }, - requestId: (request as FastifyRequest & { requestId?: string }).requestId ?? request.headers["x-request-id"] ?? null, + requestId: + (request as FastifyRequest & { requestId?: string }).requestId ?? + request.headers["x-request-id"] ?? + null, }); } } diff --git a/apps/api/src/wechat-auth.ts b/apps/api/src/wechat-auth.ts index 8c59d71..3ac8964 100644 --- a/apps/api/src/wechat-auth.ts +++ b/apps/api/src/wechat-auth.ts @@ -32,7 +32,10 @@ export class WechatAuthService { try { response = await fetch(`https://api.weixin.qq.com/sns/jscode2session?${query.toString()}`); } catch (error) { - console.error("wechat session request failed", error instanceof Error ? error.message : error); + console.error( + "wechat session request failed", + error instanceof Error ? error.message : error, + ); throw new ServiceUnavailableException("微信登录服务暂时不可用"); } if (!response.ok) { diff --git a/apps/api/test/booking.service.test.ts b/apps/api/test/booking.service.test.ts index 38333f7..e60267a 100644 --- a/apps/api/test/booking.service.test.ts +++ b/apps/api/test/booking.service.test.ts @@ -90,7 +90,10 @@ test("订单状态只能按定义的状态机流转", async () => { }, }); const bookings = new BookingService(prisma); - assert.equal((await bookings.updateStatus(brandId, "booking-1", "contacting")).status, "contacting"); + assert.equal( + (await bookings.updateStatus(brandId, "booking-1", "contacting")).status, + "contacting", + ); await assert.rejects( () => bookings.updateStatus(brandId, "booking-1", "completed"), (error: unknown) => error instanceof BadRequestException, diff --git a/apps/miniapp/app.js b/apps/miniapp/app.js index cc5b479..c0507c5 100644 --- a/apps/miniapp/app.js +++ b/apps/miniapp/app.js @@ -1,6 +1,6 @@ App({ onLaunch() { - this.globalData = { apiBaseUrl: 'http://192.168.88.29:3001', brand: {} }; + this.globalData = { apiBaseUrl: "http://192.168.88.29:3001", brand: {} }; }, globalData: {}, }); diff --git a/apps/miniapp/app.json b/apps/miniapp/app.json index 9541b89..08eab5c 100644 --- a/apps/miniapp/app.json +++ b/apps/miniapp/app.json @@ -1,9 +1,40 @@ { - "pages": ["pages/index/index", "pages/services/index", "pages/booking/index", "pages/bookings/index"], - "window": { "navigationBarTitleText": "个人品牌", "navigationBarBackgroundColor": "#FBF7F1", "navigationBarTextStyle": "black", "backgroundColor": "#FBF7F1" }, - "tabBar": { "color": "#7A4A2B", "selectedColor": "#B54A2C", "backgroundColor": "#FFFFFF", "borderStyle": "white", "list": [ - { "pagePath": "pages/index/index", "text": "首页", "iconPath": "assets/tab/home.png", "selectedIconPath": "assets/tab/home-selected.png" }, - { "pagePath": "pages/services/index", "text": "服务", "iconPath": "assets/tab/briefcase.png", "selectedIconPath": "assets/tab/briefcase-selected.png" }, - { "pagePath": "pages/bookings/index", "text": "我的", "iconPath": "assets/tab/user.png", "selectedIconPath": "assets/tab/user-selected.png" } - ] } + "pages": [ + "pages/index/index", + "pages/services/index", + "pages/booking/index", + "pages/bookings/index" + ], + "window": { + "navigationBarTitleText": "个人品牌", + "navigationBarBackgroundColor": "#FBF7F1", + "navigationBarTextStyle": "black", + "backgroundColor": "#FBF7F1" + }, + "tabBar": { + "color": "#7A4A2B", + "selectedColor": "#B54A2C", + "backgroundColor": "#FFFFFF", + "borderStyle": "white", + "list": [ + { + "pagePath": "pages/index/index", + "text": "首页", + "iconPath": "assets/tab/home.png", + "selectedIconPath": "assets/tab/home-selected.png" + }, + { + "pagePath": "pages/services/index", + "text": "服务", + "iconPath": "assets/tab/briefcase.png", + "selectedIconPath": "assets/tab/briefcase-selected.png" + }, + { + "pagePath": "pages/bookings/index", + "text": "我的", + "iconPath": "assets/tab/user.png", + "selectedIconPath": "assets/tab/user-selected.png" + } + ] + } } diff --git a/apps/miniapp/package.json b/apps/miniapp/package.json index 96308d9..ce293c0 100644 --- a/apps/miniapp/package.json +++ b/apps/miniapp/package.json @@ -2,7 +2,10 @@ "name": "@personal-brand/miniapp", "private": true, "type": "module", - "dependencies": { "@personal-brand/api-client": "workspace:*", "@personal-brand/types": "workspace:*" }, + "dependencies": { + "@personal-brand/api-client": "workspace:*", + "@personal-brand/types": "workspace:*" + }, "scripts": { "lint": "eslint src --ext .ts", "typecheck": "tsc -p tsconfig.json --noEmit", diff --git a/apps/miniapp/pages/booking/index.js b/apps/miniapp/pages/booking/index.js index 612c46e..54719e3 100644 --- a/apps/miniapp/pages/booking/index.js +++ b/apps/miniapp/pages/booking/index.js @@ -1,31 +1,92 @@ -const { request, customerRequest } = require('../../utils/request'); -const { getTemplate } = require('../../utils/templates'); +const { request, customerRequest } = require("../../utils/request"); +const { getTemplate } = require("../../utils/templates"); Page({ - data: { service: {}, form: {}, serviceId: '', quantity: 1, fulfillment: 'pickup', submitting: false, template: getTemplate('personal') }, - onLoad(query) { Promise.all([request('/public/services'), request('/public/brand')]).then(([services, brand]) => { const list = Array.isArray(services) ? services : []; const service = list.find((item) => item.id === query.serviceId) || list.find((item) => item.priceAmount !== null) || {}; this.setData({ service, serviceId: service.id || '', template: getTemplate(brand.templateKey) }); }).catch(() => wx.showToast({ title: '服务加载失败', icon: 'none' })); }, - input(event) { this.setData({ ['form.' + event.currentTarget.dataset.key]: event.detail.value }); }, - chooseFulfillment(event) { this.setData({ fulfillment: event.currentTarget.dataset.value }); }, - increase() { if (this.data.quantity < 50) this.setData({ quantity: this.data.quantity + 1 }); }, - decrease() { if (this.data.quantity > 1) this.setData({ quantity: this.data.quantity - 1 }); }, + data: { + service: {}, + form: {}, + serviceId: "", + quantity: 1, + fulfillment: "pickup", + submitting: false, + template: getTemplate("personal"), + }, + onLoad(query) { + Promise.all([request("/public/services"), request("/public/brand")]) + .then(([services, brand]) => { + const list = Array.isArray(services) ? services : []; + const service = + list.find((item) => item.id === query.serviceId) || + list.find((item) => item.priceAmount !== null) || + {}; + this.setData({ + service, + serviceId: service.id || "", + template: getTemplate(brand.templateKey), + }); + }) + .catch(() => wx.showToast({ title: "服务加载失败", icon: "none" })); + }, + input(event) { + this.setData({ ["form." + event.currentTarget.dataset.key]: event.detail.value }); + }, + chooseFulfillment(event) { + this.setData({ fulfillment: event.currentTarget.dataset.value }); + }, + increase() { + if (this.data.quantity < 50) this.setData({ quantity: this.data.quantity + 1 }); + }, + decrease() { + if (this.data.quantity > 1) this.setData({ quantity: this.data.quantity - 1 }); + }, submit() { const form = this.data.form; - if (!this.data.serviceId) return wx.showToast({ title: '请先选择服务', icon: 'none' }); - if (!form.customerName || !form.wechatId) return wx.showToast({ title: '请填写称呼和联系方式', icon: 'none' }); - if (this.data.fulfillment === 'delivery' && !form.deliveryAddress) return wx.showToast({ title: '请填写' + this.data.template.locationLabel, icon: 'none' }); + if (!this.data.serviceId) return wx.showToast({ title: "请先选择服务", icon: "none" }); + if (!form.customerName || !form.wechatId) + return wx.showToast({ title: "请填写称呼和联系方式", icon: "none" }); + if (this.data.fulfillment === "delivery" && !form.deliveryAddress) + return wx.showToast({ title: "请填写" + this.data.template.locationLabel, icon: "none" }); this.setData({ submitting: true }); - const send = () => customerRequest('/customer/bookings', { - method: 'POST', - data: { requestType: this.data.template.requestType, customerName: form.customerName, wechatId: form.wechatId, contactPreference: 'wechat', fulfillmentType: this.data.fulfillment, deliveryAddress: form.deliveryAddress, requestedTime: form.requestedTime, note: form.note, items: [{ serviceId: this.data.serviceId, quantity: this.data.quantity }] }, - }).then(() => { - this.setData({ submitting: false }); - wx.showToast({ title: '预约已提交' }); - setTimeout(() => wx.navigateTo({ url: '/pages/bookings/index' }), 500); - }).catch((error) => { - this.setData({ submitting: false }); - wx.showToast({ title: error.message || '提交失败', icon: 'none' }); - }); - const token = wx.getStorageSync('customerToken'); + const send = () => + customerRequest("/customer/bookings", { + method: "POST", + data: { + requestType: this.data.template.requestType, + customerName: form.customerName, + wechatId: form.wechatId, + contactPreference: "wechat", + fulfillmentType: this.data.fulfillment, + deliveryAddress: form.deliveryAddress, + requestedTime: form.requestedTime, + note: form.note, + items: [{ serviceId: this.data.serviceId, quantity: this.data.quantity }], + }, + }) + .then(() => { + this.setData({ submitting: false }); + wx.showToast({ title: "预约已提交" }); + setTimeout(() => wx.navigateTo({ url: "/pages/bookings/index" }), 500); + }) + .catch((error) => { + this.setData({ submitting: false }); + wx.showToast({ title: error.message || "提交失败", icon: "none" }); + }); + const token = wx.getStorageSync("customerToken"); if (token) return send(); - wx.login({ success: (login) => request('/customer/session/wechat', { method: 'POST', data: { code: login.code } }).then((result) => { wx.setStorageSync('customerToken', result.token); send(); }).catch((error) => { this.setData({ submitting: false }); wx.showToast({ title: error.message || '微信登录失败', icon: 'none' }); }), fail: (error) => { this.setData({ submitting: false }); wx.showToast({ title: error.errMsg || '微信登录失败', icon: 'none' }); } }); + wx.login({ + success: (login) => + request("/customer/session/wechat", { method: "POST", data: { code: login.code } }) + .then((result) => { + wx.setStorageSync("customerToken", result.token); + send(); + }) + .catch((error) => { + this.setData({ submitting: false }); + wx.showToast({ title: error.message || "微信登录失败", icon: "none" }); + }), + fail: (error) => { + this.setData({ submitting: false }); + wx.showToast({ title: error.errMsg || "微信登录失败", icon: "none" }); + }, + }); }, }); diff --git a/apps/miniapp/pages/booking/index.json b/apps/miniapp/pages/booking/index.json index 6f36cc1..0fcbac4 100644 --- a/apps/miniapp/pages/booking/index.json +++ b/apps/miniapp/pages/booking/index.json @@ -1 +1,5 @@ -{"navigationBarTitleText":"提交需求","navigationBarBackgroundColor":"#FBF7F1","navigationBarTextStyle":"black"} +{ + "navigationBarTitleText": "提交需求", + "navigationBarBackgroundColor": "#FBF7F1", + "navigationBarTextStyle": "black" +} diff --git a/apps/miniapp/pages/booking/index.wxss b/apps/miniapp/pages/booking/index.wxss index ea548f5..660a0f2 100644 --- a/apps/miniapp/pages/booking/index.wxss +++ b/apps/miniapp/pages/booking/index.wxss @@ -1,2 +1,138 @@ -.page{min-height:100vh;padding:24rpx 32rpx 60rpx;background:#FBF7F1;color:#2B2B2B}.product{display:flex;align-items:center;gap:20rpx;padding:20rpx;background:#F4EBD9;border-radius:16rpx}.product-image{width:220rpx;height:180rpx;overflow:hidden;border-radius:12rpx;flex:none}.product-image image,.dish-placeholder{width:100%;height:100%;display:block;background:#c79555}.product-copy{flex:1}.name{display:block;font-size:34rpx;font-weight:700}.price{display:block;margin-top:18rpx;color:#B54A2C;font-size:38rpx}.available{color:#7A4A2B;font-size:26rpx;white-space:nowrap;align-self:flex-start;margin-top:14rpx}.quantity,.fulfillment{margin-top:20rpx;padding:28rpx;background:#F4EBD9;border-radius:16rpx;font-size:32rpx}.stepper{float:right;display:flex;align-items:center;gap:18rpx}.stepper button{width:56rpx;height:56rpx;line-height:52rpx;padding:0;border-radius:50%;background:#fff;color:#B54A2C}.field-title{font-weight:700}.choices{display:flex;gap:16rpx;margin-top:18rpx}.choice{flex:1;border-radius:12rpx;background:#7A4A2B;color:#fff}.choice.active{background:#B54A2C}.form{margin-top:20rpx;background:#fff;border-radius:16rpx;padding:8rpx 28rpx}.form label{display:flex;justify-content:space-between;gap:20rpx;padding:28rpx 0;border-bottom:1rpx solid #eee;font-size:30rpx}.form input,.form textarea{flex:1;text-align:right}.form textarea{min-height:100rpx}.notice{margin:20rpx 0;padding:24rpx;background:#F4EBD9;border-radius:16rpx;color:#7A4A2B}.submit{background:#B54A2C;color:#fff;border-radius:12rpx;font-size:34rpx} -.stepper button{display:flex;width:64rpx;height:64rpx;align-items:center;justify-content:center;padding:0;border:0;border-radius:16rpx;background:#fff;color:#B54A2C;font-size:40rpx;line-height:1} +.page { + min-height: 100vh; + padding: 24rpx 32rpx 60rpx; + background: #fbf7f1; + color: #2b2b2b; +} +.product { + display: flex; + align-items: center; + gap: 20rpx; + padding: 20rpx; + background: #f4ebd9; + border-radius: 16rpx; +} +.product-image { + width: 220rpx; + height: 180rpx; + overflow: hidden; + border-radius: 12rpx; + flex: none; +} +.product-image image, +.dish-placeholder { + width: 100%; + height: 100%; + display: block; + background: #c79555; +} +.product-copy { + flex: 1; +} +.name { + display: block; + font-size: 34rpx; + font-weight: 700; +} +.price { + display: block; + margin-top: 18rpx; + color: #b54a2c; + font-size: 38rpx; +} +.available { + color: #7a4a2b; + font-size: 26rpx; + white-space: nowrap; + align-self: flex-start; + margin-top: 14rpx; +} +.quantity, +.fulfillment { + margin-top: 20rpx; + padding: 28rpx; + background: #f4ebd9; + border-radius: 16rpx; + font-size: 32rpx; +} +.stepper { + float: right; + display: flex; + align-items: center; + gap: 18rpx; +} +.stepper button { + width: 56rpx; + height: 56rpx; + line-height: 52rpx; + padding: 0; + border-radius: 50%; + background: #fff; + color: #b54a2c; +} +.field-title { + font-weight: 700; +} +.choices { + display: flex; + gap: 16rpx; + margin-top: 18rpx; +} +.choice { + flex: 1; + border-radius: 12rpx; + background: #7a4a2b; + color: #fff; +} +.choice.active { + background: #b54a2c; +} +.form { + margin-top: 20rpx; + background: #fff; + border-radius: 16rpx; + padding: 8rpx 28rpx; +} +.form label { + display: flex; + justify-content: space-between; + gap: 20rpx; + padding: 28rpx 0; + border-bottom: 1rpx solid #eee; + font-size: 30rpx; +} +.form input, +.form textarea { + flex: 1; + text-align: right; +} +.form textarea { + min-height: 100rpx; +} +.notice { + margin: 20rpx 0; + padding: 24rpx; + background: #f4ebd9; + border-radius: 16rpx; + color: #7a4a2b; +} +.submit { + background: #b54a2c; + color: #fff; + border-radius: 12rpx; + font-size: 34rpx; +} +.stepper button { + display: flex; + width: 64rpx; + height: 64rpx; + align-items: center; + justify-content: center; + padding: 0; + border: 0; + border-radius: 16rpx; + background: #fff; + color: #b54a2c; + font-size: 40rpx; + line-height: 1; +} diff --git a/apps/miniapp/pages/bookings/index.js b/apps/miniapp/pages/bookings/index.js index 98b26c8..5677884 100644 --- a/apps/miniapp/pages/bookings/index.js +++ b/apps/miniapp/pages/bookings/index.js @@ -1,10 +1,72 @@ -const { request, customerRequest } = require('../../utils/request'); -const { bookingViewModel } = require('../../utils/labels'); -const { getTemplate } = require('../../utils/templates'); +const { request, customerRequest } = require("../../utils/request"); +const { bookingViewModel } = require("../../utils/labels"); +const { getTemplate } = require("../../utils/templates"); Page({ - data: { loading: true, error: '', bookings: [], cancellingId: '', template: getTemplate('personal') }, - onLoad() { this.load(); }, onShow() { this.load(); }, - load() { const token = wx.getStorageSync('customerToken'); if (!token) return this.setData({ loading: false, bookings: [], error: '' }); this.setData({ loading: true, error: '' }); Promise.all([customerRequest('/customer/bookings'), request('/public/brand')]).then(([items, brand]) => { getApp().globalData.brand = brand; const template = getTemplate(brand.templateKey); this.setData({ template, bookings: (Array.isArray(items) ? items : []).map((item) => bookingViewModel(item, template)), loading: false }); }).catch((error) => this.setData({ loading: false, error: error.message || '网络请求失败' })); }, - retry() { this.load(); }, contact() { const brand = getApp().globalData.brand || {}; if (brand.contactPhone) return wx.makePhoneCall({ phoneNumber: brand.contactPhone }); if (brand.contactWechat) return wx.showModal({ title: '联系品牌方', content: '微信号:' + brand.contactWechat, showCancel: false }); wx.showToast({ title: '暂未配置联系方式', icon: 'none' }); }, - cancel(e) { const id = e.currentTarget.dataset.id; if (this.data.cancellingId) return; wx.showModal({ title: '取消预约', content: '确定取消这笔预约吗?', success: (result) => { if (!result.confirm) return; this.setData({ cancellingId: id }); customerRequest('/customer/bookings/' + id + '/cancel', { method: 'POST', data: {} }).then(() => { this.setData({ cancellingId: '' }); wx.showToast({ title: '已取消预约', icon: 'success' }); this.load(); }).catch((error) => { this.setData({ cancellingId: '' }); wx.showToast({ title: error.message || '取消失败', icon: 'none' }); }); } }); } + data: { + loading: true, + error: "", + bookings: [], + cancellingId: "", + template: getTemplate("personal"), + }, + onLoad() { + this.load(); + }, + onShow() { + this.load(); + }, + load() { + const token = wx.getStorageSync("customerToken"); + if (!token) return this.setData({ loading: false, bookings: [], error: "" }); + this.setData({ loading: true, error: "" }); + Promise.all([customerRequest("/customer/bookings"), request("/public/brand")]) + .then(([items, brand]) => { + getApp().globalData.brand = brand; + const template = getTemplate(brand.templateKey); + this.setData({ + template, + bookings: (Array.isArray(items) ? items : []).map((item) => + bookingViewModel(item, template), + ), + loading: false, + }); + }) + .catch((error) => this.setData({ loading: false, error: error.message || "网络请求失败" })); + }, + retry() { + this.load(); + }, + contact() { + const brand = getApp().globalData.brand || {}; + if (brand.contactPhone) return wx.makePhoneCall({ phoneNumber: brand.contactPhone }); + if (brand.contactWechat) + return wx.showModal({ + title: "联系品牌方", + content: "微信号:" + brand.contactWechat, + showCancel: false, + }); + wx.showToast({ title: "暂未配置联系方式", icon: "none" }); + }, + cancel(e) { + const id = e.currentTarget.dataset.id; + if (this.data.cancellingId) return; + wx.showModal({ + title: "取消预约", + content: "确定取消这笔预约吗?", + success: (result) => { + if (!result.confirm) return; + this.setData({ cancellingId: id }); + customerRequest("/customer/bookings/" + id + "/cancel", { method: "POST", data: {} }) + .then(() => { + this.setData({ cancellingId: "" }); + wx.showToast({ title: "已取消预约", icon: "success" }); + this.load(); + }) + .catch((error) => { + this.setData({ cancellingId: "" }); + wx.showToast({ title: error.message || "取消失败", icon: "none" }); + }); + }, + }); + }, }); diff --git a/apps/miniapp/pages/bookings/index.json b/apps/miniapp/pages/bookings/index.json index 7f70a48..9fa3e67 100644 --- a/apps/miniapp/pages/bookings/index.json +++ b/apps/miniapp/pages/bookings/index.json @@ -1 +1,5 @@ -{"navigationBarTitleText":"我的订单","navigationBarBackgroundColor":"#FBF7F1","navigationBarTextStyle":"black"} +{ + "navigationBarTitleText": "我的订单", + "navigationBarBackgroundColor": "#FBF7F1", + "navigationBarTextStyle": "black" +} diff --git a/apps/miniapp/pages/bookings/index.wxss b/apps/miniapp/pages/bookings/index.wxss index bf690ae..ccc58c1 100644 --- a/apps/miniapp/pages/bookings/index.wxss +++ b/apps/miniapp/pages/bookings/index.wxss @@ -1,2 +1,158 @@ -.page{min-height:100vh;padding:24rpx 32rpx 60rpx;background:#FBF7F1;color:#2B2B2B}.heading-row{display:flex;justify-content:space-between;align-items:center;margin:12rpx 0 32rpx}.heading{font-size:48rpx;font-weight:700}.phone{font-size:48rpx;color:#7A4A2B}.status-banner{position:relative;display:flex;justify-content:space-between;align-items:center;margin-bottom:20rpx;padding:34rpx 32rpx;background:#F4EBD9;border-radius:16rpx}.status-title{display:block;font-size:40rpx;font-weight:700}.status-sub{display:block;margin-top:10rpx;font-size:28rpx}.check{color:#B54A2C;font-size:88rpx;line-height:1}.card{margin-bottom:18rpx;padding:22rpx;background:#F4EBD9;border-radius:16rpx}.card-visual{display:flex;gap:20rpx;align-items:center}.dish-placeholder{width:190rpx;height:190rpx;flex:none;border-radius:12rpx;background:#c79555}.name{display:block;font-size:36rpx;font-weight:700;margin-bottom:14rpx}.summary{font-size:28rpx;line-height:1.6}.card-foot{display:flex;justify-content:space-between;align-items:center;margin-top:24rpx;padding:18rpx 4rpx;border-top:1rpx solid #dfcda9}.status{padding:8rpx 20rpx;border:1rpx solid #B54A2C;border-radius:30rpx;color:#B54A2C}.price{color:#B54A2C;font-size:42rpx}.actions{display:flex;gap:16rpx;margin-top:18rpx}.actions button{flex:1;border-radius:12rpx;font-size:29rpx}.contact{background:#2B2B2B;color:#fff}.cancel{background:#B54A2C;color:#fff}.cancel-note{display:block;margin-top:18rpx;text-align:center;font-size:25rpx}.faq{margin-top:24rpx;padding:28rpx 30rpx;background:#fff;border-radius:16rpx}.faq view{padding:20rpx 0;border-bottom:1rpx solid #eee;font-size:29rpx}.faq view:last-child{border-bottom:0}.faq-title{font-size:36rpx!important;font-weight:700}.faq text{float:right;color:#7A4A2B;font-size:40rpx}.state,.empty{text-align:center;padding:100rpx 20rpx;color:#7A4A2B} -.check{box-sizing:border-box;display:flex;width:108rpx;height:108rpx;align-items:center;justify-content:center;padding:18rpx;border:8rpx solid #B54A2C;border-radius:50%;color:#B54A2C;font-size:56rpx;line-height:1} +.page { + min-height: 100vh; + padding: 24rpx 32rpx 60rpx; + background: #fbf7f1; + color: #2b2b2b; +} +.heading-row { + display: flex; + justify-content: space-between; + align-items: center; + margin: 12rpx 0 32rpx; +} +.heading { + font-size: 48rpx; + font-weight: 700; +} +.phone { + font-size: 48rpx; + color: #7a4a2b; +} +.status-banner { + position: relative; + display: flex; + justify-content: space-between; + align-items: center; + margin-bottom: 20rpx; + padding: 34rpx 32rpx; + background: #f4ebd9; + border-radius: 16rpx; +} +.status-title { + display: block; + font-size: 40rpx; + font-weight: 700; +} +.status-sub { + display: block; + margin-top: 10rpx; + font-size: 28rpx; +} +.check { + color: #b54a2c; + font-size: 88rpx; + line-height: 1; +} +.card { + margin-bottom: 18rpx; + padding: 22rpx; + background: #f4ebd9; + border-radius: 16rpx; +} +.card-visual { + display: flex; + gap: 20rpx; + align-items: center; +} +.dish-placeholder { + width: 190rpx; + height: 190rpx; + flex: none; + border-radius: 12rpx; + background: #c79555; +} +.name { + display: block; + font-size: 36rpx; + font-weight: 700; + margin-bottom: 14rpx; +} +.summary { + font-size: 28rpx; + line-height: 1.6; +} +.card-foot { + display: flex; + justify-content: space-between; + align-items: center; + margin-top: 24rpx; + padding: 18rpx 4rpx; + border-top: 1rpx solid #dfcda9; +} +.status { + padding: 8rpx 20rpx; + border: 1rpx solid #b54a2c; + border-radius: 30rpx; + color: #b54a2c; +} +.price { + color: #b54a2c; + font-size: 42rpx; +} +.actions { + display: flex; + gap: 16rpx; + margin-top: 18rpx; +} +.actions button { + flex: 1; + border-radius: 12rpx; + font-size: 29rpx; +} +.contact { + background: #2b2b2b; + color: #fff; +} +.cancel { + background: #b54a2c; + color: #fff; +} +.cancel-note { + display: block; + margin-top: 18rpx; + text-align: center; + font-size: 25rpx; +} +.faq { + margin-top: 24rpx; + padding: 28rpx 30rpx; + background: #fff; + border-radius: 16rpx; +} +.faq view { + padding: 20rpx 0; + border-bottom: 1rpx solid #eee; + font-size: 29rpx; +} +.faq view:last-child { + border-bottom: 0; +} +.faq-title { + font-size: 36rpx !important; + font-weight: 700; +} +.faq text { + float: right; + color: #7a4a2b; + font-size: 40rpx; +} +.state, +.empty { + text-align: center; + padding: 100rpx 20rpx; + color: #7a4a2b; +} +.check { + box-sizing: border-box; + display: flex; + width: 108rpx; + height: 108rpx; + align-items: center; + justify-content: center; + padding: 18rpx; + border: 8rpx solid #b54a2c; + border-radius: 50%; + color: #b54a2c; + font-size: 56rpx; + line-height: 1; +} diff --git a/apps/miniapp/pages/index/index.js b/apps/miniapp/pages/index/index.js index f4e688b..109c6e0 100644 --- a/apps/miniapp/pages/index/index.js +++ b/apps/miniapp/pages/index/index.js @@ -1,23 +1,46 @@ -const { request } = require('../../utils/request'); -const config = require('../../utils/config'); -const { getTemplate } = require('../../utils/templates'); +const { request } = require("../../utils/request"); +const config = require("../../utils/config"); +const { getTemplate } = require("../../utils/templates"); Page({ - data: { loading: true, error: '', brand: {}, services: [], copy: {} }, - onLoad() { this.load(); }, + data: { loading: true, error: "", brand: {}, services: [], copy: {} }, + onLoad() { + this.load(); + }, load() { - this.setData({ loading: true, error: '' }); - Promise.all([request('/public/brand'), request('/public/services')]).then(([brand, services]) => { - getApp().globalData.brand = brand; - wx.setNavigationBarTitle({ title: brand.name || '个人品牌' }); - const copy = getTemplate(brand.templateKey); - this.setData({ brand: { ...brand, coverUrl: brand.coverUrl || '/assets/brand/home-hero.jpg' }, services, copy, loading: false }); - }).catch(() => this.setData({ loading: false, error: '暂时无法加载内容' })); + this.setData({ loading: true, error: "" }); + Promise.all([request("/public/brand"), request("/public/services")]) + .then(([brand, services]) => { + getApp().globalData.brand = brand; + wx.setNavigationBarTitle({ title: brand.name || "个人品牌" }); + const copy = getTemplate(brand.templateKey); + this.setData({ + brand: { ...brand, coverUrl: brand.coverUrl || "/assets/brand/home-hero.jpg" }, + services, + copy, + loading: false, + }); + }) + .catch(() => this.setData({ loading: false, error: "暂时无法加载内容" })); + }, + selectService(event) { + wx.navigateTo({ + url: "/pages/booking/index?serviceId=" + encodeURIComponent(event.currentTarget.dataset.id), + }); + }, + goServices() { + wx.switchTab({ url: "/pages/services/index" }); + }, + goPrivateChef() { + wx.navigateTo({ url: "/pages/booking/index?type=private_chef" }); + }, + goBooking() { + wx.navigateTo({ url: "/pages/booking/index" }); + }, + goBookings() { + wx.switchTab({ url: "/pages/bookings/index" }); + }, + goHome() { + wx.switchTab({ url: "/pages/index/index" }); }, - selectService(event) { wx.navigateTo({ url: '/pages/booking/index?serviceId=' + encodeURIComponent(event.currentTarget.dataset.id) }); }, - goServices() { wx.switchTab({ url: '/pages/services/index' }); }, - goPrivateChef() { wx.navigateTo({ url: '/pages/booking/index?type=private_chef' }); }, - goBooking() { wx.navigateTo({ url: '/pages/booking/index' }); }, - goBookings() { wx.switchTab({ url: '/pages/bookings/index' }); }, - goHome() { wx.switchTab({ url: '/pages/index/index' }); }, }); diff --git a/apps/miniapp/pages/index/index.wxss b/apps/miniapp/pages/index/index.wxss index 8869194..e096639 100644 --- a/apps/miniapp/pages/index/index.wxss +++ b/apps/miniapp/pages/index/index.wxss @@ -1 +1,161 @@ -.page{box-sizing:border-box;padding:8rpx 32rpx 170rpx;background:#FBF7F1;min-height:100vh;color:#2B2B2B}.topbar{text-align:center;padding:2rpx 0 24rpx}.brand-subtitle{display:block;color:#7A4A2B;font-size:28rpx;line-height:1.4}.hero{position:relative;height:410rpx;overflow:hidden;border-radius:24rpx;background:#7A4A2B}.hero image,.hero-placeholder{width:100%;height:100%;display:block;background:linear-gradient(135deg,#7A4A2B,#2B2B2B)}.hero-copy{position:absolute;left:34rpx;top:36rpx;color:#fff;font-size:42rpx;font-weight:700}.hero-copy text{display:block;margin-bottom:8rpx}.intro,.info-card{margin-top:20rpx;padding:28rpx;background:#F4EBD9;border-radius:16rpx}.section-title{font-size:36rpx;font-weight:700}.intro-copy{display:block;margin-top:18rpx;font-size:30rpx;line-height:1.55}.info-card{display:grid;grid-template-columns:1fr auto;gap:20rpx;font-size:29rpx}.info-label{font-weight:700;margin-right:24rpx}.chevron{font-size:50rpx}.line{grid-column:1 / -1;border-top:1rpx solid #d8c9af}.actions{display:flex;gap:16rpx;margin-top:24rpx}.actions button{flex:1;border-radius:12rpx;font-size:34rpx;color:#fff}.primary{background:#B54A2C}.secondary{background:#7A4A2B}.services-title{margin:34rpx 0 16rpx}.service{display:flex;justify-content:space-between;gap:20rpx;margin-bottom:12rpx;padding:26rpx 22rpx;background:#fff;border-radius:16rpx}.service-name{display:block;font-size:32rpx;font-weight:600}.description{display:block;color:#7A4A2B;margin-top:10rpx}.price{white-space:nowrap;color:#B54A2C;font-size:34rpx}.state{padding:80rpx 20rpx;text-align:center}.error{color:#B54A2C}.state button{margin-top:24rpx;background:#B54A2C;color:#fff;border-radius:12rpx}.tabbar{position:fixed;bottom:0;left:0;right:0;display:flex;justify-content:space-around;padding:18rpx 0 34rpx;background:#fff;border-top:1rpx solid #eee;z-index:10}.tab{display:flex;flex-direction:column;align-items:center;color:#7A4A2B;font-size:42rpx;min-width:100rpx}.tab text{font-size:24rpx;margin-top:5rpx}.tab.active{color:#B54A2C} +.page { + box-sizing: border-box; + padding: 8rpx 32rpx 170rpx; + background: #fbf7f1; + min-height: 100vh; + color: #2b2b2b; +} +.topbar { + text-align: center; + padding: 2rpx 0 24rpx; +} +.brand-subtitle { + display: block; + color: #7a4a2b; + font-size: 28rpx; + line-height: 1.4; +} +.hero { + position: relative; + height: 410rpx; + overflow: hidden; + border-radius: 24rpx; + background: #7a4a2b; +} +.hero image, +.hero-placeholder { + width: 100%; + height: 100%; + display: block; + background: linear-gradient(135deg, #7a4a2b, #2b2b2b); +} +.hero-copy { + position: absolute; + left: 34rpx; + top: 36rpx; + color: #fff; + font-size: 42rpx; + font-weight: 700; +} +.hero-copy text { + display: block; + margin-bottom: 8rpx; +} +.intro, +.info-card { + margin-top: 20rpx; + padding: 28rpx; + background: #f4ebd9; + border-radius: 16rpx; +} +.section-title { + font-size: 36rpx; + font-weight: 700; +} +.intro-copy { + display: block; + margin-top: 18rpx; + font-size: 30rpx; + line-height: 1.55; +} +.info-card { + display: grid; + grid-template-columns: 1fr auto; + gap: 20rpx; + font-size: 29rpx; +} +.info-label { + font-weight: 700; + margin-right: 24rpx; +} +.chevron { + font-size: 50rpx; +} +.line { + grid-column: 1 / -1; + border-top: 1rpx solid #d8c9af; +} +.actions { + display: flex; + gap: 16rpx; + margin-top: 24rpx; +} +.actions button { + flex: 1; + border-radius: 12rpx; + font-size: 34rpx; + color: #fff; +} +.primary { + background: #b54a2c; +} +.secondary { + background: #7a4a2b; +} +.services-title { + margin: 34rpx 0 16rpx; +} +.service { + display: flex; + justify-content: space-between; + gap: 20rpx; + margin-bottom: 12rpx; + padding: 26rpx 22rpx; + background: #fff; + border-radius: 16rpx; +} +.service-name { + display: block; + font-size: 32rpx; + font-weight: 600; +} +.description { + display: block; + color: #7a4a2b; + margin-top: 10rpx; +} +.price { + white-space: nowrap; + color: #b54a2c; + font-size: 34rpx; +} +.state { + padding: 80rpx 20rpx; + text-align: center; +} +.error { + color: #b54a2c; +} +.state button { + margin-top: 24rpx; + background: #b54a2c; + color: #fff; + border-radius: 12rpx; +} +.tabbar { + position: fixed; + bottom: 0; + left: 0; + right: 0; + display: flex; + justify-content: space-around; + padding: 18rpx 0 34rpx; + background: #fff; + border-top: 1rpx solid #eee; + z-index: 10; +} +.tab { + display: flex; + flex-direction: column; + align-items: center; + color: #7a4a2b; + font-size: 42rpx; + min-width: 100rpx; +} +.tab text { + font-size: 24rpx; + margin-top: 5rpx; +} +.tab.active { + color: #b54a2c; +} diff --git a/apps/miniapp/pages/services/index.js b/apps/miniapp/pages/services/index.js index 6f056dd..a5276fa 100644 --- a/apps/miniapp/pages/services/index.js +++ b/apps/miniapp/pages/services/index.js @@ -1,3 +1,43 @@ -const { request } = require('../../utils/request'); -const { getTemplate } = require('../../utils/templates'); -Page({ data: { loading: true, error: '', services: [], filtered: [], category: 'package', labels: {} }, onLoad() { Promise.all([request('/public/services'), request('/public/brand')]).then(([services, brand]) => { const labels = getTemplate(brand.templateKey); const mapped = services.map((item) => ({ ...item, coverUrl: item.coverUrl || (item.name.includes('红烧肉') ? '/assets/brand/service-red-braised-pork.jpg' : item.name.includes('小炒鸡') ? '/assets/brand/service-chicken.jpg' : item.name.includes('私厨') ? '/assets/brand/service-private-chef.jpg' : '') })); this.setData({ services: mapped, labels, filtered: mapped.filter((item) => item.priceAmount !== null), loading: false }); }).catch(() => this.setData({ loading: false, error: '服务加载失败' })); }, switchCategory(e) { const category = e.currentTarget.dataset.category; const filtered = category === 'package' ? this.data.services.filter((item) => item.priceAmount !== null) : this.data.services.filter((item) => item.priceAmount === null); this.setData({ category, filtered }); }, book(e) { wx.navigateTo({ url: '/pages/booking/index?serviceId=' + encodeURIComponent(e.currentTarget.dataset.id) }); } }); +const { request } = require("../../utils/request"); +const { getTemplate } = require("../../utils/templates"); +Page({ + data: { loading: true, error: "", services: [], filtered: [], category: "package", labels: {} }, + onLoad() { + Promise.all([request("/public/services"), request("/public/brand")]) + .then(([services, brand]) => { + const labels = getTemplate(brand.templateKey); + const mapped = services.map((item) => ({ + ...item, + coverUrl: + item.coverUrl || + (item.name.includes("红烧肉") + ? "/assets/brand/service-red-braised-pork.jpg" + : item.name.includes("小炒鸡") + ? "/assets/brand/service-chicken.jpg" + : item.name.includes("私厨") + ? "/assets/brand/service-private-chef.jpg" + : ""), + })); + this.setData({ + services: mapped, + labels, + filtered: mapped.filter((item) => item.priceAmount !== null), + loading: false, + }); + }) + .catch(() => this.setData({ loading: false, error: "服务加载失败" })); + }, + switchCategory(e) { + const category = e.currentTarget.dataset.category; + const filtered = + category === "package" + ? this.data.services.filter((item) => item.priceAmount !== null) + : this.data.services.filter((item) => item.priceAmount === null); + this.setData({ category, filtered }); + }, + book(e) { + wx.navigateTo({ + url: "/pages/booking/index?serviceId=" + encodeURIComponent(e.currentTarget.dataset.id), + }); + }, +}); diff --git a/apps/miniapp/pages/services/index.json b/apps/miniapp/pages/services/index.json index f7bf51c..f533acb 100644 --- a/apps/miniapp/pages/services/index.json +++ b/apps/miniapp/pages/services/index.json @@ -1 +1,5 @@ -{"navigationBarTitleText":"服务列表","navigationBarBackgroundColor":"#FBF7F1","navigationBarTextStyle":"black"} +{ + "navigationBarTitleText": "服务列表", + "navigationBarBackgroundColor": "#FBF7F1", + "navigationBarTextStyle": "black" +} diff --git a/apps/miniapp/pages/services/index.wxss b/apps/miniapp/pages/services/index.wxss index 2fe3794..3895610 100644 --- a/apps/miniapp/pages/services/index.wxss +++ b/apps/miniapp/pages/services/index.wxss @@ -1,2 +1,161 @@ -.page{min-height:100vh;padding:24rpx 32rpx 60rpx;background:#FBF7F1;color:#2B2B2B}.heading{margin:12rpx 0 28rpx}.heading text:first-child{display:block;font-size:48rpx;font-weight:700}.sub{display:block;margin-top:8rpx;font-size:30rpx}.categories{display:flex;gap:16rpx;margin-bottom:28rpx}.category{flex:1;padding:28rpx 22rpx;border-radius:16rpx;font-size:30rpx}.category text{display:block}.category-title{font-weight:700}.category text+text{margin-top:12rpx;font-size:25rpx}.package{background:#B54A2C;color:#fff}.chef{background:#F4EBD9;color:#2B2B2B}.category.selected{box-shadow:0 0 0 4rpx #E8A75F}.card{display:flex;gap:22rpx;align-items:stretch;margin-bottom:16rpx;padding:20rpx;background:#fff;border-radius:16rpx}.dish-image{width:230rpx;min-width:230rpx;height:230rpx;border-radius:12rpx;overflow:hidden}.dish-image image,.dish-placeholder{width:100%;height:100%;display:block;background:#d6b27c}.card-content{flex:1;display:flex;flex-direction:column}.card-head{display:flex;justify-content:space-between;gap:8rpx}.name{font-size:34rpx;font-weight:700}.available{padding:6rpx 12rpx;border:1rpx solid #C79555;border-radius:24rpx;color:#7A4A2B;font-size:21rpx;white-space:nowrap}.desc{display:block;margin:14rpx 0;color:#7A4A2B;font-size:27rpx;line-height:1.4}.card-bottom{display:flex;justify-content:space-between;align-items:end;margin-top:auto}.price{display:block;color:#B54A2C;font-size:38rpx}.card button{background:#B54A2C;color:#fff;border-radius:36rpx}.state{text-align:center;padding:80rpx;color:#7A4A2B} -.categories{display:flex;gap:16rpx;margin-bottom:28rpx}.category{position:relative;z-index:1;overflow:hidden}.category:before,.category:after{content:'';position:absolute;right:-28rpx;bottom:-48rpx;width:160rpx;height:104rpx;border:5rpx solid rgba(255,255,255,.16);border-radius:50% 50% 44% 44%;transform:rotate(-16deg);pointer-events:none}.category:after{right:8rpx;bottom:-34rpx;width:110rpx;height:70rpx;border-width:4rpx;border-color:rgba(255,255,255,.12)}.chef:before{border-color:rgba(181,74,44,.16)}.chef:after{border-color:rgba(181,74,44,.12)} +.page { + min-height: 100vh; + padding: 24rpx 32rpx 60rpx; + background: #fbf7f1; + color: #2b2b2b; +} +.heading { + margin: 12rpx 0 28rpx; +} +.heading text:first-child { + display: block; + font-size: 48rpx; + font-weight: 700; +} +.sub { + display: block; + margin-top: 8rpx; + font-size: 30rpx; +} +.categories { + display: flex; + gap: 16rpx; + margin-bottom: 28rpx; +} +.category { + flex: 1; + padding: 28rpx 22rpx; + border-radius: 16rpx; + font-size: 30rpx; +} +.category text { + display: block; +} +.category-title { + font-weight: 700; +} +.category text + text { + margin-top: 12rpx; + font-size: 25rpx; +} +.package { + background: #b54a2c; + color: #fff; +} +.chef { + background: #f4ebd9; + color: #2b2b2b; +} +.category.selected { + box-shadow: 0 0 0 4rpx #e8a75f; +} +.card { + display: flex; + gap: 22rpx; + align-items: stretch; + margin-bottom: 16rpx; + padding: 20rpx; + background: #fff; + border-radius: 16rpx; +} +.dish-image { + width: 230rpx; + min-width: 230rpx; + height: 230rpx; + border-radius: 12rpx; + overflow: hidden; +} +.dish-image image, +.dish-placeholder { + width: 100%; + height: 100%; + display: block; + background: #d6b27c; +} +.card-content { + flex: 1; + display: flex; + flex-direction: column; +} +.card-head { + display: flex; + justify-content: space-between; + gap: 8rpx; +} +.name { + font-size: 34rpx; + font-weight: 700; +} +.available { + padding: 6rpx 12rpx; + border: 1rpx solid #c79555; + border-radius: 24rpx; + color: #7a4a2b; + font-size: 21rpx; + white-space: nowrap; +} +.desc { + display: block; + margin: 14rpx 0; + color: #7a4a2b; + font-size: 27rpx; + line-height: 1.4; +} +.card-bottom { + display: flex; + justify-content: space-between; + align-items: end; + margin-top: auto; +} +.price { + display: block; + color: #b54a2c; + font-size: 38rpx; +} +.card button { + background: #b54a2c; + color: #fff; + border-radius: 36rpx; +} +.state { + text-align: center; + padding: 80rpx; + color: #7a4a2b; +} +.categories { + display: flex; + gap: 16rpx; + margin-bottom: 28rpx; +} +.category { + position: relative; + z-index: 1; + overflow: hidden; +} +.category:before, +.category:after { + content: ""; + position: absolute; + right: -28rpx; + bottom: -48rpx; + width: 160rpx; + height: 104rpx; + border: 5rpx solid rgba(255, 255, 255, 0.16); + border-radius: 50% 50% 44% 44%; + transform: rotate(-16deg); + pointer-events: none; +} +.category:after { + right: 8rpx; + bottom: -34rpx; + width: 110rpx; + height: 70rpx; + border-width: 4rpx; + border-color: rgba(255, 255, 255, 0.12); +} +.chef:before { + border-color: rgba(181, 74, 44, 0.16); +} +.chef:after { + border-color: rgba(181, 74, 44, 0.12); +} diff --git a/apps/miniapp/project.config.json b/apps/miniapp/project.config.json index e0bb265..417636e 100644 --- a/apps/miniapp/project.config.json +++ b/apps/miniapp/project.config.json @@ -22,4 +22,4 @@ }, "appid": "wxd75d946d6978d183", "editorSetting": {} -} \ No newline at end of file +} diff --git a/apps/miniapp/src/index.ts b/apps/miniapp/src/index.ts index 2a650b1..488e7e6 100644 --- a/apps/miniapp/src/index.ts +++ b/apps/miniapp/src/index.ts @@ -2,16 +2,36 @@ import { ApiClient, type CreateBookingInput, type FetchLike } from "@personal-br import { HTTP_STATUS } from "@personal-brand/types"; export interface MiniappRequestAdapter { - request(options: { url: string; method: string; header: Record; data?: string }): Promise<{ statusCode: number; data: unknown }>; + request(options: { + url: string; + method: string; + header: Record; + data?: string; + }): Promise<{ statusCode: number; data: unknown }>; } -export function createMiniappClient(baseUrl: string, adapter: MiniappRequestAdapter, token?: string): ApiClient { +export function createMiniappClient( + baseUrl: string, + adapter: MiniappRequestAdapter, + token?: string, +): ApiClient { const fetcher: FetchLike = async (url, init) => { - const response = await adapter.request({ url, method: init?.method ?? "GET", header: init?.headers ?? {}, ...(init?.body ? { data: init.body } : {}) }); - return { status: response.statusCode, ok: response.statusCode >= HTTP_STATUS.OK && response.statusCode < HTTP_STATUS.BAD_REQUEST, json: () => Promise.resolve(response.data) }; + const response = await adapter.request({ + url, + method: init?.method ?? "GET", + header: init?.headers ?? {}, + ...(init?.body ? { data: init.body } : {}), + }); + return { + status: response.statusCode, + ok: response.statusCode >= HTTP_STATUS.OK && response.statusCode < HTTP_STATUS.BAD_REQUEST, + json: () => Promise.resolve(response.data), + }; }; return new ApiClient({ baseUrl, fetcher, ...(token ? { token } : {}) }); } -export async function submitBooking(client: ApiClient, input: CreateBookingInput): Promise { await client.createCustomerBooking(input); } +export async function submitBooking(client: ApiClient, input: CreateBookingInput): Promise { + await client.createCustomerBooking(input); +} export const miniappName = "personal-brand-miniapp"; diff --git a/apps/miniapp/utils/config.js b/apps/miniapp/utils/config.js index a7fbe41..779588c 100644 --- a/apps/miniapp/utils/config.js +++ b/apps/miniapp/utils/config.js @@ -1,6 +1,10 @@ const app = getApp(); module.exports = { - get apiBaseUrl() { return app.globalData.apiBaseUrl; }, - get brand() { return app.globalData.brand || {}; }, + get apiBaseUrl() { + return app.globalData.apiBaseUrl; + }, + get brand() { + return app.globalData.brand || {}; + }, }; diff --git a/apps/miniapp/utils/labels.js b/apps/miniapp/utils/labels.js index 1e28cb5..e35ab9c 100644 --- a/apps/miniapp/utils/labels.js +++ b/apps/miniapp/utils/labels.js @@ -1,12 +1,21 @@ -const STATUS_LABELS = { received: '待确认', contacting: '沟通中', confirmed: '已确认', completed: '已完成', cancelled: '已取消' }; -const FULFILLMENT_LABELS = { pickup: '自取', delivery: '配送' }; +const STATUS_LABELS = { + received: "待确认", + contacting: "沟通中", + confirmed: "已确认", + completed: "已完成", + cancelled: "已取消", +}; +const FULFILLMENT_LABELS = { pickup: "自取", delivery: "配送" }; function bookingViewModel(item, template) { return { ...item, - statusLabel: STATUS_LABELS[item.status] || '未知状态', - fulfillmentLabel: template?.modeLabels?.[item.fulfillmentType] || FULFILLMENT_LABELS[item.fulfillmentType] || '待确认', - serviceName: item.service?.name || item.items?.[0]?.serviceNameSnapshot || '未命名服务', + statusLabel: STATUS_LABELS[item.status] || "未知状态", + fulfillmentLabel: + template?.modeLabels?.[item.fulfillmentType] || + FULFILLMENT_LABELS[item.fulfillmentType] || + "待确认", + serviceName: item.service?.name || item.items?.[0]?.serviceNameSnapshot || "未命名服务", quantityLabel: `${item.items?.[0]?.quantity || 1} 份`, }; } diff --git a/apps/miniapp/utils/request.js b/apps/miniapp/utils/request.js index a21588a..5d31fe6 100644 --- a/apps/miniapp/utils/request.js +++ b/apps/miniapp/utils/request.js @@ -1,15 +1,15 @@ -const config = require('./config'); +const config = require("./config"); function request(path, options = {}) { return new Promise((resolve, reject) => { wx.request({ url: config.apiBaseUrl + path, - method: options.method || 'GET', - header: { accept: 'application/json', ...(options.header || {}) }, + method: options.method || "GET", + header: { accept: "application/json", ...(options.header || {}) }, ...(options.data === undefined ? {} : { data: options.data }), success: (response) => { if (response.statusCode >= 200 && response.statusCode < 300) return resolve(response.data); - const error = response.data?.error?.message || '请求失败'; + const error = response.data?.error?.message || "请求失败"; reject(Object.assign(new Error(error), { statusCode: response.statusCode, response })); }, fail: reject, @@ -18,8 +18,11 @@ function request(path, options = {}) { } function customerRequest(path, options = {}) { - const token = wx.getStorageSync('customerToken'); - return request(path, { ...options, header: { ...(options.header || {}), Authorization: 'Bearer ' + token } }); + const token = wx.getStorageSync("customerToken"); + return request(path, { + ...options, + header: { ...(options.header || {}), Authorization: "Bearer " + token }, + }); } module.exports = { request, customerRequest }; diff --git a/apps/miniapp/utils/templates.js b/apps/miniapp/utils/templates.js index b7d03ea..aae846f 100644 --- a/apps/miniapp/utils/templates.js +++ b/apps/miniapp/utils/templates.js @@ -1,6 +1,78 @@ const TEMPLATES = { - food: { modeLabels: { pickup: '自取', delivery: '配送' }, contactLabel: '联系摊主', cancelLabel: '取消预约', cancelNote: '取消后请及时告知摊主,避免食材浪费。', hero: '今天吃什么', heroSub: '现做家常饭', about: '品牌简介', description: '个人经营的家常小灶,套餐现做,也可预约小型聚餐和私厨定制。', primary: '预约套餐', secondary: '咨询私厨', timeLabel: '营业时间', time: '11:00—20:00', addressLabel: '摊位地址', address: '校园路社区便民点 12 号', noteLabel: '配送说明', note: '满 30 元周边配送,也可自取', serviceSub: '今日可订', first: '普通套餐', firstSub: '日常家常饭', second: '私厨服务', secondSub: '聚餐定制', available: '今日可订', unavailable: '暂不可订', empty: '暂无可订服务', bookingTitle: '预约套餐', requestType: 'package', modeLabel: '取餐方式', modeA: '自取', modeB: '配送', locationLabel: '配送地址', locationPlaceholder: '请输入配送地址', notePlaceholder: '口味、餐具或其他说明', submitNotice: '提交后由摊主人工确认,确认后再安排制作。', submitLabel: '提交预约' }, - personal: { modeLabels: { pickup: '线上沟通', delivery: '线下沟通' }, contactLabel: '联系品牌方', cancelLabel: '取消申请', cancelNote: '如需调整,请尽早联系品牌方。', hero: '个人品牌', heroSub: '把专业能力,变成值得信赖的体验', about: '关于我', description: '这里展示你的专业背景、工作方式与品牌理念。', primary: '查看服务', secondary: '发起咨询', timeLabel: '服务时间', time: '工作日 10:00—18:00', addressLabel: '所在位置', address: '线上 / 线下均可沟通', noteLabel: '合作说明', note: '提交需求后,我会尽快与你联系', serviceSub: '可咨询', first: '标准服务', firstSub: '清晰的服务方案', second: '定制合作', secondSub: '按需求沟通', available: '可咨询', unavailable: '暂不可用', empty: '暂无可咨询服务', bookingTitle: '合作咨询', requestType: 'inquiry', modeLabel: '沟通方式', modeA: '线上沟通', modeB: '线下沟通', locationLabel: '沟通方式或地点', locationPlaceholder: '请输入会议方式、地点或链接', notePlaceholder: '请介绍你的需求、预算或期待结果', submitNotice: '提交后品牌方会与你确认需求、时间和合作方式。', submitLabel: '提交需求' }, + food: { + modeLabels: { pickup: "自取", delivery: "配送" }, + contactLabel: "联系摊主", + cancelLabel: "取消预约", + cancelNote: "取消后请及时告知摊主,避免食材浪费。", + hero: "今天吃什么", + heroSub: "现做家常饭", + about: "品牌简介", + description: "个人经营的家常小灶,套餐现做,也可预约小型聚餐和私厨定制。", + primary: "预约套餐", + secondary: "咨询私厨", + timeLabel: "营业时间", + time: "11:00—20:00", + addressLabel: "摊位地址", + address: "校园路社区便民点 12 号", + noteLabel: "配送说明", + note: "满 30 元周边配送,也可自取", + serviceSub: "今日可订", + first: "普通套餐", + firstSub: "日常家常饭", + second: "私厨服务", + secondSub: "聚餐定制", + available: "今日可订", + unavailable: "暂不可订", + empty: "暂无可订服务", + bookingTitle: "预约套餐", + requestType: "package", + modeLabel: "取餐方式", + modeA: "自取", + modeB: "配送", + locationLabel: "配送地址", + locationPlaceholder: "请输入配送地址", + notePlaceholder: "口味、餐具或其他说明", + submitNotice: "提交后由摊主人工确认,确认后再安排制作。", + submitLabel: "提交预约", + }, + personal: { + modeLabels: { pickup: "线上沟通", delivery: "线下沟通" }, + contactLabel: "联系品牌方", + cancelLabel: "取消申请", + cancelNote: "如需调整,请尽早联系品牌方。", + hero: "个人品牌", + heroSub: "把专业能力,变成值得信赖的体验", + about: "关于我", + description: "这里展示你的专业背景、工作方式与品牌理念。", + primary: "查看服务", + secondary: "发起咨询", + timeLabel: "服务时间", + time: "工作日 10:00—18:00", + addressLabel: "所在位置", + address: "线上 / 线下均可沟通", + noteLabel: "合作说明", + note: "提交需求后,我会尽快与你联系", + serviceSub: "可咨询", + first: "标准服务", + firstSub: "清晰的服务方案", + second: "定制合作", + secondSub: "按需求沟通", + available: "可咨询", + unavailable: "暂不可用", + empty: "暂无可咨询服务", + bookingTitle: "合作咨询", + requestType: "inquiry", + modeLabel: "沟通方式", + modeA: "线上沟通", + modeB: "线下沟通", + locationLabel: "沟通方式或地点", + locationPlaceholder: "请输入会议方式、地点或链接", + notePlaceholder: "请介绍你的需求、预算或期待结果", + submitNotice: "提交后品牌方会与你确认需求、时间和合作方式。", + submitLabel: "提交需求", + }, }; -function getTemplate(key) { return TEMPLATES[key] || TEMPLATES.personal; } +function getTemplate(key) { + return TEMPLATES[key] || TEMPLATES.personal; +} module.exports = { getTemplate, TEMPLATES }; diff --git a/docs/openapi.yaml b/docs/openapi.yaml index 5e65fb6..143c3d9 100644 --- a/docs/openapi.yaml +++ b/docs/openapi.yaml @@ -10,34 +10,34 @@ paths: get: operationId: getHealth responses: - '200': + "200": description: API health status content: application/json: schema: - $ref: '#/components/schemas/Health' + $ref: "#/components/schemas/Health" /public/brand: get: operationId: getPublicBrand responses: - '200': + "200": description: Public brand profile content: application/json: schema: - $ref: '#/components/schemas/BrandProfile' + $ref: "#/components/schemas/BrandProfile" /public/services: get: operationId: listPublicServices responses: - '200': + "200": description: Enabled public services content: application/json: schema: type: array items: - $ref: '#/components/schemas/PublicService' + $ref: "#/components/schemas/PublicService" /customer/session/wechat: post: operationId: createCustomerSession @@ -52,25 +52,25 @@ paths: code: type: string responses: - '201': + "201": description: Customer session token content: application/json: schema: - $ref: '#/components/schemas/TokenResponse' + $ref: "#/components/schemas/TokenResponse" /customer/bookings: get: operationId: listCustomerBookings security: [bearerAuth: []] responses: - '200': + "200": description: Current customer's bookings content: application/json: schema: type: array items: - $ref: '#/components/schemas/Booking' + $ref: "#/components/schemas/Booking" post: operationId: createCustomerBooking security: [bearerAuth: []] @@ -79,27 +79,27 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/CreateBooking' + $ref: "#/components/schemas/CreateBooking" responses: - '201': + "201": description: Created booking summary content: application/json: schema: - $ref: '#/components/schemas/BookingSummary' + $ref: "#/components/schemas/BookingSummary" /customer/bookings/{id}/cancel: post: operationId: cancelCustomerBooking security: [bearerAuth: []] parameters: - - $ref: '#/components/parameters/BookingId' + - $ref: "#/components/parameters/BookingId" responses: - '201': + "201": description: Cancelled booking content: application/json: schema: - $ref: '#/components/schemas/Booking' + $ref: "#/components/schemas/Booking" /admin/session/login: post: operationId: createAdminSession @@ -108,14 +108,14 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/AdminLogin' + $ref: "#/components/schemas/AdminLogin" responses: - '201': + "201": description: Admin session token content: application/json: schema: - $ref: '#/components/schemas/AdminTokenResponse' + $ref: "#/components/schemas/AdminTokenResponse" /admin/bookings: get: operationId: listAdminBookings @@ -124,7 +124,7 @@ paths: - in: query name: status schema: - $ref: '#/components/schemas/BookingStatus' + $ref: "#/components/schemas/BookingStatus" - in: query name: unreadOnly schema: @@ -134,20 +134,20 @@ paths: schema: type: string responses: - '200': + "200": description: Admin booking list content: application/json: schema: type: array items: - $ref: '#/components/schemas/Booking' + $ref: "#/components/schemas/Booking" /admin/bookings/unread-count: get: operationId: getAdminUnreadBookingCount security: [bearerAuth: []] responses: - '200': + "200": description: Number of unread bookings content: application/json: @@ -161,55 +161,55 @@ paths: operationId: getAdminBooking security: [bearerAuth: []] parameters: - - $ref: '#/components/parameters/BookingId' + - $ref: "#/components/parameters/BookingId" responses: - '200': + "200": description: Admin booking detail content: application/json: schema: - $ref: '#/components/schemas/Booking' + $ref: "#/components/schemas/Booking" /admin/bookings/{id}/status: post: operationId: updateAdminBookingStatus security: [bearerAuth: []] parameters: - - $ref: '#/components/parameters/BookingId' + - $ref: "#/components/parameters/BookingId" requestBody: required: true content: application/json: schema: - $ref: '#/components/schemas/UpdateBookingStatus' + $ref: "#/components/schemas/UpdateBookingStatus" responses: - '201': + "201": description: Updated booking content: application/json: schema: - $ref: '#/components/schemas/Booking' + $ref: "#/components/schemas/Booking" /admin/bookings/{id}/read: post: operationId: markAdminBookingRead security: [bearerAuth: []] parameters: - - $ref: '#/components/parameters/BookingId' + - $ref: "#/components/parameters/BookingId" responses: - '201': + "201": description: Updated booking /admin/bookings/tags: get: operationId: listAdminTags security: [bearerAuth: []] responses: - '200': + "200": description: Enabled tags content: application/json: schema: type: array items: - $ref: '#/components/schemas/Tag' + $ref: "#/components/schemas/Tag" post: operationId: createAdminTag security: [bearerAuth: []] @@ -223,12 +223,12 @@ paths: properties: name: { type: string, maxLength: 24 } responses: - '201': + "201": description: Created tag content: application/json: schema: - $ref: '#/components/schemas/Tag' + $ref: "#/components/schemas/Tag" components: securitySchemes: bearerAuth: @@ -253,13 +253,13 @@ components: properties: id: { type: string, format: uuid } name: { type: string } - tagline: { type: [string, 'null'] } - description: { type: [string, 'null'] } - avatarUrl: { type: [string, 'null'], format: uri } - coverUrl: { type: [string, 'null'], format: uri } - hours: { type: [string, 'null'] } - address: { type: [string, 'null'] } - deliveryNote: { type: [string, 'null'] } + tagline: { type: [string, "null"] } + description: { type: [string, "null"] } + avatarUrl: { type: [string, "null"], format: uri } + coverUrl: { type: [string, "null"], format: uri } + hours: { type: [string, "null"] } + address: { type: [string, "null"] } + deliveryNote: { type: [string, "null"] } PublicService: type: object required: [id, name, description, bookingEnabled] @@ -267,9 +267,9 @@ components: id: { type: string, format: uuid } name: { type: string } description: { type: string } - coverUrl: { type: [string, 'null'], format: uri } - priceText: { type: [string, 'null'] } - priceAmount: { type: [integer, 'null'], minimum: 0 } + coverUrl: { type: [string, "null"], format: uri } + priceText: { type: [string, "null"] } + priceAmount: { type: [integer, "null"], minimum: 0 } bookingEnabled: { type: boolean } BookingStatus: type: string @@ -298,23 +298,23 @@ components: extraData: { type: object, additionalProperties: true } items: type: array - items: { $ref: '#/components/schemas/BookingItemInput' } + items: { $ref: "#/components/schemas/BookingItemInput" } BookingSummary: type: object required: [bookingNo, status, estimatedAmount, createdAt] properties: bookingNo: { type: string } - status: { $ref: '#/components/schemas/BookingStatus' } - estimatedAmount: { type: [integer, 'null'] } + status: { $ref: "#/components/schemas/BookingStatus" } + estimatedAmount: { type: [integer, "null"] } createdAt: { type: string, format: date-time } Booking: allOf: - - $ref: '#/components/schemas/BookingSummary' + - $ref: "#/components/schemas/BookingSummary" - type: object properties: id: { type: string, format: uuid } customerName: { type: string } - adminNote: { type: [string, 'null'] } + adminNote: { type: [string, "null"] } AdminLogin: type: object required: [username, password] @@ -328,7 +328,7 @@ components: token: { type: string } AdminTokenResponse: allOf: - - $ref: '#/components/schemas/TokenResponse' + - $ref: "#/components/schemas/TokenResponse" - type: object required: [displayName] properties: @@ -337,7 +337,7 @@ components: type: object required: [status] properties: - status: { $ref: '#/components/schemas/BookingStatus' } + status: { $ref: "#/components/schemas/BookingStatus" } adminNote: { type: string } Tag: type: object diff --git a/packages/api-client/package.json b/packages/api-client/package.json index 05f69f6..ee49b8c 100644 --- a/packages/api-client/package.json +++ b/packages/api-client/package.json @@ -2,7 +2,12 @@ "name": "@personal-brand/api-client", "private": true, "type": "module", - "exports": { ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" } }, + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.js" + } + }, "scripts": { "build": "tsc -p tsconfig.json", "lint": "eslint .", diff --git a/packages/api-client/test/client.test.ts b/packages/api-client/test/client.test.ts index 092129e..9c8b6d6 100644 --- a/packages/api-client/test/client.test.ts +++ b/packages/api-client/test/client.test.ts @@ -7,7 +7,8 @@ function response(body: unknown, status = 200): FetchResponse { } test("客户端发送认证头、查询参数和 JSON 请求体", async () => { - const calls: Array<{ url: string; init?: { headers?: Record; body?: string } }> = []; + const calls: Array<{ url: string; init?: { headers?: Record; body?: string } }> = + []; const client = new ApiClient({ baseUrl: "http://api.test/", token: "token-1", @@ -18,7 +19,10 @@ test("客户端发送认证头、查询参数和 JSON 请求体", async () => { }); await client.listAdminBookings({ status: "received", unreadOnly: true, tagId: "tag/1" }); await client.createAdminTag("重点"); - assert.equal(calls[0]?.url, "http://api.test/admin/bookings?status=received&unreadOnly=true&tagId=tag%2F1"); + assert.equal( + calls[0]?.url, + "http://api.test/admin/bookings?status=received&unreadOnly=true&tagId=tag%2F1", + ); assert.equal(calls[0]?.init?.headers?.authorization, "Bearer token-1"); assert.equal(calls[1]?.init?.body, JSON.stringify({ name: "重点" })); }); @@ -26,7 +30,11 @@ test("客户端发送认证头、查询参数和 JSON 请求体", async () => { test("客户端将统一错误响应转换为 ApiClientError", async () => { const client = new ApiClient({ baseUrl: "http://api.test", - fetcher: async () => response({ data: null, error: { code: "HTTP_401", message: "无权限" }, requestId: "req-1" }, 401), + fetcher: async () => + response( + { data: null, error: { code: "HTTP_401", message: "无权限" }, requestId: "req-1" }, + 401, + ), }); await assert.rejects( () => client.getAdminUnreadCount(),