| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- <template>
- <div class="h-100 position-relative">
- <div class="dashboard-card-wrap">
- <div class="dashboard-card-header">
- <div class="dashboard-card-header-left">
- {{ form.fd.name }}
- <a-icon class="ml-2" type="loading" v-if="loading" />
- <span v-if="isUsageKeyDeny" class="ml-2">
- <a-tooltip class="mr-2"><template slot="title">{{ $t('dashboard.usage_key_deny_tips') }}</template><icon type="help" /></a-tooltip>
- <a-icon class="warning-color mr-1" type="warning" />
- {{ $t('dashboard.usage_key_deny_tips_2') }}
- </span>
- </div>
- <div class="dashboard-card-header-right">
- <slot name="actions" :handle-edit="handleEdit" />
- <router-link v-if="!edit" to="/monitoroverview" class="ml-2">
- <icon type="arrow-right" style="font-size:18px" />
- </router-link>
- </div>
- </div>
- <div class="dashboard-card-body flex-column justify-content-center">
- <template v-if="chartOptions.series[0].data.length">
- <div class="flex-fill position-relative">
- <div class="dashboard-fco-wrap">
- <e-chart :options="chartOptions" style="height: 100%; width: 100%;" autoresize />
- </div>
- </div>
- </template>
- <template v-else>
- <a-empty />
- </template>
- </div>
- </div>
- <base-drawer :visible.sync="visible" :title="$t('dashboard.text_5')" @ok="handleSubmit">
- <a-form
- hideRequiredMark
- :form="form.fc"
- v-bind="formItemLayout">
- <a-form-item :label="$t('dashboard.text_6')">
- <a-input v-decorator="decorators.name" />
- </a-form-item>
- </a-form>
- </base-drawer>
- </div>
- </template>
- <script>
- import * as R from 'ramda'
- import { mapGetters } from 'vuex'
- import { chartColors } from '@/constants'
- import BaseDrawer from '@Dashboard/components/BaseDrawer'
- import { resolveValueChangeField } from '@/utils/common/ant'
- export default {
- name: 'UnrecoveredAlarm',
- components: {
- BaseDrawer,
- },
- props: {
- options: {
- type: Object,
- required: true,
- },
- params: Object,
- edit: Boolean,
- dataRangeParams: {
- type: Object,
- },
- },
- data () {
- const initialNameValue = (this.params && this.params.name) || this.$t('monitor.overview_alert_sum')
- return {
- data: [],
- visible: false,
- loading: false,
- seriesData: [],
- form: {
- fc: this.$form.createForm(this, {
- onValuesChange: (props, values) => {
- const newField = resolveValueChangeField(values)
- R.forEachObjIndexed((item, key) => {
- this.$set(this.form.fd, key, item)
- }, newField)
- },
- }),
- fd: {
- name: initialNameValue,
- },
- },
- decorators: {
- name: [
- 'name',
- {
- initialValue: initialNameValue,
- rules: [
- { required: true, message: this.$t('dashboard.text_8') },
- ],
- },
- ],
- },
- formItemLayout: {
- wrapperCol: {
- span: 18,
- },
- labelCol: {
- span: 6,
- },
- },
- chartOptions: {
- title: [
- {
- text: this.$t('monitor.overview_alert_sum'),
- subtext: '',
- textStyle: {
- fontSize: 12,
- color: '#ccc',
- },
- subtextStyle: {
- fontSize: 18,
- color: 'rgb(100, 100, 100)',
- },
- top: '30%',
- left: 'center',
- },
- ],
- tooltip: {
- trigger: 'item',
- },
- legend: {
- bottom: '3%',
- left: 'center',
- },
- color: chartColors,
- series: [
- {
- type: 'pie',
- radius: ['50%', '65%'],
- center: ['50%', '40%'],
- // hoverAnimation: false,
- label: {
- normal: {
- show: false,
- },
- },
- labelLine: {
- normal: {
- show: false,
- },
- },
- data: [],
- },
- ],
- },
- }
- },
- computed: {
- ...mapGetters(['scope', 'capability', 'isAdminMode', 'isDomainMode', 'isProjectMode', 'userInfo']),
- isUsageKeyDeny () {
- if (this.isAdminMode && (this.dataRangeParams?.scope === 'domain' || this.dataRangeParams?.scope === 'project')) {
- return true
- }
- if (this.isDomainMode && this.dataRangeParams?.scope === 'project') {
- return true
- }
- return false
- },
- },
- watch: {
- 'form.fd' (val) {
- const newVal = { ...val }
- for (const key in newVal) {
- this.decorators[key][1].initialValue = newVal[key]
- }
- this.form.fc.setFieldsValue(newVal)
- this.$nextTick(() => {
- this.fetchData()
- })
- },
- 'dataRangeParams.scope': {
- handler (val) {
- this.fetchData()
- },
- immediate: true,
- },
- 'dataRangeParams.domain': {
- handler (val) {
- this.fetchData()
- },
- immediate: true,
- },
- 'dataRangeParams.project': {
- handler (val) {
- this.fetchData()
- },
- immediate: true,
- },
- },
- created () {
- const values = { ...this.form.fd }
- values.brand = R.join(',', values.brand || [])
- this.$emit('update', this.options.i, values)
- this.fetchData()
- },
- methods: {
- commonParams () {
- const extendParams = {
- scope: this.curNav.scope,
- }
- Object.assign(extendParams, this.extraParams)
- return extendParams
- },
- refresh () {
- return this.fetchData()
- },
- async fetchData () {
- this.loading = true
- try {
- const params = {
- scope: this.$store.getters.scope,
- }
- if (this.isAdminMode) {
- if (this.dataRangeParams?.scope === 'domain' && this.dataRangeParams?.domain) {
- params.scope = 'domain'
- params.domain_id = this.dataRangeParams?.domain
- }
- if (this.dataRangeParams?.scope === 'project' && this.dataRangeParams?.project) {
- params.scope = 'project'
- params.project_id = this.dataRangeParams?.project
- }
- }
- if (this.isDomainMode) {
- if (this.dataRangeParams?.scope === 'project' && this.dataRangeParams?.project) {
- params.scope = 'project'
- params.project_id = this.dataRangeParams?.project
- }
- }
- const { data: series = { } } = await new this.$Manager('alertrecords', 'v1').get({ id: 'total-alert', params: params })
- let total = 0
- const chartData = []
- if (Object.keys(series).length > 0) {
- for (const item in series) {
- total += series[item]
- chartData.push({ name: this.$t(`dictionary.${item}`), value: series[item] })
- }
- } else {
- chartData.push({ name: '', value: 0 })
- }
- this.chartOptions.series[0].data = chartData
- this.chartOptions.title[0].subtext = total
- } finally {
- this.loading = false
- }
- },
- handleEdit () {
- this.visible = true
- },
- async handleSubmit () {
- try {
- const values = await this.form.fc.validateFields()
- this.form.fd = values
- const updateValues = { ...values }
- this.$emit('update', this.options.i, updateValues)
- this.visible = false
- } catch (error) {
- throw error
- }
- },
- },
- }
- </script>
|