refactor: 全面迁移 vue-class-component 至 Vue 3 Composition API
- 将所有页面组件从 class 语法重写为 <script setup> 风格 - App.vue / Login.vue / Home.vue / Welcome.vue - api: Hitokoto.vue / HitokotoAdd.vue / Music.vue / PhotoWall.vue / SourceImage.vue - system: Article.vue / Statistics.vue / SystemConfig.vue / SystemConfigAdd.vue / SystemRole.vue / SystemUser.vue - 新增 src/utils/http.ts:独立 axios 实例,含请求/响应拦截器,替代 vue-axios 插件 - baselist.ts:abstract class BaseList<T> → useBaseList<T>() 组合式函数 - types.ts:VForm 类型改用 Element Plus 原生 FormInstance - main.ts:移除 vue-axios 及内联 axios 配置,路由守卫直接引用 store - 依赖清理:移除 vue-class-component、vue-axios
This commit is contained in:
+33
-54
@@ -1,65 +1,44 @@
|
||||
import { Vue } from 'vue-class-component'
|
||||
import { ref, reactive } from 'vue'
|
||||
import { Page } from './common.dto'
|
||||
import moment from 'moment'
|
||||
|
||||
export default abstract class BaseList<T extends Page> extends Vue {
|
||||
/**
|
||||
* 表格数据加载中
|
||||
*/
|
||||
loading: boolean = false
|
||||
/**
|
||||
* 表单提交中
|
||||
*/
|
||||
modalLoading: boolean = false
|
||||
/**
|
||||
* 数据总数
|
||||
*/
|
||||
total: number = 0
|
||||
abstract search: T
|
||||
/**
|
||||
* 加载数据的实现
|
||||
*/
|
||||
abstract loadData(): Promise<void>
|
||||
/**
|
||||
* 加载数据
|
||||
* @param resetPage 是否重置页码
|
||||
*/
|
||||
loadDataBase(resetPage: boolean = false): void {
|
||||
if(resetPage) {
|
||||
this.search.pageNum = 1
|
||||
export function useBaseList<T extends Page>(searchInit: T) {
|
||||
const loading = ref(false)
|
||||
const modalLoading = ref(false)
|
||||
const total = ref(0)
|
||||
const search = reactive(searchInit) as T
|
||||
|
||||
let _loadData: (() => Promise<void>) | null = null
|
||||
|
||||
function setLoadData(fn: () => Promise<void>) {
|
||||
_loadData = fn
|
||||
}
|
||||
|
||||
function loadDataBase(resetPage: boolean = false): void {
|
||||
if (resetPage) {
|
||||
search.pageNum = 1
|
||||
}
|
||||
this.loadData()
|
||||
}
|
||||
/**
|
||||
* 重置搜索项
|
||||
*/
|
||||
reset(): void {
|
||||
this.search.reset()
|
||||
this.loadData()
|
||||
}
|
||||
/**
|
||||
* 页码变更
|
||||
* @param pageNum 页码
|
||||
*/
|
||||
pageChange(pageNum: number): void {
|
||||
this.search.pageNum = pageNum
|
||||
this.loadData()
|
||||
_loadData?.()
|
||||
}
|
||||
|
||||
/**
|
||||
* 每页数据条数变更
|
||||
* @param pageSize 每页数据条数
|
||||
*/
|
||||
pageSizeChange(pageSize: number): void {
|
||||
this.search.limit = pageSize
|
||||
this.loadData()
|
||||
function reset(): void {
|
||||
search.reset()
|
||||
_loadData?.()
|
||||
}
|
||||
|
||||
/**
|
||||
* 日期时间格式化
|
||||
* @param dateStr 日期时间
|
||||
*/
|
||||
datetimeFormat(dateStr: string): string | null {
|
||||
function pageChange(pageNum: number): void {
|
||||
search.pageNum = pageNum
|
||||
_loadData?.()
|
||||
}
|
||||
|
||||
function pageSizeChange(pageSize: number): void {
|
||||
search.limit = pageSize
|
||||
_loadData?.()
|
||||
}
|
||||
|
||||
function datetimeFormat(dateStr: string): string | null {
|
||||
return dateStr ? moment(dateStr).format('YYYY-MM-DD HH:mm:ss') : null
|
||||
}
|
||||
|
||||
return { loading, modalLoading, total, search, setLoadData, loadDataBase, reset, pageChange, pageSizeChange, datetimeFormat }
|
||||
}
|
||||
Reference in New Issue
Block a user