| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- import {getPhpToken} from "../utils/readAppInfo"
- export let baseURL = 'https://testapi.hxxfb.com/'
- // 请求超出时间
- const timeout = 50000
- // const token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJhcGkuaHh4ZmIuY29tIiwiYXVkIjoiYXBpLmh4eGZiLmNvbSIsImlhdCI6MTc0MDM3MTM1NSwibmJmIjoxNzQwMzcxMzU1LCJleHAiOjE3NTExNzEzNTUsImp0aSI6WzI5OCwibWVyIl19.j2f8VwdwWY4zBpcijHntzUZ9YUms2SxChaVsYf7KnPs"
- // const token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJzaG9wLmh4eGZiLmNvbSIsImF1ZCI6InNob3AuaHh4ZmIuY29tIiwiaWF0IjoxNzQwNTY5NDI3LCJuYmYiOjE3NDA1Njk0MjcsImV4cCI6MTc1MTM2OTQyNywianRpIjpbMzU0LCJtZXIiXX0.aZrICBozUFC0lvqxHgJMKFdhQlDHG1eC9UVAPzDHs5s"
- // const token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJhcGkuaHh4ZmIuY29tIiwiYXVkIjoiYXBpLmh4eGZiLmNvbSIsImlhdCI6MTc0MDU3MTQ0OCwibmJmIjoxNzQwNTcxNDQ4LCJleHAiOjE3NTEzNzE0NDgsImp0aSI6WzM1NCwibWVyIl19.PVwYv71Gq9RxTxQclUoFMgc8cZt0ju3zQkxk6SGCQJw"
- const token = ""
- export const phpToken = uni.getStorageSync('phpToken') || token
- // 需要修改token,和根据实际修改请求头
- export function myRequestPhp(options) {
- let url = options.url;
- let method = options.method || "get";
- let data = options.data || {};
- let contentType = options.contentType || "application/json;charset=UTF-8";
- let header = {
- 'Content-Type': contentType,
- "X-Token": phpToken,
- ...options.header
- }
- return new Promise((resolve, reject) => {
- uni.request({
- url: baseURL + url,
- method: method,
- header: header,
- data: data,
- timeout,
- success:async function(response) {
- const res = response
- const message = res.data && res.data.message || ""
- // console.log(res, "resresresresres")
- // console.log(message, "99999message")
- if (res.data.status == 200) { //接口返回200走一下操作
- resolve(res)
- } else if (res.data.status == 500) { //接口返回500走一下操作
- return uni.showToast({
- title: res.data.error,
- icon: 'none'
- })
- } else if ((res.data.status == 400 || res.data.status == 40000) && (message.indexOf('登录') > -1 || message.indexOf('过期') > -1 || message.indexOf('token') > -1)) { //接口返回400走一下操作500走一下操作
- await getPhpToken()
- resolve(res)
- } else { //除了500都会走以下操作
- // console.log(message, "messag9999e")
- uni.showToast({
- title: message,
- icon: 'none',
- duration: 6000
- })
- // reject(res)
- }
- },
- fail(err) {
- console.log(err,"接口")
- if (err.errMsg.indexOf('request:fail') !== -1) {
- uni.showToast({
- title: '网络异常',
- icon: "error",
- duration: 2000
- })
- } else {
- uni.showToast({
- title: '未知异常',
- duration: 2000
- })
- }
- uni.hideToast();
- reject(err);
- },
- complete() {
- // uni.hideToast();
- }
- });
- }).catch(() => {
- uni.hideToast();
- });
- };
|