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

259 lines
8.4 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';
2020-12-04 20:53:58 +08:00
import "./permission";
import {hasPermission, hasButton} from "./permission";
import plTable from 'pl-table'
import 'pl-table/themes/index.css'
2019-12-09 19:23:20 +08:00
import {post, get, put, del} from './http.js'
2020-12-14 20:25:24 +08:00
import {clickoutside, bottomBoxWindow, stringTimeParseToUnix, unixTimeParseToString, chartResizeTool, tableSet} from './components/common/js/tools.js';
import * as tools from './components/common/js/tools.js';
import * as constants from './components/common/js/constants.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弹框组件
import assetBox from "./components/common/rightBox/assetBox"; //资产添加组件
import batchEditAsset from "./components/common/rightBox/batchEditAsset"; //资产批量修改组件
import alertConfigBox from "./components/common/rightBox/alertConfigBox"; //告警规则弹框组件
import panelBox from "./components/common/rightBox/panelBox"; //面板弹框组件
import moduleListPop from "./components/page/asset/moduleListPop"; //面板弹框组件
import cabinetConfigBox from "./components/common/popBox/cabinetConfig"; //面板弹框组件
2020-03-11 12:27:00 +08:00
import modelBox from "./components/common/rightBox/modelBox"; //model弹框
import bottomBox from "./components/common/bottomBox/bottomBox"; //上滑框
2020-03-18 19:22:45 +08:00
import loading from "./components/common/loading";
2020-03-26 19:58:09 +08:00
import mibBox from "./components/common/rightBox/mibBox";
import leftMenu from "./components/common/leftMenu";
2020-04-24 12:42:58 +08:00
import pickTime from "./components/common/pickTime";
2020-10-16 19:26:50 +08:00
import bus from "./libs/bus";
2021-01-18 18:58:57 +08:00
import {cancelWithChange} from "./components/common/js/tools";
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);
Vue.component("batch-edit-asset", batchEditAsset);
Vue.component("alert-config-box", alertConfigBox);
Vue.component("panel-box", panelBox);
Vue.component("module-list-pop", moduleListPop);
Vue.component("cabinet-config-box", cabinetConfigBox);
2020-03-11 12:27:00 +08:00
Vue.component("model-box", modelBox);
2020-03-18 19:22:45 +08:00
Vue.component('loading',loading);
2020-03-27 15:41:26 +08:00
Vue.component('bottom-box', bottomBox);
2020-03-26 19:58:09 +08:00
Vue.component('mib-box',mibBox);
Vue.component('left-menu',leftMenu);
2020-04-24 12:42:58 +08:00
Vue.component('pick-time',pickTime);
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;
Vue.prototype.$CONSTANTS = constants;
Vue.prototype.$TOOLS = tools;
Vue.prototype.$bottomBoxWindow = bottomBoxWindow; //底部上滑框控制
Vue.prototype.$stringTimeParseToUnix = stringTimeParseToUnix;
2020-05-15 15:03:42 +08:00
Vue.prototype.$unixTimeParseToString = unixTimeParseToString;
2020-05-29 21:06:55 +08:00
Vue.prototype.$chartResizeTool = chartResizeTool;
Vue.prototype.$tableSet = tableSet;
Vue.prototype.$tableHeight = { //列表页表格的高度
normal: 'calc(100% - 100px)', //常规高度,特例在下方定义
openSubList: { //打开二级列表后的高度
mainList: 'calc(100% - 60px)',
subList: 'calc(100% - 86px)',
toTopBtnTop: 'calc(50% - 11px)'
},
toTopBtnTop: 'calc(100% - 73px)',
2020-03-25 18:38:13 +08:00
noPagination: 'calc(100% - 60px)', //特例:没有翻页组件
};
2019-11-28 18:23:49 +08:00
2020-10-16 19:26:50 +08:00
Vue.mixin({
2020-12-21 11:51:58 +08:00
data:function(){
return {
prevent_opt:{
2020-12-21 11:59:49 +08:00
save:false,
2020-12-21 11:51:58 +08:00
import:false,
dumplicate:false,
delete:false,
refresh:false,
query:false,
}
}
},
2020-12-17 11:07:57 +08:00
methods: {
utcTimeToTimezone:function(time){
if(time){
return bus.UTCTimeToConfigTimezone(time)
2020-12-04 20:53:58 +08:00
}
},
2020-12-17 11:07:57 +08:00
utcTimeToTimezoneStr:function(time,format='yyyy-MM-dd hh:mm:ss'){
if(time){
return bus.timeFormate(bus.UTCTimeToConfigTimezone(time),format)
}else{
return '-'
2020-12-04 20:53:58 +08:00
}
2020-12-17 11:07:57 +08:00
},
timezoneToUtcTime:function(time){
if(time){
return bus.configTimezoneToUTCTime(time)
}
},
timezoneToUtcTimeStr:function(time,format='yyyy-MM-dd hh:mm:ss'){
if(time){
return bus.timeFormate(this.timezoneToUtcTime(time),format)
}
},
tableTitleReset:function(src,dist){
dist.forEach(item=>{
let title=src.find(t=>t.prop == item.prop)
if(title&&title.label){
item.label=title.label;
}
});
2020-12-17 11:07:57 +08:00
},
hasButton(code) {
return hasButton(this.$store.getters.buttonList, code);
},
toTop(wrap) {
let currentTop = wrap.scrollTop;
let interval = currentTop/10;
let intervalFunc = setInterval(function(){ //花200ms分10次回到顶部模拟动画效果
if (currentTop == 0) {
clearInterval(intervalFunc);
} else {
currentTop = (currentTop - interval) < interval*0.5 ? 0 : currentTop - interval;
wrap.scrollTop = currentTop;
}
}, 20);
},
toTopBtnHandler(wrap) {
let vm = this;
wrap.addEventListener('scroll', bus.debounce(function() {
vm.tools.showTopBtn = wrap.scrollTop > 50;
vm.tools.tableHover = wrap.scrollTop > 50;
}, 100));
},
numberWithEConvent(num) {
if (num) {
if ((("" + num).indexOf('E') != -1) || (("" + num).indexOf('e') != -1)) {
let regExp = new RegExp('^((\\d+.?\\d+)[Ee]{1}(\\d+))$', 'ig');
let result = regExp.exec(num);
let resultValue = "";
let power = "";
if (result != null) {
resultValue = result[2];
power = result[3];
result = regExp.exec(num);
}
if (resultValue != "") {
if (power != "") {
let powVer = Math.pow(10, power);
resultValue = resultValue * powVer;
return resultValue;
}
}
} else {
return num;
}
}
return 0;
},
translation(key) {
return i18n.t(key);
},
copyRow(row,rightBoxValKey,idKey= 'id',show = false,format,callback){
/*
row 表格当前行
rightBoxValKey 右侧弹窗绑定的 data
idKey 当前数据的唯一标识
show 打开对应的弹窗 函数
format 是否需要对当前行进行处理
callBack 回调
*/
let rowCopy={...row};
if(format){
rowCopy=format(rowCopy)
}
delete rowCopy[idKey];
this[rightBoxValKey]=rowCopy;
if(typeof show==='function'){
show()
}else if(typeof show==='string'){
this[show]=true
} else {
this['rightBox']['show']=true;
}
if(callback){
callback()
}
},
2020-12-17 11:07:57 +08:00
},
computed: {
getMenuList() {
return this.$store.state.user.menuList;
},
getButtonList() {
return this.$store.state.buttonList;
}
}
2020-12-04 20:53:58 +08:00
});
2020-10-16 19:26:50 +08:00
Vue.config.productionTip = false;
Vue.use(ElementUI);
Vue.use(Vuex);
Vue.use(VueResource);
Vue.use(plTable);
Vue.use(hasPermission);
/*指令*/
2021-01-18 18:58:57 +08:00
Vue.directive('cancel',cancelWithChange)
Vue.directive('clickoutside', clickoutside);
window.resizing = false;
window.vm = new Vue({
2019-11-28 18:23:49 +08:00
el: '#app',
router,
i18n,
store,
components: {App},
2020-12-04 20:53:58 +08:00
template: '<App/>',
mounted() {
//store.commit()
}
});
export default vm;
/* 重写组件内容 */
2020-12-14 20:25:24 +08:00
/*const elUi = require("element-ui");
const pl = require("pl-table");
//去掉el-table表头右侧的滚动条预留空间
elUi.Table.components.TableHeader.computed.hasGutter = () => {return false;};
2020-12-14 20:25:24 +08:00
pl.PlTable.components.ElTable.components.TableHeader.computed.hasGutter = () => {return false;};*/