Compare commits
10 Commits
199d1ed6ef
...
4786df0c36
| Author | SHA1 | Date | |
|---|---|---|---|
| 4786df0c36 | |||
| c4f84681d4 | |||
| 3524de0cb6 | |||
| 6755c483c7 | |||
| 00bcbf9e63 | |||
| 71fc077726 | |||
| a25c38d50d | |||
| 75b553ac93 | |||
| 1002d463e0 | |||
| 2685ff4524 |
@ -3,12 +3,12 @@
|
||||
"pages/index/index",
|
||||
"pages/main/journal/index",
|
||||
"pages/main/journal-creater/index",
|
||||
"pages/main/journal-search/index",
|
||||
"pages/main/portfolio/index",
|
||||
"pages/main/travel/index",
|
||||
"pages/main/about/index",
|
||||
"pages/main/travel/luggage/index",
|
||||
"pages/main/moment/index",
|
||||
"pages/main/journal-list/index"
|
||||
"pages/main/moment/index"
|
||||
],
|
||||
"darkmode": true,
|
||||
"themeLocation": "theme.json",
|
||||
|
||||
12
miniprogram/components/journal-list/index.json
Normal file
12
miniprogram/components/journal-list/index.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"component": true,
|
||||
"usingComponents": {
|
||||
"t-cell": "tdesign-miniprogram/cell/cell",
|
||||
"t-icon": "tdesign-miniprogram/icon/icon",
|
||||
"t-button": "tdesign-miniprogram/button/button",
|
||||
"t-loading": "tdesign-miniprogram/loading/loading",
|
||||
"t-cell-group": "tdesign-miniprogram/cell-group/cell-group",
|
||||
"t-search": "tdesign-miniprogram/search/search",
|
||||
"t-empty": "tdesign-miniprogram/empty/empty"
|
||||
}
|
||||
}
|
||||
53
miniprogram/components/journal-list/index.less
Normal file
53
miniprogram/components/journal-list/index.less
Normal file
@ -0,0 +1,53 @@
|
||||
/* components/journal-list/index.less */
|
||||
.journal-list {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.search-bar {
|
||||
padding: 8rpx 16rpx;
|
||||
flex-shrink: 0;
|
||||
background: var(--td-bg-color-container);
|
||||
box-shadow: 0 4rpx 8rpx var(--theme-shadow-light);
|
||||
}
|
||||
|
||||
.scroll-content {
|
||||
flex: 1;
|
||||
height: 0;
|
||||
padding: 0;
|
||||
|
||||
.item {
|
||||
|
||||
&.selected {
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
}
|
||||
|
||||
.thumb {
|
||||
width: 96rpx;
|
||||
height: 96rpx;
|
||||
flex-shrink: 0;
|
||||
object-fit: cover;
|
||||
margin-right: 16rpx;
|
||||
border-radius: 8rpx;
|
||||
background: var(--td-bg-color-component);
|
||||
}
|
||||
|
||||
.date {
|
||||
color: gray;
|
||||
}
|
||||
|
||||
.location {
|
||||
font-size: 24rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.loading,
|
||||
.finished {
|
||||
color: var(--td-text-color-placeholder);
|
||||
padding: 32rpx 0;
|
||||
font-size: 24rpx;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
231
miniprogram/components/journal-list/index.ts
Normal file
231
miniprogram/components/journal-list/index.ts
Normal file
@ -0,0 +1,231 @@
|
||||
// components/journal-list/index.ts
|
||||
import config from "../../config/index";
|
||||
import { JournalPage, JournalPageType } from "../../types/Journal";
|
||||
import Time from "../../utils/Time";
|
||||
import Toolkit from "../../utils/Toolkit";
|
||||
|
||||
export type JournalListItem = {
|
||||
id: number;
|
||||
date: string;
|
||||
location?: string;
|
||||
idea?: string;
|
||||
thumbUrl?: string;
|
||||
}
|
||||
|
||||
interface JournalListData {
|
||||
list: JournalListItem[];
|
||||
isFetching: boolean;
|
||||
isFinished: boolean;
|
||||
page: JournalPage;
|
||||
searchValue: string;
|
||||
}
|
||||
|
||||
// 组件实例类型扩展
|
||||
interface ComponentInstance {
|
||||
debouncedSearch?: ((keyword: string) => void) & { cancel(): void };
|
||||
}
|
||||
|
||||
Component<JournalListData, {}, {}, ComponentInstance>({
|
||||
options: {
|
||||
styleIsolation: 'apply-shared'
|
||||
},
|
||||
properties: {
|
||||
visible: {
|
||||
type: Boolean,
|
||||
value: false
|
||||
},
|
||||
type: {
|
||||
type: String,
|
||||
value: undefined // NORMAL 或 PORTFOLIO,不传则获取所有类型
|
||||
},
|
||||
selectedId: {
|
||||
type: Number,
|
||||
value: undefined
|
||||
},
|
||||
searchable: {
|
||||
type: Boolean,
|
||||
value: false // 是否显示搜索框
|
||||
},
|
||||
mode: {
|
||||
type: String,
|
||||
value: 'select' // 'select' 选择模式 或 'navigate' 跳转模式
|
||||
}
|
||||
},
|
||||
data: <JournalListData>{
|
||||
list: [],
|
||||
isFetching: false,
|
||||
isFinished: false,
|
||||
page: {
|
||||
index: 0,
|
||||
size: 16,
|
||||
type: JournalPageType.PREVIEW
|
||||
},
|
||||
searchValue: ""
|
||||
},
|
||||
lifetimes: {
|
||||
ready() {
|
||||
// 创建防抖搜索函数
|
||||
this.debouncedSearch = Toolkit.debounce(
|
||||
(keyword: string) => {
|
||||
this.resetAndSearch(keyword);
|
||||
},
|
||||
false, // 不立即执行,等待输入停止
|
||||
400 // 400ms 延迟
|
||||
);
|
||||
// 组件加载时就获取数据
|
||||
this.fetch();
|
||||
},
|
||||
detached() {
|
||||
// 组件销毁时取消防抖
|
||||
if (this.debouncedSearch) {
|
||||
this.debouncedSearch.cancel();
|
||||
}
|
||||
}
|
||||
},
|
||||
observers: {
|
||||
'visible': function(visible: boolean) {
|
||||
// visible 从 false 变为 true 时,如果还没有数据则加载
|
||||
if (visible && this.data.list.length === 0) {
|
||||
this.fetch();
|
||||
}
|
||||
},
|
||||
'type': function() {
|
||||
this.resetPage();
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
resetPage() {
|
||||
const likeExample = this.data.searchValue ? {
|
||||
idea: this.data.searchValue,
|
||||
location: this.data.searchValue
|
||||
} : undefined;
|
||||
|
||||
const equalsExample = this.properties.type ? {
|
||||
type: this.properties.type
|
||||
} : undefined;
|
||||
|
||||
this.setData({
|
||||
page: {
|
||||
index: 0,
|
||||
size: 16,
|
||||
type: JournalPageType.PREVIEW,
|
||||
equalsExample,
|
||||
likeExample
|
||||
},
|
||||
list: [],
|
||||
isFinished: false
|
||||
});
|
||||
},
|
||||
fetch() {
|
||||
if (this.data.isFetching || this.data.isFinished) {
|
||||
return;
|
||||
}
|
||||
this.setData({ isFetching: true });
|
||||
wx.request({
|
||||
url: `${config.url}/journal/list`,
|
||||
method: "POST",
|
||||
header: {
|
||||
Key: wx.getStorageSync("key")
|
||||
},
|
||||
data: this.data.page,
|
||||
success: (resp: any) => {
|
||||
const list = resp.data.data.list;
|
||||
if (!list || list.length === 0) {
|
||||
this.setData({ isFinished: true });
|
||||
return;
|
||||
}
|
||||
const result = list.map((journal: any) => {
|
||||
// 获取第一张缩略图
|
||||
const firstThumb = journal.items.find((item: any) => item.attachType === "THUMB");
|
||||
return {
|
||||
id: journal.id,
|
||||
date: Time.toPassedDate(journal.createdAt),
|
||||
idea: journal.idea,
|
||||
location: journal.location,
|
||||
thumbUrl: firstThumb ? `${config.url}/attachment/read/${firstThumb.mongoId}` : undefined
|
||||
} as JournalListItem;
|
||||
});
|
||||
this.setData({
|
||||
page: {
|
||||
...this.data.page,
|
||||
index: this.data.page.index + 1
|
||||
},
|
||||
list: this.data.list.concat(result),
|
||||
isFinished: list.length < this.data.page.size
|
||||
});
|
||||
},
|
||||
complete: () => {
|
||||
this.setData({ isFetching: false });
|
||||
}
|
||||
});
|
||||
},
|
||||
onSearchChange(e: WechatMiniprogram.CustomEvent) {
|
||||
const value = e.detail.value.trim();
|
||||
this.setData({ searchValue: value });
|
||||
// 如果是清空操作,不使用防抖(clear 事件会处理)
|
||||
if (value === "" && this.debouncedSearch) {
|
||||
this.debouncedSearch.cancel();
|
||||
return;
|
||||
}
|
||||
// 使用防抖自动搜索
|
||||
if (this.debouncedSearch) {
|
||||
this.debouncedSearch(value);
|
||||
}
|
||||
},
|
||||
onSearchSubmit(e: WechatMiniprogram.CustomEvent) {
|
||||
const value = e.detail.value.trim();
|
||||
// 立即搜索,取消防抖
|
||||
if (this.debouncedSearch) {
|
||||
this.debouncedSearch.cancel();
|
||||
}
|
||||
this.resetAndSearch(value);
|
||||
},
|
||||
onSearchClear() {
|
||||
// 取消防抖,立即搜索
|
||||
if (this.debouncedSearch) {
|
||||
this.debouncedSearch.cancel();
|
||||
}
|
||||
this.resetAndSearch("");
|
||||
},
|
||||
resetAndSearch(keyword: string) {
|
||||
const likeExample = keyword ? {
|
||||
idea: keyword,
|
||||
location: keyword
|
||||
} : undefined;
|
||||
|
||||
const equalsExample = this.properties.type ? {
|
||||
type: this.properties.type
|
||||
} : undefined;
|
||||
|
||||
this.setData({
|
||||
searchValue: keyword,
|
||||
list: [],
|
||||
page: {
|
||||
index: 0,
|
||||
size: 16,
|
||||
type: JournalPageType.PREVIEW,
|
||||
equalsExample,
|
||||
likeExample
|
||||
},
|
||||
isFetching: false,
|
||||
isFinished: false
|
||||
}, () => {
|
||||
// 无论是否有搜索词,都重新获取列表
|
||||
this.fetch();
|
||||
});
|
||||
},
|
||||
onSelectItem(e: WechatMiniprogram.BaseEvent) {
|
||||
const { id } = e.currentTarget.dataset;
|
||||
if (this.properties.mode === 'navigate') {
|
||||
// 跳转模式:触发 navigate 事件
|
||||
this.triggerEvent('navigate', { id });
|
||||
} else {
|
||||
// 选择模式:触发 select 事件
|
||||
this.triggerEvent('select', { id });
|
||||
}
|
||||
},
|
||||
onScrollToLower() {
|
||||
this.fetch();
|
||||
}
|
||||
}
|
||||
});
|
||||
77
miniprogram/components/journal-list/index.wxml
Normal file
77
miniprogram/components/journal-list/index.wxml
Normal file
@ -0,0 +1,77 @@
|
||||
<!--components/journal-list/index.wxml-->
|
||||
<view class="journal-list">
|
||||
<view wx:if="{{searchable}}" class="search-bar">
|
||||
<t-search
|
||||
value="{{searchValue}}"
|
||||
placeholder="搜索日记内容或地点"
|
||||
bind:change="onSearchChange"
|
||||
bind:submit="onSearchSubmit"
|
||||
bind:clear="onSearchClear"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<scroll-view
|
||||
class="scroll-content"
|
||||
scroll-y
|
||||
bindscrolltolower="onScrollToLower"
|
||||
>
|
||||
<block wx:if="{{list.length > 0}}">
|
||||
<t-cell-group>
|
||||
<t-cell
|
||||
class="item {{selectedId === item.id ? 'selected' : ''}}"
|
||||
wx:for="{{list}}"
|
||||
wx:key="id"
|
||||
hover
|
||||
bind:tap="onSelectItem"
|
||||
data-id="{{item.id}}"
|
||||
>
|
||||
<image
|
||||
slot="left-icon"
|
||||
wx:if="{{item.thumbUrl}}"
|
||||
class="thumb"
|
||||
src="{{item.thumbUrl}}"
|
||||
mode="aspectFill"
|
||||
/>
|
||||
<t-icon wx:else slot="left-icon" name="image" color="gray" size="96rpx" />
|
||||
<view slot="title">
|
||||
<text class="date">{{item.date}}</text>
|
||||
<text wx:if="{{item.idea}}"> · {{item.idea}}</text>
|
||||
</view>
|
||||
<text wx:if="{{item.location}}" class="location" slot="description">{{item.location}}</text>
|
||||
<t-icon
|
||||
wx:if="{{mode === 'select' && selectedId === item.id}}"
|
||||
slot="right-icon"
|
||||
class="check"
|
||||
name="check"
|
||||
size="48rpx"
|
||||
color="var(--theme-wx)"
|
||||
/>
|
||||
<t-icon
|
||||
wx:elif="{{mode === 'navigate'}}"
|
||||
slot="right-icon"
|
||||
name="chevron-right"
|
||||
/>
|
||||
</t-cell>
|
||||
</t-cell-group>
|
||||
|
||||
<view wx:if="{{isFetching}}" class="loading">
|
||||
<t-loading theme="circular" size="40rpx" text="加载中..." />
|
||||
</view>
|
||||
|
||||
<view wx:elif="{{isFinished}}" class="finished">
|
||||
{{searchable && searchValue ? '已显示全部结果' : '没有更多了'}}
|
||||
</view>
|
||||
</block>
|
||||
<block wx:elif="{{isFetching}}">
|
||||
<view class="loading">
|
||||
<t-loading theme="circular" size="40rpx" text="加载中..." />
|
||||
</view>
|
||||
</block>
|
||||
<block wx:elif="{{searchable && searchValue}}">
|
||||
<t-empty icon="search" description="未找到相关日记" />
|
||||
</block>
|
||||
<block wx:else>
|
||||
<t-empty icon="image" description="暂无记录" />
|
||||
</block>
|
||||
</scroll-view>
|
||||
</view>
|
||||
8
miniprogram/package-lock.json
generated
8
miniprogram/package-lock.json
generated
@ -9,7 +9,7 @@
|
||||
"version": "1.0.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"tdesign-miniprogram": "^1.11.2"
|
||||
"tdesign-miniprogram": "^1.12.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"miniprogram-api-typings": "^4.1.0"
|
||||
@ -22,9 +22,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/tdesign-miniprogram": {
|
||||
"version": "1.11.2",
|
||||
"resolved": "https://registry.npmjs.org/tdesign-miniprogram/-/tdesign-miniprogram-1.11.2.tgz",
|
||||
"integrity": "sha512-lXcry3vRa9jHzjpOdIxuIAh7F85kImym82VwLbCqr/TkMhycOsOepx+r1S9fum7u2nsWiYRTV+HuvDHN3KlIuA=="
|
||||
"version": "1.12.0",
|
||||
"resolved": "https://registry.npmjs.org/tdesign-miniprogram/-/tdesign-miniprogram-1.12.0.tgz",
|
||||
"integrity": "sha512-Ft+B1HWMOKuOpM9+Z0mflprWrxSB/ESo6TVymjxJ6xzMgSfEcbmFaXpd0nJ+Oj/5GCljqP06ZTeWazuk1G6Ugg=="
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"tdesign-miniprogram": "^1.11.2"
|
||||
"tdesign-miniprogram": "^1.12.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"miniprogram-api-typings": "^4.1.0"
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
// index.ts
|
||||
|
||||
import config from "../../config/index"
|
||||
import { JournalPage, JournalPageType } from "../../types/Journal";
|
||||
|
||||
interface IndexData {
|
||||
key: string;
|
||||
@ -25,9 +26,10 @@ Page({
|
||||
header: {
|
||||
Key: this.data.key
|
||||
},
|
||||
data: {
|
||||
data: <JournalPage> {
|
||||
index: 0,
|
||||
size: 1
|
||||
size: 1,
|
||||
type: JournalPageType.PREVIEW
|
||||
},
|
||||
success: (resp) => {
|
||||
const data = resp.data as any;
|
||||
@ -36,8 +38,10 @@ Page({
|
||||
wx.switchTab({
|
||||
url: "/pages/main/journal/index",
|
||||
})
|
||||
} else {
|
||||
} else if (data.code === 40100) {
|
||||
wx.showToast({ title: "密码错误", icon: "error" });
|
||||
} else {
|
||||
wx.showToast({ title: "服务异常", icon: "error" });
|
||||
}
|
||||
},
|
||||
fail: () => wx.showToast({ title: "验证失败", icon: "error" })
|
||||
|
||||
@ -26,7 +26,7 @@
|
||||
</view>
|
||||
<view class="item">
|
||||
<text class="label">版本:</text>
|
||||
<text>1.2.2</text>
|
||||
<text>1.4.0</text>
|
||||
</view>
|
||||
<view class="item copyright">
|
||||
<text>{{copyright}}</text>
|
||||
|
||||
@ -1,3 +0,0 @@
|
||||
{
|
||||
"usingComponents": {}
|
||||
}
|
||||
@ -1 +0,0 @@
|
||||
/* pages/main/journal-list/index.wxss */
|
||||
@ -1,66 +0,0 @@
|
||||
// pages/main/journal-list/index.ts
|
||||
Page({
|
||||
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
*/
|
||||
onReady() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面隐藏
|
||||
*/
|
||||
onHide() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面卸载
|
||||
*/
|
||||
onUnload() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面相关事件处理函数--监听用户下拉动作
|
||||
*/
|
||||
onPullDownRefresh() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 页面上拉触底事件的处理函数
|
||||
*/
|
||||
onReachBottom() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 用户点击右上角分享
|
||||
*/
|
||||
onShareAppMessage() {
|
||||
|
||||
}
|
||||
})
|
||||
@ -1,2 +0,0 @@
|
||||
<!--pages/main/journal-list/index.wxml-->
|
||||
<text>pages/main/journal-list/index.wxml</text>
|
||||
7
miniprogram/pages/main/journal-search/index.json
Normal file
7
miniprogram/pages/main/journal-search/index.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"t-navbar": "tdesign-miniprogram/navbar/navbar",
|
||||
"journal-list": "/components/journal-list/index"
|
||||
},
|
||||
"navigationBarTitleText": "按列表查找"
|
||||
}
|
||||
8
miniprogram/pages/main/journal-search/index.less
Normal file
8
miniprogram/pages/main/journal-search/index.less
Normal file
@ -0,0 +1,8 @@
|
||||
page {
|
||||
background: var(--td-bg-color-page);
|
||||
}
|
||||
|
||||
.content {
|
||||
width: 100vw;
|
||||
height: calc(100vh - var(--navbar-height, 88rpx));
|
||||
}
|
||||
12
miniprogram/pages/main/journal-search/index.ts
Normal file
12
miniprogram/pages/main/journal-search/index.ts
Normal file
@ -0,0 +1,12 @@
|
||||
// pages/main/journal-search/index.ts
|
||||
Page({
|
||||
onNavigateItem(e: WechatMiniprogram.CustomEvent) {
|
||||
const { id } = e.detail;
|
||||
// TODO: 跳转到编辑页面或详情页
|
||||
wx.showToast({
|
||||
title: `编辑功能待开发 (ID: ${id})`,
|
||||
icon: "none",
|
||||
duration: 2000
|
||||
});
|
||||
}
|
||||
});
|
||||
12
miniprogram/pages/main/journal-search/index.wxml
Normal file
12
miniprogram/pages/main/journal-search/index.wxml
Normal file
@ -0,0 +1,12 @@
|
||||
<view class="custom-navbar">
|
||||
<t-navbar title="按列表查找" left-arrow />
|
||||
</view>
|
||||
|
||||
<view class="content">
|
||||
<journal-list
|
||||
searchable="{{true}}"
|
||||
mode="navigate"
|
||||
type="NORMAL"
|
||||
bind:navigate="onNavigateItem"
|
||||
/>
|
||||
</view>
|
||||
@ -3,6 +3,7 @@
|
||||
import Time from "../../../utils/Time";
|
||||
import config from "../../../config/index"
|
||||
import Events from "../../../utils/Events";
|
||||
import { JournalPage, JournalPageType } from "../../../types/Journal";
|
||||
|
||||
export type Journal = {
|
||||
date: string;
|
||||
@ -24,12 +25,7 @@ export enum JournalItemType {
|
||||
}
|
||||
|
||||
interface JournalData {
|
||||
page: {
|
||||
index: number;
|
||||
size: number;
|
||||
type: string;
|
||||
orderMap?: object;
|
||||
}
|
||||
page: JournalPage;
|
||||
list: Journal[];
|
||||
dateFilterMin: number;
|
||||
dateFilterMax: number;
|
||||
@ -46,9 +42,9 @@ Page({
|
||||
page: {
|
||||
index: 0,
|
||||
size: 8,
|
||||
type: "NORMAL",
|
||||
orderMap: {
|
||||
createdAt: "DESC"
|
||||
type: JournalPageType.NORMAL,
|
||||
likeMap: {
|
||||
type: "NORMAL"
|
||||
}
|
||||
},
|
||||
list: [],
|
||||
@ -71,9 +67,9 @@ Page({
|
||||
page: {
|
||||
index: 0,
|
||||
size: 8,
|
||||
type: "NORMAL",
|
||||
orderMap: {
|
||||
createdAt: "DESC"
|
||||
type: JournalPageType.NORMAL,
|
||||
equalsExample: {
|
||||
type: "NORMAL"
|
||||
}
|
||||
},
|
||||
list: [],
|
||||
@ -181,9 +177,9 @@ Page({
|
||||
page: {
|
||||
index: this.data.page.index + 1,
|
||||
size: 8,
|
||||
type: "NORMAL",
|
||||
orderMap: {
|
||||
createdAt: "DESC"
|
||||
type: JournalPageType.NORMAL,
|
||||
equalsExample: {
|
||||
type: "NORMAL"
|
||||
}
|
||||
},
|
||||
list: this.data.list.concat(result),
|
||||
@ -233,11 +229,9 @@ Page({
|
||||
"url": "/pages/main/journal-creater/index?from=journal"
|
||||
})
|
||||
},
|
||||
toDetail() {
|
||||
wx.showToast({
|
||||
title: "此功能暂不可用",
|
||||
icon: "none",
|
||||
duration: 2000
|
||||
toSearch() {
|
||||
wx.navigateTo({
|
||||
url: "/pages/main/journal-search/index"
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
<view wx:if="{{isShowMoreMenu}}" class="more-menu">
|
||||
<t-cell-group class="content" theme="card">
|
||||
<t-cell title="新纪录" leftIcon="add" bind:tap="toCreater" />
|
||||
<t-cell title="按列表查找" leftIcon="view-list" bind:tap="toDetail" />
|
||||
<t-cell title="按列表查找" leftIcon="view-list" bind:tap="toSearch" />
|
||||
<t-cell title="按日期查找" leftIcon="calendar-1" bind:tap="openDateFilter" />
|
||||
<t-cell title="按地图查找" leftIcon="location" bind:tap="toDetail" />
|
||||
<t-cell title="按地图查找" leftIcon="location" />
|
||||
</t-cell-group>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@ -1,10 +1,14 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"t-cell": "tdesign-miniprogram/cell/cell",
|
||||
"t-popup": "tdesign-miniprogram/popup/popup",
|
||||
"t-radio": "tdesign-miniprogram/radio/radio",
|
||||
"t-navbar": "tdesign-miniprogram/navbar/navbar",
|
||||
"t-button": "tdesign-miniprogram/button/button",
|
||||
"t-checkbox": "tdesign-miniprogram/checkbox/checkbox",
|
||||
"t-cell-group": "tdesign-miniprogram/cell-group/cell-group",
|
||||
"journal-list": "../../../components/journal-list/index",
|
||||
"t-radio-group": "tdesign-miniprogram/radio-group/radio-group"
|
||||
}
|
||||
},
|
||||
"styleIsolation": "shared"
|
||||
}
|
||||
@ -102,66 +102,87 @@
|
||||
}
|
||||
}
|
||||
|
||||
.t-popup--bottom {
|
||||
padding-bottom: 0 !important;
|
||||
}
|
||||
|
||||
.archive-popup {
|
||||
|
||||
.container {
|
||||
width: 100vw;
|
||||
display: flex;
|
||||
overflow: hidden;
|
||||
background: var(--td-bg-color-container);
|
||||
flex-direction: column;
|
||||
border-top-left-radius: 16rpx;
|
||||
border-top-right-radius: 16rpx;
|
||||
|
||||
&.select-journal {
|
||||
height: 80vh;
|
||||
|
||||
.content {
|
||||
flex: 1;
|
||||
height: 0;
|
||||
}
|
||||
}
|
||||
|
||||
&.form {
|
||||
|
||||
.content {
|
||||
padding: 16rpx 32rpx;
|
||||
|
||||
.section {
|
||||
width: 100%;
|
||||
margin-top: 1.5rem;
|
||||
|
||||
.label {
|
||||
color: var(--theme-text-secondary);
|
||||
}
|
||||
|
||||
&.type {
|
||||
display: flex;
|
||||
|
||||
.radio {
|
||||
margin-right: 1em;
|
||||
}
|
||||
}
|
||||
|
||||
&.time {
|
||||
display: flex;
|
||||
|
||||
.picker {
|
||||
margin-right: .25rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
height: 116rpx;
|
||||
|
||||
border-bottom: 1px solid var(--td-component-stroke);
|
||||
|
||||
.title {
|
||||
flex: 1;
|
||||
color: var(--td-text-color-primary);
|
||||
font-size: 36rpx;
|
||||
text-align: center;
|
||||
font-weight: 600;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
|
||||
.placeholder {
|
||||
width: 128rpx;
|
||||
}
|
||||
|
||||
.btn {
|
||||
margin: 0 .5rem;
|
||||
|
||||
|
||||
&.back,
|
||||
&.cancel {
|
||||
color: var(--td-text-color-secondary);
|
||||
}
|
||||
|
||||
&.confirm {
|
||||
color: var(--theme-success);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.content {
|
||||
padding: 16rpx 32rpx;
|
||||
|
||||
.section {
|
||||
width: 100%;
|
||||
margin-top: 1.5rem;
|
||||
|
||||
.label {
|
||||
color: var(--theme-text-secondary);
|
||||
}
|
||||
|
||||
&.type {
|
||||
display: flex;
|
||||
|
||||
.radio {
|
||||
margin-right: 1em;
|
||||
}
|
||||
}
|
||||
|
||||
&.time {
|
||||
display: flex;
|
||||
|
||||
.picker {
|
||||
margin-right: .25rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,6 +25,8 @@ type MD5Result = {
|
||||
md5: string;
|
||||
}
|
||||
|
||||
type ArchiveStep = "select-type" | "select-journal" | "form";
|
||||
|
||||
interface MomentData {
|
||||
list: Item[];
|
||||
type: string;
|
||||
@ -42,6 +44,8 @@ interface MomentData {
|
||||
uploadProgress: number;
|
||||
isAuthLocation: boolean;
|
||||
isVisibleArchivePopup: boolean;
|
||||
archiveStep: ArchiveStep;
|
||||
selectedJournalId: number | null;
|
||||
}
|
||||
|
||||
Page({
|
||||
@ -60,7 +64,9 @@ Page({
|
||||
uploadTotal: "0 MB",
|
||||
uploadProgress: 0,
|
||||
isAuthLocation: false,
|
||||
isVisibleArchivePopup: false
|
||||
isVisibleArchivePopup: false,
|
||||
archiveStep: "select-type",
|
||||
selectedJournalId: null
|
||||
},
|
||||
async onLoad() {
|
||||
this.fetch();
|
||||
@ -163,7 +169,7 @@ Page({
|
||||
preview(e: WechatMiniprogram.BaseEvent) {
|
||||
const index = e.currentTarget.dataset.index;
|
||||
const total = this.data.list.length;
|
||||
|
||||
|
||||
const startIndex = Math.max(0, index - 25);
|
||||
const endIndex = Math.min(total, startIndex + 50);
|
||||
const newCurrentIndex = index - startIndex;
|
||||
@ -240,7 +246,7 @@ Page({
|
||||
});
|
||||
// 过滤文件
|
||||
const filterPath = md5Results.filter(item => filterMD5Result.indexOf(item.md5) !== -1)
|
||||
.map(item => item.path);
|
||||
.map(item => item.path);
|
||||
files = files.filter(file => filterPath.indexOf(file.tempFilePath) !== -1);
|
||||
if (files.length === 0) {
|
||||
wx.hideLoading();
|
||||
@ -295,7 +301,7 @@ Page({
|
||||
});
|
||||
uploadResolve(result.data[0].id);
|
||||
} else {
|
||||
uploadReject(new Error(`文件上传失败: ${result?.message || '未知错误'}`));
|
||||
uploadReject(new Error(`文件上传失败: ${result?.message || "未知错误"}`));
|
||||
}
|
||||
},
|
||||
fail: (err) => uploadReject(new Error(`文件上传失败: ${err.errMsg}`))
|
||||
@ -375,6 +381,47 @@ Page({
|
||||
}
|
||||
})
|
||||
},
|
||||
showArchivePopup() {
|
||||
this.setData({
|
||||
isVisibleArchivePopup: true,
|
||||
archiveStep: "select-type",
|
||||
selectedJournalId: null
|
||||
});
|
||||
},
|
||||
onArchiveToNew() {
|
||||
this.setData({
|
||||
archiveStep: "form",
|
||||
selectedJournalId: null
|
||||
});
|
||||
},
|
||||
onArchiveToExisting() {
|
||||
this.setData({
|
||||
archiveStep: "select-journal",
|
||||
selectedJournalId: null
|
||||
});
|
||||
},
|
||||
onJournalListSelect(e: any) {
|
||||
const { id } = e.detail;
|
||||
this.setData({
|
||||
selectedJournalId: id
|
||||
});
|
||||
},
|
||||
onJournalListConfirm() {
|
||||
if (this.data.selectedJournalId) {
|
||||
this.archiveChecked();
|
||||
}
|
||||
},
|
||||
onJournalListCancel() {
|
||||
this.setData({
|
||||
archiveStep: "select-type",
|
||||
selectedJournalId: null
|
||||
});
|
||||
},
|
||||
onNewJournalBack() {
|
||||
this.setData({
|
||||
archiveStep: "select-type"
|
||||
});
|
||||
},
|
||||
toggleArchivePopup() {
|
||||
this.setData({
|
||||
isVisibleArchivePopup: !this.data.isVisibleArchivePopup
|
||||
@ -434,22 +481,26 @@ Page({
|
||||
fail: handleFail
|
||||
});
|
||||
});
|
||||
const archiveData: any = {
|
||||
type: this.data.type,
|
||||
idea: this.data.idea,
|
||||
lat: this.data.location?.lat,
|
||||
lng: this.data.location?.lng,
|
||||
location: this.data.location?.text,
|
||||
pusher: openId,
|
||||
thumbIds: this.data.list.filter(item => item.checked).map(item => item.id)
|
||||
};
|
||||
// 如果选择了已存在的记录,添加 id 参数
|
||||
if (this.data.selectedJournalId) {
|
||||
archiveData.id = this.data.selectedJournalId;
|
||||
}
|
||||
wx.request({
|
||||
url: `${config.url}/journal/moment/archive`,
|
||||
method: "POST",
|
||||
header: {
|
||||
Key: wx.getStorageSync("key")
|
||||
},
|
||||
data: {
|
||||
type: this.data.type,
|
||||
idea: this.data.idea,
|
||||
createdAt: Date.parse(`${this.data.date} ${this.data.time}`),
|
||||
lat: this.data.location?.lat,
|
||||
lng: this.data.location?.lng,
|
||||
location: this.data.location?.text,
|
||||
pusher: openId,
|
||||
thumbIds: this.data.list.filter(item => item.checked).map(item => item.id)
|
||||
},
|
||||
data: archiveData,
|
||||
success: async (resp: any) => {
|
||||
if (resp.data && resp.data.code === 20000) {
|
||||
Events.emit("JOURNAL_REFRESH");
|
||||
@ -458,11 +509,12 @@ Page({
|
||||
idea: "",
|
||||
list: [],
|
||||
hasChecked: false,
|
||||
isArchiving: false
|
||||
isArchiving: false,
|
||||
selectedJournalId: undefined,
|
||||
isVisibleArchivePopup: false
|
||||
});
|
||||
await Toolkit.sleep(1000);
|
||||
this.fetch();
|
||||
this.toggleArchivePopup();
|
||||
} else {
|
||||
wx.showToast({ title: "归档失败", icon: "error" });
|
||||
this.setData({
|
||||
|
||||
@ -21,7 +21,7 @@
|
||||
class="btn archive"
|
||||
theme="primary"
|
||||
plain="true"
|
||||
bind:tap="toggleArchivePopup"
|
||||
bind:tap="showArchivePopup"
|
||||
disabled="{{isSubmitting || list.length === 0 || !hasChecked}}"
|
||||
>归档已选</t-button>
|
||||
</view>
|
||||
@ -87,18 +87,44 @@
|
||||
usingCustomNavbar
|
||||
bind:visible-change="onArchivePopupVisibleChange"
|
||||
>
|
||||
<view class="container">
|
||||
<!-- 选择归档方式 -->
|
||||
<view wx:if="{{archiveStep === 'select-type'}}" class="container select-type">
|
||||
<view class="header">
|
||||
<t-button
|
||||
class="btn cancel"
|
||||
aria-role="button"
|
||||
bind:tap="toggleArchivePopup"
|
||||
variant="text"
|
||||
>取消</t-button>
|
||||
<view class="title">归档已选项</view>
|
||||
<view class="title">归档到</view>
|
||||
<view class="placeholder"></view>
|
||||
</view>
|
||||
<t-cell-group class="content">
|
||||
<t-cell
|
||||
title="新纪录"
|
||||
leftIcon="bookmark-add"
|
||||
arrow
|
||||
bind:tap="onArchiveToNew"
|
||||
/>
|
||||
<t-cell
|
||||
title="已存在记录"
|
||||
leftIcon="view-list"
|
||||
arrow
|
||||
bind:tap="onArchiveToExisting"
|
||||
/>
|
||||
</t-cell-group>
|
||||
</view>
|
||||
<!-- 归档表单 -->
|
||||
<view wx:if="{{archiveStep === 'form'}}" class="container form">
|
||||
<view class="header">
|
||||
<t-button
|
||||
class="btn back"
|
||||
bind:tap="onNewJournalBack"
|
||||
variant="text"
|
||||
>返回</t-button>
|
||||
<view class="title">归档到新纪录</view>
|
||||
<t-button
|
||||
class="btn confirm"
|
||||
aria-role="button"
|
||||
theme="primary"
|
||||
bind:tap="archiveChecked"
|
||||
variant="text"
|
||||
>确定</t-button>
|
||||
@ -138,4 +164,31 @@
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 选择已存在记录 -->
|
||||
<view wx:if="{{archiveStep === 'select-journal'}}" class="container select-journal">
|
||||
<view class="header">
|
||||
<t-button
|
||||
class="btn back"
|
||||
bind:tap="onJournalListCancel"
|
||||
variant="text"
|
||||
>返回</t-button>
|
||||
<view class="title">归档到已存在记录</view>
|
||||
<t-button
|
||||
class="btn confirm"
|
||||
bind:tap="onJournalListConfirm"
|
||||
theme="primary"
|
||||
variant="text"
|
||||
disabled="{{!selectedJournalId}}"
|
||||
>确定</t-button>
|
||||
</view>
|
||||
<view class="content">
|
||||
<journal-list
|
||||
visible="{{archiveStep === 'select-journal'}}"
|
||||
searchable="{{true}}"
|
||||
type="{{type}}"
|
||||
selectedId="{{selectedJournalId}}"
|
||||
bind:select="onJournalListSelect"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
</t-popup>
|
||||
@ -1,17 +1,14 @@
|
||||
// pages/main/portfolio/index.ts
|
||||
|
||||
import config from "../../../config/index";
|
||||
import { JournalPage, JournalPageType } from "../../../types/Journal";
|
||||
import { QueryPage } from "../../../types/Model";
|
||||
import Events from "../../../utils/Events";
|
||||
import Time from "../../../utils/Time";
|
||||
import { Journal, JournalItemType } from "../journal/index";
|
||||
|
||||
interface IPortfolioData {
|
||||
page: {
|
||||
index: number;
|
||||
size: number;
|
||||
type: string;
|
||||
orderMap?: object;
|
||||
}
|
||||
page: JournalPage;
|
||||
list: Journal[];
|
||||
isFetching: boolean;
|
||||
isFinished: boolean;
|
||||
@ -23,9 +20,9 @@ Page({
|
||||
page: {
|
||||
index: 0,
|
||||
size: 8,
|
||||
type: "PORTFOLIO",
|
||||
orderMap: {
|
||||
createdAt: "DESC"
|
||||
type: JournalPageType.NORMAL,
|
||||
equalsExample: {
|
||||
type: "PORTFOLIO"
|
||||
}
|
||||
},
|
||||
list: [],
|
||||
@ -39,9 +36,9 @@ Page({
|
||||
page: {
|
||||
index: 0,
|
||||
size: 8,
|
||||
type: "PORTFOLIO",
|
||||
orderMap: {
|
||||
createdAt: "DESC"
|
||||
type: JournalPageType.NORMAL,
|
||||
equalsExample: {
|
||||
type: "PORTFOLIO"
|
||||
}
|
||||
},
|
||||
list: [],
|
||||
@ -111,9 +108,9 @@ Page({
|
||||
page: {
|
||||
index: this.data.page.index + 1,
|
||||
size: 8,
|
||||
type: "PORTFOLIO",
|
||||
orderMap: {
|
||||
createdAt: "DESC"
|
||||
type: JournalPageType.NORMAL,
|
||||
equalsExample: {
|
||||
type: "PORTFOLIO"
|
||||
}
|
||||
},
|
||||
list: this.data.list.concat(result),
|
||||
|
||||
@ -5,6 +5,9 @@
|
||||
|
||||
/* 浅色模式变量 */
|
||||
page {
|
||||
/* 微信标准色 */
|
||||
--theme-wx: #07C160;
|
||||
|
||||
/* === 背景色 === */
|
||||
--theme-bg-primary: #FFFFFF;
|
||||
--theme-bg-secondary: #F5F5F5;
|
||||
@ -54,6 +57,9 @@ page {
|
||||
|
||||
/* 深色模式变量 */
|
||||
page[data-weui-theme="dark"] {
|
||||
/* 微信标准色 */
|
||||
--theme-wx: #07C160;
|
||||
|
||||
/* === 背景色 === */
|
||||
--theme-bg-primary: #1A1A1A;
|
||||
--theme-bg-secondary: #2A2A2A;
|
||||
|
||||
11
miniprogram/types/Journal.ts
Normal file
11
miniprogram/types/Journal.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { QueryPage } from "./Model";
|
||||
|
||||
export type JournalPage = {
|
||||
type: JournalPageType;
|
||||
} & QueryPage;
|
||||
|
||||
export enum JournalPageType {
|
||||
|
||||
NORMAL = "NORMAL",
|
||||
PREVIEW = "PREVIEW"
|
||||
}
|
||||
44
miniprogram/types/Model.ts
Normal file
44
miniprogram/types/Model.ts
Normal file
@ -0,0 +1,44 @@
|
||||
// 基本实体模型
|
||||
export type Model = {
|
||||
id?: number;
|
||||
|
||||
createdAt?: number;
|
||||
updatedAt?: number;
|
||||
deletedAt?: number;
|
||||
}
|
||||
|
||||
export type Response = {
|
||||
code: number;
|
||||
msg?: string;
|
||||
data: object;
|
||||
}
|
||||
|
||||
export type QueryPage = {
|
||||
index: number;
|
||||
size: number;
|
||||
orderMap?: { [key: string]: OrderType };
|
||||
equalsExample?: { [key: string]: string | undefined | null };
|
||||
likeExample?: { [key: string]: string | undefined | null };
|
||||
}
|
||||
|
||||
export enum OrderType {
|
||||
ASC = "ASC",
|
||||
DESC = "DESC"
|
||||
}
|
||||
|
||||
export type QueryPageResult<T> = {
|
||||
total: number;
|
||||
list: T[];
|
||||
}
|
||||
|
||||
// 携带验证码的请求体
|
||||
export type CaptchaData<T> = {
|
||||
from: string;
|
||||
captcha: string;
|
||||
data: T;
|
||||
}
|
||||
|
||||
export type KeyValue<T> = {
|
||||
key: string;
|
||||
value: T;
|
||||
}
|
||||
Reference in New Issue
Block a user