主要更新uniapp相关功能

This commit is contained in:
hero920103 committed 2026-10-07 00:59:05 +08:00
1 parent aa92ca40a2
commit 5b4dbb2b46
65 files changed
+8532 -1921

No files matched your search

+189
View File
@@ -0,0 +1,189 @@
<template>
<view class="page">
<scroll-view class="body" scroll-y :show-scrollbar="false">
<view class="body-inner">
<view v-if="loading" class="state-box">
<text class="state-text">加载中...</text>
</view>
<u-empty
v-else-if="!notice"
mode="list"
:icon-size="80"
text="公告不存在或已被删除"
/>
<block v-else>
<view class="detail-card">
<view class="tag-row">
<u-tag v-if="notice.is_top" text="置顶" type="error" size="mini" />
<u-tag
:text="getNoticeLevelLabel(notice.level)"
:type="levelTagType(notice.level)"
size="mini"
plain
/>
<u-tag :text="getNoticeTypeLabel(notice.notice_type)" type="primary" size="mini" plain />
</view>
<text class="title">{{ notice.title }}</text>
<view class="meta">
<text>{{ notice.publisher_name || '系统' }}</text>
<text>·</text>
<text>{{ notice.publish_time || '-' }}</text>
</view>
<view class="stat-row">
<view class="stat-item">
<FaIcon name="eye" color="#8a94ad" :size="13" />
<text>{{ notice.read_count || 0 }} 次阅读</text>
</view>
</view>
</view>
<view class="content-card">
<text class="content">{{ notice.content || '(无正文)' }}</text>
</view>
</block>
<view class="bottom-space" />
</view>
</scroll-view>
</view>
</template>
<script setup>
import { ref, onMounted } from 'vue'
import { getNotice, getNoticeTypeLabel, getNoticeLevelLabel } from '@/api/oa.js'
import { isLoggedIn } from '@/utils/auth.js'
const id = ref(0)
const notice = ref(null)
const loading = ref(true)
onMounted(() => {
if (!isLoggedIn()) {
uni.reLaunch({ url: '/pages/login/login' })
return
}
const pages = getCurrentPages()
const current = pages[pages.length - 1]
id.value = Number((current && current.options && current.options.id) || 0)
loadDetail()
})
/** 公告级别 → u-tag 类型:1 重要 / 2 紧急 / 其他 普通 */
function levelTagType(level) {
const n = Number(level)
if (n === 1) return 'warning'
if (n === 2) return 'error'
return 'info'
}
async function loadDetail() {
if (!id.value) {
loading.value = false
return
}
loading.value = true
try {
notice.value = await getNotice(id.value)
} catch (e) {
notice.value = null
} finally {
loading.value = false
}
}
</script>
<style lang="scss" scoped>
@import '@/src/styles/page-common.scss';
.page {
min-height: 100vh;
background: $color-bg-page;
display: flex;
flex-direction: column;
}
.body {
flex: 1;
height: 0;
}
.body-inner {
padding: 24rpx $page-padding-x 0;
}
.detail-card {
@include card;
padding: 32rpx 28rpx;
}
.tag-row {
display: flex;
align-items: center;
gap: 10rpx;
margin-bottom: 18rpx;
}
.title {
display: block;
font-size: 38rpx;
font-weight: 600;
line-height: 1.45;
color: $color-text;
}
.meta {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 8rpx;
margin-top: 18rpx;
font-size: 24rpx;
color: $color-text-muted;
}
.stat-row {
margin-top: 18rpx;
padding-top: 18rpx;
border-top: 1rpx solid $color-divider;
}
.stat-item {
display: flex;
align-items: center;
gap: 8rpx;
font-size: 23rpx;
color: $color-text-muted;
}
.content-card {
@include card;
margin-top: 20rpx;
padding: 32rpx 28rpx;
}
.content {
font-size: 29rpx;
line-height: 1.75;
color: $color-text;
white-space: pre-wrap;
word-break: break-all;
}
.state-box {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 200rpx 48rpx;
gap: 20rpx;
}
.state-text {
font-size: 26rpx;
color: $color-text-muted;
text-align: center;
}
.bottom-space {
height: 48rpx;
}
</style>
+194
View File
@@ -0,0 +1,194 @@
<template>
<view class="page">
<view class="toolbar">
<u-search
v-model="keyword"
placeholder="搜索公告标题"
:show-action="false"
shape="round"
bg-color="#f1f5f9"
color="#0f172a"
@search="loadNotices"
@clear="clearSearch"
/>
</view>
<scroll-view class="list-scroll" scroll-y :show-scrollbar="false">
<view v-if="loading" class="state-box">
<text class="state-text">加载中...</text>
</view>
<u-empty
v-else-if="list.length === 0"
mode="list"
:icon-size="80"
:text="keyword ? '未找到相关公告' : '暂无公告'"
/>
<view v-else class="notice-list">
<view v-for="item in list" :key="item.id" class="notice-card" @tap="openDetail(item.id)">
<view class="notice-head">
<u-tag v-if="item.is_top" text="置顶" type="error" size="mini" />
<u-tag :text="getNoticeLevelLabel(item.level)" :type="levelTagType(item.level)" size="mini" plain />
<text class="notice-title">{{ item.title }}</text>
</view>
<text v-if="item.summary" class="notice-summary">{{ item.summary }}</text>
<view class="notice-meta">
<text class="meta-type">{{ getNoticeTypeLabel(item.notice_type) }}</text>
<text>{{ item.publisher_name || '系统' }}</text>
<text>·</text>
<text>{{ item.publish_time || '-' }}</text>
<text>·</text>
<text>阅读 {{ item.read_count || 0 }}</text>
</view>
</view>
</view>
<view class="bottom-space" />
</scroll-view>
</view>
</template>
<script setup>
import { ref, onMounted } from 'vue'
import { fetchNotices, getNoticeTypeLabel, getNoticeLevelLabel } from '@/api/oa.js'
import { isLoggedIn } from '@/utils/auth.js'
const keyword = ref('')
const list = ref([])
const loading = ref(false)
onMounted(() => {
if (!isLoggedIn()) {
uni.reLaunch({ url: '/pages/login/login' })
return
}
loadNotices()
})
async function loadNotices() {
loading.value = true
try {
const res = await fetchNotices({ keyword: keyword.value, pageSize: 50 })
list.value = res.list
} catch (e) {
uni.showToast({ title: '加载失败', icon: 'none' })
} finally {
loading.value = false
}
}
function clearSearch() {
keyword.value = ''
loadNotices()
}
/** 公告级别 → uview tag 类型 */
function levelTagType(level) {
const n = Number(level)
if (n === 1) return 'warning'
if (n === 2) return 'error'
return 'info'
}
function openDetail(id) {
uni.navigateTo({ url: `/pages/oa/notice/detail?id=${id}` })
}
</script>
<style lang="scss" scoped>
@import '@/src/styles/page-common.scss';
.page {
min-height: 100vh;
background: $color-bg-page;
display: flex;
flex-direction: column;
}
.toolbar {
flex-shrink: 0;
padding: 20rpx $page-padding-x;
background: $color-card;
box-shadow: $shadow-header;
}
.list-scroll {
flex: 1;
height: 0;
}
.notice-list {
padding: 24rpx $page-padding-x 0;
}
.notice-card {
@include card;
padding: 26rpx 24rpx;
margin-bottom: 20rpx;
&:active {
background: $color-bg-page;
}
}
.notice-head {
display: flex;
align-items: flex-start;
gap: 10rpx;
}
.notice-title {
flex: 1;
min-width: 0;
font-size: 30rpx;
font-weight: 500;
line-height: 1.45;
color: $color-text;
}
.notice-summary {
display: block;
margin-top: 12rpx;
font-size: 26rpx;
line-height: 1.5;
color: $color-text-secondary;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
overflow: hidden;
}
.notice-meta {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 8rpx;
margin-top: 16rpx;
font-size: 22rpx;
color: $color-text-muted;
}
.meta-type {
color: $color-primary;
background: $color-primary-bg;
padding: 2rpx 12rpx;
border-radius: $radius-sm;
}
.state-box {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 160rpx 48rpx;
gap: 20rpx;
}
.state-text {
font-size: 26rpx;
color: $color-text-muted;
text-align: center;
}
.bottom-space {
height: 40rpx;
}
</style>