login.vue 9.4 KB

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