基础项目结构文档:
接口封装api.js
包含接口,小程序官方api【例:弹窗,加载效果】进行封装,其他页面调用只需调用,减少代码冗余
接口封装
文件名:api.js
路径:/api/api.js
主要内容说明:接口、小程序官方的操作状态提示
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,
}
© 版权声明
文章版权归作者所有,未经允许请勿转载。