This commit is contained in:
zlwu committed 2026-06-07 00:40:01 +08:00
1 parent f9676f8759
commit 725774ef0c
155 files changed
+50675 -5242

No files matched your search

@@ -0,0 +1,21 @@
import { ref } from 'vue'
import { fetchUserOptions } from '@/api/admin'
export function useApplicantOptions() {
const applicantOptions = ref<{ label: string; value: string }[]>([])
async function loadApplicantOptions() {
try {
const res = await fetchUserOptions()
const data = (res as any)?.data ?? res ?? []
applicantOptions.value = (Array.isArray(data) ? data : []).map((u: any) => ({
value: String(u.value ?? u.id ?? ''),
label: String(u.label ?? u.nickName ?? u.realName ?? u.username ?? '')
}))
} catch {
applicantOptions.value = []
}
}
return { applicantOptions, loadApplicantOptions }
}
@@ -0,0 +1,61 @@
import { ref } from 'vue'
import { advanceApi, reimburseApi } from '@/api/bx'
import type { AppRouteRecord } from '@/types/router'
export const advanceApproverStats = ref({ pendingTotal: 0, monthPendingAmount: 0 })
export const reimburseApproverStats = ref({ pendingTotal: 0, monthPendingAmount: 0 })
function collectMenuCodes(items: AppRouteRecord[]): Set<string> {
const codes = new Set<string>()
function walk(list: AppRouteRecord[]) {
for (const item of list) {
const code = item.meta?.menuCode as string | undefined
if (code) codes.add(code)
if (item.children?.length) walk(item.children)
}
}
walk(items)
return codes
}
export function getMenuPendingCount(menuCode?: string | null): number {
if (menuCode === 'bx:advanceApprove:list') return advanceApproverStats.value.pendingTotal
if (menuCode === 'bx:reimburseApprove:list') return reimburseApproverStats.value.pendingTotal
return 0
}
/** 刷新侧栏「备用金审批 / 报销审批」待办数量(按用户菜单权限按需请求) */
export async function refreshApproveMenuBadges(menuList: AppRouteRecord[]) {
const codes = collectMenuCodes(menuList)
const tasks: Promise<void>[] = []
if (codes.has('bx:advanceApprove:list')) {
tasks.push(
advanceApi.pendingApprovalStats().then((res: any) => {
const d = res.data || {}
advanceApproverStats.value = {
pendingTotal: Number(d.pendingTotal ?? 0),
monthPendingAmount: Number(d.monthPendingAmount ?? 0)
}
})
)
} else {
advanceApproverStats.value = { pendingTotal: 0, monthPendingAmount: 0 }
}
if (codes.has('bx:reimburseApprove:list')) {
tasks.push(
reimburseApi.pendingApprovalStats().then((res: any) => {
const d = res.data || {}
reimburseApproverStats.value = {
pendingTotal: Number(d.pendingTotal ?? 0),
monthPendingAmount: Number(d.monthPendingAmount ?? 0)
}
})
)
} else {
reimburseApproverStats.value = { pendingTotal: 0, monthPendingAmount: 0 }
}
await Promise.allSettled(tasks)
}
@@ -0,0 +1,73 @@
import { ref, onMounted } from 'vue'
import { ElMessage } from 'element-plus'
import { expenseItemApi } from '@/api/bx'
export interface ExpenseItem {
id: string
parentId: string
itemName: string
itemCode: string
level: number
sortOrder: number
status: number | string
childCount: number
children?: ExpenseItem[]
}
/**
* 加载费用项目树形数据,供 el-tree-select 使用。
*
* 用法:
* const { expenseTree, flatList, displayName, load } = useExpenseItemTree()
*/
export function useExpenseItemTree() {
const expenseTree = ref<ExpenseItem[]>([])
const loading = ref(false)
/** 扁平列表(含所有层级),用于根据 ID 查找名称 */
const flatList = ref<ExpenseItem[]>([])
async function load() {
loading.value = true
try {
const res: any = await expenseItemApi.tree()
const tree: ExpenseItem[] = res.data ?? []
expenseTree.value = tree
flatList.value = flattenTree(tree)
} catch (e: any) {
ElMessage.error(e?.message || '加载费用项目失败')
} finally {
loading.value = false
}
}
onMounted(load)
return { expenseTree, flatList, loading, load }
}
function flattenTree(tree: ExpenseItem[]): ExpenseItem[] {
const result: ExpenseItem[] = []
for (const node of tree) {
result.push(node)
if (node.children?.length) result.push(...flattenTree(node.children))
}
return result
}
/**
* 根据费用项目 ID 查找并返回展示名称。
* - 二级项目 → "一级名称/二级名称"
* - 一级项目 → "一级名称"
*
* @param id 费用项目 ID
* @param flatList 扁平列表(由 useExpenseItemTree 提供)
*/
export function formatExpenseName(id: string | null | undefined, flatList: ExpenseItem[]): string {
if (id == null) return '-'
const item = flatList.find(i => i.id === id)
if (!item) return '-'
if (item.level === 1) return item.itemName
const parent = flatList.find(i => i.id === item.parentId)
return parent ? `${parent.itemName}/${item.itemName}` : item.itemName
}
+46
View File
@@ -0,0 +1,46 @@
import { computed, ref, type ComputedRef, type Ref } from 'vue'
type Source<T> = Ref<T[]> | ComputedRef<T[]> | (() => T[])
interface UsePagedTableOptions {
initialPage?: number
initialPageSize?: number
}
export function usePagedTable<T>(source: Source<T>, options: UsePagedTableOptions = {}) {
const currentPage = ref(options.initialPage ?? 1)
const pageSize = ref(options.initialPageSize ?? 10)
const sourceRows = computed(() => {
if (typeof source === 'function') return source()
return source.value
})
const total = computed(() => sourceRows.value.length)
const pagedRows = computed(() => {
const start = (currentPage.value - 1) * pageSize.value
const end = start + pageSize.value
return sourceRows.value.slice(start, end)
})
const rangeText = computed(() => {
const count = total.value
const start = count === 0 ? 0 : (currentPage.value - 1) * pageSize.value + 1
const end = Math.min(currentPage.value * pageSize.value, count)
return `显示 ${start}-${end} / ${count}`
})
function onSizeChange() {
currentPage.value = 1
}
return {
currentPage,
pageSize,
total,
pagedRows,
rangeText,
onSizeChange
}
}
+74
View File
@@ -0,0 +1,74 @@
import { ref, computed, watch } from 'vue'
import type { Ref } from 'vue'
interface UseServerPagedOptions {
initialPage?: number
initialPageSize?: number
}
export function useServerPaged<T>(
fetchFn: (params: { page: number; pageSize: number; [k: string]: any }) => Promise<{ rows: T[]; total: number }>,
options: UseServerPagedOptions = {},
) {
const currentPage = ref(options.initialPage ?? 1)
const pageSize = ref(options.initialPageSize ?? 10)
const total = ref(0)
const rows: Ref<T[]> = ref([]) as Ref<T[]>
const loading = ref(false)
const searchParams = ref<Record<string, any>>({})
const skipNextWatchRefresh = ref(false)
const rangeText = computed(() => {
const count = total.value
const start = count === 0 ? 0 : (currentPage.value - 1) * pageSize.value + 1
const end = Math.min(currentPage.value * pageSize.value, count)
return `显示 ${start}-${end} / ${count}`
})
async function refresh(extraParams: Record<string, any> = {}) {
if (Object.keys(extraParams).length > 0) {
searchParams.value = { ...extraParams }
}
loading.value = true
try {
const res = await fetchFn({ page: currentPage.value, pageSize: pageSize.value, ...searchParams.value })
rows.value = res.rows
total.value = res.total
} finally {
loading.value = false
}
}
async function search(extraParams: Record<string, any> = {}) {
searchParams.value = { ...extraParams }
if (currentPage.value !== 1) {
skipNextWatchRefresh.value = true
currentPage.value = 1
}
await refresh()
}
function onSizeChange() {
currentPage.value = 1
}
watch([currentPage, pageSize], async () => {
if (skipNextWatchRefresh.value) {
skipNextWatchRefresh.value = false
return
}
await refresh()
})
return {
currentPage,
pageSize,
total,
rows,
loading,
rangeText,
refresh,
search,
onSizeChange,
}
}