From 3ac990eb63f8d9743f1a3fc8e46a05fb37ded7f4 Mon Sep 17 00:00:00 2001 From: donqi Date: Thu, 14 Jul 2022 00:39:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=8C=E7=BB=B4=E7=A0=81=E5=88=86=E4=BA=AB?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/js/request.js | 44 +++++- pages/index/index.vue | 277 ++++++++++++++++++++------------- pages/index/my-home.vue | 49 +++++- pages/my/app-invite-qrcode.vue | 60 +++++++ 4 files changed, 308 insertions(+), 122 deletions(-) create mode 100644 pages/my/app-invite-qrcode.vue diff --git a/common/js/request.js b/common/js/request.js index d4eb33e..2724e76 100644 --- a/common/js/request.js +++ b/common/js/request.js @@ -10,9 +10,9 @@ export default { title: '加载中' }) // request 触发前拼接 url - // args.url = 'https://www.opsoul.com' + args.url; + args.url = 'https://www.opsoul.com' + args.url; // args.url = 'http://192.168.2.42:80' + args.url; - args.url = 'http://127.0.0.1:80' + args.url; + // args.url = 'http://127.0.0.1:80' + args.url; if (args.data) { args.data.deptId = globalData.deptId; args.data.from = globalData.from; @@ -172,7 +172,7 @@ export default { }) return res[1].data; }, - async updateUserPhone(params = {}) { + async updateUser(params = {}) { let res = await uni.request({ url: '/customer/update', method: 'POST', @@ -181,9 +181,16 @@ export default { // 更新用户信息的方法顺便更新本地缓存 if (res[1].data.code === 0) { let userInfo = this.getCurUserInfo(); - userInfo.phone = params.phone; - userInfo.account = params.account; - uni.setStorageSync('userProfile', userInfo); + let wxGetUserRes = await this.qryUserInfo(userInfo.openId); + let newUserInfo; + if (wxGetUserRes.data) { + newUserInfo = { + ...wxGetUserRes.data, + wxLoginCode: userInfo.wxLoginCode + } + } + console.log(newUserInfo) + uni.setStorageSync('userProfile', newUserInfo); } return res[1].data; }, @@ -198,7 +205,7 @@ export default { } if (phoneRes && phoneRes.data) { let userInfo = this.getCurUserInfo(); - await this.updateUserPhone({ + await this.updateUser({ customerId: userInfo.customerId, account: phoneRes.data, phone: phoneRes.data @@ -212,6 +219,19 @@ export default { getCurUserInfo() { let userProfile = uni.getStorageSync('userProfile'); return userProfile; + }, + async getCurUserNoCache() { + let userInfo = this.getCurUserInfo(); + let wxGetUserRes = await this.qryUserInfo(userInfo.openId); + if (!wxGetUserRes.data) { + userInfo = null; + } else { + userInfo = { + ...wxGetUserRes.data, + wxLoginCode: userInfo.wxLoginCode + } + } + return userInfo; }, getProductCategories(params = {}) { return uni.request({ @@ -423,5 +443,13 @@ export default { data: params }) return res[1].data; - }, + }, + async getUnlimitedWxacode(params = {}) { + let res = await uni.request({ + url: '/wx/unlimited/wxacode', + method: 'POST', + data: params + }) + return res[1].data; + } } diff --git a/pages/index/index.vue b/pages/index/index.vue index 494d07d..3ec8325 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -3,14 +3,14 @@ - + - - - - - - + + + + + + @@ -19,38 +19,39 @@ - + 发布任务 公司、家居家政雇佣上门服务 - - - - + + @@ -68,7 +69,7 @@ import moduleBar from '@/components/custom-bar/module-bar.vue'; import index from '@/pages/index/home.vue'; import workerCircle from '@/pages/index/worker-home.vue'; - import personalCenter from '@/pages/index/my-home.vue'; + import personalCenter from '@/pages/index/my-home.vue'; import msgPage from '@/pages/index/msg-home.vue'; // import publishHome from '@/pages/index/publish-home.vue'; @@ -77,7 +78,7 @@ moduleBar, index, workerCircle, - personalCenter, + personalCenter, msgPage // publishHome }, @@ -85,69 +86,127 @@ return { moduleBarInfos: [], curPageCode: 'indexPage', - isShowPublish: false, - forwardingPageCode: null + isShowPublish: false, + forwardingPageCode: null, + curUserInfo: null, + inByShare: false, + inParam: null } }, - onLoad() { - this.loadData(); + onLoad(option) { + if (option && option.scene) { + let paraStr = decodeURIComponent(option.scene); + let kvStrArr = paraStr.split("&"); + kvStrArr.forEach((kvStr) => { + let kvArr = kvStr.split("="); + option[kvArr[0]] = kvArr[1]; + }); + } + this.inParam = option; + this.loadData(option); + }, + onShareAppMessage(e) { + let shareInfo = null; + if (e && e.target && e.target.dataset) { + shareInfo = e.target.dataset.shareInfo; + } + if (!this.curUserInfo) { + this.curUserInfo = this.$request.getCurUserNoCache(); + if (!this.curUserInfo) { + uni.showToast({ + title: '请前往“我的”完成登录', + icon: 'none' + }) + return; + } + } + if (!shareInfo) { + shareInfo = { + title: '家政服务就找工圈子', + path: '/pages/index/index?distributor=' + this.curUserInfo.customerId, + imageUrl: 'http://gqz.opsoul.com/sys/group-selfie.png' + } + } + return shareInfo; }, methods: { - async loadData() { - this.moduleBarInfos = await this.$api.data('moduleBarInfos'); - }, - reloadForwardPage() { - this.getCurPageInfo({ - curPageCode: this.forwardingPageCode - }) - }, - async getCurPageInfo(data) { - let pageCode = data.curPageCode; - this.forwardingPageCode = pageCode; - // 登录校验 - if (['publishPage', 'myPage'].indexOf(pageCode) >= 0) { + async loadData(option) { + this.moduleBarInfos = await this.$api.data('moduleBarInfos'); + this.curUserInfo = this.$request.getCurUserInfo(); + // 更新分销人信息 + if (option && option.distributor) { let loginRes = await this.authLogin(); if (!loginRes) { + this.inByShare = true; return; } - } - this.forwardingPageCode = null; - - if (pageCode === 'publishPage') { - this.isShowPublish = true; + + this.inByShare = false; + let res = await this.$request.updateUser({ + customerPlace: option.distributor, + customerId: this.curUserInfo.customerId + }); + if (res && res.code === 0) { + this.inParam = null; + } + } + }, + reloadForwardPage() { + if (this.inByShare) { + this.loadData(this.inParam); } else { - this.isShowPublish = false; - this.curPageCode = pageCode; - } + this.getCurPageInfo({ + curPageCode: this.forwardingPageCode + }) + } + }, + async getCurPageInfo(data) { + let pageCode = data.curPageCode; + this.forwardingPageCode = pageCode; + // 登录校验 + if (['publishPage', 'myPage'].indexOf(pageCode) >= 0) { + let loginRes = await this.authLogin(); + if (!loginRes) { + return; + } + } + this.forwardingPageCode = null; + + if (pageCode === 'publishPage') { + this.isShowPublish = true; + } else { + this.isShowPublish = false; + this.curPageCode = pageCode; + } }, hidePublish() { this.isShowPublish = false; - }, - showPage(url) { - uni.navigateTo({ - url: url - }) - }, - async authLogin() { - // 更新缓存中的userInfo - let res = await this.$request.storageExistUser(); - // 获取缓存中的userInfo - let curUserInfo = this.$request.getCurUserInfo(); - // 校验提示登录 - if (!curUserInfo || !curUserInfo.openId) { - this.$refs.vertifyLogin.showModal(); - return false; - } else { - this.$refs.vertifyLogin.hideModal(); - } - // 校验提示获取手机号码 - if (!curUserInfo.phone) { - this.$refs.vertifyPhone.showModal(); - return false; - } else { - this.$refs.vertifyPhone.hideModal(); - } - return true; + }, + showPage(url) { + uni.navigateTo({ + url: url + }) + }, + async authLogin() { + // 更新缓存中的userInfo + let res = await this.$request.storageExistUser(); + // 获取缓存中的userInfo + let curUserInfo = this.$request.getCurUserInfo(); + // 校验提示登录 + if (!curUserInfo || !curUserInfo.openId) { + this.$refs.vertifyLogin.showModal(); + return false; + } else { + this.$refs.vertifyLogin.hideModal(); + } + // 校验提示获取手机号码 + if (!curUserInfo.phone) { + this.$refs.vertifyPhone.showModal(); + return false; + } else { + this.$refs.vertifyPhone.hideModal(); + } + return true; } } } @@ -175,25 +234,25 @@ .cu-avatar.first-avatar { background-color: #0081ff; color: #ffffff; - } - - .cu-avatar.second-avatar { - background-color: #fbbd08; - color: #ffffff; - } - - .cu-avatar.third-avatar { - background-color: #f37b1d; - color: #ffffff; - } - - .cu-avatar.fourth-avatar { - background-color: #1cbbb4; - color: #ffffff; - } - - .cu-dialog.bottom-dialog { - background-color: unset; - vertical-align: bottom; + } + + .cu-avatar.second-avatar { + background-color: #fbbd08; + color: #ffffff; + } + + .cu-avatar.third-avatar { + background-color: #f37b1d; + color: #ffffff; + } + + .cu-avatar.fourth-avatar { + background-color: #1cbbb4; + color: #ffffff; + } + + .cu-dialog.bottom-dialog { + background-color: unset; + vertical-align: bottom; } diff --git a/pages/index/my-home.vue b/pages/index/my-home.vue index 6aee92c..88849f3 100644 --- a/pages/index/my-home.vue +++ b/pages/index/my-home.vue @@ -209,10 +209,10 @@ 联系客服 --> - + + + + + + + + 小程序邀请二维码 + + + + + + + + + 请通过扫码或分享链接给好友进行邀请 + + + -