CreateOrEditRule.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{params.title}}</div>
  4. <div slot="body">
  5. <a-form
  6. v-bind="formItemLayout"
  7. :form="form.fc">
  8. <a-form-item>
  9. <span slot="label">
  10. {{$t('storage.access.group.rule.source')}}&nbsp;
  11. <a-tooltip :title="$t('storage.access.group.rule.source.tooltip')">
  12. <a-icon type="question-circle-o" />
  13. </a-tooltip>
  14. </span>
  15. <a-input :disabled="IPCheckboxDisabled" v-decorator="decorators.source" />
  16. <a-checkbox class="right-checkbox" @change="sourceChanged" :checked="isIPChecked">{{$t('compute.text_997')}}</a-checkbox>
  17. </a-form-item>
  18. <a-form-item :label="$t('storage.access.group.rule.rw.access_type')">
  19. <a-radio-group v-decorator="decorators.rw_access_type">
  20. <a-radio value="RW">{{$t('storage.access.group.rule.rw.access_type.rw')}}</a-radio>
  21. <a-radio value="R">{{$t('storage.access.group.rule.rw.access_type.r')}}</a-radio>
  22. </a-radio-group>
  23. </a-form-item>
  24. <a-form-item :label="$t('storage.access.group.rule.user.access_type')">
  25. <a-radio-group v-decorator="decorators.user_access_type">
  26. <a-radio value="no_root_squash">{{$t('storage.access.group.rule.user.access_type.no_root_squash')}}</a-radio>
  27. <a-radio value="root_squash">{{$t('storage.access.group.rule.user.access_type.root_squash')}}</a-radio>
  28. <a-radio value="all_squash">{{$t('storage.access.group.rule.user.access_type.all_squash')}}</a-radio>
  29. </a-radio-group>
  30. </a-form-item>
  31. <a-form-item>
  32. <span slot="label">{{$t('compute.text_1001')}}<a-tooltip :title="$t('compute.text_1002')">
  33. <a-icon type="question-circle-o" />
  34. </a-tooltip>
  35. </span>
  36. <a-input-number :min="1" :max="100" v-decorator="decorators.priority" />
  37. </a-form-item>
  38. </a-form>
  39. </div>
  40. <div slot="footer">
  41. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  42. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  43. </div>
  44. </base-dialog>
  45. </template>
  46. <script>
  47. import DialogMixin from '@/mixins/dialog'
  48. import WindowsMixin from '@/mixins/windows'
  49. export default {
  50. name: 'AccessGroupRuleEditDialog',
  51. mixins: [DialogMixin, WindowsMixin],
  52. props: {
  53. id: {
  54. type: String,
  55. required: true,
  56. },
  57. },
  58. data () {
  59. const selectItem = this.params.data[0]
  60. return {
  61. loading: false,
  62. form: {
  63. fc: this.$form.createForm(this),
  64. },
  65. decorators: {
  66. source: [
  67. 'source',
  68. {
  69. validateFirst: true,
  70. initialValue: selectItem.source || '',
  71. rules: [
  72. { required: true, message: this.$t('compute.text_996') },
  73. { validator: this.$validate('source') },
  74. ],
  75. },
  76. ],
  77. rw_access_type: [
  78. 'rw_access_type',
  79. {
  80. initialValue: selectItem.rw_access_type || 'RW',
  81. rules: [
  82. { required: true },
  83. ],
  84. },
  85. ],
  86. user_access_type: [
  87. 'user_access_type',
  88. {
  89. initialValue: selectItem.user_access_type || 'no_root_squash',
  90. rules: [
  91. { required: true },
  92. ],
  93. },
  94. ],
  95. priority: [
  96. 'priority',
  97. {
  98. initialValue: selectItem.priority || 1,
  99. },
  100. ],
  101. },
  102. formItemLayout: {
  103. wrapperCol: {
  104. span: 14,
  105. },
  106. labelCol: {
  107. span: 4,
  108. },
  109. },
  110. IPCheckboxDisabled: selectItem.cidr === '0.0.0.0/0',
  111. isIPChecked: selectItem.cidr === '0.0.0.0/0',
  112. }
  113. },
  114. methods: {
  115. sourceChanged (e) {
  116. this.IPCheckboxDisabled = !this.IPCheckboxDisabled
  117. this.isIPChecked = !this.isIPChecked
  118. if (e.target.checked) {
  119. this.$nextTick(() => {
  120. this.form.fc.setFieldsValue({ source: '0.0.0.0/0' })
  121. })
  122. } else {
  123. this.$nextTick(() => {
  124. this.form.fc.resetFields(['source'])
  125. })
  126. }
  127. },
  128. saveEdit (data) {
  129. if (this.params.data[0].id) {
  130. const id = this.params.data[0].id
  131. return new this.$Manager('access_group_rules').update({
  132. id,
  133. data,
  134. })
  135. }
  136. const params = {
  137. ...data,
  138. access_group_id: this.params.access_group_id,
  139. }
  140. return new this.$Manager('access_group_rules').create({
  141. data: params,
  142. })
  143. },
  144. async handleConfirm () {
  145. this.loading = true
  146. try {
  147. const values = await this.form.fc.validateFields()
  148. await this.saveEdit(values)
  149. this.loading = false
  150. this.params.refresh && this.params.refresh()
  151. this.cancelDialog()
  152. } catch (e) {
  153. this.loading = false
  154. throw e
  155. }
  156. },
  157. },
  158. }
  159. </script>
  160. <style lang="less" scoped>
  161. .right-checkbox {
  162. width: 100px;
  163. height: 40px;
  164. left: 470px;
  165. font-size: 12px!important;
  166. color: #ccc;
  167. position: absolute;
  168. }
  169. </style>