register.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template>
  2. <view class="normal-login-container">
  3. <view class="logo-content align-center justify-center flex">
  4. <image style="width: 100rpx;height: 100rpx;" :src="globalConfig.appInfo.logo" mode="widthFix">
  5. </image>
  6. <text class="title">注册</text>
  7. </view>
  8. <view class="login-form-content">
  9. <view class="input-item flex align-center">
  10. <view class="iconfont icon-user icon"></view>
  11. <input v-model="registerForm.username" class="input" type="text" placeholder="请输入账号" maxlength="30" />
  12. </view>
  13. <view class="input-item flex align-center">
  14. <view class="iconfont icon-password icon"></view>
  15. <input v-model="registerForm.password" type="password" class="input" placeholder="请输入密码" maxlength="20" />
  16. </view>
  17. <view class="input-item flex align-center">
  18. <view class="iconfont icon-password icon"></view>
  19. <input v-model="registerForm.confirmPassword" type="password" class="input" placeholder="请输入重复密码" maxlength="20" />
  20. </view>
  21. <view class="input-item flex align-center" style="width: 60%;margin: 0px;" v-if="captchaEnabled">
  22. <view class="iconfont icon-code icon"></view>
  23. <input v-model="registerForm.code" type="number" class="input" placeholder="请输入验证码" maxlength="4" />
  24. <view class="login-code">
  25. <image :src="codeUrl" @click="getCode" class="login-code-img"></image>
  26. </view>
  27. </view>
  28. <view class="action-btn">
  29. <button @click="handleRegister()" class="register-btn cu-btn block bg-blue lg round">注册</button>
  30. </view>
  31. </view>
  32. <view class="xieyi text-center">
  33. <text @click="handleUserLogin" class="text-blue">使用已有账号登录</text>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. import { getCodeImg, register } from '@/api/login'
  39. export default {
  40. data() {
  41. return {
  42. codeUrl: "",
  43. captchaEnabled: true,
  44. globalConfig: getApp().globalData.config,
  45. registerForm: {
  46. username: "",
  47. password: "",
  48. confirmPassword: "",
  49. code: "",
  50. uuid: ''
  51. }
  52. }
  53. },
  54. created() {
  55. this.getCode()
  56. },
  57. methods: {
  58. // 用户登录
  59. handleUserLogin() {
  60. let that = this
  61. that.$tab.navigateTo(`/pages/index`)
  62. },
  63. // 获取图形验证码
  64. getCode() {
  65. getCodeImg().then(res => {
  66. this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled
  67. if (this.captchaEnabled) {
  68. this.codeUrl = 'data:image/gif;base64,' + res.img
  69. this.registerForm.uuid = res.uuid
  70. }
  71. })
  72. },
  73. // 注册方法
  74. async handleRegister() {
  75. if (this.registerForm.username === "") {
  76. this.$modal.msgError("请输入您的账号")
  77. } else if (this.registerForm.password === "") {
  78. this.$modal.msgError("请输入您的密码")
  79. } else if (this.registerForm.confirmPassword === "") {
  80. this.$modal.msgError("请再次输入您的密码")
  81. } else if (this.registerForm.password !== this.registerForm.confirmPassword) {
  82. this.$modal.msgError("两次输入的密码不一致")
  83. } else if (this.registerForm.code === "" && this.captchaEnabled) {
  84. this.$modal.msgError("请输入验证码")
  85. } else {
  86. this.$modal.loading("注册中,请耐心等待...")
  87. this.register()
  88. }
  89. },
  90. // 用户注册
  91. async register() {
  92. register(this.registerForm).then(res => {
  93. this.$modal.closeLoading()
  94. uni.showModal({
  95. title: "系统提示",
  96. content: "恭喜你,您的账号 " + this.registerForm.username + " 注册成功!",
  97. success: function (res) {
  98. if (res.confirm) {
  99. uni.redirectTo({ url: `/pages/index` });
  100. }
  101. }
  102. })
  103. }).catch(() => {
  104. if (this.captchaEnabled) {
  105. this.getCode()
  106. }
  107. })
  108. },
  109. // 注册成功后,处理函数
  110. registerSuccess(result) {
  111. // 设置用户信息
  112. this.$store.dispatch('GetInfo').then(res => {
  113. this.$tab.reLaunch('/pages/phone/index')
  114. })
  115. }
  116. }
  117. }
  118. </script>
  119. <style lang="scss">
  120. page {
  121. background-color: #ffffff;
  122. }
  123. .normal-login-container {
  124. width: 100%;
  125. .logo-content {
  126. width: 100%;
  127. font-size: 21px;
  128. text-align: center;
  129. padding-top: 15%;
  130. image {
  131. border-radius: 4px;
  132. }
  133. .title {
  134. margin-left: 10px;
  135. }
  136. }
  137. .login-form-content {
  138. text-align: center;
  139. margin: 20px auto;
  140. margin-top: 15%;
  141. width: 80%;
  142. .input-item {
  143. margin: 20px auto;
  144. background-color: #f5f6f7;
  145. height: 45px;
  146. border-radius: 20px;
  147. .icon {
  148. font-size: 38rpx;
  149. margin-left: 10px;
  150. color: #999;
  151. }
  152. .input {
  153. width: 100%;
  154. font-size: 14px;
  155. line-height: 20px;
  156. text-align: left;
  157. padding-left: 15px;
  158. }
  159. }
  160. .register-btn {
  161. margin-top: 40px;
  162. height: 45px;
  163. }
  164. .xieyi {
  165. color: #333;
  166. margin-top: 20px;
  167. }
  168. .login-code {
  169. height: 38px;
  170. float: right;
  171. .login-code-img {
  172. height: 38px;
  173. position: absolute;
  174. margin-left: 10px;
  175. width: 200rpx;
  176. }
  177. }
  178. }
  179. }
  180. </style>