12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- import config from '@/common/config.js'
- const baseUrl =config.url
-
- const request = (url = '', type = 'GET',data = {}, header = {
- }) => {
- console.log(url.toLowerCase() +' ===='+url.toLowerCase().includes('/user/validateuser'))
-
- const token = uni.getStorageSync('token');
- console.log('token',token)
- if(!token && !url.toLowerCase().includes('/user/validateuser')){
- // 执行没有登录的逻辑
- uni.showToast({
- icon:'none',
- title:'token过期请重新登录'
- })
-
- setTimeout(function() {
- uni.navigateTo({
- url:'../index/login'
- })
- }, 1500);
-
- return;
- }
-
- if(token){
-
- header={
- 'Authorization':token
- }
-
- }
-
- return new Promise((resolve, reject) => {
- uni.request({
- method: type,
- url: baseUrl + url,
- data: data,
- header: header,
- dataType: 'json',
- }).then((response) => {
- let [error, res] = response;
- resolve(res.data);
- }).catch(error => {
- let [err, res] = error;
- reject(err)
- })
- });
- }
- export default request
|