register.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <!--
  2. * @Author: wyd
  3. * @Date: 2024-03
  4. * @LastEditors: wyd
  5. * @LastEditTime: 2024-05
  6. * @Description: 注册
  7. -->
  8. <script setup lang="ts">
  9. import { ref } from 'vue'
  10. import { onLoad, onPullDownRefresh, onReady } from '@dcloudio/uni-app'
  11. import { system } from '@/stores/modules/system'
  12. import { useGlobal } from '@/composables'
  13. import { validatorMobile, verifyPwd } from '@/utils/verification'
  14. import { registerApi } from '@/api/login'
  15. import Captcha from '@/base/components/Captcha.vue'
  16. import type { captchaInfo } from '@/types/login'
  17. const systemStore = system()
  18. // 表单信息
  19. const form = ref({
  20. // username: '',
  21. realname: '',
  22. password: '',
  23. mobile: '',
  24. uuid: '',
  25. code: ''
  26. })
  27. // 表单校验
  28. const rules: UniHelper.UniFormsRules = {
  29. // username: {
  30. // rules: [
  31. // {
  32. // required: true,
  33. // errorMessage: '请输入用户名'
  34. // },
  35. // {
  36. // maxLength: useGlobal().textMax,
  37. // errorMessage: '限制{maxLength}个字符'
  38. // }
  39. // ]
  40. // },
  41. realname: {
  42. rules: [
  43. {
  44. required: true,
  45. errorMessage: '请输入姓名'
  46. },
  47. {
  48. maxLength: useGlobal().textMax,
  49. errorMessage: '限制{maxLength}个字符'
  50. }
  51. ]
  52. },
  53. password: {
  54. rules: [
  55. {
  56. required: true,
  57. errorMessage: '请输入密码'
  58. },
  59. {
  60. validateFunction: verifyPwd
  61. }
  62. ]
  63. },
  64. code: {
  65. rules: [
  66. {
  67. required: true,
  68. errorMessage: '请输入验证码'
  69. }
  70. ]
  71. },
  72. mobile: {
  73. rules: [
  74. {
  75. required: true,
  76. errorMessage: '请输入手机号'
  77. },
  78. {
  79. validateFunction: validatorMobile
  80. }
  81. ]
  82. }
  83. }
  84. // 表单组件实例
  85. const formRef = ref<UniHelper.UniFormsInstance>()
  86. // 是否展示验证码
  87. let isShowCaptcha: boolean = true
  88. const captchaRef = ref()
  89. const getCaptchaInfo = (val: captchaInfo) => {
  90. isShowCaptcha = val.captchaEnabled
  91. form.value.uuid = val.uuid
  92. form.value.code = val.code
  93. }
  94. const handleSubmit = async () => {
  95. formRef.value?.validate?.((err, formData) => {
  96. if (!err) {
  97. uni.showLoading()
  98. registerApi(form.value)
  99. .then(() => {
  100. // 注册成功,返回上一页
  101. uni.showToast({
  102. title: '操作成功',
  103. icon: 'none'
  104. })
  105. setTimeout(() => {
  106. uni.navigateBack()
  107. }, 1000)
  108. })
  109. .catch((err) => {
  110. captchaRef.value?.getCaptchaImage()
  111. })
  112. }
  113. })
  114. }
  115. onLoad(async () => {
  116. await systemStore.getConfigData()
  117. })
  118. onReady(() => {
  119. formRef.value?.setRules?.(rules)
  120. })
  121. // 下拉刷新
  122. onPullDownRefresh(async () => {
  123. await systemStore.getConfigData()
  124. uni.stopPullDownRefresh()
  125. })
  126. </script>
  127. <template>
  128. <view class="login-box">
  129. <view class="center-box p15 shadow">
  130. <view class="tc f18 weight-600 black-color mb20">注册</view>
  131. <uni-forms ref="formRef" :model="form" :rules="rules">
  132. <uni-forms-item name="mobile">
  133. <uni-easyinput type="text" v-model="form.mobile" placeholder="请输入手机号" />
  134. </uni-forms-item>
  135. <!-- <uni-forms-item name="username">
  136. <uni-easyinput type="text" v-model="form.username" placeholder="请输入用户名" />
  137. </uni-forms-item> -->
  138. <uni-forms-item name="realname">
  139. <uni-easyinput type="text" v-model="form.realname" placeholder="请输入姓名" />
  140. </uni-forms-item>
  141. <uni-forms-item name="password">
  142. <uni-easyinput type="password" v-model="form.password" placeholder="请输入密码" />
  143. </uni-forms-item>
  144. <uni-forms-item v-if="isShowCaptcha && systemStore.config.captcha === 'true'" name="code">
  145. <Captcha ref="captchaRef" @getCaptchaInfo="getCaptchaInfo" class="w100" />
  146. </uni-forms-item>
  147. </uni-forms>
  148. <view class="btn-b warning-bg" @tap="handleSubmit">确 定</view>
  149. </view>
  150. </view>
  151. </template>
  152. <style lang="scss" scoped>
  153. .login-box {
  154. width: 100vw;
  155. height: 100vh;
  156. background: url('http://1.94.6.75:9000/zlhy-app/bg_login.jpg') center no-repeat;
  157. background-size: 100% 100%;
  158. position: relative;
  159. .center-box {
  160. width: calc(100vw - 60px);
  161. min-height: 200px;
  162. border-radius: 10rpx;
  163. background: rgba($color: #fff, $alpha: 0.8);
  164. position: absolute;
  165. left: 15px;
  166. top: 20%;
  167. .btn-b {
  168. width: 100% !important;
  169. }
  170. }
  171. }
  172. </style>