const API_BASE_URL = 'http://localhost:3001'; Page({ data: { loading: true, error: '', brand: {}, services: [] }, onLoad() { this.load(); }, load() { this.setData({ loading: true, error: '' }); Promise.all([this.request('/public/brand'), this.request('/public/services')]).then(([brand, services]) => { wx.setNavigationBarTitle({ title: brand.name || '阿桂的家常小灶' }); this.setData({ brand, services, loading: false }); }).catch(() => this.setData({ loading: false, error: '暂时无法加载内容' })); }, request(path) { return new Promise((resolve, reject) => wx.request({ url: API_BASE_URL + path, success: (res) => res.statusCode < 400 ? resolve(res.data) : reject(res), fail: reject })); }, selectService(event) { wx.navigateTo({ url: '/pages/booking/index?serviceId=' + encodeURIComponent(event.currentTarget.dataset.id) }); }, goServices() { wx.navigateTo({ url: '/pages/services/index' }); }, goPrivateChef() { wx.navigateTo({ url: '/pages/booking/index?type=private_chef' }); }, goBookings() { wx.navigateTo({ url: '/pages/bookings/index' }); }, goHome() { wx.reLaunch({ url: '/pages/index/index' }); }, });