import {signVal,md5} from "./MD5.js" import { getGuid, getTimeStamp } from './guid' const successCode = 200 /** * 简易封装网络请求 * @param {*} options */ export default function fetch(options) { const { url, payload = {}, method = 'GET', showToast = true } = options const client = '2' const guid = getGuid() + '' const timestamp = getTimeStamp() + '' const header = { // "x-token": uni.getStorageSync('token'), // "client": client, // "guid": guid, // "timestamp": timestamp, // "sig": md5(client + 'lz2019_random' + guid + timestamp), // "x-app-id": "lzyd", // "authorization": uni.getStorageSync('token')?uni.getStorageSync('token'):'' } if (method === 'POST') { header['content-type'] = 'application/json' } else if (method === 'get') { header['content-type'] = 'application/x-www-form-urlencoded' } return new Promise((resolve, reject) => { return uni.request({ url, method, data: signVal(payload), header: header, success:(res) => { resolve(res.data) }, fail: (err) => { reject("") uni.showToast({ title: '请求失败', icon: 'none' }) } }) }).catch((e) => {}) }