index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <template>
  2. <div class="h-100 position-relative">
  3. <div class="dashboard-card-wrap">
  4. <div class="dashboard-card-header">
  5. <div class="dashboard-card-header-left">
  6. {{ form.fd.name }}
  7. <a-icon class="ml-2" type="loading" v-if="loading" />
  8. <span v-if="isUsageKeyDeny" class="ml-2">
  9. <a-tooltip class="mr-2"><template slot="title">{{ $t('dashboard.usage_key_deny_tips') }}</template><icon type="help" /></a-tooltip>
  10. <a-icon class="warning-color mr-1" type="warning" />
  11. {{ $t('dashboard.usage_key_deny_tips_2') }}
  12. </span>
  13. </div>
  14. <div class="dashboard-card-header-right">
  15. <slot name="actions" :handle-edit="handleEdit" />
  16. <router-link v-if="!edit" to="/monitoroverview" class="ml-2">
  17. <icon type="arrow-right" style="font-size:18px" />
  18. </router-link>
  19. </div>
  20. </div>
  21. <div class="dashboard-card-body flex-column justify-content-center">
  22. <template v-if="chartOptions.series[0].data.length">
  23. <div class="flex-fill position-relative">
  24. <div class="dashboard-fco-wrap">
  25. <e-chart :options="chartOptions" style="height: 100%; width: 100%;" autoresize />
  26. </div>
  27. </div>
  28. </template>
  29. <template v-else>
  30. <a-empty />
  31. </template>
  32. </div>
  33. </div>
  34. <base-drawer :visible.sync="visible" :title="$t('dashboard.text_5')" @ok="handleSubmit">
  35. <a-form
  36. hideRequiredMark
  37. :form="form.fc"
  38. v-bind="formItemLayout">
  39. <a-form-item :label="$t('dashboard.text_6')">
  40. <a-input v-decorator="decorators.name" />
  41. </a-form-item>
  42. </a-form>
  43. </base-drawer>
  44. </div>
  45. </template>
  46. <script>
  47. import * as R from 'ramda'
  48. import { mapGetters } from 'vuex'
  49. import { chartColors } from '@/constants'
  50. import BaseDrawer from '@Dashboard/components/BaseDrawer'
  51. import { resolveValueChangeField } from '@/utils/common/ant'
  52. export default {
  53. name: 'UnrecoveredAlarm',
  54. components: {
  55. BaseDrawer,
  56. },
  57. props: {
  58. options: {
  59. type: Object,
  60. required: true,
  61. },
  62. params: Object,
  63. edit: Boolean,
  64. dataRangeParams: {
  65. type: Object,
  66. },
  67. },
  68. data () {
  69. const initialNameValue = (this.params && this.params.name) || this.$t('monitor.overview_alert_sum')
  70. return {
  71. data: [],
  72. visible: false,
  73. loading: false,
  74. seriesData: [],
  75. form: {
  76. fc: this.$form.createForm(this, {
  77. onValuesChange: (props, values) => {
  78. const newField = resolveValueChangeField(values)
  79. R.forEachObjIndexed((item, key) => {
  80. this.$set(this.form.fd, key, item)
  81. }, newField)
  82. },
  83. }),
  84. fd: {
  85. name: initialNameValue,
  86. },
  87. },
  88. decorators: {
  89. name: [
  90. 'name',
  91. {
  92. initialValue: initialNameValue,
  93. rules: [
  94. { required: true, message: this.$t('dashboard.text_8') },
  95. ],
  96. },
  97. ],
  98. },
  99. formItemLayout: {
  100. wrapperCol: {
  101. span: 18,
  102. },
  103. labelCol: {
  104. span: 6,
  105. },
  106. },
  107. chartOptions: {
  108. title: [
  109. {
  110. text: this.$t('monitor.overview_alert_sum'),
  111. subtext: '',
  112. textStyle: {
  113. fontSize: 12,
  114. color: '#ccc',
  115. },
  116. subtextStyle: {
  117. fontSize: 18,
  118. color: 'rgb(100, 100, 100)',
  119. },
  120. top: '30%',
  121. left: 'center',
  122. },
  123. ],
  124. tooltip: {
  125. trigger: 'item',
  126. },
  127. legend: {
  128. bottom: '3%',
  129. left: 'center',
  130. },
  131. color: chartColors,
  132. series: [
  133. {
  134. type: 'pie',
  135. radius: ['50%', '65%'],
  136. center: ['50%', '40%'],
  137. // hoverAnimation: false,
  138. label: {
  139. normal: {
  140. show: false,
  141. },
  142. },
  143. labelLine: {
  144. normal: {
  145. show: false,
  146. },
  147. },
  148. data: [],
  149. },
  150. ],
  151. },
  152. }
  153. },
  154. computed: {
  155. ...mapGetters(['scope', 'capability', 'isAdminMode', 'isDomainMode', 'isProjectMode', 'userInfo']),
  156. isUsageKeyDeny () {
  157. if (this.isAdminMode && (this.dataRangeParams?.scope === 'domain' || this.dataRangeParams?.scope === 'project')) {
  158. return true
  159. }
  160. if (this.isDomainMode && this.dataRangeParams?.scope === 'project') {
  161. return true
  162. }
  163. return false
  164. },
  165. },
  166. watch: {
  167. 'form.fd' (val) {
  168. const newVal = { ...val }
  169. for (const key in newVal) {
  170. this.decorators[key][1].initialValue = newVal[key]
  171. }
  172. this.form.fc.setFieldsValue(newVal)
  173. this.$nextTick(() => {
  174. this.fetchData()
  175. })
  176. },
  177. 'dataRangeParams.scope': {
  178. handler (val) {
  179. this.fetchData()
  180. },
  181. immediate: true,
  182. },
  183. 'dataRangeParams.domain': {
  184. handler (val) {
  185. this.fetchData()
  186. },
  187. immediate: true,
  188. },
  189. 'dataRangeParams.project': {
  190. handler (val) {
  191. this.fetchData()
  192. },
  193. immediate: true,
  194. },
  195. },
  196. created () {
  197. const values = { ...this.form.fd }
  198. values.brand = R.join(',', values.brand || [])
  199. this.$emit('update', this.options.i, values)
  200. this.fetchData()
  201. },
  202. methods: {
  203. commonParams () {
  204. const extendParams = {
  205. scope: this.curNav.scope,
  206. }
  207. Object.assign(extendParams, this.extraParams)
  208. return extendParams
  209. },
  210. refresh () {
  211. return this.fetchData()
  212. },
  213. async fetchData () {
  214. this.loading = true
  215. try {
  216. const params = {
  217. scope: this.$store.getters.scope,
  218. }
  219. if (this.isAdminMode) {
  220. if (this.dataRangeParams?.scope === 'domain' && this.dataRangeParams?.domain) {
  221. params.scope = 'domain'
  222. params.domain_id = this.dataRangeParams?.domain
  223. }
  224. if (this.dataRangeParams?.scope === 'project' && this.dataRangeParams?.project) {
  225. params.scope = 'project'
  226. params.project_id = this.dataRangeParams?.project
  227. }
  228. }
  229. if (this.isDomainMode) {
  230. if (this.dataRangeParams?.scope === 'project' && this.dataRangeParams?.project) {
  231. params.scope = 'project'
  232. params.project_id = this.dataRangeParams?.project
  233. }
  234. }
  235. const { data: series = { } } = await new this.$Manager('alertrecords', 'v1').get({ id: 'total-alert', params: params })
  236. let total = 0
  237. const chartData = []
  238. if (Object.keys(series).length > 0) {
  239. for (const item in series) {
  240. total += series[item]
  241. chartData.push({ name: this.$t(`dictionary.${item}`), value: series[item] })
  242. }
  243. } else {
  244. chartData.push({ name: '', value: 0 })
  245. }
  246. this.chartOptions.series[0].data = chartData
  247. this.chartOptions.title[0].subtext = total
  248. } finally {
  249. this.loading = false
  250. }
  251. },
  252. handleEdit () {
  253. this.visible = true
  254. },
  255. async handleSubmit () {
  256. try {
  257. const values = await this.form.fc.validateFields()
  258. this.form.fd = values
  259. const updateValues = { ...values }
  260. this.$emit('update', this.options.i, updateValues)
  261. this.visible = false
  262. } catch (error) {
  263. throw error
  264. }
  265. },
  266. },
  267. }
  268. </script>