2021-11-30 16:39:21 +08:00
< template >
2023-03-17 14:38:32 +08:00
< div v -clickoutside : [ isStable ] = " { obj : editChart , oldData : oldData , func : clickOutside } " :class = "boxClass" class = "right-box right-box-chart" >
2021-11-30 16:39:21 +08:00
< transition v-if = "from !== 'chartTemp'" name="right-box" >
2021-12-23 15:44:27 +08:00
<!-- < panel-box v-if = "!showPanel.type" ref="panelBox2" :panel="panel" @reload="panelReload" > < / panel -box > -- >
2021-11-30 16:39:21 +08:00
< / transition >
< div class = "right-box__header" >
2023-03-17 12:46:56 +08:00
< div class = "header__title" v-if = "from !== 'chartTemp'" > {{ editChart.id ? $ t ( " dashboard.dashboard.editChartTitle " ) : $ t ( " overall.createChart " ) }} < / div >
< div class = "header__title" v-if = "from === 'chartTemp'" > {{ editChart.id ? $ t ( " dashboard.dashboard.editChartTempTitle " ) : $ t ( " dashboard.dashboard.createChartTempTitle " ) }} < / div >
2021-11-30 16:39:21 +08:00
< div class = "header__operation" >
2023-01-06 16:17:31 +08:00
< span v -cancel : [ isStable ] = " { obj : editChart , func : clickOutside } " > < i class = "nz-icon nz-icon-close" :title = "$t('overall.close')" > < / i > < / span >
2021-11-30 16:39:21 +08:00
< / div >
< / div >
<!-- begin -- 表单 -- >
2021-12-01 16:34:50 +08:00
< div class = "right-box-form-box right-box__container chart-right-box" >
2023-06-19 18:11:24 +08:00
< el-form ref = "chartForm" :model = "editChart" :rules = "rules" label -position = " top " label -width = " 120px " @submit.native.prevent >
2022-06-16 15:58:17 +08:00
< el-form-item : label = '$t("overall.name")' prop = "name" >
2022-05-17 18:54:19 +08:00
< div style = "display:flex;align-items:center" >
2022-11-18 16:18:49 +08:00
< el-input style = "flex:1;margin-right:10px" maxlength = "64" show -word -limit size = "small" v-model = "editChart.name" id="chart-box-title" > < / el -input >
2022-05-17 18:54:19 +08:00
<!-- 显示头部 -- >
2022-07-01 09:39:20 +08:00
< div class = "choose-header-btn" v-if = "editChart.param&&editChart.param.showHeader!==0" @click="switchHeader(0)" :title="$t('overall.visible')" >
2022-05-17 18:54:19 +08:00
< i class = "nz-icon nz-icon-mimakejian" > < / i >
< / div >
<!-- 隐藏头部 -- >
2022-07-01 09:39:20 +08:00
< div class = "choose-header-btn" v-else @click ="switchHeader(1)" :title = "$t('overall.invisible')" >
2022-05-17 18:54:19 +08:00
< i class = "nz-icon nz-icon-mimabukejian" > < / i >
< / div >
< / div >
2021-11-30 16:39:21 +08:00
< / el-form-item >
< div class = "form-items--half-width-group" >
<!-- panel -- >
< el-form-item
class = "form-item--half-width"
2023-07-27 10:22:50 +08:00
v - if = "showPanel.type !== fromRoute.project && showPanel.type !== fromRoute.asset && showPanel.type !== fromRoute.endpoint && showPanel.type !== fromRoute.model"
2022-07-12 17:10:45 +08:00
: label = "$t('overall.dashboard')"
2021-11-30 16:39:21 +08:00
prop = "panelName"
>
2023-07-27 10:22:50 +08:00
< select-panel ref = "selectPanel" : disabled = "showPanel.type === 'dashboard' || from ==='dashboardTemp'" :filter-panel = "filterPanel" :chart-box = "true" :panel-lock = "true" :panelData = "panelData" :placement = "'bottom-start'" @selectPanel ="selectPanel" >
2021-11-30 16:39:21 +08:00
< template v -slot : header >
< div class = "panel-select-header" >
< el-input id = "chart-box-panelname" v-model = "filterPanel" :placeholder="$t('overall.search')" clearable size="small" style="width: 596px" > < / el -input >
< / div >
< / template >
< template v -slot : trigger >
2023-07-27 10:22:50 +08:00
< el-input placeholder = "" readonly = "readonly" size = "small" v-model = "editChart.panelName" :disabled="showPanel.type==='dashboard' || from ==='dashboardTemp'" > < / el -input >
2021-11-30 16:39:21 +08:00
< / template >
< / select-panel >
< / el-form-item >
<!-- group -- >
2023-03-17 12:46:56 +08:00
< el-form-item :label = "$t('dashboard.dashboard.chartForm.group')" class = "form-item--half-width" prop = "group" >
2023-03-01 17:49:20 +08:00
< el-select id = "chart-box-group" v-model = "editChart.groupId" :disabled="editChart.type==='group'" clearable placeholder="" popper-class="right-box-select-top prevent-clickoutside el-option-width303" size="small" value-key="chartType" >
2021-11-30 16:39:21 +08:00
< el-option v-for = "item in groupArr" :key="item.id" :label="item.name" :value="item.id" >
< span class = "panel-dropdown-label-txt" > { { item . name } } < / span >
< / el-option >
< / el-select >
< / el-form-item >
< / div >
<!-- remark -- >
< el-form-item :label = "$t('overall.remark')" >
2022-11-18 16:18:49 +08:00
< el-input maxlength = "256" show -word -limit v-model = "editChart.remark" size="small" :rows="2" type="textarea" />
2021-11-30 16:39:21 +08:00
< / el-form-item >
2021-12-24 16:06:17 +08:00
<!-- remark -- >
2021-12-24 16:36:21 +08:00
< el-form-item :label = "$t('overall.link')" v-if = "editChart.param" >
2022-11-18 16:18:49 +08:00
< el-input maxlength = "256" show -word -limit v-model = "editChart.param.link" size="small" :rows="2" type="textarea" />
2021-12-24 16:06:17 +08:00
< / el-form-item >
2021-11-30 16:39:21 +08:00
<!-- title -- >
< div class = "form__sub-title" >
2023-03-17 12:46:56 +08:00
< span > { { $t ( 'dashboard.dashboard.chartForm.dataConfig' ) } } < / span >
2021-11-30 16:39:21 +08:00
< / div >
2021-12-03 17:59:27 +08:00
< el-tabs v-model = "editChart.datasource" @tab-click="datasourceChange" type="card" >
2022-07-12 14:06:14 +08:00
< el-tab-pane :label = "$t('overall.metrics')" name = "metrics" >
2022-07-15 15:06:56 +08:00
< chart-config :variables = "variables" ref = "childrenFrommetrics" :type = "'metrics'" v-if = "editChart.datasource == 'metrics'" :params.sync="editChart" @change="editChartChange" />
2021-11-30 16:39:21 +08:00
< / el-tab-pane >
2022-03-24 15:59:05 +08:00
< el-tab-pane :label = "$t('overall.logs')" name = "logs" >
2023-08-24 13:56:40 +08:00
< chart-config :variables = "variables" ref = "childrenFromlogs" :type = "'log'" v-if = "editChart.datasource == 'logs'" :params.sync="editChart" @change="editChartChange" class="datasource-log" />
2021-11-30 16:39:21 +08:00
< / el-tab-pane >
2022-03-24 15:59:05 +08:00
< el-tab-pane :label = "$t('overall.system')" name = "system" >
2022-07-15 15:06:56 +08:00
< system-chart-config :variables = "variables" ref = "childrenFromsystem" v-if = "editChart.datasource == 'system'" :params.sync="editChart" @change="editChartChange" />
2021-11-30 16:39:21 +08:00
< / el-tab-pane >
2022-03-24 15:59:05 +08:00
< el-tab-pane :label = "$t('overall.misc')" name = "misc" >
2022-07-15 15:06:56 +08:00
< other-chart-config :variables = "variables" ref = "childrenFrommisc" v-if = "editChart.datasource == 'misc'" :params.sync="editChart" @change="editChartChange" />
2021-11-30 16:39:21 +08:00
< / el-tab-pane >
< / el-tabs >
< / el-form >
< / div >
<!-- 底部按钮 -- >
< div class = "right-box__footer" >
2023-01-06 16:17:31 +08:00
< button id = "chart-box-esc" v -cancel :[isStable] = "{obj:editChart,func:esc}" class = "footer__btn footer__btn--light" >
2021-11-30 16:39:21 +08:00
< span > { { $t ( 'overall.cancel' ) } } < / span >
< / button >
2022-01-11 11:00:03 +08:00
< button v-if = "showPanel.type && showPanel.type == 'model'" id="chart-box-Sync" v-has="'main_edit'" class="footer__btn" >
2021-11-30 16:39:21 +08:00
< span > { { $t ( 'overall.SyncSave' ) } } < / span >
< / button >
2021-12-23 17:02:21 +08:00
< button v-else-if = "from!=='chartTemp'" id="chart-box-preview" class="footer__btn" @click="preview(true)" >
2021-11-30 16:39:21 +08:00
< span > { { $t ( 'overall.preview' ) } } < / span >
< / button >
2022-01-11 11:00:03 +08:00
< button id = "chart-box-save" v-has = "'main_add'" :class="{'nz-btn-disabled':prevent_opt.save}" :disabled="prevent_opt.save" class="footer__btn" @click="save" >
2021-11-30 16:39:21 +08:00
< span > { { $t ( 'overall.save' ) } } < / span >
< / button >
< / div >
2022-09-27 14:48:34 +08:00
<!-- 预览 -- >
2021-12-23 17:02:21 +08:00
< el-dialog
v - if = "previewShow"
: visible . sync = "previewShow"
: show - close = "false"
class = "nz-dialog chart-fullscreen"
destroy - on - close
fullscreen
: modal - append - to - body = "false"
>
< panel-chart
2022-08-04 09:59:56 +08:00
v - if = "prevChart"
2023-06-08 15:33:35 +08:00
: nowTimeType = " {
id : 4 ,
type : 'hour' ,
value : 1
} "
2022-08-04 09:59:56 +08:00
style = "height: 100%;width: 100%"
2021-12-23 17:02:21 +08:00
: ref = "'chart-fullscreen-previewShow'"
: chart - info = "prevChart"
: from = "from"
: filter = "{}"
: is - fullscreen = "true"
: time - range = "timeRange"
@ showFullscreen = "preview"
> < / panel-chart >
< / el-dialog >
2021-11-30 16:39:21 +08:00
< / div >
< / template >
< script >
import { fromRoute } from '@/components/common/js/constants'
import editRigthBox from '@/components/common/mixin/editRigthBox'
2023-03-06 16:04:52 +08:00
import { resetZIndex , getUUID , s8 } from '@/components/common/js/common'
2021-11-30 16:39:21 +08:00
import selectPanel from '@/components/common/popBox/selectPanel'
2021-12-02 14:09:49 +08:00
import chartConfig from '@/components/common/rightBox/chart/chartConfig'
2021-11-30 16:39:21 +08:00
import otherChartConfig from '@/components/common/rightBox/chart/otherChartConfig'
import systemChartConfig from '@/components/common/rightBox/chart/systemChartConfig'
2021-12-23 17:02:21 +08:00
import panelChart from '@/components/chart/panelChart'
import lodash from 'lodash'
2022-01-05 15:54:42 +08:00
import bus from '@/libs/bus'
2023-01-18 09:06:31 +08:00
import chartTypeShow from '@/components/common/rightBox/chart/chartTypeShow'
2021-12-23 17:02:21 +08:00
2021-11-30 16:39:21 +08:00
const rz = {
methods : {
rz ( e ) {
resetZIndex ( e )
}
}
}
export default {
name : 'chartRightBox' ,
props : {
boxClass : String ,
panelData : Array ,
showPanel : Object ,
chart : Object ,
from : { type : String } ,
fromEndpoint : {
type : Boolean ,
default : false
}
} ,
2023-01-18 09:06:31 +08:00
mixins : [ rz , editRigthBox , chartTypeShow ] ,
2021-11-30 16:39:21 +08:00
components : {
selectPanel ,
2021-12-02 14:09:49 +08:00
chartConfig ,
2021-11-30 16:39:21 +08:00
systemChartConfig ,
2021-12-23 17:02:21 +08:00
otherChartConfig ,
panelChart
2021-11-30 16:39:21 +08:00
} ,
2021-12-17 14:28:49 +08:00
computed : {
chartLastPosition ( ) {
return this . $store . getters . getChartLastPosition
2022-11-17 18:05:36 +08:00
} ,
variables ( ) {
return this . $store . state . panel . variablesArr
2021-12-17 14:28:49 +08:00
}
} ,
2021-11-30 16:39:21 +08:00
data ( ) {
return {
fromRoute ,
2021-12-23 17:02:21 +08:00
previewShow : false ,
2021-11-30 16:39:21 +08:00
editChart : {
name : '' ,
2021-12-24 16:06:17 +08:00
remark : '' ,
link : ''
2021-11-30 16:39:21 +08:00
} ,
panel : {
id : '' ,
name : ''
} ,
2021-12-23 17:02:21 +08:00
timeRange : [ ] ,
2022-08-04 09:59:56 +08:00
prevChart : '' ,
2021-11-30 16:39:21 +08:00
filterPanel : '' ,
groupArr : [ ] ,
2022-01-04 16:26:43 +08:00
varTypeArr : [
2022-03-25 14:12:03 +08:00
{ name : this . $t ( 'asset.asset' ) , id : 1 } ,
{ name : this . $t ( 'asset.endpoint' ) , id : 2 }
2022-01-04 16:26:43 +08:00
] ,
2021-11-30 16:39:21 +08:00
panelName : '' ,
rules : {
2021-12-02 11:14:27 +08:00
name : [ { required : true , message : this . $t ( 'validate.required' ) , trigger : 'change' } ] ,
panelName : [ { required : true , message : this . $t ( 'validate.required' ) , trigger : 'change' } ]
2021-11-30 16:39:21 +08:00
}
}
} ,
methods : {
2022-05-17 18:54:19 +08:00
switchHeader ( value ) {
// 1为显示 0为隐藏
2022-05-19 16:55:27 +08:00
this . $set ( this . editChart . param , 'showHeader' , value )
2022-05-17 18:54:19 +08:00
} ,
2021-11-30 16:39:21 +08:00
clickOutside ( ) {
this . esc ( false )
} ,
/* 关闭弹框 */
esc ( refresh ) {
this . prevent _opt . save = false
this . $emit ( 'close' , refresh )
} ,
// 保存endpoint
save ( ) {
2022-04-01 10:48:43 +08:00
const self = this
let resetFlag = false // 页面是否需要重排
2021-12-02 11:14:27 +08:00
const arr = [ this . $refs . chartForm . validate ( ) ]
arr . push ( this . $refs [ 'childrenFrom' + this . editChart . datasource ] . $refs . chartForm . validate ( ) )
Promise . all ( arr ) . then ( res => {
2023-03-15 15:39:06 +08:00
this . editChart . dashboardId = this . dashboardId
2021-12-06 11:40:06 +08:00
const params = JSON . parse ( JSON . stringify ( this . editChart ) )
2022-10-14 17:11:55 +08:00
if ( params . param . valueMapping ) {
params . param . valueMapping . forEach ( item => {
delete item . uid
} )
}
2023-05-26 18:01:27 +08:00
if ( params . param . dataLink ) {
params . param . dataLink . forEach ( item => {
delete item . error
} )
}
2021-12-13 20:30:33 +08:00
if ( params . type === 'group' ) {
params . height = 1
}
2021-12-06 11:40:06 +08:00
if ( ! params . groupId ) {
2021-12-06 15:25:09 +08:00
params . groupId = 0
2021-12-06 11:40:06 +08:00
}
2023-01-18 09:06:31 +08:00
if ( ! this . isShowMinMax ( params . type ) ) {
2021-12-24 15:32:16 +08:00
delete params . param . min
delete params . param . max
}
2023-03-21 16:53:15 +08:00
if ( ! this . isStat ( params . type ) ) {
2023-02-13 15:27:30 +08:00
delete params . param . sparklineMode
2023-03-21 16:53:15 +08:00
delete params . param . comparison
2023-02-13 15:27:30 +08:00
}
2022-03-01 14:23:39 +08:00
if ( ! params . x && ! params . y && this . from === 'endpointQuery' ) { // endpointQuery 新增 放在最后
2021-12-17 16:39:22 +08:00
params . x = 0
params . y = 999
}
2022-03-18 09:39:04 +08:00
if ( this . from === 'explore' ) { // explore 新增 放在最后
params . x = 0
params . y = 999
}
2022-03-01 14:23:39 +08:00
if ( ! params . x && ! params . y && this . from === 'chartTemp' ) { // chartTemp 新增 在第一位
params . x = 0
params . y = 0
}
2022-03-30 17:25:15 +08:00
if ( isNaN ( params . y ) && isNaN ( params . y ) && params . groupId ) { // group 内的坐标需要单独计算
2021-12-23 15:44:27 +08:00
params . x = 0
params . y = 999
}
2022-03-30 17:25:15 +08:00
if ( isNaN ( params . y ) && isNaN ( params . y ) ) {
2021-12-30 11:33:24 +08:00
params . x = this . chartLastPosition . x + params . span > 12 ? 0 : this . chartLastPosition . x
params . y = this . chartLastPosition . y + 12
}
2022-03-30 17:45:45 +08:00
if ( params . x + params . span > 12 ) {
params . x = 0
params . y += 1
2022-04-01 10:48:43 +08:00
resetFlag = true
2022-03-30 17:45:45 +08:00
}
2023-04-04 17:44:05 +08:00
if ( params . groupId ) { // group 内部坐标不能包含小数
params . x = parseInt ( params . x )
params . y = parseInt ( params . y )
}
2021-12-06 15:25:09 +08:00
delete params . panel
2021-12-15 09:51:04 +08:00
if ( params . type === 'table' ) {
delete params . param . tags
}
2022-02-21 18:03:21 +08:00
if ( params . datasource === 'system' && params . param . datasource [ 0 ] . filter ) {
params . param . datasource [ 0 ] . filter = params . param . datasource [ 0 ] . filter . filter ( item => item . value )
}
2021-12-06 11:40:06 +08:00
if ( params . id ) { // 修改
2023-03-15 15:39:06 +08:00
this . $put ( 'visual/dashboard/chart' , params ) . then ( response => {
2021-12-02 15:36:01 +08:00
if ( response . code === 200 ) {
this . $message ( { duration : 1000 , type : 'success' , message : this . $t ( 'tip.saveSuccess' ) } )
2022-04-01 10:48:43 +08:00
if ( resetFlag ) {
bus . $emit ( 'creat-chart-success' , {
... params ,
cb : function ( ) {
2023-03-15 15:39:06 +08:00
self . $emit ( 'on-create-success' , { id : this . dashboardId , name : this . panelName } )
2022-04-01 10:48:43 +08:00
self . esc ( true )
}
} )
} else {
2023-03-15 15:39:06 +08:00
self . $emit ( 'on-create-success' , { id : this . dashboardId , name : this . panelName } )
2022-04-01 10:48:43 +08:00
self . esc ( true )
}
2021-12-02 15:36:01 +08:00
} else {
this . $message . error ( response . msg )
}
} )
} else { // 新增
2023-03-15 15:39:06 +08:00
this . $post ( 'visual/dashboard/chart' , params ) . then ( response => {
2021-12-02 15:36:01 +08:00
if ( response . code === 200 ) {
this . $message ( { duration : 1000 , type : 'success' , message : this . $t ( 'tip.saveSuccess' ) } )
2022-04-01 10:48:43 +08:00
if ( resetFlag ) {
bus . $emit ( 'creat-chart-success' , {
... params ,
cb : function ( ) {
2023-03-15 15:39:06 +08:00
self . $emit ( 'on-create-success' , { id : this . dashboardId , name : this . panelName } )
2022-04-01 10:48:43 +08:00
self . esc ( true )
}
} )
} else {
2023-03-15 15:39:06 +08:00
self . $emit ( 'on-create-success' , { id : this . dashboardId , name : this . panelName } )
2022-04-01 10:48:43 +08:00
self . esc ( true )
}
2021-12-02 15:36:01 +08:00
} else {
this . $message . error ( response . msg )
}
} )
}
2021-12-02 11:14:27 +08:00
} ) . catch ( res => {
2022-03-15 11:14:42 +08:00
this . $refs [ 'childrenFrom' + this . editChart . datasource ] . showError ( )
2022-07-15 17:05:03 +08:00
// console.info(res)
2021-11-30 16:39:21 +08:00
} )
} ,
selectPanel ( panel ) {
this . panelName = panel . name
2021-12-03 16:58:25 +08:00
this . editChart . panelName = panel . name
2023-03-15 15:39:06 +08:00
this . dashboardId = panel . id
2021-11-30 16:39:21 +08:00
this . editChart . groupId = ''
2023-03-15 15:39:06 +08:00
this . $get ( 'visual/dashboard/chart?dashboardId=' + this . dashboardId + '&pageSize=-1' ) . then ( response => {
2021-11-30 16:39:21 +08:00
if ( response . code === 200 ) {
this . groupArr = [ ]
response . data . list . forEach ( ( item , index ) => {
if ( item . type === 'group' ) {
this . groupArr . push ( { id : item . id , name : item . name } )
}
} )
}
} )
} ,
panelReload ( panelName ) { // 刷新panel下拉框
if ( panelName ) {
this . panelName = panelName
}
this . $emit ( 'reloadOnlyPanel' )
} ,
getGroupList ( ) {
2023-03-15 15:39:06 +08:00
this . $get ( 'visual/dashboard/chart?dashboardId=' + this . dashboardId + '&pageSize=-1' ) . then ( response => {
2021-11-30 16:39:21 +08:00
if ( response . code === 200 ) {
this . groupArr = [ ]
response . data . list . forEach ( ( item , index ) => {
if ( item . type === 'group' ) {
this . groupArr . push ( { id : item . id , name : item . name } )
}
} )
}
} )
} ,
2021-12-02 14:09:49 +08:00
datasourceChange ( ) {
2021-12-06 11:40:06 +08:00
if ( this . editChart . datasource == 'metrics' ) {
2021-12-01 17:12:02 +08:00
this . editChart = {
... this . editChart ,
span : 4 ,
height : 4 ,
unit : 2 ,
type : 'line' ,
2022-07-01 16:42:38 +08:00
elements : [ { expression : '' , legend : '' , type : 'expert' , id : '' , name : 'A' , state : 1 } ] ,
2021-12-01 17:12:02 +08:00
param : {
stack : 0 ,
nullType : 'null' ,
2021-12-16 18:13:47 +08:00
legend : { placement : 'bottom' , values : [ ] } ,
enable : {
2021-12-17 11:18:49 +08:00
thresholds : false ,
2021-12-16 18:13:47 +08:00
legend : true ,
2022-07-15 15:06:56 +08:00
valueMapping : false ,
visibility : false
2021-12-16 18:13:47 +08:00
} ,
2023-03-06 16:04:52 +08:00
thresholds : [ { id : s8 ( ) , value : undefined , color : '#eeeeeeff' } ] ,
2022-07-15 15:06:56 +08:00
showHeader : this . editChart . param . showHeader ,
visibility : {
varName : '' ,
2022-07-18 16:25:02 +08:00
operator : 'equal' ,
2022-07-15 15:06:56 +08:00
varValue : '' ,
2022-07-18 16:25:02 +08:00
result : 'show'
2023-05-26 18:01:27 +08:00
} ,
2023-08-22 17:39:27 +08:00
rightYAxis : {
elementNames : [ ] ,
style : 'line' ,
unit : 2 ,
label : '' ,
min : undefined ,
max : undefined
2023-08-23 14:43:41 +08:00
} ,
2023-05-31 17:20:02 +08:00
dataLink : [ ]
2021-12-02 14:09:49 +08:00
}
}
}
2021-12-06 11:40:06 +08:00
if ( this . editChart . datasource == 'logs' ) {
2021-12-02 14:09:49 +08:00
this . editChart = {
... this . editChart ,
span : 4 ,
height : 4 ,
unit : 2 ,
type : 'log' ,
2022-07-01 16:42:38 +08:00
elements : [ { expression : '' , legend : '' , type : 'expert' , id : '' , name : 'A' , state : 1 } ] ,
2021-12-02 14:09:49 +08:00
param : {
2022-07-15 15:06:56 +08:00
enable : {
thresholds : false ,
legend : true ,
valueMapping : false ,
visibility : false
} ,
2022-05-17 18:54:19 +08:00
limit : 100 ,
2022-07-15 15:06:56 +08:00
showHeader : this . editChart . param . showHeader ,
visibility : {
varName : '' ,
2022-07-18 16:25:02 +08:00
operator : 'equal' ,
2022-07-15 15:06:56 +08:00
varValue : '' ,
2022-07-18 16:25:02 +08:00
result : 'show'
2023-05-26 18:01:27 +08:00
} ,
2023-05-31 17:20:02 +08:00
dataLink : [ ]
2021-12-01 17:12:02 +08:00
}
}
}
2021-12-06 11:40:06 +08:00
if ( this . editChart . datasource == 'system' ) {
2021-12-02 18:33:28 +08:00
this . editChart = {
... this . editChart ,
span : 4 ,
height : 4 ,
unit : 2 ,
2021-12-06 11:40:06 +08:00
type : 'stat' ,
2021-12-02 18:33:28 +08:00
param : {
2021-12-15 17:55:56 +08:00
refer : 0 ,
2021-12-03 10:08:34 +08:00
nullType : 'null' ,
statistics : 'last' ,
2021-12-22 15:11:23 +08:00
text : 'value' ,
2021-12-16 18:13:47 +08:00
enable : {
2021-12-17 11:18:49 +08:00
thresholds : false ,
2021-12-16 18:13:47 +08:00
legend : true ,
2022-07-15 15:06:56 +08:00
valueMapping : false ,
visibility : false
2021-12-16 18:13:47 +08:00
} ,
datasource : [ {
2021-12-16 20:54:00 +08:00
name : 'System' ,
2021-12-16 18:13:47 +08:00
type : 'asset' ,
systemGroup : '' ,
systemSelect : '' ,
group : '' ,
select : '' ,
limit : 100 ,
2021-12-29 14:29:37 +08:00
sort : 'desc' ,
legend : ''
2021-12-03 10:08:34 +08:00
}
2021-12-16 18:13:47 +08:00
] ,
2022-05-17 18:54:19 +08:00
valueMapping : [ ] ,
2022-07-15 15:06:56 +08:00
showHeader : this . editChart . param . showHeader ,
visibility : {
varName : '' ,
2022-07-18 16:25:02 +08:00
operator : 'equal' ,
2022-07-15 15:06:56 +08:00
varValue : '' ,
2022-07-18 16:25:02 +08:00
result : 'show'
2023-05-26 18:01:27 +08:00
} ,
2023-05-31 17:20:02 +08:00
dataLink : [ ]
2021-12-02 18:33:28 +08:00
}
}
delete this . editChart . elements
}
2021-12-06 11:40:06 +08:00
if ( this . editChart . datasource == 'misc' ) {
2021-12-02 14:56:14 +08:00
this . editChart = {
... this . editChart ,
span : 4 ,
height : 4 ,
type : 'url' ,
param : {
2022-07-15 15:06:56 +08:00
enable : {
thresholds : false ,
legend : true ,
valueMapping : false ,
visibility : false
} ,
2022-05-17 18:54:19 +08:00
url : '' ,
2022-07-15 15:06:56 +08:00
showHeader : this . editChart . param . showHeader ,
visibility : {
varName : '' ,
2022-07-18 16:25:02 +08:00
operator : 'equal' ,
2022-07-15 15:06:56 +08:00
varValue : '' ,
2022-07-18 16:25:02 +08:00
result : 'show'
2023-05-31 17:20:02 +08:00
}
2021-12-02 14:56:14 +08:00
}
}
2021-12-02 18:33:28 +08:00
delete this . editChart . elements
2021-12-02 14:56:14 +08:00
}
2021-12-01 16:34:50 +08:00
} ,
editChartChange ( newEditChart ) {
2021-12-03 16:29:05 +08:00
this . editChart = {
... JSON . parse ( JSON . stringify ( newEditChart ) ) ,
name : this . editChart . name ,
remark : this . editChart . remark ,
groupId : this . editChart . groupId ,
2022-02-25 09:32:15 +08:00
panelName : this . editChart . panelName ,
varType : this . editChart . varType
2021-12-03 16:29:05 +08:00
}
2021-12-23 17:02:21 +08:00
} ,
preview ( show ) {
if ( show ) {
2022-08-04 09:59:56 +08:00
this . prevChart = ''
2022-09-27 14:48:34 +08:00
setTimeout ( ( ) => {
2022-08-01 18:04:55 +08:00
const start = new Date ( ) . setHours ( new Date ( ) . getHours ( ) - 1 )
const end = new Date ( )
2023-06-12 10:51:09 +08:00
this . timeRange = [ bus . computeTimezoneTime ( start ) , bus . computeTimezoneTime ( end ) ]
2022-08-04 09:59:56 +08:00
this . prevChart = {
... lodash . cloneDeep ( this . editChart ) ,
loaded : true
}
this . prevChart . param . showHeader = true
} , 200 )
2021-12-23 17:02:21 +08:00
}
2022-08-04 09:59:56 +08:00
this . previewShow = show
2021-11-30 16:39:21 +08:00
}
} ,
created ( ) {
} ,
mounted ( ) {
this . getGroupList ( )
} ,
watch : {
showPanel : {
immediate : true ,
deep : true ,
handler ( ) {
2021-12-23 15:44:27 +08:00
if ( this . showPanel && ( this . showPanel . id || this . from === 'chartTemp' ) ) {
2023-03-15 15:39:06 +08:00
this . dashboardId = this . showPanel . id
2021-11-30 16:39:21 +08:00
this . panelName = this . showPanel . name
this . editChart . panelName = this . showPanel . name
}
}
} ,
chart : {
deep : true ,
immediate : true ,
handler ( n ) {
2022-03-08 10:01:10 +08:00
const obj = JSON . parse ( JSON . stringify ( n ) )
if ( obj . param && ! obj . param . valueMapping ) {
obj . param . valueMapping = [ ]
}
if ( obj . param && ! obj . param . thresholds ) {
obj . param . thresholds = [ ]
2023-03-06 16:04:52 +08:00
} else if ( obj . param && obj . param . thresholds ) {
obj . param . thresholds . forEach ( item => {
item . id = s8 ( )
} )
2022-03-08 10:01:10 +08:00
}
2022-03-29 15:21:28 +08:00
if ( obj . groupId === - 1 ) {
obj . groupId = ''
2021-11-30 16:39:21 +08:00
}
2022-03-29 15:21:28 +08:00
if ( obj . param ) {
2022-04-02 17:41:24 +08:00
if ( ! obj . param . text && obj . param . display ) {
obj . param . text = obj . param . display
}
2022-03-29 15:21:28 +08:00
if ( ! obj . param . link ) {
this . $set ( obj . param , 'link' , '' )
2021-12-24 16:06:17 +08:00
}
2022-03-29 15:21:28 +08:00
if ( ! obj . param . enable ) {
obj . param . enable = {
2022-01-04 16:26:43 +08:00
thresholds : false ,
legend : false ,
2022-07-15 15:06:56 +08:00
valueMapping : false ,
visibility : false
}
}
if ( ! obj . param . visibility ) {
obj . param . visibility = {
varName : '' ,
2023-06-14 17:15:05 +08:00
operator : 'equal' ,
2022-07-15 15:06:56 +08:00
varValue : '' ,
2023-06-14 17:15:05 +08:00
result : 'show'
2022-01-04 16:26:43 +08:00
}
}
2022-11-14 16:00:18 +08:00
if ( obj . type === 'group' && ! obj . param . repeat ) {
obj . param . repeat = {
variable : ''
}
}
2022-01-06 17:42:38 +08:00
// this.editChart.varType = 1
2022-03-29 15:21:28 +08:00
if ( obj . param . enable . legend && ! obj . param . legend ) {
obj . param . legend = { placement : 'bottom' , values : [ ] , show : true }
2021-12-28 10:53:34 +08:00
}
2022-03-29 15:21:28 +08:00
if ( obj . param . datasource && ! obj . param . datasource [ 0 ] . legend ) {
obj . param . datasource [ 0 ] . legend = ''
2021-12-29 14:29:37 +08:00
}
2022-03-29 15:21:28 +08:00
if ( obj . param . valueMapping ) {
obj . param . valueMapping . forEach ( item => {
2022-10-14 17:11:55 +08:00
item . uid = getUUID ( )
2022-01-06 17:42:38 +08:00
if ( ! item . show ) {
item . show = false
}
2022-04-02 17:41:24 +08:00
if ( item . text && ! item . display ) {
item . display = item . text
2022-04-02 18:08:28 +08:00
} else if ( ! item . display ) {
item . display = '{{A.$value}}'
2022-04-02 17:41:24 +08:00
}
if ( item . columns && ! item . column ) {
item . column = item . columns
}
2022-01-06 17:42:38 +08:00
} )
}
2021-12-24 15:32:16 +08:00
}
2023-03-24 15:43:34 +08:00
if ( obj . elements && obj . elements . length ) {
obj . elements . forEach ( ( item , index ) => {
item . orderNum = index
delete item . seq
delete item . buildIn
delete item . chartId
} )
}
2023-06-05 14:52:04 +08:00
this . editChart = this . $lodash . cloneDeep ( obj )
this . oldData = this . $lodash . cloneDeep ( obj )
2023-01-05 17:53:42 +08:00
if ( this . stableTime ) {
clearTimeout ( this . stableTime )
this . stableTime = null
}
2021-11-30 16:39:21 +08:00
}
2021-12-06 11:40:06 +08:00
} ,
'editChart.type' : {
handler ( n ) {
if ( n === 'group' ) {
this . editChart . groupId = ''
2022-07-20 14:21:40 +08:00
} else {
this . editChart . param . enable . visibility = false
this . editChart . param . visibility . varName = ''
this . editChart . param . visibility . operator = ''
this . editChart . param . visibility . varValue = ''
this . editChart . param . visibility . result = ''
2021-12-06 11:40:06 +08:00
}
}
2022-03-29 15:21:28 +08:00
} ,
editChart : {
deep : true ,
handler ( ) {
}
2021-11-30 16:39:21 +08:00
}
}
}
< / script >