完善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 {
+123 -17
View File
@@ -15,16 +15,29 @@
<view class="field content-field">
<text class="field-label">内容</text>
<textarea
class="field-textarea"
v-model="form.content"
placeholder="记录你的想法..."
placeholder-class="placeholder"
:auto-height="false"
maxlength="5000"
:show-confirm-bar="false"
/>
<text class="char-count">{{ form.content.length }}/5000</text>
<view class="editor-wrap">
<editor
id="noteEditor"
class="note-editor"
:placeholder="'记录你的想法...'"
:value="form.content"
@ready="onEditorReady"
@input="onEditorInput"
@focus="editorFocused = true"
@blur="editorFocused = false"
/>
<view class="editor-toolbar">
<view
v-for="btn in toolbarBtns"
:key="btn.name"
class="toolbar-btn"
:class="{ active: btn.active }"
@tap="execCommand(btn)"
>
<text>{{ btn.label }}</text>
</view>
</view>
</view>
</view>
<view class="switch-row" @tap="form.pinned = !form.pinned">
@@ -57,6 +70,8 @@ import { formatDate } from '@/utils/date.js'
const noteId = ref('')
const saving = ref(false)
const editorCtx = ref(null)
const editorFocused = ref(false)
const form = reactive({
title: '',
content: '',
@@ -66,6 +81,18 @@ const meta = reactive({
updatedAt: 0
})
const toolbarBtns = reactive([
{ name: 'bold', label: 'B', active: false, value: 'bold' },
{ name: 'italic', label: 'I', active: false, value: 'italic' },
{ name: 'underline', label: 'U', active: false, value: 'underline' },
{ name: 'strike', label: 'S', active: false, value: 'strikeThrough' },
{ name: 'header', label: 'H', active: false, value: 'header' },
{ name: 'list', label: '•', active: false, value: 'insertUnorderedList' },
{ name: 'indent', label: '→', active: false, value: 'indent' },
{ name: 'outdent', label: '←', active: false, value: 'outdent' },
{ name: 'divider', label: '—', active: false, value: 'insertHorizontalRule' },
])
onLoad(async (query) => {
if (query?.id) {
noteId.value = query.id
@@ -76,6 +103,30 @@ onLoad(async (query) => {
}
})
function onEditorReady() {
uni.createSelectorQuery().select('#noteEditor').context((res) => {
if (res && res.context) {
editorCtx.value = res.context
if (form.content) {
editorCtx.value.setContents({ html: form.content })
}
}
}).exec()
}
function onEditorInput(e) {
form.content = e.detail.html || ''
}
function execCommand(btn) {
if (!editorCtx.value) return
if (btn.name === 'header') {
editorCtx.value.format('header', 'H2')
} else {
editorCtx.value.format(btn.value)
}
}
async function loadNote(id) {
try {
const note = await getNote(id)
@@ -88,6 +139,9 @@ async function loadNote(id) {
form.content = note.content
form.pinned = !!note.pinned
meta.updatedAt = note.updatedAt
if (editorCtx.value && note.content) {
editorCtx.value.setContents({ html: note.content })
}
} catch (e) {
uni.showToast({ title: '加载失败', icon: 'none' })
}
@@ -147,13 +201,19 @@ function onDelete() {
.page {
min-height: 100vh;
background: $color-bg-page;
padding: 24rpx $page-padding-x;
padding-bottom: calc(180rpx + env(safe-area-inset-bottom));
display: flex;
flex-direction: column;
padding: 24rpx $page-padding-x 0;
padding-bottom: calc(130rpx + env(safe-area-inset-bottom));
}
.form-card {
@include card;
padding: 8rpx 0;
flex: 1;
display: flex;
flex-direction: column;
overflow: hidden;
}
.field {
@@ -183,12 +243,57 @@ function onDelete() {
}
.content-field {
position: relative;
flex: 1;
display: flex;
flex-direction: column;
padding-bottom: 0;
overflow: hidden;
}
.field-textarea {
height: 480rpx;
line-height: 1.7;
.editor-wrap {
background: $color-bg-page;
border-radius: $radius-md;
overflow: hidden;
flex: 1;
display: flex;
flex-direction: column;
}
.note-editor {
width: 100%;
flex: 1;
min-height: 0;
padding: 20rpx;
font-size: 28rpx;
color: $color-text;
box-sizing: border-box;
overflow-y: auto;
}
.editor-toolbar {
display: flex;
flex-wrap: wrap;
gap: 8rpx;
padding: 16rpx 20rpx;
border-top: 1rpx solid $color-divider;
background: $color-card;
}
.toolbar-btn {
padding: 10rpx 20rpx;
border-radius: $radius-sm;
font-size: 24rpx;
color: $color-text-secondary;
background: $color-bg-page;
&.active {
color: $color-primary;
background: $color-primary-bg;
}
&:active {
opacity: 0.7;
}
}
.placeholder {
@@ -237,7 +342,7 @@ function onDelete() {
}
.meta {
margin-top: 20rpx;
margin: 20rpx 0;
padding: 0 8rpx;
font-size: 24rpx;
color: $color-text-muted;
@@ -255,6 +360,7 @@ function onDelete() {
background: $color-card;
border-top: 1rpx solid $color-border;
box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.04);
z-index: 10;
}
.btn-primary,
+1 -1
View File
@@ -111,7 +111,7 @@ function clearSearch() {
}
function preview(content) {
const text = (content || '').replace(/\s+/g, ' ').trim()
const text = (content || '').replace(/<[^>]+>/g, '').replace(/&nbsp;/g, ' ').replace(/\s+/g, ' ').trim()
if (!text) return '暂无内容'
return text.length > 60 ? `${text.slice(0, 60)}...` : text
}