login.vue 9.6 KB

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