login.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. <template>
  2. <view class="container">
  3. <view class="logo-wrap">
  4. <image class="logo" src="" mode=""></image>
  5. <view class="name">
  6. LOGO
  7. </view>
  8. </view>
  9. <view class="login_text">
  10. <view class="login_input flex">
  11. <view class="login_img">
  12. <image src="../../static/user/phone.png" mode="heightFix"></image>
  13. </view>
  14. <view class="login_name"><input class="uni-input" v-model="username" focus placeholder="请输入手机号" />
  15. </view>
  16. </view>
  17. <view class="login_input flex">
  18. <view class="login_img">
  19. <image src="../../static/user/pas.png" mode="heightFix"></image>
  20. </view>
  21. <view class="login_name"><input class="uni-input" type="password" v-model="passward" focus
  22. placeholder="请输入密码" /></view>
  23. </view>
  24. <view><button type="green" class="uni-button uni-button-green" :class="{uniButtonAction:logining}" @click="toLogin">登录</button></view>
  25. <view><button type="green" class="uni-button uni-button-green-plain" plain="true"
  26. hover-class="none" @click="register">注册</button></view>
  27. <navigator url="./forget">
  28. <view class="forget">忘记密码</view>
  29. </navigator>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. import {
  35. mapMutations
  36. } from 'vuex';
  37. import {
  38. login
  39. } from '@/api/login.js';
  40. import {
  41. getUserInfo
  42. } from '@/api/user.js';
  43. // #ifdef APP-PLUS
  44. // applelogin接口需要开发编写,基础项目中可能没有
  45. import {
  46. applelogin
  47. } from '@/api/set.js';
  48. // loginWx接口需要开发编写,基础项目中可能没有
  49. import {
  50. loginWx
  51. } from '@/api/login.js';
  52. // #endif
  53. // #ifdef H5
  54. import {
  55. loginWinxin
  56. } from '@/utils/wxAuthorized';
  57. // #endif
  58. export default {
  59. data() {
  60. return {
  61. username: '',
  62. passward: '',
  63. // #ifdef APP-PLUS
  64. is_ios: false, //判断是否为ios手机
  65. is_apple_login: false, //是否有ios授权登录功能
  66. // #endif
  67. logining:false,//判断是否登录中
  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. obj.login();
  103. uni.getUserInfo({
  104. provider: type,
  105. success(es) {
  106. if (type === 'weixin') {
  107. loginWx(es.userInfo)
  108. .then(e => {
  109. uni.setStorageSync('token', e.data.token);
  110. getUserInfo({}).then(e => {
  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. // 保存返回用户数据
  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. if(obj.logining){
  180. return
  181. }
  182. obj.logining = true;
  183. if (obj.username == '') {
  184. obj.$api.msg('请输入手机号');
  185. return;
  186. }
  187. if (obj.passward == '') {
  188. obj.$api.msg('请输入密码');
  189. return;
  190. }
  191. login({
  192. account: obj.username,
  193. password: obj.passward
  194. })
  195. .then(function(e) {
  196. obj.login();
  197. console.log(e.data.token, '123456');
  198. uni.setStorageSync('token', e.data.token);
  199. // obj.$store.commit('hasLogin', true);
  200. getUserInfo({}).then(e => {
  201. obj.logining = false;
  202. // 保存返回用户数据
  203. obj.setUserInfo(e.data);
  204. // let ur = uni.getStorageSync('present')|| '/pages/index/index';
  205. //成功跳转首页
  206. uni.navigateTo({
  207. url: '/pages/navigation/index',
  208. });
  209. }).catch((res)=>{
  210. obj.logining = false;
  211. });
  212. })
  213. .catch(function(e) {
  214. obj.logining = false;
  215. console.log(e);
  216. });
  217. },
  218. //跳转注册页
  219. register() {
  220. uni.navigateTo({
  221. url: `/pages/public/register`
  222. });
  223. },
  224. // 后退
  225. navBack() {
  226. uni.navigateBack();
  227. }
  228. }
  229. };
  230. </script>
  231. <style lang="scss">
  232. page {
  233. height: 100%;
  234. }
  235. .container {
  236. width: 100%;
  237. height: 100%;
  238. background-image: url('../../static/user/login-bg.png');
  239. background-size: 100% 100%;
  240. }
  241. .login_text {
  242. // margin: -100rpx 0 0;
  243. position: relative;
  244. padding: 0rpx 72rpx;
  245. // background-color: #ffffff;
  246. // border-top-left-radius: 40rpx;
  247. // border-top-right-radius: 40rpx;
  248. .login_input {
  249. border-bottom: 1px solid #f0f0f0;
  250. padding: 20rpx;
  251. // border-radius: 99rpx;
  252. margin-bottom: 40rpx;
  253. .login_img{
  254. text-align: center;
  255. flex-shrink: 0;
  256. width: 60rpx;
  257. }
  258. .login_img image {
  259. height: 35rpx;
  260. width: 29rpx;
  261. margin-right: 20rpx;
  262. }
  263. .uni-input {
  264. text-align: left;
  265. width: 100%;
  266. font-size: 28rpx !important;
  267. }
  268. .login_name {
  269. color: #fff;
  270. flex-grow: 1;
  271. }
  272. }
  273. .other {
  274. margin-top: 60rpx;
  275. .fenge {
  276. width: 30%;
  277. height: 2rpx;
  278. background-color: #eeeeee;
  279. }
  280. .qita {
  281. font-size: 28rpx;
  282. color: #999999;
  283. }
  284. }
  285. .weixin {
  286. width: 75rpx;
  287. height: 75rpx;
  288. margin: 25rpx auto;
  289. }
  290. .weixin image {
  291. width: 100%;
  292. height: 100%;
  293. }
  294. .weixin_text {
  295. text-align: center;
  296. font-size: 28rpx;
  297. color: #999999;
  298. }
  299. .forget {
  300. font-size: 28rpx;
  301. width: 100%;
  302. text-align: right;
  303. color: #fff;
  304. }
  305. .uni-button-green {
  306. width: 604rpx;
  307. height: 90rpx;
  308. background: #FFFFFF;
  309. border-radius: 10rpx;
  310. color:#222222;
  311. margin: 40rpx auto;
  312. }
  313. .uni-button-action {
  314. background-color:#eeeeee !important;
  315. }
  316. .uni-button-green-plain {
  317. width: 604rpx;
  318. height: 90rpx;
  319. border: 1px solid #fff;
  320. margin: 40rpx auto;
  321. border-radius: 10rpx;
  322. color: #fff;
  323. // background-color: #ffffff;
  324. }
  325. .uni-button {
  326. height: 85rpx;
  327. line-height: 85rpx;
  328. }
  329. }
  330. .loginTitle {
  331. position: absolute;
  332. top: 270rpx;
  333. width: 100%;
  334. text-align: center;
  335. color: white;
  336. font-size: 40rpx;
  337. }
  338. .logo-wrap {
  339. padding: 210rpx 0 150rpx;
  340. .logo {
  341. display: block;
  342. width: 160rpx;
  343. height: 160rpx;
  344. border-radius: 50%;
  345. background-color: #fff;
  346. margin: auto;
  347. }
  348. .name {
  349. width: 100rpx;
  350. height: 28rpx;
  351. font-size: 36rpx;
  352. color: #FFFFFF;
  353. text-align: center;
  354. width: 100%;
  355. padding-top: 20rpx;
  356. }
  357. }
  358. </style>