完善uniapp

This commit is contained in:
2026-07-16 00:35:50 +08:00
parent 61a937f7a3
commit 834c088aa2
29 changed files with 4444 additions and 305 deletions
+120 -25
View File
@@ -50,13 +50,13 @@
<view class="section">
<view class="section-header">
<text class="section-title">最近动态</text>
<text class="section-more">查看全部</text>
</view>
<view class="activity-card">
<view class="activity-item" v-for="(item, index) in activities" :key="index">
<view class="activity-icon">
<FaIcon name="circle" color="#3c9cff" :size="8" />
</view>
<view v-if="activities.length === 0" class="activity-empty">
<text class="activity-empty-text">暂无动态</text>
</view>
<view class="activity-item" v-for="(item, index) in activities" :key="index" @tap="onActivityTap(item)">
<view class="activity-dot" :class="item.type" />
<view class="activity-body">
<text class="activity-title">{{ item.title }}</text>
<text class="activity-time">{{ item.time }}</text>
@@ -75,7 +75,11 @@
<script setup>
import { ref, computed, onMounted } from 'vue'
import { onShow } from '@dcloudio/uni-app'
import { getUser, isLoggedIn } from '@/utils/auth.js'
import { fetchNotes } from '@/api/note.js'
import { fetchSchedules } from '@/api/schedule.js'
import { request } from '@/api/request.js'
import AppTabbar from '@/components/AppTabbar.vue'
const user = ref(null)
@@ -92,26 +96,71 @@ const avatarText = computed(() => {
return name.charAt(0).toUpperCase()
})
const stats = ref([
{ label: '今日访问', value: '2,847', trend: '12%', up: true },
{ label: '活跃用户', value: '1,256', trend: '8%', up: true },
{ label: '转化率', value: '68.5%', trend: '3%', up: false },
{ label: '总收入', value: '¥8.2k', trend: '15%', up: true }
const noteCount = ref(0)
const scheduleCount = ref(0)
const schedulePending = ref(0)
const stats = computed(() => [
{ label: '记事本', value: String(noteCount.value), trend: '条笔记', up: true },
{ label: '日程提醒', value: String(scheduleCount.value), trend: '条日程', up: true },
{ label: '待办事项', value: String(schedulePending.value), trend: '项待办', up: schedulePending.value > 0 },
{ label: '活跃天数', value: '1', trend: '今天', up: true }
])
const quickActions = ref([
{ name: '数据分析', icon: 'chart-line' },
{ name: '消息中心', icon: 'bell' },
{ name: '订单管理', icon: 'clipboard-list' },
{ name: '设置', icon: 'gear' }
{ name: '记事本', icon: 'note-sticky', route: '/pages/tools/notepad/index' },
{ name: '日程提醒', icon: 'calendar-days', route: '/pages/tools/schedule/index' },
{ name: '新建笔记', icon: 'pen-to-square', route: '/pages/tools/notepad/edit' },
{ name: '新建日程', icon: 'clock', route: '/pages/tools/schedule/edit' }
])
const activities = ref([
{ title: '新用户注册 +128', time: '5 分钟前' },
{ title: '系统更新完成 v2.1', time: '1 小时前' },
{ title: '订单 #8821 已发货', time: '2 小时前' },
{ title: '数据备份成功', time: '昨天 23:00' }
])
const activities = ref([])
function formatTime(ts) {
if (!ts) return ''
const now = Date.now()
const diff = now - ts
const minute = 60 * 1000
const hour = 60 * minute
const day = 24 * hour
if (diff < minute) return '刚刚'
if (diff < hour) return `${Math.floor(diff / minute)} 分钟前`
if (diff < day) return `${Math.floor(diff / hour)} 小时前`
if (diff < 7 * day) return `${Math.floor(diff / day)} 天前`
const d = new Date(ts)
return `${d.getMonth() + 1}/${d.getDate()}`
}
function formatTimeStr(dateStr) {
if (!dateStr) return ''
const ts = new Date(dateStr.replace(' ', 'T')).getTime()
return formatTime(ts)
}
async function loadDashboard() {
try {
const [noteRes, schedRes, actRes] = await Promise.all([
fetchNotes({ keyword: '' }).catch(() => ({ list: [], total: 0 })),
fetchSchedules({ keyword: '', status: 'all' }).catch(() => ({ list: [], total: 0 })),
request({ url: '/app/activity/list', data: { limit: 8 } }).catch(() => [])
])
noteCount.value = noteRes.total || 0
scheduleCount.value = schedRes.total || 0
schedulePending.value = (schedRes.list || []).filter(s => !s.completed).length
const actList = Array.isArray(actRes) ? actRes : (actRes?.list || actRes || [])
activities.value = actList.map(item => ({
type: item.target_type || 'other',
title: item.title || `${item.target_type} ${item.action}`,
time: formatTimeStr(item.created_at),
route: item.target_type === 'note' ? '/pages/tools/notepad/index' : '/pages/tools/schedule/index'
})).slice(0, 5)
} catch (e) {
console.error('loadDashboard error:', e)
}
}
onMounted(() => {
if (!isLoggedIn()) {
@@ -119,10 +168,25 @@ onMounted(() => {
return
}
user.value = getUser()
loadDashboard()
})
onShow(() => {
if (isLoggedIn()) loadDashboard()
})
function onQuickTap(item) {
uni.showToast({ title: item.name, icon: 'none' })
if (item.route) {
uni.navigateTo({ url: item.route })
} else {
uni.showToast({ title: item.name, icon: 'none' })
}
}
function onActivityTap(item) {
if (item.route) {
uni.navigateTo({ url: item.route })
}
}
</script>
@@ -294,6 +358,16 @@ function onQuickTap(item) {
overflow: hidden;
}
.activity-empty {
padding: 48rpx 0;
text-align: center;
}
.activity-empty-text {
font-size: 26rpx;
color: $color-text-muted;
}
.activity-item {
display: flex;
align-items: center;
@@ -309,10 +383,28 @@ function onQuickTap(item) {
}
}
.activity-icon {
width: 32rpx;
display: flex;
justify-content: center;
.activity-dot {
width: 16rpx;
height: 16rpx;
border-radius: 50%;
flex-shrink: 0;
background: #909399;
&.notebook {
background: #67c23a;
}
&.schedule {
background: $color-primary;
}
&.erp {
background: #e6a23c;
}
&.file {
background: #f56c6c;
}
}
.activity-body {
@@ -324,6 +416,9 @@ function onQuickTap(item) {
display: block;
font-size: 28rpx;
color: $color-text;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.activity-time {