feat: fix issues

This commit is contained in:
Rogee
2024-12-11 16:11:34 +08:00
parent fefc9b2402
commit c87bca1acd
6 changed files with 123 additions and 111 deletions

View File

@@ -1,112 +1,95 @@
<template>
<div class="goods">
<van-swipe class="goods-swipe" :autoplay="3000">
<van-swipe-item v-for="thumb in goods.thumb" :key="thumb">
<img :src="thumb" />
</van-swipe-item>
</van-swipe>
<van-search v-model="search" placeholder="请输入搜索关键词" />
<van-cell-group>
<van-cell>
<template #title>
<div class="goods-title">{{ goods.title }}</div>
<div class="goods-price">{{ formatPrice(goods.price) }}</div>
</template>
</van-cell>
<van-cell class="goods-express">
<template #title>
<van-col span="10">运费{{ goods.express }}</van-col>
<van-col span="14">剩余{{ goods.remain }}</van-col>
</template>
</van-cell>
</van-cell-group>
<van-back-top bottom="80" />
<van-cell-group class="goods-cell-group">
<van-cell value="进入店铺" icon="shop-o" is-link @click="sorry">
<template #title>
<span class="van-cell-text">有赞的店</span>
<van-tag class="goods-tag" type="danger">官方</van-tag>
</template>
</van-cell>
<van-cell title="线下门店" icon="location-o" is-link @click="sorry" />
</van-cell-group>
<van-list v-model:loading="loading" :finished="finished" finished-text="没有更多了" offset="100" @load="loadData">
<van-card v-for="item in items" :key="item" :desc="item.title" :thumb="item.poster" @click="play(item)">
<template #title>
<span>{{ item.title }}</span>
</template>
<template #price>
<template v-if="item.discount == 100"> 价格{{ item.price }} </template>
<van-cell-group class="goods-cell-group">
<van-cell title="查看商品详情" is-link @click="sorry" />
</van-cell-group>
</div>
<template v-else>
<del>{{ item.price }}</del>
<span>{{ (item.price * item.discount) / 100 }}</span>
</template>
</template>
<template #tags>
<van-space>
<van-tag v-for="resource in item.resources" plain type="primary">
<template v-if="resource == 'video'">视频</template>
<template v-if="resource == 'audio'">音频</template>
</van-tag>
</van-space>
</template>
</van-card>
</van-list>
</template>
<script>
export default {
data() {
return {
goods: {
title: "美国伽力果213约680g/3个",
price: 2680,
express: "免运费",
remain: 19,
thumb: [
"https://img.yzcdn.cn/public_files/2017/10/24/e5a5a02309a41f9f5def56684808d9ae.jpeg",
"https://img.yzcdn.cn/public_files/2017/10/24/1791ba14088f9c2be8c610d0a6cc0f93.jpeg",
],
},
};
},
<script setup>
import { ref } from "vue";
import { useRouter } from "vue-router";
import request from "@/utils/request";
methods: {
formatPrice() {
return "¥" + (this.goods.price / 100).toFixed(2);
},
const router = useRouter();
onClickCart() {
this.$router.push("cart");
},
const search = ref("");
const items = ref([]);
const loading = ref(false);
const finished = ref(false);
const pageLimit = ref(10);
sorry() {
showToast("暂无后续逻辑~");
},
},
const offset = ref("");
const play = (item) => {
// vue router goto play view
console.log("play -", item);
router.push({ name: "play", params: { id: item } });
};
const loadData = () => {
// request /v1/medias
const data = {
offset: offset.value,
limit: pageLimit.value,
action: 0,
bought: true,
};
console.log("loadData, data: ", data);
loading.value = true;
request
.post("/medias", data)
.then((res) => {
loading.value = false;
console.log("response: ", res);
if (offset.value == "") {
items.value = res.data;
} else {
items.value = items.value.concat(res.data);
}
if (res.data.length < pageLimit.value) {
console.log("finished");
finished.value = true;
loading.value = false;
}
offset.value = res.data[res.data.length - 1].hash;
})
.catch((err) => {
console.error(err);
})
.finally(() => {
// finished.value = true;
});
};
onMounted(() => {
// loadData();
});
</script>
<style lang="less">
body {
font-size: 16px;
background-color: #f8f8f8;
-webkit-font-smoothing: antialiased;
}
.goods {
padding-bottom: 50px;
&-swipe {
img {
width: 100%;
display: block;
}
}
&-title {
font-size: 16px;
}
&-price {
color: #f44;
}
&-express {
color: #999;
font-size: 12px;
padding: 5px 15px;
}
&-cell-group {
margin: 15px 0;
}
&-tag {
margin-left: 5px;
}
}
</style>

View File

@@ -17,6 +17,10 @@
</template>
</template>
<template #tag>
<template v-if="item.bought">已购买</template>
</template>
<template #tags>
<van-space>
<van-tag v-for="resource in item.resources" plain type="primary">
@@ -40,6 +44,7 @@ const search = ref("");
const items = ref([]);
const loading = ref(false);
const finished = ref(false);
const pageLimit = ref(10);
const offset = ref("");
@@ -52,33 +57,40 @@ const play = (item) => {
};
const loadData = () => {
loading.value = true;
console.log("loadData");
// request /v1/medias
const data = {
offset: offset.value,
action: 0,
limit: pageLimit.value,
};
console.log("loadData, data: ", data);
loading.value = false;
request
.post("/medias", data)
.then((res) => {
console.log(res);
loading.value = false;
console.log("response: ", res);
if (offset.value == "") {
items.value = res.data;
} else {
items.value = items.value.concat(res.data);
if (res.data.length == 0) {
finished.value = true;
}
}
offset.value = res.data[res.data.length - 1].hash;
if (res.data.length < pageLimit.value) {
console.log("finished");
finished.value = true;
loading.value = false;
}
offset.value = res.data[res.data.length - 1].hash;
})
.catch((err) => {
console.error(err);
})
.finally(() => {
loading.value = true;
// loading.value = true;
// finished.value = true;
});
};