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",
|
"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"]
|
"include": ["src/**/*.ts"]
|
||||||
}
|
}
|
||||||
+27
-25
@@ -20,33 +20,35 @@ async function main(): Promise<void> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const services = [
|
const services = [
|
||||||
{
|
{
|
||||||
brandId: brand.id,
|
brandId: brand.id,
|
||||||
name: "红烧肉双拼套餐",
|
name: "红烧肉双拼套餐",
|
||||||
description: "红烧肉、时蔬、米饭",
|
description: "红烧肉、时蔬、米饭",
|
||||||
priceText: "¥28 / 份",
|
priceText: "¥28 / 份",
|
||||||
priceAmount: 2800,
|
priceAmount: 2800,
|
||||||
sortOrder: 1,
|
sortOrder: 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
brandId: brand.id,
|
brandId: brand.id,
|
||||||
name: "小炒鸡套餐",
|
name: "小炒鸡套餐",
|
||||||
description: "现炒鸡块、时蔬、米饭",
|
description: "现炒鸡块、时蔬、米饭",
|
||||||
priceText: "¥25 / 份",
|
priceText: "¥25 / 份",
|
||||||
priceAmount: 2500,
|
priceAmount: 2500,
|
||||||
sortOrder: 2,
|
sortOrder: 2,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
brandId: brand.id,
|
brandId: brand.id,
|
||||||
name: "家庭聚餐私厨",
|
name: "家庭聚餐私厨",
|
||||||
description: "根据人数、地点和口味人工沟通报价",
|
description: "根据人数、地点和口味人工沟通报价",
|
||||||
priceText: "面议",
|
priceText: "面议",
|
||||||
bookingEnabled: true,
|
bookingEnabled: true,
|
||||||
sortOrder: 3,
|
sortOrder: 3,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
for (const service of services) {
|
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 });
|
if (existing) await prisma.service.update({ where: { id: existing.id }, data: service });
|
||||||
else await prisma.service.create({ data: service });
|
else await prisma.service.create({ data: service });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ export class BookingItemDto {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class CreateBookingDto {
|
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;
|
@IsString() customerName!: string;
|
||||||
@IsOptional() @IsString() phone?: string;
|
@IsOptional() @IsString() phone?: string;
|
||||||
@IsOptional() @IsString() wechatId?: string;
|
@IsOptional() @IsString() wechatId?: string;
|
||||||
|
|||||||
+10
-6
@@ -31,18 +31,22 @@ export class ApiExceptionFilter implements ExceptionFilter {
|
|||||||
const request = context.getRequest<FastifyRequest>();
|
const request = context.getRequest<FastifyRequest>();
|
||||||
const status = exception instanceof HttpException ? exception.getStatus() : 500;
|
const status = exception instanceof HttpException ? exception.getStatus() : 500;
|
||||||
if (!(exception instanceof HttpException)) console.error("api unhandled error", exception);
|
if (!(exception instanceof HttpException)) console.error("api unhandled error", exception);
|
||||||
const detail = exception instanceof HttpException
|
const detail =
|
||||||
? exception.getResponse()
|
exception instanceof HttpException
|
||||||
: process.env.NODE_ENV === "development" && exception instanceof Error
|
? exception.getResponse()
|
||||||
? exception.message
|
: process.env.NODE_ENV === "development" && exception instanceof Error
|
||||||
: "服务器内部错误";
|
? exception.message
|
||||||
|
: "服务器内部错误";
|
||||||
response.status(status).send({
|
response.status(status).send({
|
||||||
data: null,
|
data: null,
|
||||||
error: {
|
error: {
|
||||||
code: `HTTP_${status}`,
|
code: `HTTP_${status}`,
|
||||||
message: typeof detail === "string" ? detail : "请求失败",
|
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 {
|
try {
|
||||||
response = await fetch(`https://api.weixin.qq.com/sns/jscode2session?${query.toString()}`);
|
response = await fetch(`https://api.weixin.qq.com/sns/jscode2session?${query.toString()}`);
|
||||||
} catch (error) {
|
} 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("微信登录服务暂时不可用");
|
throw new ServiceUnavailableException("微信登录服务暂时不可用");
|
||||||
}
|
}
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
|||||||
@@ -90,7 +90,10 @@ test("订单状态只能按定义的状态机流转", async () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
const bookings = new BookingService(prisma);
|
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(
|
await assert.rejects(
|
||||||
() => bookings.updateStatus(brandId, "booking-1", "completed"),
|
() => bookings.updateStatus(brandId, "booking-1", "completed"),
|
||||||
(error: unknown) => error instanceof BadRequestException,
|
(error: unknown) => error instanceof BadRequestException,
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
App({
|
App({
|
||||||
onLaunch() {
|
onLaunch() {
|
||||||
this.globalData = { apiBaseUrl: 'http://192.168.88.29:3001', brand: {} };
|
this.globalData = { apiBaseUrl: "http://192.168.88.29:3001", brand: {} };
|
||||||
},
|
},
|
||||||
globalData: {},
|
globalData: {},
|
||||||
});
|
});
|
||||||
+38
-7
@@ -1,9 +1,40 @@
|
|||||||
{
|
{
|
||||||
"pages": ["pages/index/index", "pages/services/index", "pages/booking/index", "pages/bookings/index"],
|
"pages": [
|
||||||
"window": { "navigationBarTitleText": "个人品牌", "navigationBarBackgroundColor": "#FBF7F1", "navigationBarTextStyle": "black", "backgroundColor": "#FBF7F1" },
|
"pages/index/index",
|
||||||
"tabBar": { "color": "#7A4A2B", "selectedColor": "#B54A2C", "backgroundColor": "#FFFFFF", "borderStyle": "white", "list": [
|
"pages/services/index",
|
||||||
{ "pagePath": "pages/index/index", "text": "首页", "iconPath": "assets/tab/home.png", "selectedIconPath": "assets/tab/home-selected.png" },
|
"pages/booking/index",
|
||||||
{ "pagePath": "pages/services/index", "text": "服务", "iconPath": "assets/tab/briefcase.png", "selectedIconPath": "assets/tab/briefcase-selected.png" },
|
"pages/bookings/index"
|
||||||
{ "pagePath": "pages/bookings/index", "text": "我的", "iconPath": "assets/tab/user.png", "selectedIconPath": "assets/tab/user-selected.png" }
|
],
|
||||||
] }
|
"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",
|
"name": "@personal-brand/miniapp",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"dependencies": { "@personal-brand/api-client": "workspace:*", "@personal-brand/types": "workspace:*" },
|
"dependencies": {
|
||||||
|
"@personal-brand/api-client": "workspace:*",
|
||||||
|
"@personal-brand/types": "workspace:*"
|
||||||
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "eslint src --ext .ts",
|
"lint": "eslint src --ext .ts",
|
||||||
"typecheck": "tsc -p tsconfig.json --noEmit",
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
||||||
|
|||||||
@@ -1,31 +1,92 @@
|
|||||||
const { request, customerRequest } = require('../../utils/request');
|
const { request, customerRequest } = require("../../utils/request");
|
||||||
const { getTemplate } = require('../../utils/templates');
|
const { getTemplate } = require("../../utils/templates");
|
||||||
Page({
|
Page({
|
||||||
data: { service: {}, form: {}, serviceId: '', quantity: 1, fulfillment: 'pickup', submitting: false, template: getTemplate('personal') },
|
data: {
|
||||||
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' })); },
|
service: {},
|
||||||
input(event) { this.setData({ ['form.' + event.currentTarget.dataset.key]: event.detail.value }); },
|
form: {},
|
||||||
chooseFulfillment(event) { this.setData({ fulfillment: event.currentTarget.dataset.value }); },
|
serviceId: "",
|
||||||
increase() { if (this.data.quantity < 50) this.setData({ quantity: this.data.quantity + 1 }); },
|
quantity: 1,
|
||||||
decrease() { if (this.data.quantity > 1) this.setData({ quantity: this.data.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() {
|
submit() {
|
||||||
const form = this.data.form;
|
const form = this.data.form;
|
||||||
if (!this.data.serviceId) return wx.showToast({ title: '请先选择服务', icon: 'none' });
|
if (!this.data.serviceId) return wx.showToast({ title: "请先选择服务", icon: "none" });
|
||||||
if (!form.customerName || !form.wechatId) return wx.showToast({ title: '请填写称呼和联系方式', icon: 'none' });
|
if (!form.customerName || !form.wechatId)
|
||||||
if (this.data.fulfillment === 'delivery' && !form.deliveryAddress) return wx.showToast({ title: '请填写' + this.data.template.locationLabel, icon: 'none' });
|
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 });
|
this.setData({ submitting: true });
|
||||||
const send = () => customerRequest('/customer/bookings', {
|
const send = () =>
|
||||||
method: 'POST',
|
customerRequest("/customer/bookings", {
|
||||||
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 }] },
|
method: "POST",
|
||||||
}).then(() => {
|
data: {
|
||||||
this.setData({ submitting: false });
|
requestType: this.data.template.requestType,
|
||||||
wx.showToast({ title: '预约已提交' });
|
customerName: form.customerName,
|
||||||
setTimeout(() => wx.navigateTo({ url: '/pages/bookings/index' }), 500);
|
wechatId: form.wechatId,
|
||||||
}).catch((error) => {
|
contactPreference: "wechat",
|
||||||
this.setData({ submitting: false });
|
fulfillmentType: this.data.fulfillment,
|
||||||
wx.showToast({ title: error.message || '提交失败', icon: 'none' });
|
deliveryAddress: form.deliveryAddress,
|
||||||
});
|
requestedTime: form.requestedTime,
|
||||||
const token = wx.getStorageSync('customerToken');
|
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();
|
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}
|
.page {
|
||||||
.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}
|
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 { request, customerRequest } = require("../../utils/request");
|
||||||
const { bookingViewModel } = require('../../utils/labels');
|
const { bookingViewModel } = require("../../utils/labels");
|
||||||
const { getTemplate } = require('../../utils/templates');
|
const { getTemplate } = require("../../utils/templates");
|
||||||
Page({
|
Page({
|
||||||
data: { loading: true, error: '', bookings: [], cancellingId: '', template: getTemplate('personal') },
|
data: {
|
||||||
onLoad() { this.load(); }, onShow() { this.load(); },
|
loading: true,
|
||||||
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 || '网络请求失败' })); },
|
error: "",
|
||||||
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' }); },
|
bookings: [],
|
||||||
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' }); }); } }); }
|
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}
|
.page {
|
||||||
.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}
|
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 { request } = require("../../utils/request");
|
||||||
const config = require('../../utils/config');
|
const config = require("../../utils/config");
|
||||||
const { getTemplate } = require('../../utils/templates');
|
const { getTemplate } = require("../../utils/templates");
|
||||||
|
|
||||||
Page({
|
Page({
|
||||||
data: { loading: true, error: '', brand: {}, services: [], copy: {} },
|
data: { loading: true, error: "", brand: {}, services: [], copy: {} },
|
||||||
onLoad() { this.load(); },
|
onLoad() {
|
||||||
|
this.load();
|
||||||
|
},
|
||||||
load() {
|
load() {
|
||||||
this.setData({ loading: true, error: '' });
|
this.setData({ loading: true, error: "" });
|
||||||
Promise.all([request('/public/brand'), request('/public/services')]).then(([brand, services]) => {
|
Promise.all([request("/public/brand"), request("/public/services")])
|
||||||
getApp().globalData.brand = brand;
|
.then(([brand, services]) => {
|
||||||
wx.setNavigationBarTitle({ title: brand.name || '个人品牌' });
|
getApp().globalData.brand = brand;
|
||||||
const copy = getTemplate(brand.templateKey);
|
wx.setNavigationBarTitle({ title: brand.name || "个人品牌" });
|
||||||
this.setData({ brand: { ...brand, coverUrl: brand.coverUrl || '/assets/brand/home-hero.jpg' }, services, copy, loading: false });
|
const copy = getTemplate(brand.templateKey);
|
||||||
}).catch(() => this.setData({ loading: false, error: '暂时无法加载内容' }));
|
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 { request } = require("../../utils/request");
|
||||||
const { getTemplate } = require('../../utils/templates');
|
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) }); } });
|
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}
|
.page {
|
||||||
.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)}
|
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",
|
"appid": "wxd75d946d6978d183",
|
||||||
"editorSetting": {}
|
"editorSetting": {}
|
||||||
}
|
}
|
||||||
@@ -2,16 +2,36 @@ import { ApiClient, type CreateBookingInput, type FetchLike } from "@personal-br
|
|||||||
import { HTTP_STATUS } from "@personal-brand/types";
|
import { HTTP_STATUS } from "@personal-brand/types";
|
||||||
|
|
||||||
export interface MiniappRequestAdapter {
|
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 fetcher: FetchLike = async (url, init) => {
|
||||||
const response = await adapter.request({ url, method: init?.method ?? "GET", header: init?.headers ?? {}, ...(init?.body ? { data: init.body } : {}) });
|
const response = await adapter.request({
|
||||||
return { status: response.statusCode, ok: response.statusCode >= HTTP_STATUS.OK && response.statusCode < HTTP_STATUS.BAD_REQUEST, json: () => Promise.resolve(response.data) };
|
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 } : {}) });
|
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";
|
export const miniappName = "personal-brand-miniapp";
|
||||||
@@ -1,6 +1,10 @@
|
|||||||
const app = getApp();
|
const app = getApp();
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
get apiBaseUrl() { return app.globalData.apiBaseUrl; },
|
get apiBaseUrl() {
|
||||||
get brand() { return app.globalData.brand || {}; },
|
return app.globalData.apiBaseUrl;
|
||||||
|
},
|
||||||
|
get brand() {
|
||||||
|
return app.globalData.brand || {};
|
||||||
|
},
|
||||||
};
|
};
|
||||||
@@ -1,12 +1,21 @@
|
|||||||
const STATUS_LABELS = { received: '待确认', contacting: '沟通中', confirmed: '已确认', completed: '已完成', cancelled: '已取消' };
|
const STATUS_LABELS = {
|
||||||
const FULFILLMENT_LABELS = { pickup: '自取', delivery: '配送' };
|
received: "待确认",
|
||||||
|
contacting: "沟通中",
|
||||||
|
confirmed: "已确认",
|
||||||
|
completed: "已完成",
|
||||||
|
cancelled: "已取消",
|
||||||
|
};
|
||||||
|
const FULFILLMENT_LABELS = { pickup: "自取", delivery: "配送" };
|
||||||
|
|
||||||
function bookingViewModel(item, template) {
|
function bookingViewModel(item, template) {
|
||||||
return {
|
return {
|
||||||
...item,
|
...item,
|
||||||
statusLabel: STATUS_LABELS[item.status] || '未知状态',
|
statusLabel: STATUS_LABELS[item.status] || "未知状态",
|
||||||
fulfillmentLabel: template?.modeLabels?.[item.fulfillmentType] || FULFILLMENT_LABELS[item.fulfillmentType] || '待确认',
|
fulfillmentLabel:
|
||||||
serviceName: item.service?.name || item.items?.[0]?.serviceNameSnapshot || '未命名服务',
|
template?.modeLabels?.[item.fulfillmentType] ||
|
||||||
|
FULFILLMENT_LABELS[item.fulfillmentType] ||
|
||||||
|
"待确认",
|
||||||
|
serviceName: item.service?.name || item.items?.[0]?.serviceNameSnapshot || "未命名服务",
|
||||||
quantityLabel: `${item.items?.[0]?.quantity || 1} 份`,
|
quantityLabel: `${item.items?.[0]?.quantity || 1} 份`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
const config = require('./config');
|
const config = require("./config");
|
||||||
|
|
||||||
function request(path, options = {}) {
|
function request(path, options = {}) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
wx.request({
|
wx.request({
|
||||||
url: config.apiBaseUrl + path,
|
url: config.apiBaseUrl + path,
|
||||||
method: options.method || 'GET',
|
method: options.method || "GET",
|
||||||
header: { accept: 'application/json', ...(options.header || {}) },
|
header: { accept: "application/json", ...(options.header || {}) },
|
||||||
...(options.data === undefined ? {} : { data: options.data }),
|
...(options.data === undefined ? {} : { data: options.data }),
|
||||||
success: (response) => {
|
success: (response) => {
|
||||||
if (response.statusCode >= 200 && response.statusCode < 300) return resolve(response.data);
|
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 }));
|
reject(Object.assign(new Error(error), { statusCode: response.statusCode, response }));
|
||||||
},
|
},
|
||||||
fail: reject,
|
fail: reject,
|
||||||
@@ -18,8 +18,11 @@ function request(path, options = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function customerRequest(path, options = {}) {
|
function customerRequest(path, options = {}) {
|
||||||
const token = wx.getStorageSync('customerToken');
|
const token = wx.getStorageSync("customerToken");
|
||||||
return request(path, { ...options, header: { ...(options.header || {}), Authorization: 'Bearer ' + token } });
|
return request(path, {
|
||||||
|
...options,
|
||||||
|
header: { ...(options.header || {}), Authorization: "Bearer " + token },
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { request, customerRequest };
|
module.exports = { request, customerRequest };
|
||||||
@@ -1,6 +1,78 @@
|
|||||||
const TEMPLATES = {
|
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: '提交预约' },
|
food: {
|
||||||
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: '提交需求' },
|
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 };
|
module.exports = { getTemplate, TEMPLATES };
|
||||||
+53
-53
@@ -10,34 +10,34 @@ paths:
|
|||||||
get:
|
get:
|
||||||
operationId: getHealth
|
operationId: getHealth
|
||||||
responses:
|
responses:
|
||||||
'200':
|
"200":
|
||||||
description: API health status
|
description: API health status
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/Health'
|
$ref: "#/components/schemas/Health"
|
||||||
/public/brand:
|
/public/brand:
|
||||||
get:
|
get:
|
||||||
operationId: getPublicBrand
|
operationId: getPublicBrand
|
||||||
responses:
|
responses:
|
||||||
'200':
|
"200":
|
||||||
description: Public brand profile
|
description: Public brand profile
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/BrandProfile'
|
$ref: "#/components/schemas/BrandProfile"
|
||||||
/public/services:
|
/public/services:
|
||||||
get:
|
get:
|
||||||
operationId: listPublicServices
|
operationId: listPublicServices
|
||||||
responses:
|
responses:
|
||||||
'200':
|
"200":
|
||||||
description: Enabled public services
|
description: Enabled public services
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
$ref: '#/components/schemas/PublicService'
|
$ref: "#/components/schemas/PublicService"
|
||||||
/customer/session/wechat:
|
/customer/session/wechat:
|
||||||
post:
|
post:
|
||||||
operationId: createCustomerSession
|
operationId: createCustomerSession
|
||||||
@@ -52,25 +52,25 @@ paths:
|
|||||||
code:
|
code:
|
||||||
type: string
|
type: string
|
||||||
responses:
|
responses:
|
||||||
'201':
|
"201":
|
||||||
description: Customer session token
|
description: Customer session token
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/TokenResponse'
|
$ref: "#/components/schemas/TokenResponse"
|
||||||
/customer/bookings:
|
/customer/bookings:
|
||||||
get:
|
get:
|
||||||
operationId: listCustomerBookings
|
operationId: listCustomerBookings
|
||||||
security: [bearerAuth: []]
|
security: [bearerAuth: []]
|
||||||
responses:
|
responses:
|
||||||
'200':
|
"200":
|
||||||
description: Current customer's bookings
|
description: Current customer's bookings
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
$ref: '#/components/schemas/Booking'
|
$ref: "#/components/schemas/Booking"
|
||||||
post:
|
post:
|
||||||
operationId: createCustomerBooking
|
operationId: createCustomerBooking
|
||||||
security: [bearerAuth: []]
|
security: [bearerAuth: []]
|
||||||
@@ -79,27 +79,27 @@ paths:
|
|||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/CreateBooking'
|
$ref: "#/components/schemas/CreateBooking"
|
||||||
responses:
|
responses:
|
||||||
'201':
|
"201":
|
||||||
description: Created booking summary
|
description: Created booking summary
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/BookingSummary'
|
$ref: "#/components/schemas/BookingSummary"
|
||||||
/customer/bookings/{id}/cancel:
|
/customer/bookings/{id}/cancel:
|
||||||
post:
|
post:
|
||||||
operationId: cancelCustomerBooking
|
operationId: cancelCustomerBooking
|
||||||
security: [bearerAuth: []]
|
security: [bearerAuth: []]
|
||||||
parameters:
|
parameters:
|
||||||
- $ref: '#/components/parameters/BookingId'
|
- $ref: "#/components/parameters/BookingId"
|
||||||
responses:
|
responses:
|
||||||
'201':
|
"201":
|
||||||
description: Cancelled booking
|
description: Cancelled booking
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/Booking'
|
$ref: "#/components/schemas/Booking"
|
||||||
/admin/session/login:
|
/admin/session/login:
|
||||||
post:
|
post:
|
||||||
operationId: createAdminSession
|
operationId: createAdminSession
|
||||||
@@ -108,14 +108,14 @@ paths:
|
|||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/AdminLogin'
|
$ref: "#/components/schemas/AdminLogin"
|
||||||
responses:
|
responses:
|
||||||
'201':
|
"201":
|
||||||
description: Admin session token
|
description: Admin session token
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/AdminTokenResponse'
|
$ref: "#/components/schemas/AdminTokenResponse"
|
||||||
/admin/bookings:
|
/admin/bookings:
|
||||||
get:
|
get:
|
||||||
operationId: listAdminBookings
|
operationId: listAdminBookings
|
||||||
@@ -124,7 +124,7 @@ paths:
|
|||||||
- in: query
|
- in: query
|
||||||
name: status
|
name: status
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/BookingStatus'
|
$ref: "#/components/schemas/BookingStatus"
|
||||||
- in: query
|
- in: query
|
||||||
name: unreadOnly
|
name: unreadOnly
|
||||||
schema:
|
schema:
|
||||||
@@ -134,20 +134,20 @@ paths:
|
|||||||
schema:
|
schema:
|
||||||
type: string
|
type: string
|
||||||
responses:
|
responses:
|
||||||
'200':
|
"200":
|
||||||
description: Admin booking list
|
description: Admin booking list
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
$ref: '#/components/schemas/Booking'
|
$ref: "#/components/schemas/Booking"
|
||||||
/admin/bookings/unread-count:
|
/admin/bookings/unread-count:
|
||||||
get:
|
get:
|
||||||
operationId: getAdminUnreadBookingCount
|
operationId: getAdminUnreadBookingCount
|
||||||
security: [bearerAuth: []]
|
security: [bearerAuth: []]
|
||||||
responses:
|
responses:
|
||||||
'200':
|
"200":
|
||||||
description: Number of unread bookings
|
description: Number of unread bookings
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
@@ -161,55 +161,55 @@ paths:
|
|||||||
operationId: getAdminBooking
|
operationId: getAdminBooking
|
||||||
security: [bearerAuth: []]
|
security: [bearerAuth: []]
|
||||||
parameters:
|
parameters:
|
||||||
- $ref: '#/components/parameters/BookingId'
|
- $ref: "#/components/parameters/BookingId"
|
||||||
responses:
|
responses:
|
||||||
'200':
|
"200":
|
||||||
description: Admin booking detail
|
description: Admin booking detail
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/Booking'
|
$ref: "#/components/schemas/Booking"
|
||||||
/admin/bookings/{id}/status:
|
/admin/bookings/{id}/status:
|
||||||
post:
|
post:
|
||||||
operationId: updateAdminBookingStatus
|
operationId: updateAdminBookingStatus
|
||||||
security: [bearerAuth: []]
|
security: [bearerAuth: []]
|
||||||
parameters:
|
parameters:
|
||||||
- $ref: '#/components/parameters/BookingId'
|
- $ref: "#/components/parameters/BookingId"
|
||||||
requestBody:
|
requestBody:
|
||||||
required: true
|
required: true
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/UpdateBookingStatus'
|
$ref: "#/components/schemas/UpdateBookingStatus"
|
||||||
responses:
|
responses:
|
||||||
'201':
|
"201":
|
||||||
description: Updated booking
|
description: Updated booking
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/Booking'
|
$ref: "#/components/schemas/Booking"
|
||||||
/admin/bookings/{id}/read:
|
/admin/bookings/{id}/read:
|
||||||
post:
|
post:
|
||||||
operationId: markAdminBookingRead
|
operationId: markAdminBookingRead
|
||||||
security: [bearerAuth: []]
|
security: [bearerAuth: []]
|
||||||
parameters:
|
parameters:
|
||||||
- $ref: '#/components/parameters/BookingId'
|
- $ref: "#/components/parameters/BookingId"
|
||||||
responses:
|
responses:
|
||||||
'201':
|
"201":
|
||||||
description: Updated booking
|
description: Updated booking
|
||||||
/admin/bookings/tags:
|
/admin/bookings/tags:
|
||||||
get:
|
get:
|
||||||
operationId: listAdminTags
|
operationId: listAdminTags
|
||||||
security: [bearerAuth: []]
|
security: [bearerAuth: []]
|
||||||
responses:
|
responses:
|
||||||
'200':
|
"200":
|
||||||
description: Enabled tags
|
description: Enabled tags
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
$ref: '#/components/schemas/Tag'
|
$ref: "#/components/schemas/Tag"
|
||||||
post:
|
post:
|
||||||
operationId: createAdminTag
|
operationId: createAdminTag
|
||||||
security: [bearerAuth: []]
|
security: [bearerAuth: []]
|
||||||
@@ -223,12 +223,12 @@ paths:
|
|||||||
properties:
|
properties:
|
||||||
name: { type: string, maxLength: 24 }
|
name: { type: string, maxLength: 24 }
|
||||||
responses:
|
responses:
|
||||||
'201':
|
"201":
|
||||||
description: Created tag
|
description: Created tag
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/Tag'
|
$ref: "#/components/schemas/Tag"
|
||||||
components:
|
components:
|
||||||
securitySchemes:
|
securitySchemes:
|
||||||
bearerAuth:
|
bearerAuth:
|
||||||
@@ -253,13 +253,13 @@ components:
|
|||||||
properties:
|
properties:
|
||||||
id: { type: string, format: uuid }
|
id: { type: string, format: uuid }
|
||||||
name: { type: string }
|
name: { type: string }
|
||||||
tagline: { type: [string, 'null'] }
|
tagline: { type: [string, "null"] }
|
||||||
description: { type: [string, 'null'] }
|
description: { type: [string, "null"] }
|
||||||
avatarUrl: { type: [string, 'null'], format: uri }
|
avatarUrl: { type: [string, "null"], format: uri }
|
||||||
coverUrl: { type: [string, 'null'], format: uri }
|
coverUrl: { type: [string, "null"], format: uri }
|
||||||
hours: { type: [string, 'null'] }
|
hours: { type: [string, "null"] }
|
||||||
address: { type: [string, 'null'] }
|
address: { type: [string, "null"] }
|
||||||
deliveryNote: { type: [string, 'null'] }
|
deliveryNote: { type: [string, "null"] }
|
||||||
PublicService:
|
PublicService:
|
||||||
type: object
|
type: object
|
||||||
required: [id, name, description, bookingEnabled]
|
required: [id, name, description, bookingEnabled]
|
||||||
@@ -267,9 +267,9 @@ components:
|
|||||||
id: { type: string, format: uuid }
|
id: { type: string, format: uuid }
|
||||||
name: { type: string }
|
name: { type: string }
|
||||||
description: { type: string }
|
description: { type: string }
|
||||||
coverUrl: { type: [string, 'null'], format: uri }
|
coverUrl: { type: [string, "null"], format: uri }
|
||||||
priceText: { type: [string, 'null'] }
|
priceText: { type: [string, "null"] }
|
||||||
priceAmount: { type: [integer, 'null'], minimum: 0 }
|
priceAmount: { type: [integer, "null"], minimum: 0 }
|
||||||
bookingEnabled: { type: boolean }
|
bookingEnabled: { type: boolean }
|
||||||
BookingStatus:
|
BookingStatus:
|
||||||
type: string
|
type: string
|
||||||
@@ -298,23 +298,23 @@ components:
|
|||||||
extraData: { type: object, additionalProperties: true }
|
extraData: { type: object, additionalProperties: true }
|
||||||
items:
|
items:
|
||||||
type: array
|
type: array
|
||||||
items: { $ref: '#/components/schemas/BookingItemInput' }
|
items: { $ref: "#/components/schemas/BookingItemInput" }
|
||||||
BookingSummary:
|
BookingSummary:
|
||||||
type: object
|
type: object
|
||||||
required: [bookingNo, status, estimatedAmount, createdAt]
|
required: [bookingNo, status, estimatedAmount, createdAt]
|
||||||
properties:
|
properties:
|
||||||
bookingNo: { type: string }
|
bookingNo: { type: string }
|
||||||
status: { $ref: '#/components/schemas/BookingStatus' }
|
status: { $ref: "#/components/schemas/BookingStatus" }
|
||||||
estimatedAmount: { type: [integer, 'null'] }
|
estimatedAmount: { type: [integer, "null"] }
|
||||||
createdAt: { type: string, format: date-time }
|
createdAt: { type: string, format: date-time }
|
||||||
Booking:
|
Booking:
|
||||||
allOf:
|
allOf:
|
||||||
- $ref: '#/components/schemas/BookingSummary'
|
- $ref: "#/components/schemas/BookingSummary"
|
||||||
- type: object
|
- type: object
|
||||||
properties:
|
properties:
|
||||||
id: { type: string, format: uuid }
|
id: { type: string, format: uuid }
|
||||||
customerName: { type: string }
|
customerName: { type: string }
|
||||||
adminNote: { type: [string, 'null'] }
|
adminNote: { type: [string, "null"] }
|
||||||
AdminLogin:
|
AdminLogin:
|
||||||
type: object
|
type: object
|
||||||
required: [username, password]
|
required: [username, password]
|
||||||
@@ -328,7 +328,7 @@ components:
|
|||||||
token: { type: string }
|
token: { type: string }
|
||||||
AdminTokenResponse:
|
AdminTokenResponse:
|
||||||
allOf:
|
allOf:
|
||||||
- $ref: '#/components/schemas/TokenResponse'
|
- $ref: "#/components/schemas/TokenResponse"
|
||||||
- type: object
|
- type: object
|
||||||
required: [displayName]
|
required: [displayName]
|
||||||
properties:
|
properties:
|
||||||
@@ -337,7 +337,7 @@ components:
|
|||||||
type: object
|
type: object
|
||||||
required: [status]
|
required: [status]
|
||||||
properties:
|
properties:
|
||||||
status: { $ref: '#/components/schemas/BookingStatus' }
|
status: { $ref: "#/components/schemas/BookingStatus" }
|
||||||
adminNote: { type: string }
|
adminNote: { type: string }
|
||||||
Tag:
|
Tag:
|
||||||
type: object
|
type: object
|
||||||
|
|||||||
@@ -2,7 +2,12 @@
|
|||||||
"name": "@personal-brand/api-client",
|
"name": "@personal-brand/api-client",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"exports": { ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" } },
|
"exports": {
|
||||||
|
".": {
|
||||||
|
"types": "./dist/index.d.ts",
|
||||||
|
"import": "./dist/index.js"
|
||||||
|
}
|
||||||
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc -p tsconfig.json",
|
"build": "tsc -p tsconfig.json",
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ function response(body: unknown, status = 200): FetchResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test("客户端发送认证头、查询参数和 JSON 请求体", async () => {
|
test("客户端发送认证头、查询参数和 JSON 请求体", async () => {
|
||||||
const calls: Array<{ url: string; init?: { headers?: Record<string, string>; body?: string } }> = [];
|
const calls: Array<{ url: string; init?: { headers?: Record<string, string>; body?: string } }> =
|
||||||
|
[];
|
||||||
const client = new ApiClient({
|
const client = new ApiClient({
|
||||||
baseUrl: "http://api.test/",
|
baseUrl: "http://api.test/",
|
||||||
token: "token-1",
|
token: "token-1",
|
||||||
@@ -18,7 +19,10 @@ test("客户端发送认证头、查询参数和 JSON 请求体", async () => {
|
|||||||
});
|
});
|
||||||
await client.listAdminBookings({ status: "received", unreadOnly: true, tagId: "tag/1" });
|
await client.listAdminBookings({ status: "received", unreadOnly: true, tagId: "tag/1" });
|
||||||
await client.createAdminTag("重点");
|
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[0]?.init?.headers?.authorization, "Bearer token-1");
|
||||||
assert.equal(calls[1]?.init?.body, JSON.stringify({ name: "重点" }));
|
assert.equal(calls[1]?.init?.body, JSON.stringify({ name: "重点" }));
|
||||||
});
|
});
|
||||||
@@ -26,7 +30,11 @@ test("客户端发送认证头、查询参数和 JSON 请求体", async () => {
|
|||||||
test("客户端将统一错误响应转换为 ApiClientError", async () => {
|
test("客户端将统一错误响应转换为 ApiClientError", async () => {
|
||||||
const client = new ApiClient({
|
const client = new ApiClient({
|
||||||
baseUrl: "http://api.test",
|
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(
|
await assert.rejects(
|
||||||
() => client.getAdminUnreadCount(),
|
() => client.getAdminUnreadCount(),
|
||||||
|
|||||||
Reference in new issue
Block a user