Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ npm install
npm run lint
```

## Agent Demo

| 路径 | 说明 |
|------|------|
| `miniprogram/skills/drink-skill` | WeStoreCafe 点单:搜索 / 选规格 / 下单 / 地址,小微 handoff 进业务页 |
| `miniprogram/packageWeStoreCoffee` | WeStoreCafe 点单分包:首页 / 选规格 / 结算 + 目录数据 |
| `miniprogram/packageWeStoreCoffee/pages/home/home` | 点单首页(searchDrinks 接力页) |
| `miniprogram/packageWeStoreCoffee/pages/sku-picker/sku-picker` | 选规格接力页 |
| `miniprogram/packageWeStoreCoffee/pages/checkout/checkout` | 结算接力页 |
| `miniprogram/skills/agent-auth-skill` | 授权卡片 + 订阅消息 / 蓝牙授权 / 微信运动 / 收货地址 |
| `miniprogram/pages/protocol/user-service` | 用户服务协议页 |
| `miniprogram/pages/protocol/privacy` | 隐私政策页 |

协议名称与详情页由原子接口调用 `wx.requestAgentPrivacyAuthorization({ privacyAgreements })` 时传入,不再在 `app.json` 中静态声明。接口不再接收 `type`,统一使用 default 文案模板。

## 截图

<img width="375" src="https://res.wx.qq.com/op_res/0_vsSii5DaG-1hoXcqmBCT_tPShgSPKi3_FBVuVj1tu1ZdZD8lwYNrSQm3mdswI2">
50 changes: 49 additions & 1 deletion miniprogram/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ App({
}).catch(({ mod, errMsg }) => {
console.error(`installRouteBuilder path: ${mod}, ${errMsg}`)
})
this.registerAgentHandoff()
this.ensureCafeDemoUser()
},

onShow(opts) {
Expand Down Expand Up @@ -97,7 +99,53 @@ App({
hasLogin: false,
openid: null,
iconTabbar: '/page/extend/images/icon_tabbar.png',
systemInfo: {}
systemInfo: {},
agentHandoffs: {}
},

registerAgentHandoff() {
if (!wx.onAgentHandoff) {
console.warn('[App] 当前基础库不支持 wx.onAgentHandoff,请使用支持小微 handoff 的版本')
return
}
wx.onAgentHandoff(({ pageId, path, query, payload }) => {
console.log('[App] onAgentHandoff', { pageId, path, query, payload })
this.globalData.agentHandoffs = this.globalData.agentHandoffs || {}
this.globalData.agentHandoffs[pageId] = { path, query, payload }
})
},

takeAgentHandoff(pageId) {
const map = this.globalData.agentHandoffs || {}
const handoff = map[pageId]
if (handoff) delete map[pageId]
return handoff || null
},

ensureCafeDemoUser() {
const userInfo = wx.getStorageSync('userInfo')
if (userInfo && userInfo.openid) {
this.globalData.userInfo = userInfo
return
}
const mockOpenid = `mock_${Date.now()}`
const next = {
openid: mockOpenid,
unionid: `union_${mockOpenid}`,
nickname: `用户${Math.floor(Math.random() * 10000)}`,
avatarUrl: '',
loginTime: new Date().toISOString()
}
wx.setStorageSync('userInfo', next)
this.globalData.userInfo = next
const initialized = wx.getStorageSync(`initialized_${mockOpenid}`)
if (!initialized) {
wx.setStorageSync(`address_${mockOpenid}`, null)
wx.setStorageSync(`orders_${mockOpenid}`, [])
wx.setStorageSync(`pending_order_${mockOpenid}`, null)
wx.setStorageSync(`active_order_${mockOpenid}`, null)
wx.setStorageSync(`initialized_${mockOpenid}`, true)
}
},
// lazy loading openid
getUserOpenId(callback) {
Expand Down
33 changes: 32 additions & 1 deletion miniprogram/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
"page/ad/optimize-ad/home-small-card/home-small-card",
"page/ad/optimize-ad/home-large-card/home-large-card",
"page/ad/optimize-ad/other-small-card/other-small-card",
"page/ad/optimize-ad/other-large-card/other-large-card"
"page/ad/optimize-ad/other-large-card/other-large-card",
"pages/protocol/user-service",
"pages/protocol/privacy"
],
"usingComponents": {
"mp-navigation-bar": "/component/navigation-bar/navigation-bar"
Expand Down Expand Up @@ -419,6 +421,20 @@
"pages/customParticle/scene-customParticle-shapeEmitter/index",
"pages/customParticle/scene-customParticle-meshEmitter/index"
]
},
{
"root": "skills",
"pages": [],
"independent": true
},
{
"root": "packageWeStoreCoffee",
"name": "westoreCoffee",
"pages": [
"pages/home/home",
"pages/sku-picker/sku-picker",
"pages/checkout/checkout"
]
}
],
"preloadRule": {
Expand Down Expand Up @@ -539,6 +555,21 @@
"wxfdcee92a299bcaf1"
],
"lazyCodeLoading": "requiredComponents",
"agent": {
"skills": [
{
"name": "drink",
"description": "WeStoreCafe 点单场景:查询推荐饮品、选择规格、填写收货地址、下单支付",
"path": "skills/drink-skill"
},
{
"name": "agent-auth",
"description": "Agent 授权与开放能力:隐私授权卡片、订阅消息、蓝牙授权、微信运动、收货地址 chooseAddress。",
"path": "skills/agent-auth-skill"
}
],
"pageMetadata": "page-meta.json"
},
"__lazyCodeLoadingChunk": true,
"rendererOptions": {
"skyline": {
Expand Down
116 changes: 116 additions & 0 deletions miniprogram/packageWeStoreCoffee/data/seed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
const CATEGORIES = [
{ id: 141, name: '黑咖/果咖' },
{ id: 133, name: '奶咖' },
{ id: 136, name: '蔬果汁' },
{ id: 135, name: '水果茶' },
{ id: 139, name: '奶茶/暖饮' }
]

const DRINKS = [
{ id: 289, name: '美式', price: 15, categoryId: 141, categoryName: '黑咖/果咖', description: '', imageUrl: '' },
{ id: 293, name: '白桃茶美式', price: 16, categoryId: 141, categoryName: '黑咖/果咖', description: '清爽茶香', imageUrl: '' },
{ id: 295, name: '杨桃油柑美式', price: 18, categoryId: 141, categoryName: '黑咖/果咖', description: '鲜油柑+杨桃', imageUrl: '' },
{ id: 353, name: '凤梨美式', price: 18, categoryId: 141, categoryName: '黑咖/果咖', description: '推荐', imageUrl: '' },
{ id: 362, name: '葡萄美式', price: 18, categoryId: 141, categoryName: '黑咖/果咖', description: '', imageUrl: '' },
{ id: 294, name: '爆柠美式', price: 18, categoryId: 141, categoryName: '黑咖/果咖', description: '', imageUrl: '' },
{ id: 296, name: '鲜橙美式', price: 20, categoryId: 141, categoryName: '黑咖/果咖', description: '', imageUrl: '' },

{ id: 393, name: '焦糖蜂窝拿铁', price: 20, categoryId: 133, categoryName: '奶咖', description: '', imageUrl: '' },
{ id: 395, name: '小黄油拿铁', price: 20, categoryId: 133, categoryName: '奶咖', description: '', imageUrl: '' },
{ id: 368, name: '黄油Dirty', price: 20, categoryId: 133, categoryName: '奶咖', description: '到店制作 大口喝', imageUrl: '' },
{ id: 390, name: '轻芝士拿铁', price: 20, categoryId: 133, categoryName: '奶咖', description: '法国kiri芝士', imageUrl: '' },
{ id: 195, name: '拿铁', price: 18, categoryId: 133, categoryName: '奶咖', description: '', imageUrl: '' },
{ id: 384, name: 'SOE澳白', price: 18, categoryId: 133, categoryName: '奶咖', description: '小热杯 更"咖啡"!', imageUrl: '' },
{ id: 383, name: '秋玫瑰拿铁', price: 20, categoryId: 133, categoryName: '奶咖', description: '玫瑰与奶咖的双向奔赴', imageUrl: '' },
{ id: 299, name: '生椰拿铁', price: 20, categoryId: 133, categoryName: '奶咖', description: '', imageUrl: '' },
{ id: 297, name: '橘皮拿铁', price: 20, categoryId: 133, categoryName: '奶咖', description: '', imageUrl: '' },
{ id: 208, name: '燕麦拿铁', price: 22, categoryId: 133, categoryName: '奶咖', description: 'OATLY燕麦奶', imageUrl: '' },

{ id: 394, name: '杨桃+油柑', price: 18, categoryId: 136, categoryName: '蔬果汁', description: '', imageUrl: '' },
{ id: 389, name: '胡萝卜汁', price: 13, categoryId: 136, categoryName: '蔬果汁', description: '补充维生素A', imageUrl: '' },
{ id: 386, name: '青瓜+西芹+苹果', price: 15, categoryId: 136, categoryName: '蔬果汁', description: '全能果蔬饮就它了', imageUrl: '' },
{ id: 387, name: '青瓜+雪梨+柠檬', price: 15, categoryId: 136, categoryName: '蔬果汁', description: '一口喝出清润好气色', imageUrl: '' },
{ id: 313, name: '苹果胡萝卜汁', price: 17, categoryId: 136, categoryName: '蔬果汁', description: '现榨无糖0负担', imageUrl: '' },

{ id: 315, name: '蜂蜜柚子茶', price: 12, categoryId: 135, categoryName: '水果茶', description: '', imageUrl: '' },
{ id: 300, name: '海盐柠檬', price: 13, categoryId: 135, categoryName: '水果茶', description: '补充电解质', imageUrl: '' },
{ id: 302, name: '鸭屎香柠檬茶', price: 13, categoryId: 135, categoryName: '水果茶', description: '', imageUrl: '' },
{ id: 301, name: '白桃乌龙柠檬茶', price: 13, categoryId: 135, categoryName: '水果茶', description: '', imageUrl: '' },
{ id: 305, name: '满杯百香果', price: 13, categoryId: 135, categoryName: '水果茶', description: '', imageUrl: '' },
{ id: 306, name: '百香益力多', price: 16, categoryId: 135, categoryName: '水果茶', description: '', imageUrl: '' },
{ id: 307, name: '柠檬益力多', price: 16, categoryId: 135, categoryName: '水果茶', description: '', imageUrl: '' },
{ id: 364, name: '黑加仑柠檬茶', price: 16, categoryId: 135, categoryName: '水果茶', description: '', imageUrl: '' },
{ id: 303, name: '杨桃油柑柠檬茶', price: 16, categoryId: 135, categoryName: '水果茶', description: '鲜油柑榨+杨桃', imageUrl: '' },

{ id: 371, name: '抹茶脑袋', price: 17, categoryId: 139, categoryName: '奶茶/暖饮', description: '冷热皆宜', imageUrl: '' },
{ id: 372, name: '茶萃奶白', price: 16, categoryId: 139, categoryName: '奶茶/暖饮', description: '冷热皆宜', imageUrl: '' },
{ id: 316, name: '黑糖姜母茶', price: 12, categoryId: 139, categoryName: '奶茶/暖饮', description: '热饮 红枣配枸杞', imageUrl: '' },
{ id: 381, name: '红糖姜桃胶撞奶', price: 18, categoryId: 139, categoryName: '奶茶/暖饮', description: '热饮 姜跟牛奶很般配', imageUrl: '' }
]

function buildSkuSchema(categoryId) {
const tempDim = {
key: 'temperature', label: '温度', multiple: false,
options: [
{ value: 'ice', label: '冰' },
{ value: 'hot', label: '热' }
]
}
const sugarDim = {
key: 'sugar', label: '糖度', multiple: false,
options: [
{ value: 'none', label: '无糖' },
{ value: 'less', label: '少糖' },
{ value: 'normal', label: '标准' },
{ value: 'more', label: '多糖' }
]
}
const cupDim = {
key: 'cupSize', label: '杯型', multiple: false,
options: [
{ value: 'medium', label: '中杯', extraPrice: 0 },
{ value: 'large', label: '大杯', extraPrice: 3 },
{ value: 'xlarge', label: '超大杯', extraPrice: 6 }
]
}
const milkToppings = {
key: 'toppings', label: '加料', multiple: true,
options: [
{ value: 'oatMilk', label: '燕麦奶', extraPrice: 3 },
{ value: 'coconut', label: '椰浆', extraPrice: 3 },
{ value: 'extraShot', label: '额外浓缩', extraPrice: 5 }
]
}
const teaToppings = {
key: 'toppings', label: '加料', multiple: true,
options: [
{ value: 'pearl', label: '珍珠', extraPrice: 2 },
{ value: 'jelly', label: '椰果', extraPrice: 2 }
]
}
const juiceCupDim = {
key: 'cupSize', label: '杯型', multiple: false,
options: [
{ value: 'medium', label: '中杯', extraPrice: 0 },
{ value: 'large', label: '大杯', extraPrice: 3 }
]
}

switch (categoryId) {
case 141: return { dimensions: [tempDim, sugarDim] }
case 133: return { dimensions: [tempDim, sugarDim, cupDim, milkToppings] }
case 136: return { dimensions: [tempDim, juiceCupDim] }
case 135: return { dimensions: [tempDim, sugarDim, cupDim] }
case 139: return { dimensions: [tempDim, sugarDim, cupDim, teaToppings] }
default: return { dimensions: [tempDim, sugarDim] }
}
}

function buildCatalog() {
return DRINKS.map(d => ({
...d,
skuSchema: buildSkuSchema(d.categoryId)
}))
}

module.exports = { CATEGORIES, DRINKS, buildCatalog, buildSkuSchema }
Loading
Loading