文件
yjyf/yjyf-app/components/master/MasterMessageView.vue
MiAn fafddceaf2 feat: 新增发票抬头、晒单、钱包日志等模型及后台管理功能
- 新增 invoice_title、showcase、wallet_log 模型及对应语言包
- 新增后台控制器、视图及搜索字段配置
- 修复服务类目删除保护逻辑
- 优化后台登录页面文案及样式
- 新增前端角色切换逻辑及页面拦截
- 新增 SVG 图标及样式变量
- 修复接口权限及下拉框默认值问题
2026-11-11 17:02:35 +08:00

252 行
7.3 KiB
Vue

<template>
<view class="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>
<YjyfRefreshScroll
class="msg-scroll"
theme="light"
:refresh-task="load"
>
<view class="list">
<view class="msg clickable-hover" :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>
<view class="go-row" v-if="m.order_id">
<text class="go">查看工单详情</text>
<image class="go-arrow" src="/static/icons/arrow-right.svg" mode="aspectFit" />
</view>
</view>
<view class="empty-box" v-if="!loading && !list.length">
<image class="empty-img" src="/static/icons/empty-message.svg" mode="aspectFit" />
<text class="empty-txt">暂无消息通知</text>
</view>
</view>
</YjyfRefreshScroll>
<!-- 系统通知详情抽屉 -->
<view class="detail-mask" v-if="activeMsg" @tap="activeMsg = null">
<view class="detail-sheet" @tap.stop>
<view class="ds-head">
<text class="ds-title">{{ activeMsg.title }}</text>
<view class="ds-close clickable-hover" @tap="activeMsg = null">
<image class="ds-close-ico" src="/static/icons/close.svg" mode="aspectFit" />
</view>
</view>
<text class="ds-time">{{ activeMsg.time_text }}</text>
<text class="ds-content">{{ activeMsg.content }}</text>
<view class="ds-btn clickable-hover" @tap="activeMsg = null">我知道了</view>
</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';
import YjyfRefreshScroll from '@/components/YjyfRefreshScroll.vue';
const emit = defineEmits(['switch-tab']);
const list = ref([]);
const loading = ref(false);
const category = ref('all');
const activeMsg = ref(null);
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({ type: 'master', category: category.value, limit: 30 });
list.value = res.list || [];
} catch (e) {
} finally {
loading.value = false;
}
}
function switchCat(k) {
category.value = k;
load();
}
const readingAll = ref(false);
async function open(m) {
if (!m.is_read && !m._reading) {
m._reading = true;
try {
await api.messageRead({ id: m.id, type: 'master' });
m.is_read = 1;
uni.$emit('yjyf:unreadChanged');
} catch (e) {
} finally {
m._reading = false;
}
}
if (m.order_id) {
uni.navigateTo({ url: `/pages/master/detail?id=${m.order_id}` });
} else {
activeMsg.value = m;
}
}
async function readAll() {
if (readingAll.value) return;
readingAll.value = true;
try {
const res = await api.messageReadAll({ type: 'master' });
uni.showToast({ title: '已全部标记已读(' + (res.count || 0) + ' 条)', icon: 'none' });
uni.$emit('yjyf:unreadChanged');
await load();
} catch (e) {
} finally {
readingAll.value = false;
}
}
onMounted(() => {
load();
});
defineExpose({
load
});
</script>
<style lang="scss" scoped>
.message-view {
height: calc(100vh - 112rpx - constant(safe-area-inset-bottom));
height: calc(100vh - 112rpx - env(safe-area-inset-bottom));
display: flex;
flex-direction: column;
overflow: hidden;
background: $yjyf-bg-page;
}
.head {
flex-shrink: 0;
position: relative;
z-index: 2;
display: flex;
align-items: center;
background: $yjyf-bg-card;
padding: 20rpx $yjyf-space-md;
border-bottom: 1rpx solid $yjyf-border-color;
}
.msg-scroll { flex: 1; height: 0; width: 100%; }
.cats { flex: 1; display: flex; gap: 14rpx; }
.cat {
padding: 0 24rpx;
height: 56rpx;
line-height: 56rpx;
border-radius: $yjyf-radius-pill;
background: $yjyf-bg-page;
font-size: $yjyf-font-sub;
color: $yjyf-text-regular;
}
.cat.on {
background: $yjyf-primary-bg;
color: $yjyf-primary;
font-weight: 600;
}
.read-all { font-size: $yjyf-font-sub; color: $yjyf-primary; font-weight: 500; }
.list { padding: $yjyf-space-md; }
.msg {
background: $yjyf-bg-card;
border-radius: $yjyf-radius-md;
padding: $yjyf-space-md;
margin-bottom: 20rpx;
box-shadow: $yjyf-shadow-card;
}
.msg.unread { border-left: 6rpx solid $yjyf-primary; }
.msg-top { display: flex; align-items: center; }
.dot { width: 14rpx; height: 14rpx; border-radius: 50%; background: $yjyf-primary; margin-right: 12rpx; flex-shrink: 0; }
.title { flex: 1; min-width: 0; font-size: $yjyf-font-body; font-weight: 700; color: $yjyf-text-main; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.time { flex-shrink: 0; margin-left: 12rpx; font-size: $yjyf-font-micro; color: $yjyf-text-muted; }
.content {
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
margin-top: 12rpx;
font-size: $yjyf-font-sub;
color: $yjyf-text-regular;
line-height: 1.5;
}
.go-row {
margin-top: 16rpx;
padding-top: 14rpx;
border-top: 1rpx solid $yjyf-border-color;
display: flex;
align-items: center;
justify-content: space-between;
}
.go { font-size: $yjyf-font-sub; color: $yjyf-primary; font-weight: 500; }
.go-arrow { width: 26rpx; height: 26rpx; opacity: 0.6; }
.empty-box {
padding: 140rpx 0;
display: flex;
flex-direction: column;
align-items: center;
}
.empty-img { width: 160rpx; height: 160rpx; margin-bottom: 20rpx; }
.empty-txt { font-size: $yjyf-font-sub; color: $yjyf-text-secondary; }
.detail-mask {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.55);
z-index: 1000;
display: flex;
flex-direction: column;
justify-content: flex-end;
}
.detail-sheet {
background: $yjyf-bg-card;
border-radius: $yjyf-radius-lg $yjyf-radius-lg 0 0;
padding: 36rpx $yjyf-space-lg calc(36rpx + env(safe-area-inset-bottom));
}
.ds-head { display: flex; align-items: center; justify-content: space-between; gap: 16rpx; }
.ds-title { flex: 1; font-size: $yjyf-font-title; font-weight: 700; color: $yjyf-text-main; }
.ds-close { width: 56rpx; height: 56rpx; display: flex; align-items: center; justify-content: flex-end; }
.ds-close-ico { width: 32rpx; height: 32rpx; opacity: 0.65; }
.ds-time { display: block; margin-top: 10rpx; font-size: $yjyf-font-micro; color: $yjyf-text-muted; }
.ds-content { display: block; margin: 28rpx 0 40rpx; font-size: $yjyf-font-body; color: $yjyf-text-regular; line-height: 1.65; white-space: pre-wrap; }
.ds-btn {
height: 88rpx;
border-radius: $yjyf-radius-pill;
background: $yjyf-gradient-primary;
color: #FFFFFF;
font-size: $yjyf-font-body;
font-weight: 600;
display: flex;
align-items: center;
justify-content: center;
}
.clickable-hover:active { opacity: 0.85; }
</style>