login.vue 9.5 KB

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