List.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <page-list
  3. :list="list"
  4. :columns="templateListColumns || columns"
  5. :group-actions="groupActions"
  6. :single-actions="singleActions"
  7. :showSearchbox="showSearchbox"
  8. :show-group-actions="showGroupActions"
  9. :show-single-actions="isTemplate ? false : showSingleActions"
  10. :export-data-options="exportDataOptions"
  11. :show-page="!isTemplate" />
  12. </template>
  13. <script>
  14. import expectStatus from '@/constants/expectStatus'
  15. import { getNameFilter, getTenantFilter, getStatusFilter, getBrandFilter, getDomainFilter, getOsArchFilter, getRegionFilter, getDescriptionFilter, getCreatedAtFilter } from '@/utils/common/tableFilter'
  16. import WindowsMixin from '@/mixins/windows'
  17. import ListMixin from '@/mixins/list'
  18. import ResTemplateListMixin from '@/mixins/resTemplateList'
  19. import GlobalSearchMixin from '@/mixins/globalSearch'
  20. import SingleActionsMixin from '../mixins/singleActions'
  21. import ColumnsMixin from '../mixins/columns'
  22. export default {
  23. name: 'ServertemplateList',
  24. mixins: [WindowsMixin, ListMixin, GlobalSearchMixin, ColumnsMixin, SingleActionsMixin, ResTemplateListMixin],
  25. props: {
  26. id: String,
  27. getParams: {
  28. type: Object,
  29. default: () => ({}),
  30. },
  31. cloudEnv: String,
  32. showGroupActions: {
  33. type: Boolean,
  34. default: () => (true),
  35. },
  36. showSingleActions: {
  37. type: Boolean,
  38. default: () => (true),
  39. },
  40. cloudEnvOptions: {
  41. type: Array,
  42. },
  43. },
  44. data () {
  45. return {
  46. list: this.$list.createList(this, {
  47. id: this.id,
  48. resource: 'servertemplates',
  49. ctx: this,
  50. getParams: this.getParam,
  51. isTemplate: this.isTemplate,
  52. templateLimit: this.templateLimit,
  53. steadyStatus: Object.values(expectStatus.servertemplate).flat(),
  54. filterOptions: {
  55. id: {
  56. label: this.$t('table.title.id'),
  57. },
  58. name: getNameFilter(),
  59. description: getDescriptionFilter(),
  60. projects: getTenantFilter(),
  61. project_domains: getDomainFilter(),
  62. status: getStatusFilter('servertemplate'),
  63. brand: getBrandFilter(),
  64. os_type: {
  65. label: this.$t('table.title.os'),
  66. dropdown: true,
  67. multiple: true,
  68. items: [
  69. { label: 'Windows', key: 'windows' },
  70. { label: 'Linux', key: 'linux' },
  71. { label: 'VMware', key: 'VMWare' },
  72. ],
  73. filter: true,
  74. formatter: val => {
  75. return `os_type.in(${val})`
  76. },
  77. },
  78. vpc: {
  79. label: 'VPC',
  80. },
  81. region: getRegionFilter(),
  82. billing_type: {
  83. label: this.$t('table.title.bill_type'),
  84. dropdown: true,
  85. items: Object.keys(this.$t('billingType')).map((k) => {
  86. return {
  87. label: this.$t('billingType')[k],
  88. key: k,
  89. }
  90. }),
  91. },
  92. os_arch: getOsArchFilter(),
  93. created_at: getCreatedAtFilter(),
  94. },
  95. hiddenColumns: ['os_type', 'os_arch', 'created_at'],
  96. responseData: this.responseData,
  97. }),
  98. groupActions: [
  99. {
  100. label: this.$t('compute.perform_create'),
  101. permission: 'servertemplates_create',
  102. action: () => {
  103. this.$router.push({
  104. path: '/servertemplate/create',
  105. query: {
  106. type: this.cloudEnv === 'onpremise' ? 'idc' : this.cloudEnv || this._cloudEnv,
  107. source: 'servertemplate',
  108. },
  109. })
  110. },
  111. meta: () => {
  112. return {
  113. buttonType: 'primary',
  114. validate: !!this._cloudEnv,
  115. }
  116. },
  117. },
  118. {
  119. label: this.$t('compute.perform_delete'),
  120. permission: 'servertemplates_delete',
  121. action: () => {
  122. this.createDialog('DeleteResDialog', {
  123. vm: this,
  124. data: this.list.selectedItems,
  125. columns: this.columns,
  126. title: this.$t('compute.perform_delete'),
  127. name: this.$t('dictionary.servertemplate'),
  128. onManager: this.onManager,
  129. })
  130. },
  131. meta: () => this.$getDeleteResult(this.list.selectedItems),
  132. },
  133. ],
  134. }
  135. },
  136. computed: {
  137. _cloudEnv () {
  138. if (this.cloudEnvOptions && this.cloudEnvOptions.length > 0) {
  139. const idc = this.cloudEnvOptions.find(item => item.key === 'idc')
  140. if (idc && idc.key) {
  141. return idc.key
  142. }
  143. const item = this.cloudEnvOptions.find(item => item.key) || {}
  144. return item.key
  145. }
  146. return ''
  147. },
  148. exportDataOptions () {
  149. return {
  150. downloadType: 'local',
  151. title: this.$t('compute.text_873'),
  152. items: [
  153. { field: 'id', title: 'ID' },
  154. ...this.columns,
  155. ],
  156. }
  157. },
  158. },
  159. watch: {
  160. cloudEnv (val) {
  161. this.$nextTick(() => {
  162. this.list.fetchData(0)
  163. })
  164. },
  165. },
  166. created () {
  167. this.list.fetchData()
  168. this.initSidePageTab('servertemplate-detail')
  169. },
  170. methods: {
  171. getParam () {
  172. const ret = {
  173. details: true,
  174. ...this.getParams,
  175. }
  176. if (this.cloudEnv) ret.cloud_env = this.cloudEnv
  177. return ret
  178. },
  179. handleOpenSidepage (row, tab) {
  180. this.sidePageTriggerHandle(this, 'ServertemplateSidePage', {
  181. id: row.id,
  182. resource: 'servertemplates',
  183. getParams: this.getParam,
  184. }, {
  185. list: this.list,
  186. tab,
  187. })
  188. },
  189. },
  190. }
  191. </script>