register.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <template>
  2. <view class="container">
  3. <view class="back-btn yticon icon-zuojiantou-up" @click="navBack"></view>
  4. <!-- 设置白色背景防止软键盘把下部绝对定位元素顶上来盖住输入框等 -->
  5. <view class="wrapper">
  6. <view class="left-top-sign">{{desc}}</view>
  7. <view class="welcome">
  8. {{desc}}
  9. </view>
  10. <view class="input-content">
  11. <view class="input-item" v-if="event == 'register'">
  12. <text class="tit">用户名</text>
  13. <input
  14. type="text"
  15. :value="username"
  16. placeholder="请输入用户名"
  17. data-key="username"
  18. @input="inputChange"
  19. />
  20. </view>
  21. <view class="input-item">
  22. <text class="tit">手机号码</text>
  23. <input
  24. type="number"
  25. :value="mobile"
  26. placeholder="请输入手机号码"
  27. data-key="mobile"
  28. @input="inputChange"
  29. />
  30. </view>
  31. <view class="input-item">
  32. <text class="tit">密码</text>
  33. <input
  34. type="text"
  35. value=""
  36. placeholder="6-18位不含特殊字符的数字、字母组合"
  37. placeholder-class="input-empty"
  38. maxlength="20"
  39. password
  40. data-key="password"
  41. @confirm="toLogin"
  42. @input="inputChange"
  43. />
  44. </view>
  45. <view class="input-item">
  46. <text class="tit">验证码</text>
  47. <input
  48. type="text"
  49. :value="captcha"
  50. placeholder="请输入验证码"
  51. data-key="captcha"
  52. @input="inputChange"
  53. />
  54. <button class="get_captcha" @click="getCaptcha">{{get_captcha}}</button>
  55. </view>
  56. </view>
  57. <button class="confirm-btn" @click="toLogin" :disabled="logining">
  58. {{status}}
  59. </button>
  60. <view class="forget-section">
  61. </view>
  62. </view>
  63. </view>
  64. </template>
  65. <script>
  66. import {
  67. mapMutations
  68. } from 'vuex';
  69. export default{
  70. data(){
  71. return {
  72. username: '',
  73. mobile: '',
  74. password: '',
  75. captcha:'',
  76. logining: false,
  77. status: '',
  78. desc: '',
  79. get_captcha: '获取验证码',
  80. event: ''
  81. }
  82. },
  83. onLoad(options){
  84. if(options.event == 'register'){
  85. this.status = '立即注册';
  86. this.desc = '注册账号'
  87. }else{
  88. this.status = '确认修改';
  89. this.desc = '修改密码'
  90. }
  91. this.event = options.event;
  92. },
  93. methods: {
  94. ...mapMutations(['login']),
  95. async getCaptcha(){
  96. let that = this;
  97. let num = 60;
  98. if (this.mobile == '') {
  99. this.$api.msg('请输入手机号码');
  100. return;
  101. }
  102. let data = await this.$api.request('/sms/send', 'POST', {
  103. mobile: this.mobile,
  104. event: this.event
  105. });
  106. if (data) {
  107. that.get_captcha = num + ' S';
  108. let intervalId = setInterval(function(){
  109. num--;
  110. that.get_captcha = num + ' S';
  111. if (num == 0) {
  112. that.get_captcha = '获取验证码'
  113. clearInterval(intervalId);
  114. }
  115. }, 1000);
  116. }
  117. },
  118. navBack(){
  119. uni.navigateBack();
  120. },
  121. inputChange (e) {
  122. const key = e.currentTarget.dataset.key;
  123. this[key] = e.detail.value;
  124. },
  125. async toLogin(){
  126. this.logining = true; // 按钮锁
  127. let url = this.event == 'register' ? '/user/register' : '/user/resetpwd';
  128. let data = await this.$api.request(url, 'POST', {
  129. mobile: this.mobile,
  130. password: this.password,
  131. username: this.username,
  132. captcha: this.captcha,
  133. event: this.event
  134. });
  135. if (data) {
  136. this.login(data.userinfo);
  137. setTimeout(function(){
  138. uni.navigateBack();
  139. }, 3000);
  140. } else {
  141. this.logining = false;
  142. }
  143. },
  144. forget(){
  145. uni.navigateTo({
  146. url:'./forget'
  147. })
  148. },
  149. register(){
  150. uni.navigateTo({
  151. url:'./forget'
  152. })
  153. }
  154. },
  155. }
  156. </script>
  157. <style lang='scss'>
  158. page{
  159. background: #fff;
  160. }
  161. .container{
  162. padding-top: 80rpx;
  163. position:relative;
  164. width: 100vw;
  165. height: 100vh;
  166. overflow: hidden;
  167. background: #fff;
  168. }
  169. .wrapper{
  170. position:relative;
  171. z-index: 90;
  172. background: #fff;
  173. padding-bottom: 40upx;
  174. }
  175. .back-btn{
  176. position:absolute;
  177. left: 40upx;
  178. z-index: 9999;
  179. padding-top: var(--status-bar-height);
  180. top: 40upx;
  181. font-size: 40upx;
  182. color: $font-color-dark;
  183. }
  184. .left-top-sign{
  185. font-size: 120upx;
  186. color: $page-color-base;
  187. position:relative;
  188. left: -16upx;
  189. }
  190. .welcome{
  191. position:relative;
  192. left: 50upx;
  193. top: -90upx;
  194. font-size: 46upx;
  195. color: #555;
  196. text-shadow: 1px 0px 1px rgba(0,0,0,.3);
  197. }
  198. .input-content{
  199. padding: 0 60upx;
  200. }
  201. .input-item{
  202. display:flex;
  203. flex-direction: column;
  204. align-items:flex-start;
  205. justify-content: center;
  206. padding: 0 30upx;
  207. background:$page-color-light;
  208. height: 120upx;
  209. border-radius: 4px;
  210. margin-bottom: 50upx;
  211. position: relative;
  212. &:last-child{
  213. margin-bottom: 0;
  214. }
  215. .tit{
  216. height: 50upx;
  217. line-height: 56upx;
  218. font-size: $font-sm+2upx;
  219. color: $font-color-base;
  220. }
  221. input{
  222. height: 60upx;
  223. font-size: $font-base + 2upx;
  224. color: $font-color-dark;
  225. width: 100%;
  226. }
  227. .get_captcha {
  228. position: absolute;
  229. right: 0;
  230. display: block;
  231. width: 40%;
  232. background: $uni-color-primary;
  233. color: #fff;
  234. text-align: center;
  235. line-height: 76upx;
  236. border-radius: 50upx;
  237. z-index: 100;
  238. }
  239. }
  240. .confirm-btn{
  241. width: 630upx;
  242. height: 76upx;
  243. line-height: 76upx;
  244. border-radius: 50px;
  245. margin-top: 70upx;
  246. background: $uni-color-primary;
  247. color: #fff;
  248. font-size: $font-lg;
  249. &:after{
  250. border-radius: 100px;
  251. }
  252. }
  253. .forget-section{
  254. font-size: $font-sm+10upx;
  255. color: $font-color-spec;
  256. text-align: center;
  257. margin-top: 100upx;
  258. label{
  259. margin: 10upx 60upx;
  260. }
  261. }
  262. .register-section{
  263. position:absolute;
  264. left: 0;
  265. bottom: 50upx;
  266. width: 100%;
  267. font-size: $font-sm+2upx;
  268. color: $font-color-base;
  269. text-align: center;
  270. text{
  271. color: $font-color-spec;
  272. margin-left: 10upx;
  273. }
  274. }
  275. </style>