login.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. <template>
  2. <view class="login">
  3. <view class="img">
  4. <image src="https://t9.9026.com/imgs/bg_1.jpg" mode="scaleToFill"></image>
  5. </view>
  6. <view class="title">
  7. <view class="line"></view>
  8. <view class="logintype"><text>登录方式</text></view>
  9. <view class="line"></view>
  10. </view>
  11. <view class="typebtn">
  12. <view class="item" @click="goYouyue">
  13. <image src="/static/icon/youyue.png" mode="scaleToFill"></image>
  14. <text>加入优悦会</text>
  15. </view>
  16. <view class="item" @click="getmsg">
  17. <image src="/static/icon/wechart.png" mode="scaleToFill"></image>
  18. <text>微信登录</text>
  19. <!-- <text v-if="isLoginOff">授权登录</text> -->
  20. </view>
  21. </view>
  22. <!-- <u-modal @close="closeMask" closeOnClickOverlay="true" :show="modal.show" :title="modal.title"
  23. :show-confirm-button="false">
  24. <view>
  25. <button class="avatar" open-type="chooseAvatar" @chooseavatar="handleChooseAvatar">
  26. <image class="user-avatar" style="height: 176rpx;width: 176rpx;border-radius: 50%;"
  27. :src="modal.avatar?modal.avatar:'/static/icon/avatar.png'" />
  28. </button>
  29. <input class="avatar" type="nickname" :value="modal.nickname" placeholder="填写昵称"
  30. @change="handleChangeNickname">
  31. <button class="confirm" @click="handleConfirmWechatUserInfo">提交</button>
  32. </view>
  33. </u-modal> -->
  34. <u-popup :show="modal.show" :round="10" mode="bottom" @close="close">
  35. <view class="popup-login">
  36. <view class="popup-login-top">
  37. <image style="width: 56rpx; height: 56rpx; margin-right: 20rpx; "
  38. src="https://t9.9026.com/imgs/loginLogo1.png" mode=""></image>
  39. <text>登录后体验更多功能</text>
  40. </view>
  41. <view class="popup-login-main">
  42. <button class="avatar" open-type="chooseAvatar" @chooseavatar="handleChooseAvatar">
  43. <image class="user-avatar" style="height: 176rpx;width: 176rpx;border-radius: 50%;"
  44. :src="modal.avatar?modal.avatar:'https://t9.9026.com/imgs/loginAvatar.png'" />
  45. </button>
  46. </view>
  47. <view class="popup-login-ipt">
  48. <input class="avatar" type="nickname" :value="modal.nickname" placeholder="输入昵称"
  49. @change="handleChangeNickname">
  50. </view>
  51. <view class="popup-login-btn" @click="handleConfirmWechatUserInfo">
  52. <button class="confirm">完成</button>
  53. </view>
  54. <view class="popup-login-text">
  55. <view>登录即代表已阅读并同意<text style="color: #FF6200;">服务协议、隐私协议</text></view>
  56. </view>
  57. </view>
  58. </u-popup>
  59. </view>
  60. </template>
  61. <script>
  62. export default {
  63. data() {
  64. return {
  65. imgBase64: '',
  66. isLoginOff: false,
  67. modal: {
  68. show: false,
  69. title: '用户信息获取',
  70. nickname: '',
  71. avatar: ''
  72. },
  73. code: '',
  74. encryptedData: '',
  75. iv: '',
  76. data: {}
  77. }
  78. },
  79. onLoad() {
  80. this.isLoginOff = this.$store.getters.userInfo
  81. },
  82. methods: {
  83. getPageUrl() {
  84. const pages = getCurrentPages();
  85. console.log(pages, '--------->pages')
  86. if (pages.length == 1) {
  87. const currentPage = pages[0];
  88. let pageUrl = `${currentPage.$page.fullPath}`;
  89. console.log('当前页面url1:', pageUrl);
  90. return pageUrl
  91. } else {
  92. const currentPage = pages[pages.length - 2];
  93. let pageUrl = `${currentPage.$page.fullPath}`;
  94. console.log('当前页面url2:', pageUrl);
  95. return pageUrl
  96. }
  97. },
  98. //关闭遮罩层
  99. closeMask() {
  100. this.modal.show = false
  101. },
  102. close() {
  103. this.modal.show = false
  104. },
  105. //提交
  106. handleConfirmWechatUserInfo() {
  107. if (!this.modal.avatar) {
  108. this.$u.toast('请上传头像')
  109. return
  110. }
  111. if (!this.modal.nickname) {
  112. this.$u.toast('请填写昵称')
  113. return
  114. }
  115. this.$loading('数据提交中...')
  116. this.$api.my.update({
  117. avatar: this.modal.avatar,
  118. nickname: this.modal.nickname
  119. }).then(res => {
  120. this.$hideLoading()
  121. this.$store.dispatch('user/info', res.data)
  122. this.modal.show = false
  123. //获取登录页前地址
  124. let pages = this.getPageUrl()
  125. if (pages != '/pages/login/login') {
  126. uni.reLaunch({
  127. url: pages,
  128. })
  129. } else {
  130. uni.switchTab({
  131. url: '/pages/my/my'
  132. })
  133. }
  134. })
  135. },
  136. handleGetWechatUserInfo() {
  137. this.modal.show = true
  138. },
  139. // 获取头像
  140. handleChooseAvatar({
  141. detail
  142. }) {
  143. let _this = this
  144. // this.modal.avatar = detail.avatarUrl
  145. uni.getFileSystemManager().readFile({
  146. filePath: detail.avatarUrl, // 选择图片返回的相对路径
  147. encoding: 'base64', // 编码格式
  148. success: res => { // 成功的回调
  149. uni.uploadFile({
  150. url: _this.$setting.BASE_URL + '/v1/user/uploadFile',
  151. // filePath: 'data:image/png;base64,' + res.data,
  152. filePath: detail.avatarUrl,
  153. name: 'file',
  154. success({
  155. data
  156. }) {
  157. const res = JSON.parse(data)
  158. const {
  159. url
  160. } = res.data
  161. _this.modal.avatar = url
  162. console.log('-->data', _this.modal.avatar)
  163. }
  164. })
  165. // this.modal.avatar = detail.avatarUrl
  166. // console.log('data:image/png;base64,' + res.data)
  167. }
  168. })
  169. },
  170. //获取昵称
  171. handleChangeNickname(res) {
  172. this.modal.nickname = res.detail.value
  173. },
  174. // 加入优悦会
  175. goYouyue() {
  176. uni.navigateTo({
  177. url: '/pages/login/youyue'
  178. })
  179. },
  180. getCode() {
  181. return new Promise((resolve, reject) => {
  182. uni.getUserInfo({
  183. success: loginRes => {
  184. this.data.encryptData = loginRes.encryptedData,
  185. this.data.iv = loginRes.iv
  186. resolve(this.data)
  187. }
  188. })
  189. })
  190. },
  191. //获取微信登录的code码
  192. getmsg() {
  193. uni.login({
  194. provider: uni.$u.platform,
  195. success: res => {
  196. this.getCode().then((data) => {
  197. const params = {
  198. code: res.code,
  199. iv: data.iv,
  200. encryptData: data.encryptData
  201. }
  202. console.log(params);
  203. this.$api.my.myLogin(params).then(res => {
  204. if (res.code == 0) {
  205. let {
  206. token
  207. } = res.data
  208. this.handleGetWechatUserInfo()
  209. // this.handleConfirmWechatUserInfo()
  210. this.$store.dispatch('user/token', token)
  211. } else {
  212. uni.showToast({
  213. icon: 'none',
  214. title: res.msg
  215. })
  216. }
  217. })
  218. })
  219. }
  220. })
  221. },
  222. }
  223. }
  224. </script>
  225. <style lang="scss" scoped>
  226. $pageColor:#F9F9F9;
  227. $bgColor:#FFFFFF;
  228. .login {
  229. height: 100%;
  230. background: $bgColor;
  231. box-sizing: border-box;
  232. }
  233. .userinfo {
  234. position: absolute;
  235. top: 38rpx;
  236. left: 200rpx;
  237. .unlogin {
  238. width: 220rpx;
  239. font-size: 44rpx;
  240. font-family: PingFang-SC-Heavy, PingFang-SC;
  241. font-weight: 500;
  242. color: #FFFFFF;
  243. display: block;
  244. margin-top: 20rpx;
  245. }
  246. .username {
  247. width: 184rpx;
  248. height: 44rpx;
  249. font-size: 44rpx;
  250. font-family: PingFang-SC-Heavy, PingFang-SC;
  251. font-weight: 500;
  252. color: #FFFFFF;
  253. line-height: 44rpx;
  254. display: block;
  255. margin-bottom: 24rpx;
  256. }
  257. .userId {
  258. font-size: 32rpx;
  259. font-family: PingFang-SC-Medium, PingFang-SC;
  260. font-weight: 400;
  261. color: #FFFFFF;
  262. line-height: 32rpx;
  263. }
  264. }
  265. .img {
  266. image {
  267. width: 100vw;
  268. height: 910rpx;
  269. }
  270. }
  271. .title {
  272. height: 40rpx;
  273. width: 690rpx;
  274. // margin-top: 168rpx;
  275. margin-left: 30rpx;
  276. margin-bottom: 72rpx;
  277. display: flex;
  278. align-items: center;
  279. justify-content: space-between;
  280. .line {
  281. width: 240rpx;
  282. height: 2rpx;
  283. background: #EDEDED;
  284. border-radius: 1rpx;
  285. }
  286. .logintype {
  287. position: relative;
  288. top: -8rpx;
  289. text {
  290. font-size: 28rpx;
  291. font-family: PingFang-SC-Medium, PingFang-SC;
  292. font-weight: 500;
  293. color: #333333;
  294. }
  295. }
  296. }
  297. .typebtn {
  298. display: flex;
  299. align-items: center;
  300. justify-content: space-around;
  301. .item {
  302. width: 140rpx;
  303. height: 156rpx;
  304. display: flex;
  305. flex-direction: column;
  306. align-items: center;
  307. justify-content: center;
  308. image {
  309. width: 104rpx;
  310. height: 104rpx;
  311. margin-bottom: 12rpx;
  312. }
  313. text {
  314. display: block;
  315. font-size: 28rpx;
  316. font-family: PingFang-SC-Medium, PingFang-SC;
  317. font-weight: 500;
  318. color: #666666;
  319. }
  320. }
  321. }
  322. //登录弹框
  323. .popup-login {
  324. width: 100%;
  325. height: 706rpx;
  326. background: #FFFFFF;
  327. box-shadow: 0rpx -10rpx 32rpx 0px rgba(0, 0, 0, 0.04);
  328. border-radius: 16rpx 16rpx 0px 0px;
  329. padding: 40rpx 64rpx 92rpx;
  330. .popup-login-top {
  331. display: flex;
  332. align-items: center;
  333. justify-content: flex-start;
  334. font-size: 30rpx;
  335. font-weight: bold;
  336. color: #000000;
  337. }
  338. .popup-login-main {
  339. width: 100%;
  340. display: flex;
  341. align-items: center;
  342. justify-content: center;
  343. margin-top: 62rpx;
  344. .avatar {
  345. width: 176rpx;
  346. height: 176rpx;
  347. border-radius: 50%;
  348. border: 0;
  349. background: transparent;
  350. &::after {
  351. border: none;
  352. }
  353. .user-avatar {
  354. object-fit: cover;
  355. object-position: center;
  356. }
  357. }
  358. }
  359. .popup-login-ipt {
  360. width: 100%;
  361. height: 88rpx;
  362. background: #F6F6F6;
  363. border-radius: 44rpx;
  364. display: flex;
  365. align-items: center;
  366. justify-content: center;
  367. margin-top: 48rpx;
  368. .avatar {
  369. width: 100%;
  370. height: 100%;
  371. text-align: center;
  372. font-size: 28rpx;
  373. font-weight: bold;
  374. color: #999999;
  375. }
  376. }
  377. .popup-login-btn {
  378. width: 100%;
  379. height: 88rpx;
  380. background: #1AAC1B;
  381. border-radius: 38rpx;
  382. display: flex;
  383. align-items: center;
  384. justify-content: center;
  385. margin-top: 32rpx;
  386. .confirm {
  387. border: 0;
  388. background: transparent;
  389. font-size: 28rpx;
  390. font-weight: bold;
  391. color: #FFFFFF;
  392. &::after {
  393. border: none;
  394. }
  395. }
  396. }
  397. .popup-login-text {
  398. display: flex;
  399. align-items: center;
  400. justify-content: center;
  401. margin-top: 32rpx;
  402. font-weight: bold;
  403. color: #999999;
  404. font-size: 22rpx;
  405. }
  406. }
  407. </style>