refactor: 重构多个组件以支持 Vue 3 语法和功能

- 将多个组件转换为 `<script setup>` 语法,提升可读性和性能
- 优化状态管理和事件处理逻辑,简化代码结构
- 更新样式和布局以适应新组件结构
- 添加新功能和修复已知问题,提升用户体验
This commit is contained in:
Yer11214
2026-07-08 18:37:11 +08:00
parent 4d0b0fb5e4
commit 349ffa4f34
189 changed files with 18278 additions and 20758 deletions

View File

@@ -17,7 +17,7 @@
</div>
<div class="flex price-box">
<div class="purchase-price">
当前:<span>{{ activityData.surplusPrice == 0 ? this.bargains.purchasePrice :unitPrice(activityData.surplusPrice)}}</span>
当前:<span>{{ activityData.surplusPrice == 0 ? bargains.purchasePrice : unitPrice(activityData.surplusPrice)}}</span>
</div>
<div class="max-price">原价:<span>{{unitPrice(bargainDetail.price)}}</span>
@@ -47,7 +47,7 @@
</div>
</div>
<!-- 我要开团 -->
<div class="start" v-if="activityData.memberId != isLogin().id" @click="startOpenGroup">我要开团
<div class="start" v-if="activityData.memberId != loginUser.id" @click="startOpenGroup">我要开团
</div>
</div>
</div>
@@ -84,7 +84,7 @@
<u-modal title="恭喜您砍掉了" v-model:show="Bargaining" mask-close-able :show-confirm-button="false"
:title-style="{color: lightColor}">
<view class="slot-content">
<u-count-to :start-val="0" ref="uCountTo" font-size="100" :color="lightColor" :end-val="kanjiaPrice"
<u-count-to :start-val="0" ref="uCountToRef" font-size="100" :color="lightColor" :end-val="kanjiaPrice"
:decimals="2" :autoplay="autoplay"></u-count-to><span class="price"></span>
</view>
</u-modal>
@@ -103,233 +103,226 @@
:goodsName="bargainDetail.goodsName" v-if="shareFlage " />
<!-- 购买 -->
<popupGoods ref="popupGoods" :buyMask="maskFlag" @closeBuy="closePopupBuy" :goodsDetail="bargainDetail"
<popupGoods ref="popupGoodsRef" :buyMask="maskFlag" @closeBuy="closePopupBuy" :goodsDetail="bargainDetail"
:goodsSpec="goodsSpec" v-if="bargainDetail.id " @handleClickSku="getGoodsDetail" />
</div>
</div>
</template>
<script>
import popupGoods from "@/components/m-buy/goods"; //购物车商品的模块
<script setup lang="ts">
import { ref, computed, watch, nextTick } from 'vue'
import { onLoad, onShow } from '@dcloudio/uni-app'
// #ifdef MP-WEIXIN
import { onShareAppMessage } from '@dcloudio/uni-app'
// #endif
import { useStore } from '@/store'
import popupGoods from '@/components/m-buy/goods'
import {
getBargainDetail,
getBargainActivity,
openBargain,
getBargainLog,
helpBargain,
} from "@/api/promotions";
import shares from "@/components/m-share/index";
import config from "@/config/config";
export default {
components: {
shares,
popupGoods,
},
data() {
return {
style: {
img:"display:block"
},
background: {
backgroundColor: "transparent",
},
maskFlag: false, //商品弹框
shareFlage: false,
lightColor: this.$lightColor,
bargains: {},
bargainDetail: {}, //砍价商品详情
Bargaining: false, //砍价弹出框
helpBargainFlage: false, //帮砍弹出框
autoplay: false, //砍价金额滚动
kanjiaPrice: 0, //砍价金额
totalPercent: 0, //砍价半分比
activityData: "", //砍价活动
cutPrice: 0, //已砍金额
params: {
// id: "", //砍价活动ID
// kanjiaActivityGoodsId: "", //砍价商品SkuID
// kanjiaActivityId: "", //邀请活动ID有值说明是被邀请人
// status: "", //状态
},
} from '@/api/promotions'
import shares from '@/components/m-share/index'
import config from '@/config/config'
import { unitPrice, noPassByName, isLogin } from '@/utils/filters.js'
logData: [], // 帮砍记录
//获取帮砍记录参数
logParams: {
pageNumber: 1,
pageSize: 20,
kanJiaActivityId: "",
},
const store = useStore()
goodsDetail: {}, //商品详情
goodsSpec: {}, //商品规格
selectedGoods: "", //选择的商品
};
},
onLoad(options) {
this.routerVal = options;
if (options.activityId) {
this.params.kanjiaActivityId = options.activityId;
const lightColor = computed(() => store.getters.lightColor)
const style = ref({
img: 'display:block',
})
const background = ref({
backgroundColor: 'transparent',
})
const maskFlag = ref(false)
const shareFlage = ref(false)
const bargains = ref<any>({})
const bargainDetail = ref<any>({})
const Bargaining = ref(false)
const helpBargainFlage = ref(false)
const autoplay = ref(false)
const kanjiaPrice = ref(0)
const totalPercent = ref(0)
const activityData = ref<any>({})
const cutPrice = ref<number | string>(0)
const params = ref<Record<string, any>>({})
const logData = ref<any[]>([])
const logParams = ref({
pageNumber: 1,
pageSize: 20,
kanJiaActivityId: '',
})
const goodsSpec = ref<any>({})
const routerVal = ref<Record<string, string>>({})
const loginUser = computed(() => isLogin() || {})
const popupGoodsRef = ref<any>(null)
const uCountToRef = ref<any>(null)
onLoad((options) => {
routerVal.value = options || {}
if (options?.activityId) {
params.value.kanjiaActivityId = options.activityId
}
})
// #ifdef MP-WEIXIN
onShareAppMessage(() => {
return {
path: share(),
title: `请快来帮我砍一刀${bargainDetail.value.goodsName}`,
imageUrl: bargainDetail.value.thumbnail || config.logo,
}
})
// #endif
onShow(() => {
init()
})
watch(Bargaining, (val) => {
if (val) {
nextTick(() => {
uCountToRef.value?.start?.()
})
}
})
watch(
activityData,
(val) => {
if (val) {
totalPercent.value =
100 -
Math.floor((val.surplusPrice / bargainDetail.value.price) * 100)
cutPrice.value = (
bargainDetail.value.price - activityData.value.surplusPrice
).toFixed(2)
logParams.value.kanJiaActivityId = val.id
if (params.value.kanjiaActivityId && val.help) {
helpBargainFlage.value = true
}
getBargainLogList()
}
},
{ immediate: true }
)
// #ifdef MP-WEIXIN
onShareAppMessage(res) {
return {
path: this.share(),
title: `请快来帮我砍一刀${this.bargainDetail.goodsName}`,
imageUrl: this.bargainDetail.thumbnail || config.logo,
};
},
// #endif
function share() {
return (
'/pages/promotion/bargain/detail?id=' +
routerVal.value.id +
'&activityId=' +
activityData.value.id
)
}
onShow() {
this.init();
},
watch: {
// 砍价弹窗
Bargaining(val) {
if (val) {
this.$nextTick(() => {
this.$refs.uCountTo.start();
});
}
},
// 监听砍价活动金额
activityData: {
handler(val) {
if (val) {
// 计算砍价百分比
this.totalPercent =
100 -
Math.floor((val.surplusPrice / this.bargainDetail.price) * 100);
this.cutPrice = (
this.bargainDetail.price - this.activityData.surplusPrice
).toFixed(2);
// 获取砍价日志
this.logParams.kanJiaActivityId = val.id;
function back() {
if (getCurrentPages().length > 1) {
uni.navigateBack()
} else {
uni.redirectTo({
url: `/pages/promotion/bargain/list`,
})
}
}
// 判断是否是帮砍
if (this.params.kanjiaActivityId && val.help) {
this.helpBargainFlage = true;
}
function startOpenGroup() {
uni.redirectTo({
url: `/pages/promotion/bargain/list`,
})
}
this.getBargainLogList();
}
},
immediate: true,
},
},
methods: {
share() {
return (
"/pages/promotion/bargain/detail?id=" +
this.routerVal.id +
"&activityId=" +
this.activityData.id
);
},
// 返回上一级
back() {
// 进行路由栈判定如果当前路由栈是空的就返回拼团列表页面
if (getCurrentPages().length > 1) {
uni.navigateBack();
} else {
uni.redirectTo({
url: `/pages/promotion/bargain/list`,
});
}
},
function closePopupBuy() {
maskFlag.value = false
}
// 跳转选择商品页面
startOpenGroup() {
uni.redirectTo({
url: `/pages/promotion/bargain/list`,
});
},
closePopupBuy(val) {
this.maskFlag = false;
},
closeShare() {
this.shareFlage = false;
},
// 邀请砍价
shareBargain() {
this.shareFlage = true;
},
function closeShare() {
shareFlage.value = false
}
// 获取商品详情
getGoodsDetail() {
uni.showLoading({
title: "加载中",
mask: true,
});
this.$refs.popupGoods.buy({
skuId: this.bargainDetail.id,
id: this.routerVal.id,
num: 1,
cartType: "KANJIA",
});
},
function shareBargain() {
shareFlage.value = true
}
// 初始化商品以及砍价活动
async init() {
// 获取商品
let res = await getBargainDetail(this.routerVal.id);
if (res.data.success) {
this.bargainDetail = res.data.result.goodsSku;
this.bargains = res.data.result;
// 被邀请活动id
if (this.params.kanjiaActivityId) {
} else {
this.params.kanjiaActivityGoodsId = this.routerVal.id;
}
// 获取砍价活动
this.activity();
}
},
// 获取砍价活动
async activity() {
let res = await getBargainActivity(this.params);
// 判断当前是否是第一次进入,如果是第一次进入默认砍一刀
res.data.success
? res.data.result.launch
? (this.activityData = res.data.result)
: this.openActivity()
: "";
},
// 分页获取砍价活动-帮砍记录
async getBargainLogList() {
let res = await getBargainLog(this.logParams);
if (res.data.success) {
this.logData = res.data.result.records;
}
},
// 帮忙砍一刀
async handleClickHelpBargain() {
let res = await helpBargain(this.params.kanjiaActivityId);
if (res.data.success) {
this.helpBargainFlage = false;
this.kanjiaPrice = res.data.result.kanjiaPrice;
this.Bargaining = true;
// 帮砍完成之后查询帮砍记录
this.init();
} else {
this.helpBargainFlage = false;
}
},
// 发起砍价活动
async openActivity(data) {
let res = await openBargain({ id: this.routerVal.id });
if (res.data.success) {
this.kanjiaPrice = res.data.result.kanjiaPrice;
this.Bargaining = true;
// 查询帮砍记录
this.init();
}
},
},
};
function getGoodsDetail() {
uni.showLoading({
title: '加载中',
mask: true,
})
popupGoodsRef.value?.buy({
skuId: bargainDetail.value.id,
id: routerVal.value.id,
num: 1,
cartType: 'KANJIA',
})
}
async function init() {
const res = await getBargainDetail(routerVal.value.id)
if (res.data.success) {
bargainDetail.value = res.data.result.goodsSku
bargains.value = res.data.result
if (!params.value.kanjiaActivityId) {
params.value.kanjiaActivityGoodsId = routerVal.value.id
}
activity()
}
}
async function activity() {
const res = await getBargainActivity(params.value)
if (res.data.success) {
if (res.data.result.launch) {
activityData.value = res.data.result
} else {
openActivity()
}
}
}
async function getBargainLogList() {
const res = await getBargainLog(logParams.value)
if (res.data.success) {
logData.value = res.data.result.records
}
}
async function handleClickHelpBargain() {
const res = await helpBargain(params.value.kanjiaActivityId)
if (res.data.success) {
helpBargainFlage.value = false
kanjiaPrice.value = res.data.result.kanjiaPrice
Bargaining.value = true
init()
} else {
helpBargainFlage.value = false
}
}
async function openActivity() {
const res = await openBargain({ id: routerVal.value.id })
if (res.data.success) {
kanjiaPrice.value = res.data.result.kanjiaPrice
Bargaining.value = true
init()
}
}
</script>
<style lang="scss">
page {

View File

@@ -15,58 +15,53 @@
</div>
</template>
<script>
import { getBargainList } from "@/api/promotions";
<script setup lang="ts">
import { ref } from 'vue'
import { onShow, onReachBottom } from '@dcloudio/uni-app'
import { getBargainList } from '@/api/promotions'
import goodsTemplate from '@/components/m-goods-list/promotion'
export default {
components:{goodsTemplate},
data() {
return {
background: {
backgroundColor: "transparent",
},
params: {
promotionStatus: "START", //开始/上架
pageNumber: 1,
pageSize: 20,
},
bargainList: [], //砍价活动列表
};
},
onShow() {
this.params.pageNumber = 1;
this.bargainList = [];
this.init();
},
onReachBottom() {
this.params.pageNumber++;
this.init();
},
methods: {
// 返回上一级
back() {
uni.switchTab({
url: "/pages/tabbar/home/index",
});
},
/**
* 初始化砍价列表
*/
async init() {
let res = await getBargainList(this.params); //砍价列表
if (res.data.success) {
this.bargainList.push(...res.data.result.records);
}
},
// 跳转到砍价详情
navigateToBargainDetail(val) {
uni.navigateTo({
url: `/pages/promotion/bargain/detail?id=${val.id}`,
});
},
},
};
const background = ref({
backgroundColor: 'transparent',
})
const params = ref({
promotionStatus: 'START',
pageNumber: 1,
pageSize: 20,
})
const bargainList = ref<any[]>([])
onShow(() => {
params.value.pageNumber = 1
bargainList.value = []
init()
})
onReachBottom(() => {
params.value.pageNumber++
init()
})
function back() {
uni.switchTab({
url: '/pages/tabbar/home/index',
})
}
async function init() {
const res = await getBargainList(params.value)
if (res.data.success) {
bargainList.value.push(...res.data.result.records)
}
}
function navigateToBargainDetail(val: any) {
uni.navigateTo({
url: `/pages/promotion/bargain/detail?id=${val.id}`,
})
}
</script>
<style lang="scss">
page {
@@ -129,4 +124,4 @@ page {
.empty {
height: 400rpx;
}
</style>
</style>

View File

@@ -1,80 +1,80 @@
<template>
<div class="box">
<div v-if="bargainLog.length != 0">
<div v-for="(item,index) in bargainLog" class="flex" :key="index">
<div>
<u-image border-radius="20" width='230' height="230" :src="item.thumbnail"></u-image>
</div>
<div class="goods">
<div class="wes-2">
<view class="box">
<view v-if="bargainLog.length != 0">
<view v-for="(item,index) in bargainLog" class="flex" :key="index">
<view class="goods-img">
<u-image radius="20rpx" width="230rpx" height="230rpx" :src="item.thumbnail"></u-image>
</view>
<view class="goods">
<view class="wes-2">
{{item.goodsName}}
</div>
<div>
还剩<span class="surplusPrice">{{unitPrice(item.surplusPrice)}}</span>
</div>
</view>
<view class="surplus">
还剩<text class="surplusPrice">{{unitPrice(item.surplusPrice)}}</text>
</view>
<div @click="navigateToBargainDetail(item)" v-if="item.status == 'START'" class="buy">
<view @click="navigateToBargainDetail(item)" v-if="item.status == 'START'" class="buy">
继续免费领
</div>
</div>
<div class="tips-box">
<div class="tips" :class="[item.status]">
</view>
</view>
<view class="tips-box">
<view class="tips" :class="[item.status]">
{{statusWay[item.status]}}
</div>
</div>
</div>
</div>
<div v-else>
</view>
</view>
</view>
</view>
<view v-else>
<u-empty style="margin-top:20%;" text="暂无砍价活动"></u-empty>
</div>
</div>
</view>
</view>
</template>
<script>
import { getMineBargainLog } from "@/api/promotions";
export default {
data() {
return {
params: {
pageNumber: 1,
pageSize: 10,
},
bargainLog: [],
statusWay: {
START: "砍价开始",
FAIL: "砍价失败",
SUCCESS: "砍价成功",
END: "活动结束",
},
};
},
onReachBottom() {
this.params.pageNumber++;
this.init();
},
onShow() {
this.params.pageNumber = 1;
this.bargainLog = [];
this.init();
},
methods: {
// 初始化砍价记录
async init() {
let res = await getMineBargainLog(this.params);
if (res.data.success) {
this.bargainLog.push(...res.data.result.records);
}
},
// 跳转到砍价详情
navigateToBargainDetail(val) {
uni.navigateTo({
url: `/pages/promotion/bargain/detail?id=${val.kanjiaActivityGoodsId}`,
});
},
},
};
<script setup lang="ts">
import { ref } from 'vue'
import { onShow, onReachBottom } from '@dcloudio/uni-app'
import { getMineBargainLog } from '@/api/promotions'
import { unitPrice } from '@/utils/filters.js'
const params = ref({
pageNumber: 1,
pageSize: 10,
})
const bargainLog = ref<any[]>([])
const statusWay: Record<string, string> = {
START: '砍价开始',
FAIL: '砍价失败',
SUCCESS: '砍价成功',
END: '活动结束',
}
onReachBottom(() => {
params.value.pageNumber++
init()
})
onShow(() => {
params.value.pageNumber = 1
bargainLog.value = []
init()
})
async function init() {
const res = await getMineBargainLog(params.value)
if (res.data.success) {
bargainLog.value.push(...res.data.result.records)
}
}
function navigateToBargainDetail(val: any) {
uni.navigateTo({
url: `/pages/promotion/bargain/detail?id=${val.kanjiaActivityGoodsId}`,
})
}
</script>
<style scoped>
<style>
page {
background: #fff;
}
@@ -84,14 +84,20 @@ page {
padding: 0 32rpx;
background: #fff;
}
.goods-img {
width: 230rpx;
height: 230rpx;
flex: 0 0 230rpx;
}
.buy {
background: $light-color;
color: #fff;
display: inline;
display: flex;
align-items: center;
justify-content: center;
padding: 10rpx 0;
border-radius: 100rpx;
width: 200rpx;
text-align: center;
font-size: 24rpx;
margin-top: 20rpx;
}
@@ -113,6 +119,11 @@ page {
font-weight: bold;
color: $light-color;
}
.surplus {
color: #333;
font-size: 26rpx;
margin-top: 12rpx;
}
.goods {
margin: 0 20rpx;
display: flex;
@@ -122,7 +133,8 @@ page {
}
.flex {
border-bottom: 1rpx solid #f7f7f7;
display: flex;
align-items: center;
padding: 20rpx 0;
margin: 10rpx 0;
}
@@ -138,4 +150,4 @@ page {
.FAIL {
color: $main-color;
}
</style>
</style>

View File

@@ -39,112 +39,100 @@
</view>
</template>
<script>
import * as API_Promotions from "@/api/promotions";
import * as API_Goods from "@/api/goods";
import goodsTemplate from '@/components/m-goods-list/promotion.vue'
export default {
components: {
goodsTemplate
},
data() {
return {
is_empty: false,
search: false,
title: "拼团活动",
<script setup lang="ts">
import { ref, watch } from 'vue'
import { onLoad, onReachBottom, onNavigationBarButtonTap } from '@dcloudio/uni-app'
import * as API_Promotions from '@/api/promotions'
import goodsTemplate from '@/components/m-goods-list/promotion.vue'
empty: false,
params: {
pageNumber: 1,
pageSize: 10,
categoryPath: "",
goodsName: "",
},
goodsList: [],
};
},
mounted() {},
watch: {
search(val) {
if (!val && !this.title) {
this.title = "拼团活动";
}
},
},
onReachBottom() {
this.loadMore();
},
// 点击搜索按钮
onNavigationBarButtonTap(e) {
this.popupFlag = !this.popupFlag;
},
async onLoad() {
this.GET_AssembleGoods();
},
const is_empty = ref(false)
const search = ref(false)
const title = ref('拼团活动')
const popupFlag = ref(false)
methods: {
back() {
if (this.search) {
this.search = false;
this.params.goodsName = "";
this.goodsList = [];
this.params.pageNumber = 1;
this.GET_AssembleGoods();
return;
}
const pages = getCurrentPages();
if (pages.length > 1) {
uni.navigateBack();
} else {
uni.switchTab({
url: "/pages/tabbar/home/index",
});
}
},
loadMore() {
this.params.pageNumber++;
this.GET_AssembleGoods();
},
searchFlag() {
this.search = !this.search;
},
const params = ref({
pageNumber: 1,
pageSize: 10,
categoryPath: '',
goodsName: '',
})
toHref(goods) {
uni.navigateTo({
url: `/pages/product/goods?id=${goods.skuId}&goodsId=${goods.goodsId}`,
});
},
searchFun() {
this.goodsList = [];
this.GET_AssembleGoods();
},
// 请求拼团数据
GET_AssembleGoods() {
const goodsList = ref<any[]>([])
const params = JSON.parse(JSON.stringify(this.params));
if (params.category_id === 0) delete params.category_id;
watch(search, (val) => {
if (!val && !title.value) {
title.value = '拼团活动'
}
})
API_Promotions.getAssembleList(params)
.then((response) => {
const data = response.data.result.records;
onReachBottom(() => {
loadMore()
})
if (!data || !data.length) {
this.is_empty = true;
onNavigationBarButtonTap(() => {
popupFlag.value = !popupFlag.value
})
} else {
if (data.length <= this.params.pageSize) {
onLoad(async () => {
GET_AssembleGoods()
})
} else {
function back() {
if (search.value) {
search.value = false
params.value.goodsName = ''
goodsList.value = []
params.value.pageNumber = 1
GET_AssembleGoods()
return
}
const pages = getCurrentPages()
if (pages.length > 1) {
uni.navigateBack()
} else {
uni.switchTab({
url: '/pages/tabbar/home/index',
})
}
}
}
this.is_empty = false;
this.goodsList.push(...(data || []));
}
})
.catch(() => {});
},
},
};
function loadMore() {
params.value.pageNumber++
GET_AssembleGoods()
}
function searchFlag() {
search.value = !search.value
}
function toHref(goods: any) {
uni.navigateTo({
url: `/pages/product/goods?id=${goods.skuId}&goodsId=${goods.goodsId}`,
})
}
function searchFun() {
goodsList.value = []
GET_AssembleGoods()
}
function GET_AssembleGoods() {
const requestParams = JSON.parse(JSON.stringify(params.value))
if (requestParams.category_id === 0) delete requestParams.category_id
API_Promotions.getAssembleList(requestParams)
.then((response) => {
const data = response.data.result.records
if (!data || !data.length) {
is_empty.value = true
} else {
is_empty.value = false
goodsList.value.push(...(data || []))
}
})
.catch(() => {})
}
</script>
<style lang="scss" scoped>

View File

@@ -1,3 +1,4 @@
// #ifndef MP-WEIXIN
import api from "@/config/api.js";
import mqtt from "mqtt";
@@ -291,3 +292,28 @@ export function createMqttClient(options = {}) {
}
export { MqttClient };
// #endif
// #ifdef MP-WEIXIN
class MqttClient {
connect() {
return Promise.resolve(this);
}
disconnect() {}
isConnected() {
return false;
}
subscribe() {
return this;
}
on() {
return this;
}
}
export function createMqttClient() {
return new MqttClient();
}
export { MqttClient };
// #endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,7 @@
/**
* 直播腾讯云 IM由 saas-uni-v3 useChat 迁移)
*/
// #ifndef MP-WEIXIN
import TencentCloudChat from "@tencentcloud/chat";
import { fetchLiveSetting } from "./liveSetting.js";
@@ -321,3 +322,13 @@ export class LiveChatService {
this.savedViewLiveResult = null;
}
}
// #endif
// #ifdef MP-WEIXIN
export class LiveChatService {
constructor() {}
setGroupID() {}
async initTencentIm() {}
cleanup() {}
}
// #endif

View File

@@ -1,6 +1,7 @@
/**
* 直播 MQTT 连接管理(由 saas-uni-v3 useMqtt 迁移)
*/
// #ifndef MP-WEIXIN
import { createMqttClient } from "../mqtt/mqtt.js";
export class LiveMqttService {
@@ -220,3 +221,20 @@ export class LiveMqttService {
this.disconnectMqtt();
}
}
// #endif
// #ifdef MP-WEIXIN
export class LiveMqttService {
constructor() {}
set messageHandlers() {}
setMessageHandlers() {}
initMqtt() {}
isConnected() {
return false;
}
get mqttClient() {
return null;
}
cleanup() {}
}
// #endif

View File

@@ -82,204 +82,169 @@
</view>
</template>
<script>
import { getLiveList } from "@/api/promotions.js";
import config from "@/config/config";
export default {
data() {
return {
config,
status: "loadmore",
activeColor: this.$lightColor,
current: 0, // 当前tabs索引
keyword: "", //搜索直播间
// 标签栏
tabs: [
{
name: "直播中",
},
{
name: "全部",
},
],
// 导航栏的配置
background: {
background: "#ff9f28",
},
// 直播间params
params: [
{
pageNumber: 1,
pageSize: 10,
status: "START",
},
{
pageNumber: 1,
pageSize: 4,
},
],
// 推荐直播间Params
recommendParams: {
pageNumber: 1,
pageSize: 3,
recommend: 0,
},
// 直播间列表
liveList: [],
// 推荐直播间列表
recommendLiveList: [],
<script setup lang="ts">
import { getLiveList } from '@/api/promotions.js'
import config from '@/config/config'
import { useStore } from '@/store'
import { onReachBottom, onShow } from '@dcloudio/uni-app'
import { computed, ref } from 'vue'
//轮播图滚动的图片
swiperImg: [
{
image:
"https://lilishop-oss.oss-cn-beijing.aliyuncs.com/48d789cb9c864b7b87c1c0f70996c3e8.jpeg",
},
],
};
const store = useStore()
const activeColor = computed(() => store.getters.lightColor)
const status = ref('loadmore')
const current = ref(0)
const keyword = ref('')
const tabs = ref([
{ name: '直播中' },
{ name: '全部' },
])
const background = ref({
background: '#ff9f28',
})
const params = ref([
{
pageNumber: 1,
pageSize: 10,
status: 'START',
},
onShow() {
this.params[this.current].pageNumber = 1;
this.liveList = [];
this.getLives();
this.getRecommendLives();
{
pageNumber: 1,
pageSize: 4,
},
onReachBottom() {
this.params[this.current].pageNumber++;
this.getLives();
])
const recommendParams = ref({
pageNumber: 1,
pageSize: 3,
recommend: 0,
})
const liveList = ref<any[]>([])
const recommendLiveList = ref<any[]>([])
const swiperImg = ref<any[]>([
{
image:
'https://lilishop-oss.oss-cn-beijing.aliyuncs.com/48d789cb9c864b7b87c1c0f70996c3e8.jpeg',
},
methods: {
back() {
uni.navigateBack({
delta: 1,
fail: () => {
uni.switchTab({ url: "/pages/tabbar/home/index" });
},
});
},
/**
* 点击标签栏切换
*/
changeTabs() {
this.params[this.current].pageNumber = 1;
this.init();
},
])
/**
* 初始化直播间
*/
init() {
this.liveList = [];
this.status = "loadmore";
this.getLives();
},
onShow(() => {
params.value[current.value].pageNumber = 1
liveList.value = []
getLives()
getRecommendLives()
})
/**
* 清除搜索内容
*/
clear() {
delete this.params[this.current].name;
this.init();
},
/**
* 点击顶部推荐直播间
*/
clickSwiper(val) {
console.log(this.swiperImg[val]);
this.handleLivePlayer(this.swiperImg[val]);
},
onReachBottom(() => {
params.value[current.value].pageNumber++
getLives()
})
/**
* 搜索直播间
*/
searchLive(val) {
this.params[this.current].pageNumber = 1;
this.params[this.current].name = val;
this.init();
function back() {
uni.navigateBack({
delta: 1,
fail: () => {
uni.switchTab({ url: '/pages/tabbar/home/index' })
},
/**
* 获取推荐直播间
*/
async getRecommendLives() {
this.status = "loading";
let recommendLives = await getLiveList(this.recommendParams);
if (recommendLives.data.success) {
// 推荐直播间
if (recommendLives.data.result.records.length) {
this.status = "loadmore";
this.recommendLiveList = recommendLives.data.result.records;
} else {
this.status = "noMore";
}
})
}
/**
* 如果推荐直播间没有的情况下
* 1.获取直播间第一个图片
* 2.如果没有直播间设置一个默认图片
*/
function changeTabs() {
params.value[current.value].pageNumber = 1
init()
}
if (!this.recommendLiveList.length) {
if (this.liveList[0] && this.liveList[0].shareImg) {
this.swiperImg = [
{
image: this.liveList[0].shareImg,
roomId: this.liveList[0].roomId,
},
];
}
} else {
this.recommendLiveList.forEach((item) => {
this.swiperImg = [{ image: item.shareImg, roomId: item.roomId }];
});
function init() {
liveList.value = []
status.value = 'loadmore'
getLives()
}
function clear() {
delete params.value[current.value].name
init()
}
function clickSwiper(val: number) {
console.log(swiperImg.value[val])
handleLivePlayer(swiperImg.value[val])
}
function searchLive(val: string) {
params.value[current.value].pageNumber = 1
params.value[current.value].name = val
init()
}
async function getRecommendLives() {
status.value = 'loading'
const recommendLives = await getLiveList(recommendParams.value)
if (recommendLives.data.success) {
if (recommendLives.data.result.records.length) {
status.value = 'loadmore'
recommendLiveList.value = recommendLives.data.result.records
} else {
status.value = 'noMore'
}
if (!recommendLiveList.value.length) {
if (liveList.value[0] && liveList.value[0].shareImg) {
swiperImg.value = [
{
image: liveList.value[0].shareImg,
roomId: liveList.value[0].roomId,
},
]
}
} else {
recommendLiveList.value.forEach((item) => {
swiperImg.value = [{ image: item.shareImg, roomId: item.roomId }]
})
}
}
}
async function getLives() {
status.value = 'loading'
const res = await getLiveList(params.value[current.value])
if (res.data.success) {
if (res.data.result.records.length) {
status.value = 'loadmore'
liveList.value.push(...res.data.result.records)
} else {
status.value = 'noMore'
}
res.data.result.total >
params.value[current.value].pageNumber *
params.value[current.value].pageSize
? (status.value = 'loadmore')
: (status.value = 'noMore')
liveList.value.forEach((item) => {
if (item.roomGoodsList && typeof item.roomGoodsList === 'string') {
try {
item.roomGoodsList = JSON.parse(item.roomGoodsList)
} catch (e) {
item.roomGoodsList = []
}
}
},
})
}
}
/**
* 获取直播间
*/
async getLives() {
this.status = "loading";
let res = await getLiveList(this.params[this.current]);
// 直播间
if (res.data.success) {
if (res.data.result.records.length ) {
this.status = "loadmore";
this.liveList.push(...res.data.result.records);
} else {
this.status = "noMore";
}
res.data.result.total >
this.params[this.current].pageNumber *
this.params[this.current].pageSize
? (this.status = "loadmore")
: (this.status = "noMore");
this.liveList.forEach((item) => {
if (item.roomGoodsList && typeof item.roomGoodsList === "string") {
try {
item.roomGoodsList = JSON.parse(item.roomGoodsList);
} catch (e) {
item.roomGoodsList = [];
}
}
});
}
},
/**
* 进入直播间
*/
handleLivePlayer(val) {
const id = val.id || val.roomId;
if (!id) return;
uni.navigateTo({
url: `/pages/live/room?id=${id}`,
});
},
},
};
function handleLivePlayer(val: any) {
const id = val.id || val.roomId
if (!id) return
uni.navigateTo({
url: `/pages/promotion/live/room?id=${id}`,
})
}
</script>
<style lang="scss" scoped>
@@ -431,4 +396,4 @@ page {
font-size: 28rpx;
color: #999;
}
</style>
</style>

View File

@@ -49,70 +49,63 @@
</div>
<!-- 购买 -->
<popupGoods ref="popupGoods" :goodsSpec="goodsSpec" :buyMask="maskFlag" @closeBuy="closePopupBuy" :goodsDetail="goodsData" v-if="goodsData.id " @handleClickSku="getGoodsDetail" />
<popupGoods ref="popupGoodsRef" :goodsSpec="goodsSpec" :buyMask="maskFlag" @closeBuy="closePopupBuy" :goodsDetail="goodsData" v-if="goodsData.id " @handleClickSku="getGoodsDetail" />
<div class="box4"></div>
</div>
</div>
</template>
<script>
import popupGoods from "@/components/m-buy/goods"; //购物车商品的模块
import { getPointsGoodsDetail } from "@/api/promotions";
export default {
components: {
popupGoods,
},
data() {
return {
style: {
img:"display:block"
},
maskFlag: false, //商品弹框
lightColor: this.$lightColor,
goodsData: {}, //积分商品中商品详情
pointDetail: {}, //积分商品详情
goodsDetail: {}, //商品详情
goodsSpec: {}, //商品规格
selectedGoods: {},
};
},
onLoad(options) {
this.routerVal = options;
},
onShow() {
this.init();
},
watch: {},
methods: {
// 购买积分商品
getGoodsDetail() {
uni.showLoading({
title: "加载中",
mask: true,
});
this.$refs.popupGoods.buy({
skuId: this.goodsData.id,
num: 1,
cartType: "POINTS",
});
},
<script setup lang="ts">
import { ref } from 'vue'
import { onLoad, onShow } from '@dcloudio/uni-app'
import popupGoods from '@/components/m-buy/goods'
import { getPointsGoodsDetail } from '@/api/promotions'
import { unitPrice } from '@/utils/filters.js'
// 初始化商品
async init() {
// 获取商品
let res = await getPointsGoodsDetail(this.routerVal.id);
if (res.data.success) {
this.goodsData = res.data.result.goodsSku;
this.pointDetail = res.data.result;
}
},
const style = ref({
img: 'display:block',
})
closePopupBuy(val) {
this.maskFlag = val;
},
},
};
const maskFlag = ref(false)
const goodsData = ref<any>({})
const pointDetail = ref<any>({})
const goodsSpec = ref<any>({})
const routerVal = ref<Record<string, string>>({})
const popupGoodsRef = ref<any>(null)
onLoad((options) => {
routerVal.value = options || {}
})
onShow(() => {
init()
})
function getGoodsDetail() {
uni.showLoading({
title: '加载中',
mask: true,
})
popupGoodsRef.value?.buy({
skuId: goodsData.value.id,
num: 1,
cartType: 'POINTS',
})
}
async function init() {
const res = await getPointsGoodsDetail(routerVal.value.id)
if (res.data.success) {
goodsData.value = res.data.result.goodsSku
pointDetail.value = res.data.result
}
}
function closePopupBuy(val: boolean) {
maskFlag.value = val
}
</script>
<style lang="scss">
</style>

View File

@@ -99,172 +99,168 @@
</view>
</template>
<script>
import { getPointsCategory, getPointsGoods } from "@/api/promotions.js";
import userPoint from "./user";
export default {
components: {
"user-point": userPoint,
},
data() {
return {
headOffSetTop: "0",
tabIndex: 0,
categoryIndexData: [
{
categoryId: 0,
name: "全部",
loadStatus: "more",
goods: [],
params: {
pageNumber: 1,
pageSize: 10,
pointsGoodsCategoryId: "",
},
},
],
currentLeft: 0,
pageParams: {
<script setup lang="ts">
import { ref, watch } from 'vue'
import {
onLoad,
onShow,
onPullDownRefresh,
onReachBottom,
onPageScroll,
} from '@dcloudio/uni-app'
import { getPointsCategory, getPointsGoods } from '@/api/promotions.js'
import userPoint from './user.vue'
import { unitPrice } from '@/utils/filters.js'
interface CategoryTab {
categoryId: number | string
name: string
loadStatus: string
goods: any[]
params: {
pageNumber: number
pageSize: number
pointsGoodsCategoryId: number | string
}
}
function createDefaultCategory(): CategoryTab[] {
return [
{
categoryId: 0,
name: '全部',
loadStatus: 'more',
goods: [],
params: {
pageNumber: 1,
pageSize: 10,
pointsGoodsCategoryId: 0,
pointsGoodsCategoryId: '',
},
flag: true,
};
},
onLoad() {},
async onPullDownRefresh() {
// #ifndef H5
this.categoryIndexData[this.tabIndex].goods = [];
this.categoryIndexData[this.tabIndex].params.pageNumber = 1;
this.categoryIndexData[this.tabIndex].loadStatus = "more";
this.loadGoods();
// #endif
},
// #ifndef H5
onPageScroll(e) {
if (e.scrollTop < -40 && this.flag) {
this.flag = false;
this.categoryIndexData[this.tabIndex].goods = [];
this.categoryIndexData[this.tabIndex].params.pageNumber = 1;
this.categoryIndexData[this.tabIndex].loadStatus = "more";
uni.startPullDownRefresh();
this.loadGoods();
}
},
// #endif
watch: {
tabIndex(val) {
if (
this.categoryIndexData[this.tabIndex].goods.length == 0 &&
this.categoryIndexData[this.tabIndex].params.pageNumber == 1
) {
this.loadGoods();
}
},
},
async onShow() {
//获取顶级分类
this.categoryIndexData = [
{
categoryId: 0,
name: "全部",
loadStatus: "more",
]
}
const tabIndex = ref(0)
const categoryIndexData = ref<CategoryTab[]>(createDefaultCategory())
const currentLeft = ref(0)
const flag = ref(true)
onLoad(() => {})
async function onPullDownRefreshHandler() {
// #ifndef H5
categoryIndexData.value[tabIndex.value].goods = []
categoryIndexData.value[tabIndex.value].params.pageNumber = 1
categoryIndexData.value[tabIndex.value].loadStatus = 'more'
loadGoods()
// #endif
}
onPullDownRefresh(onPullDownRefreshHandler)
// #ifndef H5
onPageScroll((e) => {
if (e.scrollTop < -40 && flag.value) {
flag.value = false
categoryIndexData.value[tabIndex.value].goods = []
categoryIndexData.value[tabIndex.value].params.pageNumber = 1
categoryIndexData.value[tabIndex.value].loadStatus = 'more'
uni.startPullDownRefresh()
loadGoods()
}
})
// #endif
watch(tabIndex, () => {
if (
categoryIndexData.value[tabIndex.value].goods.length == 0 &&
categoryIndexData.value[tabIndex.value].params.pageNumber == 1
) {
loadGoods()
}
})
onShow(async () => {
categoryIndexData.value = createDefaultCategory()
const response = await getPointsCategory()
if (response.data.success) {
const navData = response.data.result.records
navData.forEach((item: any) => {
categoryIndexData.value.push({
categoryId: item.id,
goods: [],
loadStatus: 'more',
name: item.name,
params: {
pageNumber: 1,
pageSize: 10,
pointsGoodsCategoryId: "",
pointsGoodsCategoryId: item.id,
},
},
];
})
})
}
let response = await getPointsCategory();
loadGoods()
})
if (response.data.success) {
let navData = response.data.result.records;
navData.forEach((item) => {
this.categoryIndexData.push({
categoryId: item.id,
goods: [],
loadStatus: "more",
name: item.name,
params: {
pageNumber: 1,
pageSize: 10,
pointsGoodsCategoryId: item.id,
},
});
});
function toGoods(item: any) {
uni.navigateTo({
url: `/pages/promotion/point/detail?id=${item.id}`,
})
}
async function loadGoods() {
const index = tabIndex.value
const response = await getPointsGoods(categoryIndexData.value[index].params)
if (response.data.success) {
categoryIndexData.value[index].goods.push(
...response.data.result.records
)
if (response.data.result.records.length < 10) {
categoryIndexData.value[index].loadStatus = 'noMore'
}
setTimeout(() => {
flag.value = true
}, 3000)
}
this.loadGoods();
},
methods: {
// 跳转
navigateTo(url) {
uni.navigateTo({
url,
});
},
toGoods(item) {
//跳转详情
uni.navigateTo({
url: `/pages/promotion/point/detail?id=${item.id}`,
});
},
async loadGoods() {
let index = this.tabIndex;
//获取商品数据
let response = await getPointsGoods(this.categoryIndexData[index].params);
if (response.data.success) {
this.categoryIndexData[index].goods.push(
...response.data.result.records
);
if (response.data.result.records.length < 10) {
this.categoryIndexData[index].loadStatus = "noMore";
}
let _this = this;
setTimeout(function () {
_this.flag = true;
}, 3000);
}
// #ifndef H5
uni.stopPullDownRefresh();
// #endif
},
setCat(type) {
this.tabIndex = type;
},
ontabchange(e) {
this.tabIndex = e.detail.current;
if (e.detail.current > 3) {
this.currentLeft = (e.detail.current - 3) * 70;
} else {
this.currentLeft = 0;
}
},
loadMore() {
if (this.categoryIndexData[this.tabIndex].loadStatus !== "more") {
return;
}
this.categoryIndexData[this.tabIndex].params.pageNumber++;
this.loadGoods();
},
},
// #ifdef H5
onReachBottom() {
if (this.categoryIndexData[this.tabIndex].loadStatus !== 'more') {
return;
}
this.loadMore();
},
// #ifndef H5
uni.stopPullDownRefresh()
// #endif
};
}
function setCat(type: number) {
tabIndex.value = type
}
function ontabchange(e: any) {
tabIndex.value = e.detail.current
if (e.detail.current > 3) {
currentLeft.value = (e.detail.current - 3) * 70
} else {
currentLeft.value = 0
}
}
function loadMore() {
if (categoryIndexData.value[tabIndex.value].loadStatus !== 'more') {
return
}
categoryIndexData.value[tabIndex.value].params.pageNumber++
loadGoods()
}
// #ifdef H5
onReachBottom(() => {
if (categoryIndexData.value[tabIndex.value].loadStatus !== 'more') {
return
}
loadMore()
})
// #endif
</script>
<style lang="scss" scoped>
page {

View File

@@ -10,26 +10,22 @@
</div>
</div>
</template>
<script>
import { getUserInfo } from "@/api/members";
export default {
data() {
return {
userInfo: {},
};
},
mounted() {
this.init();
},
methods: {
async init() {
let res = await getUserInfo();
if (res.data.success) {
this.userInfo = res.data.result;
}
},
},
};
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { getUserInfo } from '@/api/members'
const userInfo = ref<any>({})
onMounted(() => {
init()
})
async function init() {
const res = await getUserInfo()
if (res.data.success) {
userInfo.value = res.data.result
}
}
</script>
<style lang="scss" scoped>
.user-point {
@@ -65,4 +61,4 @@ export default {
font-weight: bold;
text-align: center;
}
</style>
</style>

View File

@@ -38,128 +38,115 @@
</view>
</template>
<script>
import {
getSeckillTimeLine,
getSeckillTimeGoods
} from "@/api/promotions.js";
import Foundation from "@/utils/Foundation.js";
import goodsTemplate from '@/components/m-goods-list/promotion.vue'
export default {
components: {
goodsTemplate
},
data() {
return {
nav: 0, //默认选择第一个时间
timeLine: "", //获取几个点活动
resTime: 0, //当前时间
time: 0, //距离下一个活动的时间值
times: {}, //时间集合
onlyOne: "", //是否最后一个商品
goodsList: [], //商品集合
params: {
pageNumber: 1,
pageSize: 10,
},
};
},
<script setup lang="ts">
import { ref } from 'vue'
import { onShow, onUnload } from '@dcloudio/uni-app'
import { getSeckillTimeLine, getSeckillTimeGoods } from '@/api/promotions.js'
import Foundation from '@/utils/Foundation.js'
import goodsTemplate from '@/components/m-goods-list/promotion.vue'
/**
* 显示时间活动
*/
async onShow() {
await this.getTimeLine();
if (!this.timeLine) {
await uni.showToast({
icon: "none",
duration: 2000,
title: "今天没有活动,明天再来吧",
});
}
this._setTimeInterval = setInterval(() => {
if (this.time <= 0) {
clearInterval(this._setTimeInterval);
this.getGoodsList();
this.getTimeLine();
} else {
this.times = Foundation.countTimeDown(this.time);
this.time--;
}
}, 1000);
},
const nav = ref(0)
const timeLine = ref<any[]>([])
const resTime = ref(0)
const time = ref(0)
const times = ref<any>({})
const onlyOne = ref(false)
const goodsList = ref<any[]>([])
const diffTime = ref(0)
onUnload() {
this._setTimeInterval && clearInterval(this._setTimeInterval);
},
methods: {
back() {
uni.navigateBack({
delta: 1,
fail: () => {
uni.switchTab({
url: "/pages/tabbar/home/index",
});
},
});
},
/**
* 获取时间线商品
*/
async getTimeLine() {
let res = await getSeckillTimeLine();
if (res.data.success && res.data.result.length > 0) {
let timeLine = res.data.result.sort(
(x, y) => Number(x.timeLine) - Number(y.timeLine)
);
this.timeLine = timeLine.slice(0, 5);
this.resTime = parseInt(new Date().getTime() / 1000);
this.onlyOne = res.data.result.length === 1;
this.diffTime = parseInt(new Date().getTime() / 1000) - this.resTime;
const params = ref<{
pageNumber: number
pageSize: number
timeLine?: string | number
}>({
pageNumber: 1,
pageSize: 10,
})
this.time =
this.timeLine[this.nav].distanceStartTime ||
(this.timeLine[this.nav + 1] &&
this.timeLine[this.nav + 1].distanceStartTime) ||
Foundation.theNextDayTime() - this.diffTime;
this.times = Foundation.countTimeDown(this.time);
let setTimeInterval: ReturnType<typeof setInterval> | null = null
this.getGoodsList();
}
},
onShow(async () => {
await getTimeLine()
if (!timeLine.value.length) {
await uni.showToast({
icon: 'none',
duration: 2000,
title: '今天没有活动,明天再来吧',
})
}
setTimeInterval = setInterval(() => {
if (time.value <= 0) {
if (setTimeInterval) clearInterval(setTimeInterval)
getGoodsList()
getTimeLine()
} else {
times.value = Foundation.countTimeDown(time.value)
time.value--
}
}, 1000)
})
/**
* 获取商品集合
*/
async getGoodsList() {
this.params.timeLine = this.timeLine[this.nav].timeLine;
let res = await getSeckillTimeGoods(this.params.timeLine);
if (res.data.success && res.data.result.length != 0) {
this.goodsList = res.data.result;
} else {
this.goodsList = [];
}
},
onUnload(() => {
if (setTimeInterval) clearInterval(setTimeInterval)
})
function back() {
uni.navigateBack({
delta: 1,
fail: () => {
uni.switchTab({
url: '/pages/tabbar/home/index',
})
},
})
}
/**
* 单击导航时间
*/
clickNavigateTime(type) {
this.nav = type;
this.goodsList = [];
this.diffTime = parseInt(new Date().getTime() / 1000) - this.resTime;
this.time =
this.timeLine[this.nav].distanceStartTime ||
(this.timeLine[this.nav + 1] &&
this.timeLine[this.nav + 1].distanceStartTime) ||
Foundation.theNextDayTime() - this.diffTime;
async function getTimeLine() {
const res = await getSeckillTimeLine()
if (res.data.success && res.data.result.length > 0) {
const sorted = res.data.result.sort(
(x: any, y: any) => Number(x.timeLine) - Number(y.timeLine)
)
timeLine.value = sorted.slice(0, 5)
resTime.value = parseInt(String(new Date().getTime() / 1000))
onlyOne.value = res.data.result.length === 1
diffTime.value = parseInt(String(new Date().getTime() / 1000)) - resTime.value
this.times = Foundation.countTimeDown(this.time);
this.getGoodsList();
},
},
};
time.value =
timeLine.value[nav.value].distanceStartTime ||
(timeLine.value[nav.value + 1] &&
timeLine.value[nav.value + 1].distanceStartTime) ||
Foundation.theNextDayTime() - diffTime.value
times.value = Foundation.countTimeDown(time.value)
getGoodsList()
}
}
async function getGoodsList() {
if (!timeLine.value.length) return
params.value.timeLine = timeLine.value[nav.value].timeLine
const res = await getSeckillTimeGoods(params.value.timeLine)
if (res.data.success && res.data.result.length != 0) {
goodsList.value = res.data.result
} else {
goodsList.value = []
}
}
function clickNavigateTime(type: number) {
nav.value = type
goodsList.value = []
diffTime.value = parseInt(String(new Date().getTime() / 1000)) - resTime.value
time.value =
timeLine.value[nav.value].distanceStartTime ||
(timeLine.value[nav.value + 1] &&
timeLine.value[nav.value + 1].distanceStartTime) ||
Foundation.theNextDayTime() - diffTime.value
times.value = Foundation.countTimeDown(time.value)
getGoodsList()
}
</script>
<style lang="scss" scoped>