移除系统监控模块

部分代码简化
修改密码时以md5形式发送参数
socket参数修改:session_id->token
自行判断当user.admin==1时的角色名称
master
toesbieya 6 years ago
parent 255b808a9d
commit 14404fa6a4
  1. 2
      vue/src/config/request.js
  2. 7
      vue/src/layout/components/Navbar/index.vue
  3. 2
      vue/src/layout/index.vue
  4. 7
      vue/src/router/authority/modules/system.js
  5. 4
      vue/src/store/modules/resource.js
  6. 13
      vue/src/store/modules/socket.js
  7. 30
      vue/src/store/modules/user.js
  8. 4
      vue/src/utils/index.js
  9. 2
      vue/src/views/purchase/order/components/EditDialog.vue
  10. 2
      vue/src/views/sell/order/components/EditDialog.vue
  11. 129
      vue/src/views/system/monitor/components/Cpu.vue
  12. 128
      vue/src/views/system/monitor/components/Jvm.vue
  13. 128
      vue/src/views/system/monitor/components/Memory.vue
  14. 172
      vue/src/views/system/monitor/index.vue
  15. 8
      vue/src/views/system/user/components/EditDialog.vue
  16. 6
      vue/src/views/system/user/index.vue
  17. 6
      vue/src/views/userCenter/components/Account.vue

@ -48,7 +48,7 @@ service.interceptors.response.use(
return MessageBox.alert('请登录后重试', {
type: 'warning',
beforeClose: (action, instance, done) => {
store.dispatch('user/logout').then(() => done())
store.dispatch('user/logout').then(done)
}
})
}

@ -29,9 +29,6 @@
<el-dropdown-item class="hidden-xs" icon="el-icon-guide" @click.native="()=>$guide(0,guideSteps)">
新手指引
</el-dropdown-item>
<router-link v-if="showSystemMonitor" to="/system/monitor">
<el-dropdown-item icon="el-icon-monitor">系统监控</el-dropdown-item>
</router-link>
<router-link v-if="showSystemResource" to="/system/resource">
<el-dropdown-item icon="el-icon-setting">接口设置</el-dropdown-item>
</router-link>
@ -75,10 +72,6 @@
...mapState('setting', ['sidebarCollapse', 'showBreadcrumb']),
showSystemMonitor() {
return auth('/system/monitor')
},
showSystemResource() {
return auth('/system/resource')
}

@ -37,7 +37,7 @@
...mapState('socket', ['online']),
...mapState('user', {
isLogin: state => !isEmpty(state.id) && !isEmpty(state.token)
isLogin: state => !isEmpty(state.id, state.token)
}),
containerClass() {

@ -50,13 +50,6 @@ const router = {
component: () => lazyLoadView(import('@/views/system/resource')),
hidden: true,
meta: {title: '接口设置'}
},
{
path: 'monitor',
name: 'systemMonitor',
component: () => lazyLoadView(import('@/views/system/monitor')),
hidden: true,
meta: {title: '系统监控'}
}
]
}

@ -4,7 +4,7 @@ import authorityRoutes from '@/router/authority'
import {needAuth} from "@/utils/auth"
import {createTree} from "@/utils/tree"
import {getAllResources} from "@/api/system/resource"
import {isEmpty} from "@/utils"
import {emptyOrDefault, isEmpty} from "@/utils"
import {isExternal} from "@/utils/validate"
const finalConstantRoutes = transformOriginRoutes(constantRoutes)
@ -159,7 +159,7 @@ function sort(routes, getSortValue = defaultGetSortValue) {
const defaultGetSortValue = item => {
item = deepTap(item)
return !item || isEmpty(item.sort) ? 10000 : item.sort
return !item || emptyOrDefault(item.sort, 10000)
}
const deepTap = item => {

@ -1,4 +1,5 @@
import {MessageBox} from "element-ui"
import {isEmpty} from "@/utils"
import {socketUrl} from '@/config'
import SocketIO from 'socket.io-client'
import {createMutations} from "@/utils"
@ -13,7 +14,7 @@ const mutations = createMutations(state)
const actions = {
init(context, user) {
if (!user || !user.id || !user.session_id) return
if (isEmpty(user, user.id, user.token)) return
socket = initSocket(user)
@ -29,9 +30,9 @@ const actions = {
}
}
function initSocket({id, session_id}) {
function initSocket({id, token}) {
return new SocketIO(socketUrl, {
query: {id, session_id},
query: {id, token},
transports: ['websocket']
})
}
@ -79,11 +80,7 @@ function customEventBind(socket, {state, commit, dispatch, rootState}) {
return MessageBox.alert(msg || '你已被强制下线,请重新登陆', {
type: 'warning',
beforeClose: (action, instance, done) => {
dispatch('user/logout', null, {root: true})
.then(() => {
done()
location.reload()
})
dispatch('user/logout', null, {root: true}).finally(done)
}
})
})

@ -1,7 +1,7 @@
import {login, logout} from '@/api/account'
import {createMutations, isEmpty} from "@/utils"
import {createMutations, emptyOrDefault} from "@/utils"
import {autoCompleteUrl} from "@/utils/file"
import {getUser, setUser} from "@/utils/storage"
import {login, logout} from '@/api/account'
//刷新时从本地存储中获取用户信息
const user = getUser()
@ -11,14 +11,13 @@ const state = {
prepare_logout: '',
/*用户基本信息*/
id: !isEmpty(user.id) ? user.id : null,
admin: !isEmpty(user.admin) ? user.admin : 0,
token: !isEmpty(user.token) ? user.token : '',
name: !isEmpty(user.name) ? user.name : '',
avatar: !isEmpty(user.avatar) ? user.avatar : '',
role_name: !isEmpty(user.role_name) ? user.role_name : '',
resources: !isEmpty(user.resources) ? user.resources : {},
session_id: !isEmpty(user.session_id) ? user.session_id : ''
id: emptyOrDefault(user.id, null),
name: emptyOrDefault(user.name),
role_name: emptyOrDefault(user.role_name),
avatar: emptyOrDefault(user.avatar),
admin: emptyOrDefault(user.admin),
token: emptyOrDefault(user.token),
resources: emptyOrDefault(user.resources, {})
}
const mutations = createMutations(state, true)
@ -29,6 +28,7 @@ const actions = {
return new Promise((resolve, reject) => {
login({username: username.trim(), password})
.then(user => {
user.admin === 1 && (user.role_name = '超级管理员')
user.avatar = autoCompleteUrl(user.avatar)
commit('$all', user)
setUser(user)
@ -44,11 +44,15 @@ const actions = {
if (state.prepare_logout) return Promise.reject()
commit('prepare_logout', 'yes')
logout(state.token)
.then(() => dispatch('socket/close', null, {root: true}))
.then(() => {
dispatch('removeUser')
dispatch('tagsView/delAllViews', null, {root: true})
commit('resource/hasInitRoutes', false, {root: true})
return Promise.all([
dispatch('socket/close', null, {root: true}),
dispatch('removeUser'),
dispatch('tagsView/delAllViews', null, {root: true})
])
})
.then(() => {
resolve()
window.location.reload()
})

@ -2,6 +2,10 @@ export function isEmpty(...str) {
return str.some(i => i === undefined || i === null || i === '')
}
export function emptyOrDefault(v, defaultValue = '') {
return isEmpty(v) ? defaultValue : v
}
//简单重置对象属性
export function resetObj(obj) {
if (isEmpty(obj)) return

@ -193,7 +193,7 @@
}
let index = 1
for (let sub of this.form.data) {
if (isEmpty(sub.cid) || isEmpty(sub.cname)) return `${index}个商品分类不能为空`
if (isEmpty(sub.cid, sub.cname)) return `${index}个商品分类不能为空`
if (isEmpty(sub.num)) return `${index}个商品数量不能为空`
if (isEmpty(sub.price)) return `${index + 1}个商品单价不能为空`
if (sub.num < 0 || !isInteger(sub.num)) return `${index}个商品数量有误`

@ -201,7 +201,7 @@
}
let index = 1
for (let sub of this.form.data) {
if (isEmpty(sub.cid) || isEmpty(sub.cname)) return `${index}个商品分类不能为空`
if (isEmpty(sub.cid, sub.cname)) return `${index}个商品分类不能为空`
if (isEmpty(sub.num)) return `${index}个商品数量不能为空`
if (isEmpty(sub.price)) return `${index + 1}个商品单价不能为空`
if (sub.num < 0 || !isInteger(sub.num)) return `${index}个商品数量有误`

@ -1,129 +0,0 @@
<template>
<el-card class="chart-card">
<div slot="header">
<span><b>cpu监控</b></span>
<span class="title-span">
当前使用率
<count-to
:decimals="2"
:end-val="data.utilizationRate"
:start-val="data.lastUtilizationRate"
suffix="%"
/>
</span>
<span class="title-span">
峰值
<count-to
:decimals="2"
:end-val="data.maxUtilizationRate"
:start-val="data.lastMaxUtilizationRate"
suffix="%"
/>
</span>
</div>
<div class="line-chart"/>
</el-card>
</template>
<script>
import {logic, resize} from "@/mixins/chart"
import CountTo from 'vue-count-to'
export default {
name: "Cpu",
mixins: [resize, logic],
components: {CountTo},
props: {
data: Object
},
data() {
return {
options: {
xAxis: {
data: [],
type: 'category',
axisTick: {
show: false
}
},
grid: {
left: 10,
right: 10,
bottom: 20,
top: 30,
containLabel: true
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross'
},
padding: [5, 10]
},
yAxis: {
name: '%',
axisTick: {
show: false
}
},
dataZoom: [
{
start: 30,
end: 70,
}
],
series: [{
name: 'cpu使用率',
itemStyle: {
normal: {
color: '#FF005A',
lineStyle: {
color: '#FF005A',
width: 2
}
}
},
smooth: true,
type: 'line',
areaStyle: {},
data: []
}]
}
}
},
watch: {
data: {
deep: true,
handler({xData, vData}) {
if (!xData || !vData) return
this.setOptions({xData, vData})
}
}
},
methods: {
init() {
this.chart.setOption(this.options)
},
$_getChartDom() {
return this.$el.querySelector('.line-chart')
},
setOptions({xData, vData} = {}) {
this.chart.setOption({
xAxis: {data: xData},
series: [{data: vData}]
})
}
}
}
</script>

@ -1,128 +0,0 @@
<template>
<el-card class="chart-card">
<div slot="header">
<span><b>JVM监控</b></span>
<span class="title-span">{{data.used|numberFormatter}} / {{data.total|numberFormatter}}</span>
<span class="title-span">
当前使用率
<count-to
:decimals="2"
:end-val="data.utilizationRate"
:start-val="data.lastUtilizationRate"
suffix="%"
/>
</span>
<span class="title-span">
峰值
<count-to
:decimals="2"
:end-val="data.maxUtilizationRate"
:start-val="data.lastMaxUtilizationRate"
suffix="%"
/>
</span>
</div>
<div class="line-chart"/>
</el-card>
</template>
<script>
import {logic, resize} from "@/mixins/chart"
import CountTo from 'vue-count-to'
export default {
name: "Jvm",
mixins: [resize, logic],
components: {CountTo},
props: {
data: Object
},
data() {
return {
options: {
xAxis: {
data: [],
type: 'category',
axisTick: {
show: false
}
},
grid: {
left: 10,
right: 10,
bottom: 20,
top: 30,
containLabel: true
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross'
},
padding: [5, 10]
},
yAxis: {
name: '%',
axisTick: {
show: false
}
},
dataZoom: [
{
start: 30,
end: 70,
}
],
series: [{
name: '占用率',
itemStyle: {
normal: {
color: '#FF005A',
lineStyle: {
color: '#FF005A',
width: 2
}
}
},
smooth: true,
type: 'line',
areaStyle: {},
data: []
}]
}
}
},
watch: {
data: {
deep: true,
handler({xData, vData}) {
if (!xData || !vData) return
this.setOptions({xData, vData})
}
}
},
methods: {
init() {
this.chart.setOption(this.options)
},
$_getChartDom() {
return this.$el.querySelector('.line-chart')
},
setOptions({xData, vData} = {}) {
this.chart.setOption({
xAxis: {data: xData},
series: [{data: vData}]
})
}
}
}
</script>

@ -1,128 +0,0 @@
<template>
<el-card class="chart-card">
<div slot="header">
<span><b>内存监控</b></span>
<span class="title-span">{{data.used|numberFormatter}} / {{data.total|numberFormatter}}</span>
<span class="title-span">
当前使用率
<count-to
:decimals="2"
:end-val="data.utilizationRate"
:start-val="data.lastUtilizationRate"
suffix="%"
/>
</span>
<span class="title-span">
峰值
<count-to
:decimals="2"
:end-val="data.maxUtilizationRate"
:start-val="data.lastMaxUtilizationRate"
suffix="%"
/>
</span>
</div>
<div class="line-chart"/>
</el-card>
</template>
<script>
import {logic, resize} from "@/mixins/chart"
import CountTo from 'vue-count-to'
export default {
name: "Memory",
mixins: [resize, logic],
components: {CountTo},
props: {
data: Object
},
data() {
return {
options: {
xAxis: {
data: [],
type: 'category',
axisTick: {
show: false
}
},
grid: {
left: 10,
right: 10,
bottom: 20,
top: 30,
containLabel: true
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross'
},
padding: [5, 10]
},
yAxis: {
name: '%',
axisTick: {
show: false
}
},
dataZoom: [
{
start: 30,
end: 70,
}
],
series: [{
name: '占用率',
itemStyle: {
normal: {
color: '#FF005A',
lineStyle: {
color: '#FF005A',
width: 2
}
}
},
smooth: true,
type: 'line',
areaStyle: {},
data: []
}]
}
}
},
watch: {
data: {
deep: true,
handler({xData, vData}) {
if (!xData || !vData) return
this.setOptions({xData, vData})
}
}
},
methods: {
init() {
this.chart.setOption(this.options)
},
$_getChartDom() {
return this.$el.querySelector('.line-chart')
},
setOptions({xData, vData} = {}) {
this.chart.setOption({
xAxis: {data: xData},
series: [{data: vData}]
})
}
}
}
</script>

@ -1,172 +0,0 @@
<template>
<div>
<div class="tip-row">
<span>启动时间{{operatingInfo.bootedTime}}</span>
<span style="margin-left: 20px">运行时间{{operatingInfo.upTime|timePass}}</span>
</div>
<cpu-info :data="cpuInfo"/>
<el-row :gutter="40" style="margin-top: 32px">
<el-col :span="12">
<memory-info :data="memoryInfo"/>
</el-col>
<el-col :span="12">
<jvm-info :data="jvmInfo"/>
</el-col>
</el-row>
</div>
</template>
<script>
import {getMonitorInfo} from "@/api/system/monitor"
import CpuInfo from './components/Cpu'
import MemoryInfo from './components/Memory'
import JvmInfo from './components/Jvm'
import {timeFormat} from "@/utils"
import {sub} from "@/utils/math"
export default {
name: "systemMonitor",
components: {CpuInfo, MemoryInfo, JvmInfo},
data() {
return {
loading: false,
info: {
diskInfo: [{
"name": "",
"remain": 0,
"total": 0,
"used": 0,
"utilizationRate": 0
}]
},
expire: 60,
time: '',
refreshTimer: null,
operatingInfo: {
bootedTime: 'NaN',
upTime: 'NaN'
},
cpuInfo: {
name: '',
core: 'NaN',
utilizationRate: 0.00,
lastUtilizationRate: 0.00,
maxUtilizationRate: 0.00,
lastMaxUtilizationRate: 0.00,
xData: [],
vData: []
},
memoryInfo: {
total: 0,
used: 0,
utilizationRate: 0.00,
lastUtilizationRate: 0.00,
maxUtilizationRate: 0.00,
lastMaxUtilizationRate: 0.00,
xData: [],
vData: []
},
jvmInfo: {
total: 0,
used: 0,
remain: 0,
utilizationRate: 0.00,
lastUtilizationRate: 0.00,
maxUtilizationRate: 0.00,
lastMaxUtilizationRate: 0.00,
xData: [],
vData: []
}
}
},
methods: {
getData() {
if (this.loading) return
this.loading = true
getMonitorInfo()
.then(data => {
this.expire = data.expire
this.time = timeFormat('HH:mm:ss', new Date(data.timestamp))
this.handleOperatingInfo(data.operatingInfo)
this.handleCpuInfo(data.cpuInfo)
this.handleMemoryInfo(data.memoryInfo)
this.handleJvmInfo(data.jvmInfo)
})
.finally(() => this.loading = false)
},
handleOperatingInfo(info) {
this.operatingInfo.bootedTime = timeFormat(null, new Date(info.bootedTime * 1000))
this.operatingInfo.upTime = info.upTime
},
handleCpuInfo(info) {
let used = (Number)(sub(100, info.idle).toFixed(2))
this.cpuInfo.name = info.name
this.cpuInfo.core = info.core
this.cpuInfo.lastUtilizationRate = this.cpuInfo.utilizationRate
this.cpuInfo.utilizationRate = used
if (used > this.cpuInfo.maxUtilizationRate) {
this.cpuInfo.lastMaxUtilizationRate = this.cpuInfo.maxUtilizationRate
this.cpuInfo.maxUtilizationRate = used
}
this.cpuInfo.xData.push(this.time)
this.cpuInfo.vData.push(used)
},
handleMemoryInfo(info) {
info.utilizationRate = (Number)(info.utilizationRate.toFixed(2))
this.memoryInfo.total = info.total
this.memoryInfo.used = info.used
this.memoryInfo.remain = info.remain
this.memoryInfo.lastUtilizationRate = this.memoryInfo.utilizationRate
this.memoryInfo.utilizationRate = info.utilizationRate
if (info.utilizationRate > this.memoryInfo.maxUtilizationRate) {
this.memoryInfo.lastMaxUtilizationRate = this.memoryInfo.maxUtilizationRate
this.memoryInfo.maxUtilizationRate = info.utilizationRate
}
this.memoryInfo.xData.push(this.time)
this.memoryInfo.vData.push(info.utilizationRate)
},
handleJvmInfo(info) {
info.utilizationRate = (Number)(info.utilizationRate.toFixed(2))
this.jvmInfo.total = info.total
this.jvmInfo.used = info.used
this.jvmInfo.remain = info.remain
this.jvmInfo.lastUtilizationRate = this.jvmInfo.utilizationRate
this.jvmInfo.utilizationRate = info.utilizationRate
if (info.utilizationRate > this.jvmInfo.maxUtilizationRate) {
this.jvmInfo.lastMaxUtilizationRate = this.jvmInfo.maxUtilizationRate
this.jvmInfo.maxUtilizationRate = info.utilizationRate
}
this.jvmInfo.xData.push(this.time)
this.jvmInfo.vData.push(info.utilizationRate)
},
},
mounted() {
this.getData()
this.refreshTimer = setInterval(() => this.getData(), 40000)
}
}
</script>
<style lang="scss">
.chart-card {
width: 100%;
.title-span {
margin-left: 20px
}
.line-chart {
height: 250px;
}
}
</style>

@ -12,7 +12,11 @@
<el-input v-model="form.name" :readonly="!canEdit" maxlength="20"/>
</el-form-item>
<el-form-item label="角 色:" prop="role">
<role-selector v-model="form.role" :disabled="!canEdit" @get-name="form.role_name=$event"/>
<role-selector
v-model="form.role"
:disabled="!canEdit"
@get-name="e => form.role_name = e"
/>
</el-form-item>
<el-form-item label="状 态:" prop="status">
<el-radio-group v-model="form.status" :disabled="!canEdit">
@ -53,7 +57,7 @@
data() {
const validateName = (r, v, c) => {
checkName(this.form.name)
checkName(this.form.name, this.form.id)
.then(({msg}) => msg ? c(msg) : c())
.catch(e => c(e))
}

@ -48,7 +48,11 @@
>
</el-table-column>
<el-table-column align="center" label="用户名" prop="name" show-overflow-tooltip/>
<el-table-column align="center" label="角 色" prop="role_name" show-overflow-tooltip/>
<el-table-column align="center" label="角 色" show-overflow-tooltip>
<template v-slot="{row}">
{{row.admin===1?'超级管理员':row.role_name}}
</template>
</el-table-column>
<el-table-column align="center" label="创建时间" width="150" show-overflow-tooltip>
<template v-slot="{row}">{{row.ctime | timestamp2Date}}</template>
</el-table-column>

@ -25,6 +25,7 @@
</template>
<script>
import md5 from "js-md5"
import DialogForm from '@/components/DialogForm'
import dialogMixin from "@/mixins/dialogMixin"
import {updateUserPwd} from "@/api/account"
@ -77,7 +78,10 @@
this.$refs.form.validate(v => {
if (!v) return
this.loading = true
updateUserPwd(this.form)
updateUserPwd({
old_pwd: md5(this.form.old_pwd),
new_pwd: md5(this.form.new_pwd),
})
.then(() => elSuccess('修改成功'))
.finally(() => {
this.loading = false

Loading…
Cancel
Save