tenant-modal.tsx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. import { defineComponent, PropType, toRefs, watch } from 'vue'
  18. import Modal from '@/components/modal'
  19. import { NForm, NFormItem, NInput, NSelect } from 'naive-ui'
  20. import { useModalData } from './use-modalData'
  21. import { useI18n } from 'vue-i18n'
  22. const TenantModal = defineComponent({
  23. name: 'tenant-modal',
  24. props: {
  25. showModalRef: {
  26. type: Boolean as PropType<boolean>,
  27. default: false
  28. },
  29. statusRef: {
  30. type: Number as PropType<number>,
  31. default: 0
  32. },
  33. row: {
  34. type: Object as PropType<any>,
  35. default: {}
  36. }
  37. },
  38. emits: ['cancelModal', 'confirmModal'],
  39. setup(props, ctx) {
  40. const { variables, getListData, handleValidate } = useModalData(props, ctx)
  41. const { t } = useI18n()
  42. const cancelModal = () => {
  43. if (props.statusRef === 0) {
  44. variables.model.tenantCode = ''
  45. variables.model.description = ''
  46. }
  47. ctx.emit('cancelModal', props.showModalRef)
  48. }
  49. const confirmModal = () => {
  50. handleValidate(props.statusRef)
  51. }
  52. watch(
  53. () => props.showModalRef,
  54. () => {
  55. props.showModalRef && getListData(props.statusRef)
  56. }
  57. )
  58. watch(
  59. () => props.statusRef,
  60. () => {
  61. if (props.statusRef === 0) {
  62. variables.model.tenantCode = ''
  63. variables.model.description = ''
  64. variables.model.queueId = null
  65. } else {
  66. variables.model.id = props.row.id
  67. variables.model.tenantCode = props.row.tenantCode
  68. variables.model.queueId = props.row.queueId
  69. variables.model.description = props.row.description
  70. }
  71. }
  72. )
  73. watch(
  74. () => props.row,
  75. () => {
  76. variables.model.id = props.row.id
  77. variables.model.tenantCode = props.row.tenantCode
  78. variables.model.queueId = props.row.queueId
  79. variables.model.description = props.row.description
  80. }
  81. )
  82. return { t, ...toRefs(variables), cancelModal, confirmModal }
  83. },
  84. render() {
  85. const { t } = this
  86. return (
  87. <div>
  88. <Modal
  89. title={
  90. this.statusRef === 0
  91. ? t('security.tenant.create_tenant')
  92. : t('security.tenant.edit_tenant')
  93. }
  94. show={this.showModalRef}
  95. onCancel={this.cancelModal}
  96. onConfirm={this.confirmModal}
  97. confirmClassName='btn-submit'
  98. cancelClassName='btn-cancel'
  99. confirmLoading={this.saving}
  100. >
  101. {{
  102. default: () => (
  103. <NForm
  104. model={this.model}
  105. rules={this.rules}
  106. ref='tenantFormRef'
  107. require-mark-placement='left'
  108. size='small'
  109. style="{ maxWidth: '240px' }"
  110. >
  111. <NFormItem
  112. label={t('security.tenant.tenant_code')}
  113. path='tenantCode'
  114. >
  115. <NInput
  116. class='input-tenant-code'
  117. disabled={this.statusRef === 1}
  118. placeholder={t('security.tenant.tenant_code_tips')}
  119. v-model={[this.model.tenantCode, 'value']}
  120. />
  121. </NFormItem>
  122. <NFormItem
  123. label={t('security.tenant.queue_name')}
  124. path='queueId'
  125. >
  126. <NSelect
  127. class='select-queue'
  128. placeholder={t('security.tenant.queue_name_tips')}
  129. options={this.model.generalOptions}
  130. v-model={[this.model.queueId, 'value']}
  131. />
  132. </NFormItem>
  133. <NFormItem
  134. label={t('security.tenant.description')}
  135. path='description'
  136. >
  137. <NInput
  138. class='input-description'
  139. placeholder={t('security.tenant.description_tips')}
  140. v-model={[this.model.description, 'value']}
  141. type='textarea'
  142. />
  143. </NFormItem>
  144. </NForm>
  145. )
  146. }}
  147. </Modal>
  148. </div>
  149. )
  150. }
  151. })
  152. export default TenantModal