refactor pages struct
This commit is contained in:
12
miniprogram/pages/main/tabs/journal/index.json
Normal file
12
miniprogram/pages/main/tabs/journal/index.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"component": true,
|
||||
"usingComponents": {
|
||||
"t-cell": "tdesign-miniprogram/cell/cell",
|
||||
"t-icon": "tdesign-miniprogram/icon/icon",
|
||||
"t-navbar": "tdesign-miniprogram/navbar/navbar",
|
||||
"t-indexes": "tdesign-miniprogram/indexes/indexes",
|
||||
"t-cell-group": "tdesign-miniprogram/cell-group/cell-group",
|
||||
"t-indexes-anchor": "tdesign-miniprogram/indexes-anchor/indexes-anchor"
|
||||
},
|
||||
"styleIsolation": "shared"
|
||||
}
|
||||
130
miniprogram/pages/main/tabs/journal/index.less
Normal file
130
miniprogram/pages/main/tabs/journal/index.less
Normal file
@ -0,0 +1,130 @@
|
||||
.more-menu {
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
z-index: 999;
|
||||
position: fixed;
|
||||
background: var(--theme-bg-overlay);
|
||||
|
||||
.content {
|
||||
z-index: 1000;
|
||||
position: fixed;
|
||||
background: var(--theme-bg-menu);
|
||||
box-shadow: 0 0 12px var(--theme-shadow-medium);
|
||||
border-radius: 8rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.journal-list {
|
||||
width: 100vw;
|
||||
|
||||
.content {
|
||||
|
||||
.date {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.text,
|
||||
.items {
|
||||
position: relative;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
> .text {
|
||||
color: var(--theme-text-primary);
|
||||
width: calc(100% - 32px - 2rem);
|
||||
padding: 8px 16px;
|
||||
margin: .5rem 1rem 1rem 1rem;
|
||||
position: relative;
|
||||
background: var(--theme-bg-journal);
|
||||
box-shadow: 0 2px 10px var(--theme-shadow-medium);
|
||||
border-radius: 2px;
|
||||
|
||||
// 纸张纹理效果
|
||||
&::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background:
|
||||
linear-gradient(90deg,
|
||||
var(--theme-texture-light) 0%,
|
||||
var(--theme-texture-bright) 50%,
|
||||
var(--theme-texture-light) 100%),
|
||||
linear-gradient(var(--theme-texture-line) 1px, transparent 1px),
|
||||
linear-gradient(90deg, var(--theme-texture-line) 1px, transparent 1px);
|
||||
pointer-events: none;
|
||||
background-size: 100% 100%, 10px 10px, 10px 10px;
|
||||
}
|
||||
|
||||
.location {
|
||||
gap: 6rpx;
|
||||
display: flex;
|
||||
margin-top: 16rpx;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
|
||||
.icon {
|
||||
color: var(--theme-wx);
|
||||
}
|
||||
|
||||
.text {
|
||||
color: var(--theme-text-secondary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.items {
|
||||
gap: .25rem;
|
||||
display: flex;
|
||||
padding-bottom: 2rem;
|
||||
align-items: flex-start;
|
||||
|
||||
.column {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.item {
|
||||
overflow: hidden;
|
||||
background: var(--theme-bg-card);
|
||||
margin-bottom: .25rem;
|
||||
|
||||
&.thumbnail {
|
||||
width: 100%;
|
||||
display: block;
|
||||
}
|
||||
|
||||
&.video {
|
||||
height: auto;
|
||||
position: relative;
|
||||
|
||||
&::after {
|
||||
content: "";
|
||||
top: 50%;
|
||||
left: 53%;
|
||||
width: 0;
|
||||
height: 0;
|
||||
position: absolute;
|
||||
transform: translate(-50%, -50%);
|
||||
border-top: 16px solid transparent;
|
||||
border-left: 24px solid var(--theme-video-play);
|
||||
border-bottom: 16px solid transparent;
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.start {
|
||||
color: var(--theme-text-secondary);
|
||||
padding: 1rem 0;
|
||||
font-size: 12px;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
244
miniprogram/pages/main/tabs/journal/index.ts
Normal file
244
miniprogram/pages/main/tabs/journal/index.ts
Normal file
@ -0,0 +1,244 @@
|
||||
// pages/journal/index.ts
|
||||
|
||||
import Time from "../../../../utils/Time";
|
||||
import config from "../../../../config/index"
|
||||
import Events from "../../../../utils/Events";
|
||||
import Toolkit from "../../../../utils/Toolkit";
|
||||
import { Journal, JournalPage, JournalPageType } from "../../../../types/Journal";
|
||||
import { OrderType } from "../../../../types/Model";
|
||||
import { PreviewImageMetadata } from "../../../../types/Attachment";
|
||||
import { MediaItem, MediaItemType } from "../../../../types/UI";
|
||||
import { JournalApi } from "../../../../api/JournalApi";
|
||||
|
||||
interface JournalData {
|
||||
page: JournalPage;
|
||||
list: Journal[];
|
||||
dateFilterMin: number;
|
||||
dateFilterMax: number;
|
||||
dateFilterAllows: number[];
|
||||
dateFilterVisible: boolean;
|
||||
isFetching: boolean;
|
||||
isFinished: boolean;
|
||||
stickyOffset: number;
|
||||
isShowMoreMenu: boolean;
|
||||
menuTop: number;
|
||||
menuLeft: number;
|
||||
}
|
||||
|
||||
Page({
|
||||
data: <JournalData>{
|
||||
page: {
|
||||
index: 0,
|
||||
size: 8,
|
||||
type: JournalPageType.NORMAL,
|
||||
likeMap: {
|
||||
type: "NORMAL"
|
||||
},
|
||||
orderMap: {
|
||||
createdAt: OrderType.DESC
|
||||
}
|
||||
},
|
||||
list: [],
|
||||
dateFilterMin: new Date("2025/06/28 16:00:00").getTime(),
|
||||
dateFilterMax: new Date(2026, 1, 15).getTime(),
|
||||
dateFilterAllows: [
|
||||
new Date(2025, 11, 15).getTime(),
|
||||
new Date(2025, 11, 20).getTime(),
|
||||
new Date(2025, 11, 10).getTime(),
|
||||
],
|
||||
dateFilterVisible: false,
|
||||
isFetching: false,
|
||||
isFinished: false,
|
||||
stickyOffset: 0,
|
||||
isShowMoreMenu: false,
|
||||
menuTop: 0,
|
||||
menuLeft: 0
|
||||
},
|
||||
onLoad() {
|
||||
Events.reset("JOURNAL_REFRESH", () => {
|
||||
this.setData({
|
||||
page: {
|
||||
index: 0,
|
||||
size: 8,
|
||||
type: JournalPageType.NORMAL,
|
||||
equalsExample: {
|
||||
type: "NORMAL"
|
||||
},
|
||||
orderMap: {
|
||||
createdAt: OrderType.DESC
|
||||
}
|
||||
},
|
||||
list: [],
|
||||
isFetching: false,
|
||||
isFinished: false
|
||||
});
|
||||
this.fetch();
|
||||
});
|
||||
this.setData({
|
||||
list: []
|
||||
})
|
||||
this.fetch();
|
||||
},
|
||||
onReady() {
|
||||
this.getCustomNavbarHeight();
|
||||
},
|
||||
onHide() {
|
||||
this.setData({
|
||||
isShowMoreMenu: false
|
||||
})
|
||||
},
|
||||
onReachBottom() {
|
||||
this.fetch();
|
||||
},
|
||||
getCustomNavbarHeight() {
|
||||
const query = wx.createSelectorQuery();
|
||||
query.select(".custom-navbar").boundingClientRect();
|
||||
query.exec((res) => {
|
||||
const { height = 0 } = res[0] || {};
|
||||
this.setData({ stickyOffset: height });
|
||||
});
|
||||
},
|
||||
toggleMoreMenu() {
|
||||
if (!this.data.isShowMoreMenu) {
|
||||
// 打开菜单时计算位置
|
||||
const query = wx.createSelectorQuery();
|
||||
query.select(".more").boundingClientRect();
|
||||
query.exec((res) => {
|
||||
if (res[0]) {
|
||||
const { top, left, height } = res[0];
|
||||
this.setData({
|
||||
isShowMoreMenu: true,
|
||||
menuTop: top + height + 16, // 按钮下方 8px
|
||||
menuLeft: left
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// 关闭菜单
|
||||
this.setData({
|
||||
isShowMoreMenu: false
|
||||
});
|
||||
}
|
||||
},
|
||||
/** 阻止事件冒泡 */
|
||||
stopPropagation() {
|
||||
// 空函数,仅用于阻止事件冒泡
|
||||
},
|
||||
toCreater() {
|
||||
wx.navigateTo({
|
||||
url: "/pages/main/journal/editor/index?from=journal"
|
||||
})
|
||||
},
|
||||
toSearch() {
|
||||
wx.navigateTo({
|
||||
url: "/pages/main/journal/search/index"
|
||||
})
|
||||
},
|
||||
toMap() {
|
||||
wx.navigateTo({
|
||||
url: "/pages/main/journal/map/index"
|
||||
})
|
||||
},
|
||||
toDate() {
|
||||
wx.navigateTo({
|
||||
url: "/pages/main/journal/date/index"
|
||||
})
|
||||
},
|
||||
async fetch() {
|
||||
if (this.data.isFetching || this.data.isFinished) {
|
||||
return;
|
||||
}
|
||||
this.setData({
|
||||
isFetching: true
|
||||
});
|
||||
try {
|
||||
const pageResult = await JournalApi.getList(this.data.page);
|
||||
const list = pageResult.list;
|
||||
if (!list || list.length === 0) {
|
||||
this.setData({
|
||||
isFinished: true,
|
||||
isFetching: false
|
||||
});
|
||||
return;
|
||||
}
|
||||
list.forEach(journal => {
|
||||
const mediaItems = journal.items!.filter((item) => item.attachType === "THUMB").map((thumbItem, index) => {
|
||||
const metadata = (typeof thumbItem.metadata === "string" ? JSON.parse(thumbItem.metadata) : thumbItem.metadata) as PreviewImageMetadata;
|
||||
const thumbURL = `${config.url}/attachment/read/${thumbItem.mongoId}`;
|
||||
const sourceURL = `${config.url}/attachment/read/${metadata.sourceMongoId}`;
|
||||
const isVideo = metadata.sourceMimeType?.startsWith("video/");
|
||||
return {
|
||||
type: isVideo ? MediaItemType.VIDEO : MediaItemType.IMAGE,
|
||||
thumbURL,
|
||||
sourceURL,
|
||||
size: thumbItem.size || 0,
|
||||
attachmentId: thumbItem.id,
|
||||
width: metadata.width,
|
||||
height: metadata.height,
|
||||
originalIndex: index
|
||||
} as MediaItem;
|
||||
});
|
||||
journal.date = Time.toDate(journal.createdAt);
|
||||
journal.time = Time.toTime(journal.createdAt);
|
||||
journal.datetime = Time.toPassedDateTime(journal.createdAt);
|
||||
journal.mediaItems = mediaItems;
|
||||
journal.columnedItems = Toolkit.splitItemsIntoColumns(mediaItems, 3, (item) => {
|
||||
if (item.width && item.height && 0 < item.width) {
|
||||
return item.height / item.width;
|
||||
}
|
||||
return 1;
|
||||
})
|
||||
});
|
||||
this.setData({
|
||||
page: {
|
||||
index: this.data.page.index + 1,
|
||||
size: 8,
|
||||
type: JournalPageType.NORMAL,
|
||||
equalsExample: {
|
||||
type: "NORMAL"
|
||||
},
|
||||
orderMap: {
|
||||
createdAt: OrderType.DESC
|
||||
}
|
||||
},
|
||||
list: this.data.list.concat(list),
|
||||
isFinished: list.length < this.data.page.size,
|
||||
isFetching: false
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("加载日记失败:", error);
|
||||
this.setData({ isFetching: false });
|
||||
}
|
||||
},
|
||||
preview(e: WechatMiniprogram.BaseEvent) {
|
||||
const { journalIndex, itemIndex } = e.currentTarget.dataset;
|
||||
const journal = this.data.list[journalIndex];
|
||||
const items = journal.mediaItems!;
|
||||
const total = items.length;
|
||||
|
||||
const startIndex = Math.max(0, itemIndex - 25);
|
||||
const endIndex = Math.min(total, startIndex + 50);
|
||||
const newCurrentIndex = itemIndex - startIndex;
|
||||
|
||||
const sources = items.slice(startIndex, endIndex).map((item) => {
|
||||
return {
|
||||
url: item.sourceURL,
|
||||
type: item.type === MediaItemType.IMAGE ? "image" : "video"
|
||||
}
|
||||
}) as any;
|
||||
wx.previewMedia({
|
||||
current: newCurrentIndex,
|
||||
sources
|
||||
})
|
||||
},
|
||||
openLocation(e: WechatMiniprogram.BaseEvent) {
|
||||
const { journalIndex } = e.currentTarget.dataset;
|
||||
const journal = this.data.list[journalIndex] as Journal;
|
||||
if (journal.lat && journal.lng) {
|
||||
wx.openLocation({
|
||||
latitude: journal.lat,
|
||||
longitude: journal.lng,
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
56
miniprogram/pages/main/tabs/journal/index.wxml
Normal file
56
miniprogram/pages/main/tabs/journal/index.wxml
Normal file
@ -0,0 +1,56 @@
|
||||
<view class="custom-navbar">
|
||||
<t-navbar title="我们的记录" placeholder>
|
||||
<view slot="left" class="more" bind:tap="toggleMoreMenu">
|
||||
<t-icon name="view-list" size="24px" />
|
||||
</view>
|
||||
</t-navbar>
|
||||
</view>
|
||||
<view wx:if="{{isShowMoreMenu}}" class="more-menu" catchtap="toggleMoreMenu">
|
||||
<t-cell-group
|
||||
class="content"
|
||||
theme="card"
|
||||
style="top: {{menuTop}}px; left: {{menuLeft}}px;"
|
||||
catchtap="stopPropagation"
|
||||
>
|
||||
<t-cell title="新纪录" leftIcon="add" bind:tap="toCreater" />
|
||||
<t-cell title="按列表查找" leftIcon="view-list" bind:tap="toSearch" />
|
||||
<t-cell title="按日期查找" leftIcon="calendar-1" bind:tap="toDate" />
|
||||
<t-cell title="按地图查找" leftIcon="location" bind:tap="toMap" />
|
||||
</t-cell-group>
|
||||
</view>
|
||||
<t-indexes
|
||||
class="journal-list"
|
||||
bind:scroll="onScroll"
|
||||
sticky-offset="{{stickyOffset}}"
|
||||
>
|
||||
<view class="content" wx:for="{{list}}" wx:for-item="journal" wx:for-index="journalIndex" wx:key="index">
|
||||
<t-indexes-anchor class="date" index="{{journal.datetime}}" />
|
||||
<view wx:if="{{journal.idea || journal.location}}" class="text">
|
||||
<text class="idea">{{journal.idea}}</text>
|
||||
<view
|
||||
wx:if="{{journal.location}}"
|
||||
class="location"
|
||||
bind:tap="openLocation"
|
||||
data-journal-index="{{journalIndex}}"
|
||||
>
|
||||
<t-icon class="icon" name="location-filled" />
|
||||
<text class="text">{{journal.location}}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view wx:if="{{journal.columnedItems}}" class="items">
|
||||
<view wx:for="{{journal.columnedItems}}" wx:for-item="column" wx:for-index="columnIndex" wx:key="columnIndex" class="column">
|
||||
<block wx:for="{{column}}" wx:for-item="item" wx:for-index="itemIndex" wx:key="attachmentId">
|
||||
<image
|
||||
class="item thumbnail {{item.type}}"
|
||||
src="{{item.thumbURL}}"
|
||||
mode="widthFix"
|
||||
bindtap="preview"
|
||||
data-item-index="{{item.originalIndex}}"
|
||||
data-journal-index="{{journalIndex}}"
|
||||
></image>
|
||||
</block>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view wx:if="{{isFinished}}" class="start">已回到最初的起点</view>
|
||||
</t-indexes>
|
||||
Reference in New Issue
Block a user