123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- // 配置请求根路径
- const BASE_URL = process.env.UNI_BASE_URL;
- const request = (url, data, method = 'GET') => {
- return new Promise((resolve, reject) => {
- let header = {
- "Content-Type": "application/json"
- }
- const res = uni.getStorageSync('storage_key');
- const token = res.token
- if (token) {
- header['Authorization'] = token
- }
- uni.request({
- url: url,
- data: data,
- method: method,
- header: header,
- success: res => {
- if (res.statusCode == 200) {
- if (res.data.code === "200" || res.data.code === "") {
- resolve(res.data)
- } else if (res.data.code === "20004" || res.data.code === "20005") {
- uni.removeStorageSync("storage_key")
- uni.navigateTo({
- url: '/pages/login/index'
- })
- } else {
- uni.showToast({
- title: res.data.message,
- icon: "none"
- })
- }
- } else {
- reject(res)
- }
- },
- fail: res => {
- reject(res)
- },
- })
- });
- }
- //不带token接口请求,首页
- const request1 = (url, data, method = 'GET') => {
- return new Promise((resolve, reject) => {
- let header = {
- 'Content-Type': 'application/json',
- 'tenant': 'MDAwMA==',
- }
- uni.request({
- url: url,
- data: data,
- method: method,
- header: header,
- success: res => {
- if (res.data.code === "200" || res.data.code == "" || data.code === "") {
- resolve(res.data)
- } else {
- reject(res)
- }
- },
- fail: res => {
- reject(res)
- }
- })
- });
- }
- export {
- request,
- request1,
- BASE_URL
- }
|