|
|
// The Vue build version to load with the `import` command
|
|
|
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
|
|
|
import "babel-polyfill";
|
|
|
import "es6-promise/auto";
|
|
|
import ElementUI from "element-ui";
|
|
|
import "element-ui/lib/theme-chalk/index.css";
|
|
|
import {
|
|
|
Message
|
|
|
} from "element-ui";
|
|
|
Vue.use(ElementUI);
|
|
|
import App from "./App.vue";
|
|
|
import store from "./store";
|
|
|
import BaiduMap from "vue-baidu-map";
|
|
|
Vue.use(BaiduMap, {
|
|
|
// ak 是在百度地图开发者平台申请的密钥 详见 http://lbsyun.baidu.com/apiconsole/key */
|
|
|
ak: "OPfwfWopYoyhvGv50ST0DULf3tzvNXY1"
|
|
|
});
|
|
|
import iView from "iview";
|
|
|
Vue.use(iView);
|
|
|
import Print from "vue-print-nb";
|
|
|
import axios from "axios";
|
|
|
import VueAxios from "vue-axios";
|
|
|
import "./utils/dialog";
|
|
|
import "./plugins";
|
|
|
// import "./utils/directive/focus";
|
|
|
import echarts from "echarts";
|
|
|
import {
|
|
|
getCookie
|
|
|
} from "./utils/utils.js";
|
|
|
import apiConfig from "../config/api.config.js";
|
|
|
import vueEsign from "vue-esign";
|
|
|
import animated from "animate.css"; // npm install animate.css --save安装,在引入
|
|
|
import formatTime from "./utils/filters.js";
|
|
|
import arrDiff from "./utils/array.js";
|
|
|
import {
|
|
|
Loading
|
|
|
} from "element-ui";
|
|
|
import countdown from "./utils/countdown.js";
|
|
|
import "./utils/rem.js";
|
|
|
Vue.use(animated);
|
|
|
Vue.use(vueEsign);
|
|
|
|
|
|
import {
|
|
|
thousands
|
|
|
} from '@/utils/index.js'
|
|
|
|
|
|
import Vue from "vue";
|
|
|
import Router from "vue-router";
|
|
|
import router from "./router";
|
|
|
import "./flexible.js";
|
|
|
|
|
|
Vue.use(Router);
|
|
|
Vue.use(VueAxios, axios);
|
|
|
axios.defaults.baseURL = apiConfig.baseUrl;
|
|
|
Vue.use(Print); //注册
|
|
|
|
|
|
import {
|
|
|
message
|
|
|
} from "./utils/resetMessage.js"; //现在提示弹窗每次只弹一条
|
|
|
// import VueParticles from 'vue-particles'
|
|
|
// Vue.use(VueParticles)
|
|
|
|
|
|
Vue.prototype.$thousands = thousands
|
|
|
Vue.prototype.$message = message;
|
|
|
Vue.prototype.$countdown = countdown;
|
|
|
Vue.prototype.bus = new Vue();
|
|
|
Vue.prototype.$echarts = echarts;
|
|
|
Vue.prototype.formatTime = formatTime;
|
|
|
Vue.prototype.arrDiff = arrDiff;
|
|
|
Vue.config.productionTip = false;
|
|
|
|
|
|
export function getNextDate(date, day) {
|
|
|
var dd = new Date(date);
|
|
|
var y = dd.getFullYear();
|
|
|
var m =
|
|
|
dd.getMonth() + 1 < 10 ? "0" + (dd.getMonth() + 1) : dd.getMonth() + 1;
|
|
|
var d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate();
|
|
|
return y + "-" + m + "-" + d;
|
|
|
}
|
|
|
axios.defaults.withCredentials = true; //让ajax携带cookie
|
|
|
// 全局过滤器--时间戳格式化时间//.padStart(2 , "0") 不足两位的,用0填充
|
|
|
Vue.filter("dateFormat", function (originVal) {
|
|
|
const dt = new Date(originVal);
|
|
|
const y = dt.getFullYear();
|
|
|
const m = (dt.getMonth() + 1 + "").padStart(2, "0");
|
|
|
const d = (dt.getDate() + "").padStart(2, "0");
|
|
|
const hh = (dt.getHours() + "").padStart(2, "0");
|
|
|
const mm = (dt.getMinutes() + "").padStart(2, "0");
|
|
|
const ss = (dt.getSeconds() + "").padStart(2, "0");
|
|
|
return `${y}-${m}-${d} ${hh}:${mm}:${ss}`;
|
|
|
});
|
|
|
Vue.filter("dateMonth", function (originVal) {
|
|
|
const dt = new Date(originVal);
|
|
|
const y = dt.getFullYear();
|
|
|
const m = (dt.getMonth() + 1 + "").padStart(2, "0");
|
|
|
const d = (dt.getDate() + "").padStart(2, "0");
|
|
|
const hh = (dt.getHours() + "").padStart(2, "0");
|
|
|
const mm = (dt.getMinutes() + "").padStart(2, "0");
|
|
|
const ss = (dt.getSeconds() + "").padStart(2, "0");
|
|
|
return `${y}-${m}-${d}`;
|
|
|
});
|
|
|
Vue.filter("phone", function (phone) {
|
|
|
return phone.substring(0, 3) + "****" + phone.substring(phone.length - 4);
|
|
|
});
|
|
|
Vue.filter("identityNum", function (identityNum) {
|
|
|
return (
|
|
|
identityNum.substring(0, 4) +
|
|
|
"**************" +
|
|
|
identityNum.substring(identityNum.length - 10)
|
|
|
);
|
|
|
});
|
|
|
|
|
|
Vue.filter("money", function (money) {
|
|
|
return (money * 1).toFixed(2);
|
|
|
});
|
|
|
|
|
|
Vue.prototype.openLoading = function () {
|
|
|
const loading = this.$loading({
|
|
|
// 声明一个loading对象
|
|
|
lock: true, // 是否锁屏
|
|
|
text: "正在加载...", // 加载动画的文字
|
|
|
spinner: "el-icon-loading", // 引入的loading图标
|
|
|
background: "rgba(0, 0, 0, 0.3)", // 背景颜色
|
|
|
target: ".sub-main", // 需要遮罩的区域
|
|
|
body: true,
|
|
|
customClass: "mask" // 遮罩层新增类名
|
|
|
});
|
|
|
setTimeout(function () {
|
|
|
// 设定定时器,超时5S后自动关闭遮罩层,避免请求失败时,遮罩层一直存在的问题
|
|
|
loading.close(); // 关闭遮罩层
|
|
|
}, 5000);
|
|
|
return loading;
|
|
|
};
|
|
|
|
|
|
router.beforeEach((to, from, next) => {
|
|
|
// console.log('新',to);
|
|
|
// console.log('旧',from);
|
|
|
var token = localStorage.getItem("token");
|
|
|
if (from.path.indexOf("login") != -1) {
|
|
|
next();
|
|
|
}
|
|
|
// if (to.path.indexOf('login') != -1 || to.path.indexOf('home') != -1) {
|
|
|
// if (token) {
|
|
|
// next()
|
|
|
|
|
|
// } else {
|
|
|
// Message({
|
|
|
// showClose: true,
|
|
|
// type: 'warning',
|
|
|
// message: '请先登录',
|
|
|
// duration: 2000
|
|
|
// })
|
|
|
// next({ path: '/login' });
|
|
|
// }
|
|
|
|
|
|
if (to.path.indexOf("login") != -1 || to.path.indexOf("home") != -1) {
|
|
|
next();
|
|
|
} else if (token) {
|
|
|
next();
|
|
|
} else {
|
|
|
Message({
|
|
|
showClose: true,
|
|
|
type: "warning",
|
|
|
message: "请先登录",
|
|
|
duration: 2000
|
|
|
});
|
|
|
next({
|
|
|
path: "/login"
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
Vue.directive("role", {
|
|
|
inserted(el, binding) {
|
|
|
// binding.value获取到的是传递到自定义指令中属性的值
|
|
|
if (!roleFunction(binding.value)) {
|
|
|
el.remove();
|
|
|
}
|
|
|
|
|
|
function roleFunction(value) {
|
|
|
let roleList = JSON.parse(sessionStorage.getItem("list"));
|
|
|
for (let item of roleList) {
|
|
|
if (item.id == value) {
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
|
|
|
/* eslint-disable no-new */
|
|
|
new Vue({
|
|
|
el: "#app",
|
|
|
router,
|
|
|
store,
|
|
|
components: {
|
|
|
App
|
|
|
},
|
|
|
template: "<App/>"
|
|
|
});
|
|
|
|
|
|
export default router;
|