12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- import env from "./config.js"
- export const request = (options) => {
- return new Promise((resolve, reject) => {
-
-
-
-
-
-
-
- let token = uni.getStorageSync('AppAuthorization');
- let header={}
- header=options.headers || {'Content-Type': 'application/json'}
- if(!token){
- header=options.headers || {'Content-Type': 'application/json'}
- }else{
- if(options.headers){
- options.headers["AppAuthorization"]=token
- }
- header=options.headers || {'Content-Type': 'application/json','AppAuthorization': token}
- }
-
-
-
-
-
- uni.request({
- header:header,
- url: env.BASEURL + options.url,
- method: options.method || 'GET',
- data: options.data || {},
- dataType:options.dataType||"json",
- timeout:options.timeout||40000,
- success: (res) => {
-
- if (res.data.code == 200||(res.data.meta&&res.data.meta.success==true)) {
-
-
-
- resolve(res)
- }else{
-
- if(res.data.msg){
- uni.showToast({
- icon: "none",
- title: res.data.msg
- })
- }
- let noLogin = [10003,10004]
- if (noLogin.includes(res.data.code)) {
- setTimeout(() => {
- uni.navigateTo({
- url: '/pages/myinfo/login'
- });
- }, 1000);
- }
- resolve(res)
-
- }
- },
- fail: (err) => {
- console.log('request-fail>>>',options.url,err)
-
-
-
-
-
- reject(err)
- },
- complete() {
- if (!options.hideload) {
- uni.hideLoading()
- }
- }
- })
- })
- }
|