register.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <!-- 注册 -->
  2. <template>
  3. <view class="container flex-column">
  4. <global-loading />
  5. <view class="register" @click="$jump('/pages_category_page2/userModule/login', '', 0, 'reLaunch')">
  6. 登录
  7. </view>
  8. <view class="PhoneAuthentication">
  9. <text class="textRL">手机号快捷注册</text>
  10. <text class="textTips">注册完后将会自动发登录</text>
  11. </view>
  12. <view class="LoginForm">
  13. <view class="iphoneNum-box">
  14. <text class="labels">手机号</text>
  15. <input v-model="registerQuery.phone" type="text" placeholder="请输入手机号">
  16. </view>
  17. <view class="iphoneNum-box">
  18. <text class="labels">验证码</text>
  19. <input v-model="registerQuery.verificationCode" type="text" placeholder="请输入验证码">
  20. <view v-if="!disabled" class="getcode" @click="getVerify">
  21. {{ text }}
  22. </view>
  23. <view v-else class="awaitCode">
  24. {{ text }}
  25. </view>
  26. </view>
  27. <view class="iphoneNum-box">
  28. <text class="labels">设置密码</text>
  29. <input v-model="registerQuery.password" type="text" password placeholder="请设置密码">
  30. </view>
  31. <view class="iphoneNum-box">
  32. <text class="labels">再次输入密码</text>
  33. <input v-model="registerQuery.passwordAgain" type="text" password placeholder="请设置密码">
  34. </view>
  35. <view class="ReadingAgreement">
  36. <radio style="transform:scale(0.8)" color="#CE2601" :checked="agreement" @click="agreement = !agreement" />
  37. <view class="Agreement">
  38. 我已阅读并同意<text class="redText" @click="$jump('protocol?type=app_user_agreement')">
  39. 《巨蜂商城用户服务协议》
  40. </text>以及<text class="redText" @click="$jump('protocol?type=app_privacy_agreement')">
  41. 《隐私政策》
  42. </text>
  43. </view>
  44. </view>
  45. </view>
  46. <tui-button
  47. :disabled="!agreement" type="danger" width="650rpx" margin="0 auto"
  48. height="82rpx"
  49. style="margin-top: 60rpx;" @click="getRegister"
  50. >
  51. 立即注册
  52. </tui-button>
  53. <view class="problem">
  54. <text @click="$jump('/pages_category_page2/userModule/login', '', 0, 'reLaunch')">
  55. 已有账号<text
  56. class="redText"
  57. >
  58. 去登录
  59. </text>
  60. </text>
  61. <text>无法接收验证码?</text>
  62. </view>
  63. </view>
  64. </template>
  65. <script>
  66. import sendVerifyCode from '@/mixins/SendVerifyCode'
  67. import { J_STORAGE_KEY } from '../../config/constant'
  68. const NET = require('../../utils/request')
  69. const API = require('../../config/api')
  70. import { getVerifyCodeApi } from '../../api/user'
  71. export default {
  72. name: 'Register',
  73. mixins: [ sendVerifyCode ],
  74. data() {
  75. return {
  76. // 注册
  77. registerQuery: {
  78. phone: '',
  79. verificationCode: '',
  80. password: '',
  81. passwordAgain: ''
  82. },
  83. agreement: false
  84. }
  85. },
  86. methods: {
  87. // 注册账号
  88. getRegister() {
  89. const phoneCodeVerification = /^1(3\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\d|9[0-35-9])\d{8}$/
  90. if (this.registerQuery.phone == '') {
  91. this.$showToast('请输入手机号!')
  92. } else if (!phoneCodeVerification.test(this.registerQuery.phone)) {
  93. this.$showToast('请输入正确的手机号!')
  94. } else if (this.registerQuery.verificationCode == '') {
  95. this.$showToast('请获取验证码!')
  96. } else if (!this.registerQuery.password) {
  97. this.$showToast('请设置密码!')
  98. } else if (this.registerQuery.password !== this.registerQuery.passwordAgain) {
  99. this.$showToast('请设置密码!')
  100. } else if (!this.agreement) {
  101. this.$showToast('请先阅读并同意《用户服务协议和个人隐私协议》')
  102. } else {
  103. // uni.showLoading({
  104. // mask: true,
  105. // title: '正在注册...',
  106. // duration: 2000,
  107. // })
  108. NET.request(API.Login, {
  109. type: 1, // type为1是注册
  110. phone: this.registerQuery.phone,
  111. verificationCode: this.registerQuery.verificationCode,
  112. password: this.registerQuery.password
  113. }, 'POST').then((res) => {
  114. uni.hideLoading()
  115. this.$showToast('注册成功!')
  116. const item = res.data
  117. uni.setStorageSync(J_STORAGE_KEY, item)
  118. setTimeout(() => {
  119. this.$switchTab('/pages/tabbar/user/index')
  120. }, 600)
  121. })
  122. .catch((res) => {
  123. this.$showToast(res.data.message)
  124. })
  125. }
  126. },
  127. // 获取验证码
  128. getVerify() {
  129. const phoneCodeVerification = /^1(3\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\d|9[0-35-9])\d{8}$/
  130. if (this.registerQuery.phone == '') {
  131. this.$showToast('请输入手机号!')
  132. } else if (!phoneCodeVerification.test(this.registerQuery.phone)) {
  133. this.$showToast('请输入正确的手机号!')
  134. } else {
  135. getVerifyCodeApi({
  136. phone: this.registerQuery.phone
  137. }).then((res) => {
  138. this.sendCode()
  139. })
  140. .catch((res) => {
  141. this.$showToast(res.data.message)
  142. })
  143. }
  144. }
  145. }
  146. }
  147. </script>
  148. <style lang="scss" scoped>
  149. .container {
  150. background-color: #FFFFFF;
  151. .redText {
  152. color: #CE2601;
  153. }
  154. .register {
  155. margin-top: 50rpx;
  156. position: relative;
  157. text-align: right;
  158. padding-right: 40rpx;
  159. }
  160. .PhoneAuthentication {
  161. margin-top: 15rpx;
  162. font-family: Source Han Sans CN;
  163. width: 466rpx;
  164. height: 100rpx;
  165. display: flex;
  166. flex-direction: column;
  167. padding: 0px 30rpx;
  168. gap: 8rpx;
  169. .textRL {
  170. font-size: 44rpx;
  171. font-weight: 600;
  172. line-height: 60rpx;
  173. color: #222229;
  174. }
  175. .textTips {
  176. font-size: 24rpx;
  177. font-weight: 350;
  178. line-height: 32rpx;
  179. color: #888889;
  180. }
  181. }
  182. .LoginForm {
  183. margin-top: 50rpx;
  184. width: 750rpx;
  185. .iphoneNum-box {
  186. /* 自动布局 */
  187. margin: 0 auto;
  188. height: 114rpx;
  189. display: flex;
  190. flex-direction: row;
  191. align-items: center;
  192. gap: 32rpx;
  193. border-bottom: 2rpx solid #E6E6E8;
  194. width: 690rpx;
  195. color: #222229;
  196. .labels {
  197. font-size: 32rpx;
  198. font-weight: normal;
  199. line-height: 48rpx;
  200. }
  201. }
  202. .ReadingAgreement {
  203. width: 710rpx;
  204. margin: 0 auto;
  205. margin-top: 33rpx;
  206. gap: 32rpx;
  207. display: flex;
  208. align-items: center;
  209. font-size: 24rpx;
  210. .Agreement {
  211. margin-left: -15rpx;
  212. }
  213. }
  214. }
  215. .problem {
  216. margin: 0 auto;
  217. margin-top: 30rpx;
  218. width: 654rpx;
  219. display: flex;
  220. justify-content: space-between;
  221. font-size: 24rpx;
  222. font-weight: 350;
  223. line-height: 32rpx;
  224. color: #878788;
  225. }
  226. .getcode {
  227. position: absolute;
  228. right: 30rpx;
  229. font-size: 32rpx;
  230. font-weight: normal;
  231. line-height: 48rpx;
  232. text-align: right;
  233. color: #CE2601;
  234. }
  235. .awaitCode {
  236. position: absolute;
  237. right: 30rpx;
  238. font-size: 32rpx;
  239. font-weight: normal;
  240. line-height: 48rpx;
  241. text-align: right;
  242. color: #888889;
  243. }
  244. }
  245. </style>