columns.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. import i18n from '@/locales'
  2. import { getTagColor, getTagTitle } from '@/utils/common/tag'
  3. import Actions from '@/components/PageList/Actions'
  4. const getRuleCondition = (data) => {
  5. const { condition } = data
  6. if (condition === 'or') {
  7. return i18n.t('cloudenv.text_587')
  8. } else if (data.hasOwnProperty('project_id')) {
  9. return i18n.t('cloudenv.text_588')
  10. } else {
  11. return i18n.t('cloudenv.match_by_tag_key')
  12. }
  13. }
  14. const getResourceRuleTableColumn = ({
  15. field = 'name',
  16. title = i18n.t('cloudenv.text_582'),
  17. } = {}) => {
  18. return {
  19. field,
  20. title,
  21. slots: {
  22. default: ({ row }, h) => {
  23. const tags = row.tags.map(item => {
  24. const rgb = getTagColor(item.key, item.value, 'rgb')
  25. const strRgb = rgb.join(',')
  26. return (<span
  27. class="tag mb-1 text-truncate d-inline-block"
  28. title={getTagTitle(item.key, item.value)}
  29. key={`${item.key}${item.value}`}
  30. style={{ backgroundColor: `rgba(${strRgb},.1)`, boxSizing: 'border-box', color: `rgb(${strRgb})`, border: `solid 1px rgb(${strRgb})`, padding: '0 5px', marginRight: '10px' }}>
  31. { getTagTitle('user:' + item.key, item.value) }
  32. </span>)
  33. })
  34. return [<div>{ getRuleCondition(row) }</div>, <div>{ ...tags }</div>]
  35. },
  36. header: ({ column }, h) => {
  37. return [<span>{title}</span>]
  38. },
  39. },
  40. }
  41. }
  42. export default {
  43. data () {
  44. return {
  45. checkColumn: {
  46. type: 'checkbox',
  47. width: 40,
  48. showHeaderOverflow: false,
  49. resizable: false,
  50. },
  51. normalColmns: [
  52. getResourceRuleTableColumn(),
  53. {
  54. title: i18n.t('cloudenv.text_584'),
  55. field: 'accounts',
  56. slots: {
  57. default: ({ row }, h) => {
  58. if (row.condition === 'and' && !row.hasOwnProperty('project_id') && !row.hasOwnProperty('project')) {
  59. return i18n.t('cloudenv.project_same_as_tag_value')
  60. }
  61. let project = row.project
  62. if (project) {
  63. if (row.project_id) {
  64. project += ` (${this.$t('cloudenv.target_project')})`
  65. } else {
  66. project += ` (${this.$t('cloudenv.target_name')})`
  67. }
  68. }
  69. return [
  70. <span class="text-color-secondary">{ project || '-'}</span>]
  71. },
  72. },
  73. },
  74. {
  75. field: '_action',
  76. title: this.$t('table.title._action'),
  77. minWidth: 120,
  78. resizable: false,
  79. slots: {
  80. default: ({ row }, h) => {
  81. return [
  82. this.$createElement(Actions, {
  83. props: {
  84. options: this.singleActions,
  85. row,
  86. buttonType: 'link',
  87. buttonSize: 'small',
  88. buttonStyle: {
  89. fontSize: '14px',
  90. },
  91. },
  92. }),
  93. ]
  94. },
  95. header: ({ column }, h) => {
  96. return [
  97. this.$createElement('span', {
  98. style: {
  99. paddingLeft: '7px',
  100. },
  101. }, this.$t('table.title._action')),
  102. ]
  103. },
  104. },
  105. },
  106. ],
  107. dragColumn: {
  108. width: 1,
  109. slots: {
  110. default: () => {
  111. return [
  112. <span v-show={this.canSort} class="drag-btn">
  113. <i class="vxe-icon--menu"></i>
  114. </span>,
  115. ]
  116. },
  117. header: () => {
  118. return [
  119. <vxe-tooltip v-show={this.canSort} v-model={this.showHelpTip2} content={i18n.t('cloudenv.text_591')} enterable>
  120. <i class="vxe-icon--question" onClick={ () => { this.showHelpTip2 = !this.showHelpTip2 } }></i>
  121. </vxe-tooltip>,
  122. ]
  123. },
  124. },
  125. },
  126. }
  127. },
  128. created () {
  129. this.singleActions = [
  130. {
  131. label: i18n.t('cloudenv.text_593'),
  132. permission: 'projectmappings_update',
  133. action: (row) => {
  134. this.createDialog('ProjectMappingRuleEditDialog', {
  135. id: this.data.id,
  136. rules: this.data.rules || [],
  137. editType: 'edit',
  138. data: [row],
  139. columns: this.columns,
  140. title: i18n.t('cloudenv.text_598'),
  141. success: (res) => {
  142. this.$bus.$emit('ProjectMappingRuleUpdate', res)
  143. },
  144. })
  145. },
  146. meta: () => {
  147. const ret = {
  148. validate: true,
  149. }
  150. if (!(this.isAdminMode || this.data.domain_id === this.userInfo.projectDomainId)) {
  151. ret.validate = false
  152. ret.tooltip = this.$t('cloudenv.text_597')
  153. }
  154. return ret
  155. },
  156. },
  157. {
  158. label: i18n.t('cloudenv.text_108'),
  159. permission: 'projectmappings_delete',
  160. action: (row) => {
  161. this.createDialog('DeleteResDialog', {
  162. name: this.$t('cloudenv.text_582'),
  163. vm: this,
  164. data: [row],
  165. columns: [this.normalColmns[0], this.normalColmns[1]],
  166. title: this.$t('table.action.delete'),
  167. ok: () => {
  168. this.checkedRecords = [row]
  169. this.deleteProjectMappingRules()
  170. },
  171. })
  172. },
  173. meta: (row) => {
  174. const ret = {
  175. validate: true,
  176. }
  177. if (!(this.isAdminMode || this.data.domain_id === this.userInfo.projectDomainId)) {
  178. ret.validate = false
  179. ret.tooltip = this.$t('cloudenv.text_597')
  180. }
  181. if (this.data && this.data.rules.length <= 1) {
  182. ret.validate = false
  183. }
  184. return ret
  185. },
  186. },
  187. ]
  188. },
  189. computed: {
  190. columns: function () {
  191. if (this.canSort) {
  192. this.dragColumn.width = 60
  193. } else {
  194. this.dragColumn.width = 1
  195. }
  196. return [this.checkColumn, this.dragColumn, ...this.normalColmns]
  197. },
  198. },
  199. methods: {
  200. getRuleCondition (data) {
  201. const { condition } = data
  202. if (condition === 'or') {
  203. return i18n.t('cloudenv.text_587')
  204. } else if (data.hasOwnProperty('project_id')) {
  205. return i18n.t('cloudenv.text_588')
  206. } else {
  207. return i18n.t('cloudenv.match_by_tag_key')
  208. }
  209. },
  210. },
  211. }