register.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. <template>
  2. <view class="container">
  3. <view class="container_text">
  4. <image class="banner-img" src="/static/img/img02.png" mode="scaleToFill"></image>
  5. </view>
  6. <view class="login_text">
  7. <view class="login_input flex">
  8. <view class="login_img">
  9. <!-- <image src="/static/icon/img03.png" mode="heightFix"></image> -->
  10. +86
  11. </view>
  12. <view class="login_name"><input class="uni-input" v-model="phone" type="number" focus placeholder="请输入手机号" /></view>
  13. </view>
  14. <view class="login_input flex">
  15. <view class="login_img">
  16. <image src="/static/icon/login_pw2.png" mode="heightFix"></image>
  17. </view>
  18. <view class="login_name flex">
  19. <input class="uni-input width" v-model="code" focus placeholder="请输入验证码" />
  20. <view class="code" @click="verification">{{ countDown == 0 ? '验证码' : countDown }}</view>
  21. </view>
  22. </view>
  23. <view class="login_input flex">
  24. <view class="login_img">
  25. <image src="/static/icon/login_pw.png" mode="heightFix"></image>
  26. </view>
  27. <view class="login_name"><input class="uni-input" type="password" v-model="password" focus
  28. placeholder="请输入密码" /></view>
  29. </view>
  30. <view class="login_input flex">
  31. <view class="login_img">
  32. <image src="/static/icon/login_pw.png" mode="heightFix"></image>
  33. </view>
  34. <view class="login_name"><input class="uni-input" type="password" v-model="repassword" focus
  35. placeholder="请重复输入密码" /></view>
  36. </view>
  37. <view class="login_input flex" v-if="isShowIllegality">
  38. <view class="login_img">
  39. <image src="/static/icon/login_name.png" mode="heightFix"></image>
  40. </view>
  41. <view class="login_name"><input class="uni-input" type="text" v-model="invitation" focus
  42. placeholder="请输入邀请码" /></view>
  43. </view>
  44. <view><button type="green" @click="register" class="uni-button uni-button-green">注册账号</button></view>
  45. <view><button class="uni-button uni-button-green uni-button-green-plain" type="green" plain="true"
  46. hover-class="none" @click="login">返回登录</button></view>
  47. </view>
  48. <codeImage @openCode='getCode' loginType="register" @close='showAlert=false' :phone="phone" ref="alertImage" :show='showAlert'></codeImage>
  49. </view>
  50. </template>
  51. <script>
  52. import {
  53. register,
  54. } from '@/api/login.js';
  55. import {
  56. mapState
  57. } from 'vuex';
  58. import codeImage from '@/components/codeImage.vue';
  59. export default {
  60. data() {
  61. return {
  62. phone: '', //用户
  63. password: '', //密码
  64. repassword: '',
  65. invitation: '', //邀请码
  66. code: '', //验证码
  67. time: '', //保存倒计时对象
  68. countDown: 0 ,//倒计时
  69. showAlert:false,
  70. };
  71. },
  72. computed: {
  73. ...mapState(["isShowIllegality"])
  74. },
  75. components: {
  76. codeImage
  77. },
  78. onLoad(options) {
  79. // 获取扫码邀请人id
  80. this.invitation = uni.getStorageSync('spread') || '';
  81. if (options.spread) {
  82. this.invitation = options.spread;
  83. }
  84. },
  85. watch: {
  86. // 监听倒计时
  87. countDown(i) {
  88. if (i == 0) {
  89. clearInterval(this.time);
  90. }
  91. }
  92. },
  93. methods: {
  94. close() {
  95. console.log('end')
  96. this.showAlert = false;
  97. },
  98. // 发送验证码
  99. getCode() {
  100. const obj = this;
  101. obj.countDown = 60;
  102. obj.time = setInterval(() => {
  103. obj.countDown--;
  104. }, 1000);
  105. //调用验证码接口
  106. },
  107. // 注册
  108. register() {
  109. let obj = this;
  110. if (obj.phone == '') {
  111. obj.$api.msg('请输入电话号码');
  112. return;
  113. }
  114. if (!/(^1[2|3|4|5|6|7|8|9][0-9]{9}$)/.test(this.phone)) {
  115. obj.$api.msg('请输入正确的手机号');
  116. return;
  117. }
  118. if (obj.password == '') {
  119. obj.$api.msg('请输入密码');
  120. return;
  121. }
  122. if (obj.repassword == '') {
  123. obj.$api.msg('请再次输入密码');
  124. return;
  125. }
  126. if (obj.repassword != obj.password) {
  127. obj.$api.msg('两次密码不正确');
  128. return;
  129. }
  130. // if ((obj.invitation = '')) {
  131. // obj.$api.msg('请输入邀请码');
  132. // return;
  133. // }
  134. // if (obj.code == '') {
  135. // obj.$api.msg('请输入验证码');
  136. // return;
  137. // }
  138. register({
  139. account: obj.phone, //账号
  140. captcha: obj.code, //验证码
  141. password: obj.password, //密码
  142. spread: obj.invitation //上级推广人
  143. }).then(function(e) {
  144. uni.showToast({
  145. title: '注册成功',
  146. duration: 2000,
  147. position: 'top'
  148. });
  149. setTimeout(function() {
  150. uni.navigateTo({
  151. url: '/pages/public/login'
  152. });
  153. }, 1000);
  154. });
  155. //调用注册接口,成功跳转登录页
  156. },
  157. //发送验证码
  158. verification() {
  159. let obj = this;
  160. if (this.phone == '') {
  161. this.$api.msg('请输入电话号码');
  162. return;
  163. }
  164. if (this.phone.length < 11) {
  165. this.$api.msg('请输入正确的手机号');
  166. return;
  167. }
  168. // 判断是否在倒计时
  169. if (obj.countDown > 0) {
  170. return false;
  171. } else {
  172. obj.showAlert = true;
  173. obj.$refs.alertImage.getImage()
  174. }
  175. },
  176. login() {
  177. //返回登录
  178. uni.navigateTo({
  179. url: '/pages/public/login'
  180. });
  181. }
  182. }
  183. };
  184. </script>
  185. <style lang="scss">
  186. page {
  187. height: 100%;
  188. }
  189. .container {
  190. width: 100%;
  191. height: 100%;
  192. background-size: 100%;
  193. }
  194. .container_text {
  195. position: relative;
  196. width: 100%;
  197. height: 500rpx;
  198. top: 0rpx;
  199. .banner-img {
  200. width: 100%;
  201. height: 100%;
  202. }
  203. }
  204. .login_text {
  205. margin: -100rpx 0 0;
  206. position: relative;
  207. padding: 100rpx 102rpx;
  208. background-color: #ffffff;
  209. border-top-left-radius: 40rpx;
  210. border-top-right-radius: 40rpx;
  211. .login_input {
  212. border: 1px solid #f0f0f0;
  213. padding: 20rpx;
  214. border-radius: 99rpx;
  215. margin-bottom: 40rpx;
  216. .login_img{
  217. text-align: center;
  218. flex-shrink: 0;
  219. width: 60rpx;
  220. color:#dc262b ;
  221. }
  222. .login_img image {
  223. height: 35rpx;
  224. // width: 29rpx;
  225. // margin-right: 20rpx;
  226. }
  227. .uni-input {
  228. text-align: left;
  229. width: 100%;
  230. font-size: 28rpx !important;
  231. }
  232. .login_name {
  233. color: #333333;
  234. flex-grow: 1;
  235. }
  236. }
  237. .other {
  238. margin-top: 60rpx;
  239. .fenge {
  240. width: 30%;
  241. height: 2rpx;
  242. background-color: #eeeeee;
  243. }
  244. .qita {
  245. font-size: 28rpx;
  246. color: #999999;
  247. }
  248. }
  249. .weixin {
  250. width: 75rpx;
  251. height: 75rpx;
  252. margin: 25rpx auto;
  253. }
  254. .weixin image {
  255. width: 100%;
  256. height: 100%;
  257. }
  258. .weixin_text {
  259. text-align: center;
  260. font-size: 28rpx;
  261. color: #999999;
  262. }
  263. .forget {
  264. font-size: 28rpx;
  265. width: 100%;
  266. text-align: right;
  267. color: #999999;
  268. }
  269. .uni-button-green {
  270. color: #ffffff;
  271. background-color: #db292b;
  272. margin: 40rpx 10rpx;
  273. border-radius: 50rpx;
  274. }
  275. .uni-button-green-plain {
  276. border: 1px solid #db292b;
  277. margin: 40rpx 10rpx;
  278. border-radius: 50rpx;
  279. color: #db292b;
  280. background-color: #ffffff;
  281. }
  282. .uni-button {
  283. height: 85rpx;
  284. line-height: 85rpx;
  285. }
  286. }
  287. .forget {
  288. width: 100rpx;
  289. font-size: 24rpx;
  290. color: #ffffff;
  291. margin: 0px auto;
  292. border-bottom: 1px solid #ffffff;
  293. }
  294. .width {
  295. flex-grow: 1;
  296. }
  297. .code {
  298. color: #db292b;
  299. font-size: 23rpx;
  300. border-left: 1px solid #eeeeee;
  301. width: 150rpx;
  302. flex-shrink: 0;
  303. text-align: center;
  304. }
  305. uni-button {
  306. height: 80rpx !important;
  307. line-height: 80rpx !important;
  308. }
  309. </style>