refactor: 模块化小程序配置与请求逻辑
This commit is contained in:
1 parent
5b5ba9f7da
commit
34ec893369
11 files changed
+67
-20
No files matched your search
@@ -1,2 +1,2 @@
|
||||
const API = getApp().globalData.apiBaseUrl;
|
||||
Page({data:{loading:true,services:[],filtered:[],category:'package'},onLoad(){wx.request({url:API+'/public/services',success:res=>this.setData({services:res.data,filtered:res.data.filter(x=>x.priceAmount!==null),loading:false}),fail:()=>this.setData({loading:false})})},switchCategory(e){const category=e.currentTarget.dataset.category;const filtered=category==='package'?this.data.services.filter(x=>x.priceAmount!==null):this.data.services.filter(x=>x.priceAmount===null);this.setData({category,filtered})},book(e){wx.navigateTo({url:'/pages/booking/index?serviceId='+e.currentTarget.dataset.id})}});
|
||||
const { request } = require('../../utils/request');
|
||||
Page({ data: { loading: true, error: '', services: [], filtered: [], category: 'package' }, onLoad() { request('/public/services').then((services) => this.setData({ services, filtered: services.filter((item) => item.priceAmount !== null), loading: false })).catch(() => this.setData({ loading: false, error: '服务加载失败' })); }, switchCategory(e) { const category = e.currentTarget.dataset.category; const filtered = category === 'package' ? this.data.services.filter((item) => item.priceAmount !== null) : this.data.services.filter((item) => item.priceAmount === null); this.setData({ category, filtered }); }, book(e) { wx.navigateTo({ url: '/pages/booking/index?serviceId=' + encodeURIComponent(e.currentTarget.dataset.id) }); } });
|
||||
Reference in new issue
Block a user