From 3c7ce2a8faaaffa072d9cbee92e83d89d8f45cc6 Mon Sep 17 00:00:00 2001 From: que01 Date: Sat, 19 Sep 2026 12:26:29 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=BC=95=E5=85=A5=E5=93=81?= =?UTF-8?q?=E7=89=8C=E8=A1=8C=E4=B8=9A=E6=A8=A1=E6=9D=BF=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20260919122000_add_brand_template/migration.sql | 1 + apps/api/prisma/schema.prisma | 1 + apps/api/prisma/seed.ts | 1 + apps/api/src/admin.dto.ts | 1 + apps/api/src/main.ts | 1 + apps/miniapp/pages/index/index.js | 5 +++-- apps/miniapp/pages/index/index.wxml | 8 ++++---- apps/miniapp/pages/services/index.js | 2 +- apps/miniapp/pages/services/index.wxml | 2 +- packages/api-client/src/index.ts | 1 + 10 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 apps/api/prisma/migrations/20260919122000_add_brand_template/migration.sql diff --git a/apps/api/prisma/migrations/20260919122000_add_brand_template/migration.sql b/apps/api/prisma/migrations/20260919122000_add_brand_template/migration.sql new file mode 100644 index 0000000..0eee2f4 --- /dev/null +++ b/apps/api/prisma/migrations/20260919122000_add_brand_template/migration.sql @@ -0,0 +1 @@ +ALTER TABLE "BrandProfile" ADD COLUMN "templateKey" TEXT NOT NULL DEFAULT 'food'; diff --git a/apps/api/prisma/schema.prisma b/apps/api/prisma/schema.prisma index 4277511..c6980fe 100644 --- a/apps/api/prisma/schema.prisma +++ b/apps/api/prisma/schema.prisma @@ -34,6 +34,7 @@ enum FulfillmentType { model BrandProfile { id String @id @default(uuid()) name String + templateKey String @default("food") tagline String? description String? avatarUrl String? diff --git a/apps/api/prisma/seed.ts b/apps/api/prisma/seed.ts index bf1811a..1da8fa7 100644 --- a/apps/api/prisma/seed.ts +++ b/apps/api/prisma/seed.ts @@ -10,6 +10,7 @@ async function main(): Promise { create: { id: "00000000-0000-0000-0000-000000000001", name: "阿成家常菜", + templateKey: "food", tagline: "现做家常套餐,也为小型聚餐定制一桌热饭菜", description: "每天认真做好一顿家常饭。", hours: "周一至周六 10:30-20:00", diff --git a/apps/api/src/admin.dto.ts b/apps/api/src/admin.dto.ts index b306c7d..3135063 100644 --- a/apps/api/src/admin.dto.ts +++ b/apps/api/src/admin.dto.ts @@ -2,6 +2,7 @@ import { IsArray, IsBoolean, IsIn, IsInt, IsOptional, IsString, Max, Min } from export class UpdateBrandDto { @IsOptional() @IsString() name?: string; + @IsOptional() @IsString() templateKey?: string; @IsOptional() @IsString() tagline?: string; @IsOptional() @IsString() description?: string; @IsOptional() @IsString() avatarUrl?: string; diff --git a/apps/api/src/main.ts b/apps/api/src/main.ts index 370cc39..cfa31d0 100644 --- a/apps/api/src/main.ts +++ b/apps/api/src/main.ts @@ -48,6 +48,7 @@ export class PublicController { select: { id: true, name: true, + templateKey: true, tagline: true, description: true, avatarUrl: true, diff --git a/apps/miniapp/pages/index/index.js b/apps/miniapp/pages/index/index.js index 7e47cd5..9c68245 100644 --- a/apps/miniapp/pages/index/index.js +++ b/apps/miniapp/pages/index/index.js @@ -2,14 +2,15 @@ const { request } = require('../../utils/request'); const config = require('../../utils/config'); Page({ - data: { loading: true, error: '', brand: {}, services: [] }, + 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 || '个人品牌' }); - this.setData({ brand, services, loading: false }); + 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: '提交需求后,我会尽快与你联系' }; + this.setData({ brand, services, copy, loading: false }); }).catch(() => this.setData({ loading: false, error: '暂时无法加载内容' })); }, selectService(event) { wx.navigateTo({ url: '/pages/booking/index?serviceId=' + encodeURIComponent(event.currentTarget.dataset.id) }); }, diff --git a/apps/miniapp/pages/index/index.wxml b/apps/miniapp/pages/index/index.wxml index fc8f493..dbaab8d 100644 --- a/apps/miniapp/pages/index/index.wxml +++ b/apps/miniapp/pages/index/index.wxml @@ -3,10 +3,10 @@ 加载中... {{error}} - {{brand.name || '个人品牌'}}{{brand.tagline || '把专业能力,变成值得信赖的体验'}} - 关于我{{brand.description || '这里展示你的专业背景、工作方式与品牌理念。'}} - 服务时间{{brand.hours || '工作日 10:00—18:00'}}›所在位置{{brand.address || '线上 / 线下均可沟通'}}合作说明{{brand.deliveryNote || '提交需求后,我会尽快与你联系'}} - + {{copy.hero}}{{copy.heroSub}} + {{copy.about}}{{brand.description || copy.description}} + {{copy.timeLabel}}{{brand.hours || copy.time}}›{{copy.addressLabel}}{{brand.address || copy.address}}{{copy.noteLabel}}{{brand.deliveryNote || copy.note}} + 今日服务 {{item.name}}{{item.description}}{{item.priceText}} diff --git a/apps/miniapp/pages/services/index.js b/apps/miniapp/pages/services/index.js index c9d8bb3..9718252 100644 --- a/apps/miniapp/pages/services/index.js +++ b/apps/miniapp/pages/services/index.js @@ -1,2 +1,2 @@ const { request } = require('../../utils/request'); -Page({ data: { loading: true, error: '', services: [], filtered: [], category: 'package' }, onLoad() { request('/public/services').then((services) => this.setData({ services, 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) }); } }); +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) }); } }); diff --git a/apps/miniapp/pages/services/index.wxml b/apps/miniapp/pages/services/index.wxml index 6195147..0c306b1 100644 --- a/apps/miniapp/pages/services/index.wxml +++ b/apps/miniapp/pages/services/index.wxml @@ -1 +1 @@ -服务列表可咨询● 标准服务清晰的服务方案● 定制合作按需求沟通加载中...{{error}}暂无可咨询服务{{item.name}}{{item.bookingEnabled ? '可咨询' : '暂不可用'}}{{item.description}}{{item.priceText || '沟通报价'}} +服务列表{{labels.sub}}● {{labels.first}}{{labels.firstSub}}● {{labels.second}}{{labels.secondSub}}加载中...{{error}}{{labels.empty}}{{item.name}}{{item.bookingEnabled ? labels.available : labels.unavailable}}{{item.description}}{{item.priceText || '面议'}} diff --git a/packages/api-client/src/index.ts b/packages/api-client/src/index.ts index dabd767..38a62f1 100644 --- a/packages/api-client/src/index.ts +++ b/packages/api-client/src/index.ts @@ -10,6 +10,7 @@ export type { BookingStatus } from "@personal-brand/types"; export interface BrandProfile { id: string; name: string; + templateKey: string; tagline: string | null; description: string | null; avatarUrl: string | null;