login.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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="username" 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">
  24. <input class="uni-input" type="password" v-model="passward" focus placeholder="请输入密码" />
  25. </view>
  26. </view>
  27. <view><button type="green" class="uni-button uni-button-green" @click="toLogin">立即登录</button></view>
  28. <view><button type="green" class="uni-button uni-button-green-plain" plain="true" hover-class="none"
  29. @click="$refs.popup.open()">更多</button></view>
  30. </view>
  31. <!-- #ifdef APP-PLUS -->
  32. <loginMethods @onLogin='loginGl'></loginMethods>
  33. <!-- #endif -->
  34. <agreement @checkedChange='changeChecked'></agreement>
  35. <uni-popup ref="popup" type="bottom">
  36. <view class="buttomBox">
  37. <navigator url="/pages/public/phoneLogin">
  38. <view class="item borde-b">
  39. 手机登录
  40. </view>
  41. </navigator>
  42. <navigator url="/pages/public/forget">
  43. <view class="item borde-b">
  44. 忘记密码
  45. </view>
  46. </navigator>
  47. <navigator url="/pages/public/register">
  48. <view class="item">
  49. 注册
  50. </view>
  51. </navigator>
  52. </view>
  53. <view class="buttomBox" @click="close">
  54. <view class="item qx">
  55. 取消
  56. </view>
  57. </view>
  58. </uni-popup>
  59. </view>
  60. </template>
  61. <script>
  62. import loginMethods from "./loginMethods.vue"
  63. import agreement from "./agreement.vue"
  64. import {
  65. mapMutations
  66. } from 'vuex';
  67. import {
  68. login
  69. } from '@/api/login.js';
  70. import {
  71. getUserInfo
  72. } from '@/api/user.js';
  73. export default {
  74. data() {
  75. return {
  76. checked: false, //是否同意条款
  77. username: '',
  78. passward: '',
  79. };
  80. },
  81. onLoad() {
  82. let obj = this;
  83. },
  84. components: {
  85. loginMethods,
  86. agreement
  87. },
  88. methods: {
  89. ...mapMutations('user', ['setUserInfo', 'login','logout']),
  90. // 监听隐私条例
  91. changeChecked(check) {
  92. this.checked = check;
  93. },
  94. loginGl(userinfo){
  95. if(!this.checked){
  96. this.logout();
  97. uni.showModal({
  98. title: '提示',
  99. content: '请先阅读同意《绿津服务》《隐私条例》',
  100. showCancel: false,
  101. });
  102. return;
  103. }
  104. let ur = uni.getStorageSync('present') || '/pages/index/index';
  105. // 用于处理缓存bug
  106. if (ur == 'pages/product/product') {
  107. ur = '/pages/index/index'
  108. }
  109. if (!userinfo.phone) {
  110. uni.showModal({
  111. title: '提示',
  112. content: '请先绑定手机号',
  113. showCancel: false,
  114. success: res => {
  115. if (res.confirm) {
  116. uni.navigateTo({
  117. url: '/pages/set/phone',
  118. });
  119. }
  120. },
  121. });
  122. } else {
  123. uni.switchTab({
  124. url: ur,
  125. fail(e) {
  126. uni.navigateTo({
  127. url: ur,
  128. fail(e) {
  129. uni.navigateTo({
  130. url: '/pages/index/index',
  131. });
  132. }
  133. });
  134. }
  135. });
  136. }
  137. },
  138. //登录
  139. async toLogin() {
  140. let obj = this;
  141. if (obj.username == '') {
  142. uni.showToast({
  143. title: "请输入手机号",
  144. icon:'none'
  145. });
  146. return;
  147. }
  148. if (obj.passward == '') {
  149. uni.showToast({
  150. title: "请输入密码",
  151. icon:'none'
  152. });
  153. return;
  154. }
  155. if(!this.checked){
  156. uni.showModal({
  157. title: '提示',
  158. content: '请先阅读同意《绿津服务》《隐私条例》',
  159. showCancel: false,
  160. });
  161. return;
  162. }
  163. obj.logining = true;
  164. login({
  165. account: obj.username,
  166. password: obj.passward
  167. })
  168. .then(function(e) {
  169. uni.setStorageSync('token', e.data.token);
  170. obj.$store.commit('hasLogin', true);
  171. getUserInfo({}).then(e => {
  172. obj.login();
  173. // 保存返回用户数据
  174. obj.setUserInfo(e.data);
  175. let ur = uni.getStorageSync('present') || '/pages/index/index';
  176. //成功跳转首页
  177. uni.reLaunch({
  178. url: ur,
  179. fail(e) {
  180. uni.switchTab({
  181. url: '/pages/index/index',
  182. });
  183. }
  184. })
  185. });
  186. })
  187. .catch(function(e) {
  188. console.log(e);
  189. });
  190. },
  191. //跳转注册页
  192. register() {
  193. uni.navigateTo({
  194. url: `/pages/public/register`
  195. });
  196. },
  197. // 后退
  198. navBack() {
  199. uni.navigateBack();
  200. },
  201. // 关闭更多弹窗
  202. close() {
  203. this.$refs.popup.close();
  204. }
  205. }
  206. };
  207. </script>
  208. <style lang="scss">
  209. page {
  210. height: 100%;
  211. background-color: #FFFFFF;
  212. padding-top: 44px;
  213. }
  214. .container {
  215. width: 100%;
  216. height: 100%;
  217. background-size: 100%;
  218. padding-top: 50rpx;
  219. }
  220. .container_text {
  221. text-align: center;
  222. .logName {
  223. font-weight: bold;
  224. font-size: 36rpx;
  225. margin: 30rpx 0 80rpx;
  226. }
  227. .banner-img {
  228. width: 170rpx;
  229. height: 170rpx;
  230. margin: 0 auto;
  231. border-radius: 20rpx;
  232. }
  233. }
  234. .login_text {
  235. margin: auto 50rpx;
  236. position: relative;
  237. background-color: #ffffff;
  238. border-radius: 20rpx;
  239. .login_input {
  240. border-bottom: 1px solid #f0f0f0;
  241. margin-bottom: 30rpx;
  242. padding: 30rpx 0;
  243. line-height: 1;
  244. .login_img {
  245. height: 35rpx;
  246. width: 70rpx;
  247. flex-shrink: 0;
  248. font-size: 30rpx;
  249. margin-right: 20rpx;
  250. color: $font-base;
  251. }
  252. .uni-input {
  253. text-align: left;
  254. width: 100%;
  255. font-size: 28rpx !important;
  256. }
  257. .login_name {
  258. color: #333333;
  259. flex-grow: 1;
  260. }
  261. }
  262. .forget {
  263. font-size: 28rpx;
  264. width: 100%;
  265. text-align: right;
  266. color: #999999;
  267. }
  268. .uni-button-green {
  269. color: #ffffff;
  270. background-color: #5dbc7c;
  271. margin: 40rpx 10rpx;
  272. border-radius: 50rpx;
  273. box-shadow: 0px 8px 10px 0px rgba(166, 203, 184, 0.75);
  274. }
  275. .uni-button-green-plain {
  276. margin: 40rpx 10rpx;
  277. border-radius: 50rpx;
  278. color: $font-base;
  279. background-color: $page-color-base;
  280. border: none;
  281. }
  282. .uni-button {
  283. height: 80rpx;
  284. line-height: 80rpx;
  285. font-size: 28rpx;
  286. width: 100%;
  287. }
  288. }
  289. .buttomBox {
  290. border-radius: 20rpx;
  291. margin: 0 $page-row-spacing;
  292. margin-bottom: 30rpx;
  293. color: $color-green;
  294. background-color: #FFFFFF;
  295. overflow: hidden;
  296. .item {
  297. line-height: 100rpx;
  298. height: 100rpx;
  299. text-align: center;
  300. font-size: 32rpx;
  301. &.qx {
  302. font-weight: bold;
  303. }
  304. }
  305. .border_b {
  306. border-bottom: 1px solid $page-color-light;
  307. }
  308. }
  309. </style>