性能优化

This commit is contained in:
Searchstars
2025-02-22 13:28:55 +08:00
parent 115e241e86
commit 2fb5d9aacd
10 changed files with 241 additions and 196 deletions
Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 726 B

+4
View File
@@ -45,6 +45,10 @@ export default {
},
onInit() {
global.ui.InitPage(this._parentVM)
this._parentVM.$options.onBackPress = () => {
global.ui.OnBackPressTriggered()
return true
}
const deviceInfo = global.DEVICE_INFO
if (deviceInfo.screenShape == "rect") {
+29 -28
View File
@@ -3,9 +3,9 @@
<template>
<div class="page">
<image style="position: absolute; left: 0px" src="{{getBgImg}}"></image>
<image style="position: absolute; left: 0px" src="{{getBgImg}}" static></image>
<scroll class="scroll {{scrclass}}" scroll-y="true" bounces="true">
<switch-bar title="dynamic.title"></switch-bar>
<switch-bar title="dynamic.title" static></switch-bar>
<div class="waterfall" if="show_content">
<div class="waterfall-column">
<dyn-show for="{{dynamic.render_split_1}}" dyn="{{$item}}"></dyn-show>
@@ -14,7 +14,8 @@
<dyn-show for="{{dynamic.render_split_2}}" dyn="{{$item}}"></dyn-show>
</div>
</div>
<text style="margin-top: 25px"></text>
<!-- 此处无数据绑定,添加static属性 -->
<text style="margin-top: 25px" static></text>
</scroll>
<image style="position: absolute; margin-top: 245px" if="{{anims.show_loading}}" src="{{anims.loading_src.value}}"></image>
</div>
@@ -29,13 +30,13 @@ export default {
show_loading: false
},
dynamic: {
render_split_1: {},
render_split_2: {}
render_split_1: [],
render_split_2: []
}
},
computed: {
getBgImg(){
return this.$app.$def.bgimg.GetBackgroundImageSrc()
getBgImg() {
return this.$app.$def.bgimg.GetBackgroundImageSrc();
}
},
SplitWaterfallArea(arr) {
@@ -43,35 +44,35 @@ export default {
const arr2 = [];
arr.forEach((value, index) => {
if (index % 2 === 0) {
arr1.push(value);
} else {
arr2.push(value);
}
if (index % 2 === 0) {
arr1.push(value);
} else {
arr2.push(value);
}
});
return { arr1, arr2 };
},
async LoadDynamics(){
try{
this.anims.loading.start()
async LoadDynamics() {
try {
this.anims.loading.start();
var dynamic = await global.biliclient.getDynamicList()
var split_result = this.SplitWaterfallArea(dynamic.items)
this.dynamic.render_split_1 = split_result.arr1
this.dynamic.render_split_2 = split_result.arr2
var dynamic = await global.biliclient.getDynamicList();
var split_result = this.SplitWaterfallArea(dynamic.items);
this.dynamic.render_split_1.splice(0, this.dynamic.render_split_1.length, ...split_result.arr1);
this.dynamic.render_split_2.splice(0, this.dynamic.render_split_2.length, ...split_result.arr2);
this.anims.loading.stop()
this.anims.show_loading = false
this.show_content = true
}
catch(e){
global.logger.error(e.toString())
this.anims.loading.stop();
this.anims.show_loading = false;
this.show_content = true;
} catch (e) {
global.logger.error(e.toString());
}
},
onReady(){
global.animengine.defaults.loading.CreateLoadingAnimation(this)
this.LoadDynamics()
onReady() {
global.animengine.defaults.loading.CreateLoadingAnimation(this);
this.LoadDynamics();
}
}
</script>
+59 -43
View File
@@ -7,21 +7,27 @@
<scroll scroll-y="true" class="scroll {{scrclass}}" bounces="true">
<switch-bar title="main.title"></switch-bar>
<text class="tip">{{ funnytip }}</text>
<image style="position: absolute; margin-top: 265px" if="{{anims.show_loading}}" src="{{anims.loading_src.value}}">
<image
style="position: absolute; margin-top: 265px"
if="{{anims.show_loading}}"
src="{{anims.loading_src.value}}">
</image>
<div class="recommend_div" if="{{show_recommend_div}}">
<videoshow for="{{recommend_vids}}" video="{{$item}}" tid="vids"></videoshow>
<text style="margin-top: 25px"></text>
<text style="margin-top: 25px" static></text>
</div>
</scroll>
<div style="position: absolute; bottom: 0px" @click="Refresh()">
<image src="/common/main_floatingrefresh.png"></image>
<image src="/common/main_floatingrefresh.png" static></image>
</div>
<text style="position: absolute; color: rgba(0, 0, 0, 0); width: 0px; top: 50px">
{{ anims.refresh_bottom.value }}
</text>
<image if="{{anims.showRefreshFX}}" style="position: absolute; bottom: {{anims.refresh_bottom.value}}px"
src="/common/TranslateFX/refreshFX.png"></image>
<image
if="{{anims.showRefreshFX}}"
style="position: absolute; bottom: {{anims.refresh_bottom.value}}px"
src.static="/common/TranslateFX/refreshFX.png">
</image>
</div>
</template>
@@ -31,6 +37,7 @@ import prompt from "@system.prompt"
export default {
private: {
scrclass: "",
// 初始化推荐视频数组为空,后续采用原地更新方式
recommend_vids: [],
show_recommend_div: false,
funnytip: "",
@@ -38,84 +45,93 @@ export default {
show_loading: false,
refresh: null,
showRefreshFX: false,
refresh_bottom: {value: "-350"}
refresh_bottom: { value: "-350" }
},
bgimg: ""
},
computed: {
getBgImg(){
return this.$app.$def.bgimg.GetBackgroundImageSrc()
getBgImg() {
return this.$app.$def.bgimg.GetBackgroundImageSrc();
}
},
async Refresh() {
if (!this.anims.showRefreshFX) {
this.recommend_vids = []
this.anims.show_loading = true
this.show_recommend_div = false
this.anims.showRefreshFX = true
this.recommend_vids.splice(0, this.recommend_vids.length);
this.anims.show_loading = true;
this.show_recommend_div = false;
this.anims.showRefreshFX = true;
this.anims.loading.start()
this.anims.loading.start();
setTimeout(() => this.anims.refresh.start(), 200)
this._timerRefreshStart = setTimeout(() => {
this.anims.refresh.start();
}, 200);
setTimeout(async () => {
this.anims.refresh_bottom.value = "-350px"
this.anims.refresh.stop()
this.anims.showRefreshFX = false
await this.GetVids()
}, 1200)
this._timerRefreshStop = setTimeout(async () => {
this.anims.refresh_bottom.value = "-350px";
this.anims.refresh.stop();
this.anims.showRefreshFX = false;
await this.GetVids();
}, 1200);
} else {
prompt.showToast({message: "你先别急。"})
prompt.showToast({ message: "你先别急。" });
}
},
async GetVids() {
try {
const {fresh_type, home_vid_count} = global.settings.SETTINGS
this.recommend_vids = await global.biliclient.getMainPageRecommendVideos(
fresh_type,
home_vid_count
)
const { fresh_type, home_vid_count } = global.settings.SETTINGS;
const vids = await global.biliclient.getMainPageRecommendVideos(fresh_type, home_vid_count);
this.recommend_vids.splice(0, this.recommend_vids.length, ...vids);
} catch (error) {
global.logger.error("获取推荐视频时出错:", error)
prompt.showToast({message: "获取推荐视频失败,请重试。"})
global.logger.error("获取推荐视频时出错:", error);
prompt.showToast({ message: "获取推荐视频失败,请重试。" });
} finally {
this.anims.loading.stop()
this.anims.show_loading = false
this.show_recommend_div = true
this.anims.loading.stop();
this.anims.show_loading = false;
this.show_recommend_div = true;
}
},
async checkUpdates() {
try {
const result = await global.biliclient.checkHyperbilibiliUpdates()
const result = await global.biliclient.checkHyperbilibiliUpdates();
if (result.update) {
prompt.showToast({message: result.msg, duration: 6000})
prompt.showToast({ message: result.msg, duration: 6000 });
}
} catch (error) {
global.logger.error("检查更新时出错:", error)
global.logger.error("检查更新时出错:", error);
}
},
onInit() {
this.GetVids()
this.funnytip = this.$app.$def.funnytips.getTips()
this.checkUpdates()
this.GetVids();
this.funnytip = this.$app.$def.funnytips.getTips();
this.checkUpdates();
},
onReady() {
const {loading_src, refresh_bottom} = this.anims
const { refresh_bottom } = this.anims;
global.animengine.defaults.loading.CreateLoadingAnimation(this)
this.anims.loading.start()
global.animengine.defaults.loading.CreateLoadingAnimation(this);
this.anims.loading.start();
this.anims.refresh = new global.animengine.DomAnim(
"mainPage",
{value: "0px"},
{ value: "0px" },
refresh_bottom,
0,
450,
1000
)
);
},
onDestroy() {
global.animengine.clearPageAnims("mainPage")
global.animengine.clearPageAnims("mainPage");
if (this._timerRefreshStart) {
clearTimeout(this._timerRefreshStart);
this._timerRefreshStart = null;
}
if (this._timerRefreshStop) {
clearTimeout(this._timerRefreshStop);
this._timerRefreshStop = null;
}
}
}
</script>
@@ -8,11 +8,12 @@
<switch-bar title="savedcontent.title" static></switch-bar>
<div style="flex-direction: column; align-items: center; width: 100%" for="{{content}}">
<div if="{{$item.type == 'article' ? true : false}}"
style="flex-direction: column; align-items: center; width: 100%" onclick="OpenArticle($item.id)">
style="flex-direction: column; align-items: center; width: 100%"
onclick="OpenArticle($item.id)" static>
<articleshow article="{{$item}}"></articleshow>
</div>
</div>
<text style="margin-top: 25px"></text>
<text style="margin-top: 25px" static></text>
</scroll>
</div>
</template>
@@ -31,18 +32,14 @@ export default {
},
PatchContent(origin_content) {
try {
var new_content = []
// 暂无可进行的patch操作
new_content = origin_content
let new_content = origin_content
return new_content
} catch (e) {
global.logger.error("[savedcontent.PatchContent] Patch Error: " + e.toString())
}
},
async OpenArticle(id) {
var html = await global.savedcontent.SavedContentManager.getContent(id)
const html = await global.savedcontent.SavedContentManager.getContent(id)
router.push({
uri: "pages/article/articleshow",
params: {
@@ -53,10 +50,9 @@ export default {
})
},
async LoadContent() {
var origin_content = await global.savedcontent.SavedContentManager.listAllContent()
global.logger.log(origin_content)
this.content = this.PatchContent(origin_content)
global.logger.log(this.content)
const origin_content = await global.savedcontent.SavedContentManager.listAllContent()
const patched = this.PatchContent(origin_content)
this.content.splice(0, this.content.length, ...patched)
},
onInit() {
this.LoadContent()
@@ -0,0 +1,21 @@
<import name="title-bar" src="@components/TitleBar/TitleBar.ux"></import>
<template>
<div class="page">
<scroll class="scroll {{scrclass}}" scroll-y="true" bounces="true">
<title-bar title="检查更新"></title-bar>
</scroll>
</div>
</template>
<script>
export default {
private: {
scrclass: ""
}
}
</script>
<style lang="less">
@import "@less/global.less";
</style>
@@ -4,29 +4,27 @@
<template>
<div class="page">
<scroll scroll-y="true" class="scroll {{scrclass}}" bounces="true">
<title-bar title="foldervideos.title"></title-bar>
<title-bar title="foldervideos.title" static></title-bar>
<div style="flex-direction: row; align-items: center">
<div @click="BackPN()" style="width: 40px; height: 40px; align-items: center; justify-content: center">
<image src="/common/changepage_left.png"></image>
<div static @click="BackPN()" style="width: 40px; height: 40px; align-items: center; justify-content: center">
<image src="/common/changepage_left.png" static></image>
</div>
<text style="margin-left: 17px; font-size: 25px; font-weight: 600; color: #9e9e9e">
<text style.static="margin-left: 17px; font-size: 25px; font-weight: 600; color: #9e9e9e">
{{ $t("foldervideos.no") }} {{ current_pn }} {{ $t("foldervideos.page") }}
</text>
<div style="
margin-left: 17px;
width: 40px;
height: 40px;
align-items: center;
justify-content: center;
" @click="NextPN()">
<image src="/common/changepage_right.png"></image>
<div static style="margin-left: 17px; width: 40px; height: 40px; align-items: center; justify-content: center" @click="NextPN()">
<image src="/common/changepage_right.png" static></image>
</div>
</div>
<div class="foldervid_div">
<videoshow video="{{$item}}" for="{{foldervid_vids}}"></videoshow>
<videoshow video="{{$item}}" for="{{foldervid_vids}}"></videoshow>
</div>
<text style="margin-top: 25px"></text>
<text style="margin-top: 25px" static></text>
</scroll>
<image style="position: absolute; margin-top: 265px" if="{{anims.show_loading}}" src="{{anims.loading_src.value}}"></image>
</div>
</template>
@@ -63,7 +61,7 @@ export default {
OpenVideo(bvid) {
router.replace({
uri: "pages/video/videodetail",
params: {bvid}
params: { bvid }
})
},
calcSpace(vid_title, isListItem) {
@@ -75,7 +73,7 @@ export default {
},
async LoadVideos() {
this.anims.show_loading = true
this.foldervid_vids = [] // Clear Array
this.foldervid_vids.splice(0, this.foldervid_vids.length)
this.anims.loading.start()
try {
@@ -88,8 +86,8 @@ export default {
global.biliclient.getVideoInfoByBVID(media.bvid)
)
// 并行获取所有视频信息
this.foldervid_vids = await Promise.all(videoInfoPromises)
const videos = await Promise.all(videoInfoPromises)
this.foldervid_vids.splice(0, 0, ...videos)
} catch (error) {
global.logger.error("加载视频时发生错误:", error)
} finally {
+28 -30
View File
@@ -3,9 +3,11 @@
<template>
<div class="page">
<scroll scroll-y="true" class="scroll {{scrclass}}" bounces="true">
<title-bar title="dmlist.title"></title-bar>
<title-bar title="dmlist.title" static></title-bar>
<image style="position: absolute; margin-top: 245px" if="{{anims.show_loading}}" src="{{anims.loading_src.value}}">
</image>
<div class="dmlist" for="{{sessions}}" if="{{show_dmlist}}">
<div class="user" onclick="GoDMPage($item.talker_id)" onlongpress="LongPressHandle($item.talker_id)">
<image class="userface" src="{{session_cards[$item.talker_id].face}}@75w_75h" alt="/common/fullgray.png"></image>
@@ -20,14 +22,15 @@
}}
</text>
</div>
<image if="{{$item.pinned}}" src="/common/dmlist_pinned_mask.png"
style="position: absolute; top: 0px; right: 0px"></image>
<image if="{{$item.pinned}}" src.static="/common/dmlist_pinned_mask.png" style.static="position: absolute; top: 0px; right: 0px"></image>
</div>
</div>
<text style="font-size: 18px; margin-top: 15px; font-weight: 600" show="{{Show20UserLimit}}">
<text style.static="font-size: 18px; margin-top: 15px; font-weight: 600" show="{{Show20UserLimit}}">
{{ $t("dmlist.userCountLimit") }}
</text>
<text style="margin-top: 25px"></text>
<text style="margin-top: 25px" static></text>
</scroll>
</div>
</template>
@@ -35,6 +38,7 @@
<script>
import router from "@system.router"
import prompt from "@system.prompt"
export default {
private: {
sessions: [],
@@ -64,7 +68,6 @@ export default {
message: "成功固定该用户"
})
}
this.InitSessions()
},
async InitSessions() {
@@ -72,38 +75,33 @@ export default {
this.anims.loading.start()
this.anims.show_loading = true
this.sessions = (await global.biliclient.getDMSessions(1, 2)).session_list
// 裁切至10
this.sessions.length = Math.min(this.sessions.length, 10)
const dmData = await global.biliclient.getDMSessions(1, 2)
let sessionsData = dmData.session_list.slice(0, 10)
var session_uids = []
this.sessions.forEach((session) => {
let session_uids = []
let filteredSessions = []
sessionsData.forEach(session => {
if (session.talker_id) {
session_uids.push(session.talker_id)
} else {
// Pass掉非法UID
this.sessions = this.sessions.filter((item) => item !== session)
global.logger.log("[InitSessions > if (session.talker_id)] 非法UID已剔除:", session.talker_id)
}
// Pinned去重
global.settings.SETTINGS.pinnedDMUsers.forEach((pinnedUid) => {
if (session.talker_id == pinnedUid) {
this.sessions = this.sessions.filter((item) => item !== session)
session_uids.pop()
global.logger.log("[InitSessions > if (session.talker_id == pinnedUid)] 重复UID已剔除:", session.talker_id)
if (global.settings.SETTINGS.pinnedDMUsers.indexOf(session.talker_id) === -1) {
filteredSessions.push(session)
session_uids.push(session.talker_id)
} else {
global.logger.log("[InitSessions] 重复UID已剔除:", session.talker_id)
}
})
} else {
global.logger.log("[InitSessions] 非法UID已剔除:", session.talker_id)
}
})
// pinned处理
var objectsArray = global.settings.SETTINGS.pinnedDMUsers.map((num) => {
return {talker_id: num, pinned: true}
const pinnedObjects = global.settings.SETTINGS.pinnedDMUsers.map(uid => {
return { talker_id: uid, pinned: true }
})
this.sessions = objectsArray.concat(this.sessions)
const combinedSessions = pinnedObjects.concat(filteredSessions)
session_uids = session_uids.concat(global.settings.SETTINGS.pinnedDMUsers)
this.sessions.splice(0, this.sessions.length, ...combinedSessions)
this.session_cards = await global.biliclient.getMultiUserInfoByUID(session_uids)
this.anims.loading.stop()
+68 -62
View File
@@ -7,65 +7,79 @@
<div class="page">
<image style="position: absolute; left: 0px" src="{{getBgImg}}"></image>
<scroll scroll-y="true" class="scroll {{scrclass}}" bounces="true">
<switch-bar title="searchresult.title" if="{{!overview_mode}}"></switch-bar>
<!-- 搜索结果页面标题,仅当 overview_mode 为 false 时展示 -->
<switch-bar title="searchresult.title" if="{{!overview_mode}}" static></switch-bar>
<!-- 搜索条:点击后返回搜索页 -->
<div class="searchbar" if="{{!overview_mode}}" @click="SearchBarClick">
<image src="/common/searchpage_search.png" style="margin-left: 16px"></image>
<text style="margin-left: 12px; font-weight: 600; font-size: 25px; lines: 1; text-overflow: ellipsis">{{ keyword }}</text>
<!-- 图片 src 为常量,可加 static 修饰 -->
<image src="/common/searchpage_search.png" style="margin-left: 16px" static></image>
<text style="margin-left: 12px; font-weight: 600; font-size: 25px; lines: 1; text-overflow: ellipsis">
{{ keyword }}
</text>
</div>
<div class="typebar" style="margin-top: 13px" if="{{!overview_mode}}">
<!-- 类型导航条 -->
<div class="typebar" style.static="margin-top: 13px" if="{{!overview_mode}}">
<text class="typetext" style="color: {{typebar_colors.c1}};">{{ $t("searchresult.all") }}</text>
<text class="typetext" style="color: {{typebar_colors.c2}}; margin-left: 20px;">{{ $t("searchresult.video") }}</text>
<text class="typetext" style="color: {{typebar_colors.c3}}; margin-left: 20px;">{{ $t("searchresult.user") }}</text>
<text class="typetext" style="color: {{typebar_colors.c4}}; margin-left: 20px;">{{ $t("searchresult.article") }}</text>
</div>
<swiper indicator="false" @change="UpdateTypeBarColors" class="swipermain" style="margin-top: 15px"
if="{{!anims.show_loading}}" duration="10">
<!-- 分页 swiper:仅在加载结束后显示 -->
<swiper indicator="false" @change="UpdateTypeBarColors" class="swipermain" style.static="margin-top: 15px" if="{{!anims.show_loading}}">
<!-- 第一页:综合结果 -->
<div class="swiper_box">
<scroll class="swiper_container" scroll-y="true" if="{{typebar_if.c1}}" @scroll="ScrollOverviewCheck">
<div class="tiplabel" if="{{comprehensive_status.has_users_result}}">
<text class="listtip">用户</text>
<!-- 文案为固定文本,添加 static -->
<text class="listtip" static>用户</text>
</div>
<div style="width: 100%; justify-content: center"
if="{{comprehensive_status.has_users_result}}">
<div style.static="width: 100%; justify-content: center" if="{{comprehensive_status.has_users_result}}">
<user user="{{search.users[0]}}"></user>
</div>
<div class="tiplabel" style="margin-top: 10px" if="{{comprehensive_status.has_video_result}}">
<text class="listtip">视频</text>
<div class="tiplabel" style.static="margin-top: 10px" if="{{comprehensive_status.has_video_result}}">
<text class="listtip" static>视频</text>
</div>
<div style="width: 100%; justify-content: center"
if="{{comprehensive_status.has_video_result}}" for="{{search.comprehensive_videos}}">
<div style.static="width: 100%; justify-content: center" if="{{comprehensive_status.has_video_result}}" for="{{search.comprehensive_videos}}">
<div style="width: 77%; justify-content: center; margin-top: 5px" onclick="OpenVideo($item.bvid)">
<videoshow video="{{$item}}"></videoshow>
</div>
</div>
<text style="margin-top: 30px"></text>
<text style="margin-top: 30px" static></text>
</scroll>
</div>
<!-- 第二页:视频 -->
<div class="swiper_box">
<scroll if="{{typebar_if.c2}}" class="swiper_container" scroll-y="true" @scroll="ScrollOverviewCheck">
<div style="width: 100%; justify-content: center" for="{{search.videos}}">
<div style.static="width: 100%; justify-content: center" for="{{search.videos}}">
<div style="width: 77%; justify-content: center; margin-top: 5px" onclick="OpenVideo($item.bvid)">
<videoshow video="{{$item}}"></videoshow>
</div>
</div>
<text style="margin-top: 30px"></text>
<text style="margin-top: 30px" static></text>
</scroll>
</div>
<!-- 第三页:用户 -->
<div class="swiper_box">
<scroll if="{{typebar_if.c3}}" class="swiper_container" scroll-y="true" @scroll="ScrollOverviewCheck">
<div style="width: 100%; justify-content: center; margin-top: 5px" for="{{search.users}}">
<div style.static="width: 100%; justify-content: center; margin-top: 5px" for="{{search.users}}">
<user user="{{$item}}"></user>
</div>
<text style="margin-top: 30px"></text>
<text style="margin-top: 30px" static></text>
</scroll>
</div>
<!-- 第四页:文章 -->
<div class="swiper_box">
<scroll if="{{typebar_if.c4}}" class="swiper_container" scroll-y="true" @scroll="ScrollOverviewCheck">
<div style="flex-direction: column; align-items: center; width: 100%" for="{{search.articles}}"
onclick="OpenArticle($item)">
<div style.static="flex-direction: column; align-items: center; width: 100%" for="{{search.articles}}" onclick="OpenArticle($item)">
<articleshow article="{{$item}}" show-category="true"></articleshow>
</div>
<text style="margin-top: 30px"></text>
<text style="margin-top: 30px" static></text>
</scroll>
</div>
</swiper>
@@ -110,12 +124,14 @@ export default {
}
},
UpdateTypeBarColors(index) {
// 初始化所有颜色为默认灰色
this.typebar_colors = {
c1: "#919191",
c2: "#919191",
c3: "#919191",
c4: "#919191"
}
// 初始化所有类型页标识为 false
this.typebar_if = {
c1: false,
c2: false,
@@ -123,6 +139,7 @@ export default {
c4: false
}
if (index.index >= 0 && index.index < 4) {
// 高亮当前页颜色,并标记该页为展示状态
this.typebar_colors[`c${index.index + 1}`] = "#0851ac"
this.typebar_if[`c${index.index + 1}`] = true
}
@@ -131,11 +148,8 @@ export default {
router.back()
},
ScrollOverviewCheck(ret) {
if (ret.scrollY != 0) {
this.overview_mode = true
} else {
this.overview_mode = false
}
// 当滚动不在顶部时,进入概要模式
this.overview_mode = ret.scrollY != 0
},
OpenArticle(item) {
router.push({
@@ -151,55 +165,53 @@ export default {
global.logger.log("[searchresult -> videodetail] open bvid: " + bvid)
router.push({
uri: "pages/video/videodetail",
params: {bvid}
params: { bvid }
})
},
async PatchSearchResult() {
try {
// 使用局部变量减少内存占用
// 使用局部变量减少内存占用
let videos = []
let comprehensive_videos = []
let articles = []
// 确保 this.search 存在
// 确保 search 对象存在
const search = this.search || {}
// 安全获取数组,如果不存在或不是数组则默认为空数组
// 安全获取各列表数据
const videosList = Array.isArray(search.videos) ? search.videos : []
const comprehensiveVideosList = Array.isArray(search.comprehensive_videos)
? search.comprehensive_videos
: []
const articlesList = Array.isArray(search.articles) ? search.articles : []
const usersList = Array.isArray(search.users) ? search.users : []
// 处理 videos
// 处理视频列表
videosList.forEach((video) => {
// 确保 video 对象的属性存在
videos.push({
pic: video.pic || "",
title: (video.title || "").replace(/<\/?[^>]+(>|$)/g, "").trim(),
owner: {name: video.author || "未知"},
stat: {view: Number(video.play) || 0},
owner: { name: video.author || "未知" },
stat: { view: Number(video.play) || 0 },
bvid: video.bvid || ""
})
})
global.logger.log("[searchresult.PatchSearchResult] 已处理视频")
// 处理 comprehensive_videos
// 处理综合视频列表
comprehensiveVideosList.forEach((video) => {
comprehensive_videos.push({
pic: video.pic || "",
title: (video.title || "").replace(/<\/?[^>]+(>|$)/g, "").trim(),
owner: {name: video.author || "未知"},
stat: {view: Number(video.play) || 0},
owner: { name: video.author || "未知" },
stat: { view: Number(video.play) || 0 },
bvid: video.bvid || ""
})
})
global.logger.log("[searchresult.PatchSearchResult] 已处理综合视频")
// 处理 articles
// 处理文章列表
articlesList.forEach((article) => {
// 确保文章标题存在
if (article.title) {
article.title = article.title.replace(/<\/?[^>]+(>|$)/g, "").trim()
} else {
@@ -208,16 +220,14 @@ export default {
articles.push(article)
})
global.logger.log("[searchresult.PatchSearchResult] 已处理文章")
// 原地更新 videos 数组,如果不是数组则直接赋值新的数组并记录警告
if (Array.isArray(search.videos)) {
search.videos.splice(0, search.videos.length, ...videos)
} else {
search.videos = videos
global.logger.warn("[searchresult.PatchSearchResult] 'videos' 不是数组。已初始化为空数组。")
}
// 原地更新 comprehensive_videos 数组,如果不是数组则直接赋值新的数组并记录警告
if (Array.isArray(search.comprehensive_videos)) {
search.comprehensive_videos.splice(
0,
@@ -230,19 +240,15 @@ export default {
"[searchresult.PatchSearchResult] 'comprehensive_videos' 不是数组。已初始化为空数组。"
)
}
// 原地更新 articles 数组,如果不是数组则直接赋值新的数组并记录警告
if (Array.isArray(search.articles)) {
search.articles.splice(0, search.articles.length, ...articles)
} else {
search.articles = articles
global.logger.warn("[searchresult.PatchSearchResult] 'articles' 不是数组。已初始化为空数组。")
}
// 确保 comprehensive_status 存在
this.comprehensive_status = this.comprehensive_status || {}
// 更新 comprehensive_status,确保相关数组存在
// 更新综合状态
this.comprehensive_status.has_users_result = usersList.length > 0
this.comprehensive_status.has_video_result = videos.length > 0
} catch (e) {
@@ -252,25 +258,25 @@ export default {
async DoSearch() {
this.anims.show_loading = true
this.anims.loading.start()
// 搜视频+推荐用户
// 搜视频推荐用户
this.search = await global.biliclient.searchContents(this.keyword, 10)
// 深度搜索用户
var users = await global.biliclient.searchContentWithType(this.keyword, "bili_user")
this.search.users = users.result
// 搜索专栏
// 搜索专栏文章
var articles = await global.biliclient.searchContentWithType(this.keyword, "article")
this.search.articles = articles.result
await this.PatchSearchResult()
this.anims.show_loading = false
this.anims.loading.stop()
},
onInit() {
global.runGC()
this.UpdateTypeBarColors({index: 0})
this.UpdateTypeBarColors({ index: 0 })
global.animengine.defaults.loading.CreateLoadingAnimation(this)
this.DoSearch()
}
+8 -3
View File
@@ -5,7 +5,11 @@ class GlobalActions {
global.vmPool[vm._name] = vm
}
static ClearCurrentVmSrcClass() {
static UpdateCurrentPageName(){
global.currentPageName = router.getState().name
}
static ClearCurrentVmSrcClass(){
global.vmPool[global.currentPageName].scrclass = ""
}
}
@@ -34,13 +38,14 @@ export function Init(){
}
export function InitPage(vm){
global.currentPageName = vm._name
GlobalActions.UpdateCurrentPageName()
GlobalActions.AddToVmPool(vm)
GlobalActions.ClearCurrentVmSrcClass()
global.logger.log("[ui.InitPage] vm set successed. name=", global.currentPageName)
}
export function OnBackPressTriggered(){
GlobalActions.UpdateCurrentPageName()
global.vmPool[global.currentPageName].scrclass = "scroll-backanim"
setTimeout(() => {
GlobalActions.ClearCurrentVmSrcClass()
@@ -51,5 +56,5 @@ export function OnBackPressTriggered(){
global.logger.log("lastpage=", lastPageName, "currentPage=", global.currentPageName)
global.vmPool[lastPageName].scrclass = ""
global.vmPool[lastPageName].scrclass = "scroll-frombackanim"
}, 300)
}, 150)
}