login.vue 11 KB

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