login.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <template>
  2. <view class="register">
  3. <view class="register_head">
  4. <!-- <text>{{ isPassword ? '密码登录' : '手机快捷登录' }}</text> -->
  5. <!-- <text>{{ isPassword ? '如忘记密码可用已注册手机登录' : '未注册过的手机号将自动创建账号' }}</text> -->
  6. </view>
  7. <view class="register_ul">
  8. <view class="register_li flex">
  9. <view class="register_ipt"><input type="number" maxlength="11" v-model="from.mobile" placeholder="请输入手机号" placeholder-style="color:#999999" /></view>
  10. </view>
  11. <view class="register_li flex">
  12. <view class="register_ipt">
  13. <input type="password" v-model="from.password" maxlength="12" placeholder="请输入密码" v-if="isPassword" placeholder-style="color:#999999" />
  14. <input type="number" maxlength="6" v-model="from.captcha" placeholder="请输入验证码" v-else placeholder-style="color:#999999" />
  15. </view>
  16. <view class="code center" v-if="!isPassword" @click="getCode">{{ codeTxt }}</view>
  17. </view>
  18. </view>
  19. <view class="register_code" @click="isPassword = !isPassword" v-if="isPassword">验证码登录</view>
  20. <button class="register_btn" hover-class="hover-view" @click="submit">登录</button>
  21. <view class="register_footer center">
  22. <text @click="goPassword">{{ isPassword ? '忘记密码' : '密码登录' }}</text>
  23. <text></text>
  24. <text @click="goRegister">注册账号</text>
  25. </view>
  26. <view class="register_fast center" @click="wxLogin">
  27. <text>选择登录方式</text>
  28. <image src="/static/image/publice/weixin@3x.png" mode=""></image>
  29. </view>
  30. <view class="register_consent center">
  31. <image :src="isConsent ? '/static/image/publice/xuanzhong@2x.png' : '/static/image/publice/weixuanzhong1@2x.png'" mode="" @click="isConsent = !isConsent"></image>
  32. <text>登录即表明同意</text>
  33. <text class="blue" @click="goUser">《用户协议》</text>
  34. <text>和</text>
  35. <text class="blue" @click="goPrivacy">《隐私政策》</text>
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. import $DB from '../../http/debounce.js';
  41. export default {
  42. data() {
  43. return {
  44. isPassword: false, //是否密码登录
  45. isConsent: true, //是否同意
  46. flag: true,
  47. codeTxt: '获取验证码',
  48. sending: true,
  49. second: 60,
  50. disabled: false,
  51. from: {
  52. mobile: '', //
  53. captcha: '', //
  54. sharecode: '',
  55. password: '',
  56. is_channel: ''
  57. }
  58. };
  59. },
  60. methods: {
  61. //微信登录
  62. wxLogin() {
  63. this.$api
  64. .getWechatLoginUrl({ redirect: '/h5/#/pages/login/bindPhone?sharecode=' + uni.getStorageSync('sharecode') + '&is_channel=' + uni.getStorageSync('is_channel') })
  65. .then(res => {
  66. if (res.code === 1) {
  67. location.href = res.data.url;
  68. // uni.setStorageSync('token',res.data.token)
  69. // uni.setStorageSync('is_notice',res.data.is_notice)
  70. // uni.removeStorageSync('is_channel')
  71. // uni.switchTab({url:'/pages/tabbar/index'})
  72. }
  73. });
  74. },
  75. //去隐私协议
  76. goPrivacy() {
  77. uni.navigateTo({ url: '/pagesA/pages/privacy' });
  78. },
  79. //去用户协议
  80. goUser() {
  81. uni.navigateTo({ url: '/pagesA/pages/user' });
  82. },
  83. //登录
  84. submit: $DB(function() {
  85. if (!this.from.mobile.match(/^(0|86|17951)?1[3456789]\d{9}$/)) {
  86. uni.showToast({
  87. title: '请输入正确的手机号',
  88. icon: 'none'
  89. });
  90. return;
  91. }
  92. if (!this.from.captcha && !this.isPassword) return uni.showToast({ title: '请输入验证码', icon: 'none' });
  93. if (!this.isConsent) return uni.showToast({ title: '请阅读并同意用户和隐私协议', icon: 'none' });
  94. if (!this.flag) return;
  95. this.flag = false;
  96. this.from.is_channel = uni.getStorageSync('is_channel');
  97. this.$api[this.isPassword ? 'passwordLogin' : 'mobilelogin']({ ...this.from, msg: '登录中' })
  98. .then(res => {
  99. if (res.data.registerurl) {
  100. //存在跳转链接
  101. location.href = res.data.registerurl;
  102. return;
  103. }
  104. if (res.code === 1) {
  105. uni.setStorageSync('token', res.data.token);
  106. uni.setStorageSync('is_notice', res.data.is_notice);
  107. uni.removeStorageSync('is_channel');
  108. uni.switchTab({ url: '/pages/tabbar/index' });
  109. } else {
  110. this.flag = true;
  111. }
  112. })
  113. .catch(res => {
  114. this.flag = true;
  115. });
  116. }),
  117. //验证码登录
  118. codeLogin() {
  119. uni.navigateTo({ url: '/pages/login/phoneLogin' });
  120. },
  121. //注册账号
  122. goRegister() {
  123. uni.navigateTo({ url: '/pages/login/register' });
  124. },
  125. //忘记密码
  126. goPassword() {
  127. if (this.isPassword) {
  128. uni.navigateTo({ url: '/pages/login/forgetPassword' });
  129. } else {
  130. this.isPassword = true;
  131. }
  132. },
  133. //获取验证码
  134. getCode: $DB(function() {
  135. if (!this.sending) return;
  136. if (!this.from.mobile.match(/^(0|86|17951)?1[3456789]\d{9}$/)) {
  137. uni.showToast({
  138. title: '请输入正确的手机号',
  139. icon: 'none'
  140. });
  141. return;
  142. }
  143. this.$api.send({ mobile: this.from.mobile, msg: '发送中', event: 'login' }).then(res => {
  144. this.sending = false;
  145. this.disabled = true;
  146. if (res.code === 1) {
  147. this.timeDown();
  148. }
  149. uni.showToast({
  150. title: res.msg,
  151. icon: 'none'
  152. });
  153. });
  154. }),
  155. timeDown() {
  156. let result = setInterval(() => {
  157. --this.second;
  158. this.codeTxt = this.second + 'S';
  159. if (this.second < 0) {
  160. clearInterval(result);
  161. this.sending = true;
  162. this.disabled = false;
  163. this.second = 60;
  164. this.codeTxt = '获取验证码';
  165. }
  166. }, 1000);
  167. }
  168. },
  169. onLoad() {
  170. if (uni.getStorageSync('sharecode')) {
  171. this.from.sharecode = uni.getStorageSync('sharecode');
  172. }
  173. }
  174. };
  175. </script>
  176. <style>
  177. page {
  178. background: #ffffff;
  179. }
  180. </style>
  181. <style lang="scss">
  182. .register {
  183. min-height: 100vh;
  184. padding: 0 42rpx;
  185. position: relative;
  186. .register_head {
  187. display: flex;
  188. flex-direction: column;
  189. padding: 30rpx 0 40rpx 0;
  190. text {
  191. &:first-child {
  192. font-size: 40rpx;
  193. font-weight: bold;
  194. }
  195. &:last-child {
  196. color: #999999;
  197. font-size: 26rpx;
  198. margin-top: 20rpx;
  199. }
  200. }
  201. }
  202. .register_li {
  203. padding: 40rpx 0;
  204. border-bottom: 2rpx solid #dddddd;
  205. .register_ipt {
  206. flex: 1;
  207. input {
  208. width: 100%;
  209. font-size: 30rpx;
  210. }
  211. }
  212. .code {
  213. width: 150rpx;
  214. color: #4eabfc;
  215. font-size: 28rpx;
  216. }
  217. }
  218. }
  219. .register_btn {
  220. height: 80rpx;
  221. margin-top: 50rpx;
  222. background-image: linear-gradient(45deg, #89f7fe, #7c66ff);
  223. border-radius: 40rpx;
  224. }
  225. .register_code {
  226. color: #4eabfc;
  227. font-size: 28rpx;
  228. text-align: right;
  229. margin: 30rpx 0 0rpx 0;
  230. }
  231. .register_footer {
  232. margin: 50rpx 0 125rpx 0;
  233. text {
  234. color: #4eabfc;
  235. font-size: 26rpx;
  236. &:nth-child(2) {
  237. width: 1px;
  238. height: 25rpx;
  239. margin: 0 35rpx;
  240. background: #4eabfc;
  241. }
  242. }
  243. }
  244. .register_fast {
  245. margin-top: 125rpx;
  246. flex-direction: column;
  247. text {
  248. color: #999999;
  249. margin-bottom: 40rpx;
  250. }
  251. image {
  252. width: 472rpx;
  253. height: 72rpx;
  254. }
  255. }
  256. .register_consent {
  257. margin-top: 50px;
  258. /*
  259. width: 100%;
  260. position: absolute;
  261. left: 50%;
  262. bottom: 70rpx;
  263. transform: translateX(-50%);
  264. */
  265. image {
  266. width: 30rpx;
  267. height: 30rpx;
  268. flex-shrink: 0;
  269. margin-right: 10rpx;
  270. }
  271. .blue {
  272. color: #4eabfc;
  273. }
  274. }
  275. </style>