封装分享功能

This commit is contained in:
2026-01-21 09:40:31 +08:00
parent a125995808
commit c60a2115ea
7 changed files with 1423 additions and 945 deletions

View File

@@ -136,6 +136,15 @@ export const getInviteCode = (data) => {
data: data,
});
};
export const autoGetInviteCode = (data) => {
return request({
url: prveUrl + "/user/distribution/autoGetInviteCode",
method: "get",
data: data,
});
};
// 获取配置
export const getConfig = (data) => {

View File

@@ -1,6 +1,6 @@
// const debug = process.env.NODE_ENV == 'development' ? true : false;
// const debug = false; // false线上 true本地
const debug = false; // false线上 true本地
const debug = true; // false线上 true本地
let baseUrl = ''
let baseUrlwws = ''

File diff suppressed because it is too large Load Diff

View File

@@ -2,9 +2,11 @@
<view class="content min-page bg-f7">
<view class="contentbox">
<template v-if="shopExtend.length">
<image class="bg" :src="shopExtend[0].value" mode="aspectFill" v-if="!isJsonArrayString(shopExtend[0].value)"></image>
<image class="bg" :src="shopExtend[0].value" mode="aspectFill"
v-if="!isJsonArrayString(shopExtend[0].value)"></image>
<swiper class="swiper" autoplay circular v-else>
<swiper-item class="swiper-item" v-for="(item, index) in JSON.parse(shopExtend[0].value)" :key="index">
<swiper-item class="swiper-item" v-for="(item, index) in JSON.parse(shopExtend[0].value)"
:key="index">
<image class="swiper-bg" :src="item"></image>
</swiper-item>
</swiper>
@@ -118,516 +120,535 @@
</template>
<script setup>
import attractPopup from '@/components/attract-popup.vue';
import { homeData } from '@/common/api/market/index.js';
import { getMemberConfig, getRechargeConfig } from '@/common/api/index/index.js';
import { ref, reactive, defineProps, defineEmits, onMounted } from 'vue';
import { isJsonArrayString } from '@/utils/util.js';
import attractPopup from '@/components/attract-popup.vue';
import {
homeData
} from '@/common/api/market/index.js';
import {
getMemberConfig,
getRechargeConfig
} from '@/common/api/index/index.js';
import {
ref,
reactive,
defineProps,
defineEmits,
onMounted
} from 'vue';
import {
isJsonArrayString
} from '@/utils/util.js';
const attractPopupRef = ref(null);
const attractPopupRef = ref(null);
const imgs = {
recharge: 'https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/4/2f22c0ced494497e8d6f981832b191c9.png',
share: 'https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/4/bcb8d461e96d445ba40256079da775b3.png',
vip: 'https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/4/cfc3bf5ba12747c6ada4d5a388aceca3.png',
orderFood: 'https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/4/7c54a22d56f44813bf3f76c1a82a34f3.png',
big_orderFood: 'https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/4/b3c7f6139eff4a7d81482cf533ec79fa.png',
takeout: 'https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/4/3623cbf425d845a993acb4309404a7b9.png',
groupBuying: 'https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/4/117745e0f3db48b489f9d4e5c5967043.png',
points: 'https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/4/df0758f7b86449f89f882e50226e17c7.png',
code: 'https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/4/044dcaf913054f03a9db7983f048b1e6.png',
defaultAvatar: 'https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/4/b98d2c7110e847f996e8d7ba4342f0a5.png',
taocan: 'https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/4/1eb9aa9b865b47b39ab9d7ac404601a9.png'
};
// 定义接收的属性
const props = defineProps({
shopExtend: {
type: Array,
default: []
}
});
function toGroupBuying() {
uni.navigateTo({
url: '/groupBuying/index/index'
});
}
function toFenxiao() {
uni.navigateTo({
url: '/distribution/shop-detail/index?shopId=' + uni.cache.get('shopId')
});
}
function toIntegralMall() {
uni.navigateTo({
url: '/scoreShop/index/index?shopId=' + uni.cache.get('shopId')
});
}
import { productStore } from '@/stores/user.js';
import { onShow } from '@dcloudio/uni-app';
// 显示弹窗
const popupShow = ref(false);
const scanCodehandle = (i) => {
popupShow.value = true;
};
// 预点单
function beforehandOrderHandle() {
popupShow.value = false;
uni.cache.set('dinersNum', 1);
uni.cache.set('tableCode', shopUserInfo.id);
uni.navigateTo({
url: '/pages/product/index?type=beforehand'
});
}
// 扫码点餐
async function scanOrderHandle() {
popupShow.value = false;
const store = productStore();
await store.scanCodeactions();
}
function toTaocan() {
uni.navigateTo({
url: '/userPackage/index/index'
});
}
const memberindex = (url) => {
uni.pro.navigateTo(url, {
shopId: uni.cache.get('shopId'),
type: 'index'
});
};
const shopUserInfo = reactive({});
Object.assign(shopUserInfo, uni.cache.get('shopUserInfo') || {});
function tomember() {
if (isMember.value) {
const shopId = uni.cache.get('shopId');
if (!shopUserInfo.isVip) {
uni.navigateTo({
url: '/user/vip/buy-vip?shopId=' + shopId
});
return;
const imgs = {
recharge: 'https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/4/2f22c0ced494497e8d6f981832b191c9.png',
share: 'https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/4/bcb8d461e96d445ba40256079da775b3.png',
vip: 'https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/4/cfc3bf5ba12747c6ada4d5a388aceca3.png',
orderFood: 'https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/4/7c54a22d56f44813bf3f76c1a82a34f3.png',
big_orderFood: 'https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/4/b3c7f6139eff4a7d81482cf533ec79fa.png',
takeout: 'https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/4/3623cbf425d845a993acb4309404a7b9.png',
groupBuying: 'https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/4/117745e0f3db48b489f9d4e5c5967043.png',
points: 'https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/4/df0758f7b86449f89f882e50226e17c7.png',
code: 'https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/4/044dcaf913054f03a9db7983f048b1e6.png',
defaultAvatar: 'https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/4/b98d2c7110e847f996e8d7ba4342f0a5.png',
taocan: 'https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/4/1eb9aa9b865b47b39ab9d7ac404601a9.png'
};
// 定义接收的属性
const props = defineProps({
shopExtend: {
type: Array,
default: []
}
uni.navigateTo({
url: '/user/vip/vip?shopId=' + shopId
});
} else {
uni.showToast({
title: '暂未开放',
icon: 'none'
});
}
}
function toCharge() {
if (isCharge.value) {
const shopId = uni.cache.get('shopId');
uni.navigateTo({
url: '/pages/user/member/czzx?shopId=' + shopId
});
} else {
uni.showToast({
title: '暂未开放',
icon: 'none'
});
}
}
const getQueryString = (url, name) => {
//解码
var reg = new RegExp('(^|&|/?)' + name + '=([^&|/?]*)(&|/?|$)', 'i');
var r = url.substr(1).match(reg);
if (r != null) {
return r[2];
}
return null;
};
// 获取会员配置
const isMember = ref(0);
const isCharge = ref(0);
async function getVipConfig() {
try {
const res1 = await getMemberConfig({
shopId: uni.cache.get('shopId')
});
const res2 = await getRechargeConfig({
shopId: uni.cache.get('shopId')
});
isMember.value = +res1.memberConfig.isOpen;
isCharge.value = +res2.isEnable;
} catch (error) {
console.log(error);
}
}
const allConfig = reactive({
takeout: 0,
group: 0,
pointsMall: 0,
distribution: 0,
couponNum: 0,
pointNum: 0
});
function getHomeData() {
homeData().then((res) => {
Object.assign(allConfig, res);
imgs.defaultAvatar = res.userAvatar ? res.userAvatar : imgs.defaultAvatar;
});
}
onMounted(() => {
updateData();
});
function updateData() {
function toGroupBuying() {
uni.navigateTo({
url: '/groupBuying/index/index'
});
}
function toFenxiao() {
uni.navigateTo({
url: '/distribution/shop-detail/index?shopId=' + uni.cache.get('shopId')
});
}
function toIntegralMall() {
uni.navigateTo({
url: '/scoreShop/index/index?shopId=' + uni.cache.get('shopId')
});
}
import {
productStore
} from '@/stores/user.js';
import {
onShow
} from '@dcloudio/uni-app';
// 显示弹窗
const popupShow = ref(false);
const scanCodehandle = (i) => {
popupShow.value = true;
};
// 预点单
function beforehandOrderHandle() {
popupShow.value = false;
uni.cache.set('dinersNum', 1);
uni.cache.set('tableCode', shopUserInfo.id);
uni.navigateTo({
url: '/pages/product/index?type=beforehand'
});
}
// 扫码点餐
async function scanOrderHandle() {
popupShow.value = false;
const store = productStore();
await store.scanCodeactions();
}
function toTaocan() {
uni.navigateTo({
url: '/userPackage/index/index'
});
}
const memberindex = (url) => {
uni.pro.navigateTo(url, {
shopId: uni.cache.get('shopId'),
type: 'index'
});
};
const shopUserInfo = reactive({});
Object.assign(shopUserInfo, uni.cache.get('shopUserInfo') || {});
getVipConfig();
getHomeData();
}
defineExpose({
updateData
});
function tomember() {
if (isMember.value) {
const shopId = uni.cache.get('shopId');
if (!shopUserInfo.isVip) {
uni.navigateTo({
url: '/user/vip/buy-vip?shopId=' + shopId
});
return;
}
uni.navigateTo({
url: '/user/vip/vip?shopId=' + shopId
});
} else {
uni.showToast({
title: '暂未开放',
icon: 'none'
});
}
}
function toCharge() {
if (isCharge.value) {
const shopId = uni.cache.get('shopId');
uni.navigateTo({
url: '/pages/user/member/czzx?shopId=' + shopId
});
} else {
uni.showToast({
title: '暂未开放',
icon: 'none'
});
}
}
const getQueryString = (url, name) => {
//解码
var reg = new RegExp('(^|&|/?)' + name + '=([^&|/?]*)(&|/?|$)', 'i');
var r = url.substr(1).match(reg);
if (r != null) {
return r[2];
}
return null;
};
// 获取会员配置
const isMember = ref(0);
const isCharge = ref(0);
async function getVipConfig() {
try {
const res1 = await getMemberConfig({
shopId: uni.cache.get('shopId')
});
const res2 = await getRechargeConfig({
shopId: uni.cache.get('shopId')
});
isMember.value = +res1.memberConfig.isOpen;
isCharge.value = +res2.isEnable;
} catch (error) {
console.log(error);
}
}
const allConfig = reactive({
takeout: 0,
group: 0,
pointsMall: 0,
distribution: 0,
couponNum: 0,
pointNum: 0
});
function getHomeData() {
homeData().then((res) => {
Object.assign(allConfig, res);
imgs.defaultAvatar = res.userAvatar ? res.userAvatar : imgs.defaultAvatar;
});
}
onMounted(() => {
updateData();
});
function updateData() {
Object.assign(shopUserInfo, uni.cache.get('shopUserInfo') || {});
getVipConfig();
getHomeData();
}
defineExpose({
updateData
});
</script>
<style scoped lang="scss">
page {
background: #f6f8fa;
}
page {
background: #f6f8fa;
}
.swiper {
width: 100%;
height: 100%;
.swiper-item {
.swiper {
width: 100%;
height: 100%;
.swiper-bg {
.swiper-item {
width: 100%;
height: 100%;
.swiper-bg {
width: 100%;
height: 100%;
}
}
}
}
.content {
.contentbox {
position: relative;
width: 100%;
height: 430rpx;
.bg {
.content {
.contentbox {
position: relative;
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
z-index: -1;
}
height: 430rpx;
.contentboxitem {
position: absolute;
bottom: 0;
width: 90%;
left: 50%;
transform: translate(-50%, 50%);
padding: 38rpx 0 26rpx 0;
background: rgba(255, 255, 255, 0.98);
box-shadow: 0rpx 6rpx 12rpx 2rpx rgba(0, 0, 0, 0.16);
border-radius: 20rpx 20rpx 20rpx 20rpx;
.contentboxitemleft {
width: 50%;
border-right: 2rpx solid #623618;
image {
width: 134rpx;
height: 134rpx;
}
.contentboxitemlefttextone {
margin-top: 10rpx;
font-family: Source Han Sans CN, Source Han Sans CN;
font-weight: 400;
font-size: 32rpx;
color: #333333;
}
.contentboxitemlefttexttow {
margin-top: 2rpx;
font-family: Source Han Sans CN, Source Han Sans CN;
font-weight: 400;
font-size: 24rpx;
color: #999999;
}
.bg {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
z-index: -1;
}
.contentboxitemright {
width: 50%;
padding: 0 34rpx;
.contentboxitem {
position: absolute;
bottom: 0;
width: 90%;
left: 50%;
transform: translate(-50%, 50%);
padding: 38rpx 0 26rpx 0;
background: rgba(255, 255, 255, 0.98);
box-shadow: 0rpx 6rpx 12rpx 2rpx rgba(0, 0, 0, 0.16);
border-radius: 20rpx 20rpx 20rpx 20rpx;
.contentboxitemright_item:nth-child(2) {
margin-top: 30rpx;
}
.contentboxitemleft {
width: 50%;
border-right: 2rpx solid #623618;
.contentboxitemright_item {
image {
width: 96rpx;
height: 96rpx;
width: 134rpx;
height: 134rpx;
}
.contentboxitemright_itembox {
width: 170rpx;
.contentboxitemlefttextone {
margin-top: 10rpx;
font-family: Source Han Sans CN, Source Han Sans CN;
font-weight: 400;
font-size: 32rpx;
color: #333333;
}
text:nth-child(1) {
font-family: Source Han Sans CN, Source Han Sans CN;
font-weight: 400;
font-size: 32rpx;
color: #333333;
.contentboxitemlefttexttow {
margin-top: 2rpx;
font-family: Source Han Sans CN, Source Han Sans CN;
font-weight: 400;
font-size: 24rpx;
color: #999999;
}
}
.contentboxitemright {
width: 50%;
padding: 0 34rpx;
.contentboxitemright_item:nth-child(2) {
margin-top: 30rpx;
}
.contentboxitemright_item {
image {
width: 96rpx;
height: 96rpx;
}
text:nth-child(2) {
margin-top: 2rpx;
font-family: Source Han Sans CN, Source Han Sans CN;
font-weight: 400;
font-size: 24rpx;
color: #999999;
.contentboxitemright_itembox {
width: 170rpx;
text:nth-child(1) {
font-family: Source Han Sans CN, Source Han Sans CN;
font-weight: 400;
font-size: 32rpx;
color: #333333;
}
text:nth-child(2) {
margin-top: 2rpx;
font-family: Source Han Sans CN, Source Han Sans CN;
font-weight: 400;
font-size: 24rpx;
color: #999999;
}
}
}
}
}
}
}
}
.popup-content {
width: 90vw;
background-color: #fff;
border-radius: 8px;
.popup-content {
width: 90vw;
background-color: #fff;
border-radius: 8px;
.header-wrap {
height: 64px;
display: flex;
align-items: center;
justify-content: space-between;
border-bottom: 1px solid #ececec;
padding: 0 28upx;
.header-wrap {
height: 64px;
display: flex;
align-items: center;
justify-content: space-between;
border-bottom: 1px solid #ececec;
padding: 0 28upx;
.t {
font-size: 32upx;
color: #333;
.t {
font-size: 32upx;
color: #333;
}
.close {
$size: 60upx;
width: $size;
height: $size;
display: flex;
align-items: center;
justify-content: center;
}
}
.close {
$size: 60upx;
width: $size;
height: $size;
.btn-content {
height: 86px;
display: flex;
align-items: center;
justify-content: center;
gap: 60upx;
.btn {
width: 248upx;
}
}
}
.btn-content {
height: 86px;
.menus {
display: flex;
align-items: center;
justify-content: center;
gap: 60upx;
padding: 32rpx 40rpx;
margin-top: 150rpx;
gap: 20rpx;
.btn {
width: 248upx;
.menu-item {
background-color: #fff;
border-radius: 16rpx;
text-align: center;
padding: 32rpx 28rpx;
box-shadow: 0rpx 6rpx 12rpx 2rpx rgba(0, 0, 0, 0.16);
flex: 1;
}
}
}
.menus {
display: flex;
padding: 32rpx 40rpx;
margin-top: 150rpx;
gap: 20rpx;
.menu-item {
background-color: #fff;
border-radius: 16rpx;
text-align: center;
padding: 32rpx 28rpx;
box-shadow: 0rpx 6rpx 12rpx 2rpx rgba(0, 0, 0, 0.16);
flex: 1;
}
}
.userInfo {
display: flex;
padding: 22rpx 24rpx;
margin: 0 4rpx;
align-items: center;
align-self: stretch;
border-radius: 24rpx;
background: #fff;
position: relative;
z-index: 99;
margin-top: -36rpx;
.vip {
background: #fa720a;
font-size: 24rpx;
color: #ffffff;
padding: 6rpx 10rpx;
margin-left: 10rpx;
border-radius: 20rpx 20rpx 20rpx 0;
}
.code {
width: 33px;
height: 33px;
}
}
.new-menus-box {
margin: 0 16rpx 0 16rpx;
.new-menus {
.userInfo {
display: flex;
background-color: #fff;
border-radius: 16rpx;
padding: 22rpx 24rpx;
margin: 0 4rpx;
align-items: center;
align-self: stretch;
border-radius: 24rpx;
background: #fff;
position: relative;
z-index: 99;
margin-top: -36rpx;
.icon {
width: 79px;
height: 79px;
.vip {
background: #fa720a;
font-size: 24rpx;
color: #ffffff;
padding: 6rpx 10rpx;
margin-left: 10rpx;
border-radius: 20rpx 20rpx 20rpx 0;
}
&.layout2 {
padding: 29px 0;
.diner,
.takeout {
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.line {
width: 2rpx;
height: 156rpx;
background: #ededed;
}
.takeout {
}
.code {
width: 33px;
height: 33px;
}
}
&.layout1 {
padding: 36rpx 40rpx;
justify-content: space-between;
.new-menus-box {
margin: 0 16rpx 0 16rpx;
.new-menus {
display: flex;
background-color: #fff;
border-radius: 16rpx;
align-items: center;
.big_img {
width: 330rpx;
height: 330rpx;
.icon {
width: 79px;
height: 79px;
}
&.layout2 {
padding: 29px 0;
.diner,
.takeout {
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.line {
width: 2rpx;
height: 156rpx;
background: #ededed;
}
.takeout {}
}
&.layout1 {
padding: 36rpx 40rpx;
justify-content: space-between;
display: flex;
align-items: center;
.big_img {
width: 330rpx;
height: 330rpx;
}
.title {
font-size: 48rpx;
}
.desc {
margin-top: 20rpx;
font-size: 32rpx;
color: #999;
}
}
}
}
.groupBuying {
padding: 16rpx 38rpx;
border-top: 2rpx solid #ededed;
background-color: #fff;
display: flex;
justify-content: space-between;
align-items: center;
.img {
width: 40px;
height: 40px;
}
}
.title {
color: #333333;
font-size: 36rpx;
font-weight: 700;
}
.desc {
margin-top: 16rpx;
font-size: 28rpx;
color: #999;
}
.points {
margin-top: 10px;
background-color: #fff;
padding: 16rpx 68rpx;
border-radius: 16rpx;
display: flex;
align-items: center;
justify-content: space-between;
.img {
width: 98px;
height: 98px;
}
}
.taocan {
.img {
width: 117px;
height: 117px;
}
}
.bottom_menus {
display: flex;
gap: 14rpx;
margin-top: 10px;
.item {
flex: 1;
display: flex;
padding: 20rpx;
flex-direction: column;
align-items: center;
border-radius: 18rpx;
background: #fff;
.img {
width: 39px;
height: 39px;
}
.title {
font-size: 48rpx;
font-size: 32rpx;
}
.desc {
margin-top: 20rpx;
font-size: 32rpx;
margin-top: 8rpx;
color: #999;
font-size: 24rpx;
white-space: nowrap;
}
}
}
}
.groupBuying {
padding: 16rpx 38rpx;
border-top: 2rpx solid #ededed;
background-color: #fff;
display: flex;
justify-content: space-between;
align-items: center;
.img {
width: 40px;
height: 40px;
}
}
.title {
color: #333333;
font-size: 36rpx;
font-weight: 700;
}
.desc {
margin-top: 16rpx;
font-size: 28rpx;
color: #999;
}
.points {
margin-top: 10px;
background-color: #fff;
padding: 16rpx 68rpx;
border-radius: 16rpx;
display: flex;
align-items: center;
justify-content: space-between;
.img {
width: 98px;
height: 98px;
}
}
.taocan {
.img {
width: 117px;
height: 117px;
}
}
.bottom_menus {
display: flex;
gap: 14rpx;
margin-top: 10px;
.item {
flex: 1;
display: flex;
padding: 20rpx;
flex-direction: column;
align-items: center;
border-radius: 18rpx;
background: #fff;
.img {
width: 39px;
height: 39px;
}
.title {
font-size: 32rpx;
}
.desc {
margin-top: 8rpx;
color: #999;
font-size: 24rpx;
white-space: nowrap;
}
}
}
</style>
</style>

View File

@@ -749,7 +749,7 @@
useCartStore
} from '@/stores/order.js';
import {
computed, provide
computed, provide, reactive
} from 'vue';
const cartStore = useCartStore();
/**
@@ -2436,28 +2436,51 @@
}
});
}
import {
shareMixin,
handleMixinOnLoad,returnQuery
} from '@/utils/share.js'
defineOptions({
mixins: [shareMixin],
});
onShareAppMessage((res)=>{
let query=returnQuery()
query+='&type=beforehand'
return {
...res,
...query,
path: '/pages/product/index' + '?' + query,
query,
}
})
const pageOptions=reactive({})
onLoad(async (e) => {
Object.assign(pageOptions,e)
if (e.type) {
orderType.value = e.type;
}
//获取用户信息
const userInfo = await APIshopUserInfo({
shopId: uni.cache.get('shopId')
})
//获取店铺信息
const shopInfoRes = await APIusershopInfodetail({
shopId: uni.cache.get('shopId')
});
await handleMixinOnLoad(e)
const userInfo= userStore.userInfo
const shopInfoRes=userStore.shopInfo
// //获取用户信息
// const userInfo = await APIshopUserInfo({
// shopId: uni.cache.get('shopId')
// })
// //获取店铺信息
// const shopInfoRes = await APIusershopInfodetail({
// shopId: uni.cache.get('shopId')
// });
if (shopInfoRes && shopInfoRes.shopInfo) {
Object.assign(shopInfo, shopInfoRes.shopInfo);
uni.cache.set('shopInfo', shopInfoRes.shopInfo)
}
if (userInfo && typeof userInfo === 'object') {
shopUserInfo.value = userInfo
uni.cache.set('shopUserInfo', userInfo)
}
await productqueryProduct();

View File

@@ -49,7 +49,7 @@ export const Storelogin = defineStore("login", {
rawData: infoRes.rawData,
source: "wechat",
});
console.log('APIuserlogin',res);
console.log('APIuserlogin', res);
if (res) {
this.token = res.token;
this.miniAppOpenId = res.userInfo
@@ -110,12 +110,90 @@ export const productStore = defineStore("product", {
latitude: "",
longitude: "",
},
token: "",
miniAppOpenId: "",
userInfo: "",
shopId: uni.cache.get('shopId') || '',
shopInfo: {
shopId: "",
isOrderFence: 0,
id: '',
},
shopUserInfo:{
},
isHasLogin:false
}),
actions: {
actionslogin() {
return new Promise(async (resolve, reject) => {
// #ifdef MP-WEIXIN
uni.login({
provider: "weixin",
success: (data) => {
// 微信小程序环境
uni.getUserInfo({
provider: "weixin",
success: async (infoRes) => {
let res = await APIuserlogin({
code: data.code, //临时登录凭证
rawData: infoRes.rawData,
source: "wechat",
});
console.log('APIuserlogin', res);
if (res) {
this.token = res.token;
this.isHasLogin=true
this.miniAppOpenId = res.userInfo
.miniAppOpenId;
this.userInfo = res.userInfo;
uni.cache.set("token", res.token);
uni.cache.set("userInfo", res.userInfo);
uni.cache.set("followIndex", res
.followIndex || "");
}
resolve(true);
},
fail: (err) => {
reject(false);
},
});
},
});
// #endif
// #ifdef MP-ALIPAY
my.getAuthCode({
scopes: "auth_base",
success: async (data) => {
// 支付宝小程序环境
// my.getAuthUserInfo({
// success: async (infoRes) => {
let res = await APIuserlogin({
code: data.authCode, //临时登录凭证
// rawData: JSON.stringify(infoRes),
source: "alipay",
});
if (res) {
this.isHasLogin=true
this.token = res.token;
this.miniAppOpenId = res.userInfo.miniAppOpenId;
this.userInfo = res.userInfo;
uni.cache.set("token", res.token);
uni.cache.set("openId", res.userInfo.alipayOpenId);
uni.cache.set("userInfo", res.userInfo);
resolve(true);
}
},
fail: () => {
reject(false);
},
});
// #endif
// #ifdef H5
resolve(true)
// #endif
});
},
getLocation() {
return new Promise((resolve, reject) => {
console.log("获取经纬度");
@@ -185,11 +263,11 @@ export const productStore = defineStore("product", {
console.log("扫码内容", q);
// #ifdef H5
uni.navigateTo({
url:'/pages/product/index'
url: '/pages/product/index'
})
return
return
// #endif
return new Promise(async (resolve, reject) => {
if (q) {
console.log(q);
@@ -448,19 +526,41 @@ export const productStore = defineStore("product", {
// 通过shopId 获取店铺会员信息
actionsproductqueryProduct() {
console.log('actionsproductqueryProduct:token',uni.cache.get('token'));
return new Promise(async (resolve, reject) => {
try {
let res = await APIshopUserInfo();
uni.cache.set("shopUserInfo", res);
uni.cache.set("orderVIP", res);
uni.cache.set("ordershopUserInfo", res.shopInfo);
resolve(res);
if(res&& typeof res === 'object'){
this.shopUserInfo=res;
uni.cache.set("shopUserInfo", res);
uni.cache.set("orderVIP", res);
uni.cache.set("ordershopUserInfo", res.shopInfo);
resolve(res);
}else{
reject(false);
}
} catch (e) {
reject(false);
}
});
},
async pageOnload() {
//登录
await this.actionslogin()
//获取会员信息
await this.actionsproductqueryProduct()
//获取店铺信息
await this.getShopInfo()
},
async getShopInfo(shopId) {
const shopRes = await APIusershopInfodetail({
shopId: this.shopId || shopId,
});
this.shopInfo = shopRes.shopInfo;
uni.cache.set("shopInfo", shopRes.shopInfo);
},
// 用户信息获取
actionsAPIuser() {
return new Promise(async (resolve, reject) => {

View File

@@ -1,7 +1,15 @@
import {
autoBindInviteUser
autoBindInviteUser,
autoGetInviteCode
} from '@/common/api/market/distribution.js'
import {
APIshopUserInfo,
APIusershopInfodetail
} from '@/common/api/member.js'
import {
productStore
} from '@/stores/user.js';
const accountStore = productStore();
const accountInfo = wx.getAccountInfoSync();
export const envVersion = accountInfo.miniProgram.envVersion;
let type = 3;
@@ -32,7 +40,7 @@ export function bindInvite(args) {
shopUserId,
shopId,
inviteCode
} = args;
} = args;
// 校验邀请码有效性若邀请码为空、null、undefined则直接返回不执行后续绑定逻辑
if (!inviteCode || inviteCode === null || inviteCode === undefined) {
@@ -52,4 +60,238 @@ export function wxShare(par) {
...par,
type
}
}
}
export async function returnQuery(query) {
const shopId = uni.cache.get('shopId')
const shopUserInfo = uni.cache.get('shopUserInfo')
const shopInfo = uni.cache.get('shopInfo')
const inviteCode = await autoGetInviteCode({
shopId: shopId,
shopUserId: shopUserInfo.id
})
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
const currentPath = currentPage.route;
const currentOptions = currentPage.options;
let sharePath = `/${currentPath}`;
const queryJson = {
inviteCode: (inviteCode && inviteCode !== true) ? inviteCode : null,
shopId,
shopUserId: shopUserInfo.id,
...query
}
for (const key in currentOptions) {
if (currentOptions.hasOwnProperty(key)) {
queryJson[key] = encodeURIComponent(currentOptions[key])
}
}
queryJson.shopId = shopId
queryJson.inviteCode = (inviteCode && inviteCode !== true) ? inviteCode : null
queryJson.shopUserId = shopUserInfo.id
let result = ''
for (let key in queryJson) {
if (queryJson[key]) {
if (result === '') {
result += `${key}=${queryJson[key]}`
} else {
result += `&${key}=${queryJson[key]}`
}
}
}
return result
}
function parseQueryString(queryString) {
const queryParams = queryString.split("&").map((param) => param.split("="));
const params = {};
for (const [key, value] of queryParams) {
params[key] = value;
}
return params;
}
/**
* 混入的 onLoad 核心逻辑(抽成独立函数)
* @param {Object} opt - 页面 onLoad 接收的参数
* @param {Object} vm - 组件实例this
*/
export async function handleMixinOnLoad(opt, vm) {
console.log('onLoad');
const options = {}
if (opt.q) {
const q = decodeURIComponent(opt.q);
const params = parseQueryString(q.split("?")[1]);
Object.assign(options, params);
} else {
Object.assign(options, opt);
}
console.log('options', options);
if (options.shopId) {
uni.cache.set('shopId', options.shopId)
accountStore.shopId = options.shopId
await accountStore.pageOnload()
}
uni.setStorageSync('loadFinsh', true)
// const shopId = uni.cache.get('shopId')
// const shopUserInfo = uni.cache.get('shopUserInfo')
// const shopInfo = uni.cache.get('shopInfo')
// const inviteCode = await autoGetInviteCode({
// shopId: shopId,
// shopUserId: shopUserInfo.id
// })
if (options.inviteCode) {
bindInvite(options)
}
}
// utils/share.js
export const shareMixin = {
// async onLoad(opt) {
// console.log('onLoad');
// const options = {}
// if (opt.q) {
// const q = decodeURIComponent(opt.q);
// const params = parseQueryString(q.split("?")[1]);
// Object.assign(options, params);
// } else {
// Object.assign(options, opt);
// }
// console.log('options', options);
// if (options.shopId) {
// uni.cache.set('shopId', options.shopId)
// }
// const shopId = uni.cache.get('shopId')
// const shopUserInfo = uni.cache.get('shopUserInfo')
// const shopInfo = uni.cache.get('shopInfo')
// const inviteCode = await autoGetInviteCode({
// shopId: shopId,
// shopUserId: shopUserInfo.id
// })
// uni.setStorageSync('loadFinsh',true)
// if (options.inviteCode) {
// bindInvite(options)
// }
// },
async onShareAppMessage(res) {
// const shopId = uni.cache.get('shopId')
// const shopUserInfo = uni.cache.get('shopUserInfo')
const shopInfo = uni.cache.get('shopInfo')
// const inviteCode = await autoGetInviteCode({
// shopId: shopId,
// shopUserId: shopUserInfo.id
// })
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
const currentPath = currentPage.route;
const currentOptions = currentPage.options;
let sharePath = `/${currentPath}`;
// const queryJson = {
// inviteCode: (inviteCode && inviteCode !== true) ? inviteCode : null,
// shopId,
// shopUserId: shopUserInfo.id,
// }
// for (const key in currentOptions) {
// if (currentOptions.hasOwnProperty(key)) {
// queryJson[key] = encodeURIComponent(currentOptions[key])
// }
// }
// queryJson.shopId = shopId
// queryJson.inviteCode = (inviteCode && inviteCode !== true) ? inviteCode : null
// queryJson.shopUserId = shopUserInfo.id
const query = returnQuery()
// 全局默认配置(可被页面覆盖)
const defaultShareConfig = {
title: shopInfo.shopName,
path: sharePath + '?' + query,
imageUrl: shopInfo.logo,
query,
// desc: '描述',
success: (res) => {
console.log('分享好友成功', res);
// 可加埋点等统一逻辑
},
fail: (err) => {
console.error('分享好友失败', err);
}
};
// 页面自定义配置覆盖全局
const pageShareConfig = this.$options.shareConfig || {};
console.log('mixIn onShareAppMessage', {
...defaultShareConfig,
...pageShareConfig
})
return {
...defaultShareConfig,
...pageShareConfig
};
},
async onShareTimeline() {
// const shopId = uni.cache.get('shopId')
// const shopUserInfo = uni.cache.get('shopUserInfo')
const shopInfo = uni.cache.get('shopInfo')
// const inviteCode = await autoGetInviteCode({
// shopId: shopId,
// shopUserId: shopUserInfo.id
// })
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
const currentPath = currentPage.route;
const currentOptions = currentPage.options;
let sharePath = `/${currentPath}`;
// const queryJson = {
// inviteCode: (inviteCode && inviteCode !== true) ? inviteCode : null,
// shopId,
// shopUserId: shopUserInfo.id,
// }
// for (const key in currentOptions) {
// if (currentOptions.hasOwnProperty(key)) {
// queryJson[key] = encodeURIComponent(currentOptions[key])
// }
// }
// queryJson.shopId = shopId
// queryJson.inviteCode = (inviteCode && inviteCode !== true) ? inviteCode : null
// queryJson.shopUserId = shopUserInfo.id
const query = returnQuery()
const defaultTimelineConfig = {
title: shopInfo.shopName,
path: sharePath + '?' + query,
imageUrl: shopInfo.logo,
query,
};
const pageTimelineConfig = this.$options.shareTimelineConfig || {};
return {
...defaultTimelineConfig,
...pageTimelineConfig
};
}
};