login.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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" @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. };
  69. },
  70. onLoad() {
  71. let obj = this;
  72. // #ifdef APP-PLUS
  73. let system = uni.getStorageSync('platform');
  74. // 判断是否为ios
  75. if (system == 'ios') {
  76. obj.is_ios = true;
  77. }
  78. uni.getSystemInfo({
  79. success(e) {
  80. if (+e.system.split('.')[0] >= 13) {
  81. obj.is_apple_login = true;
  82. }
  83. }
  84. });
  85. // #endif
  86. },
  87. methods: {
  88. ...mapMutations('user', ['setUserInfo', 'login']),
  89. // 微信登录
  90. wecahtLogin(type) {
  91. let obj = this;
  92. // #ifdef H5
  93. let weichatBrowser = uni.getStorageSync('weichatBrowser');
  94. if (weichatBrowser) {
  95. loginWinxin();
  96. }
  97. // #endif
  98. // #ifdef APP-PLUS
  99. uni.login({
  100. provider: type,
  101. success(e) {
  102. uni.getUserInfo({
  103. provider: type,
  104. success(es) {
  105. if (type === 'weixin') {
  106. loginWx(es.userInfo)
  107. .then(e => {
  108. uni.setStorageSync('token', e.data.token);
  109. getUserInfo({}).then(e => {
  110. obj.login();
  111. // 保存返回用户数据
  112. obj.setUserInfo(e.data);
  113. //成功跳转首页
  114. uni.switchTab({
  115. url: '/pages/index/index'
  116. });
  117. });
  118. })
  119. .catch(e => {
  120. console.log(e);
  121. uni.showModal({
  122. content: JSON.stringify(e),
  123. success() {},
  124. fail() {}
  125. });
  126. });
  127. }
  128. if (type === 'apple') {
  129. console.log(es.userInfo);
  130. applelogin({
  131. account: es.userInfo.openId
  132. })
  133. .then(function(e) {
  134. console.log(e, 'token');
  135. uni.setStorageSync('token', e.data.token);
  136. getUserInfo({}).then(e => {
  137. obj.login();
  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. obj.logining = true;
  181. if (obj.username == '') {
  182. obj.$api.msg('请输入手机号');
  183. return;
  184. }
  185. if (obj.passward == '') {
  186. obj.$api.msg('请输入密码');
  187. return;
  188. }
  189. login({
  190. account: obj.username,
  191. password: obj.passward
  192. })
  193. .then(function(e) {
  194. console.log(e.data.token, '123456');
  195. uni.setStorageSync('token', e.data.token);
  196. // obj.$store.commit('hasLogin', true);
  197. getUserInfo({}).then(e => {
  198. obj.login();
  199. // 保存返回用户数据
  200. obj.setUserInfo(e.data);
  201. // let ur = uni.getStorageSync('present')|| '/pages/index/index';
  202. //成功跳转首页
  203. uni.navigateTo({
  204. url: '/pages/navigation/index',
  205. });
  206. });
  207. })
  208. .catch(function(e) {
  209. console.log(e);
  210. });
  211. },
  212. //跳转注册页
  213. register() {
  214. uni.navigateTo({
  215. url: `/pages/public/register`
  216. });
  217. },
  218. // 后退
  219. navBack() {
  220. uni.navigateBack();
  221. }
  222. }
  223. };
  224. </script>
  225. <style lang="scss">
  226. /* #ifdef APP-PLUS */
  227. .ios_login {
  228. width: 260rpx;
  229. border-radius: 12rpx;
  230. justify-content: center;
  231. border: 1px solid #212121;
  232. margin: 24rpx auto;
  233. padding: 10rpx;
  234. background-color: #212121;
  235. color: #ffffff;
  236. .loginIcon {
  237. width: 50rpx;
  238. height: 50rpx;
  239. }
  240. .weixin_text {
  241. line-height: 1;
  242. margin-left: 20rpx;
  243. color: #ffffff !important;
  244. }
  245. }
  246. /* #endif */
  247. .ios_login {
  248. width: 350rpx;
  249. border-radius: 12rpx;
  250. justify-content: center;
  251. border: 1px solid #212121;
  252. margin: 24rpx auto;
  253. padding: 15rpx;
  254. background-color: #212121;
  255. color: #ffffff;
  256. font-size: 32rpx;
  257. .loginIcon {
  258. font-size: 35rpx;
  259. width: 35rpx;
  260. height: 35rpx;
  261. }
  262. .weixin_text {
  263. line-height: 1;
  264. margin-left: 20rpx;
  265. color: #ffffff !important;
  266. }
  267. }
  268. page {
  269. height: 100%;
  270. }
  271. .container {
  272. width: 100%;
  273. height: 100%;
  274. background-size: 100%;
  275. }
  276. .container_text {
  277. position: relative;
  278. width: 100%;
  279. height: 500rpx;
  280. top: 0rpx;
  281. .banner-img {
  282. width: 100%;
  283. height: 100%;
  284. }
  285. .title-img {
  286. position: absolute;
  287. left: 50%;
  288. top: 100rpx;
  289. margin-left: -130rpx;
  290. width: 260rpx;
  291. height: 156rpx;
  292. .title-image {
  293. width: 260rpx;
  294. height: 156rpx;
  295. }
  296. }
  297. }
  298. .login_text {
  299. margin: -100rpx 0 0;
  300. position: relative;
  301. padding: 100rpx 102rpx;
  302. background-color: #ffffff;
  303. border-top-left-radius: 40rpx;
  304. border-top-right-radius: 40rpx;
  305. .login_input {
  306. border: 1px solid #f0f0f0;
  307. padding: 20rpx;
  308. border-radius: 99rpx;
  309. margin-bottom: 40rpx;
  310. .login_img{
  311. text-align: center;
  312. flex-shrink: 0;
  313. width: 60rpx;
  314. }
  315. .login_img image {
  316. height: 35rpx;
  317. width: 29rpx;
  318. margin-right: 20rpx;
  319. }
  320. .uni-input {
  321. text-align: left;
  322. width: 100%;
  323. font-size: 28rpx !important;
  324. }
  325. .login_name {
  326. color: #333333;
  327. flex-grow: 1;
  328. }
  329. }
  330. .other {
  331. margin-top: 60rpx;
  332. .fenge {
  333. width: 30%;
  334. height: 2rpx;
  335. background-color: #eeeeee;
  336. }
  337. .qita {
  338. font-size: 28rpx;
  339. color: #999999;
  340. }
  341. }
  342. .weixin {
  343. width: 75rpx;
  344. height: 75rpx;
  345. margin: 25rpx auto;
  346. }
  347. .weixin image {
  348. width: 100%;
  349. height: 100%;
  350. }
  351. .weixin_text {
  352. text-align: center;
  353. font-size: 28rpx;
  354. color: #999999;
  355. }
  356. .forget {
  357. font-size: 28rpx;
  358. width: 100%;
  359. text-align: right;
  360. color: #999999;
  361. }
  362. .uni-button-green {
  363. color: #ffffff;
  364. background-color: #db292b;
  365. margin: 40rpx 10rpx;
  366. border-radius: 50rpx;
  367. }
  368. .uni-button-green-plain {
  369. border: 1px solid #db292b;
  370. margin: 40rpx 10rpx;
  371. border-radius: 50rpx;
  372. color: #db292b;
  373. background-color: #ffffff;
  374. }
  375. .uni-button {
  376. height: 85rpx;
  377. line-height: 85rpx;
  378. }
  379. }
  380. .loginTitle {
  381. position: absolute;
  382. top: 270rpx;
  383. width: 100%;
  384. text-align: center;
  385. color: white;
  386. font-size: 40rpx;
  387. }
  388. </style>