This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
nezha-nezha-fronted/nezha-fronted/src/main.js

201 lines
6.6 KiB
JavaScript
Raw Normal View History

2020-01-13 19:04:03 +08:00
//import "./assets/css/main.css";
2020-01-17 16:50:17 +08:00
import './assets/stylus/index.scss'
import "./assets/css/nzIcon.css";
import "./assets/css/main.css";
import 'element-ui/lib/theme-chalk/index.css';
import ElementUI from 'element-ui';
import 'xterm/dist/xterm.css'
import i18n from './components/common/i18n'
2019-11-28 18:23:49 +08:00
import Vue from 'vue'
import Vuex from 'vuex'
import store from './store/index';
2019-11-28 18:23:49 +08:00
import App from './App'
import router from './router'
import VueResource from 'vue-resource'
import axios from 'axios';
2019-12-09 19:23:20 +08:00
import {post, get, put, del} from './http.js'
import Pagination from "./components/common/pagination"; //引入全局分页组件
import searchInput from "./components/common/searchInput"; //搜索框组件
import elementSet from "./components/common/elementSet"; //自定义表头组件
import projectBox from './components/common/rightBox/projectBox'; //project弹框组件
import moduleBox from './components/common/rightBox/moduleBox'; //module弹框组件
import editEndpointBox from './components/common/rightBox/editEndpointBox'; //endpoint弹框组件
import addEndpointBox from './components/common/rightBox/addEndpointBox'; //endpoint弹框组件
2019-12-23 15:43:05 +08:00
import assetAddUnit from "./components/page/asset/assetAddUnit"; //资产添加组件
import assetEditUnit from "./components/page/asset/assetEditUnit"; //资产添加组件
import assetBox from "./components/common/rightBox/assetBox"; //资产添加组件
import alertConfigBox from "./components/common/rightBox/alertConfigBox"; //告警规则弹框组件
import dcConfigBox from "./components/common/popBox/dcConfig"; //idc配置弹框组件
import panelBox from "./components/common/rightBox/panelBox"; //面板弹框组件
import moduleListPop from "./components/page/asset/moduleListPop"; //面板弹框组件
import cabinetConfigBox from "./components/common/popBox/cabinetConfig"; //面板弹框组件
2020-02-21 17:57:19 +08:00
import dcBox from "./components/common/rightBox/dcBox"; //dc弹框
2020-02-24 20:27:14 +08:00
import selectArea from "./components/common/popBox/selectArea"; //dc弹框
/*import 'vue-happy-scroll/docs/happy-scroll.css'
import {HappyScroll} from 'vue-happy-scroll'
Vue.component('happy-scroll', HappyScroll)*/
import PerfectScrollbar from "perfect-scrollbar";
import "perfect-scrollbar/css/perfect-scrollbar.css";
2019-12-16 17:14:58 +08:00
Vue.component("Pagination", Pagination);
2019-12-16 17:14:58 +08:00
Vue.component("searchInput", searchInput);
Vue.component("element-set", elementSet);
Vue.component("project-box", projectBox);
Vue.component("module-box", moduleBox);
Vue.component("edit-endpoint-box", editEndpointBox);
Vue.component("add-endpoint-box", addEndpointBox);
Vue.component("asset-box", assetBox);
2019-12-23 15:43:05 +08:00
Vue.component("assetAddUnit", assetAddUnit);
Vue.component("assetEditUnit", assetEditUnit);
Vue.component("alert-config-box", alertConfigBox);
2020-01-03 16:04:23 +08:00
Vue.component("idc-config-box", dcConfigBox);
Vue.component("panel-box", panelBox);
Vue.component("module-list-pop", moduleListPop);
Vue.component("cabinet-config-box", cabinetConfigBox);
2020-02-21 17:57:19 +08:00
Vue.component("dc-box", dcBox);
2020-02-24 20:27:14 +08:00
Vue.component("select-area", selectArea);
Vue.prototype.$axios = axios;
Vue.prototype.$post = post;
Vue.prototype.$get = get;
2019-12-09 19:23:20 +08:00
Vue.prototype.$put = put;
Vue.prototype.$delete = del;
2019-11-28 18:23:49 +08:00
Vue.config.productionTip = false;
Vue.use(ElementUI);
Vue.use(Vuex);
Vue.use(VueResource);
const el_scrollBar = el => {
//在元素上加点私货名字随便取确保不会和已有属性重复即可我取名叫做_ps_
if (el._ps_ instanceof PerfectScrollbar) {
el._ps_.update();
} else {
//el上挂一份属性
el._ps_ = new PerfectScrollbar(el, {});
}
};
Vue.directive("scrollBar", {
inserted(el, binding, vnode) {
const { arg } = binding;
if (arg === "el-table") {
el = el.querySelector(".el-table__body-wrapper");
!el && console.warn("未发现className为el-table__body-wrapper的dom");
// 启用x轴后不让原生滚动条出来作乱
vnode.context.$nextTick(() => {
el.classList.add("ps");
el.addEventListener("ps-scroll-y", () =>
el.classList.add("ps")
);
el.addEventListener("ps-scroll-x", () =>
el.classList.add("ps")
);
});
} else if (arg === 'metric-set') {
}
const rules = ["fixed", "absolute", "relative"];
if (!rules.includes(window.getComputedStyle(el, null).position)) {
console.error(
`perfect-scrollbar所在的容器的position属性必须是以下之一${rules.join(
"、"
)}`
);
}
//el上挂一份属性
el_scrollBar(el);
},
componentUpdated(el, binding, vnode, oldVnode) {
const { arg } = binding;
if (arg === "el-table") {
el = el.querySelector(".el-table__body-wrapper");
!el && console.warn("未发现className为el-table__body-wrapper的dom");
}
try {
vnode.context.$nextTick(() => {
el_scrollBar(el);
});
} catch (error) {
console.error(error);
el_scrollBar(el);
}
},
});
const exceptClassName = ["config-dropdown", "nz-pop", "el-picker", "chart-box-dropdown", 'metric-dropdown']; //clickoutside排除的class(白名单)
const clickoutside = {
// 初始化指令
bind(el, binding, vnode) {
function documentHandler(e) {
if (el.contains(e.target)) {
return false;
} else {
//console.info(e)
let flag = true;
top: for (let i = 0; i < e.path.length; i++) {
for (let j = 0; j < exceptClassName.length; j++) {
if (e.path[i].className && e.path[i].className.indexOf(exceptClassName[j]) != -1) {
flag = false;
break top;
}
}
}
if (!flag) {
return false;
}
}
// 判断指令中是否绑定了函数
if (binding.expression) {
// 如果绑定了函数 则调用那个函数此处binding.value就是handleClose方法
if (binding.arg) {
binding.value(e, binding.arg);
} else {
binding.value(e);
}
}
}
// 给当前元素绑定个私有变量方便在unbind中可以解除事件监听
el.__vueClickOutside__ = documentHandler;
document.addEventListener('mousedown', documentHandler);
},
unbind(el, binding) {
// 解除事件监听
document.removeEventListener('mousedown', el.__vueClickOutside__);
delete el.__vueClickOutside__;
},
};
Vue.directive('clickoutside',
clickoutside
)
2019-11-28 18:23:49 +08:00
/* eslint-disable no-new */
window.vm = new Vue({
2019-11-28 18:23:49 +08:00
el: '#app',
router,
i18n,
store,
components: {App},
2019-11-28 18:23:49 +08:00
template: '<App/>'
})
export default vm
/*router.beforeEach((to, from, next) => {
if (to.path === '/login') {
next()
} else {
2019-12-26 18:06:51 +08:00
let token = sessionStorage.getItem('nz-token');
if (token) {
next()
} else {
next({ path: '/dashboard' })
}
}
})*/