refactor: 模块化小程序配置与请求逻辑
This commit is contained in:
1 parent
5b5ba9f7da
commit
34ec893369
11 files changed
+67
-20
No files matched your search
@@ -1,18 +1,17 @@
|
||||
const API_BASE_URL = getApp().globalData.apiBaseUrl;
|
||||
const { request } = require('../../utils/request');
|
||||
const config = require('../../utils/config');
|
||||
|
||||
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 || '阿桂的家常小灶' });
|
||||
Promise.all([request('/public/brand'), request('/public/services')]).then(([brand, services]) => {
|
||||
getApp().globalData.brand = brand;
|
||||
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' }); },
|
||||
|
||||
Reference in new issue
Block a user