fix: search issues

This commit is contained in:
Rogee
2024-12-13 17:51:51 +08:00
parent 1fba1b1deb
commit b9df73191b
6 changed files with 59 additions and 53 deletions

View File

@@ -111,36 +111,38 @@ func (svc *Service) List(ctx context.Context, tenantId, userId int64, filter *Li
tbl := table.Medias tbl := table.Medias
stmt := tbl. stmt := tbl.
SELECT(tbl.AllColumns). SELECT(tbl.AllColumns).
WHERE(tbl.TenantID.EQ(Int(tenantId))).
ORDER_BY(tbl.ID.DESC()) ORDER_BY(tbl.ID.DESC())
cond := tbl.TenantID.EQ(Int(tenantId))
if filter.Title != nil && *filter.Title != "" { if filter.Title != nil && *filter.Title != "" {
stmt = stmt.WHERE(tbl.Title.LIKE(String("%" + *filter.Title + "%"))) cond = cond.AND(tbl.Title.LIKE(String("%" + *filter.Title + "%")))
} }
if filter.Bought != nil && *filter.Bought { if filter.Bought != nil && *filter.Bought {
if len(boughtIDs) > 0 { if len(boughtIDs) > 0 {
stmt = stmt. cond = cond.
WHERE(tbl.ID.IN(lo.Map(boughtIDs, func(item int64, _ int) Expression { AND(tbl.ID.IN(lo.Map(boughtIDs, func(item int64, _ int) Expression {
return Int(item) return Int(item)
})...)) })...))
} }
} else { } else {
stmt = stmt.WHERE(tbl.Publish.EQ(Bool(true))) cond = cond.AND(tbl.Publish.EQ(Bool(true)))
} }
if filter.OffsetID > 0 { if filter.OffsetID > 0 {
if filter.Action == 0 { if filter.Action == 0 {
stmt = stmt.WHERE(tbl.ID.LT(Int(filter.OffsetID))) cond = cond.AND(tbl.ID.LT(Int(filter.OffsetID)))
stmt = stmt.LIMIT(10) stmt = stmt.LIMIT(10)
} }
if filter.Action == 1 { if filter.Action == 1 {
stmt = stmt.WHERE(tbl.ID.GT(Int(filter.OffsetID))) cond = cond.AND(tbl.ID.GT(Int(filter.OffsetID)))
} }
} else { } else {
stmt = stmt.LIMIT(10) stmt = stmt.LIMIT(10)
} }
stmt = stmt.WHERE(cond)
log.Debug(stmt.DebugSql()) log.Debug(stmt.DebugSql())
var dest []model.Medias var dest []model.Medias

View File

@@ -1,5 +1,8 @@
<template> <template>
<van-cell-group inset title="充值码"> <van-cell-group inset>
<template #title>
<van-button block size="small" type="primary" plain @click="loadChargeCodes">刷新充值码</van-button>
</template>
<van-cell v-for="c in codes" size="large" :title="getCodeAmountTitle(c)" :value="c.code" @click="copyCode(c)" /> <van-cell v-for="c in codes" size="large" :title="getCodeAmountTitle(c)" :value="c.code" @click="copyCode(c)" />
</van-cell-group> </van-cell-group>
</template> </template>

View File

@@ -1,9 +1,8 @@
<template> <template>
<van-search v-model="search" placeholder="请输入搜索关键词" /> <van-search v-if="!bought" v-model="search" placeholder="请输入搜索关键词" @search="onSearch" @cancel="onSearchCancel" />
<van-back-top bottom="80" /> <van-back-top bottom="80" />
<van-list style="padding-bottom: 3em" v-model:loading="loading" :finished="finished" finished-text="没有更多了" <van-list style="padding-bottom: 3em" v-model:loading="loading" :finished="finished" finished-text="没有更多了"
offset="100" @load="loadData"> offset="100" @load="loadData">
<list-item-card v-for="item in items" :key="item" :item="item" :bought="bought" /> <list-item-card v-for="item in items" :key="item" :item="item" :bought="bought" />
@@ -26,6 +25,17 @@ export default defineComponent({
const pageLimit = ref(10); const pageLimit = ref(10);
const offset = ref(""); const offset = ref("");
const onSearch = () => {
items.value = [];
offset.value = "";
finished.value = false;
loadData();
};
const onSearchCancel = () => {
search.value = "";
onSearch();
};
const loadData = () => { const loadData = () => {
// request /v1/medias // request /v1/medias
@@ -34,6 +44,7 @@ export default defineComponent({
action: 0, action: 0,
limit: pageLimit.value, limit: pageLimit.value,
bought: props.bought, bought: props.bought,
title: search.value,
}; };
request request
@@ -69,6 +80,8 @@ export default defineComponent({
loading, loading,
finished, finished,
loadData, loadData,
onSearch,
onSearchCancel,
}; };
}, },
}); });

View File

@@ -1,20 +1,18 @@
<template> <template>
<van-nav-bar :title="item.title" left-text="返回" left-arrow @click-left="onClickLeft" /> <van-nav-bar :title="item.title" left-text="返回" left-arrow @click-left="onClickLeft" />
<video id="video" :poster="item.poster"></video> <video id="video" :poster="item.poster"></video>
<van-progress v-if="playing" :percentage="100 * currentTime / item.duration" stroke-width="8" :show-pivot="false" /> <van-progress v-if="playing" :percentage="(100 * currentTime) / item.duration" stroke-width="8" :show-pivot="false" />
<template v-if="false === item.bought"> <template v-if="false === item.bought">
<van-notice-bar left-icon="volume-o" text="未购买的视频、音频默认播放时长为1分钟左右。" /> <van-notice-bar left-icon="volume-o" text="未购买的视频、音频默认播放时长为1分钟左右。" />
<van-button square type="warning" @click="buy()" size="large" block> <van-button square type="warning" @click="buy()" size="large" block>
花费 {{ item.price * item.discount / 100 }} 立即购买 花费 {{ (item.price * item.discount) / 100 }} 立即购买
</van-button> </van-button>
</template> </template>
<template v-else></template> <template v-else></template>
<div id="container"> <div id="container">
<van-space direction="vertical" fill size="2rem"> <van-space direction="vertical" fill size="2rem">
<template v-if="playing"> <template v-if="playing">
<van-row> <van-row>
<van-col span="24"> <van-col span="24">
@@ -34,7 +32,6 @@
</van-col> </van-col>
</van-row> </van-row>
</template> </template>
</van-space> </van-space>
</div> </div>
</template> </template>
@@ -47,118 +44,110 @@ import { onBeforeUnmount, onMounted } from "vue";
const router = useRouter(); const router = useRouter();
const route = useRoute(); const route = useRoute();
console.log("router: ", router);
console.log("route: ", route.meta);
const item = ref({ const item = ref({
title: "加载中...", title: "加载中...",
}) });
const currentTime = ref(0); const currentTime = ref(0);
const duration = ref(0); const duration = ref(0);
const playing = ref(false); const playing = ref(false);
onBeforeUnmount(() => { onBeforeUnmount(() => {
const player = document.getElementById('video'); const player = document.getElementById("video");
if (player && playing.value) { if (player && playing.value) {
stop(); stop();
} }
}) });
onMounted(() => { onMounted(() => {
console.log(123123)
loadMedia(route.params.hash); loadMedia(route.params.hash);
const player = document.getElementById('video'); const player = document.getElementById("video");
player.addEventListener('timeupdate', updateTime); player.addEventListener("timeupdate", updateTime);
player.addEventListener('loadedmetadata', () => { player.addEventListener("loadedmetadata", () => {
duration.value = player.duration; duration.value = player.duration;
}); });
player.addEventListener('ended', function () { player.addEventListener("ended", function () {
console.log("Video ended"); console.log("Video ended");
playing.value = false; playing.value = false;
}); });
player.addEventListener('pause', () => { player.addEventListener("pause", () => {
playing.value = false; playing.value = false;
player.currentTime = 0; player.currentTime = 0;
currentTime.value = 0; currentTime.value = 0;
}); });
}) });
const onClickLeft = () => { const onClickLeft = () => {
if (route.meta.from?.name) { if (route.meta.from?.name) {
router.back() router.back();
return; return;
} }
router.replace({ router.replace({
name: 'tab.home', name: "tab.home",
params: { params: {
tenant: route.params.tenant tenant: route.params.tenant,
} },
}); });
}; };
const loadMedia = (hash) => { const loadMedia = (hash) => {
console.log("loadMedia: ", hash);
setTimeout(() => { setTimeout(() => {
request request
.get(`/medias/${hash}`) .get(`/medias/${hash}`)
.then((res) => { .then((res) => {
console.log(res) console.log(res);
item.value = res.data; item.value = res.data;
}) })
.catch((err) => { .catch((err) => {
console.error("ERROR", err); console.error("ERROR", err);
}) });
}, 1000) }, 1000);
} };
const play = (hash, type) => { const play = (hash, type) => {
playing.value = true; playing.value = true;
const player = document.getElementById('video'); const player = document.getElementById("video");
const source = `/v1/medias/${hash}/${type}` const source = `/v1/medias/${hash}/${type}`;
if (Hls.isSupported()) { if (Hls.isSupported()) {
var hls = new Hls({ var hls = new Hls({
xhrSetup: function (xhr, url) { xhrSetup: function (xhr, url) {
xhr.setRequestHeader('Authorization', 'Bearer ' + __GA); xhr.setRequestHeader("Authorization", "Bearer " + __GA);
} },
}); });
hls.loadSource(source); hls.loadSource(source);
hls.attachMedia(player); hls.attachMedia(player);
hls.on(Hls.Events.MANIFEST_PARSED, function () { hls.on(Hls.Events.MANIFEST_PARSED, function () {
player.play(); player.play();
}); });
} else if (player.canPlayType('application/vnd.apple.mpegurl')) { } else if (player.canPlayType("application/vnd.apple.mpegurl")) {
player.src = source; player.src = source;
player.addEventListener('loadedmetadata', function () { player.addEventListener("loadedmetadata", function () {
player.play(); player.play();
}); });
} }
};
}
const updateTime = () => { const updateTime = () => {
const player = document.getElementById('video'); const player = document.getElementById("video");
currentTime.value = player?.currentTime; currentTime.value = player?.currentTime;
}; };
const stop = () => { const stop = () => {
const player = document.getElementById('video'); const player = document.getElementById("video");
if (!player) { if (!player) {
return; return;
} }
player.pause(); player.pause();
player.currentTime = 0; player.currentTime = 0;
currentTime.value = 0; currentTime.value = 0;
} };
const formatTime = (time) => { const formatTime = (time) => {
const minutes = Math.floor(time / 60); const minutes = Math.floor(time / 60);
const seconds = Math.floor(time % 60); const seconds = Math.floor(time % 60);
return `${minutes}:${seconds < 10 ? '0' : ''}${seconds}`; return `${minutes}:${seconds < 10 ? "0" : ""}${seconds}`;
}; };
</script> </script>
<style scoped> <style scoped>

View File

@@ -1,5 +1,4 @@
<template> <template>
<div style="width:100%; height: 50px;background-color: #3700B3;"></div>
<charge-notice-bar v-if="user.admin_contact" :contact="user.admin_contact" /> <charge-notice-bar v-if="user.admin_contact" :contact="user.admin_contact" />
<!-- 可以使用 CellGroup 作为容器 --> <!-- 可以使用 CellGroup 作为容器 -->