1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- import { showLoading, hideLoading } from './plugIn/globalLoading'
- import { J_STORAGE_KEY } from '../config/constant'
- const request = (url, data, method = 'GET') => new Promise((resolve, reject) => {
- const header = {
- 'Content-Type': 'application/json'
- }
- const res = uni.getStorageSync(J_STORAGE_KEY)
- const token = res.token
- if (token) {
- header.Authorization = token
- }
- showLoading()
- uni.request({
- url,
- data,
- method,
- header,
- success: (res) => {
- hideLoading()
- 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(J_STORAGE_KEY)
- uni.navigateTo({
- url: '/pages_category_page2/userModule/login'
- })
- } else {
- uni.showToast({
- title: res.data.message,
- icon: 'none'
- })
- }
- } else {
- reject(res)
- }
- },
- fail: (res) => {
- hideLoading()
- reject(res)
- }
- })
- })
- const request1 = (url, data, method = 'GET') => new Promise((resolve, reject) => {
- const header = {
- 'Content-Type': 'application/json',
- 'tenant': 'MDAwMA=='
- }
- showLoading()
- uni.request({
- url,
- data,
- method,
- header,
- success: (res) => {
- hideLoading()
- if (res.data.code === '200' || data.code === '') {
- resolve(res.data)
- } else {
- reject(res)
- }
- },
- fail: (res) => {
- hideLoading()
- reject(res)
- }
- })
- })
- module.exports = {
- request,
- request1
- }
|