style: 统一全仓代码格式
This commit is contained in:
1 parent
d811478d0f
commit
8033cabff9
30 files changed
+1183
-187
No files matched your search
+12
-1
@@ -1 +1,12 @@
|
||||
<!doctype html><html lang="zh-CN"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>个人品牌后台</title></head><body><main id="app"></main><script type="module" src="/src/main.tsx"></script></body></html>
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
<title>个人品牌后台</title>
|
||||
</head>
|
||||
<body>
|
||||
<main id="app"></main>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -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"]
|
||||
}
|
||||
+27
-25
@@ -20,33 +20,35 @@ async function main(): Promise<void> {
|
||||
});
|
||||
|
||||
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 });
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
+10
-6
@@ -31,18 +31,22 @@ export class ApiExceptionFilter implements ExceptionFilter {
|
||||
const request = context.getRequest<FastifyRequest>();
|
||||
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,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
+1
-1
@@ -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: {},
|
||||
});
|
||||
+38
-7
@@ -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"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -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",
|
||||
|
||||
@@ -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" });
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
@@ -1 +1,5 @@
|
||||
{"navigationBarTitleText":"提交需求","navigationBarBackgroundColor":"#FBF7F1","navigationBarTextStyle":"black"}
|
||||
{
|
||||
"navigationBarTitleText": "提交需求",
|
||||
"navigationBarBackgroundColor": "#FBF7F1",
|
||||
"navigationBarTextStyle": "black"
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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" });
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
@@ -1 +1,5 @@
|
||||
{"navigationBarTitleText":"我的订单","navigationBarBackgroundColor":"#FBF7F1","navigationBarTextStyle":"black"}
|
||||
{
|
||||
"navigationBarTitleText": "我的订单",
|
||||
"navigationBarBackgroundColor": "#FBF7F1",
|
||||
"navigationBarTextStyle": "black"
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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' }); },
|
||||
});
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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),
|
||||
});
|
||||
},
|
||||
});
|
||||
@@ -1 +1,5 @@
|
||||
{"navigationBarTitleText":"服务列表","navigationBarBackgroundColor":"#FBF7F1","navigationBarTextStyle":"black"}
|
||||
{
|
||||
"navigationBarTitleText": "服务列表",
|
||||
"navigationBarBackgroundColor": "#FBF7F1",
|
||||
"navigationBarTextStyle": "black"
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -22,4 +22,4 @@
|
||||
},
|
||||
"appid": "wxd75d946d6978d183",
|
||||
"editorSetting": {}
|
||||
}
|
||||
}
|
||||
@@ -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<string, string>; data?: string }): Promise<{ statusCode: number; data: unknown }>;
|
||||
request(options: {
|
||||
url: string;
|
||||
method: string;
|
||||
header: Record<string, string>;
|
||||
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<void> { await client.createCustomerBooking(input); }
|
||||
export async function submitBooking(client: ApiClient, input: CreateBookingInput): Promise<void> {
|
||||
await client.createCustomerBooking(input);
|
||||
}
|
||||
export const miniappName = "personal-brand-miniapp";
|
||||
@@ -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 || {};
|
||||
},
|
||||
};
|
||||
@@ -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} 份`,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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 };
|
||||
@@ -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 };
|
||||
Reference in new issue
Block a user