消毒机设备
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

170 lines
4.8 KiB

2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
  1. <script lang="ts" setup>
  2. import type { FormInstance } from 'element-plus'
  3. import { useSettingStore } from '@/stores/settingStore'
  4. import { syncSendCmd } from 'apis/system'
  5. import SoftKeyboard from 'components/common/SoftKeyboard/index.vue'
  6. import { FtMessage } from 'libs/message'
  7. import { ref, watchEffect } from 'vue'
  8. const emits = defineEmits(['refresh'])
  9. const settingStore = useSettingStore()
  10. const visible = ref(settingStore.addUserVisible)
  11. const modalType = ref(settingStore.userModalState)
  12. const inputValue = ref<string>('')
  13. const keyboardVisible = ref(false)
  14. const keyboardType = ref<'text' | 'number'>('text')
  15. const softKeyboardRef = ref()
  16. const userFormRef = ref()
  17. const focusedInput = ref<string | null>(null)
  18. const modalTitle = ref('新增用户')
  19. const userForm = ref<Record<string, any>>({
  20. name: '',
  21. passwd: '',
  22. confirmPasswd: '',
  23. roleType: '',
  24. })
  25. watchEffect(() => {
  26. modalType.value = settingStore.userModalState
  27. if (settingStore.userModalState === 'edit') {
  28. modalTitle.value = '修改密码'
  29. }
  30. if (settingStore.currentEditUser) {
  31. userForm.value = settingStore.currentEditUser
  32. }
  33. else {
  34. modalTitle.value = '新增用户'
  35. }
  36. visible.value = settingStore.addUserVisible
  37. if (focusedInput.value) {
  38. userForm.value[focusedInput.value] = inputValue.value
  39. }
  40. })
  41. const onSave = (formRef: FormInstance | undefined) => {
  42. if (!formRef) {
  43. return
  44. }
  45. formRef.validate((valid) => {
  46. if (valid) {
  47. if (userForm.value.id) {
  48. doEdit()
  49. }
  50. else {
  51. doSave()
  52. }
  53. }
  54. else {
  55. console.log('error submit!')
  56. }
  57. })
  58. onClose()
  59. }
  60. const openKeyboard = (e: any) => {
  61. setTimeout(() => {
  62. keyboardVisible.value = true
  63. const labelName = e.target.name
  64. const formValue = userForm.value[labelName as keyof typeof userForm.value]
  65. inputValue.value = formValue ? formValue.toString() : ''
  66. focusedInput.value = e.target.name
  67. }, 100)
  68. }
  69. const doEdit = () => {
  70. }
  71. const doSave = () => {
  72. const name = userForm.value.name
  73. const passwd = userForm.value.passwd
  74. const confirmPasswd = userForm.value.confirmPasswd
  75. const roleType = userForm.value.roleType
  76. if (passwd !== confirmPasswd) {
  77. FtMessage.error('输入的密码不一致')
  78. return
  79. }
  80. const saveParams = {
  81. className: 'UserMgrService',
  82. fnName: 'addUser',
  83. params: {
  84. name,
  85. passwd,
  86. roleType: roleType ? 'admin' : 'maintainer',
  87. },
  88. }
  89. syncSendCmd(saveParams).then((res) => {
  90. if (res.ackcode === 0) {
  91. FtMessage.success('成功')
  92. emits('refresh')
  93. }
  94. })
  95. }
  96. const onClose = () => {
  97. settingStore.updateVisible(false)
  98. }
  99. const handleConfirm = (value: string) => {
  100. console.log('确认输入:', value)
  101. }
  102. </script>
  103. <template>
  104. <FtDialog v-model="visible" :title="modalTitle" :ok-handle="() => { onSave(userFormRef) }" @cancel="onClose">
  105. <div>
  106. <el-form ref="userFormRef" :model="userForm" label-width="auto" style="max-width: 400px">
  107. <el-form-item
  108. v-if="!userForm.id"
  109. label="登录名:"
  110. prop="name"
  111. :rules="[{
  112. required: true,
  113. message: '输入登录名',
  114. trigger: ['blur', 'change'],
  115. }]"
  116. >
  117. <el-input v-model="userForm.name" v-prevent-keyboard name="name" @focus="openKeyboard" placeholder="登录名" />
  118. </el-form-item>
  119. <div>
  120. <el-form-item
  121. label="密码:"
  122. prop="passwd"
  123. :rules="{
  124. required: true,
  125. message: '输入密码',
  126. trigger: ['blur', 'change'],
  127. }"
  128. >
  129. <el-input v-model="userForm.passwd" v-prevent-keyboard name="passwd" @focus="openKeyboard" type="password" placeholder="密码" />
  130. </el-form-item>
  131. <el-form-item
  132. label="确认密码:"
  133. prop="confirmPasswd"
  134. :rules="{
  135. required: true,
  136. message: '输入密码',
  137. trigger: ['blur', 'change'],
  138. }"
  139. >
  140. <el-input v-model="userForm.confirmPasswd" v-prevent-keyboard name="confirmPasswd" @focus="openKeyboard" type="password" placeholder="确认密码" />
  141. </el-form-item>
  142. </div>
  143. <el-form-item
  144. label="是否管理员:"
  145. >
  146. <el-checkbox v-model="userForm.roleType" size="small" />
  147. </el-form-item>
  148. </el-form>
  149. <Teleport to="body">
  150. <SoftKeyboard
  151. ref="softKeyboardRef"
  152. v-model="inputValue"
  153. :is-visible="keyboardVisible"
  154. :keyboard-type="keyboardType"
  155. @update-keyboard-visible="(visible) => keyboardVisible = visible"
  156. @confirm="handleConfirm"
  157. @close="keyboardVisible = false"
  158. />
  159. </Teleport>
  160. </div>
  161. </FtDialog>
  162. </template>
  163. <style lang="scss" scoped>
  164. </style>