@aquiferre/ui-kit 0.1.1 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/ConfirmDialog.vue +2 -2
- package/components/DataTable.vue +75 -8
- package/components/FormDialog.vue +3 -3
- package/components/Pagination.vue +59 -10
- package/components/TopNavbar.vue +15 -15
- package/package.json +1 -1
- package/types.ts +3 -0
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
<Transition name="fade">
|
|
4
4
|
<div v-if="visible" class="dialog-overlay">
|
|
5
5
|
<div class="fixed inset-0 bg-bg-overlay" @click="cancel" />
|
|
6
|
-
<div class="dialog max-w-sm">
|
|
6
|
+
<div class="panel-glass dialog max-w-sm">
|
|
7
7
|
<div class="px-6 py-4">
|
|
8
8
|
<h3 class="dialog-title">{{ title }}</h3>
|
|
9
9
|
<p v-if="content" class="text-text-secondary text-sm mt-2">{{ content }}</p>
|
|
10
10
|
</div>
|
|
11
|
-
<div class="dialog-actions px-6 py-4 border-t border-border-primary bg-bg-secondary rounded-b-2xl">
|
|
11
|
+
<div class="dialog-actions px-6 py-4 border-t border-border-primary bg-bg-secondary/50 rounded-b-2xl">
|
|
12
12
|
<button class="btn-secondary" @click="cancel">
|
|
13
13
|
{{ cancelText }}
|
|
14
14
|
</button>
|
package/components/DataTable.vue
CHANGED
|
@@ -3,10 +3,15 @@
|
|
|
3
3
|
<table class="table">
|
|
4
4
|
<thead class="table-header">
|
|
5
5
|
<tr>
|
|
6
|
+
<th v-if="selectable" class="table-header-cell w-8">
|
|
7
|
+
<input type="checkbox" :checked="allSelected" @change="toggleAll" />
|
|
8
|
+
</th>
|
|
6
9
|
<th
|
|
7
10
|
v-for="col in columns"
|
|
8
11
|
:key="col.key"
|
|
9
12
|
class="table-header-cell"
|
|
13
|
+
:class="col.width"
|
|
14
|
+
:style="col.align ? `text-align:${col.align}` : undefined"
|
|
10
15
|
>
|
|
11
16
|
{{ col.title }}
|
|
12
17
|
</th>
|
|
@@ -14,12 +19,25 @@
|
|
|
14
19
|
</thead>
|
|
15
20
|
<tbody class="table-body">
|
|
16
21
|
<tr v-if="!loading && data.length === 0">
|
|
17
|
-
<td :colspan="
|
|
22
|
+
<td :colspan="colspan" class="table-empty">
|
|
18
23
|
{{ emptyText }}
|
|
19
24
|
</td>
|
|
20
25
|
</tr>
|
|
21
|
-
<tr
|
|
22
|
-
|
|
26
|
+
<tr
|
|
27
|
+
v-for="(row, index) in data"
|
|
28
|
+
:key="row[rowKey] ?? index"
|
|
29
|
+
class="table-row cursor-pointer"
|
|
30
|
+
@click="handleRowClick(row)"
|
|
31
|
+
>
|
|
32
|
+
<td v-if="selectable" class="table-cell" @click.stop>
|
|
33
|
+
<input type="checkbox" :checked="isSelected(row)" @change="toggleRow(row)" />
|
|
34
|
+
</td>
|
|
35
|
+
<td
|
|
36
|
+
v-for="col in columns"
|
|
37
|
+
:key="col.key"
|
|
38
|
+
class="table-cell"
|
|
39
|
+
:class="col.align === 'center' ? 'text-center' : col.align === 'right' ? 'text-right' : undefined"
|
|
40
|
+
>
|
|
23
41
|
<slot :name="col.key" :row="row" :value="row[col.key]">
|
|
24
42
|
{{ row[col.key] }}
|
|
25
43
|
</slot>
|
|
@@ -38,15 +56,64 @@
|
|
|
38
56
|
</template>
|
|
39
57
|
|
|
40
58
|
<script setup lang="ts">
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
title: string
|
|
44
|
-
}
|
|
59
|
+
import { computed } from 'vue'
|
|
60
|
+
import type { Column } from '../types'
|
|
45
61
|
|
|
46
|
-
defineProps<{
|
|
62
|
+
const props = withDefaults(defineProps<{
|
|
47
63
|
columns: Column[]
|
|
48
64
|
data: any[]
|
|
49
65
|
loading?: boolean
|
|
50
66
|
emptyText?: string
|
|
67
|
+
selectable?: boolean
|
|
68
|
+
selected?: string[]
|
|
69
|
+
rowKey?: string
|
|
70
|
+
}>(), {
|
|
71
|
+
loading: false,
|
|
72
|
+
emptyText: '暂无数据',
|
|
73
|
+
selectable: false,
|
|
74
|
+
selected: () => [],
|
|
75
|
+
rowKey: 'id',
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
const emit = defineEmits<{
|
|
79
|
+
'update:selected': [ids: string[]]
|
|
80
|
+
'row-click': [row: any]
|
|
51
81
|
}>()
|
|
82
|
+
|
|
83
|
+
const colspan = computed(() => props.columns.length + (props.selectable ? 1 : 0))
|
|
84
|
+
|
|
85
|
+
const selectedSet = computed(() => new Set(props.selected))
|
|
86
|
+
|
|
87
|
+
function isSelected(row: any) {
|
|
88
|
+
return selectedSet.value.has(row[props.rowKey])
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const allSelected = computed(() =>
|
|
92
|
+
props.data.length > 0 && props.data.every(row => selectedSet.value.has(row[props.rowKey]))
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
function toggleAll(e: Event) {
|
|
96
|
+
const checked = (e.target as HTMLInputElement).checked
|
|
97
|
+
if (checked) {
|
|
98
|
+
emit('update:selected', props.data.map(row => row[props.rowKey]))
|
|
99
|
+
} else {
|
|
100
|
+
emit('update:selected', [])
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function toggleRow(row: any) {
|
|
105
|
+
const id = row[props.rowKey]
|
|
106
|
+
const current = [...props.selected]
|
|
107
|
+
const idx = current.indexOf(id)
|
|
108
|
+
if (idx >= 0) {
|
|
109
|
+
current.splice(idx, 1)
|
|
110
|
+
} else {
|
|
111
|
+
current.push(id)
|
|
112
|
+
}
|
|
113
|
+
emit('update:selected', current)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function handleRowClick(row: any) {
|
|
117
|
+
emit('row-click', row)
|
|
118
|
+
}
|
|
52
119
|
</script>
|
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
<Transition name="fade">
|
|
4
4
|
<div v-if="visible" class="dialog-overlay">
|
|
5
5
|
<div class="fixed inset-0 bg-bg-overlay" @click="cancel" />
|
|
6
|
-
<div class="
|
|
6
|
+
<div class="panel-glass" :class="[width || 'max-w-lg', 'dialog']">
|
|
7
7
|
<div class="flex items-center justify-between px-6 py-4 border-b border-border-primary">
|
|
8
8
|
<h3 class="text-lg font-medium text-text-primary">{{ title }}</h3>
|
|
9
|
-
<button class="text-text-tertiary hover:text-text-primary" @click="cancel">×</button>
|
|
9
|
+
<button class="text-text-tertiary hover:text-text-primary text-2xl leading-none" @click="cancel">×</button>
|
|
10
10
|
</div>
|
|
11
11
|
<div class="px-6 py-4">
|
|
12
12
|
<slot />
|
|
13
13
|
</div>
|
|
14
|
-
<div class="dialog-actions px-6 py-4 border-t border-border-primary bg-bg-secondary rounded-b-2xl">
|
|
14
|
+
<div class="dialog-actions px-6 py-4 border-t border-border-primary bg-bg-secondary/50 rounded-b-2xl">
|
|
15
15
|
<button
|
|
16
16
|
class="btn-secondary"
|
|
17
17
|
@click="cancel"
|
|
@@ -1,27 +1,36 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div class="flex items-center justify-between px-6 py-
|
|
3
|
-
<div class="text-
|
|
4
|
-
共 {{ total }}
|
|
2
|
+
<div class="flex items-center justify-between px-6 py-2">
|
|
3
|
+
<div class="text-xs text-text-tertiary">
|
|
4
|
+
共 {{ total }} 条,第 {{ startItem }} - {{ endItem }} 条
|
|
5
5
|
</div>
|
|
6
|
-
<div class="flex items-center space-x-
|
|
6
|
+
<div class="flex items-center space-x-1">
|
|
7
7
|
<button
|
|
8
8
|
:disabled="page <= 1"
|
|
9
|
-
class="btn-
|
|
9
|
+
class="btn-glass btn-sm disabled:opacity-50"
|
|
10
10
|
@click="changePage(page - 1)"
|
|
11
11
|
>
|
|
12
|
-
上一页
|
|
12
|
+
← 上一页
|
|
13
13
|
</button>
|
|
14
|
-
<
|
|
14
|
+
<template v-for="p in visiblePages" :key="p">
|
|
15
|
+
<span v-if="p === '...'" class="btn-glass btn-sm pointer-events-none">…</span>
|
|
16
|
+
<button
|
|
17
|
+
v-else
|
|
18
|
+
:class="p === page ? 'pagination-btn-active btn-sm' : 'btn-glass btn-sm'"
|
|
19
|
+
@click="changePage(p as number)"
|
|
20
|
+
>
|
|
21
|
+
{{ p }}
|
|
22
|
+
</button>
|
|
23
|
+
</template>
|
|
15
24
|
<button
|
|
16
25
|
:disabled="page >= totalPages"
|
|
17
|
-
class="btn-
|
|
26
|
+
class="btn-glass btn-sm disabled:opacity-50"
|
|
18
27
|
@click="changePage(page + 1)"
|
|
19
28
|
>
|
|
20
|
-
下一页
|
|
29
|
+
下一页 →
|
|
21
30
|
</button>
|
|
22
31
|
<select
|
|
23
32
|
:value="pageSize"
|
|
24
|
-
class="select
|
|
33
|
+
class="select ml-2"
|
|
25
34
|
@change="changePageSize(Number(($event.target as HTMLSelectElement).value))"
|
|
26
35
|
>
|
|
27
36
|
<option :value="10">10条/页</option>
|
|
@@ -33,6 +42,7 @@
|
|
|
33
42
|
</template>
|
|
34
43
|
|
|
35
44
|
<script setup lang="ts">
|
|
45
|
+
// @ts-nocheck
|
|
36
46
|
import { computed } from 'vue'
|
|
37
47
|
|
|
38
48
|
const props = defineProps<{
|
|
@@ -49,7 +59,46 @@ const emit = defineEmits<{
|
|
|
49
59
|
|
|
50
60
|
const totalPages = computed(() => Math.max(1, Math.ceil(props.total / props.pageSize)))
|
|
51
61
|
|
|
62
|
+
const startItem = computed(() => (props.page - 1) * props.pageSize + 1)
|
|
63
|
+
const endItem = computed(() => Math.min(props.page * props.pageSize, props.total))
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 生成可见页码数组,当前页 ±2 范围内显示,其余用 '...' 省略
|
|
67
|
+
* 始终显示首页和末页
|
|
68
|
+
*/
|
|
69
|
+
const visiblePages = computed(() => {
|
|
70
|
+
const total = totalPages.value
|
|
71
|
+
const current = props.page
|
|
72
|
+
const delta = 2
|
|
73
|
+
const pages: (number | string)[] = []
|
|
74
|
+
|
|
75
|
+
if (total <= 7) {
|
|
76
|
+
for (let i = 1; i <= total; i++) pages.push(i)
|
|
77
|
+
return pages
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Always show first page
|
|
81
|
+
pages.push(1)
|
|
82
|
+
|
|
83
|
+
const rangeStart = Math.max(2, current - delta)
|
|
84
|
+
const rangeEnd = Math.min(total - 1, current + delta)
|
|
85
|
+
|
|
86
|
+
if (rangeStart > 2) pages.push('...')
|
|
87
|
+
|
|
88
|
+
for (let i = rangeStart; i <= rangeEnd; i++) {
|
|
89
|
+
pages.push(i)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (rangeEnd < total - 1) pages.push('...')
|
|
93
|
+
|
|
94
|
+
// Always show last page
|
|
95
|
+
pages.push(total)
|
|
96
|
+
|
|
97
|
+
return pages
|
|
98
|
+
})
|
|
99
|
+
|
|
52
100
|
function changePage(p: number) {
|
|
101
|
+
if (p < 1 || p > totalPages.value) return
|
|
53
102
|
emit('update:page', p)
|
|
54
103
|
emit('change', p, props.pageSize)
|
|
55
104
|
}
|
package/components/TopNavbar.vue
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<header class="navbar">
|
|
3
3
|
<div class="flex items-center gap-3">
|
|
4
4
|
<slot name="brand">
|
|
5
|
-
<div class="w-8 h-8 rounded-lg bg-
|
|
5
|
+
<div class="w-8 h-8 rounded-lg bg-accent-primary flex items-center justify-center">
|
|
6
6
|
<svg class="w-5 h-5 text-text-inverse" viewBox="0 0 24 24" fill="currentColor">
|
|
7
7
|
<path d="M12 2L2 7l10 5 10-5-10-5z"/>
|
|
8
8
|
</svg>
|
|
@@ -10,21 +10,21 @@
|
|
|
10
10
|
<span class="navbar-brand">{{ title }}</span>
|
|
11
11
|
</slot>
|
|
12
12
|
<span v-if="tenantLabel" class="text-xs text-text-tertiary">| {{ tenantLabel }}</span>
|
|
13
|
-
</div>
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
14
|
+
<nav v-if="modules.length > 0" class="flex items-center gap-1 ml-4">
|
|
15
|
+
<router-link
|
|
16
|
+
v-for="mod in modules"
|
|
17
|
+
:key="mod.key"
|
|
18
|
+
:to="mod.href"
|
|
19
|
+
class="px-3 py-1.5 text-sm rounded-t-md transition-all duration-150 border-b-2"
|
|
20
|
+
:class="activeModule === mod.key
|
|
21
|
+
? 'font-medium border-accent-primary'
|
|
22
|
+
: 'text-text-secondary hover:text-text-primary border-transparent'"
|
|
23
|
+
>
|
|
24
|
+
{{ mod.label }}
|
|
25
|
+
</router-link>
|
|
26
|
+
</nav>
|
|
27
|
+
</div>
|
|
28
28
|
|
|
29
29
|
<div class="navbar-user">
|
|
30
30
|
<!-- 主题切换 -->
|
package/package.json
CHANGED
package/types.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export interface Column {
|
|
2
2
|
key: string
|
|
3
3
|
title: string
|
|
4
|
+
width?: string
|
|
5
|
+
align?: 'left' | 'center' | 'right'
|
|
4
6
|
}
|
|
5
7
|
|
|
6
8
|
export interface MenuItem {
|
|
@@ -23,6 +25,7 @@ export interface NavModule {
|
|
|
23
25
|
href: string
|
|
24
26
|
paths: string[]
|
|
25
27
|
permissions: string[]
|
|
28
|
+
superAdminOnly?: boolean
|
|
26
29
|
}
|
|
27
30
|
|
|
28
31
|
export interface DropdownItem {
|