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

233 lines
6.7 KiB
JavaScript
Raw Normal View History

// import '@/assets/stylus/index.scss'
2021-03-19 18:52:19 +08:00
import 'element-ui/lib/theme-chalk/index.css'
import 'xterm/dist/xterm.css'
import '@/assets/stylus/main.scss'
import '@/assets/css/main.scss'
import ElementUI from 'element-ui'
import i18n from './components/common/i18n'
2019-11-28 18:23:49 +08:00
import Vue from 'vue'
import Vuex from 'vuex'
2021-03-19 18:52:19 +08:00
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'
2021-03-19 18:52:19 +08:00
import axios from 'axios'
import { hasPermission, hasButton } from './permission'
import plTable from 'pl-table'
import 'pl-table/themes/index.css'
2021-03-19 18:52:19 +08:00
import { post, get, put, del } from './http.js'
import { clickoutside, bottomBoxWindow, stringTimeParseToUnix, unixTimeParseToString, chartResizeTool, tableSet, cancelWithChange } from './components/common/js/tools.js'
import * as tools from './components/common/js/tools.js'
import * as constants from './components/common/js/constants.js'
2021-03-19 18:52:19 +08:00
import Pagination from './components/common/pagination' // 引入全局分页组件
import searchInput from './components/common/searchInput' // 搜索框组件
import elementSet from './components/common/elementSet' // 自定义表头组件
import loading from '@/components/common/loading'
import pickTime from '@/components/common/pickTime'
import bus from '@/libs/bus'
import theme from '@/assets/css/theme.scss'
import myDatePicker from '@/components/common/myDatePicker'
import vSelectPage from 'v-selectpage'
import nzDataList from '@/components/common/table/nzDataList'
Vue.use(vSelectPage, {
dataLoad: function (vue, url, params) {
if (params.pageNumber) {
params.pageNo = params.pageNumber
}
return new Promise((resolve, reject) => {
get(url, params).then(res => {
resolve(res)
}, e => reject(e))
})
}
})
Vue.use(myDatePicker)
2021-03-19 18:52:19 +08:00
Vue.component('Pagination', Pagination)
Vue.component('searchInput', searchInput)
Vue.component('element-set', elementSet)
Vue.component('loading', loading)
Vue.component('pick-time', pickTime)
Vue.component('myDatePicker', myDatePicker)
Vue.component('nzDataList', nzDataList)
2019-12-16 17:14:58 +08:00
2021-03-19 18:52:19 +08:00
Vue.prototype.$axios = axios
Vue.prototype.$post = post
Vue.prototype.$get = get
Vue.prototype.$put = put
Vue.prototype.$delete = del
Vue.prototype.$CONSTANTS = constants
Vue.prototype.$TOOLS = tools
Vue.prototype.$bottomBoxWindow = bottomBoxWindow // 底部上滑框控制
Vue.prototype.$stringTimeParseToUnix = stringTimeParseToUnix
Vue.prototype.$unixTimeParseToString = unixTimeParseToString
Vue.prototype.$chartResizeTool = chartResizeTool
Vue.prototype.$tableSet = tableSet
Vue.prototype.$tableHeight = { // 列表页表格的高度
normal: 'calc(100% - 48px)', // 常规高度,特例在下方定义
2021-03-19 18:52:19 +08:00
openSubList: { // 打开二级列表后的高度
mainList: 'calc(100% - 60px)',
2021-04-14 18:35:42 +08:00
subList: 'calc(100% - 38px)',
toTopBtnTop: 'calc(50% - 11px)'
},
toTopBtnTop: 'calc(100% - 73px)',
2021-03-19 18:52:19 +08:00
noPagination: 'calc(100% - 60px)' // 特例:没有翻页组件
}
2019-11-28 18:23:49 +08:00
2020-10-16 19:26:50 +08:00
Vue.mixin({
2021-03-19 18:52:19 +08:00
data: function () {
2020-12-21 11:51:58 +08:00
return {
2021-03-19 18:52:19 +08:00
prevent_opt: {
save: false,
import: false,
duplicate: false,
2021-03-19 18:52:19 +08:00
delete: false,
refresh: false,
query: false
},
theme: theme // scss主题变量
2020-12-21 11:51:58 +08:00
}
},
2020-12-17 11:07:57 +08:00
methods: {
2021-03-19 18:52:19 +08:00
utcTimeToTimezone: function (time) {
if (time) {
2020-12-17 11:07:57 +08:00
return bus.UTCTimeToConfigTimezone(time)
2020-12-04 20:53:58 +08:00
}
},
2021-03-19 18:52:19 +08:00
utcTimeToTimezoneStr: function (time, format = 'yyyy-MM-dd hh:mm:ss') {
if (time) {
return bus.timeFormate(bus.UTCTimeToConfigTimezone(time), format)
} else {
2020-12-17 11:07:57 +08:00
return '-'
2020-12-04 20:53:58 +08:00
}
2020-12-17 11:07:57 +08:00
},
2021-03-19 18:52:19 +08:00
timezoneToUtcTime: function (time) {
if (time) {
2020-12-17 11:07:57 +08:00
return bus.configTimezoneToUTCTime(time)
}
},
2021-03-19 18:52:19 +08:00
timezoneToUtcTimeStr: function (time, format = 'yyyy-MM-dd hh:mm:ss') {
if (time) {
return bus.timeFormate(this.timezoneToUtcTime(time), format)
2020-12-17 11:07:57 +08:00
}
},
2021-03-19 18:52:19 +08:00
hasButton (code) {
return hasButton(this.$store.getters.buttonList, code)
2020-12-17 11:07:57 +08:00
},
2021-03-19 18:52:19 +08:00
numberWithEConvent (num) {
if (num) {
2021-03-19 18:52:19 +08:00
if ((('' + num).indexOf('E') !== -1) || (('' + num).indexOf('e') !== -1)) {
const regExp = /'^((\\d+.?\\d+)[Ee]{1}(\\d+))$', 'ig'/
let result = regExp.exec(num)
let resultValue = ''
let power
if (result != null) {
2021-03-19 18:52:19 +08:00
resultValue = result[2]
power = result[3]
result = regExp.exec(num)
}
2021-03-19 18:52:19 +08:00
if (resultValue) {
if (power) {
const powVer = Math.pow(10, power)
resultValue = resultValue * powVer
return resultValue
}
}
} else {
2021-03-19 18:52:19 +08:00
return num
}
}
2021-03-19 18:52:19 +08:00
return 0
},
2021-03-19 18:52:19 +08:00
translation (key) {
return i18n.t(key)
},
2021-03-19 18:52:19 +08:00
copyRow (row, rightBoxValKey, idKey = 'id', show = false, format, callback) {
/*
row 表格当前行
rightBoxValKey 右侧弹窗绑定的 data
idKey 当前数据的唯一标识
show 打开对应的弹窗 函数
format 是否需要对当前行进行处理
callBack 回调
*/
2021-03-19 18:52:19 +08:00
let rowCopy = { ...row }
if (rowCopy.name) {
rowCopy.name = 'Copy from ' + rowCopy.name
}
2021-03-19 18:52:19 +08:00
if (format) {
rowCopy = format(rowCopy)
}
2021-03-19 18:52:19 +08:00
delete rowCopy[idKey]
this[rightBoxValKey] = rowCopy
if (typeof show === 'function') {
show()
2021-03-19 18:52:19 +08:00
} else if (typeof show === 'string') {
this[show] = true
} else {
this.rightBox.show = true
}
2021-03-19 18:52:19 +08:00
if (callback) {
callback()
}
2021-03-19 18:52:19 +08:00
}
2020-12-17 11:07:57 +08:00
},
computed: {
2021-03-19 18:52:19 +08:00
getMenuList () {
return this.$store.state.user.menuList
2020-12-17 11:07:57 +08:00
},
2021-03-19 18:52:19 +08:00
getButtonList () {
return this.$store.state.buttonList
},
$routePath: function () {
return this.$route.path
2020-12-17 11:07:57 +08:00
}
}
2021-03-19 18:52:19 +08:00
})
2020-10-16 19:26:50 +08:00
2021-03-19 18:52:19 +08:00
Vue.config.productionTip = false
Vue.use(ElementUI)
Vue.use(Vuex)
Vue.use(VueResource)
Vue.use(plTable)
Vue.use(hasPermission)
2021-03-19 18:52:19 +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,
2021-03-19 18:52:19 +08:00
components: { App },
2020-12-04 20:53:58 +08:00
template: '<App/>',
2021-03-19 18:52:19 +08:00
mounted () {
// store.commit()
2020-12-04 20:53:58 +08:00
}
2021-03-19 18:52:19 +08:00
})
2021-03-19 18:52:19 +08:00
export default window.vm
2021-04-22 18:03:56 +08:00
const orignalSetItem = localStorage.setItem
localStorage.setItem = function (key, value) {
const setItemEvent = new Event('setItemEvent')
setItemEvent.key = key
setItemEvent.value = value
window.dispatchEvent(setItemEvent)
orignalSetItem.apply(this, arguments)
}
/* 重写组件内容 */
2021-03-19 18:52:19 +08:00
/* const elUi = require("element-ui");
const pl = require("pl-table");
//去掉el-table表头右侧的滚动条预留空间
elUi.Table.components.TableHeader.computed.hasGutter = () => {return false;};
2021-03-19 18:52:19 +08:00
pl.PlTable.components.ElTable.components.TableHeader.computed.hasGutter = () => {return false;}; */