| | |
| | | import Vue from 'vue' |
| | | import ElementUI from 'element-ui'; |
| | | import 'element-ui/lib/theme-chalk/index.css'; |
| | | import VueAxios from 'vue-axios' |
| | | import $ from 'jquery' |
| | | import qs from 'qs' |
| | | import App from './App' |
| | | import Vue from "vue"; |
| | | import ElementUI from "element-ui"; |
| | | import "element-ui/lib/theme-chalk/index.css"; |
| | | import VueAxios from "vue-axios"; |
| | | import $ from "jquery"; |
| | | import qs from "qs"; |
| | | import App from "./App"; |
| | | import VueRouter from "vue-router"; |
| | | import router from './router/index' |
| | | import axios from 'axios' |
| | | import api from './assets/api/controller.js' |
| | | import swal from 'sweetalert' |
| | | import Big from 'big.js' |
| | | import router from "./router/index"; |
| | | import axios from "axios"; |
| | | import api from "./assets/api/controller.js"; |
| | | import swal from "sweetalert"; |
| | | import Big from "big.js"; |
| | | import VueBarcode from "vue-barcode"; |
| | | import Moment from 'moment' |
| | | import Moment from "moment"; |
| | | |
| | | Vue.prototype.$Big = Big; |
| | | |
| | | // 项目切换 |
| | | Vue.prototype.PROJECT = '检测中心' |
| | | Vue.prototype.PROJECT = "检测中心"; |
| | | // Vue.prototype.PROJECT = '装备电缆' |
| | | //本地 |
| | | // Vue.prototype.LOCATIONVUE = "http://127.0.0.1:80"; |
| | | // const javaApi = 'http://127.0.0.1:8001'; |
| | | const javaApi = 'http://172.20.10.5:8001'; |
| | | Vue.prototype.LOCATIONVUE = "http://127.0.0.1:80"; |
| | | const javaApi = "http://127.0.0.1:8001"; |
| | | // const javaApi = "http://192.168.0.170:8001"; |
| | | |
| | | //通信测试库 |
| | | // Vue.prototype.LOCATIONVUE = "http://10.1.13.77:8080"; |
| | | // const javaApi = 'http://10.1.13.77:8001'; |
| | | // const javaApi = "http://10.1.13.77:8001"; |
| | | |
| | | // 通信正式库 |
| | | Vue.prototype.LOCATIONVUE = "http://10.193.45.63:8080"; |
| | | const javaApi = 'https://ztwxlims.ztt.cn:7443/lims/'; |
| | | // Vue.prototype.LOCATIONVUE = "http://192.168.22.29:8080"; |
| | | // const javaApi = 'https://ztwxlims.ztt.cn:7443/lims/'; |
| | | // const javaApi = 'http://192.168.22.29:8001/lims/'; |
| | | |
| | | // //云 |
| | | // Vue.prototype.LOCATIONVUE = "http://114.132.189.42:8080"; |
| | |
| | | // const javaApi = 'http://10.16.173.59:8001'; |
| | | // const javaApi = 'http://192.168.92.249:8001'; |
| | | |
| | | Vue.prototype.HaveJson = (val) => { |
| | | return JSON.parse(JSON.stringify(val)) |
| | | } |
| | | Vue.prototype.javaApi = javaApi |
| | | Vue.prototype.$moment = Moment |
| | | Vue.prototype.HaveJson = val => { |
| | | return JSON.parse(JSON.stringify(val)); |
| | | }; |
| | | Vue.prototype.javaApi = javaApi; |
| | | Vue.prototype.$moment = Moment; |
| | | |
| | | Vue.use(VueAxios, axios) |
| | | Vue.config.productionTip = false |
| | | Vue.use(VueAxios, axios); |
| | | Vue.config.productionTip = false; |
| | | Vue.config.performance = true; |
| | | Vue.use(VueRouter); |
| | | Vue.use(ElementUI); |
| | | Vue.component('barcode', VueBarcode) |
| | | Vue.component("barcode", VueBarcode); |
| | | Vue.use(qs); |
| | | Vue.use(api); |
| | | |
| | | axios.defaults.baseURL = javaApi |
| | | axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8' |
| | | axios.defaults.withCredentials = true |
| | | axios.defaults.crossDomain = true |
| | | Vue.prototype.$axios = axios |
| | | axios.defaults.baseURL = javaApi; |
| | | axios.defaults.headers.post["Content-Type"] = |
| | | "application/x-www-form-urlencoded;charset=UTF-8"; |
| | | axios.defaults.withCredentials = true; |
| | | axios.defaults.crossDomain = true; |
| | | Vue.prototype.$axios = axios; |
| | | |
| | | import { |
| | | Message |
| | | } from 'element-ui'; |
| | | axios.interceptors.request.use(function(config) { |
| | | let tk = sessionStorage.getItem("token") |
| | | let token; |
| | | if (tk != undefined && tk != '') { |
| | | token = tk |
| | | } |
| | | if (token) { |
| | | config.headers['token'] = "" + token |
| | | // config.headers['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8' |
| | | // config.headers['Content-Type'] = 'application/json' |
| | | } |
| | | if ((config.method === 'post' || config.method === 'put')&&!config.noQs) { |
| | | config.data = qs.stringify(config.data) |
| | | } |
| | | if (config.headers['Content-Type'] == 'application/json'&&!config.noQs) { |
| | | config.data = qs.parse(config.data) |
| | | } |
| | | return config |
| | | }, function(error) { |
| | | return Promise.reject(error) |
| | | }) |
| | | import { Message } from "element-ui"; |
| | | axios.interceptors.request.use( |
| | | function(config) { |
| | | let tk = sessionStorage.getItem("token"); |
| | | let token; |
| | | if (tk != undefined && tk != "") { |
| | | token = tk; |
| | | } |
| | | if (token) { |
| | | config.headers["token"] = "" + token; |
| | | // config.headers['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8' |
| | | // config.headers['Content-Type'] = 'application/json' |
| | | } |
| | | if ((config.method === "post" || config.method === "put") && !config.noQs) { |
| | | config.data = qs.stringify(config.data); |
| | | } |
| | | if (config.headers["Content-Type"] == "application/json" && !config.noQs) { |
| | | config.data = qs.parse(config.data); |
| | | } |
| | | return config; |
| | | }, |
| | | function(error) { |
| | | return Promise.reject(error); |
| | | } |
| | | ); |
| | | |
| | | axios.interceptors.response.use(res => { |
| | | if(res.data.code === 201){ |
| | | Message({ |
| | | type: 'error', |
| | | dangerouslyUseHTMLString: true, |
| | | message: `${res.data.message}` |
| | | }) |
| | | } |
| | | return res.data |
| | | }, async function(err) { |
| | | if (JSON.stringify(err).indexOf('timeout of') > -1) { |
| | | Message.error('请求超时,请检查网络设置') |
| | | } else if (JSON.stringify(err).indexOf('ERR_CONNECTION_RESET') > -1 || JSON.stringify(err).indexOf( |
| | | 'Network Error') > -1) { |
| | | Message.error('网络连接错误') |
| | | } else if (err.response.status == "503") { |
| | | Message.error('服务未响应') |
| | | } else if (err.response.status == "404") { |
| | | Message.error('请求失败,链接地址不存在') |
| | | } else if (err.response.status == "403") { |
| | | Message.error('token不存在') |
| | | } else if (err.response.status == "402") { |
| | | Message.error('无效签名,请重新登录') |
| | | localStorage.removeItem('autoenter') |
| | | window.location.href = '/enter' |
| | | } else if (err.response.status == "401") { |
| | | await axios.post("/user/refresh", { |
| | | reToken: sessionStorage.getItem('reToken') |
| | | }).then(res => { |
| | | if (res.data.code == 201) { |
| | | Message.error('认证失败,需要重新登录') |
| | | localStorage.removeItem('autoenter') |
| | | next({ |
| | | path: '/enter' |
| | | }) |
| | | return Promise.reject(err) |
| | | } |
| | | sessionStorage.setItem('token', res.data.token) |
| | | sessionStorage.setItem('reToken', res.data.reToken) |
| | | }) |
| | | return axios(err.config) |
| | | } else if (err.response.status == "500") { |
| | | Message.error('服务端出现错误') |
| | | } |
| | | return Promise.reject(err) |
| | | }) |
| | | axios.interceptors.response.use( |
| | | res => { |
| | | if (res.data.code === 201) { |
| | | Message({ |
| | | type: "error", |
| | | dangerouslyUseHTMLString: true, |
| | | message: `${res.data.message}` |
| | | }); |
| | | } |
| | | return res.data; |
| | | }, |
| | | async function(err) { |
| | | if (JSON.stringify(err).indexOf("timeout of") > -1) { |
| | | Message.error("请求超时,请检查网络设置"); |
| | | } else if ( |
| | | JSON.stringify(err).indexOf("ERR_CONNECTION_RESET") > -1 || |
| | | JSON.stringify(err).indexOf("Network Error") > -1 |
| | | ) { |
| | | Message.error("网络连接错误"); |
| | | } else if (err.response.status == "503") { |
| | | Message.error("服务未响应"); |
| | | } else if (err.response.status == "404") { |
| | | Message.error("请求失败,链接地址不存在"); |
| | | } else if (err.response.status == "403") { |
| | | Message.error("token不存在"); |
| | | } else if (err.response.status == "402") { |
| | | Message.error("无效签名,请重新登录"); |
| | | localStorage.removeItem("autoenter"); |
| | | window.location.href = "/enter"; |
| | | } else if (err.response.status == "401") { |
| | | await axios |
| | | .post("/user/refresh", { |
| | | reToken: sessionStorage.getItem("reToken") |
| | | }) |
| | | .then(res => { |
| | | if (res.data.code == 201) { |
| | | Message.error("认证失败,需要重新登录"); |
| | | localStorage.removeItem("autoenter"); |
| | | next({ |
| | | path: "/enter" |
| | | }); |
| | | return Promise.reject(err); |
| | | } |
| | | sessionStorage.setItem("token", res.data.token); |
| | | sessionStorage.setItem("reToken", res.data.reToken); |
| | | }); |
| | | return axios(err.config); |
| | | } else if (err.response.status == "500") { |
| | | Message.error("服务端出现错误"); |
| | | } |
| | | return Promise.reject(err); |
| | | } |
| | | ); |
| | | |
| | | router.beforeEach((to, from, next) => { |
| | | if(to.path.indexOf('/test') == 0){ |
| | | next() |
| | | return |
| | | } |
| | | if (to.path.indexOf('/enter') != 0) { |
| | | if (sessionStorage.getItem('token') == null || sessionStorage.getItem('token') == '' || sessionStorage.getItem( |
| | | 'token') == undefined) { |
| | | if (to.path.indexOf("/test") == 0) { |
| | | next(); |
| | | return; |
| | | } |
| | | if (to.path.indexOf("/enter") != 0) { |
| | | if ( |
| | | sessionStorage.getItem("token") == null || |
| | | sessionStorage.getItem("token") == "" || |
| | | sessionStorage.getItem("token") == undefined |
| | | ) { |
| | | next({ |
| | | path: '/enter' |
| | | }) |
| | | path: "/enter" |
| | | }); |
| | | } |
| | | } |
| | | next() |
| | | next(); |
| | | }); |
| | | |
| | | new Vue({ |
| | | el: '#app', |
| | | router, |
| | | render: h => h(App), |
| | | el: "#app", |
| | | router, |
| | | render: h => h(App), |
| | | beforeCreate() { |
| | | // 需要在全局添加一个属性 |
| | | Vue.prototype.$bus = this |
| | | // 需要在全局添加一个属性 |
| | | Vue.prototype.$bus = this; |
| | | } |
| | | }); |
| | | |