优化h5项目

This commit is contained in:
zhuoda
2021-01-10 20:21:30 +08:00
parent 7e580440f0
commit 606e763126
61 changed files with 878 additions and 923 deletions

View File

@@ -0,0 +1,65 @@
import Axios from 'axios';
import config from '@/config';
import cookie from '@/lib/cookie';
import { Toast } from 'vant';
export const baseUrl = config.baseUrl.erpApiUrl;
const axios = Axios.create({
baseURL: baseUrl,
timeout: 30000,
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
});
// 添加请求拦截器
axios.interceptors.request.use(
function(config) {
const token = cookie.getToken();
if (token) {
config.headers['x-access-token'] = token;
}
return config;
},
function(error) {
return Promise.reject(error);
}
);
// 添加响应拦截器
axios.interceptors.response.use(
res => {
const { data } = res;
if (data && data.code && data.code !== 1) {
if (data.code === 121) {
cookie.clearToken();
localStorage.clear();
window.location.href = window.location.pathname + '#/login';
Toast.fail('未登录,或登录失效,请登录');
return;
} else if (data.code === 502) {
window.location.href = window.location.pathname + '#/500';
return;
} else {
Toast.fail(data.msg);
return Promise.reject(res);
}
}
return Promise.resolve(data);
},
error => {
Toast.fail('服务内部错误');
return Promise.reject(error);
}
);
export const postAxios = (url, data, config) => {
return axios.post(url, data, config);
};
export const getAxios = (url, data) => {
return axios.get(url, {
params: data
});
};

View File

@@ -1,6 +1,9 @@
/*
* @Description:
* @Author: zhuoda
* @Author: hanyu
* @Date: 2020-05-28 12:46:06
* @LastEditTime: 2020-07-08 09:16:15
* @LastEditors: hy
*/
// smart sentry
import * as Sentry from '@sentry/browser';

View File

@@ -1,84 +0,0 @@
// 处理table操作按钮
const tableAction = (h, array) => {
let btnArray = [];
let btnMore = [];
array.map((item, index) => {
if (index < 2) {
let btn = h(
'a',
{
props: {
type: !index ? 'primary' : 'info',
size: 'small',
to: item.to ? item.to : '',
target: item.target ? item.target : '_self',
ghost: true
},
style: {
marginLeft: '5px'
},
directives: item.directives,
on: {
click: item.action
}
},
item.title
);
btnArray.push(btn);
} else {
btnMore.push(
h(
'DropdownItem',
{
nativeOn: {
click: item.action
}
},
item.title
)
);
}
});
let dropdown = h(
'Dropdown',
{
props: {
transfer: true
}
},
[
h(
'a',
{
props: {
type: 'default',
size: 'small'
},
style: {
marginLeft: '5px'
}
},
[
h('span', '更多'),
h('Icon', {
props: {
type: 'ios-arrow-down'
}
})
]
),
h(
'DropdownMenu',
{
slot: 'list'
},
btnMore
)
]
);
if (array.length > 2) {
btnArray.push(dropdown);
}
return btnArray;
};
export default tableAction;