phoneLogin.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <template>
  2. <view class="container">
  3. <view class="container_text">
  4. <view>
  5. <image class="banner-img" src="../../static/image/logo.png" mode="scaleToFill"></image>
  6. </view>
  7. <view class="logName">
  8. 母婴界严选
  9. </view>
  10. </view>
  11. <view class="login_text">
  12. <view class="login_input flex">
  13. <view class="login_img">
  14. +86
  15. </view>
  16. <view class="login_name"><input class="uni-input" v-model="phone" focus placeholder="请输入手机号" />
  17. </view>
  18. </view>
  19. <view class="login_input flex">
  20. <view class="login_img">
  21. 验证码
  22. </view>
  23. <view class="login_name flex">
  24. <input class="uni-input width" v-model="code" focus placeholder="请输入验证码" />
  25. <view class="code" @click="verification">{{ countDown == 0 ? '验证码' : countDown }}</view>
  26. </view>
  27. </view>
  28. <view><button type="green" class="uni-button uni-button-green" @click="toLogin">立即登录</button></view>
  29. <view><button type="green" class="uni-button uni-button-green-plain" plain="true" hover-class="none"
  30. @click="$refs.popup.open()">更多</button></view>
  31. </view>
  32. <!-- #ifdef APP-PLUS -->
  33. <!-- <loginMethods @onLogin='loginGl'></loginMethods> -->
  34. <!-- #endif -->
  35. <agreement @checkedChange='changeChecked'></agreement>
  36. <uni-popup ref="popup" type="bottom">
  37. <view class="buttomBox">
  38. <navigator url="/pages/public/login">
  39. <view class="item borde-b">
  40. 账号登录
  41. </view>
  42. </navigator>
  43. <navigator url="/pages/public/forget">
  44. <view class="item borde-b">
  45. 忘记密码
  46. </view>
  47. </navigator>
  48. <navigator url="/pages/public/register">
  49. <view class="item">
  50. 注册
  51. </view>
  52. </navigator>
  53. </view>
  54. <view class="buttomBox" @click="close">
  55. <view class="item qx">
  56. 取消
  57. </view>
  58. </view>
  59. </uni-popup>
  60. </view>
  61. </template>
  62. <script>
  63. import {
  64. mapMutations
  65. } from 'vuex';
  66. import {
  67. verify,
  68. loginMobile,
  69. getUserInfo
  70. } from '@/api/login.js';
  71. // #ifdef APP-PLUS
  72. // applelogin接口需要开发编写,基础项目中可能没有
  73. import {
  74. applelogin
  75. } from '@/api/set.js';
  76. // loginWx接口需要开发编写,基础项目中可能没有
  77. import {
  78. loginWx
  79. } from '@/api/login.js';
  80. // #endif
  81. // #ifdef H5
  82. import {
  83. loginWinxin
  84. } from '@/utils/wxAuthorized';
  85. // #endif
  86. import loginMethods from "./loginMethods.vue"
  87. import agreement from "./agreement.vue"
  88. export default {
  89. data() {
  90. return {
  91. checked: false, //是否同意条款
  92. phone: '',
  93. code: '',
  94. time: '', //保存倒计时对象
  95. countDown: 0 //倒计时
  96. };
  97. },
  98. components: {
  99. loginMethods,
  100. agreement
  101. },
  102. watch: {
  103. // 监听倒计时
  104. countDown(i) {
  105. if (i == 0) {
  106. clearInterval(this.time);
  107. }
  108. }
  109. },
  110. onLoad() {
  111. },
  112. methods: {
  113. ...mapMutations('user', ['setUserInfo', 'login']),
  114. changeChecked(check) {
  115. this.checked = check;
  116. },
  117. //登录
  118. async toLogin() {
  119. let obj = this;
  120. if (obj.phone == '') {
  121. obj.$api.msg('请输入电话号码');
  122. return;
  123. }
  124. if (obj.phone.length!=11) {
  125. obj.$api.msg('请输入正确的手机号');
  126. return;
  127. }
  128. if (obj.code == '') {
  129. obj.$api.msg('请输入验证码');
  130. return;
  131. }
  132. if (!obj.checked) {
  133. uni.showModal({
  134. title: '提示',
  135. content: '请先阅读同意《母婴界严选服务》《隐私条例》',
  136. showCancel: false,
  137. });
  138. return;
  139. }
  140. loginMobile({
  141. phone: obj.phone, //账号
  142. captcha: obj.code
  143. }).then(function(e) {
  144. uni.setStorageSync('token', e.data.token);
  145. getUserInfo({}).then(e => {
  146. obj.login();
  147. // 保存返回用户数据
  148. obj.setUserInfo(e.data);
  149. //成功跳转首页
  150. uni.switchTab({
  151. url: '/pages/index/index'
  152. });
  153. });
  154. }).catch((e) => {
  155. console.log(e);
  156. });
  157. },
  158. //发送验证码
  159. verification() {
  160. let obj = this;
  161. if (this.phone == '') {
  162. this.$api.msg('请输入电话号码');
  163. return;
  164. }
  165. if (this.phone.length < 11) {
  166. this.$api.msg('请输入正确的手机号');
  167. return;
  168. }
  169. // 判断是否在倒计时
  170. if (obj.countDown > 0) {
  171. return false;
  172. } else {
  173. obj.countDown = 60;
  174. obj.time = setInterval(() => {
  175. obj.countDown--;
  176. }, 1000);
  177. //调用验证码接口
  178. verify({
  179. phone: obj.phone,
  180. type: 'login'
  181. })
  182. .then(({
  183. data
  184. }) => {})
  185. .catch(err => {
  186. console.log(err);
  187. });
  188. }
  189. },
  190. // 后退
  191. navBack() {
  192. uni.navigateBack();
  193. },
  194. // 关闭更多弹窗
  195. close() {
  196. this.$refs.popup.close();
  197. }
  198. }
  199. };
  200. </script>
  201. <style lang="scss">
  202. page {
  203. height: 100%;
  204. background-color: #FFFFFF;
  205. padding-top: 44px;
  206. }
  207. .container {
  208. width: 100%;
  209. height: 100%;
  210. background-size: 100%;
  211. padding-top: 50rpx;
  212. }
  213. .container_text {
  214. text-align: center;
  215. .logName {
  216. font-weight: bold;
  217. font-size: 36rpx;
  218. margin: 30rpx 0 80rpx;
  219. }
  220. .banner-img {
  221. width: 170rpx;
  222. height: 170rpx;
  223. margin: 0 auto;
  224. border-radius: 20rpx;
  225. }
  226. }
  227. .login_text {
  228. margin: auto 50rpx;
  229. position: relative;
  230. background-color: #ffffff;
  231. border-radius: 20rpx;
  232. .login_input {
  233. border-bottom: 1px solid #f0f0f0;
  234. margin-bottom: 30rpx;
  235. padding: 30rpx 0;
  236. .login_img {
  237. height: 35rpx;
  238. width: 100rpx;
  239. flex-shrink: 0;
  240. font-size: 30rpx;
  241. text-align: center;
  242. margin-right: 20rpx;
  243. color: $font-base;
  244. }
  245. .uni-input {
  246. text-align: left;
  247. width: 100%;
  248. font-size: 28rpx !important;
  249. }
  250. .login_name {
  251. color: #333333;
  252. flex-grow: 1;
  253. .code {
  254. color: #5dbc7c;
  255. font-size: 23rpx;
  256. border-left: 1px solid #eeeeee;
  257. width: 150rpx;
  258. flex-shrink: 0;
  259. text-align: center;
  260. }
  261. }
  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: #5dbc7c;
  272. margin: 40rpx 10rpx;
  273. border-radius: 50rpx;
  274. box-shadow: 0px 8px 10px 0px rgba(166, 203, 184, 0.75);
  275. }
  276. .uni-button-green-plain {
  277. margin: 40rpx 10rpx;
  278. border-radius: 50rpx;
  279. color: $font-base;
  280. background-color: $page-color-base;
  281. border: none;
  282. }
  283. .uni-button {
  284. height: 80rpx;
  285. line-height: 80rpx;
  286. font-size: 28rpx;
  287. width: 100%;
  288. }
  289. }
  290. .buttomBox {
  291. border-radius: 20rpx;
  292. margin: 0 $page-row-spacing;
  293. margin-bottom: 30rpx;
  294. color: $color-green;
  295. background-color: #FFFFFF;
  296. overflow: hidden;
  297. .item {
  298. line-height: 100rpx;
  299. height: 100rpx;
  300. text-align: center;
  301. font-size: 32rpx;
  302. &.qx {
  303. font-weight: bold;
  304. }
  305. }
  306. .border_b {
  307. border-bottom: 1px solid $page-color-light;
  308. }
  309. }
  310. </style>