register.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. this.$tab.navigateTo(`/pages/login`)
  61. },
  62. // 获取图形验证码
  63. getCode() {
  64. getCodeImg().then(res => {
  65. this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled
  66. if (this.captchaEnabled) {
  67. this.codeUrl = 'data:image/gif;base64,' + res.img
  68. this.registerForm.uuid = res.uuid
  69. }
  70. })
  71. },
  72. // 注册方法
  73. async handleRegister() {
  74. if (this.registerForm.username === "") {
  75. this.$modal.msgError("请输入您的账号")
  76. } else if (this.registerForm.password === "") {
  77. this.$modal.msgError("请输入您的密码")
  78. } else if (this.registerForm.confirmPassword === "") {
  79. this.$modal.msgError("请再次输入您的密码")
  80. } else if (this.registerForm.password !== this.registerForm.confirmPassword) {
  81. this.$modal.msgError("两次输入的密码不一致")
  82. } else if (this.registerForm.code === "" && this.captchaEnabled) {
  83. this.$modal.msgError("请输入验证码")
  84. } else {
  85. this.$modal.loading("注册中,请耐心等待...")
  86. this.register()
  87. }
  88. },
  89. // 用户注册
  90. async register() {
  91. register(this.registerForm).then(res => {
  92. this.$modal.closeLoading()
  93. uni.showModal({
  94. title: "系统提示",
  95. content: "恭喜你,您的账号 " + this.registerForm.username + " 注册成功!",
  96. success: function (res) {
  97. if (res.confirm) {
  98. uni.redirectTo({ url: `/pages/login` });
  99. }
  100. }
  101. })
  102. }).catch(() => {
  103. if (this.captchaEnabled) {
  104. this.getCode()
  105. }
  106. })
  107. },
  108. // 注册成功后,处理函数
  109. registerSuccess(result) {
  110. // 设置用户信息
  111. this.$store.dispatch('GetInfo').then(res => {
  112. this.$tab.reLaunch('/pages/index')
  113. })
  114. }
  115. }
  116. }
  117. </script>
  118. <style lang="scss">
  119. page {
  120. background-color: #ffffff;
  121. }
  122. .normal-login-container {
  123. width: 100%;
  124. .logo-content {
  125. width: 100%;
  126. font-size: 21px;
  127. text-align: center;
  128. padding-top: 15%;
  129. image {
  130. border-radius: 4px;
  131. }
  132. .title {
  133. margin-left: 10px;
  134. }
  135. }
  136. .login-form-content {
  137. text-align: center;
  138. margin: 20px auto;
  139. margin-top: 15%;
  140. width: 80%;
  141. .input-item {
  142. margin: 20px auto;
  143. background-color: #f5f6f7;
  144. height: 45px;
  145. border-radius: 20px;
  146. .icon {
  147. font-size: 38rpx;
  148. margin-left: 10px;
  149. color: #999;
  150. }
  151. .input {
  152. width: 100%;
  153. font-size: 14px;
  154. line-height: 20px;
  155. text-align: left;
  156. padding-left: 15px;
  157. }
  158. }
  159. .register-btn {
  160. margin-top: 40px;
  161. height: 45px;
  162. }
  163. .xieyi {
  164. color: #333;
  165. margin-top: 20px;
  166. }
  167. .login-code {
  168. height: 38px;
  169. float: right;
  170. .login-code-img {
  171. height: 38px;
  172. position: absolute;
  173. margin-left: 10px;
  174. width: 200rpx;
  175. }
  176. }
  177. }
  178. }
  179. </style>