tenant-modal.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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, onMounted, 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. emits: ['cancelModal', 'confirmModal'],
  25. setup(props, ctx) {
  26. const { variables, getListData, handleValidate} = useModalData(props, ctx)
  27. const { t } = useI18n()
  28. const cancelModal = () => {
  29. if (props.statusRef === 0) {
  30. variables.model.tenantCode = ''
  31. variables.model.description = ''
  32. }
  33. ctx.emit('cancelModal', props.showModalRef)
  34. }
  35. const confirmModal = () => {
  36. handleValidate(props.statusRef)
  37. }
  38. watch(() => props.showModalRef, () => {
  39. props.showModalRef && getListData()
  40. })
  41. watch(() => props.statusRef, () => {
  42. if (props.statusRef === 0) {
  43. variables.model.tenantCode = ''
  44. variables.model.description = ''
  45. } else {
  46. variables.model.id = props.row.id
  47. variables.model.tenantCode = props.row.tenantCode
  48. variables.model.queueId = props.row.queueId
  49. variables.model.description = props.row.description
  50. }
  51. })
  52. watch(() => props.row, () => {
  53. variables.model.id = props.row.id
  54. variables.model.tenantCode = props.row.tenantCode
  55. variables.model.queueId = props.row.queueId
  56. variables.model.description = props.row.description
  57. })
  58. return { t, ...toRefs(variables), cancelModal, confirmModal }
  59. },
  60. props: {
  61. showModalRef: {
  62. type: Boolean as PropType<boolean>,
  63. default: false,
  64. },
  65. statusRef: {
  66. type: Number as PropType<number>,
  67. default: 0,
  68. },
  69. row: {
  70. type: Object as PropType<any>,
  71. default: {},
  72. }
  73. },
  74. render() {
  75. const { t } = this
  76. return (
  77. <div>
  78. <Modal
  79. title={this.statusRef === 0 ? t('security.tenant.create_tenant') : t('security.tenant.edit_tenant')}
  80. show={this.showModalRef}
  81. onCancel={this.cancelModal}
  82. onConfirm={this.confirmModal}
  83. >
  84. {{
  85. default: () => (
  86. <NForm
  87. model={this.model}
  88. rules={this.rules}
  89. ref="tenantFormRef"
  90. label-placement="left"
  91. label-width={140}
  92. require-mark-placement="left"
  93. size="small"
  94. style="{ maxWidth: '240px' }"
  95. >
  96. <NFormItem label={t('security.tenant.tenant_code')} path="tenantCode">
  97. <NInput disabled={this.statusRef === 1} placeholder={t('security.tenant.tenant_code_tips')} v-model={[this.model.tenantCode, 'value']} />
  98. </NFormItem>
  99. <NFormItem label={t('security.tenant.queue_name')} path="queueId">
  100. <NSelect
  101. placeholder={t('security.tenant.queue_name_tips')}
  102. options={this.model.generalOptions}
  103. v-model={[this.model.queueId, 'value']}
  104. />
  105. </NFormItem>
  106. <NFormItem label={t('security.tenant.description')} path="description">
  107. <NInput
  108. placeholder={t('security.tenant.description_tips')}
  109. v-model={[this.model.description, 'value']}
  110. type="textarea"
  111. />
  112. </NFormItem>
  113. </NForm>
  114. ),
  115. }}
  116. </Modal>
  117. </div>
  118. )
  119. },
  120. })
  121. export default TenantModal