接口请求
uni.request 接口请求封装,包含登录验证、请求拦截、响应拦截、错误处理等
import request from '@/utils/request';
// get请求
const getUserInfo = (params?: any) => request.get('user/getUserInfo', params);
// post请求
const updatePassword = (params?: any) => request.post('user/updatePassword', params);
// 上传文件
const uplaodFile = (filePath: string, data?: any, callBack?: any) => request.upload('upload/file', 'file', filePath, data, callBack);本地存储
对 uni.getStorageSync、uni.setStorageSync、uni.removeStorageSync、uni.clearStorageSync 进行封装
import storage from '@/utils/storage';
// 获取缓存
storage.get(token);
// 设置缓存
storage.set(token, 123456);
// 删除缓存
storage.delete(token);
// 清空缓存
storage.clear();微信公众号jssdk
对微信公众号jssdk方法封装
import wechat from '@/utils/wechat';
// 获取公众号授权url
wechat.authCodeUrl(url);
// 获取初始化页面链接
wechat.getConfigUrl();
// 初始化
wechat.config();
// 公众号授权登录
wechat.authLogin(code);
// 准备
wechat.ready();
// 页面分享
wechat.share(params, callback);
// 获取地理位置
wechat.getLocation();调用支付
系统对通用支付方法封装,可自行扩展
import pay from '@/utils/pay/pay';
// 微信支付
pay('WECHAT', params);
// 支付宝支付
pay('ALIPAY', params)