index.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <template>
  2. <a-form-item :required="isRequired" class="no-line-height" :label="$t('cloudenv.text_22')" v-bind="formItemLayout">
  3. <a-input-group compact>
  4. <a-select v-decorator="decorators.conditionKey">
  5. <a-select-option value="projects">{{ $t('dictionary.project') }}</a-select-option>
  6. </a-select>
  7. <a-form-item class="mb-0 custom-form-item">
  8. <base-select
  9. style="width: 300px;"
  10. v-decorator="decorators.conditionVals"
  11. resource="projects"
  12. version="v1"
  13. @change="conditionValsChange"
  14. :params="projectParams"
  15. remote
  16. :remote-fn="q => ({ filter: `name.contains(${q})` })"
  17. :select-props="{ placeholder: $t('rules.project'), mode: 'multiple' }" />
  18. </a-form-item>
  19. </a-input-group>
  20. </a-form-item>
  21. </template>
  22. <script>
  23. export default {
  24. name: 'ConditionSelect',
  25. props: {
  26. decorators: {
  27. type: Object,
  28. required: true,
  29. validator: val => val.conditionKey && val.conditionVals,
  30. },
  31. formItemLayout: {
  32. type: Object,
  33. required: true,
  34. },
  35. },
  36. data () {
  37. return {
  38. scope: this.$store.getters.scope,
  39. }
  40. },
  41. computed: {
  42. projectParams () {
  43. return {
  44. limit: 20,
  45. scope: this.scope,
  46. }
  47. },
  48. isRequired () {
  49. const { conditionVals = [] } = this.decorators
  50. const [, options] = conditionVals
  51. if (options && options.rules && options.rules.length > 0) {
  52. return options.rules.some(rules => rules.required)
  53. }
  54. return false
  55. },
  56. },
  57. methods: {
  58. conditionValsChange (...args) {
  59. this.$emit('conditionValsChange', ...args)
  60. },
  61. },
  62. }
  63. </script>
  64. <style lang="less" scoped>
  65. .no-line-height {
  66. .custom-form-item ::v-deep .ant-form-item-control {
  67. line-height: 0px;
  68. }
  69. }
  70. </style>