login.vue 11 KB

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