AccountList.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <template>
  2. <page-list
  3. :columns="columns"
  4. :group-actions="groupActions"
  5. :list="list"
  6. :single-actions="singleActions" />
  7. </template>
  8. <script>
  9. import { ACCOUNT_PRIVILEGES } from '../constants'
  10. import PasswordFetcher from '@Compute/sections/PasswordFetcher'
  11. import { getStatusTableColumn, getCopyWithContentTableColumn } from '@/utils/common/tableColumn'
  12. import WindowsMixin from '@/mixins/windows'
  13. import expectStatus from '@/constants/expectStatus'
  14. import { HYPERVISORS_MAP } from '@/constants'
  15. import { getNameFilter, getStatusFilter } from '@/utils/common/tableFilter'
  16. export default {
  17. name: 'RedisAccountList',
  18. mixins: [WindowsMixin],
  19. props: {
  20. params: {
  21. type: Object,
  22. },
  23. data: {
  24. type: Object,
  25. },
  26. },
  27. data () {
  28. const steadyStatus = Object.values(expectStatus.redisAccount).flat()
  29. return {
  30. steadyStatus,
  31. list: this.$list.createList(this, {
  32. id: 'RedisAccountListForRedisSidePage',
  33. resource: 'elasticcacheaccounts',
  34. getParams: this.params,
  35. steadyStatus,
  36. filterOptions: {
  37. name: getNameFilter(),
  38. status: getStatusFilter('redisAccount'),
  39. },
  40. }),
  41. columns: [
  42. getCopyWithContentTableColumn(),
  43. getStatusTableColumn({ statusModule: 'redisAccount' }),
  44. {
  45. field: 'password',
  46. title: this.$t('db.text_195'),
  47. width: 100,
  48. slots: {
  49. default: ({ row }) => {
  50. return [<PasswordFetcher serverId={row.id} resourceType='elasticcacheaccounts' />]
  51. },
  52. },
  53. },
  54. {
  55. field: 'account_type',
  56. title: this.$t('db.text_309'),
  57. minWidth: 100,
  58. slots: {
  59. default: ({ row }) => {
  60. return row.account_type === 'admin' ? this.$t('db.text_310') : this.$t('db.text_311')
  61. },
  62. },
  63. },
  64. {
  65. field: 'ip',
  66. title: this.$t('db.text_196'),
  67. minWidth: 150,
  68. slots: {
  69. default: ({ row }) => {
  70. return ACCOUNT_PRIVILEGES[row.account_privilege] || '-'
  71. },
  72. },
  73. },
  74. ],
  75. groupActions: [
  76. {
  77. label: this.$t('db.text_41'),
  78. permission: 'redis_elasticcacheaccounts_create',
  79. action: () => {
  80. this.createDialog('RedisAccountDialog', {
  81. list: this.list,
  82. redisItem: this.data,
  83. })
  84. },
  85. meta: () => {
  86. let validate = true
  87. let tooltip = ''
  88. if (this.data.brand === 'Huawei') {
  89. validate = false
  90. tooltip = this.$t('db.text_202')
  91. }
  92. if (this.data.brand === 'Aliyun' && this.data.engine_version === '2.8') {
  93. validate = false
  94. tooltip = this.$t('db.text_312')
  95. }
  96. if (this.data.brand === 'Qcloud' && this.data.slave_zones && this.data.slave_zones.length > 0) {
  97. validate = false
  98. tooltip = this.$t('db.redis.qcloud.multizone.tooltips')
  99. }
  100. if ((this.data.brand === HYPERVISORS_MAP.aws.brand || this.data.brand === HYPERVISORS_MAP.azure.brand) && validate) {
  101. validate = false
  102. tooltip = this.$t('db.text_384', [this.data.brand])
  103. }
  104. return {
  105. buttonType: 'primary',
  106. validate,
  107. tooltip,
  108. }
  109. },
  110. },
  111. ],
  112. singleActions: [
  113. {
  114. label: this.$t('db.text_201'),
  115. permission: 'redis_elasticcacheaccounts_perform_reset_password',
  116. action: (obj) => {
  117. this.createDialog('RedisAccountLisResetPwdDialog', {
  118. data: [obj],
  119. steadyStatus: this.steadyStatus,
  120. list: this.list,
  121. columns: this.columns,
  122. redisItem: this.data,
  123. })
  124. },
  125. meta: () => this.commonMeta,
  126. },
  127. {
  128. label: this.$t('db.text_203'),
  129. permission: 'redis_elasticcacheaccounts_perform_reset_password',
  130. action: (obj) => {
  131. this.createDialog('RedisAccountListSetPrivilegeDialog', {
  132. title: this.$t('db.text_203'),
  133. steadyStatus: this.steadyStatus,
  134. initialValues: {
  135. account_privilege: obj.account_privilege,
  136. },
  137. data: [obj],
  138. list: this.list,
  139. columns: this.columns,
  140. redisItem: this.data,
  141. })
  142. },
  143. meta: (obj) => {
  144. const isAdmin = obj.account_type === 'admin'
  145. const brandMap = {
  146. Aliyun: this.$t('db.text_52'),
  147. Qcloud: this.$t('db.text_361'),
  148. }
  149. return {
  150. validate: this.commonMeta.validate && !isAdmin,
  151. tooltip: this.commonMeta.tooltip || (isAdmin ? this.$t('db.text_313', [brandMap[obj.brand]]) : null),
  152. }
  153. },
  154. },
  155. {
  156. label: this.$t('db.text_42'),
  157. permission: 'redis_elasticcacheaccounts_delete',
  158. action: (obj) => {
  159. this.createDialog('RedisWhiteListDeleteDialog', {
  160. data: [obj],
  161. columns: this.columns,
  162. title: this.$t('db.text_206'),
  163. list: this.list,
  164. })
  165. },
  166. meta: (obj) => {
  167. const isHuawei = this.data.brand === 'Huawei'
  168. let tooltip = ''
  169. if (isHuawei) {
  170. tooltip = this.$t('db.text_202')
  171. }
  172. if (obj.account_type === 'admin') {
  173. tooltip = this.$t('db.text_315')
  174. }
  175. return {
  176. validate: !tooltip,
  177. tooltip,
  178. }
  179. },
  180. },
  181. ],
  182. }
  183. },
  184. computed: {
  185. commonMeta () {
  186. if (this.data.brand === 'Qcloud' && this.data.slave_zones && this.data.slave_zones.length > 0) {
  187. return {
  188. validate: false,
  189. tooltip: this.$t('db.redis.qcloud.multizone.tooltips'),
  190. }
  191. }
  192. const isHuawei = this.data.brand === 'Huawei'
  193. return {
  194. validate: !isHuawei,
  195. tooltip: isHuawei ? this.$t('db.text_202') : null,
  196. }
  197. },
  198. },
  199. created () {
  200. this.list.fetchData()
  201. },
  202. }
  203. </script>