login.vue 9.6 KB

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