封装分享功能

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, data: data,
}); });
}; };
export const autoGetInviteCode = (data) => {
return request({
url: prveUrl + "/user/distribution/autoGetInviteCode",
method: "get",
data: data,
});
};
// 获取配置 // 获取配置
export const getConfig = (data) => { export const getConfig = (data) => {

View File

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

View File

@@ -5,7 +5,8 @@
<!-- 轮播图 --> <!-- 轮播图 -->
<swipers :carousel="hometoplist.bannerList"></swipers> <swipers :carousel="hometoplist.bannerList"></swipers>
<!-- 广告 --> <!-- 广告 -->
<advertisement :bannervo="hometoplist.freeBannerList" :itemStyle="advertisementStyle" ref="refbannervo"></advertisement> <advertisement :bannervo="hometoplist.freeBannerList" :itemStyle="advertisementStyle" ref="refbannervo">
</advertisement>
<!-- 金刚区 --> <!-- 金刚区 -->
<diamond :district="hometoplist.district"></diamond> <diamond :district="hometoplist.district"></diamond>
<!-- 今日上线 --> <!-- 今日上线 -->
@@ -133,39 +134,67 @@
</template> </template>
<script setup> <script setup>
import CouponModal from '@/components/coupon-modal.vue'; import CouponModal from '@/components/coupon-modal.vue';
import { ref, computed, onMounted, reactive, onBeforeUnmount, watch, getCurrentInstance, nextTick } from 'vue'; import {
import { onLoad, onReady, onShow, onReachBottom, onPageScroll } from '@dcloudio/uni-app'; ref,
// 获取全局属性 computed,
const { proxy } = getCurrentInstance(); onMounted,
import pageLoading from './components/pageLoading.vue'; reactive,
import swipers from './components/swiper.vue'; //引入轮播 onBeforeUnmount,
import advertisement from './components/advertisement.vue'; //广告 watch,
import diamond from './components/diamond.vue'; //金刚区 getCurrentInstance,
import todaylist from './components/todaylist.vue'; //今日上线 nextTick
import indexs from './indexs.vue'; } from 'vue';
import AreaSelect from './components/AreaSelect.vue'; //城市联动 import {
import grouping from './components/grouping.vue'; //其他 onLoad,
import Nav from '@/components/indexnav.vue'; //导航栏 onReady,
import { APIhomehomePageUp, APIhome } from '@/common/api/index/index.js'; onShow,
import { APIgeocodelocation } from '@/common/api/api.js'; onReachBottom,
import { useNavbarStore } from '@/stores/navbarStore'; onPageScroll
import { productStore } from '@/stores/user.js'; } from '@dcloudio/uni-app';
import { getUnReadCountReq } from '../../common/api/account/message'; // 获取全局属性
const store = useNavbarStore(); const {
const storeuser = productStore(); proxy
store.updateNavbarConfig({ } = getCurrentInstance();
import pageLoading from './components/pageLoading.vue';
import swipers from './components/swiper.vue'; //引入轮播
import advertisement from './components/advertisement.vue'; //广告
import diamond from './components/diamond.vue'; //金刚区
import todaylist from './components/todaylist.vue'; //今日上线
import indexs from './indexs.vue';
import AreaSelect from './components/AreaSelect.vue'; //城市联动
import grouping from './components/grouping.vue'; //其他
import Nav from '@/components/indexnav.vue'; //导航栏
import {
APIhomehomePageUp,
APIhome
} from '@/common/api/index/index.js';
import {
APIgeocodelocation
} from '@/common/api/api.js';
import {
useNavbarStore
} from '@/stores/navbarStore';
import {
productStore
} from '@/stores/user.js';
import {
getUnReadCountReq
} from '../../common/api/account/message';
const store = useNavbarStore();
const storeuser = productStore();
store.updateNavbarConfig({
showBack: true, //左边返回键 showBack: true, //左边返回键
rightText: '', //右边文字 rightText: '', //右边文字
showSearch: true, //true是标题其他事文字 showSearch: true, //true是标题其他事文字
title: '我的页面', title: '我的页面',
isTransparent: false, isTransparent: false,
hasPlaceholder: false //是否要占位符 hasPlaceholder: false //是否要占位符
}); });
// 显示 // 显示
const showindex = ref('index'); const showindex = ref('index');
//计算广告图片的重合尺寸是位移 //计算广告图片的重合尺寸是位移
const getStyle = (e) => { const getStyle = (e) => {
if (e > hometoplist.freeBannerList.length / 2) { if (e > hometoplist.freeBannerList.length / 2) {
var right = hometoplist.freeBannerList.length - e; var right = hometoplist.freeBannerList.length - e;
return { return {
@@ -180,13 +209,13 @@ const getStyle = (e) => {
opacity: 1 opacity: 1
}; };
} }
}; };
const advertisementStyle = ref([]); const advertisementStyle = ref([]);
const refbannervo = ref(null); const refbannervo = ref(null);
//数据 //数据
const hometoplist = reactive({}); const hometoplist = reactive({});
// 首页上面数据 // 首页上面数据
const hometop = async () => { const hometop = async () => {
try { try {
let res = await APIhomehomePageUp(); let res = await APIhomehomePageUp();
Object.assign(hometoplist, res); Object.assign(hometoplist, res);
@@ -205,9 +234,9 @@ const hometop = async () => {
.exec(); .exec();
}, 500); }, 500);
} catch (e) {} } catch (e) {}
}; };
// 下面初始数据 // 下面初始数据
const formhomelist = reactive({ const formhomelist = reactive({
//筛选 //筛选
address: '', //地址 address: '', //地址
categoryId: '1', //品类 categoryId: '1', //品类
@@ -218,15 +247,15 @@ const formhomelist = reactive({
status: 'loadmore', status: 'loadmore',
name: '1', name: '1',
list: [] list: []
}); });
// 使用 reactive 创建响应式对象 // 使用 reactive 创建响应式对象
const timeData = ref({}); const timeData = ref({});
// 定义 onChange 方法 // 定义 onChange 方法
const onChange = (e) => { const onChange = (e) => {
timeData.value = e; timeData.value = e;
}; };
const onLoadhome = async () => { const onLoadhome = async () => {
try { try {
let res = await APIhome(formhomelist); let res = await APIhome(formhomelist);
var dates = new Date().getTime(); var dates = new Date().getTime();
@@ -270,9 +299,9 @@ const onLoadhome = async () => {
} }
} }
} catch (e) {} } catch (e) {}
}; };
// /筛选数据处理 // /筛选数据处理
const init_fn = async () => { const init_fn = async () => {
formhomelist.list = []; formhomelist.list = [];
Object.assign(formhomelist, { Object.assign(formhomelist, {
address: uni.cache.get('getLocationstorage').address, //地址 address: uni.cache.get('getLocationstorage').address, //地址
@@ -286,28 +315,28 @@ const init_fn = async () => {
status: 'loadmore' status: 'loadmore'
}); });
onLoadhome(); onLoadhome();
}; };
const orderVIP = ref({ const orderVIP = ref({
shopExtendList: '' shopExtendList: ''
}); });
// 弹出层处理 // 弹出层处理
const showproductlist = ref(false); const showproductlist = ref(false);
// 定义方法 // 定义方法
const openproductlist = (e) => { const openproductlist = (e) => {
hometoplist.menuList[viewHistoryindex.value].name = e; //下标更改name hometoplist.menuList[viewHistoryindex.value].name = e; //下标更改name
showproductlist.value = !showproductlist.value; showproductlist.value = !showproductlist.value;
}; };
// 存储每个元素距离顶部的距离 // 存储每个元素距离顶部的距离
const elementTop = ref(0); const elementTop = ref(0);
// 存储是否吸顶的状态 // 存储是否吸顶的状态
const isSticky = ref(true); const isSticky = ref(true);
//下标 //下标
const viewHistoryindex = ref(null); const viewHistoryindex = ref(null);
// 点击滑动元素 // 点击滑动元素
const viewHistory = async (item, index) => { const viewHistory = async (item, index) => {
if (isSticky) { if (isSticky) {
uni.pageScrollTo({ uni.pageScrollTo({
scrollTop: elementTop.value, scrollTop: elementTop.value,
@@ -316,29 +345,47 @@ const viewHistory = async (item, index) => {
} }
// 是否有弹出层 // 是否有弹出层
if (item.isChild) { if (item.isChild) {
showproductlist.value = showproductlist.value ? (viewHistoryindex.value == index ? false : true) : !showproductlist.value; showproductlist.value = showproductlist.value ? (viewHistoryindex.value == index ? false : true) : !
showproductlist.value;
} }
viewHistoryindex.value = index; viewHistoryindex.value = index;
}; };
// 滑动 // 滑动
onPageScroll((res) => { onPageScroll((res) => {
isSticky.value = res.scrollTop > elementTop.value ? true : false; isSticky.value = res.scrollTop > elementTop.value ? true : false;
uni.$u.debounce((store.scrollTop = res.scrollTop), 500); uni.$u.debounce((store.scrollTop = res.scrollTop), 500);
}); });
const indexsRef = ref(null); const indexsRef = ref(null);
const shopId = ref(null)
const shopInfo = ref(null)
onShow(async () => {
if (!storeuser.isHasLogin) {
await handleMixinOnLoad(options)
console.log('shopInfo', uni.cache.get('shopInfo'));
console.log('【页面】开始处理自身业务逻辑');
setTimeout(() => {
showPageLoading.value = false;
getUnReadMsgCount();
}, 800);
onPageShow()
} else {
onPageShow()
}
onShow(async () => { });
async function onPageShow() {
try { try {
await storeuser.getLocation(); await storeuser.getLocation();
proxy.$isResolve(); proxy.$isResolve();
const shopId = uni.cache.get('shopId'); shopId.value = uni.cache.get('shopId');
if (shopId) { if (shopId.value) {
indexsRef.value.updateData(); indexsRef.value.updateData();
} }
} catch (error) {} } catch (error) {}
await proxy.$onLaunched; await proxy.$onLaunched;
if (uni.cache.get('shopId')) { if (shopId.value) {
showindex.value = 'shopIndex'; showindex.value = 'shopIndex';
await storeuser.actionsproductqueryProduct(); await storeuser.actionsproductqueryProduct();
await nextTick(); await nextTick();
@@ -349,11 +396,13 @@ onShow(async () => {
init_fn(); init_fn();
// 获取初始定位高度 // 获取初始定位高度
} }
});
const showPageLoading = ref(true); shopInfo.value = uni.cache.get('shopInfo');
}
const getUnReadMsgCount = async () => { const showPageLoading = ref(true);
const getUnReadMsgCount = async () => {
let res = await getUnReadCountReq() let res = await getUnReadCountReq()
let badge = Number(res) let badge = Number(res)
@@ -367,30 +416,64 @@ const getUnReadMsgCount = async () => {
index: 2 index: 2
}) })
} }
} }
onMounted(async () => {
setTimeout(() => {
showPageLoading.value = false;
getUnReadMsgCount();
}, 800);
});
onReachBottom(() => { onReachBottom(() => {
onLoadhome(); onLoadhome();
}); });
// 页面离开时清除定时器 import {
// onBeforeUnmount(() => { shareMixin,
// if (refbannervo.value) { handleMixinOnLoad
// refbannervo.value.clearTimer(); } from '@/utils/share.js'
// }
// });
watch(() => shopId.value, (newval) => {
if (newval) {
uni.showShareMenu({
withShareTicket: true, // 可选:是否返回分享票据
menus: ['shareAppMessage', 'shareTimeline'] // 显示「分享好友」和「分享朋友圈」
});
} else {
uni.hideShareMenu();
}
}, {
immediate: true
})
defineOptions({
mixins: [shareMixin],
});
const options = reactive({})
onLoad(async (opt) => {
Object.assign(options, opt)
// await handleMixinOnLoad(options)
// console.log('shopInfo', uni.cache.get('shopInfo'));
// console.log('【页面】开始处理自身业务逻辑');
// setTimeout(() => {
// showPageLoading.value = false;
// getUnReadMsgCount();
// }, 800);
})
// 页面离开时清除定时器
// onBeforeUnmount(() => {
// if (refbannervo.value) {
// refbannervo.value.clearTimer();
// }
// });
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.content { .content {
background: #f9f9f9; background: #f9f9f9;
.fourcontent { .fourcontent {
@@ -702,5 +785,5 @@ onReachBottom(() => {
} }
} }
} }
} }
</style> </style>

View File

@@ -2,9 +2,11 @@
<view class="content min-page bg-f7"> <view class="content min-page bg-f7">
<view class="contentbox"> <view class="contentbox">
<template v-if="shopExtend.length"> <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 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> <image class="swiper-bg" :src="item"></image>
</swiper-item> </swiper-item>
</swiper> </swiper>
@@ -118,15 +120,28 @@
</template> </template>
<script setup> <script setup>
import attractPopup from '@/components/attract-popup.vue'; import attractPopup from '@/components/attract-popup.vue';
import { homeData } from '@/common/api/market/index.js'; import {
import { getMemberConfig, getRechargeConfig } from '@/common/api/index/index.js'; homeData
import { ref, reactive, defineProps, defineEmits, onMounted } from 'vue'; } from '@/common/api/market/index.js';
import { isJsonArrayString } from '@/utils/util.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 = { const imgs = {
recharge: 'https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/4/2f22c0ced494497e8d6f981832b191c9.png', 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', 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', vip: 'https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/4/cfc3bf5ba12747c6ada4d5a388aceca3.png',
@@ -138,75 +153,79 @@ const imgs = {
code: 'https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/4/044dcaf913054f03a9db7983f048b1e6.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', 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' taocan: 'https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/4/1eb9aa9b865b47b39ab9d7ac404601a9.png'
}; };
// 定义接收的属性 // 定义接收的属性
const props = defineProps({ const props = defineProps({
shopExtend: { shopExtend: {
type: Array, type: Array,
default: [] default: []
} }
}); });
function toGroupBuying() { function toGroupBuying() {
uni.navigateTo({ uni.navigateTo({
url: '/groupBuying/index/index' url: '/groupBuying/index/index'
}); });
} }
function toFenxiao() { function toFenxiao() {
uni.navigateTo({ uni.navigateTo({
url: '/distribution/shop-detail/index?shopId=' + uni.cache.get('shopId') url: '/distribution/shop-detail/index?shopId=' + uni.cache.get('shopId')
}); });
} }
function toIntegralMall() { function toIntegralMall() {
uni.navigateTo({ uni.navigateTo({
url: '/scoreShop/index/index?shopId=' + uni.cache.get('shopId') url: '/scoreShop/index/index?shopId=' + uni.cache.get('shopId')
}); });
} }
import { productStore } from '@/stores/user.js'; import {
import { onShow } from '@dcloudio/uni-app'; productStore
} from '@/stores/user.js';
import {
onShow
} from '@dcloudio/uni-app';
// 显示弹窗 // 显示弹窗
const popupShow = ref(false); const popupShow = ref(false);
const scanCodehandle = (i) => { const scanCodehandle = (i) => {
popupShow.value = true; popupShow.value = true;
}; };
// 预点单 // 预点单
function beforehandOrderHandle() { function beforehandOrderHandle() {
popupShow.value = false; popupShow.value = false;
uni.cache.set('dinersNum', 1); uni.cache.set('dinersNum', 1);
uni.cache.set('tableCode', shopUserInfo.id); uni.cache.set('tableCode', shopUserInfo.id);
uni.navigateTo({ uni.navigateTo({
url: '/pages/product/index?type=beforehand' url: '/pages/product/index?type=beforehand'
}); });
} }
// 扫码点餐 // 扫码点餐
async function scanOrderHandle() { async function scanOrderHandle() {
popupShow.value = false; popupShow.value = false;
const store = productStore(); const store = productStore();
await store.scanCodeactions(); await store.scanCodeactions();
} }
function toTaocan() { function toTaocan() {
uni.navigateTo({ uni.navigateTo({
url: '/userPackage/index/index' url: '/userPackage/index/index'
}); });
} }
const memberindex = (url) => { const memberindex = (url) => {
uni.pro.navigateTo(url, { uni.pro.navigateTo(url, {
shopId: uni.cache.get('shopId'), shopId: uni.cache.get('shopId'),
type: 'index' type: 'index'
}); });
}; };
const shopUserInfo = reactive({}); const shopUserInfo = reactive({});
Object.assign(shopUserInfo, uni.cache.get('shopUserInfo') || {}); Object.assign(shopUserInfo, uni.cache.get('shopUserInfo') || {});
function tomember() { function tomember() {
if (isMember.value) { if (isMember.value) {
const shopId = uni.cache.get('shopId'); const shopId = uni.cache.get('shopId');
if (!shopUserInfo.isVip) { if (!shopUserInfo.isVip) {
@@ -224,9 +243,9 @@ function tomember() {
icon: 'none' icon: 'none'
}); });
} }
} }
function toCharge() { function toCharge() {
if (isCharge.value) { if (isCharge.value) {
const shopId = uni.cache.get('shopId'); const shopId = uni.cache.get('shopId');
uni.navigateTo({ uni.navigateTo({
@@ -238,8 +257,8 @@ function toCharge() {
icon: 'none' icon: 'none'
}); });
} }
} }
const getQueryString = (url, name) => { const getQueryString = (url, name) => {
//解码 //解码
var reg = new RegExp('(^|&|/?)' + name + '=([^&|/?]*)(&|/?|$)', 'i'); var reg = new RegExp('(^|&|/?)' + name + '=([^&|/?]*)(&|/?|$)', 'i');
var r = url.substr(1).match(reg); var r = url.substr(1).match(reg);
@@ -247,12 +266,12 @@ const getQueryString = (url, name) => {
return r[2]; return r[2];
} }
return null; return null;
}; };
// 获取会员配置 // 获取会员配置
const isMember = ref(0); const isMember = ref(0);
const isCharge = ref(0); const isCharge = ref(0);
async function getVipConfig() { async function getVipConfig() {
try { try {
const res1 = await getMemberConfig({ const res1 = await getMemberConfig({
shopId: uni.cache.get('shopId') shopId: uni.cache.get('shopId')
@@ -266,43 +285,46 @@ async function getVipConfig() {
} catch (error) { } catch (error) {
console.log(error); console.log(error);
} }
} }
const allConfig = reactive({ const allConfig = reactive({
takeout: 0, takeout: 0,
group: 0, group: 0,
pointsMall: 0, pointsMall: 0,
distribution: 0, distribution: 0,
couponNum: 0, couponNum: 0,
pointNum: 0 pointNum: 0
}); });
function getHomeData() { function getHomeData() {
homeData().then((res) => { homeData().then((res) => {
Object.assign(allConfig, res); Object.assign(allConfig, res);
imgs.defaultAvatar = res.userAvatar ? res.userAvatar : imgs.defaultAvatar; imgs.defaultAvatar = res.userAvatar ? res.userAvatar : imgs.defaultAvatar;
}); });
} }
onMounted(() => { onMounted(() => {
updateData(); updateData();
}); });
function updateData() { function updateData() {
Object.assign(shopUserInfo, uni.cache.get('shopUserInfo') || {}); Object.assign(shopUserInfo, uni.cache.get('shopUserInfo') || {});
getVipConfig(); getVipConfig();
getHomeData(); getHomeData();
} }
defineExpose({ defineExpose({
updateData updateData
}); });
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
page { page {
background: #f6f8fa; background: #f6f8fa;
} }
.swiper { .swiper {
width: 100%; width: 100%;
height: 100%; height: 100%;
@@ -315,9 +337,9 @@ page {
height: 100%; height: 100%;
} }
} }
} }
.content { .content {
.contentbox { .contentbox {
position: relative; position: relative;
width: 100%; width: 100%;
@@ -405,9 +427,9 @@ page {
} }
} }
} }
} }
.popup-content { .popup-content {
width: 90vw; width: 90vw;
background-color: #fff; background-color: #fff;
border-radius: 8px; border-radius: 8px;
@@ -446,9 +468,9 @@ page {
width: 248upx; width: 248upx;
} }
} }
} }
.menus { .menus {
display: flex; display: flex;
padding: 32rpx 40rpx; padding: 32rpx 40rpx;
margin-top: 150rpx; margin-top: 150rpx;
@@ -462,9 +484,9 @@ page {
box-shadow: 0rpx 6rpx 12rpx 2rpx rgba(0, 0, 0, 0.16); box-shadow: 0rpx 6rpx 12rpx 2rpx rgba(0, 0, 0, 0.16);
flex: 1; flex: 1;
} }
} }
.userInfo { .userInfo {
display: flex; display: flex;
padding: 22rpx 24rpx; padding: 22rpx 24rpx;
margin: 0 4rpx; margin: 0 4rpx;
@@ -489,9 +511,9 @@ page {
width: 33px; width: 33px;
height: 33px; height: 33px;
} }
} }
.new-menus-box { .new-menus-box {
margin: 0 16rpx 0 16rpx; margin: 0 16rpx 0 16rpx;
.new-menus { .new-menus {
@@ -523,8 +545,7 @@ page {
background: #ededed; background: #ededed;
} }
.takeout { .takeout {}
}
} }
&.layout1 { &.layout1 {
@@ -549,9 +570,9 @@ page {
} }
} }
} }
} }
.groupBuying { .groupBuying {
padding: 16rpx 38rpx; padding: 16rpx 38rpx;
border-top: 2rpx solid #ededed; border-top: 2rpx solid #ededed;
background-color: #fff; background-color: #fff;
@@ -563,21 +584,21 @@ page {
width: 40px; width: 40px;
height: 40px; height: 40px;
} }
} }
.title { .title {
color: #333333; color: #333333;
font-size: 36rpx; font-size: 36rpx;
font-weight: 700; font-weight: 700;
} }
.desc { .desc {
margin-top: 16rpx; margin-top: 16rpx;
font-size: 28rpx; font-size: 28rpx;
color: #999; color: #999;
} }
.points { .points {
margin-top: 10px; margin-top: 10px;
background-color: #fff; background-color: #fff;
padding: 16rpx 68rpx; padding: 16rpx 68rpx;
@@ -590,16 +611,16 @@ page {
width: 98px; width: 98px;
height: 98px; height: 98px;
} }
} }
.taocan { .taocan {
.img { .img {
width: 117px; width: 117px;
height: 117px; height: 117px;
} }
} }
.bottom_menus { .bottom_menus {
display: flex; display: flex;
gap: 14rpx; gap: 14rpx;
margin-top: 10px; margin-top: 10px;
@@ -629,5 +650,5 @@ page {
white-space: nowrap; white-space: nowrap;
} }
} }
} }
</style> </style>

View File

@@ -749,7 +749,7 @@
useCartStore useCartStore
} from '@/stores/order.js'; } from '@/stores/order.js';
import { import {
computed, provide computed, provide, reactive
} from 'vue'; } from 'vue';
const cartStore = useCartStore(); const cartStore = useCartStore();
/** /**
@@ -2437,27 +2437,50 @@
}); });
} }
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) => { onLoad(async (e) => {
Object.assign(pageOptions,e)
if (e.type) { if (e.type) {
orderType.value = e.type; orderType.value = e.type;
} }
//获取用户信息 await handleMixinOnLoad(e)
const userInfo = await APIshopUserInfo({ const userInfo= userStore.userInfo
shopId: uni.cache.get('shopId') const shopInfoRes=userStore.shopInfo
}) // //获取用户信息
//获取店铺信息 // const userInfo = await APIshopUserInfo({
const shopInfoRes = await APIusershopInfodetail({ // shopId: uni.cache.get('shopId')
shopId: uni.cache.get('shopId') // })
}); // //获取店铺信息
// const shopInfoRes = await APIusershopInfodetail({
// shopId: uni.cache.get('shopId')
// });
if (shopInfoRes && shopInfoRes.shopInfo) { if (shopInfoRes && shopInfoRes.shopInfo) {
Object.assign(shopInfo, shopInfoRes.shopInfo); Object.assign(shopInfo, shopInfoRes.shopInfo);
uni.cache.set('shopInfo', shopInfoRes.shopInfo)
} }
if (userInfo && typeof userInfo === 'object') { if (userInfo && typeof userInfo === 'object') {
shopUserInfo.value = userInfo shopUserInfo.value = userInfo
uni.cache.set('shopUserInfo', userInfo)
} }
await productqueryProduct(); await productqueryProduct();

View File

@@ -49,7 +49,7 @@ export const Storelogin = defineStore("login", {
rawData: infoRes.rawData, rawData: infoRes.rawData,
source: "wechat", source: "wechat",
}); });
console.log('APIuserlogin',res); console.log('APIuserlogin', res);
if (res) { if (res) {
this.token = res.token; this.token = res.token;
this.miniAppOpenId = res.userInfo this.miniAppOpenId = res.userInfo
@@ -110,12 +110,90 @@ export const productStore = defineStore("product", {
latitude: "", latitude: "",
longitude: "", longitude: "",
}, },
token: "",
miniAppOpenId: "",
userInfo: "",
shopId: uni.cache.get('shopId') || '',
shopInfo: { shopInfo: {
shopId: "", shopId: "",
isOrderFence: 0, isOrderFence: 0,
id: '',
}, },
shopUserInfo:{
},
isHasLogin:false
}), }),
actions: { 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() { getLocation() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
console.log("获取经纬度"); console.log("获取经纬度");
@@ -185,7 +263,7 @@ export const productStore = defineStore("product", {
console.log("扫码内容", q); console.log("扫码内容", q);
// #ifdef H5 // #ifdef H5
uni.navigateTo({ uni.navigateTo({
url:'/pages/product/index' url: '/pages/product/index'
}) })
return return
// #endif // #endif
@@ -448,19 +526,41 @@ export const productStore = defineStore("product", {
// 通过shopId 获取店铺会员信息 // 通过shopId 获取店铺会员信息
actionsproductqueryProduct() { actionsproductqueryProduct() {
console.log('actionsproductqueryProduct:token',uni.cache.get('token'));
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
try { try {
let res = await APIshopUserInfo(); let res = await APIshopUserInfo();
if(res&& typeof res === 'object'){
this.shopUserInfo=res;
uni.cache.set("shopUserInfo", res); uni.cache.set("shopUserInfo", res);
uni.cache.set("orderVIP", res); uni.cache.set("orderVIP", res);
uni.cache.set("ordershopUserInfo", res.shopInfo); uni.cache.set("ordershopUserInfo", res.shopInfo);
resolve(res); resolve(res);
}else{
reject(false);
}
} catch (e) { } catch (e) {
reject(false); 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() { actionsAPIuser() {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {

View File

@@ -1,7 +1,15 @@
import { import {
autoBindInviteUser autoBindInviteUser,
autoGetInviteCode
} from '@/common/api/market/distribution.js' } 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(); const accountInfo = wx.getAccountInfoSync();
export const envVersion = accountInfo.miniProgram.envVersion; export const envVersion = accountInfo.miniProgram.envVersion;
let type = 3; let type = 3;
@@ -53,3 +61,237 @@ export function wxShare(par) {
type 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
};
}
};