feat: fix issues
This commit is contained in:
0
backend/__debug_bin3572908368
Normal file
0
backend/__debug_bin3572908368
Normal file
Binary file not shown.
@@ -25,6 +25,16 @@ func (c *Controller) List(ctx fiber.Ctx) error {
|
||||
}
|
||||
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)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -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 {
|
||||
return &ListItem{
|
||||
item := &ListItem{
|
||||
ID: m.ID,
|
||||
Poster: fmt.Sprintf("/static/%s/poster.jpg", m.Hash),
|
||||
Hash: m.Hash,
|
||||
@@ -93,7 +93,10 @@ func (svc *Service) ModelToListItem(ctx context.Context, m *model.Medias) *ListI
|
||||
Resources: m.Resources,
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
Bought: false,
|
||||
}
|
||||
|
||||
return item
|
||||
}
|
||||
|
||||
// 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 {
|
||||
return svc.ModelToListItem(ctx, &m)
|
||||
item := svc.ModelToListItem(ctx, &m)
|
||||
if lo.Contains(boughtIDs, m.ID) {
|
||||
item.Bought = true
|
||||
}
|
||||
return item
|
||||
})
|
||||
|
||||
return items, nil
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user