feat: 接入小程序品牌组件基础层

This commit is contained in:
que01 committed 2026-09-20 11:33:58 +08:00
1 parent 8fd399f4c2
commit 1a9dc426f6
27 files changed
+158 -9

No files matched your search

+7
View File
@@ -0,0 +1,7 @@
@import "styles/tokens.wxss";
page {
background: var(--brand-color-bg);
color: var(--brand-color-text);
font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif;
}
@@ -0,0 +1,15 @@
Component({
options: { addGlobalClass: true },
properties: {
theme: { type: String, value: "primary" },
size: { type: String, value: "large" },
disabled: Boolean,
loading: Boolean,
block: { type: Boolean, value: true },
},
methods: {
handleTap(event) {
if (!this.data.disabled && !this.data.loading) this.triggerEvent("tap", event.detail);
},
},
});
@@ -0,0 +1,6 @@
{
"component": true,
"usingComponents": {
"t-button": "tdesign-miniprogram/button/button"
}
}
@@ -0,0 +1 @@
<t-button theme="{{theme}}" size="{{size}}" block="{{block}}" disabled="{{disabled}}" loading="{{loading}}" bind:tap="handleTap"><slot /></t-button>
@@ -0,0 +1,8 @@
:host {
display: block;
}
t-button {
--td-button-primary-bg-color: var(--brand-color-primary);
--td-button-primary-active-bg-color: var(--brand-color-primary-dark);
--td-button-radius: var(--brand-radius-control);
}
@@ -0,0 +1 @@
Component({ properties: { description: { type: String, value: "暂无内容" } } });
@@ -0,0 +1 @@
{ "component": true, "usingComponents": { "t-empty": "tdesign-miniprogram/empty/empty" } }
@@ -0,0 +1 @@
<t-empty description="{{description}}" />
@@ -0,0 +1,3 @@
t-empty {
--td-empty-description-color: var(--brand-color-muted);
}
@@ -0,0 +1,19 @@
Component({
options: { addGlobalClass: true },
properties: {
label: String,
value: { type: String, value: "" },
placeholder: String,
type: { type: String, value: "text" },
required: Boolean,
maxlength: { type: Number, value: -1 },
},
methods: {
handleChange(event) {
this.triggerEvent("change", event.detail);
},
handleBlur(event) {
this.triggerEvent("blur", event.detail);
},
},
});
@@ -0,0 +1,7 @@
{
"component": true,
"usingComponents": {
"t-input": "tdesign-miniprogram/input/input",
"t-textarea": "tdesign-miniprogram/textarea/textarea"
}
}
@@ -0,0 +1 @@
<view class="field"><view wx:if="{{label}}" class="label">{{label}}<text wx:if="{{required}}" class="required"> *</text></view><t-textarea wx:if="{{type === 'textarea'}}" value="{{value}}" placeholder="{{placeholder}}" maxlength="{{maxlength}}" bind:change="handleChange" bind:blur="handleBlur" /><t-input wx:else value="{{value}}" type="{{type}}" placeholder="{{placeholder}}" maxlength="{{maxlength}}" bind:change="handleChange" bind:blur="handleBlur" /></view>
@@ -0,0 +1,18 @@
.field {
margin-bottom: 24rpx;
}
.label {
margin-bottom: 12rpx;
color: var(--brand-color-text);
font-size: 28rpx;
font-weight: 600;
}
.required {
color: var(--brand-color-primary);
}
t-input,
t-textarea {
--td-input-bg-color: var(--brand-color-surface);
--td-input-border-color: #eadfce;
--td-input-border-radius: var(--brand-radius-control);
}
@@ -0,0 +1 @@
Component({ properties: { text: { type: String, value: "加载中…" } } });
@@ -0,0 +1 @@
{ "component": true, "usingComponents": { "t-loading": "tdesign-miniprogram/loading/loading" } }
@@ -0,0 +1 @@
<view class="loading"><t-loading size="48rpx" text="{{text}}" layout="vertical" /></view>
@@ -0,0 +1,6 @@
.loading {
padding: 96rpx 0;
display: flex;
justify-content: center;
color: var(--brand-color-muted);
}
+2 -1
View File
@@ -4,7 +4,8 @@
"type": "module",
"dependencies": {
"@personal-brand/api-client": "workspace:*",
"@personal-brand/types": "workspace:*"
"@personal-brand/types": "workspace:*",
"tdesign-miniprogram": "^1.16.1"
},
"scripts": {
"lint": "eslint src --ext .ts",
+5 -1
View File
@@ -1,5 +1,9 @@
{
"navigationBarTitleText": "提交需求",
"navigationBarBackgroundColor": "#FBF7F1",
"navigationBarTextStyle": "black"
"navigationBarTextStyle": "black",
"usingComponents": {
"brand-button": "/components/ui/brand-button/brand-button",
"brand-field": "/components/ui/brand-field/brand-field"
}
}
+2 -2
View File
@@ -2,6 +2,6 @@
<view class="product"><view class="product-image"><image wx:if="{{service.coverUrl}}" src="{{service.coverUrl}}" mode="aspectFill"/><view wx:else class="dish-placeholder"></view></view><view class="product-copy"><text class="name">{{service.name || '选择服务'}}</text><text class="price">{{service.priceText || '沟通报价'}}</text></view><text class="available">{{template.available}}</text></view>
<view class="quantity"><text>数量</text><view class="stepper"><button bindtap="decrease">−</button><text>{{quantity}} 份</text><button bindtap="increase">+</button></view></view>
<view class="fulfillment"><text class="field-title">{{template.modeLabel}}</text><view class="choices"><button class="choice {{fulfillment === 'pickup' ? 'active' : ''}}" data-value="pickup" bindtap="chooseFulfillment">{{template.modeA}}</button><button class="choice {{fulfillment === 'delivery' ? 'active' : ''}}" data-value="delivery" bindtap="chooseFulfillment">{{template.modeB}}</button></view></view>
<view class="form"><label>怎么称呼<input name="customerName" placeholder="请输入你的称呼" bindinput="input" data-key="customerName"/></label><label>联系方式<input name="wechatId" placeholder="手机号或微信号" bindinput="input" data-key="wechatId"/></label><label>期望时间<input name="requestedTime" placeholder="例如:下周三 14:00" bindinput="input" data-key="requestedTime"/></label><label wx:if="{{fulfillment === 'delivery'}}">{{template.locationLabel}}<input name="deliveryAddress" placeholder="{{template.locationPlaceholder}}" bindinput="input" data-key="deliveryAddress"/></label><label>{{template.requestType === 'package' ? '备注' : '需求说明'}}<textarea placeholder="{{template.notePlaceholder}}" bindinput="input" data-key="note"></textarea></label></view>
<view class="notice">● {{template.submitNotice}}</view><button class="submit" loading="{{submitting}}" disabled="{{submitting}}" bindtap="submit">{{submitting ? '提交中...' : template.submitLabel}}</button>
<view class="form"><brand-field label="怎么称呼" placeholder="请输入你的称呼" required value="{{form.customerName}}" bind:change="input" data-key="customerName"/><brand-field label="联系方式" placeholder="手机号或微信号" required value="{{form.wechatId}}" bind:change="input" data-key="wechatId"/><brand-field label="期望时间" placeholder="例如:下周三 14:00" value="{{form.requestedTime}}" bind:change="input" data-key="requestedTime"/><brand-field wx:if="{{fulfillment === 'delivery'}}" label="{{template.locationLabel}}" placeholder="{{template.locationPlaceholder}}" value="{{form.deliveryAddress}}" bind:change="input" data-key="deliveryAddress"/><brand-field label="{{template.requestType === 'package' ? '备注' : '需求说明'}}" placeholder="{{template.notePlaceholder}}" type="textarea" value="{{form.note}}" bind:change="input" data-key="note"/></view>
<view class="notice">● {{template.submitNotice}}</view><brand-button loading="{{submitting}}" disabled="{{submitting}}" bind:tap="submit">{{submitting ? '提交中...' : template.submitLabel}}</brand-button>
</view>
+5 -1
View File
@@ -1,5 +1,9 @@
{
"navigationBarTitleText": "我的订单",
"navigationBarBackgroundColor": "#FBF7F1",
"navigationBarTextStyle": "black"
"navigationBarTextStyle": "black",
"usingComponents": {
"brand-loading": "/components/ui/brand-loading/brand-loading",
"brand-empty": "/components/ui/brand-empty/brand-empty"
}
}
+2 -2
View File
@@ -1,8 +1,8 @@
<view class="page">
<view class="heading-row"><text class="heading">我的订单</text><text class="phone" bindtap="contact">☎</text></view>
<view wx:if="{{loading}}" class="state">加载中...</view>
<brand-loading wx:if="{{loading}}" />
<view wx:elif="{{error}}" class="state error"><text>{{error}}</text><button size="mini" bindtap="retry">重新加载</button></view>
<view wx:elif="{{!bookings.length}}" class="empty">完成预约后,订单会显示在这里</view>
<brand-empty wx:elif="{{!bookings.length}}" description="完成预约后,订单会显示在这里" />
<block wx:else>
<view class="status-banner"><view><text class="status-title">订单状态</text><text class="status-sub">查看每笔预约的最新进展</text></view><text class="check">✓</text></view>
<view wx:for="{{bookings}}" wx:key="id" class="card">
+5 -1
View File
@@ -1,5 +1,9 @@
{
"navigationBarTitleText": "服务列表",
"navigationBarBackgroundColor": "#FBF7F1",
"navigationBarTextStyle": "black"
"navigationBarTextStyle": "black",
"usingComponents": {
"brand-loading": "/components/ui/brand-loading/brand-loading",
"brand-empty": "/components/ui/brand-empty/brand-empty"
}
}
+1 -1
View File
@@ -1 +1 @@
<view class="page"><view class="heading"><text>服务列表</text><text class="sub">{{labels.sub}}</text></view><view class="categories"><view class="category package {{category === 'package' ? 'selected' : ''}}" data-category="package" bindtap="switchCategory"><text class="category-title">● {{labels.first}}</text><text>{{labels.firstSub}}</text></view><view class="category chef {{category === 'private_chef' ? 'selected' : ''}}" data-category="private_chef" bindtap="switchCategory"><text class="category-title">● {{labels.second}}</text><text>{{labels.secondSub}}</text></view></view><view wx:if="{{loading}}" class="state">加载中...</view><view wx:elif="{{error}}" class="state">{{error}}</view><view wx:elif="{{!filtered.length}}" class="state">{{labels.empty}}</view><view wx:else><view wx:for="{{filtered}}" wx:key="id" class="card" data-id="{{item.id}}" data-offering-id="{{item.kind ? item.id : ''}}" bindtap="book"><view class="dish-image"><image wx:if="{{item.coverUrl}}" src="{{item.coverUrl}}" mode="aspectFill"/><view wx:else class="dish-placeholder"></view></view><view class="card-content"><view class="card-head"><view class="name">{{item.name}}</view><text class="available">{{item.isEnabled !== false ? labels.available : labels.unavailable}}</text></view><text class="desc">{{item.description || item.summary}}</text><view class="card-bottom"><text class="price">{{item.priceText || '面议'}}</text><button size="mini">查看详情</button></view></view></view></view></view>
<view class="page"><view class="heading"><text>服务列表</text><text class="sub">{{labels.sub}}</text></view><view class="categories"><view class="category package {{category === 'package' ? 'selected' : ''}}" data-category="package" bindtap="switchCategory"><text class="category-title">● {{labels.first}}</text><text>{{labels.firstSub}}</text></view><view class="category chef {{category === 'private_chef' ? 'selected' : ''}}" data-category="private_chef" bindtap="switchCategory"><text class="category-title">● {{labels.second}}</text><text>{{labels.secondSub}}</text></view></view><brand-loading wx:if="{{loading}}" /><view wx:elif="{{error}}" class="state">{{error}}</view><brand-empty wx:elif="{{!filtered.length}}" description="{{labels.empty}}" /><view wx:else><view wx:for="{{filtered}}" wx:key="id" class="card" data-id="{{item.id}}" data-offering-id="{{item.kind ? item.id : ''}}" bindtap="book"><view class="dish-image"><image wx:if="{{item.coverUrl}}" src="{{item.coverUrl}}" mode="aspectFill"/><view wx:else class="dish-placeholder"></view></view><view class="card-content"><view class="card-head"><view class="name">{{item.name}}</view><text class="available">{{item.isEnabled !== false ? labels.available : labels.unavailable}}</text></view><text class="desc">{{item.description || item.summary}}</text><view class="card-bottom"><text class="price">{{item.priceText || '面议'}}</text><button size="mini">查看详情</button></view></view></view></view></view>
+14
View File
@@ -0,0 +1,14 @@
/* 个人品牌 Design Tokens;行业模板只提供内容,不覆盖这些基础视觉变量。 */
page {
--brand-color-bg: #fbf7f1;
--brand-color-surface: #ffffff;
--brand-color-subtle: #f4ebd9;
--brand-color-primary: #b54a2c;
--brand-color-primary-dark: #913a23;
--brand-color-text: #2b2b2b;
--brand-color-muted: #7a4a2b;
--brand-color-accent: #e8a75f;
--brand-radius-card: 16rpx;
--brand-radius-control: 12rpx;
--brand-space-page: 32rpx;
}
+17
View File
@@ -0,0 +1,17 @@
# 小程序 UI 基础层
小程序使用 `tdesign-miniprogram` 提供成熟的交互控件,再由 `apps/miniapp/components/ui/` 提供品牌层封装。行业模板只负责内容和字段配置,不直接依赖 TDesign 组件名。
## 首次预览
在微信开发者工具中打开 `apps/miniapp` 后执行「工具 → 构建 npm」。构建完成后,工具会生成被 `.gitignore` 忽略的 `miniprogram_npm/` 目录,页面即可解析 `tdesign-miniprogram/*` 组件路径。
依赖升级后需要重新执行一次「构建 npm」。CI 或发布流程也必须先完成该步骤,再上传小程序代码。
## 组件边界
- `BrandButton`、`BrandField`、`BrandEmpty`、`BrandLoading`:稳定的品牌交互契约,页面只依赖这些封装。
- `tdesign-miniprogram`:输入、按钮、弹层、加载等基础行为和无障碍细节。
- 页面和行业模板:只消费统一字段与状态,不出现 `templateKey === "food"` 一类分支。
品牌颜色、圆角和间距统一维护在 `apps/miniapp/styles/tokens.wxss`。
+8
View File
@@ -118,6 +118,9 @@ importers:
'@personal-brand/types':
specifier: workspace:*
version: link:../../packages/types
tdesign-miniprogram:
specifier: ^1.16.1
version: 1.16.1
packages/api-client:
dependencies:
@@ -1823,6 +1826,9 @@ packages:
resolution: {integrity: sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==}
engines: {node: '>=8'}
tdesign-miniprogram@1.16.1:
resolution: {integrity: sha512-exdLrz9qAYXuGSFWugtiiXMbE+sdMzDwZC1yrDnsUepJLoMFp2SFMPr7l1eFihraAneDRV4qntiarnD5owNhNg==}
thread-stream@4.2.0:
resolution: {integrity: sha512-e2zZ96wSChazBsbENf/Pcm/4swHt2cEKQ92rhUjkL9GCKiTDJIaTBenjE/m9DXi0QBmTMDkFDdOomUy20A1tDQ==}
engines: {node: '>=20'}
@@ -3643,6 +3649,8 @@ snapshots:
dependencies:
has-flag: 4.0.0
tdesign-miniprogram@1.16.1: {}
thread-stream@4.2.0:
dependencies:
real-require: 1.0.0