|
@@ -1,4 +1,6 @@
|
|
|
-import { getSystemInfoAsync } from '@/utils/system';
|
|
|
+import {
|
|
|
+ getSystemInfoAsync
|
|
|
+} from '@/utils/system';
|
|
|
import store from '@/store';
|
|
|
|
|
|
const BASE_URL = 'https://test.api.chelvc.com';
|
|
@@ -22,16 +24,18 @@ export function request(options) {
|
|
|
title: options.loadingText || '加载中...',
|
|
|
});
|
|
|
return new Promise(async (resolve, reject) => {
|
|
|
- const { deviceId, osName, osVersion } = await getSystemInfoAsync();
|
|
|
+ const {
|
|
|
+ deviceId,
|
|
|
+ osName,
|
|
|
+ osVersion
|
|
|
+ } = await getSystemInfoAsync();
|
|
|
const access_token = store.getters.access_token;
|
|
|
return uni.request({
|
|
|
timeout: TIME_OUT,
|
|
|
url: BASE_URL + options.url,
|
|
|
method: options.method.toUpperCase() || 'GET',
|
|
|
data: options.data,
|
|
|
- header: Object.assign(
|
|
|
- {},
|
|
|
- {
|
|
|
+ header: Object.assign({}, {
|
|
|
Authorization: `Bearer ${access_token}`,
|
|
|
'Content-Type': 'application/json; charset=utf-8',
|
|
|
client_id: 'chelvc_client',
|
|
@@ -47,15 +51,24 @@ export function request(options) {
|
|
|
options.header,
|
|
|
),
|
|
|
success: res => {
|
|
|
- if (res.statusCode !== 200) {
|
|
|
- uni.showToast({
|
|
|
- icon: 'none',
|
|
|
- title: res.data.message || errStatus[res.statusCode],
|
|
|
- duration: 2000,
|
|
|
- });
|
|
|
- reject(res);
|
|
|
- } else {
|
|
|
- resolve(res.data);
|
|
|
+ switch (res.statusCode) {
|
|
|
+ case 401:
|
|
|
+ uni.reLaunch({
|
|
|
+ url: '/pages/login/index'
|
|
|
+ })
|
|
|
+ reject(res);
|
|
|
+ break;
|
|
|
+ // 无权限
|
|
|
+ case 403:
|
|
|
+ uni.showToast({
|
|
|
+ title: msg,
|
|
|
+ icon: 'none',
|
|
|
+ duration: 2000
|
|
|
+ });
|
|
|
+ reject(res);
|
|
|
+ break
|
|
|
+ default:
|
|
|
+ resolve(res.data);
|
|
|
}
|
|
|
},
|
|
|
fail: err => {
|
|
@@ -81,7 +94,11 @@ export function request(options) {
|
|
|
* @returns
|
|
|
*/
|
|
|
export async function uploadFile(filePath) {
|
|
|
- const { deviceId, osName, osVersion } = await getSystemInfoAsync();
|
|
|
+ const {
|
|
|
+ deviceId,
|
|
|
+ osName,
|
|
|
+ osVersion
|
|
|
+ } = await getSystemInfoAsync();
|
|
|
const access_token = store.getters.access_token;
|
|
|
uni.showLoading({
|
|
|
title: '正在上传...',
|