
功能特性: - JWT用户认证系统 - 日报CRUD管理 - 三级权限控制 - 多维度搜索过滤 - 统计分析功能 - 评论互动系统 - 响应式Cool Admin界面 - 暗色主题支持 技术栈: - 后端:Django 4.2.7 + DRF + SimpleJWT - 前端:Vue 3 + Element Plus + Pinia - 数据库:SQLite/PostgreSQL - 部署:Docker + Nginx 包含内容: - 完整的后端API代码 - 现代化前端界面 - 数据库迁移文件 - 部署脚本和文档 - 演示页面和测试工具
153 lines
3.5 KiB
JavaScript
153 lines
3.5 KiB
JavaScript
import { defineStore } from 'pinia'
|
|
|
|
export const useAppStore = defineStore('app', {
|
|
state: () => ({
|
|
// 侧边栏
|
|
sidebar: {
|
|
opened: true,
|
|
withoutAnimation: false
|
|
},
|
|
|
|
// 设备类型
|
|
device: 'desktop',
|
|
|
|
// 主题
|
|
theme: 'light',
|
|
|
|
// 加载状态
|
|
loading: false,
|
|
|
|
// 页面标题
|
|
title: '企业级日报系统',
|
|
|
|
// 标签页
|
|
visitedViews: [],
|
|
cachedViews: []
|
|
}),
|
|
|
|
getters: {
|
|
sidebarOpened: (state) => state.sidebar.opened,
|
|
isMobile: (state) => state.device === 'mobile',
|
|
isDark: (state) => state.theme === 'dark'
|
|
},
|
|
|
|
actions: {
|
|
// 切换侧边栏
|
|
toggleSidebar() {
|
|
this.sidebar.opened = !this.sidebar.opened
|
|
this.sidebar.withoutAnimation = false
|
|
},
|
|
|
|
// 关闭侧边栏
|
|
closeSidebar(withoutAnimation = false) {
|
|
this.sidebar.opened = false
|
|
this.sidebar.withoutAnimation = withoutAnimation
|
|
},
|
|
|
|
// 设置设备类型
|
|
setDevice(device) {
|
|
this.device = device
|
|
},
|
|
|
|
// 切换主题
|
|
toggleTheme() {
|
|
this.theme = this.theme === 'light' ? 'dark' : 'light'
|
|
this.updateTheme()
|
|
},
|
|
|
|
// 设置主题
|
|
setTheme(theme) {
|
|
this.theme = theme
|
|
this.updateTheme()
|
|
},
|
|
|
|
// 更新主题
|
|
updateTheme() {
|
|
const html = document.documentElement
|
|
if (this.theme === 'dark') {
|
|
html.classList.add('dark')
|
|
} else {
|
|
html.classList.remove('dark')
|
|
}
|
|
localStorage.setItem('theme', this.theme)
|
|
},
|
|
|
|
// 初始化主题
|
|
initTheme() {
|
|
const savedTheme = localStorage.getItem('theme')
|
|
if (savedTheme) {
|
|
this.setTheme(savedTheme)
|
|
} else {
|
|
// 检查系统主题偏好
|
|
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
this.setTheme(prefersDark ? 'dark' : 'light')
|
|
}
|
|
},
|
|
|
|
// 设置加载状态
|
|
setLoading(loading) {
|
|
this.loading = loading
|
|
},
|
|
|
|
// 设置页面标题
|
|
setTitle(title) {
|
|
this.title = title
|
|
document.title = title
|
|
},
|
|
|
|
// 添加访问过的视图
|
|
addVisitedView(view) {
|
|
if (this.visitedViews.some(v => v.path === view.path)) return
|
|
this.visitedViews.push({
|
|
name: view.name,
|
|
path: view.path,
|
|
title: view.meta?.title || view.name
|
|
})
|
|
},
|
|
|
|
// 删除访问过的视图
|
|
delVisitedView(view) {
|
|
const index = this.visitedViews.findIndex(v => v.path === view.path)
|
|
if (index > -1) {
|
|
this.visitedViews.splice(index, 1)
|
|
}
|
|
},
|
|
|
|
// 删除其他访问过的视图
|
|
delOthersVisitedViews(view) {
|
|
this.visitedViews = this.visitedViews.filter(v => v.path === view.path)
|
|
},
|
|
|
|
// 删除所有访问过的视图
|
|
delAllVisitedViews() {
|
|
this.visitedViews = []
|
|
},
|
|
|
|
// 添加缓存视图
|
|
addCachedView(view) {
|
|
if (this.cachedViews.includes(view.name)) return
|
|
if (!view.meta?.noCache) {
|
|
this.cachedViews.push(view.name)
|
|
}
|
|
},
|
|
|
|
// 删除缓存视图
|
|
delCachedView(view) {
|
|
const index = this.cachedViews.indexOf(view.name)
|
|
if (index > -1) {
|
|
this.cachedViews.splice(index, 1)
|
|
}
|
|
},
|
|
|
|
// 删除其他缓存视图
|
|
delOthersCachedViews(view) {
|
|
this.cachedViews = this.cachedViews.filter(name => name === view.name)
|
|
},
|
|
|
|
// 删除所有缓存视图
|
|
delAllCachedViews() {
|
|
this.cachedViews = []
|
|
}
|
|
}
|
|
})
|