register.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <template>
  2. <view class="content">
  3. <view class="logo">
  4. <image
  5. style="height:104rpx;width:104rpx"
  6. src="/static/logo.png"
  7. mode="aspectFit"
  8. />
  9. </view>
  10. <view class="login-title">
  11. <span>{{$t('login.register')}}</span>
  12. </view>
  13. <!-- 账号密码登录 -->
  14. <view class="inp_box">
  15. <u-input type="text" :border="false" v-model="registerForm.phone" placeholder="请输入用户名" />
  16. </view>
  17. <!-- 账号密码登录 -->
  18. <view class="inp_box">
  19. <u-input type="text" :border="false" v-model="registerForm.displayName" placeholder="请输入显示名" />
  20. </view>
  21. <!-- 账号密码登录 -->
  22. <view class="inp_box">
  23. <u-input type="password" :border="false" v-model="registerForm.password" placeholder="请输入密码" />
  24. </view>
  25. <view class="inp_box">
  26. <u-input type="password" :border="false" v-model="registerForm.password2" placeholder="请输入确认密码" />
  27. </view>
  28. <u-button type="primary" shape="circle" @click="phoneLogin">{{$t('login.register')}}</u-button>
  29. </view>
  30. </template>
  31. <script>
  32. import {
  33. getRegTelCode,
  34. register
  35. } from '../../api/login'
  36. export default {
  37. data() {
  38. return {
  39. time: 0,
  40. timer: '',
  41. isGetCode: false,
  42. option: [{
  43. text: '',
  44. value: 1,
  45. }],
  46. registerForm: {
  47. phone: "",
  48. password:"",
  49. displayName: "",
  50. verificationCode: "",
  51. type: "",
  52. password2:'',
  53. },
  54. roleList: [{
  55. value: 0,
  56. text: this.$t("login.dealer")
  57. },
  58. {
  59. value: 1,
  60. text: this.$t("login.driver")
  61. }
  62. ],
  63. }
  64. },
  65. onLoad(options) {
  66. this.registerForm.type = '3'
  67. },
  68. methods: {
  69. backLogin() {
  70. uni.navigateBack({
  71. delta: 1
  72. })
  73. },
  74. //获取验证码
  75. getCode() {
  76. let phone = /^1[3-9]\d{9}$/
  77. if (!this.registerForm.type) {
  78. uni.showToast({
  79. title: this.$t('login.displayNamePlaceholder'),
  80. icon: "none",
  81. duration: 2500,
  82. })
  83. return;
  84. }
  85. if (!this.registerForm.displayName) {
  86. uni.showToast({
  87. title: this.$t('login.displayNamePlaceholder'),
  88. icon: "none",
  89. duration: 2500,
  90. })
  91. return;
  92. }
  93. if (!this.registerForm.password) {
  94. uni.showToast({
  95. title: this.$t('login.passwordPlaceholder'),
  96. icon: "none",
  97. duration: 2500,
  98. })
  99. return;
  100. }
  101. if (!this.registerForm.phone) {
  102. uni.showToast({
  103. title: "请输入用户名",
  104. icon: "none",
  105. duration: 2500,
  106. })
  107. return;
  108. }
  109. // if (!phone.test(this.registerForm.phone)) {
  110. // uni.showToast({
  111. // title: this.$t('base.smsCode.phoneErrTip'),
  112. // icon: "none",
  113. // duration: 2500,
  114. // })
  115. // return;
  116. // }
  117. getRegTelCode(this.registerForm.phone).then(res => {
  118. if (res.statusCode === 200) {
  119. if(res.data && res.data.code==1){
  120. uni.showToast({
  121. title: res.data.msg,
  122. icon: "none",
  123. duration: 2500,
  124. })
  125. return;
  126. }
  127. this.isGetCode = true
  128. this.time = 60
  129. this.timer = setInterval(() => {
  130. this.time--
  131. if (this.time == 0) {
  132. clearInterval(this.timer)
  133. }
  134. }, 1000)
  135. }
  136. })
  137. },
  138. //注册并登录
  139. phoneLogin() {
  140. let phone = /^1[3-9]\d{9}$/
  141. if (this.registerForm.displayName == '') {
  142. uni.showToast({
  143. title: this.$t('login.displayNamePlaceholder'),
  144. icon: "none",
  145. duration: 2500,
  146. })
  147. return;
  148. }
  149. if (this.registerForm.password == '') {
  150. uni.showToast({
  151. title: this.$t('login.passwordPlaceholder'),
  152. icon: "none",
  153. duration: 2500,
  154. })
  155. return;
  156. }
  157. if (this.registerForm.phone == '') {
  158. uni.showToast({
  159. title: "请输入用户名",
  160. icon: "none",
  161. duration: 2500,
  162. })
  163. return;
  164. }
  165. // if (!phone.test(this.registerForm.phone)) {
  166. // uni.showToast({
  167. // title: this.$t('base.smsCode.phoneErrTip'),
  168. // icon: "none",
  169. // duration: 2500,
  170. // })
  171. // return;
  172. // }
  173. if (this.registerForm.password!=this.registerForm.password2) {
  174. uni.showToast({
  175. title: '两次密码不一样',
  176. icon: "none",
  177. duration: 2500,
  178. })
  179. return;
  180. }
  181. this.registerForm.username=this.registerForm.phone
  182. uni.showLoading({
  183. title: '注册中',
  184. mask: true
  185. })
  186. register(this.registerForm).then(res => {
  187. console.log(res);
  188. if (res.data == this.registerForm.phone) {
  189. uni.showToast({
  190. title: '注册成功,稍等跳转',
  191. icon: "none",
  192. mask:true,
  193. duration: 2000,
  194. })
  195. setTimeout(() => {
  196. uni.redirectTo({
  197. url: `/pages/login/login?username=${this.registerForm.phone}`
  198. })
  199. }, 2000)
  200. }
  201. uni.hideLoading()
  202. // this.registerForm.phone=''
  203. this.registerForm.password=''
  204. this.registerForm.password2=''
  205. this.registerForm.displayName=''
  206. }).finally(()=>{
  207. uni.hideLoading()
  208. })
  209. },
  210. }
  211. }
  212. </script>
  213. <style>
  214. /* #ifndef APP-NVUE */
  215. view {
  216. display: flex;
  217. box-sizing: border-box;
  218. flex-direction: column;
  219. }
  220. page {
  221. box-sizing: border-box;
  222. padding: 0rpx 48rpx 80rpx;
  223. height: 100%;
  224. }
  225. /* #endif*/
  226. </style>
  227. <style lang="scss" scoped>
  228. @import '../../common/css/login.scss';
  229. .bgc{
  230. position: absolute;
  231. height: 77%;
  232. width: 160%;
  233. bottom: 0;
  234. left: -30%;
  235. z-index: -50;
  236. background-color: #4680F9;
  237. border-top-left-radius: 200px;
  238. border-top-right-radius: 200px;
  239. }
  240. </style>