login.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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. obj.$api.msg('请输入手机号');
  143. return;
  144. }
  145. if (obj.passward == '') {
  146. obj.$api.msg('请输入密码');
  147. return;
  148. }
  149. if(!this.checked){
  150. uni.showModal({
  151. title: '提示',
  152. content: '请先阅读同意《母婴界严选服务》《隐私条例》',
  153. showCancel: false,
  154. });
  155. return;
  156. }
  157. obj.logining = true;
  158. login({
  159. account: obj.username,
  160. password: obj.passward
  161. })
  162. .then(function(e) {
  163. uni.setStorageSync('token', e.data.token);
  164. obj.$store.commit('hasLogin', true);
  165. getUserInfo({}).then(e => {
  166. obj.login();
  167. // 保存返回用户数据
  168. obj.setUserInfo(e.data);
  169. let ur = uni.getStorageSync('present') || '/pages/index/index';
  170. //成功跳转首页
  171. uni.reLaunch({
  172. url: ur,
  173. fail(e) {
  174. uni.switchTab({
  175. url: '/pages/index/index',
  176. });
  177. }
  178. })
  179. });
  180. })
  181. .catch(function(e) {
  182. console.log(e);
  183. });
  184. },
  185. //跳转注册页
  186. register() {
  187. uni.navigateTo({
  188. url: `/pages/public/register`
  189. });
  190. },
  191. // 后退
  192. navBack() {
  193. uni.navigateBack();
  194. },
  195. // 关闭更多弹窗
  196. close() {
  197. this.$refs.popup.close();
  198. }
  199. }
  200. };
  201. </script>
  202. <style lang="scss">
  203. page {
  204. height: 100%;
  205. background-color: #FFFFFF;
  206. padding-top: 44px;
  207. }
  208. .container {
  209. width: 100%;
  210. height: 100%;
  211. background-size: 100%;
  212. padding-top: 50rpx;
  213. }
  214. .container_text {
  215. text-align: center;
  216. .logName {
  217. font-weight: bold;
  218. font-size: 36rpx;
  219. margin: 30rpx 0 80rpx;
  220. }
  221. .banner-img {
  222. width: 170rpx;
  223. height: 170rpx;
  224. margin: 0 auto;
  225. border-radius: 20rpx;
  226. }
  227. }
  228. .login_text {
  229. margin: auto 50rpx;
  230. position: relative;
  231. background-color: #ffffff;
  232. border-radius: 20rpx;
  233. .login_input {
  234. border-bottom: 1px solid #f0f0f0;
  235. margin-bottom: 30rpx;
  236. padding: 30rpx 0;
  237. line-height: 1;
  238. .login_img {
  239. height: 35rpx;
  240. width: 70rpx;
  241. flex-shrink: 0;
  242. font-size: 30rpx;
  243. margin-right: 20rpx;
  244. color: $font-base;
  245. }
  246. .uni-input {
  247. text-align: left;
  248. width: 100%;
  249. font-size: 28rpx !important;
  250. }
  251. .login_name {
  252. color: #333333;
  253. flex-grow: 1;
  254. }
  255. }
  256. .forget {
  257. font-size: 28rpx;
  258. width: 100%;
  259. text-align: right;
  260. color: #999999;
  261. }
  262. .uni-button-green {
  263. color: #ffffff;
  264. background-color: #5dbc7c;
  265. margin: 40rpx 10rpx;
  266. border-radius: 50rpx;
  267. box-shadow: 0px 8px 10px 0px rgba(166, 203, 184, 0.75);
  268. }
  269. .uni-button-green-plain {
  270. margin: 40rpx 10rpx;
  271. border-radius: 50rpx;
  272. color: $font-base;
  273. background-color: $page-color-base;
  274. border: none;
  275. }
  276. .uni-button {
  277. height: 80rpx;
  278. line-height: 80rpx;
  279. font-size: 28rpx;
  280. width: 100%;
  281. }
  282. }
  283. .buttomBox {
  284. border-radius: 20rpx;
  285. margin: 0 $page-row-spacing;
  286. margin-bottom: 30rpx;
  287. color: $color-green;
  288. background-color: #FFFFFF;
  289. overflow: hidden;
  290. .item {
  291. line-height: 100rpx;
  292. height: 100rpx;
  293. text-align: center;
  294. font-size: 32rpx;
  295. &.qx {
  296. font-weight: bold;
  297. }
  298. }
  299. .border_b {
  300. border-bottom: 1px solid $page-color-light;
  301. }
  302. }
  303. </style>