login.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. <template>
  2. <view class="container">
  3. <view class="container_text">
  4. <image class="banner-img" src="/static/img/logo.png" 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="$t('login.a1')" />
  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="$t('login.a3')" /></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="./forget">
  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%;
  281. background-image: url("../../static/img/loginBg.png");
  282. background-repeat: no-repeat;
  283. background-position: 100% 100%;
  284. }
  285. /* #ifdef APP-PLUS */
  286. .ios_login {
  287. width: 260rpx;
  288. border-radius: 12rpx;
  289. justify-content: center;
  290. border: 1px solid #212121;
  291. margin: 24rpx auto;
  292. padding: 10rpx;
  293. // background-color: #212121;
  294. color: #ffffff;
  295. .loginIcon {
  296. width: 50rpx;
  297. height: 50rpx;
  298. }
  299. .weixin_text {
  300. line-height: 1;
  301. margin-left: 20rpx;
  302. color: #ffffff !important;
  303. }
  304. }
  305. /* #endif */
  306. .ios_login {
  307. width: 350rpx;
  308. border-radius: 12rpx;
  309. justify-content: center;
  310. border: 1px solid #212121;
  311. margin: 24rpx auto;
  312. padding: 15rpx;
  313. // background-color: #212121;
  314. color: #ffffff;
  315. font-size: 32rpx;
  316. .loginIcon {
  317. font-size: 35rpx;
  318. width: 35rpx;
  319. height: 35rpx;
  320. }
  321. .weixin_text {
  322. line-height: 1;
  323. margin-left: 20rpx;
  324. color: #ffffff !important;
  325. }
  326. }
  327. page {
  328. height: 100%;
  329. }
  330. .container_text {
  331. width: 100%;
  332. height: 500rpx;
  333. top: 0rpx;
  334. .banner-img {
  335. width: 144rpx;
  336. margin-top: 100rpx;
  337. margin-left: 302rpx;
  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. }
  359. .login_name {
  360. margin-left: 20rpx;
  361. flex-grow: 1;
  362. color: #fff;
  363. }
  364. }
  365. .other {
  366. margin-top: 60rpx;
  367. .fenge {
  368. width: 30%;
  369. height: 2rpx;
  370. background-color: #eeeeee;
  371. }
  372. .qita {
  373. font-size: 28rpx;
  374. color: #999999;
  375. }
  376. }
  377. .weixin {
  378. width: 75rpx;
  379. height: 75rpx;
  380. margin: 25rpx auto;
  381. }
  382. .weixin image {
  383. width: 100%;
  384. height: 100%;
  385. }
  386. .weixin_text {
  387. text-align: center;
  388. font-size: 28rpx;
  389. color: #999999;
  390. }
  391. .forget {
  392. font-size: 28rpx;
  393. width: 100%;
  394. text-align: right;
  395. color: #999999;
  396. }
  397. .uni-button-green {
  398. color: #1257FE;
  399. background-color: #FFF;
  400. margin: 40rpx 0rpx;
  401. border-radius: 10rpx;
  402. }
  403. .uni-button-green-plain {
  404. border: 1px solid #FFF;
  405. margin: 40rpx 0rpx;
  406. border-radius: 10rpx;
  407. color: #FFF;
  408. background-color: transparent;
  409. }
  410. .uni-button {
  411. height: 85rpx;
  412. line-height: 85rpx;
  413. }
  414. }
  415. .loginTitle {
  416. position: absolute;
  417. top: 250rpx;
  418. width: 100%;
  419. text-align: center;
  420. color: #cbb174;
  421. font-size: 40rpx;
  422. }
  423. /* #ifdef H5 */
  424. .loadapp {
  425. margin-top: 20rpx;
  426. border: 1px solid #feb041;
  427. background-color: transparent;
  428. color: #feb041;
  429. width: 45%;
  430. }
  431. /* #endif */
  432. </style>