You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
142 lines
4.0 KiB
142 lines
4.0 KiB
import { createApp } from 'vue'
|
|
import App from './App.vue'
|
|
import router from './router/index'
|
|
import { _createStore } from './vuex';
|
|
|
|
|
|
// 引入http请求插件
|
|
import $API from './utils/api'
|
|
import $http from './utils/http'
|
|
import { addRequestInterceptor, addResponseInterceptor } from './utils/http'
|
|
import Qs from 'qs';
|
|
|
|
// reset 样式
|
|
import '@/assets/css/reset.css'
|
|
// import '@/assets/css/swiper6.min.css'
|
|
import '@/assets/js/rem.js'
|
|
// import '@/assets/js/swiper6.min.js'
|
|
import '@/assets/css/style.scss'
|
|
|
|
import { Toast, Swipe, SwipeItem, Popup, Picker, Tab, Tabs, Dialog, Uploader, DatetimePicker, Slider, Checkbox, CheckboxGroup, Form, Field, CellGroup, Area, Button, Progress, List} from 'vant';
|
|
|
|
import 'vant/lib/index.css';
|
|
|
|
Toast.setDefaultOptions({ duration: 1500 });
|
|
|
|
|
|
// 路由拦截器
|
|
// router.beforeEach((to, from, next) => {
|
|
// if (to.matched.length != 0) {
|
|
// if (to.meta.requireAuth) { // 判断该路由是否需要登录权限
|
|
// if (Boolean(localStorage.getItem("userInfo"))) { // 通过vuex state获取当前的user是否存在
|
|
// next();
|
|
// } else {
|
|
// next({
|
|
// path: '/login',
|
|
// query: { redirect: to.fullPath } // 将跳转的路由path作为参数,登录成功后跳转到该路由
|
|
// })
|
|
// }
|
|
// } else {
|
|
// if (Boolean(localStorage.getItem("userInfo"))) { // 判断是否登录
|
|
// if (to.path != "/" && to.path != "/login") { //判断是否要跳到登录界面
|
|
// next();
|
|
// } else {
|
|
// /**
|
|
// * 防刷新,如果登录,修改路由跳转到登录页面,修改路由为登录后的首页
|
|
// */
|
|
// next({
|
|
// path: '/standardizedData/groupAirline'
|
|
// })
|
|
// }
|
|
// } else {
|
|
// next();
|
|
// }
|
|
// }
|
|
// } else {
|
|
// next({
|
|
// path: '/login',
|
|
// query: { redirect: to.fullPath } // 将跳转的路由path作为参数,登录成功后跳转到该路由
|
|
// })
|
|
// }
|
|
// })
|
|
|
|
|
|
// request前自动添加api配置
|
|
addRequestInterceptor(
|
|
(config) => {
|
|
let Authorization = "";
|
|
if (typeof localStorage !== "undefined") {
|
|
const userData = JSON.parse(localStorage.getItem('userData')) || "";
|
|
if (userData) {
|
|
let token = '';
|
|
if (userData.token) {
|
|
token = userData.token
|
|
} else if(userData.data.token){
|
|
token = userData.data.token
|
|
}
|
|
Authorization = "Bearer " + token;
|
|
}
|
|
config.headers['Authorization'] = Authorization;
|
|
}
|
|
config.transformRequest = [
|
|
function(data){
|
|
return Qs.stringify(data) //使用Qs将请求参数序列化
|
|
}]
|
|
/*统一加/api前缀*/
|
|
//config.url = `/api${config.url}`
|
|
return config
|
|
},
|
|
(error) => {
|
|
return Promise.reject(error)
|
|
}
|
|
)
|
|
|
|
// http 返回response前处理
|
|
addResponseInterceptor(
|
|
(response) => {
|
|
/*todo 在这里统一前置处理请求响应 */
|
|
return Promise.resolve(response.data)
|
|
},
|
|
(error) => {
|
|
/*
|
|
* todo 统一处理500、400等错误状态
|
|
* 这里reject下,交给entry-server.js的处理
|
|
*/
|
|
const { response, request } = error
|
|
return Promise.reject({ code: response.status, data: response.data, method: request.method, path: request.path })
|
|
}
|
|
)
|
|
|
|
const app = createApp(App)
|
|
const store = _createStore();
|
|
|
|
app.use(router)
|
|
app.use(store)
|
|
|
|
app.use(Toast)
|
|
.use(Swipe)
|
|
.use(Popup)
|
|
.use(Picker)
|
|
.use(Tab)
|
|
.use(Tabs)
|
|
.use(Dialog)
|
|
.use(Uploader)
|
|
.use(DatetimePicker)
|
|
.use(SwipeItem)
|
|
.use(Slider)
|
|
.use(Checkbox)
|
|
.use(CheckboxGroup)
|
|
.use(Form)
|
|
.use(Field)
|
|
.use(CellGroup)
|
|
.use(Area)
|
|
.use(Button)
|
|
.use(Progress)
|
|
.use(List);
|
|
|
|
// app.config.globalProperties.$coverUrl = 'http://192.168.99.67:8080'
|
|
app.config.globalProperties.$coverUrl = 'http://58.49.77.70:8443'
|
|
|
|
app.config.globalProperties.$API = $API
|
|
app.config.globalProperties.$http = $http
|
|
app.mount('#app')
|