消毒机设备
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.

180 lines
5.0 KiB

2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
3 weeks ago
2 months ago
2 months ago
3 weeks ago
2 months ago
3 weeks ago
2 months ago
3 weeks ago
2 months ago
3 weeks ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
3 weeks 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. if (settingStore.currentEditUser) {
  30. userForm.value = settingStore.currentEditUser
  31. }
  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. }
  59. const openKeyboard = (e: any) => {
  60. setTimeout(() => {
  61. keyboardVisible.value = true
  62. const labelName = e.target.name
  63. const formValue = userForm.value[labelName]
  64. inputValue.value = formValue ? formValue.toString() : ''
  65. focusedInput.value = e.target.name
  66. }, 100)
  67. }
  68. const doEdit = () => {
  69. }
  70. const doSave = () => {
  71. const name = userForm.value.name
  72. const passwd = userForm.value.passwd
  73. const confirmPasswd = userForm.value.confirmPasswd
  74. const roleType = userForm.value.roleType
  75. if (passwd !== confirmPasswd) {
  76. FtMessage.error('输入的密码不一致')
  77. return
  78. }
  79. const saveParams = {
  80. className: 'UserMgrService',
  81. fnName: 'addUser',
  82. params: {
  83. name,
  84. passwd,
  85. roleType: roleType ? 'admin' : 'maintainer',
  86. },
  87. }
  88. syncSendCmd(saveParams).then((res) => {
  89. if (res.ackcode === 0) {
  90. FtMessage.success('成功')
  91. emits('refresh')
  92. onClose()
  93. }
  94. })
  95. }
  96. const onClose = () => {
  97. const defaultForm = {
  98. id: 0,
  99. name: '',
  100. passwd: '',
  101. confirmPasswd: '',
  102. roleType: '',
  103. }
  104. userForm.value = defaultForm
  105. settingStore.updateCurrentEditUser(defaultForm)
  106. focusedInput.value = null
  107. settingStore.updateVisible(false)
  108. }
  109. const handleConfirm = (value: string) => {
  110. console.log('确认输入:', value)
  111. }
  112. </script>
  113. <template>
  114. <FtDialog v-if="visible" v-model="visible" :title="modalTitle" :ok-handle="() => { onSave(userFormRef) }" @cancel="onClose">
  115. <div>
  116. <el-form ref="userFormRef" :model="userForm" label-width="auto" style="max-width: 400px">
  117. <el-form-item
  118. v-if="!userForm.id"
  119. label="登录名:"
  120. prop="name"
  121. :rules="[{
  122. required: true,
  123. message: '输入登录名',
  124. trigger: ['blur', 'change'],
  125. }]"
  126. >
  127. <el-input v-model="userForm.name" v-prevent-keyboard name="name" @focus="openKeyboard" placeholder="登录名" />
  128. </el-form-item>
  129. <div>
  130. <el-form-item
  131. label="密码:"
  132. prop="passwd"
  133. :rules="{
  134. required: true,
  135. message: '输入密码',
  136. trigger: ['blur', 'change'],
  137. }"
  138. >
  139. <el-input v-model="userForm.passwd" v-prevent-keyboard name="passwd" @focus="openKeyboard" type="password" placeholder="密码" />
  140. </el-form-item>
  141. <el-form-item
  142. label="确认密码:"
  143. prop="confirmPasswd"
  144. :rules="{
  145. required: true,
  146. message: '输入密码',
  147. trigger: ['blur', 'change'],
  148. }"
  149. >
  150. <el-input v-model="userForm.confirmPasswd" v-prevent-keyboard name="confirmPasswd" @focus="openKeyboard" placeholder="确认密码" />
  151. </el-form-item>
  152. </div>
  153. <el-form-item
  154. label="是否管理员:"
  155. >
  156. <el-checkbox v-model="userForm.roleType" size="small" />
  157. </el-form-item>
  158. </el-form>
  159. <Teleport to="body">
  160. <SoftKeyboard
  161. ref="softKeyboardRef"
  162. v-model="inputValue"
  163. :is-visible="keyboardVisible"
  164. :keyboard-type="keyboardType"
  165. @update-keyboard-visible="(visible) => keyboardVisible = visible"
  166. @confirm="handleConfirm"
  167. @close="keyboardVisible = false"
  168. />
  169. </Teleport>
  170. </div>
  171. </FtDialog>
  172. </template>
  173. <style lang="scss" scoped>
  174. </style>