login.vue 8.5 KB

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