feat: 增加行业模板注册与切换能力
This commit is contained in:
1 parent
3c7ce2a8fa
commit
5b831b6740
7 files changed
+18
-6
No files matched your search
@@ -2,7 +2,7 @@ import { IsArray, IsBoolean, IsIn, IsInt, IsOptional, IsString, Max, Min } from
|
||||
|
||||
export class UpdateBrandDto {
|
||||
@IsOptional() @IsString() name?: string;
|
||||
@IsOptional() @IsString() templateKey?: string;
|
||||
@IsOptional() @IsIn(["food", "personal"]) templateKey?: "food" | "personal";
|
||||
@IsOptional() @IsString() tagline?: string;
|
||||
@IsOptional() @IsString() description?: string;
|
||||
@IsOptional() @IsString() avatarUrl?: string;
|
||||
|
||||
@@ -107,10 +107,11 @@ test("admin can read and update brand and service configuration", async () => {
|
||||
const updatedBrand = await request("/admin/config/brand", {
|
||||
method: "PATCH",
|
||||
headers: { authorization: `Bearer ${adminToken}` },
|
||||
payload: { description: "集成测试品牌简介", contactPhone: "13800000000" },
|
||||
payload: { description: "集成测试品牌简介", contactPhone: "13800000000", templateKey: "personal" },
|
||||
});
|
||||
assert.equal(updatedBrand.statusCode, 200);
|
||||
assert.equal(JSON.parse(updatedBrand.body).description, "集成测试品牌简介");
|
||||
assert.equal(JSON.parse(updatedBrand.body).templateKey, "personal");
|
||||
|
||||
const updatedService = await request(`/admin/config/services/${serviceBefore.id}`, {
|
||||
method: "PATCH",
|
||||
@@ -121,7 +122,7 @@ test("admin can read and update brand and service configuration", async () => {
|
||||
assert.equal(JSON.parse(updatedService.body).priceText, "集成测试价格");
|
||||
assert.equal(JSON.parse(updatedService.body).sortOrder, 99);
|
||||
} finally {
|
||||
await prisma.brandProfile.update({ where: { id: brandId }, data: { description: brandBefore.description, contactPhone: brandBefore.contactPhone } });
|
||||
await prisma.brandProfile.update({ where: { id: brandId }, data: { description: brandBefore.description, contactPhone: brandBefore.contactPhone, templateKey: brandBefore.templateKey } });
|
||||
await prisma.service.update({ where: { id: serviceBefore.id }, data: { priceText: serviceBefore.priceText, sortOrder: serviceBefore.sortOrder } });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const { request } = require('../../utils/request');
|
||||
const config = require('../../utils/config');
|
||||
const { getTemplate } = require('../../utils/templates');
|
||||
|
||||
Page({
|
||||
data: { loading: true, error: '', brand: {}, services: [], copy: {} },
|
||||
@@ -9,7 +10,7 @@ Page({
|
||||
Promise.all([request('/public/brand'), request('/public/services')]).then(([brand, services]) => {
|
||||
getApp().globalData.brand = brand;
|
||||
wx.setNavigationBarTitle({ title: brand.name || '个人品牌' });
|
||||
const copy = brand.templateKey === 'food' ? { hero: '今天吃什么', heroSub: '现做家常饭', about: '品牌简介', description: '个人经营的家常小灶,套餐现做,也可预约小型聚餐和私厨定制。', primary: '预约套餐', secondary: '咨询私厨', timeLabel: '营业时间', time: '11:00—20:00', addressLabel: '摊位地址', address: '校园路社区便民点 12 号', noteLabel: '配送说明', note: '满 30 元周边配送,也可自取' } : { hero: brand.name || '个人品牌', heroSub: brand.tagline || '把专业能力,变成值得信赖的体验', about: '关于我', description: '这里展示你的专业背景、工作方式与品牌理念。', primary: '查看服务', secondary: '发起咨询', timeLabel: '服务时间', time: '工作日 10:00—18:00', addressLabel: '所在位置', address: '线上 / 线下均可沟通', noteLabel: '合作说明', note: '提交需求后,我会尽快与你联系' };
|
||||
const copy = getTemplate(brand.templateKey);
|
||||
this.setData({ brand, services, copy, loading: false });
|
||||
}).catch(() => this.setData({ loading: false, error: '暂时无法加载内容' }));
|
||||
},
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
const { request } = require('../../utils/request');
|
||||
Page({ data: { loading: true, error: '', services: [], filtered: [], category: 'package', labels: {} }, onLoad() { Promise.all([request('/public/services'), request('/public/brand')]).then(([services, brand]) => { const labels = brand.templateKey === 'food' ? { sub: '今日可订', first: '普通套餐', firstSub: '日常家常饭', second: '私厨服务', secondSub: '聚餐定制', available: '今日可订', unavailable: '暂不可订', empty: '暂无可订服务' } : { sub: '可咨询', first: '标准服务', firstSub: '清晰的服务方案', second: '定制合作', secondSub: '按需求沟通', available: '可咨询', unavailable: '暂不可用', empty: '暂无可咨询服务' }; this.setData({ services, labels, filtered: services.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 { 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); this.setData({ services, labels, filtered: services.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) }); } });
|
||||
@@ -0,0 +1,6 @@
|
||||
const TEMPLATES = {
|
||||
food: { 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: '暂无可订服务' },
|
||||
personal: { hero: '个人品牌', heroSub: '把专业能力,变成值得信赖的体验', about: '关于我', description: '这里展示你的专业背景、工作方式与品牌理念。', primary: '查看服务', secondary: '发起咨询', timeLabel: '服务时间', time: '工作日 10:00—18:00', addressLabel: '所在位置', address: '线上 / 线下均可沟通', noteLabel: '合作说明', note: '提交需求后,我会尽快与你联系', serviceSub: '可咨询', first: '标准服务', firstSub: '清晰的服务方案', second: '定制合作', secondSub: '按需求沟通', available: '可咨询', unavailable: '暂不可用', empty: '暂无可咨询服务' },
|
||||
};
|
||||
function getTemplate(key) { return TEMPLATES[key] || TEMPLATES.personal; }
|
||||
module.exports = { getTemplate, TEMPLATES };
|
||||
@@ -4,13 +4,14 @@ import type {
|
||||
ContactPreference,
|
||||
FulfillmentType,
|
||||
PublicService,
|
||||
BrandTemplateKey,
|
||||
} from "@personal-brand/types";
|
||||
export type { BookingStatus } from "@personal-brand/types";
|
||||
|
||||
export interface BrandProfile {
|
||||
id: string;
|
||||
name: string;
|
||||
templateKey: string;
|
||||
templateKey: BrandTemplateKey;
|
||||
tagline: string | null;
|
||||
description: string | null;
|
||||
avatarUrl: string | null;
|
||||
|
||||
@@ -3,6 +3,8 @@ export type BookingRequestType = "package" | "private_chef";
|
||||
export type ContactPreference = "wechat" | "phone" | "none";
|
||||
export type FulfillmentType = "pickup" | "delivery";
|
||||
export type OrderStatus = BookingStatus;
|
||||
export type BrandTemplateKey = "food" | "personal";
|
||||
export const BRAND_TEMPLATE = { FOOD: "food", PERSONAL: "personal" } as const satisfies Record<Uppercase<BrandTemplateKey>, BrandTemplateKey>;
|
||||
|
||||
export const HTTP_STATUS = {
|
||||
OK: 200,
|
||||
|
||||
Reference in new issue
Block a user