fix: 修复 VoiceController Map.of 兼容性 + ExploreController 参数不匹配
- VoiceController: Map.of() -> Collections.singletonMap() 兼容 Java 8 - ExploreController: 补齐 takeoutService.roll() 缺失的 taste/priceRange/allergies 参数 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
165
miniapp/pages/fridge-input/fridge-input.js
Normal file
165
miniapp/pages/fridge-input/fridge-input.js
Normal file
@@ -0,0 +1,165 @@
|
||||
const storage = require('../../utils/storage');
|
||||
const app = getApp();
|
||||
|
||||
const DEFAULT_STAPLES = ['油', '盐', '酱油', '醋', '料酒', '生抽', '蚝油', '葱', '姜', '蒜'];
|
||||
|
||||
Page({
|
||||
data: {
|
||||
inputValue: '',
|
||||
ingredients: [],
|
||||
selected: {},
|
||||
staples: [],
|
||||
voiceRecording: false,
|
||||
showStapleEditor: false,
|
||||
stapleEditValue: ''
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
const saved = storage.get('custom_staples', null);
|
||||
this.setData({ staples: saved || [...DEFAULT_STAPLES] });
|
||||
},
|
||||
|
||||
onInput(e) {
|
||||
this.setData({ inputValue: e.detail.value });
|
||||
},
|
||||
|
||||
addIngredient() {
|
||||
const name = this.data.inputValue.trim();
|
||||
if (!name) return;
|
||||
this.add(name);
|
||||
this.setData({ inputValue: '' });
|
||||
},
|
||||
|
||||
onToggle(e) {
|
||||
const { name, selected } = e.detail;
|
||||
if (selected) {
|
||||
this.add(name);
|
||||
} else {
|
||||
this.remove(name);
|
||||
}
|
||||
},
|
||||
|
||||
add(name) {
|
||||
if (this.data.ingredients.includes(name)) return;
|
||||
const ingredients = [...this.data.ingredients, name];
|
||||
const selected = { ...this.data.selected, [name]: true };
|
||||
this.setData({ ingredients, selected });
|
||||
},
|
||||
|
||||
remove(name) {
|
||||
const ingredients = this.data.ingredients.filter(i => i !== name);
|
||||
const selected = { ...this.data.selected, [name]: false };
|
||||
this.setData({ ingredients, selected });
|
||||
},
|
||||
|
||||
/* ── 语音输入 ── */
|
||||
voiceInput() {
|
||||
const recorder = wx.getRecorderManager();
|
||||
|
||||
if (this.data.voiceRecording) {
|
||||
// 松手停止
|
||||
recorder.stop();
|
||||
this.setData({ voiceRecording: false });
|
||||
wx.hideLoading();
|
||||
return;
|
||||
}
|
||||
|
||||
this.setData({ voiceRecording: true });
|
||||
wx.showLoading({ title: '正在听…', mask: true });
|
||||
|
||||
recorder.start({
|
||||
duration: 10000,
|
||||
sampleRate: 16000,
|
||||
numberOfChannels: 1,
|
||||
encodeBitRate: 48000,
|
||||
format: 'mp3'
|
||||
});
|
||||
|
||||
recorder.onStop((res) => {
|
||||
this.setData({ voiceRecording: false });
|
||||
wx.hideLoading();
|
||||
|
||||
// 上传录音到后端识别
|
||||
wx.uploadFile({
|
||||
url: app.globalData.baseUrl + '/api/voice/recognize',
|
||||
filePath: res.tempFilePath,
|
||||
name: 'audio',
|
||||
header: { 'Content-Type': 'multipart/form-data' },
|
||||
success: (uploadRes) => {
|
||||
try {
|
||||
const data = JSON.parse(uploadRes.data);
|
||||
if (data.code === 200 && data.data && data.data.text) {
|
||||
const text = data.data.text.trim();
|
||||
if (text) {
|
||||
// 按逗号/空格/顿号分割多个食材
|
||||
const names = text.split(/[,,、\s]+/);
|
||||
names.forEach(n => this.add(n));
|
||||
wx.showToast({ title: '已识别 ' + names.length + ' 种食材', icon: 'success' });
|
||||
return;
|
||||
}
|
||||
}
|
||||
wx.showToast({ title: '未识别到食材,请手动输入', icon: 'none' });
|
||||
} catch (e) {
|
||||
wx.showToast({ title: '识别失败,请手动输入', icon: 'none' });
|
||||
}
|
||||
},
|
||||
fail: () => {
|
||||
wx.showToast({ title: '语音服务暂不可用', icon: 'none' });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
recorder.onError(() => {
|
||||
this.setData({ voiceRecording: false });
|
||||
wx.hideLoading();
|
||||
wx.showToast({ title: '录音失败,请重试', icon: 'none' });
|
||||
});
|
||||
},
|
||||
|
||||
/* ── 自定义常备调料 ── */
|
||||
editStaples() {
|
||||
this.setData({ showStapleEditor: true, stapleEditValue: '' });
|
||||
},
|
||||
|
||||
onStapleInput(e) {
|
||||
this.setData({ stapleEditValue: e.detail.value });
|
||||
},
|
||||
|
||||
addStaple() {
|
||||
const name = this.data.stapleEditValue.trim();
|
||||
if (!name) return;
|
||||
if (this.data.staples.includes(name)) {
|
||||
wx.showToast({ title: '已存在', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
const staples = [...this.data.staples, name];
|
||||
this.setData({ staples, stapleEditValue: '' });
|
||||
storage.set('custom_staples', staples);
|
||||
},
|
||||
|
||||
removeStaple(e) {
|
||||
const name = e.currentTarget.dataset.name;
|
||||
const staples = this.data.staples.filter(s => s !== name);
|
||||
this.setData({ staples });
|
||||
storage.set('custom_staples', staples);
|
||||
},
|
||||
|
||||
closeStapleEditor() {
|
||||
this.setData({ showStapleEditor: false });
|
||||
},
|
||||
|
||||
/* ── 开盒 ── */
|
||||
openBox() {
|
||||
if (this.data.ingredients.length === 0) {
|
||||
wx.showToast({ title: '请先输入食材', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
// 将用户自定义的常备调料一并传入后端
|
||||
const payload = {
|
||||
ingredients: this.data.ingredients,
|
||||
staples: this.data.staples
|
||||
};
|
||||
const params = encodeURIComponent(JSON.stringify(payload));
|
||||
wx.navigateTo({ url: '/pages/recipe-list/recipe-list?payload=' + params });
|
||||
}
|
||||
});
|
||||
6
miniapp/pages/fridge-input/fridge-input.json
Normal file
6
miniapp/pages/fridge-input/fridge-input.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"ingredient-tag": "/components/ingredient-tag/ingredient-tag"
|
||||
},
|
||||
"navigationBarTitleText": "冰箱盲盒"
|
||||
}
|
||||
66
miniapp/pages/fridge-input/fridge-input.wxml
Normal file
66
miniapp/pages/fridge-input/fridge-input.wxml
Normal file
@@ -0,0 +1,66 @@
|
||||
<view class="fridge-page">
|
||||
<view class="title">冰箱里有什么?</view>
|
||||
|
||||
<view class="input-area">
|
||||
<input class="ingredient-input"
|
||||
placeholder="输入食材名称"
|
||||
value="{{inputValue}}"
|
||||
bind:input="onInput"
|
||||
bind:confirm="addIngredient"
|
||||
/>
|
||||
<view class="voice-btn {{voiceRecording ? 'recording' : ''}}" bind:tap="voiceInput">
|
||||
<text>{{voiceRecording ? '🔴' : '🎤'}}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<view class="section-title">常用食材</view>
|
||||
<view class="tag-list">
|
||||
<ingredient-tag icon="🥚" name="鸡蛋" selected="{{selected['鸡蛋']}}" bind:toggle="onToggle" />
|
||||
<ingredient-tag icon="🍅" name="西红柿" selected="{{selected['西红柿']}}" bind:toggle="onToggle" />
|
||||
<ingredient-tag icon="🍗" name="鸡胸肉" selected="{{selected['鸡胸肉']}}" bind:toggle="onToggle" />
|
||||
<ingredient-tag icon="🧅" name="洋葱" selected="{{selected['洋葱']}}" bind:toggle="onToggle" />
|
||||
<ingredient-tag icon="🥔" name="土豆" selected="{{selected['土豆']}}" bind:toggle="onToggle" />
|
||||
<ingredient-tag icon="🌶️" name="青椒" selected="{{selected['青椒']}}" bind:toggle="onToggle" />
|
||||
<ingredient-tag icon="🥦" name="胡萝卜" selected="{{selected['胡萝卜']}}" bind:toggle="onToggle" />
|
||||
<ingredient-tag icon="🥬" name="西兰花" selected="{{selected['西兰花']}}" bind:toggle="onToggle" />
|
||||
<ingredient-tag icon="🥕" name="生菜" selected="{{selected['生菜']}}" bind:toggle="onToggle" />
|
||||
<ingredient-tag icon="🥬" name="豆腐" selected="{{selected['豆腐']}}" bind:toggle="onToggle" />
|
||||
<ingredient-tag icon="🥩" name="猪肉" selected="{{selected['猪肉']}}" bind:toggle="onToggle" />
|
||||
<ingredient-tag icon="🐥" name="鸡腿" selected="{{selected['鸡腿']}}" bind:toggle="onToggle" />
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<view class="section-title">
|
||||
我的常备调料
|
||||
<text class="edit-link" bind:tap="editStaples">编辑</text>
|
||||
</view>
|
||||
<view class="tag-list staples">
|
||||
<text class="staple-tag" wx:for="{{staples}}" wx:key="*this">{{item}}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<button class="btn-primary btn-large" bind:tap="openBox" disabled="{{ingredients.length === 0}}">
|
||||
开盒做饭!
|
||||
</button>
|
||||
|
||||
<!-- 常备调料编辑弹窗 -->
|
||||
<view class="modal-mask" wx:if="{{showStapleEditor}}" bind:tap="closeStapleEditor"></view>
|
||||
<view class="modal-sheet {{showStapleEditor ? 'show' : ''}}">
|
||||
<view class="sheet-header">
|
||||
<text class="sheet-title">编辑常备调料</text>
|
||||
<text class="sheet-close" bind:tap="closeStapleEditor">完成</text>
|
||||
</view>
|
||||
<view class="sheet-input-row">
|
||||
<input class="sheet-input" placeholder="调料名称" value="{{stapleEditValue}}" bind:input="onStapleInput" bind:confirm="addStaple" />
|
||||
<view class="btn-add" bind:tap="addStaple">添加</view>
|
||||
</view>
|
||||
<view class="sheet-tags">
|
||||
<view class="sheet-tag" wx:for="{{staples}}" wx:key="*this">
|
||||
<text>{{item}}</text>
|
||||
<text class="tag-remove" bind:tap="removeStaple" data-name="{{item}}">✕</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
206
miniapp/pages/fridge-input/fridge-input.wxss
Normal file
206
miniapp/pages/fridge-input/fridge-input.wxss
Normal file
@@ -0,0 +1,206 @@
|
||||
/*
|
||||
* 冰箱盲盒 · 食材输入
|
||||
*/
|
||||
|
||||
.fridge-page {
|
||||
padding: var(--space-lg);
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
/* ── 标题 ── */
|
||||
.title {
|
||||
font-size: var(--text-headline);
|
||||
font-weight: 700;
|
||||
margin-bottom: var(--space-md);
|
||||
}
|
||||
|
||||
/* ── 输入区 ── */
|
||||
.input-area {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: var(--space-lg);
|
||||
}
|
||||
|
||||
.ingredient-input {
|
||||
flex: 1;
|
||||
height: 88rpx;
|
||||
background: var(--color-surface);
|
||||
border-radius: var(--radius-lg);
|
||||
padding: 0 var(--space-md);
|
||||
font-size: var(--text-body);
|
||||
box-shadow: var(--shadow-sm);
|
||||
margin-right: var(--space-sm);
|
||||
}
|
||||
|
||||
.voice-btn {
|
||||
width: 88rpx;
|
||||
height: 88rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: var(--color-primary);
|
||||
border-radius: var(--radius-lg);
|
||||
font-size: 36rpx;
|
||||
transition: background 0.15s ease;
|
||||
}
|
||||
|
||||
.voice-btn:active {
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
.voice-btn.recording {
|
||||
background: #E53935;
|
||||
animation: voicePulse 0.6s ease-in-out infinite alternate;
|
||||
}
|
||||
|
||||
@keyframes voicePulse {
|
||||
from { transform: scale(1); }
|
||||
to { transform: scale(1.08); }
|
||||
}
|
||||
|
||||
/* ── 分区 ── */
|
||||
.section {
|
||||
margin-bottom: var(--space-lg);
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: var(--text-body-sm);
|
||||
font-weight: 600;
|
||||
color: var(--color-text-secondary);
|
||||
margin-bottom: var(--space-sm);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.tag-list {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
/* ── 常备调料 ── */
|
||||
.staple-tag {
|
||||
display: inline-flex;
|
||||
padding: 8rpx var(--space-md);
|
||||
border-radius: var(--radius-full);
|
||||
background: #F5F2EE;
|
||||
font-size: var(--text-body-sm);
|
||||
color: var(--color-text-muted);
|
||||
margin: 4rpx 8rpx;
|
||||
}
|
||||
|
||||
.edit-link {
|
||||
font-size: var(--text-body-sm);
|
||||
color: var(--color-primary);
|
||||
font-weight: 500;
|
||||
margin-left: 8rpx;
|
||||
}
|
||||
|
||||
/* ── 开盒按钮 ── */
|
||||
.btn-large {
|
||||
width: 100%;
|
||||
height: 100rpx;
|
||||
font-size: var(--text-body);
|
||||
margin-top: var(--space-xl);
|
||||
}
|
||||
|
||||
/* ── 调料编辑弹窗 ── */
|
||||
.modal-mask {
|
||||
position: fixed;
|
||||
top: 0; left: 0; right: 0; bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.45);
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
.modal-sheet {
|
||||
position: fixed;
|
||||
left: 0; right: 0; bottom: 0;
|
||||
background: var(--color-surface);
|
||||
border-radius: var(--radius-lg) var(--radius-lg) 0 0;
|
||||
padding: var(--space-lg);
|
||||
padding-bottom: calc(var(--space-lg) + constant(safe-area-inset-bottom));
|
||||
padding-bottom: calc(var(--space-lg) + env(safe-area-inset-bottom));
|
||||
z-index: 101;
|
||||
transform: translateY(100%);
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
|
||||
.modal-sheet.show {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
.sheet-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: var(--space-md);
|
||||
}
|
||||
|
||||
.sheet-title {
|
||||
font-size: var(--text-subtitle);
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.sheet-close {
|
||||
font-size: var(--text-body);
|
||||
color: var(--color-primary);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.sheet-input-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: var(--space-md);
|
||||
}
|
||||
|
||||
.sheet-input {
|
||||
flex: 1;
|
||||
height: 80rpx;
|
||||
background: #F7F5F2;
|
||||
border-radius: var(--radius-md);
|
||||
padding: 0 var(--space-md);
|
||||
font-size: var(--text-body);
|
||||
margin-right: var(--space-sm);
|
||||
}
|
||||
|
||||
.btn-add {
|
||||
width: 120rpx;
|
||||
height: 80rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: var(--color-primary);
|
||||
color: #FFFFFF;
|
||||
border-radius: var(--radius-md);
|
||||
font-size: var(--text-body-sm);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.btn-add:active {
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
.sheet-tags {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
max-height: 360rpx;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.sheet-tag {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 8rpx var(--space-md);
|
||||
background: #F7F5F2;
|
||||
border-radius: var(--radius-full);
|
||||
font-size: var(--text-body-sm);
|
||||
color: var(--color-text);
|
||||
margin-right: 12rpx;
|
||||
margin-bottom: 12rpx;
|
||||
}
|
||||
|
||||
.tag-remove {
|
||||
margin-left: 8rpx;
|
||||
font-size: var(--text-caption);
|
||||
color: var(--color-text-muted);
|
||||
padding: 2rpx;
|
||||
}
|
||||
Reference in New Issue
Block a user