Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
wangcheng15 committed Apr 11, 2022
1 parent 1397135 commit 6517184
Show file tree
Hide file tree
Showing 12 changed files with 374 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/assets/css/variable.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ $cellTextColor: #39414D;
$cellCommentColor: #66A0A4;
$cellStringColor: #1021D5;
$cellKeywordColor: #CF2F72;
$pattern-grey-100: #A5B2C5;
$pattern-blue-100: #CEE6FD;
$pattern-blue-200: #e6f1fb;
$pattern-blue-300: #3991e1;
Expand Down
7 changes: 6 additions & 1 deletion src/components/CreateConnection/Form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
<div class="connect-form">
<el-form size="small" ref="form" :model="form" :rules="rules">
<el-form-item :label="$t('settings.connectionName')" prop="name">
<el-input v-model.trim="form.name" :placeholder="$t('pleaseInput')" />
<el-input v-model.trim="form.name" :placeholder="$t('pleaseInput')">
<template slot="prepend">{{ userInfo.username + '_' }}</template>
</el-input>
</el-form-item>
<el-form-item :label="$t('settings.dataSource')" prop="datasource">
<el-select v-model="form.datasource" style="width: 100%;" @change="value => handleInput('datasource', value)" :placeholder="$t('pleaseSelect')">
Expand Down Expand Up @@ -70,6 +72,9 @@ import { encryptData } from '@/util'
@Component({
computed: {
...mapState({
userInfo: state => state.user.userInfo
}),
...mapState('CreateConnectionModal', {
form: state => state.form,
type: state => state.type,
Expand Down
5 changes: 4 additions & 1 deletion src/components/CreateConnection/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ import Form from './Form.vue'
@Component({
computed: {
...mapState({
userInfo: state => state.user.userInfo
}),
...mapState('CreateConnectionModal', {
isShow: state => state.isShow,
form: state => state.form,
Expand Down Expand Up @@ -83,7 +86,7 @@ export default class CreateConnectionModal extends Vue {
await this.$refs.ruleForm.checkForm()
this.isSubmiting = true
const params = {
name: this.form.name,
name: this.userInfo.username + '_' + this.form.name,
content: { ...this.form }
}
if (params.content.password) {
Expand Down
192 changes: 192 additions & 0 deletions src/components/Header/EngineInfo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
<template>
<div class="pop-wrap">
<el-popover v-if="userInfo" :trigger="'hover'" :placement="'bottom'">
<div class="engine-detail">
<div class="detail-item">
<div class="item-label">{{ $t('menu.engine_status') }}</div>
<div class="item-value">{{ $t('menu.state.' + getEngineStatus()) }}</div>
</div>
<div class="detail-item">
<div class="item-label">{{ $t('menu.heart_beat') }}</div>
<div class="item-value">
<span>{{ $t('menu.step') }}</span>
<i class="el-ksd-icon-refresh_22" @click="refreshEngineInfo"></i>
</div>
</div>
<div class="detail-item">
<div class="item-label">{{ $t('menu.usage') }}</div>
<div class="item-value">
<el-progress :percentage="engineUsage" :format="format" :color="customColor"></el-progress>
</div>
</div>
</div>
<section slot="reference" v-if="userInfo" class="engine-info-wrap">
<span class="engine-status" :class="getEngineStatus()"></span>
<span class="engine-label">{{ engineName || '' }}</span>
</section>
</el-popover>
</div>
</template>

<script>
import Vue from 'vue';
import Component from 'vue-class-component';
import { Watch } from 'vue-property-decorator';
import { mapActions, mapState } from 'vuex';
import { ENGINE_STATUS } from '../../config';
import { actionsTypes } from '../../store';
@Component({
computed: {
...mapState({
userInfo: state => state.user.userInfo,
engineInfo: state => state.settings.engineInfo
})
},
methods: {
...mapActions({
getEngineInfo: actionsTypes.GET_ENGINE_INFO
})
}
})
export default class EngineInfo extends Vue {
timer = null
customColor = '#0875DA'
get engineStatus () {
return this.engineInfo?.status
}
get engineName () {
return this.engineInfo?.name
}
get engineUsage () {
if (this.engineInfo && this.engineInfo.usage) {
return Math.round(this.engineInfo.usage * 100)
} else {
return 0
}
}
@Watch('userInfo', { immediate: true })
handlerUserInfoChanged (newVal) {
if (newVal) {
this.getEngineInfo()
this.initInterval()
} else {
this.clear()
}
}
format (percentage) {
let label = ''
if (this.engineStatus === 0) {
label = this.$t('menu.percentage.unavailable')
this.customColor = '#E03B3B'
}
if (percentage > 80) {
label = this.$t('menu.percentage.crowded')
this.customColor = '#E03B3B'
} else {
label = this.$t('menu.percentage.available')
this.customColor = '#0875DA'
}
return label
}
async refreshEngineInfo () {
this.clear()
try {
const res = await this.getEngineInfo('?refresh=true')
if (res && res.code === '') {
this.$message.success(this.$t('menu.refresh_success'))
}
} catch (err) {
console.log(err)
} finally {
this.initInterval()
}
}
getEngineStatus () {
return ENGINE_STATUS[this.engineStatus]
}
initInterval () {
this.timer = setInterval(() => {
this.getEngineInfo()
}, 10000)
}
clear () {
if (this.timer) {
clearInterval(this.timer)
}
}
beforeDestroy () {
this.clear()
}
}
</script>
<style lang="scss" scoped>
@import '../../assets/css/variable.scss';
.pop-wrap {
display: flex;
align-items: center;
.engine-info-wrap {
margin-right: 10px;
display: inline-flex;
align-items: center;
cursor: pointer;
.engine-status {
margin-right: 10px;
width: 10px;
height: 10px;
border-radius: 5px;
&.available {
background: $pattern-green-500;
}
&.unavailable {
background: $pattern-grey-100;
}
}
.engine-label {
color: $--color-white;
}
}
}
.engine-detail {
display: flex;
flex-direction: column;
.detail-item {
display: flex;
align-items: center;
margin: 8px;
.item-label {
color: $findAndReplaceTitleColor;
font-weight: bold;
white-space: pre;
}
.item-value {
display: inline-flex;
align-items: center;
width: 100%;
min-width: 280px;
white-space: nowrap;
.el-progress {
width: 100%;
}
i {
margin-left: 6px;
cursor: pointer;
}
}
}
}
</style>
8 changes: 6 additions & 2 deletions src/components/Header/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<header-menu v-if="!isLoginPage"></header-menu>
</div>
<div class="page-header-right">
<EngineInfo />
<GlobalHelp />
<ChangeLang />
<UserInfo class="page-header-right-item" v-if="!isLoginPage" />
Expand All @@ -18,17 +19,20 @@ import { Component } from 'vue-property-decorator'
import HeaderMenu from './HeaderMenu'
import UserInfo from './UserInfo'
import GlobalHelp from './GlobalHelp'
import ChangeLang from './ChangeLang.vue'
import ChangeLang from './ChangeLang'
import EngineInfo from './EngineInfo'
import { mapState } from 'vuex'
@Component({
components: {
HeaderMenu,
UserInfo,
GlobalHelp,
ChangeLang
ChangeLang,
EngineInfo
},
computed: {
...mapState({
userInfo: state => state.user.userInfo,
isTrial: state => state.global.is_trial
}),
isLoginPage () {
Expand Down
5 changes: 5 additions & 0 deletions src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,8 @@ export const ACTION_OF_STATE = {
[INSTANCE_STATE['9']]: [0, 0, 5, 0],
[INSTANCE_STATE['10']]: [0, 0, 5, 0]
}

export const ENGINE_STATUS = {
0: 'unavailable',
2: 'available'
}
16 changes: 15 additions & 1 deletion src/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,21 @@
"schedules": "Schedules",
"settings": "Settings",
"give_feedback": "Give Feedback",
"Byzer_docs": "Byzer Notebook Docs"
"Byzer_docs": "Byzer Notebook Docs",
"engine_status": "Engine State: ",
"heart_beat": "Heartbeat Detection: ",
"usage": "Resource Rate: ",
"state": {
"available": "Running",
"unavailable": "Disabled"
},
"percentage": {
"available": "Normal",
"unavailable": "Disabled",
"crowded": "Crowded"
},
"step": "Auto-refresh engine state every 10 seconds",
"refresh_success": "Engine state refreshed successfully"
},
"home": {
"quick_start": "Quick Start",
Expand Down
16 changes: 15 additions & 1 deletion src/locale/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,21 @@
"schedules": "调度",
"settings": "设置",
"give_feedback": "反馈",
"Byzer_docs": "Byzer Notebook 手册"
"Byzer_docs": "Byzer Notebook 手册",
"engine_status": "引擎状态:",
"heart_beat": "心跳检测:",
"usage": "资源占比:",
"state": {
"available": "运行中",
"unavailable": "不可用"
},
"percentage": {
"available": "正常",
"unavailable": "不可用",
"crowded": "拥挤"
},
"step": "每 10 秒自动刷新引擎状态",
"refresh_success": "引擎状态刷新成功"
},
"home": {
"quick_start": "快速开始",
Expand Down
Loading

0 comments on commit 6517184

Please sign in to comment.