重构项目文件夹目录

This commit is contained in:
2026-06-15 15:53:55 +08:00
parent 8093e07190
commit 7cbe5b3de5
1098 changed files with 34 additions and 4441 deletions
@@ -0,0 +1,218 @@
/**
* Purpose: userApi supports index.js by holding or executing the user api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const userApi = require('../../api/user')
/**
* Purpose: navigation supports index.js by holding or executing the navigation page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const navigation = require('../../utils/navigation')
const { previewImagesSafely } = require('../../utils/file')
/**
* notifications page logic.
* Call guide: page data drives the WXML template, and each method is called by user events or lifecycle callbacks.
*/
Page({
/**
* Purpose: data supports index.js by holding or executing the data page or API role.
* Usage: import, call, read, or update this page-data from the owning page/module while preserving the surrounding loading and permission flow.
*/
data: {
/**
* Purpose: loading supports index.js by holding or executing the loading page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loading: false,
/**
* Purpose: messages supports index.js by holding or executing the messages page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
messages: [],
/**
* Purpose: unreadCount supports index.js by holding or executing the unread count page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
unreadCount: 0,
/**
* Purpose: detailVisible supports index.js by holding or executing the detail visible page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
detailVisible: false,
/**
* Purpose: currentMessage supports index.js by holding or executing the current message page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
currentMessage: null
},
/**
* `onShow` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
onShow() {
this.loadMessages()
},
async loadMessages() {
if (!navigation.ensureLogin('查看消息通知')) {
return
}
this.setData({ loading: true })
try {
const messages = await userApi.listMyMessages()
const list = Array.isArray(messages) ? messages : []
this.setData({
/**
* Purpose: messages supports index.js by holding or executing the messages page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
messages: list,
/**
* Purpose: unreadCount supports index.js by holding or executing the unread count page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
unreadCount: list.filter(item => item.readStatus !== 1).length
})
} catch (error) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: error.message || '消息加载失败',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
} finally {
this.setData({ loading: false })
}
},
async handleOpenMessage(event) {
const id = event.currentTarget.dataset.id
const item = this.data.messages.find(message => String(message.id) === String(id))
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!item) {
return
}
const actionTarget = navigation.buildMessageActionPath(item)
if (actionTarget) {
try {
if (item.readStatus !== 1) {
await userApi.markMessageRead(item.id)
}
const opened = await navigation.openActionPath(actionTarget)
await this.loadMessages()
if (opened) {
return
}
} catch (error) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: error.message || '打开消息失败',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
return
}
}
this.setData({
/**
* Purpose: currentMessage supports index.js by holding or executing the current message page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
currentMessage: item,
/**
* Purpose: detailVisible supports index.js by holding or executing the detail visible page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
detailVisible: true
})
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (item.readStatus !== 1) {
try {
await userApi.markMessageRead(item.id)
await this.loadMessages()
} catch (error) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: error.message || '标记已读失败',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
}
}
},
/**
* `handleCloseDetail` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
handleCloseDetail() {
this.setData({
/**
* Purpose: detailVisible supports index.js by holding or executing the detail visible page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
detailVisible: false,
/**
* Purpose: currentMessage supports index.js by holding or executing the current message page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
currentMessage: null
})
},
/**
* `handlePreviewImage` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
handlePreviewImage() {
const imageUrl = this.data.currentMessage && this.data.currentMessage.imageUrl
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!imageUrl) {
return
}
previewImagesSafely(imageUrl, [imageUrl])
},
/**
* Purpose: noop supports index.js by holding or executing the noop page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
noop() {},
/**
* `handleBack` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
handleBack() {
navigation.goBack('/pages/profile/index')
}
})
@@ -0,0 +1,6 @@
{
"navigationStyle": "custom",
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,50 @@
<navigation-bar title="消息通知" showBack="{{true}}" fallbackPath="/pages/profile/index" color="{{navThemeColor || '#4A443F'}}" background="{{navThemeBackground || '#FDFBF9'}}"></navigation-bar>
<view class="notifications-page">
<view class="summary-card">
<view class="summary-title">消息通知</view>
<view class="summary-desc">{{unreadCount}} 条未读消息</view>
</view>
<view wx:if="{{messages.length}}" class="message-list">
<view
wx:for="{{messages}}"
wx:key="id"
class="message-item {{item.readStatus === 1 ? '' : 'unread'}}"
data-id="{{item.id}}"
bindtap="handleOpenMessage"
>
<view class="message-dot"></view>
<view class="message-copy">
<view class="message-title">{{item.title}}</view>
<view class="message-meta">{{item.publisherName || '系统消息'}} · {{item.publishTime || item.createTime}}</view>
<view wx:if="{{item.imageUrl}}" class="message-badge">含图片</view>
</view>
<view class="message-arrow">></view>
</view>
</view>
<view wx:else class="empty-card">
暂无消息
</view>
<view wx:if="{{detailVisible && currentMessage}}" class="detail-mask" bindtap="handleCloseDetail">
<view class="detail-panel" catchtap="noop">
<view class="detail-header">
<view>
<view class="detail-title">{{currentMessage.title}}</view>
<view class="detail-meta">{{currentMessage.publisherName || '系统消息'}} · {{currentMessage.publishTime || currentMessage.createTime}}</view>
</view>
<button class="detail-close" size="mini" bindtap="handleCloseDetail">关闭</button>
</view>
<view wx:if="{{currentMessage.content}}" class="detail-content">{{currentMessage.content}}</view>
<image
wx:if="{{currentMessage.imageUrl}}"
class="detail-image"
src="{{currentMessage.imageUrl}}"
mode="aspectFit"
bindtap="handlePreviewImage"
/>
</view>
</view>
</view>
@@ -0,0 +1,152 @@
.notifications-page {
min-height: 100vh;
padding: 176rpx 28rpx 40rpx;
background: var(--theme-page-bg);
box-sizing: border-box;
}
.summary-card,
.message-item,
.empty-card {
border-radius: 18rpx;
background: #ffffff;
box-shadow: 0 16rpx 40rpx rgba(150, 82, 105, 0.08);
}
.summary-card {
padding: 34rpx;
margin-bottom: 22rpx;
}
.summary-title {
color: var(--text-primary);
font-size: 38rpx;
font-weight: 800;
}
.summary-desc {
margin-top: 8rpx;
color: #927f88;
font-size: 26rpx;
}
.message-list {
display: flex;
flex-direction: column;
gap: 18rpx;
}
.message-item {
display: flex;
align-items: center;
gap: 18rpx;
padding: 28rpx;
}
.message-dot {
width: 16rpx;
height: 16rpx;
border-radius: 50%;
background: #d7c9cf;
}
.message-item.unread .message-dot {
background: #ff5c8a;
}
.message-copy {
flex: 1;
min-width: 0;
}
.message-title {
color: var(--text-primary);
font-size: 30rpx;
font-weight: 700;
}
.message-meta {
margin-top: 8rpx;
color: #9b8d94;
font-size: 24rpx;
}
.message-badge {
display: inline-block;
margin-top: 10rpx;
padding: 4rpx 16rpx;
border-radius: 999rpx;
background: #fff0f4;
color: #d74270;
font-size: 22rpx;
}
.message-arrow {
color: #c3aab4;
}
.empty-card {
padding: 60rpx;
color: #9b8d94;
text-align: center;
}
.detail-mask {
position: fixed;
inset: 0;
z-index: 1000;
display: flex;
align-items: flex-end;
background: rgba(26, 18, 24, 0.45);
}
.detail-panel {
width: 100%;
max-height: 82vh;
padding: 34rpx 30rpx 46rpx;
border-radius: 28rpx 28rpx 0 0;
background: #fff;
box-sizing: border-box;
overflow-y: auto;
}
.detail-header {
display: flex;
gap: 20rpx;
align-items: flex-start;
justify-content: space-between;
}
.detail-title {
color: var(--text-primary);
font-size: 34rpx;
font-weight: 800;
}
.detail-meta {
margin-top: 8rpx;
color: #9b8d94;
font-size: 24rpx;
}
.detail-close {
margin: 0;
border-radius: 999rpx;
}
.detail-content {
margin-top: 28rpx;
color: #4b4048;
font-size: 28rpx;
line-height: 1.8;
white-space: pre-wrap;
}
.detail-image {
width: 100%;
min-height: 320rpx;
max-height: 760rpx;
margin-top: 24rpx;
border-radius: 18rpx;
background: var(--theme-page-bg);
}