user-modal.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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, inject } from 'vue'
  18. import { useI18n } from 'vue-i18n'
  19. import {
  20. NInput,
  21. NForm,
  22. NFormItem,
  23. NSelect,
  24. NRadio,
  25. NRadioGroup,
  26. NSpace,
  27. NAlert
  28. } from 'naive-ui'
  29. import Modal from '@/components/modal'
  30. import {
  31. useModal,
  32. useSharedUserModalState,
  33. UserModalSharedStateKey
  34. } from './use-modal'
  35. export const UserModal = defineComponent({
  36. name: 'user-modal',
  37. setup() {
  38. const { t } = useI18n()
  39. const sharedState =
  40. inject(UserModalSharedStateKey) || useSharedUserModalState()
  41. const modalState = useModal(sharedState)
  42. return {
  43. t,
  44. ...modalState
  45. }
  46. },
  47. render() {
  48. const { t } = this
  49. return (
  50. <Modal
  51. show={this.show}
  52. title={this.titleMap?.[this.mode || 'add']}
  53. onCancel={this.onModalCancel}
  54. confirmLoading={this.confirmLoading}
  55. onConfirm={this.onConfirm}
  56. >
  57. {{
  58. default: () => {
  59. if (this.mode === 'delete') {
  60. return (
  61. <NAlert type='error' title={t('security.user.delete_confirm')}>
  62. {t('security.user.delete_confirm_tip')}
  63. </NAlert>
  64. )
  65. }
  66. return (
  67. <NForm
  68. ref='formRef'
  69. model={this.formValues}
  70. rules={this.formRules}
  71. labelPlacement='left'
  72. labelAlign='left'
  73. labelWidth={80}
  74. >
  75. <NFormItem label={t('security.user.username')} path='userName'>
  76. <NInput
  77. inputProps={{ autocomplete: 'off' }}
  78. v-model:value={this.formValues.userName}
  79. />
  80. </NFormItem>
  81. <NFormItem
  82. label={t('security.user.user_password')}
  83. path='userPassword'
  84. >
  85. <NInput
  86. inputProps={{ autocomplete: 'off' }}
  87. type='password'
  88. v-model:value={this.formValues.userPassword}
  89. />
  90. </NFormItem>
  91. <NFormItem
  92. label={t('security.user.tenant_code')}
  93. path='tenantId'
  94. >
  95. <NSelect
  96. options={this.tenants}
  97. v-model:value={this.formValues.tenantId}
  98. />
  99. </NFormItem>
  100. <NFormItem label={t('security.user.queue')} path='queue'>
  101. <NSelect
  102. options={this.queues}
  103. v-model:value={this.formValues.queue}
  104. />
  105. </NFormItem>
  106. <NFormItem label={t('security.user.email')} path='email'>
  107. <NInput v-model:value={this.formValues.email} />
  108. </NFormItem>
  109. <NFormItem label={t('security.user.phone')} path='phone'>
  110. <NInput v-model:value={this.formValues.phone} />
  111. </NFormItem>
  112. <NFormItem label={t('security.user.state')} path='state'>
  113. <NRadioGroup v-model:value={this.formValues.state}>
  114. <NSpace>
  115. <NRadio value={1}>启用</NRadio>
  116. <NRadio value={0}>停用</NRadio>
  117. </NSpace>
  118. </NRadioGroup>
  119. </NFormItem>
  120. </NForm>
  121. )
  122. }
  123. }}
  124. </Modal>
  125. )
  126. }
  127. })
  128. export default UserModal