基础项目结构文档:
接口封装api.js
包含接口,小程序官方api【例:弹窗,加载效果】进行封装,其他页面调用只需调用,减少代码冗余
接口封装
文件名:api.js
路径:/api/api.js
主要内容说明:接口、小程序官方的操作状态提示
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | const addApi = '/api/'; // ---登录getkey const getkey = addApi + 'server/getkey_pc'; // ---报警事件 const alarmConfig = addApi + 'event/alarm_config'; const realEvt = addApi + 'event/real_evt'; const realEvtCount = addApi + 'event/real_evt_count'; const confirmEvt = addApi + 'event/confirm_evt'; const getEquipEvt = addApi + 'event/get_equip_evt'; const getSetEvt = addApi + 'event/get_set_evt'; /** * 我是华丽的分割线------------------------------------------------- */ // 状态提示 function showLoading(t) { // 请求前的loading wx.showLoading({ title: t ? t : '数据加载中...', mask: true }) } // 状态提示 function showToast(t, icon) { wx.showToast({ title: t ? t : '操作失败', icon: icon ? icon : 'none', //loading/none duration: 1600 }) } // 返回上一页 function navBack() { wx.navigateBack({ delta: 1 }) } // 返回首页 function navHome() { wx.switchTab({ url: '/pages/home/home', }) } // 保留当前页面跳转新页面,参数为跳转路径 function navTo(e){ wx.navigateTo({ url: e }) } // 导出 module.exports = { // 操作提示 showLoading, showToast, navHome, navBack, navTo, // 接口 getkey, setGenerateImageData, alarmConfig, realEvt, realEvtCount, confirmEvt, getEquipEvt, } |