phoneLogin.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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. uni.showToast({
  122. title: "请输入电话号码",
  123. icon:'none'
  124. });
  125. return;
  126. }
  127. if (obj.phone.length!=11) {
  128. uni.showToast({
  129. title: "请输入正确的手机号",
  130. icon:'none'
  131. });
  132. return;
  133. }
  134. if (obj.code == '') {
  135. uni.showToast({
  136. title: "请输入验证码",
  137. icon:'none'
  138. });
  139. return;
  140. }
  141. if (!obj.checked) {
  142. uni.showModal({
  143. title: '提示',
  144. content: '请先阅读同意《绿津服务》《隐私条例》',
  145. showCancel: false,
  146. });
  147. return;
  148. }
  149. loginMobile({
  150. phone: obj.phone, //账号
  151. captcha: obj.code
  152. }).then(function(e) {
  153. uni.setStorageSync('token', e.data.token);
  154. getUserInfo({}).then(e => {
  155. obj.login();
  156. // 保存返回用户数据
  157. obj.setUserInfo(e.data);
  158. //成功跳转首页
  159. uni.switchTab({
  160. url: '/pages/index/index'
  161. });
  162. });
  163. }).catch((e) => {
  164. console.log(e);
  165. });
  166. },
  167. //发送验证码
  168. verification() {
  169. let obj = this;
  170. if (this.phone == '') {
  171. uni.showToast({
  172. title: "请输入电话号码",
  173. icon:'none'
  174. });
  175. return;
  176. }
  177. if (this.phone.length < 11) {
  178. uni.showToast({
  179. title: "请输入正确的手机号",
  180. icon:'none'
  181. });
  182. return;
  183. }
  184. // 判断是否在倒计时
  185. if (obj.countDown > 0) {
  186. return false;
  187. } else {
  188. obj.countDown = 60;
  189. obj.time = setInterval(() => {
  190. obj.countDown--;
  191. }, 1000);
  192. //调用验证码接口
  193. verify({
  194. phone: obj.phone,
  195. type: 'login'
  196. })
  197. .then(({
  198. data
  199. }) => {})
  200. .catch(err => {
  201. console.log(err);
  202. });
  203. }
  204. },
  205. // 后退
  206. navBack() {
  207. uni.navigateBack();
  208. },
  209. // 关闭更多弹窗
  210. close() {
  211. this.$refs.popup.close();
  212. }
  213. }
  214. };
  215. </script>
  216. <style lang="scss">
  217. page {
  218. height: 100%;
  219. background-color: #FFFFFF;
  220. padding-top: 44px;
  221. }
  222. .container {
  223. width: 100%;
  224. height: 100%;
  225. background-size: 100%;
  226. padding-top: 50rpx;
  227. }
  228. .container_text {
  229. text-align: center;
  230. .logName {
  231. font-weight: bold;
  232. font-size: 36rpx;
  233. margin: 30rpx 0 80rpx;
  234. }
  235. .banner-img {
  236. width: 170rpx;
  237. height: 170rpx;
  238. margin: 0 auto;
  239. border-radius: 20rpx;
  240. }
  241. }
  242. .login_text {
  243. margin: auto 50rpx;
  244. position: relative;
  245. background-color: #ffffff;
  246. border-radius: 20rpx;
  247. .login_input {
  248. border-bottom: 1px solid #f0f0f0;
  249. margin-bottom: 30rpx;
  250. padding: 30rpx 0;
  251. .login_img {
  252. height: 35rpx;
  253. width: 100rpx;
  254. flex-shrink: 0;
  255. font-size: 30rpx;
  256. text-align: center;
  257. margin-right: 20rpx;
  258. color: $font-base;
  259. }
  260. .uni-input {
  261. text-align: left;
  262. width: 100%;
  263. font-size: 28rpx !important;
  264. }
  265. .login_name {
  266. color: #333333;
  267. flex-grow: 1;
  268. .code {
  269. color: #5dbc7c;
  270. font-size: 23rpx;
  271. border-left: 1px solid #eeeeee;
  272. width: 150rpx;
  273. flex-shrink: 0;
  274. text-align: center;
  275. }
  276. }
  277. }
  278. .forget {
  279. font-size: 28rpx;
  280. width: 100%;
  281. text-align: right;
  282. color: #999999;
  283. }
  284. .uni-button-green {
  285. color: #ffffff;
  286. background-color: #5dbc7c;
  287. margin: 40rpx 10rpx;
  288. border-radius: 50rpx;
  289. box-shadow: 0px 8px 10px 0px rgba(166, 203, 184, 0.75);
  290. }
  291. .uni-button-green-plain {
  292. margin: 40rpx 10rpx;
  293. border-radius: 50rpx;
  294. color: $font-base;
  295. background-color: $page-color-base;
  296. border: none;
  297. }
  298. .uni-button {
  299. height: 80rpx;
  300. line-height: 80rpx;
  301. font-size: 28rpx;
  302. width: 100%;
  303. }
  304. }
  305. .buttomBox {
  306. border-radius: 20rpx;
  307. margin: 0 $page-row-spacing;
  308. margin-bottom: 30rpx;
  309. color: $color-green;
  310. background-color: #FFFFFF;
  311. overflow: hidden;
  312. .item {
  313. line-height: 100rpx;
  314. height: 100rpx;
  315. text-align: center;
  316. font-size: 32rpx;
  317. &.qx {
  318. font-weight: bold;
  319. }
  320. }
  321. .border_b {
  322. border-bottom: 1px solid $page-color-light;
  323. }
  324. }
  325. </style>