login.vue 9.5 KB

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