RuleList.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <template>
  2. <page-list
  3. :list="list"
  4. :columns="columns"
  5. :group-actions="groupActions"
  6. :single-actions="singleActions"
  7. :showSearchbox="showSearchbox"
  8. :showGroupActions="showGroupActions" />
  9. </template>
  10. <script>
  11. import numerify from 'numerify'
  12. import { getNameDescriptionTableColumn, getTimeTableColumn, getStatusTableColumn, getEnabledTableColumn } from '@/utils/common/tableColumn'
  13. import { getEnabledSwitchActions } from '@/utils/common/tableActions'
  14. import { getStatusFilter, getEnabledFilter } from '@/utils/common/tableFilter'
  15. import expectStatus from '@/constants/expectStatus'
  16. import WindowsMixin from '@/mixins/windows'
  17. import GlobalSearchMixin from '@/mixins/globalSearch'
  18. import ListMixin from '@/mixins/list'
  19. export default {
  20. name: 'ScalingGroupRuleListSidePage',
  21. mixins: [WindowsMixin, ListMixin, GlobalSearchMixin],
  22. props: {
  23. id: String,
  24. getParams: {
  25. type: [Function, Object],
  26. },
  27. data: {
  28. type: Object,
  29. },
  30. },
  31. data () {
  32. return {
  33. list: this.$list.createList(this, {
  34. id: 'RuleListForScalingGroupSidePage',
  35. resource: 'scalingpolicies',
  36. apiVersion: 'v1',
  37. getParams: this.getParams,
  38. steadyStatus: Object.values(expectStatus.scalingpolicie).flat(),
  39. filterOptions: {
  40. name: {
  41. label: this.$t('compute.text_228'),
  42. filter: true,
  43. formatter: val => {
  44. return `name.contains("${val}")`
  45. },
  46. },
  47. status: getStatusFilter('scalingpolicie'),
  48. enabled: getEnabledFilter(),
  49. trigger_type: {
  50. label: this.$t('compute.text_913'),
  51. dropdown: true,
  52. items: Object.keys(this.$t('flexGrouTriggerType')).map(k => {
  53. return {
  54. label: this.$t('flexGrouTriggerType')[k],
  55. key: k,
  56. }
  57. }),
  58. },
  59. },
  60. }),
  61. columns: [
  62. getNameDescriptionTableColumn({
  63. onManager: this.onManager,
  64. // hideField: true,
  65. // slotCallback: row => {
  66. // return (
  67. // <side-page-trigger name='FiexGroupSidePage' id={row.id} list={this.list} vm={this}>{ row.name }</side-page-trigger>
  68. // )
  69. // },
  70. }),
  71. getEnabledTableColumn(),
  72. getStatusTableColumn({ statusModule: 'scalingpolicie' }),
  73. {
  74. field: 'trigger_type',
  75. title: this.$t('compute.text_913'),
  76. width: 120,
  77. formatter: ({ cellValue }) => {
  78. return this.$t('flexGrouTriggerType')[cellValue]
  79. },
  80. },
  81. {
  82. field: 'cycle',
  83. title: this.$t('compute.text_914'),
  84. width: 300,
  85. formatter: ({ row }) => {
  86. return this.formatTriggerType(row)
  87. },
  88. },
  89. {
  90. field: 'action',
  91. title: this.$t('compute.text_929'),
  92. width: 100,
  93. formatter: ({ row }) => {
  94. const acn = this.$t('flexGroupRuleAction')[row.action]
  95. return this.$t('compute.text_961', [acn, row.number])
  96. },
  97. },
  98. {
  99. field: 'cooling_time',
  100. title: this.$t('compute.text_962'),
  101. width: 100,
  102. formatter: ({ row }) => {
  103. return this.$t('compute.text_963', [row.cooling_time])
  104. },
  105. },
  106. // {
  107. // field: 'startTimeAndendTime',
  108. // title: '有效时间',
  109. // width: 160,
  110. // slots: {
  111. // default: ({ row }) => {
  112. // const { start_time: startTime, end_time: endTime } = row.cycle_timer
  113. // if (startTime && endTime) {
  114. // return [
  115. // <div>
  116. // {this.$moment(startTime).format()} <br/>
  117. // {this.$moment(endTime).format()}
  118. // </div>,
  119. // ]
  120. // }
  121. // },
  122. // },
  123. // },
  124. getTimeTableColumn(),
  125. ],
  126. singleActions: [
  127. {
  128. label: this.$t('compute.text_249'),
  129. action: obj => {
  130. this.createDialog('FlexRuleStartDialog', {
  131. data: [obj],
  132. columns: this.columns,
  133. title: this.$t('compute.text_249'),
  134. onManager: this.onManager,
  135. refresh: this.refresh,
  136. })
  137. },
  138. meta: (obj) => {
  139. let tooltip = ''
  140. if (!this.data.enabled) {
  141. tooltip = this.$t('compute.text_964')
  142. }
  143. if (!obj.enabled) {
  144. tooltip = this.$t('compute.text_965')
  145. }
  146. if (obj.status !== 'ready') {
  147. tooltip = this.$t('compute.text_966')
  148. }
  149. return {
  150. validate: !tooltip,
  151. tooltip,
  152. }
  153. },
  154. },
  155. {
  156. label: this.$t('compute.text_352'),
  157. actions: obj => {
  158. return [
  159. ...getEnabledSwitchActions(this, obj, ['scalingpolicies_perform_enable', 'scalingpolicies_perform_disable']),
  160. {
  161. label: this.$t('compute.perform_delete'),
  162. permission: 'scalingpolicies_delete',
  163. action: (obj) => {
  164. this.createDialog('DeleteResDialog', {
  165. data: [obj],
  166. columns: this.columns,
  167. title: this.$t('compute.perform_delete'),
  168. onManager: this.onManager,
  169. refresh: this.refresh,
  170. })
  171. },
  172. meta: (obj) => {
  173. return {
  174. validate: !obj.enabled,
  175. tooltip: obj.enabled && this.$t('compute.text_967'),
  176. }
  177. },
  178. },
  179. ]
  180. },
  181. },
  182. ],
  183. groupActions: [
  184. {
  185. label: this.$t('compute.perform_create'),
  186. permission: 'scalingpolicies_create',
  187. action: () => {
  188. this.createDialog('FiexRuleListCreateDialog', {
  189. title: this.$t('compute.perform_create'),
  190. resData: this.data,
  191. refresh: this.refresh,
  192. onManager: this.onManager,
  193. })
  194. },
  195. meta: () => ({
  196. buttonType: 'primary',
  197. }),
  198. },
  199. {
  200. label: this.$t('common.batchAction'),
  201. actions: () => {
  202. return [
  203. {
  204. label: this.$t('compute.text_656'),
  205. permission: 'scalingpolicies_perform_enable',
  206. action: () => {
  207. this.list.batchPerformAction('enable', null)
  208. },
  209. meta: () => ({
  210. validate: this.list.selectedItems.length,
  211. }),
  212. },
  213. {
  214. label: this.$t('compute.text_569'),
  215. permission: 'scalingpolicies_perform_disable',
  216. action: () => {
  217. this.list.batchPerformAction('disable', null)
  218. },
  219. meta: () => ({
  220. validate: this.list.selectedItems.length,
  221. }),
  222. },
  223. {
  224. label: this.$t('compute.perform_delete'),
  225. permission: 'scalingpolicies_delete',
  226. action: () => {
  227. this.createDialog('DeleteResDialog', {
  228. data: this.list.selectedItems,
  229. columns: this.columns,
  230. title: this.$t('compute.perform_delete'),
  231. onManager: this.onManager,
  232. })
  233. },
  234. meta: (obj) => {
  235. return {
  236. validate: this.list.selectedItems.length && this.list.selectedItems.every(val => !val.enabled),
  237. }
  238. },
  239. },
  240. ]
  241. },
  242. meta: () => ({
  243. validate: this.list.selectedItems.length,
  244. }),
  245. },
  246. ],
  247. }
  248. },
  249. created () {
  250. this.list.fetchData()
  251. },
  252. methods: {
  253. formatTriggerType (row) {
  254. const type = row.trigger_type
  255. const initStatus = ['creating', 'create_failed', 'init']
  256. if (initStatus.indexOf(row.status) > -1) {
  257. return '-'
  258. }
  259. // 告警策略
  260. if (type === 'alarm' && row.alarm) {
  261. const { indicator, operator, value, cumulate } = row.alarm
  262. const wrapperType = {
  263. lt: '<',
  264. gt: '>',
  265. }
  266. const unit = indicator === 'cpu' ? '%' : 'b/s'
  267. const cumulateTxt = this.$t('compute.text_968', [cumulate])
  268. return `${this.$t('flexGroupIndicator')[indicator]} ${wrapperType[operator]} ${value} ${unit},${cumulateTxt}`
  269. }
  270. // 定时策略
  271. if (type === 'timing' && row.timer) {
  272. const timeTxt = this.$moment(row.timer.exec_time).format()
  273. return this.$t('compute.text_969', [timeTxt])
  274. }
  275. // 周期策略
  276. if (type === 'cycle' && row.cycle_timer) {
  277. const timer = row.cycle_timer
  278. const { hour, minute, start_time: startTime, end_time: endTime } = timer
  279. const now = this.$moment()
  280. const utcOffset = now.utcOffset() * -1
  281. const trueHour = now.set({ hour }).subtract(utcOffset, 'minutes').hour()
  282. const typeTxt = this.$t('flexGroupCycleType')[timer.cycle_type]
  283. let itemsTxt = ''
  284. // 周
  285. if (timer.cycle_type === 'week' && timer.week_days.length > 0) {
  286. itemsTxt = '【' + timer.week_days.map(v => {
  287. return this.$t('flexGroupSubCycleTypeWeek')[v]
  288. }).join('|') + '】'
  289. }
  290. // 月
  291. if (timer.cycle_type === 'month') {
  292. itemsTxt = '【' + timer.month_days.map(v => {
  293. return this.$t('compute.text_927', [v])
  294. }).join('|') + '】'
  295. }
  296. let tiemStr = ''
  297. if (startTime && endTime) {
  298. tiemStr = this.$t('compute.text_970', [this.$moment(startTime).format('YYYY-MM-DD'), this.$moment(endTime).format('YYYY-MM-DD')])
  299. }
  300. return this.$t('compute.text_972', [typeTxt, itemsTxt, numerify(trueHour, '00'), numerify(minute, '00'), tiemStr])
  301. }
  302. return '-'
  303. },
  304. },
  305. }
  306. </script>