二维码分享功能

This commit is contained in:
donqi 2022-07-14 00:39:45 +08:00
parent ed9a8ccd88
commit 3ac990eb63
4 changed files with 308 additions and 122 deletions

View File

@ -10,9 +10,9 @@ export default {
title: '加载中' title: '加载中'
}) })
// request 触发前拼接 url // 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://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) { if (args.data) {
args.data.deptId = globalData.deptId; args.data.deptId = globalData.deptId;
args.data.from = globalData.from; args.data.from = globalData.from;
@ -172,7 +172,7 @@ export default {
}) })
return res[1].data; return res[1].data;
}, },
async updateUserPhone(params = {}) { async updateUser(params = {}) {
let res = await uni.request({ let res = await uni.request({
url: '/customer/update', url: '/customer/update',
method: 'POST', method: 'POST',
@ -181,9 +181,16 @@ export default {
// 更新用户信息的方法顺便更新本地缓存 // 更新用户信息的方法顺便更新本地缓存
if (res[1].data.code === 0) { if (res[1].data.code === 0) {
let userInfo = this.getCurUserInfo(); let userInfo = this.getCurUserInfo();
userInfo.phone = params.phone; let wxGetUserRes = await this.qryUserInfo(userInfo.openId);
userInfo.account = params.account; let newUserInfo;
uni.setStorageSync('userProfile', userInfo); if (wxGetUserRes.data) {
newUserInfo = {
...wxGetUserRes.data,
wxLoginCode: userInfo.wxLoginCode
}
}
console.log(newUserInfo)
uni.setStorageSync('userProfile', newUserInfo);
} }
return res[1].data; return res[1].data;
}, },
@ -198,7 +205,7 @@ export default {
} }
if (phoneRes && phoneRes.data) { if (phoneRes && phoneRes.data) {
let userInfo = this.getCurUserInfo(); let userInfo = this.getCurUserInfo();
await this.updateUserPhone({ await this.updateUser({
customerId: userInfo.customerId, customerId: userInfo.customerId,
account: phoneRes.data, account: phoneRes.data,
phone: phoneRes.data phone: phoneRes.data
@ -213,6 +220,19 @@ export default {
let userProfile = uni.getStorageSync('userProfile'); let userProfile = uni.getStorageSync('userProfile');
return 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 = {}) { getProductCategories(params = {}) {
return uni.request({ return uni.request({
url: '/goods/deptcategory/app/list', url: '/goods/deptcategory/app/list',
@ -424,4 +444,12 @@ export default {
}) })
return res[1].data; return res[1].data;
}, },
async getUnlimitedWxacode(params = {}) {
let res = await uni.request({
url: '/wx/unlimited/wxacode',
method: 'POST',
data: params
})
return res[1].data;
}
} }

View File

@ -19,7 +19,8 @@
<view class="cu-avatar round middle-avatar first-avatar"> <view class="cu-avatar round middle-avatar first-avatar">
<view class="cuIcon-formfill"></view> <view class="cuIcon-formfill"></view>
</view> </view>
<view class="flex flex-column-around text-left margin-left-sm text-white" @click="showPage('/pages/publish/publish-task')"> <view class="flex flex-column-around text-left margin-left-sm text-white"
@click="showPage('/pages/publish/publish-task')">
<view class="text-xl">发布任务</view> <view class="text-xl">发布任务</view>
<view>公司家居家政雇佣上门服务</view> <view>公司家居家政雇佣上门服务</view>
</view> </view>
@ -86,20 +87,78 @@
moduleBarInfos: [], moduleBarInfos: [],
curPageCode: 'indexPage', curPageCode: 'indexPage',
isShowPublish: false, isShowPublish: false,
forwardingPageCode: null forwardingPageCode: null,
curUserInfo: null,
inByShare: false,
inParam: null
} }
}, },
onLoad() { onLoad(option) {
this.loadData(); 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: { methods: {
async loadData() { async loadData(option) {
this.moduleBarInfos = await this.$api.data('moduleBarInfos'); 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.inByShare = false;
let res = await this.$request.updateUser({
customerPlace: option.distributor,
customerId: this.curUserInfo.customerId
});
if (res && res.code === 0) {
this.inParam = null;
}
}
}, },
reloadForwardPage() { reloadForwardPage() {
this.getCurPageInfo({ if (this.inByShare) {
curPageCode: this.forwardingPageCode this.loadData(this.inParam);
}) } else {
this.getCurPageInfo({
curPageCode: this.forwardingPageCode
})
}
}, },
async getCurPageInfo(data) { async getCurPageInfo(data) {
let pageCode = data.curPageCode; let pageCode = data.curPageCode;

View File

@ -209,10 +209,10 @@
<view class="cuIcon-servicefill text-olive"></view> <view class="cuIcon-servicefill text-olive"></view>
<text>联系客服</text> <text>联系客服</text>
</view> --> </view> -->
<!-- <view class="cu-item"> <view class="cu-item" @click="showAppInviteQrcode">
<view class="cuIcon-qr_code text-green"></view> <view class="cuIcon-qr_code text-green"></view>
<text>二维码分享</text> <text>二维码分享</text>
</view> --> </view>
<!-- <view class="cu-item"> <!-- <view class="cu-item">
<view class="cuIcon-moneybagfill text-cyan"></view> <view class="cuIcon-moneybagfill text-cyan"></view>
<text>钱包</text> <text>钱包</text>
@ -251,13 +251,39 @@
</view> </view>
</view> --> </view> -->
</view> </view>
<!-- app二维码分享 -->
<view class="cu-modal" :class="appShareQrcodeModal?'show':''">
<view class="cu-dialog bg-white">
<view class="cu-bar bg-white justify-end">
<view class="content">小程序邀请二维码</view>
<view class="action" @click="hideModal" data-modal="appShareQrcodeModal">
<text class="cuIcon-close text-red"></text>
</view>
</view>
<view class="padding-tb-sm">
<image :src="'data:image/png;base64,' + appQrcode" mode="aspectFit"></image>
</view>
<view class="text-center padding">
<view class="padding-bottom-sm text-lg">请通过扫码或分享链接给好友进行邀请</view>
<button class="cu-btn bg-main-color shadow-blur" open-type="share">
<text class="cuIcon-share"></text>
<text>分享链接给好友</text>
</button>
</view>
</view>
</view>
</view> </view>
</template> </template>
<script> <script>
// import appInviteQrcode from '@/pages/my/app-invite-qrcode.vue';
export default { export default {
name: 'personal-center', name: 'personal-center',
components: {}, // components: {
// appInviteQrcode
// },
data() { data() {
return { return {
pageContentTop: this.CustomBar, pageContentTop: this.CustomBar,
@ -302,7 +328,10 @@
type: -1, type: -1,
name: '已完成' name: '已完成'
}], }],
productOrderType: 1 productOrderType: 1,
appQrcode: '',
appShareQrcodeModal: false
} }
}, },
onReady() { onReady() {
@ -342,6 +371,13 @@
url: '/pages/my/apply-operator' url: '/pages/my/apply-operator'
}) })
}, },
async showAppInviteQrcode() {
let res = await this.$request.getUnlimitedWxacode({
scene: "distributor=" + this.curUserInfo.customerId
});
this.appQrcode = res.data;
this.appShareQrcodeModal = true;
},
showPage(pageUrl) { showPage(pageUrl) {
if (pageUrl) { if (pageUrl) {
uni.navigateTo({ uni.navigateTo({
@ -353,6 +389,9 @@
title: '功能开发中' title: '功能开发中'
}) })
} }
},
hideModal(e) {
this[e.currentTarget.dataset.modal] = false;
} }
} }
} }

View File

@ -0,0 +1,60 @@
<template>
<!-- 报价/客户支付模态框 -->
<view class="cu-modal" :class="show?'show':''">
<view class="cu-dialog bg-white">
<view class="cu-bar bg-white justify-end">
<view class="content">小程序邀请二维码</view>
<view class="action" @click="hideModal">
<text class="cuIcon-close text-red"></text>
</view>
</view>
<view class="padding-tb-sm">
<image :src="'data:image/png;base64,' + url"></image>
</view>
<view class="text-center">
<view>请通过扫码或分享链接给好友进行邀请</view>
<button class="cu-btn bg-main-color shadow-blur" open-type="share" :data-shareInfo="shareInfo"
style="width: 100%;">
<text class="cuIcon-share"></text>
<text>分享链接给好友</text>
</button>
</view>
</view>
</view>
</template>
<script>
export default {
nama: 'app-invite-qrcode',
data() {
return {
url: '',
show: false,
shareTemplate: {
title: '家政服务就找工圈子',
path: '/pages/index/index?customerPlace=',
imageUrl: 'http://gqz.opsoul.com/sys/group-selfie.png'
},
shareInfo: null
}
},
methods: {
showModal(url) {
this.show = true;
this.url = url;
let curUserInfo = this.$request.getCurUserInfo();
if (curUserInfo.customerId && curUserInfo.customerId > 0) {
let path = this.shareTemplate.path + curUserInfo.customerId;
this.shareInfo = {
...this.shareTemplate,
path: path
}
}
},
hideModal() {
this.shareInfo = null;
this.show = false;
}
}
}
</script>