login.vue 8.3 KB

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