文件
yjyf/yjyf-app/components/user/UserMessageView.vue
MiAn 3ebd795cbb feat(ui): 新增/优化界面样式、图标及交互组件
- 新增多个功能图标(箭头、盾牌、位置等)
- 优化全局按钮、标签、输入框等组件样式
- 修复导航栏高度计算逻辑,适配微信小程序
- 优化消息页、订单页、个人中心等页面布局
- 修复微信支付配置及通知接口问题
2026-11-09 09:57:22 +08:00

110 行
3.8 KiB
Vue

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<template>
<view class="user-message-view">
<!-- 统一顶部橙色导航栏 -->
<YjyfNavBar theme="orange" title="消息中心" />
<view class="head">
<view class="cats">
<view v-for="c in cats" :key="c.key" class="cat clickable-hover" :class="{ on: category === c.key }" @tap="switchCat(c.key)">{{ c.name }}</view>
</view>
<text class="read-all clickable-hover" @tap="readAll">全部已读</text>
</view>
<view class="list">
<view class="msg" :class="{ unread: !m.is_read }" v-for="m in list" :key="m.id" @tap="open(m)">
<view class="msg-top">
<view class="dot" v-if="!m.is_read"></view>
<text class="title">{{ m.title }}</text>
<text class="time">{{ m.time_text }}</text>
</view>
<text class="content">{{ m.content }}</text>
<text class="go" v-if="m.order_id">查看订单 ›</text>
</view>
<view class="empty" v-if="!loading && !list.length">暂无消息</view>
</view>
</view>
</template>
<script setup>
import { ref, onMounted } from 'vue';
import api from '@/utils/api.js';
import { isLogin, toLogin } from '@/utils/request.js';
import YjyfNavBar from '@/components/YjyfNavBar.vue';
const list = ref([]);
const loading = ref(false);
const category = ref('all');
const cats = [
{ key: 'all', name: '全部' },
{ key: 'order', name: '订单' },
{ key: 'system', name: '系统' },
{ key: 'remind', name: '提醒' }
];
async function load() {
if (!isLogin()) { toLogin(); return; }
loading.value = true;
try {
const res = await api.messageList({ category: category.value, limit: 30 });
list.value = res.list || [];
} catch (e) {
} finally {
loading.value = false;
}
}
function switchCat(k) {
category.value = k;
load();
}
async function open(m) {
if (!m.is_read) {
try {
await api.messageRead({ id: m.id });
m.is_read = 1;
} catch (e) {}
}
if (m.order_id) {
uni.navigateTo({ url: `/pages/order/detail?id=${m.order_id}` });
}
}
async function readAll() {
try {
const res = await api.messageReadAll({});
uni.showToast({ title: '已全部标记已读(' + res.count + ' 条)', icon: 'none' });
load();
} catch (e) {}
}
onMounted(() => {
load();
});
defineExpose({
load
});
</script>
<style scoped>
.user-message-view { min-height: 100vh; background: #F5F6F8; padding-bottom: 40rpx; }
.head { display: flex; align-items: center; background: #fff; padding: 20rpx 24rpx; box-shadow: 0 4rpx 12rpx rgba(0,0,0,.03); }
.cats { flex: 1; display: flex; align-items: center; gap: 16rpx; }
.cat { height: 56rpx; padding: 0 26rpx; display: inline-flex; align-items: center; justify-content: center; border-radius: 28rpx; background: #F5F6F8; font-size: 24rpx; color: #444444; line-height: 1; }
.cat.on { background: #FFF7F0; color: #F0710D; font-weight: 600; }
.read-all { display: inline-flex; align-items: center; height: 56rpx; line-height: 56rpx; font-size: 24rpx; color: #F0710D; font-weight: 500; }
.list { padding: 24rpx; }
.msg { background: #fff; border-radius: 20rpx; padding: 22rpx 24rpx; margin-bottom: 18rpx; box-shadow: 0 6rpx 20rpx rgba(240,129,31,.06); }
.msg.unread { border-left: 6rpx solid #F0710D; }
.msg-top { display: flex; align-items: center; }
.dot { width: 12rpx; height: 12rpx; border-radius: 50%; background: #F0710D; margin-right: 10rpx; }
.title { flex: 1; min-width: 0; font-size: 28rpx; font-weight: 600; color: #1F1F1F; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.time { flex-shrink: 0; margin-left: 12rpx; font-size: 22rpx; color: #AAAAAA; }
.content { display: block; margin-top: 10rpx; font-size: 24rpx; color: #666; line-height: 34rpx; }
.go { display: block; margin-top: 10rpx; font-size: 22rpx; color: #4A7CFF; }
.empty { padding: 110rpx 0; text-align: center; font-size: 24rpx; color: #9A9A9A; }
.clickable-hover:active { opacity: 0.85; transform: scale(0.98); }
</style>