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

Binary file not shown.

View File

@@ -25,6 +25,16 @@ func (c *Controller) List(ctx fiber.Ctx) error {
} }
claim := ctx.Locals(consts.CtxKeyClaim).(*jwt.Claims) claim := ctx.Locals(consts.CtxKeyClaim).(*jwt.Claims)
if filter.Offset != "" {
model, err := c.svc.GetMediaByHash(ctx.Context(), claim.TenantID, filter.Offset)
if err != nil {
log.WithField("action", "medias.Show").WithError(err).Error("GetMediaByHash")
return err
}
filter.OffsetID = model.ID
}
items, err := c.svc.List(ctx.Context(), claim.TenantID, claim.UserID, &filter) items, err := c.svc.List(ctx.Context(), claim.TenantID, claim.UserID, &filter)
if err != nil { if err != nil {
return err return err

View File

@@ -81,7 +81,7 @@ func (svc *Service) GetMediaByID(ctx context.Context, tenantId, userId, id int64
} }
func (svc *Service) ModelToListItem(ctx context.Context, m *model.Medias) *ListItem { func (svc *Service) ModelToListItem(ctx context.Context, m *model.Medias) *ListItem {
return &ListItem{ item := &ListItem{
ID: m.ID, ID: m.ID,
Poster: fmt.Sprintf("/static/%s/poster.jpg", m.Hash), Poster: fmt.Sprintf("/static/%s/poster.jpg", m.Hash),
Hash: m.Hash, Hash: m.Hash,
@@ -93,7 +93,10 @@ func (svc *Service) ModelToListItem(ctx context.Context, m *model.Medias) *ListI
Resources: m.Resources, Resources: m.Resources,
CreatedAt: m.CreatedAt, CreatedAt: m.CreatedAt,
UpdatedAt: m.UpdatedAt, UpdatedAt: m.UpdatedAt,
Bought: false,
} }
return item
} }
// List // List
@@ -146,7 +149,11 @@ func (svc *Service) List(ctx context.Context, tenantId, userId int64, filter *Li
} }
items := lo.Map(dest, func(m model.Medias, _ int) *ListItem { items := lo.Map(dest, func(m model.Medias, _ int) *ListItem {
return svc.ModelToListItem(ctx, &m) item := svc.ModelToListItem(ctx, &m)
if lo.Contains(boughtIDs, m.ID) {
item.Bought = true
}
return item
}) })
return items, nil return items, nil

View File

@@ -1,112 +1,95 @@
<template> <template>
<div class="goods"> <van-search v-model="search" placeholder="请输入搜索关键词" />
<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-cell-group> <van-back-top bottom="80" />
<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-cell-group class="goods-cell-group"> <van-list v-model:loading="loading" :finished="finished" finished-text="没有更多了" offset="100" @load="loadData">
<van-cell value="进入店铺" icon="shop-o" is-link @click="sorry"> <van-card v-for="item in items" :key="item" :desc="item.title" :thumb="item.poster" @click="play(item)">
<template #title> <template #title>
<span class="van-cell-text">有赞的店</span> <span>{{ item.title }}</span>
<van-tag class="goods-tag" type="danger">官方</van-tag> </template>
</template> <template #price>
</van-cell> <template v-if="item.discount == 100"> 价格{{ item.price }} </template>
<van-cell title="线下门店" icon="location-o" is-link @click="sorry" />
</van-cell-group>
<van-cell-group class="goods-cell-group"> <template v-else>
<van-cell title="查看商品详情" is-link @click="sorry" /> <del>{{ item.price }}</del>
</van-cell-group> <span>{{ (item.price * item.discount) / 100 }}</span>
</div> </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> </template>
<script> <script setup>
export default { import { ref } from "vue";
data() { import { useRouter } from "vue-router";
return { import request from "@/utils/request";
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",
],
},
};
},
methods: { const router = useRouter();
formatPrice() {
return "¥" + (this.goods.price / 100).toFixed(2);
},
onClickCart() { const search = ref("");
this.$router.push("cart"); const items = ref([]);
}, const loading = ref(false);
const finished = ref(false);
const pageLimit = ref(10);
sorry() { const offset = ref("");
showToast("暂无后续逻辑~");
}, 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> </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> </template>
<template #tag>
<template v-if="item.bought">已购买</template>
</template>
<template #tags> <template #tags>
<van-space> <van-space>
<van-tag v-for="resource in item.resources" plain type="primary"> <van-tag v-for="resource in item.resources" plain type="primary">
@@ -40,6 +44,7 @@ const search = ref("");
const items = ref([]); const items = ref([]);
const loading = ref(false); const loading = ref(false);
const finished = ref(false); const finished = ref(false);
const pageLimit = ref(10);
const offset = ref(""); const offset = ref("");
@@ -52,33 +57,40 @@ const play = (item) => {
}; };
const loadData = () => { const loadData = () => {
loading.value = true;
console.log("loadData");
// request /v1/medias // request /v1/medias
const data = { const data = {
offset: offset.value, offset: offset.value,
action: 0, action: 0,
limit: pageLimit.value,
}; };
console.log("loadData, data: ", data);
loading.value = false;
request request
.post("/medias", data) .post("/medias", data)
.then((res) => { .then((res) => {
console.log(res); loading.value = false;
console.log("response: ", res);
if (offset.value == "") { if (offset.value == "") {
items.value = res.data; items.value = res.data;
} else { } else {
items.value = items.value.concat(res.data); 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) => { .catch((err) => {
console.error(err); console.error(err);
}) })
.finally(() => { .finally(() => {
loading.value = true; // loading.value = true;
// finished.value = true; // finished.value = true;
}); });
}; };