login.vue 8.0 KB

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