sign.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <template>
  2. <view class="bd-sign">
  3. <view class="bd-item dir-left-nowrap cross-center">
  4. <image src="./image/phone.png" class="bd-label box-grow-0"></image>
  5. <input class="bd-input box-grow-1" v-model="mobile" placeholder="请输入手机号" type="text">
  6. </view>
  7. <template v-if="!isPassword">
  8. <view class="bd-item dir-left-nowrap cross-center">
  9. <image src="./image/image.png" class="bd-label box-grow-0"></image>
  10. <input class="bd-input box-grow-1" v-model="pic_captcha" placeholder="请输入图形验证码" type="text">
  11. <image :src="imageUrl" @click="getImageUrl" class="bd-image box-grow-0"></image>
  12. </view>
  13. <view class="bd-item dir-left-nowrap cross-center">
  14. <image src="./image/message.png" class="bd-label box-grow-0"></image>
  15. <input class="bd-input box-grow-1" v-model="captcha" placeholder="请输入短消息验证码" type="text">
  16. <view v-if="!isSend" class="bd-btn box-grow-0" @click="getVerCode">获取验证码</view>
  17. <view v-else class="bd-btn box-grow-0 bd-send" >重新发送{{ timeNum }}S</view>
  18. </view>
  19. </template>
  20. <template v-else>
  21. <view class="bd-item dir-left-nowrap cross-center">
  22. <image src="./image/password.png" class="bd-label box-grow-0"></image>
  23. <input class="bd-input box-grow-1" v-model="password" placeholder="请输入密码" type="text">
  24. </view>
  25. </template>
  26. <view class="bd-bottom" :class="agree ? 'bd-yes-agree' : 'bd-no-agree'" @click="sign">登入</view>
  27. <view class="bd-agree-group dir-left-nowrap cross-center main-between" >
  28. <text class="bd-color" v-if="!isPassword" @click="isPassword = true">密码登入</text>
  29. <text class="bd-color" v-else @click="isPassword = false">验证码登入</text>
  30. <text class="bd-color" @click="router('/pages/registered/index')">手机号快速注册</text>
  31. </view>
  32. <view class="bd-forget bd-color" v-if="isPassword" @click="routerGo('/pages/registered/forget')">忘记密码?</view>
  33. </view>
  34. </template>
  35. <script>
  36. export default {
  37. name: "sign",
  38. data() {
  39. return {
  40. pic_captcha: '',
  41. mobile: '',
  42. captcha: '',
  43. validate_code_id: '',
  44. type: '',
  45. password: '',
  46. imageUrl: '',
  47. isSend: false,
  48. timeNum: 60,
  49. timeIng: 0,
  50. isPassword: false
  51. }
  52. },
  53. onLoad() { this.$commonLoad.onload();
  54. this.getImageUrl();
  55. // #ifdef H5
  56. this.$storage.setStorageSync('platform', 'mobile');
  57. // #endif
  58. console.log(bdImage);
  59. },
  60. computed: {
  61. agree: function() {
  62. if ((this.mobile && this.pic_captcha) || (this.mobile && this.password)) {
  63. return true;
  64. } else {
  65. return false;
  66. }
  67. }
  68. },
  69. methods: {
  70. getVerCode: function() {
  71. this.timeNum = 60;
  72. this.$request({
  73. url: this.$api.registered.sms,
  74. method: "post",
  75. data: {
  76. mobile: this.mobile,
  77. pic_captcha: this.pic_captcha
  78. }
  79. }).then(response => {
  80. if (response.code === 0) {
  81. this.isSend = true;
  82. this.validate_code_id = response.data.validate_code_id;
  83. this.change();
  84. } else {
  85. this.getImageUrl();
  86. uni.showToast({
  87. icon: 'none',
  88. title: response.msg
  89. })
  90. }
  91. });
  92. },
  93. getImageUrl: function() {
  94. this.$request({
  95. url: this.$api.registered.captcha,
  96. data: {
  97. refresh: true
  98. }
  99. }).then(response => {
  100. this.imageUrl = response.url;
  101. });
  102. },
  103. change: function () {
  104. clearInterval(this.timeIng);
  105. this.timeIng = setInterval(() => {
  106. this.timeNum--;
  107. if (this.timeNum === 0) {
  108. clearInterval(this.timeIng);
  109. this.isSend = false;
  110. }
  111. }, 1000);
  112. },
  113. sign: function() {
  114. if (!this.agree) return;
  115. let data = {
  116. type: this.type,
  117. mobile: this.mobile,
  118. validate_code_id: this.validate_code_id,
  119. captcha: this.captcha,
  120. password: this.password
  121. }
  122. if (this.isPassword) {
  123. delete data.validate_code_id;
  124. delete data.captcha;
  125. data.type = 'username';
  126. } else {
  127. data.type = 'mobile';
  128. delete data.password;
  129. }
  130. this.$request({
  131. url: this.$api.registered.login,
  132. method: "post",
  133. data: data
  134. }).then(response => {
  135. if (response.code === 0) {
  136. this.$storage.setStorageSync('_USER_ACCESS_TOKEN', response.data.access_token);
  137. uni.redirectTo({
  138. url: '/pages/user-center/user-center'
  139. });
  140. } else {
  141. this.getImageUrl();
  142. uni.showToast({
  143. icon: 'none',
  144. title: response.msg
  145. });
  146. }
  147. });
  148. },
  149. router(url) {
  150. uni.redirectTo({
  151. url
  152. });
  153. },
  154. routerGo(url) {
  155. uni.navigateTo({
  156. url
  157. });
  158. // uni.
  159. }
  160. },
  161. beforeDestroy() {
  162. clearInterval(this.timeIng);
  163. }
  164. }
  165. </script>
  166. <style scoped>
  167. .bd-sign {
  168. min-height: 100vh;
  169. background-color: #ffffff;
  170. padding: 46upx 42upx;
  171. }
  172. .bd-item {
  173. height: 100upx;
  174. border-bottom: 2upx solid #f4f4f4;
  175. }
  176. .bd-label {
  177. width: 36upx;
  178. height: 36upx;
  179. margin: 0 25upx 0 2upx;
  180. }
  181. .bd-btn {
  182. border-left: 1upx solid #f4f4f4;
  183. width: 226upx;
  184. height: 53upx;
  185. line-height: 53upx;
  186. font-size: 32upx;
  187. color: #ff4544;
  188. text-align: center;
  189. }
  190. .bd-image {
  191. width: 160upx;
  192. height: 67upx;
  193. }
  194. .bd-input {
  195. height: 36upx;
  196. }
  197. .bd-bottom {
  198. height: 88upx;
  199. line-height: 88upx;
  200. color: #ffffff;
  201. font-size: 36upx;
  202. border-radius: 44upx;
  203. margin-top: 68upx;
  204. text-align: center;
  205. }
  206. .bd-yes-agree {
  207. background: rgba(255, 69, 68, 1);
  208. }
  209. .bd-no-agree {
  210. background: rgba(255, 69, 68, 0.5);
  211. }
  212. .bd-agree-group {
  213. margin-top: 42upx;
  214. }
  215. .bd-color {
  216. font-size: 28upx;
  217. color: #ff4544;
  218. }
  219. /deep/ .uni-radio-input {
  220. width: 35upx;
  221. height: 35upx;
  222. }
  223. .bd-send {
  224. color: rgba(255, 69, 68, 0.5);
  225. }
  226. .bd-forget {
  227. position: fixed;
  228. bottom: 50upx;
  229. left: 50%;
  230. transform: translateX(-50%);
  231. }
  232. </style>