Skip to content

Commit 89fa69a

Browse files
authored
Merge branch 'wechat-miniprogram:master' into master
2 parents ce893a4 + a061b17 commit 89fa69a

70 files changed

Lines changed: 5395 additions & 2 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎README.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ npm install
2929
npm run lint
3030
```
3131

32+
## Agent Demo
33+
34+
| 路径 | 说明 |
35+
|------|------|
36+
| `miniprogram/skills/drink-skill` | WeStoreCafe 点单:搜索 / 选规格 / 下单 / 地址,小微 handoff 进业务页 |
37+
| `miniprogram/packageWeStoreCoffee` | WeStoreCafe 点单分包:首页 / 选规格 / 结算 + 目录数据 |
38+
| `miniprogram/packageWeStoreCoffee/pages/home/home` | 点单首页(searchDrinks 接力页) |
39+
| `miniprogram/packageWeStoreCoffee/pages/sku-picker/sku-picker` | 选规格接力页 |
40+
| `miniprogram/packageWeStoreCoffee/pages/checkout/checkout` | 结算接力页 |
41+
| `miniprogram/skills/agent-auth-skill` | 授权卡片 + 订阅消息 / 蓝牙授权 / 微信运动 / 收货地址 |
42+
| `miniprogram/pages/protocol/user-service` | 用户服务协议页 |
43+
| `miniprogram/pages/protocol/privacy` | 隐私政策页 |
44+
45+
协议名称与详情页由原子接口调用 `wx.requestAgentPrivacyAuthorization({ privacyAgreements })` 时传入,不再在 `app.json` 中静态声明。接口不再接收 `type`,统一使用 default 文案模板。
46+
3247
## 截图
3348

3449
<img width="375" src="https://res.wx.qq.com/op_res/0_vsSii5DaG-1hoXcqmBCT_tPShgSPKi3_FBVuVj1tu1ZdZD8lwYNrSQm3mdswI2">

‎miniprogram/app.js‎

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ App({
6565
}).catch(({ mod, errMsg }) => {
6666
console.error(`installRouteBuilder path: ${mod}, ${errMsg}`)
6767
})
68+
this.registerAgentHandoff()
69+
this.ensureCafeDemoUser()
6870
},
6971

7072
onShow(opts) {
@@ -97,7 +99,53 @@ App({
9799
hasLogin: false,
98100
openid: null,
99101
iconTabbar: '/page/extend/images/icon_tabbar.png',
100-
systemInfo: {}
102+
systemInfo: {},
103+
agentHandoffs: {}
104+
},
105+
106+
registerAgentHandoff() {
107+
if (!wx.onAgentHandoff) {
108+
console.warn('[App] 当前基础库不支持 wx.onAgentHandoff,请使用支持小微 handoff 的版本')
109+
return
110+
}
111+
wx.onAgentHandoff(({ pageId, path, query, payload }) => {
112+
console.log('[App] onAgentHandoff', { pageId, path, query, payload })
113+
this.globalData.agentHandoffs = this.globalData.agentHandoffs || {}
114+
this.globalData.agentHandoffs[pageId] = { path, query, payload }
115+
})
116+
},
117+
118+
takeAgentHandoff(pageId) {
119+
const map = this.globalData.agentHandoffs || {}
120+
const handoff = map[pageId]
121+
if (handoff) delete map[pageId]
122+
return handoff || null
123+
},
124+
125+
ensureCafeDemoUser() {
126+
const userInfo = wx.getStorageSync('userInfo')
127+
if (userInfo && userInfo.openid) {
128+
this.globalData.userInfo = userInfo
129+
return
130+
}
131+
const mockOpenid = `mock_${Date.now()}`
132+
const next = {
133+
openid: mockOpenid,
134+
unionid: `union_${mockOpenid}`,
135+
nickname: `用户${Math.floor(Math.random() * 10000)}`,
136+
avatarUrl: '',
137+
loginTime: new Date().toISOString()
138+
}
139+
wx.setStorageSync('userInfo', next)
140+
this.globalData.userInfo = next
141+
const initialized = wx.getStorageSync(`initialized_${mockOpenid}`)
142+
if (!initialized) {
143+
wx.setStorageSync(`address_${mockOpenid}`, null)
144+
wx.setStorageSync(`orders_${mockOpenid}`, [])
145+
wx.setStorageSync(`pending_order_${mockOpenid}`, null)
146+
wx.setStorageSync(`active_order_${mockOpenid}`, null)
147+
wx.setStorageSync(`initialized_${mockOpenid}`, true)
148+
}
101149
},
102150
// lazy loading openid
103151
getUserOpenId(callback) {

‎miniprogram/app.json‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
"page/ad/optimize-ad/home-small-card/home-small-card",
1515
"page/ad/optimize-ad/home-large-card/home-large-card",
1616
"page/ad/optimize-ad/other-small-card/other-small-card",
17-
"page/ad/optimize-ad/other-large-card/other-large-card"
17+
"page/ad/optimize-ad/other-large-card/other-large-card",
18+
"pages/protocol/user-service",
19+
"pages/protocol/privacy"
1820
],
1921
"usingComponents": {
2022
"mp-navigation-bar": "/component/navigation-bar/navigation-bar"
@@ -419,6 +421,20 @@
419421
"pages/customParticle/scene-customParticle-shapeEmitter/index",
420422
"pages/customParticle/scene-customParticle-meshEmitter/index"
421423
]
424+
},
425+
{
426+
"root": "skills",
427+
"pages": [],
428+
"independent": true
429+
},
430+
{
431+
"root": "packageWeStoreCoffee",
432+
"name": "westoreCoffee",
433+
"pages": [
434+
"pages/home/home",
435+
"pages/sku-picker/sku-picker",
436+
"pages/checkout/checkout"
437+
]
422438
}
423439
],
424440
"preloadRule": {
@@ -539,6 +555,21 @@
539555
"wxfdcee92a299bcaf1"
540556
],
541557
"lazyCodeLoading": "requiredComponents",
558+
"agent": {
559+
"skills": [
560+
{
561+
"name": "drink",
562+
"description": "WeStoreCafe 点单场景:查询推荐饮品、选择规格、填写收货地址、下单支付",
563+
"path": "skills/drink-skill"
564+
},
565+
{
566+
"name": "agent-auth",
567+
"description": "Agent 授权与开放能力:隐私授权卡片、订阅消息、蓝牙授权、微信运动、收货地址 chooseAddress。",
568+
"path": "skills/agent-auth-skill"
569+
}
570+
],
571+
"pageMetadata": "page-meta.json"
572+
},
542573
"__lazyCodeLoadingChunk": true,
543574
"rendererOptions": {
544575
"skyline": {
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
const CATEGORIES = [
2+
{ id: 141, name: '黑咖/果咖' },
3+
{ id: 133, name: '奶咖' },
4+
{ id: 136, name: '蔬果汁' },
5+
{ id: 135, name: '水果茶' },
6+
{ id: 139, name: '奶茶/暖饮' }
7+
]
8+
9+
const DRINKS = [
10+
{ id: 289, name: '美式', price: 15, categoryId: 141, categoryName: '黑咖/果咖', description: '', imageUrl: '' },
11+
{ id: 293, name: '白桃茶美式', price: 16, categoryId: 141, categoryName: '黑咖/果咖', description: '清爽茶香', imageUrl: '' },
12+
{ id: 295, name: '杨桃油柑美式', price: 18, categoryId: 141, categoryName: '黑咖/果咖', description: '鲜油柑+杨桃', imageUrl: '' },
13+
{ id: 353, name: '凤梨美式', price: 18, categoryId: 141, categoryName: '黑咖/果咖', description: '推荐', imageUrl: '' },
14+
{ id: 362, name: '葡萄美式', price: 18, categoryId: 141, categoryName: '黑咖/果咖', description: '', imageUrl: '' },
15+
{ id: 294, name: '爆柠美式', price: 18, categoryId: 141, categoryName: '黑咖/果咖', description: '', imageUrl: '' },
16+
{ id: 296, name: '鲜橙美式', price: 20, categoryId: 141, categoryName: '黑咖/果咖', description: '', imageUrl: '' },
17+
18+
{ id: 393, name: '焦糖蜂窝拿铁', price: 20, categoryId: 133, categoryName: '奶咖', description: '', imageUrl: '' },
19+
{ id: 395, name: '小黄油拿铁', price: 20, categoryId: 133, categoryName: '奶咖', description: '', imageUrl: '' },
20+
{ id: 368, name: '黄油Dirty', price: 20, categoryId: 133, categoryName: '奶咖', description: '到店制作 大口喝', imageUrl: '' },
21+
{ id: 390, name: '轻芝士拿铁', price: 20, categoryId: 133, categoryName: '奶咖', description: '法国kiri芝士', imageUrl: '' },
22+
{ id: 195, name: '拿铁', price: 18, categoryId: 133, categoryName: '奶咖', description: '', imageUrl: '' },
23+
{ id: 384, name: 'SOE澳白', price: 18, categoryId: 133, categoryName: '奶咖', description: '小热杯 更"咖啡"!', imageUrl: '' },
24+
{ id: 383, name: '秋玫瑰拿铁', price: 20, categoryId: 133, categoryName: '奶咖', description: '玫瑰与奶咖的双向奔赴', imageUrl: '' },
25+
{ id: 299, name: '生椰拿铁', price: 20, categoryId: 133, categoryName: '奶咖', description: '', imageUrl: '' },
26+
{ id: 297, name: '橘皮拿铁', price: 20, categoryId: 133, categoryName: '奶咖', description: '', imageUrl: '' },
27+
{ id: 208, name: '燕麦拿铁', price: 22, categoryId: 133, categoryName: '奶咖', description: 'OATLY燕麦奶', imageUrl: '' },
28+
29+
{ id: 394, name: '杨桃+油柑', price: 18, categoryId: 136, categoryName: '蔬果汁', description: '', imageUrl: '' },
30+
{ id: 389, name: '胡萝卜汁', price: 13, categoryId: 136, categoryName: '蔬果汁', description: '补充维生素A', imageUrl: '' },
31+
{ id: 386, name: '青瓜+西芹+苹果', price: 15, categoryId: 136, categoryName: '蔬果汁', description: '全能果蔬饮就它了', imageUrl: '' },
32+
{ id: 387, name: '青瓜+雪梨+柠檬', price: 15, categoryId: 136, categoryName: '蔬果汁', description: '一口喝出清润好气色', imageUrl: '' },
33+
{ id: 313, name: '苹果胡萝卜汁', price: 17, categoryId: 136, categoryName: '蔬果汁', description: '现榨无糖0负担', imageUrl: '' },
34+
35+
{ id: 315, name: '蜂蜜柚子茶', price: 12, categoryId: 135, categoryName: '水果茶', description: '', imageUrl: '' },
36+
{ id: 300, name: '海盐柠檬', price: 13, categoryId: 135, categoryName: '水果茶', description: '补充电解质', imageUrl: '' },
37+
{ id: 302, name: '鸭屎香柠檬茶', price: 13, categoryId: 135, categoryName: '水果茶', description: '', imageUrl: '' },
38+
{ id: 301, name: '白桃乌龙柠檬茶', price: 13, categoryId: 135, categoryName: '水果茶', description: '', imageUrl: '' },
39+
{ id: 305, name: '满杯百香果', price: 13, categoryId: 135, categoryName: '水果茶', description: '', imageUrl: '' },
40+
{ id: 306, name: '百香益力多', price: 16, categoryId: 135, categoryName: '水果茶', description: '', imageUrl: '' },
41+
{ id: 307, name: '柠檬益力多', price: 16, categoryId: 135, categoryName: '水果茶', description: '', imageUrl: '' },
42+
{ id: 364, name: '黑加仑柠檬茶', price: 16, categoryId: 135, categoryName: '水果茶', description: '', imageUrl: '' },
43+
{ id: 303, name: '杨桃油柑柠檬茶', price: 16, categoryId: 135, categoryName: '水果茶', description: '鲜油柑榨+杨桃', imageUrl: '' },
44+
45+
{ id: 371, name: '抹茶脑袋', price: 17, categoryId: 139, categoryName: '奶茶/暖饮', description: '冷热皆宜', imageUrl: '' },
46+
{ id: 372, name: '茶萃奶白', price: 16, categoryId: 139, categoryName: '奶茶/暖饮', description: '冷热皆宜', imageUrl: '' },
47+
{ id: 316, name: '黑糖姜母茶', price: 12, categoryId: 139, categoryName: '奶茶/暖饮', description: '热饮 红枣配枸杞', imageUrl: '' },
48+
{ id: 381, name: '红糖姜桃胶撞奶', price: 18, categoryId: 139, categoryName: '奶茶/暖饮', description: '热饮 姜跟牛奶很般配', imageUrl: '' }
49+
]
50+
51+
function buildSkuSchema(categoryId) {
52+
const tempDim = {
53+
key: 'temperature', label: '温度', multiple: false,
54+
options: [
55+
{ value: 'ice', label: '冰' },
56+
{ value: 'hot', label: '热' }
57+
]
58+
}
59+
const sugarDim = {
60+
key: 'sugar', label: '糖度', multiple: false,
61+
options: [
62+
{ value: 'none', label: '无糖' },
63+
{ value: 'less', label: '少糖' },
64+
{ value: 'normal', label: '标准' },
65+
{ value: 'more', label: '多糖' }
66+
]
67+
}
68+
const cupDim = {
69+
key: 'cupSize', label: '杯型', multiple: false,
70+
options: [
71+
{ value: 'medium', label: '中杯', extraPrice: 0 },
72+
{ value: 'large', label: '大杯', extraPrice: 3 },
73+
{ value: 'xlarge', label: '超大杯', extraPrice: 6 }
74+
]
75+
}
76+
const milkToppings = {
77+
key: 'toppings', label: '加料', multiple: true,
78+
options: [
79+
{ value: 'oatMilk', label: '燕麦奶', extraPrice: 3 },
80+
{ value: 'coconut', label: '椰浆', extraPrice: 3 },
81+
{ value: 'extraShot', label: '额外浓缩', extraPrice: 5 }
82+
]
83+
}
84+
const teaToppings = {
85+
key: 'toppings', label: '加料', multiple: true,
86+
options: [
87+
{ value: 'pearl', label: '珍珠', extraPrice: 2 },
88+
{ value: 'jelly', label: '椰果', extraPrice: 2 }
89+
]
90+
}
91+
const juiceCupDim = {
92+
key: 'cupSize', label: '杯型', multiple: false,
93+
options: [
94+
{ value: 'medium', label: '中杯', extraPrice: 0 },
95+
{ value: 'large', label: '大杯', extraPrice: 3 }
96+
]
97+
}
98+
99+
switch (categoryId) {
100+
case 141: return { dimensions: [tempDim, sugarDim] }
101+
case 133: return { dimensions: [tempDim, sugarDim, cupDim, milkToppings] }
102+
case 136: return { dimensions: [tempDim, juiceCupDim] }
103+
case 135: return { dimensions: [tempDim, sugarDim, cupDim] }
104+
case 139: return { dimensions: [tempDim, sugarDim, cupDim, teaToppings] }
105+
default: return { dimensions: [tempDim, sugarDim] }
106+
}
107+
}
108+
109+
function buildCatalog() {
110+
return DRINKS.map(d => ({
111+
...d,
112+
skuSchema: buildSkuSchema(d.categoryId)
113+
}))
114+
}
115+
116+
module.exports = { CATEGORIES, DRINKS, buildCatalog, buildSkuSchema }

0 commit comments

Comments
 (0)