login.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. <template>
  2. <view class="container">
  3. <view class="top"><image src="../../static/img/login-bg.png" mode=""></image></view>
  4. <view class="logo">
  5. <view class="logo-img"><image src="../../static/img/logo.png" mode=""></image></view>
  6. <view class="logo-title">微乐购</view>
  7. </view>
  8. <view class="login-box">
  9. <view class="username"><image src="../../static/img/phone.png" mode=""></image></view>
  10. <view class="input-bbox">
  11. <input class="input-user" type="text" v-model="phone" placeholder="请输入账号" />
  12. <!-- <text class="select-box">
  13. <select class="select" @change="change($event)" ref='hhh'>
  14. <option value="1" @click="change">1</option>
  15. <option value="2">2</option>
  16. </select>
  17. </text> -->
  18. </view>
  19. </view>
  20. <view class="login-box">
  21. <view class="username" style="width: 30rpx; height: 36rpx;"><image src="../../static/img/zfpwd.png" mode=""></image></view>
  22. <input class="input-box" type="password" v-model="password" placeholder="请输入密码" />
  23. </view>
  24. <view class="login" @click="toLogin">登录</view>
  25. <view class="forget flex">
  26. <view @click="navTo('/pages/public/forget')">忘记密码</view>
  27. <view class="shu"></view>
  28. <view class="login-tip"><text class="register" @click="navTo('/pages/public/register')">立即注册</text></view>
  29. </view>
  30. <label class="two" @click="checkboxChange">
  31. <radio style="transform:scale(0.7)" color="#5dbc7c" :checked="istype" />
  32. 我已阅读并同意
  33. <text @click.stop="navTo('/pages/contract/agreement')">《用户协议》</text>
  34. &nbsp
  35. <text @click.stop="navTo('/pages/contract/privacy')">《隐私政策》</text>
  36. </label>
  37. <!-- <view class="flex other">
  38. <view class="fenge"></view>
  39. <view class="qita">其他方式登录</view>
  40. <view class="fenge"></view>
  41. </view> -->
  42. <!-- #ifndef APP-PLUS -->
  43. <!-- <view class="weixin" @click="wecahtLogin('weixin')"><image src="/static/img/login-weixin.png"></image></view>
  44. <view class="weixin_text" @click="wecahtLogin('weixin')">微信登录</view> -->
  45. <!-- #endif -->
  46. <!-- #ifdef APP-PLUS -->
  47. <!-- <block v-if="!is_ios">
  48. <view class="weixin" @click="wecahtLogin('weixin')"><image src="/static/img/login-weixin.png" mode="scaleToFill"></image></view>
  49. <view class="weixin_text" @click="wecahtLogin('weixin')">微信登录</view>
  50. </block>
  51. <block v-else>
  52. <view class="ios_login flex" @click="wecahtLogin('weixin')">
  53. <text class="iconfont iconweixin"></text>
  54. <text class="weixin_text">微信登录</text>
  55. </view>
  56. <view v-if="is_apple_login" class="ios_login flex" @click="wecahtLogin('apple')">
  57. <image class="loginIcon" src="/static/static/icon/appleIcon.png" mode=" scaleToFill"></image>
  58. <text class="weixin_text">通过Apple登录</text>
  59. </view>
  60. </block> -->
  61. <!-- #endif -->
  62. </view>
  63. </template>
  64. <script>
  65. import { mapMutations } from 'vuex';
  66. import { login, loginWx } from '@/api/login.js';
  67. import { getUserInfo } from '@/api/user.js';
  68. import { getFileIndex, getFile, writerTxt, getFileText } from '@/utils/fileController.js';
  69. // #ifdef H5
  70. import { loginWinxin } from '@/utils/wxAuthorized';
  71. // #endif
  72. export default {
  73. data() {
  74. return {
  75. phone: '',
  76. password: '',
  77. istype: false,
  78. // #ifdef APP-PLUS
  79. is_ios: false, //判断是否为ios手机
  80. is_apple_login: false //是否有ios授权登录功能
  81. // #endif
  82. };
  83. },
  84. onLoad() {
  85. uni.hideLoading();
  86. },
  87. methods: {
  88. ...mapMutations('user', ['setUserInfo', 'login']),
  89. checkboxChange() {
  90. this.istype = !this.istype;
  91. console.log(this.istype);
  92. },
  93. change(e) {
  94. this.phone = e.target.value;
  95. },
  96. //登录
  97. wecahtLogin(type) {
  98. let obj = this;
  99. // #ifdef H5
  100. let weichatBrowser = uni.getStorageSync('weichatBrowser');
  101. if (weichatBrowser) {
  102. loginWinxin();
  103. }
  104. // #endif
  105. // #ifdef APP-PLUS
  106. uni.login({
  107. provider: type,
  108. success(e) {
  109. console.log(e, 'e12345678989789');
  110. uni.getUserInfo({
  111. provider: type,
  112. success(es) {
  113. console.log(es, 'es123456789');
  114. if (type === 'weixin') {
  115. console.log('weixin');
  116. loginWx(es.userInfo)
  117. .then(e => {
  118. uni.showLoading({
  119. title: '登录中'
  120. });
  121. console.log(e, '123456');
  122. uni.setStorageSync('token', e.data.token);
  123. getUserInfo({}).then(e => {
  124. obj.login();
  125. // 保存返回用户数据
  126. obj.setUserInfo(e.data);
  127. uni.hideLoading();
  128. //成功跳转首页
  129. uni.switchTab({
  130. url: '/pages/index/index'
  131. });
  132. });
  133. })
  134. .catch(e => {
  135. console.log(e);
  136. uni.showModal({
  137. content: JSON.stringify(e),
  138. success() {},
  139. fail() {}
  140. });
  141. });
  142. }
  143. if (type === 'apple') {
  144. console.log(es.userInfo);
  145. applelogin({
  146. account: es.userInfo.openId
  147. })
  148. .then(function(e) {
  149. console.log(e, 'token');
  150. uni.setStorageSync('token', e.data.token);
  151. getUserInfo({}).then(e => {
  152. obj.login();
  153. // 保存返回用户数据
  154. obj.setUserInfo(e.data);
  155. //成功跳转首页
  156. uni.switchTab({
  157. url: '/pages/index/index'
  158. });
  159. });
  160. })
  161. .catch(function(e) {
  162. console.log(e);
  163. });
  164. }
  165. },
  166. fail(es) {
  167. uni.showModal({
  168. content: JSON.stringify(es),
  169. success() {
  170. // obj.login();
  171. // // 保存返回用户数据
  172. // obj.setUserInfo(e.data);
  173. // //成功跳转首页
  174. // uni.switchTab({
  175. // url: '/pages/index/index'
  176. // });
  177. }
  178. });
  179. }
  180. });
  181. },
  182. fail(e) {
  183. uni.showModal({
  184. title: '提示',
  185. content: JSON.stringify(e),
  186. showCancel: false
  187. });
  188. }
  189. });
  190. // #endif
  191. },
  192. async toLogin() {
  193. uni.showLoading({
  194. title: '正在登陆中'
  195. });
  196. let obj = this;
  197. obj.logining = true;
  198. if (obj.phone == '') {
  199. obj.$api.msg('请输入账号');
  200. return;
  201. }
  202. if (obj.password == '') {
  203. obj.$api.msg('请输入密码');
  204. return;
  205. }
  206. if (!obj.istype) {
  207. obj.$api.msg('请查看并同意用户协议和隐私政策');
  208. return;
  209. }
  210. login({
  211. account: obj.phone,
  212. password: obj.password
  213. })
  214. .then(function(e) {
  215. uni.setStorageSync('token', e.data.token);
  216. getUserInfo({}).then(e => {
  217. obj.login();
  218. //#ifdef APP-PLUS
  219. getFileIndex().then(info => {
  220. getFile(info, 'userInfo').then(data => {
  221. writerTxt(data, e.data);
  222. });
  223. });
  224. //#endif
  225. // 保存返回用户数据
  226. obj.setUserInfo(e.data);
  227. uni.switchTab({
  228. url: '/pages/index/index'
  229. });
  230. });
  231. uni.hideLoading();
  232. })
  233. .catch(function(e) {
  234. console.log(e);
  235. });
  236. },
  237. navTo(url) {
  238. uni.navigateTo({
  239. url
  240. });
  241. },
  242. // 后退
  243. navBack() {
  244. uni.navigateBack();
  245. }
  246. }
  247. };
  248. </script>
  249. <style lang="scss">
  250. page {
  251. min-height: 100%;
  252. background-color: #ffffff;
  253. }
  254. .top {
  255. width: 750rpx;
  256. height: 470rpx;
  257. image {
  258. width: 100%;
  259. height: 100%;
  260. }
  261. }
  262. .logo {
  263. position: absolute;
  264. left: 50%;
  265. right: 0;
  266. top: 110rpx;
  267. margin-left: -80rpx;
  268. .logo-img {
  269. width: 160rpx;
  270. height: 160rpx;
  271. box-shadow: 0px 12rpx 13rpx 0px rgba(51, 145, 255, 0.47);
  272. border-radius: 50%;
  273. image {
  274. width: 100%;
  275. height: 100%;
  276. border-radius: 50%;
  277. }
  278. }
  279. .logo-title {
  280. width: 160rpx;
  281. text-align: center;
  282. font-size: 32rpx;
  283. font-family: PingFang SC;
  284. font-weight: 400;
  285. color: #ffffff;
  286. margin-top: 10rpx;
  287. }
  288. }
  289. .loginTitle {
  290. font-weight: bold;
  291. color: #333333;
  292. font-size: 58rpx;
  293. padding-bottom: 34rpx;
  294. }
  295. .loginText {
  296. font-weight: 500;
  297. color: #333333;
  298. font-size: 34rpx;
  299. padding-bottom: 34rpx;
  300. }
  301. .login-box {
  302. display: flex;
  303. justify-content: flex-start;
  304. border-bottom: 1px solid #eeeeee;
  305. margin: 90rpx 72rpx 0;
  306. padding-bottom: 28rpx;
  307. .username {
  308. width: 26rpx;
  309. height: 43rpx;
  310. font-weight: 500;
  311. color: #333333;
  312. font-size: 32rpx;
  313. flex-shrink: 0;
  314. image {
  315. width: 100%;
  316. height: 100%;
  317. }
  318. }
  319. .input-box {
  320. margin-left: 40rpx;
  321. width: 100%;
  322. }
  323. .input-bbox {
  324. margin-left: 40rpx;
  325. width: 100%;
  326. position: relative;
  327. .input-user {
  328. background: #ffffff;
  329. position: absolute;
  330. z-index: 10;
  331. top: 0;
  332. left: 0;
  333. width: 90%;
  334. }
  335. .select-box {
  336. background: #ffffff;
  337. position: absolute;
  338. top: 0;
  339. left: 0;
  340. bottom: 0;
  341. width: 100%;
  342. .select {
  343. background: #ffffff;
  344. outline: none;
  345. height: 100%;
  346. border: none;
  347. width: 100%;
  348. }
  349. }
  350. }
  351. }
  352. .forget {
  353. justify-content: center;
  354. text-align: right;
  355. margin: 36rpx 0rpx;
  356. font-weight: 500;
  357. color: #1dcbe4;
  358. font-size: 28rpx;
  359. .mui-checkbox {
  360. font-weight: 500;
  361. color: #333333;
  362. font-size: 35rpx;
  363. }
  364. .shu {
  365. height: 26rpx;
  366. width: 1px;
  367. background-color: #1dcbe4;
  368. margin: 0 10rpx;
  369. }
  370. }
  371. .login {
  372. margin: 100rpx auto 0;
  373. width: 604rpx;
  374. height: 90rpx;
  375. background: #08d29b;
  376. box-shadow: 0px 12rpx 13rpx 0px rgba(51, 145, 255, 0.2);
  377. border-radius: 10rpx;
  378. font-size: 34rpx;
  379. font-family: SourceHanSansCN;
  380. font-weight: 400;
  381. color: #ffffff;
  382. line-height: 90rpx;
  383. text-align: center;
  384. }
  385. .login-tip {
  386. text-align: center;
  387. font-weight: 500;
  388. color: #333333;
  389. font-size: 28rpx;
  390. .register {
  391. color: #08d29b;
  392. }
  393. }
  394. .other {
  395. margin-top: 60rpx;
  396. .fenge {
  397. width: 30%;
  398. height: 2rpx;
  399. background-color: #eeeeee;
  400. }
  401. .qita {
  402. font-size: 28rpx;
  403. color: #999999;
  404. }
  405. }
  406. .weixin {
  407. width: 75rpx;
  408. height: 75rpx;
  409. margin: 25rpx auto;
  410. }
  411. .weixin image {
  412. width: 100%;
  413. height: 100%;
  414. }
  415. .weixin_text {
  416. text-align: center;
  417. font-size: 28rpx;
  418. color: #999999;
  419. }
  420. .forget {
  421. font-size: 28rpx;
  422. width: 100%;
  423. text-align: right;
  424. color: #999999;
  425. }
  426. .two {
  427. margin: 20rpx 40rpx;
  428. font-size: 28rpx;
  429. text-align: center;
  430. font-family: PingFang SC;
  431. font-weight: 500;
  432. color: #999999;
  433. text {
  434. color: #5dbc7c;
  435. }
  436. }
  437. </style>