123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- import config from "@/config";
- import store from "../store";
- const logout = () => {
- }
- /* 消息提示 */
- const tip = (msg) => {
- let types = type || 'warning';
- if (msg == 'RET_INVALID_PASSWORD') msg = '账号密码有误'
- if (msg == 'RET_INVALID_CODE') msg = '短信验证码有误'
- uni.showToast({
- title: msg,
- icon: 'none'
- })
- }
- const errorCallBack = () => {
- // 请求失败处理
- tip('出错了,请联系管理员~');
- resolve({
- state: false,
- data: null,
- msg: 'error'
- });
- uni.hideLoading();
- }
- export function request(options) {
- return new Promise((resolve, reject) => {
- let header = options.header || {
- 'Content-Type': 'application/json'
- }
- if (uni.getStorageSync('token')) header['token'] = uni.getStorageSync('token');
- uni.request({
- url: config.baseUrl + options.url, // 服务器url
- method: options.method || 'GET', // 请求方法,默认为GET
- data: options.data || {}, // 请求参数
- header: header, // 设置请求的 header
- success: (res) => {
- // 请求成功
- if (res.statusCode === 200) {
- let data = res.data;
- if (data.code != '200' && data.code != '20001') tip(data.message || data.msg);
- resolve({
- state: data.code == '200',
- data: data.data,
- msg: data.code == '200' ? 'success' : 'error'
- });
- } else {
- errorCallBack(resolve);
- }
- },
- fail: () => errorCallBack(resolve)
- });
- });
- };
|