login.vue 8.6 KB

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