c-admin-kit 1.0.0 → 1.0.2
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/LLMS.md +257 -0
- package/README.md +213 -107
- package/llms.txt +19 -0
- package/package.json +7 -2
package/LLMS.md
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
# C-Admin-Kit: AI Assistant Context & Guidelines
|
|
2
|
+
|
|
3
|
+
> This document is designed for AI Coding Assistants (Cursor, GitHub Copilot, Claude Code, Antigravity, Windsurf, etc.) to understand the architectural rules, coding standards, and golden patterns of `c-admin-kit`.
|
|
4
|
+
> 🌐 **Live Demo & Playground**: [https://admin-kit.cheatppf.xyz](https://admin-kit.cheatppf.xyz)
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 🤖 Role & Instruction for AI
|
|
9
|
+
|
|
10
|
+
When generating or refactoring Vue 3 + Element Plus admin pages using `c-admin-kit`:
|
|
11
|
+
1. **Mandatory Prefix**: All components **MUST ALWAYS** use the `c-` prefix in template (e.g., `<c-simple-table>`, `<c-search-box>`, `<c-async-button>`). Never use `<simple-table>` or `<search-box>`.
|
|
12
|
+
2. **Never Handwrite CRUD Glue Code**:
|
|
13
|
+
- Always use `useListPage` to manage search, reset, pagination, batch delete, state toggling, and routing.
|
|
14
|
+
- Always use `SearchFieldFactory` to declare search form fields. Do NOT manually construct verbose search option objects.
|
|
15
|
+
3. **Async Action Safety**: Always use `<c-async-button :on-click="fn">` or `useConfirmSubmit` for asynchronous operations to automatically handle loading states and prevent double-clicks.
|
|
16
|
+
4. **Style Import**: Ensure `import 'c-admin-kit/dist/c-admin-kit.css'` is present in `main.ts` or component.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## 📦 Import Signatures
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import {
|
|
24
|
+
// Components
|
|
25
|
+
CSimpleTable,
|
|
26
|
+
CSearchBox,
|
|
27
|
+
CAsyncButton,
|
|
28
|
+
CCollapsibleContainer,
|
|
29
|
+
CCustomDrawer,
|
|
30
|
+
CImagePreview,
|
|
31
|
+
CDiff,
|
|
32
|
+
CSelectWithAll,
|
|
33
|
+
CSelectWithPage,
|
|
34
|
+
|
|
35
|
+
// Composables / Hooks
|
|
36
|
+
useListPage,
|
|
37
|
+
useForm,
|
|
38
|
+
useDownload,
|
|
39
|
+
useConfirmAction,
|
|
40
|
+
useConfirmSubmit,
|
|
41
|
+
useDialog,
|
|
42
|
+
|
|
43
|
+
// Utilities & Factories
|
|
44
|
+
SearchFieldFactory,
|
|
45
|
+
CommonSearchFields,
|
|
46
|
+
listToTree,
|
|
47
|
+
treeToList,
|
|
48
|
+
findTreeNode,
|
|
49
|
+
findParentNodes,
|
|
50
|
+
filterTree,
|
|
51
|
+
mapTree,
|
|
52
|
+
|
|
53
|
+
// Types
|
|
54
|
+
type TableColumn,
|
|
55
|
+
type SearchField
|
|
56
|
+
} from 'c-admin-kit'
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## Standard CRUD Page Pattern
|
|
62
|
+
|
|
63
|
+
AI should use this template as the standard blueprint for any admin list view:
|
|
64
|
+
|
|
65
|
+
```vue
|
|
66
|
+
<template>
|
|
67
|
+
<div class="page-container">
|
|
68
|
+
<!-- 1. Search Box -->
|
|
69
|
+
<c-search-box
|
|
70
|
+
:fields="searchFields"
|
|
71
|
+
@search="handleSearch"
|
|
72
|
+
@reset="handleReset"
|
|
73
|
+
/>
|
|
74
|
+
|
|
75
|
+
<!-- 2. Dynamic Adaptive Table -->
|
|
76
|
+
<c-simple-table
|
|
77
|
+
ref="tableRef"
|
|
78
|
+
:api="getUserListApi"
|
|
79
|
+
:columns="columns"
|
|
80
|
+
table-key="user_management_table"
|
|
81
|
+
auto-height
|
|
82
|
+
>
|
|
83
|
+
<!-- Header Action Bar -->
|
|
84
|
+
<template #headerLeft>
|
|
85
|
+
<c-async-button type="primary" :on-click="handleAdd">
|
|
86
|
+
新增用户
|
|
87
|
+
</c-async-button>
|
|
88
|
+
<el-button
|
|
89
|
+
type="danger"
|
|
90
|
+
:disabled="selectedRows.length === 0"
|
|
91
|
+
@click="handleBatchDelete(selectedRows)"
|
|
92
|
+
>
|
|
93
|
+
批量删除
|
|
94
|
+
</el-button>
|
|
95
|
+
</template>
|
|
96
|
+
|
|
97
|
+
<!-- Custom Actions Column Slot -->
|
|
98
|
+
<template #actions="{ row }">
|
|
99
|
+
<el-button link type="primary" @click="handleEdit(row)">编辑</el-button>
|
|
100
|
+
<el-button link type="warning" @click="changeState(row)">
|
|
101
|
+
{{ row.status === 1 ? '停用' : '启用' }}
|
|
102
|
+
</el-button>
|
|
103
|
+
<el-button link type="danger" @click="handleDelete(row)">删除</el-button>
|
|
104
|
+
</template>
|
|
105
|
+
</c-simple-table>
|
|
106
|
+
</div>
|
|
107
|
+
</template>
|
|
108
|
+
|
|
109
|
+
<script setup lang="ts">
|
|
110
|
+
import { ref, computed } from 'vue'
|
|
111
|
+
import {
|
|
112
|
+
CSimpleTable,
|
|
113
|
+
CSearchBox,
|
|
114
|
+
CAsyncButton,
|
|
115
|
+
SearchFieldFactory,
|
|
116
|
+
useListPage,
|
|
117
|
+
type TableColumn
|
|
118
|
+
} from 'c-admin-kit'
|
|
119
|
+
import {
|
|
120
|
+
getUserListApi,
|
|
121
|
+
deleteUserApi,
|
|
122
|
+
batchDeleteUserApi,
|
|
123
|
+
changeUserStatusApi
|
|
124
|
+
} from '@/api/user'
|
|
125
|
+
|
|
126
|
+
const selectedRows = ref<any[]>([])
|
|
127
|
+
|
|
128
|
+
// 1. Standard CRUD Workflow Hook
|
|
129
|
+
const {
|
|
130
|
+
tableRef,
|
|
131
|
+
handleSearch,
|
|
132
|
+
handleReset,
|
|
133
|
+
handleDelete,
|
|
134
|
+
handleBatchDelete,
|
|
135
|
+
changeState,
|
|
136
|
+
handleAdd,
|
|
137
|
+
handleEdit
|
|
138
|
+
} = useListPage({
|
|
139
|
+
apiList: getUserListApi,
|
|
140
|
+
apiDelete: deleteUserApi,
|
|
141
|
+
apiBatchDelete: batchDeleteUserApi,
|
|
142
|
+
apiChangeState: changeUserStatusApi,
|
|
143
|
+
addPath: '/user/add',
|
|
144
|
+
editPath: '/user/edit'
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
// 2. Search Fields Declaration via Factory
|
|
148
|
+
const searchFields = computed(() => [
|
|
149
|
+
SearchFieldFactory.input({ prop: 'keyword', label: '关键词' }),
|
|
150
|
+
SearchFieldFactory.select({
|
|
151
|
+
prop: 'status',
|
|
152
|
+
label: '状态',
|
|
153
|
+
options: [
|
|
154
|
+
{ label: '启用', value: 1 },
|
|
155
|
+
{ label: '停用', value: 0 }
|
|
156
|
+
]
|
|
157
|
+
}),
|
|
158
|
+
SearchFieldFactory.dateRange({ prop: 'createTime', label: '创建时间' })
|
|
159
|
+
])
|
|
160
|
+
|
|
161
|
+
// 3. Columns Declaration (Supports dot-path nested properties like 'dept.name')
|
|
162
|
+
const columns: TableColumn[] = [
|
|
163
|
+
{ type: 'selection' },
|
|
164
|
+
{ type: 'index', label: '序号' },
|
|
165
|
+
{ prop: 'username', label: '用户名' },
|
|
166
|
+
{ prop: 'department.name', label: '所属部门' },
|
|
167
|
+
{ prop: 'status', label: '状态', type: 'status' },
|
|
168
|
+
{ prop: 'createTime', label: '创建时间' },
|
|
169
|
+
{ label: '操作', slot: 'actions', width: 180, fixed: 'right' }
|
|
170
|
+
]
|
|
171
|
+
</script>
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## 🧩 Component API & Contracts
|
|
177
|
+
|
|
178
|
+
### 1. `CSimpleTable` (`<c-simple-table>`)
|
|
179
|
+
- **Props**:
|
|
180
|
+
- `api`: `(params: Record<string, any>) => Promise<any>` - The API function to load page data.
|
|
181
|
+
- `columns`: `TableColumn[]` - Column definitions.
|
|
182
|
+
- `tableKey`: `string` - Unique identifier for column settings persistence.
|
|
183
|
+
- `autoHeight`: `boolean` - Automatically stretch to fill the viewport without page scrollbars (default `false`).
|
|
184
|
+
- `emptyCellText`: `string` - Placeholder for empty cell values (default `"-"`).
|
|
185
|
+
- `dragSort`: `boolean` - Enable drag-and-drop row sorting.
|
|
186
|
+
- `showPagination`: `boolean` - (default `true`).
|
|
187
|
+
- `params`: `Record<string, any>` - Static query parameters merged into fetch requests.
|
|
188
|
+
- **Column Properties (`TableColumn`)**:
|
|
189
|
+
- `prop`: string (supports dot path like `"user.profile.name"`).
|
|
190
|
+
- `label`: string.
|
|
191
|
+
- `type`: `'selection' | 'index' | 'status' | 'drag'`.
|
|
192
|
+
- `slot`: string (custom cell slot name).
|
|
193
|
+
- `formatter`: `(row, col, value, index) => string`.
|
|
194
|
+
- `render`: `(row, col, index) => VNode`.
|
|
195
|
+
- **Slots**:
|
|
196
|
+
- `#headerLeft`: Content on top-left (e.g. Add, Batch Delete).
|
|
197
|
+
- `#headerRight`: Content on top-right (e.g. Export, Custom Buttons).
|
|
198
|
+
- `#[column.slot]`: Custom column body cell slot with `{ row, column, $index }`.
|
|
199
|
+
|
|
200
|
+
### 2. `CSearchBox` (`<c-search-box>`)
|
|
201
|
+
- **Props**:
|
|
202
|
+
- `fields`: `SearchField[]` generated by `SearchFieldFactory`.
|
|
203
|
+
- `fieldsPerRow`: `number` (default `4`).
|
|
204
|
+
- `defaultExpanded`: `boolean` (default `false`).
|
|
205
|
+
- **Events**:
|
|
206
|
+
- `@search`: `(params: Record<string, any>) => void`
|
|
207
|
+
- `@reset`: `(params: Record<string, any>) => void`
|
|
208
|
+
- `@field-change`: `({ prop, value, form }) => void`
|
|
209
|
+
|
|
210
|
+
### 3. `CAsyncButton` (`<c-async-button>`)
|
|
211
|
+
- **Props**:
|
|
212
|
+
- `:on-click`: `(e: MouseEvent) => Promise<any> | any` - When it returns a Promise or Thenable, the button automatically activates `loading` and disables itself until completion.
|
|
213
|
+
|
|
214
|
+
### 4. `CCollapsibleContainer` (`<c-collapsible-container>`)
|
|
215
|
+
- **Slots**: `#left`, `#right`.
|
|
216
|
+
- **Props**: `defaultWidth: number` (default 240), `minWidth: number`, `maxWidth: number`.
|
|
217
|
+
|
|
218
|
+
### 5. `CCustomDrawer` (`<c-custom-drawer>`)
|
|
219
|
+
- **Props**: `v-model: boolean`, `title: string`, `size: string`, `confirmLoading: boolean`, `showFooter: boolean`.
|
|
220
|
+
- **Events**: `@confirm`, `@cancel`, `@close`.
|
|
221
|
+
|
|
222
|
+
---
|
|
223
|
+
|
|
224
|
+
## 🛠️ Composables Cheat Sheet
|
|
225
|
+
|
|
226
|
+
### `useListPage(options)`
|
|
227
|
+
- Automatically coordinates `CSearchBox` and `CSimpleTable`.
|
|
228
|
+
- Call `tableRef.value.refresh()` or `handleSearch()` to trigger reloads.
|
|
229
|
+
- Call `handleDelete(row)` to trigger a standard danger confirmation modal before calling `apiDelete`.
|
|
230
|
+
- Call `handleBatchDelete(rows)` with `apiBatchDelete` or `apiDelete.batch`.
|
|
231
|
+
|
|
232
|
+
### `useForm(options)`
|
|
233
|
+
- `submit(apiCall, successMsg, customTransform)`:
|
|
234
|
+
1. Validates form with `formRef.value.validate()`.
|
|
235
|
+
2. Blocks if validation fails.
|
|
236
|
+
3. Turns `loading.value = true`.
|
|
237
|
+
4. Calls `apiCall(formData)` and notifies success with `ElMessage.success`.
|
|
238
|
+
- `reset()`: Resets fields and validation states safely.
|
|
239
|
+
|
|
240
|
+
### `useDownload(apiFn, options)`
|
|
241
|
+
- `const { download, downloading } = useDownload(exportApi, { filename: 'Report' })`
|
|
242
|
+
- Automatically reads `content-disposition` from headers to name the download file.
|
|
243
|
+
- Exposes `downloading: Ref<boolean>` for button loading status.
|
|
244
|
+
|
|
245
|
+
### `treeManager`
|
|
246
|
+
- `listToTree(flatArray, { id: 'id', pid: 'parentId', children: 'children' })`: O(n) Hash Map converter.
|
|
247
|
+
- `treeToList(tree)`: Flattens hierarchical tree back to array.
|
|
248
|
+
- `findParentNodes(tree, targetId)`: Returns array of ancestor nodes from root down to matched item.
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
## 🚫 Anti-Patterns (What AI Should NEVER Do)
|
|
253
|
+
|
|
254
|
+
- ❌ **DO NOT** use native `<el-table>` for standard CRUD pages when `c-simple-table` is available.
|
|
255
|
+
- ❌ **DO NOT** handwrite repetitive `pageSize`, `pageNum`, `currentPage` reactive variables; let `useListPage` and `c-simple-table` manage them.
|
|
256
|
+
- ❌ **DO NOT** bind plain `@click` with manual `loading = true / false` on buttons when `<c-async-button :on-click="...">` can handle it declaratively.
|
|
257
|
+
- ❌ **DO NOT** use un-prefixed tags like `<simple-table>`. Always prefix with `<c-simple-table>`.
|
package/README.md
CHANGED
|
@@ -1,110 +1,116 @@
|
|
|
1
|
-
# C-Admin-Kit
|
|
1
|
+
# C-Admin-Kit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="https://img.shields.io/npm/v/c-admin-kit?color=409EFF&label=npm" alt="npm version" />
|
|
5
|
+
<img src="https://img.shields.io/npm/dm/c-admin-kit?color=67C23A&label=downloads" alt="downloads" />
|
|
6
|
+
<img src="https://img.shields.io/badge/Vue-3.3+-42b883?logo=vue.js" alt="vue" />
|
|
7
|
+
<img src="https://img.shields.io/badge/Element--Plus-2.3+-409EFF?logo=element" alt="element-plus" />
|
|
8
|
+
<img src="https://img.shields.io/badge/TypeScript-100%25-3178c6?logo=typescript" alt="typescript" />
|
|
9
|
+
<img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="license" />
|
|
10
|
+
</p>
|
|
4
11
|
|
|
5
|
-
|
|
12
|
+
`c-admin-kit` 是一套专为企业级中后台打造的高阶通用组件与 Hooks 套件。基于 **Vue 3 + Element Plus + TypeScript** 构建,提供成熟的标准 CRUD 流程封装、配置化高级表格、多条件搜索工厂、异步防重按钮、平滑拖拽分栏及常用树形数据工具函数。
|
|
13
|
+
|
|
14
|
+
> 🌐 **在线预览与交互演练场**:[https://admin-kit.cheatppf.xyz](https://admin-kit.cheatppf.xyz)
|
|
15
|
+
> 📌 **团队规范约束**:为彻底避免多工程复用时的组件同名冲突,所有组件**统一且固定强制使用 `c-` / `C` 前缀**(如 `<c-simple-table>`、`<c-search-box>`),开箱即用,代码风格统一。
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## ✨ 核心特性
|
|
20
|
+
|
|
21
|
+
- 🛡️ **100% TypeScript**:源码全量 TS 编写,严格类型定义,类型提示精确到组件 Props、Emits、Slots 及 Hook 泛型。
|
|
22
|
+
- ⚡ **轻量纯净**:以 `peerDependencies` 消费宿主环境的 `vue`、`element-plus`,打包体积仅几十 KB,无多余冗余包,完美继承宿主主题变量。
|
|
23
|
+
- 🎯 **开箱即用**:自带企业级增删改查最佳实践,配合 `useListPage` 与 `SearchFieldFactory`,10 余行代码即可完成完整页面。
|
|
24
|
+
- 🌲 **Tree-Shaking**:支持全量安装与细粒度子路径按需导入,生产构建零多余冗余代码。
|
|
6
25
|
|
|
7
26
|
---
|
|
8
27
|
|
|
9
|
-
##
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
└── README.md
|
|
28
|
+
## 📥 安装
|
|
29
|
+
|
|
30
|
+
在您的 Vue 3 + Element Plus 工程中执行:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
# 推荐使用 pnpm
|
|
34
|
+
pnpm add c-admin-kit
|
|
35
|
+
|
|
36
|
+
# 或者 npm / yarn
|
|
37
|
+
npm install c-admin-kit
|
|
38
|
+
yarn add c-admin-kit
|
|
21
39
|
```
|
|
22
40
|
|
|
41
|
+
> ⚠️ **前置依赖**:请确保项目已安装 `vue (>= 3.3.0)` 与 `element-plus (>= 2.3.0)`。
|
|
42
|
+
|
|
23
43
|
---
|
|
24
44
|
|
|
25
45
|
## 🚀 快速上手
|
|
26
46
|
|
|
27
|
-
### 1. 全局完整引入 (main.js)
|
|
47
|
+
### 1. 全局完整引入 (`main.ts` / `main.js`)
|
|
28
48
|
|
|
29
|
-
```
|
|
49
|
+
```typescript
|
|
30
50
|
import { createApp } from 'vue'
|
|
31
51
|
import ElementPlus from 'element-plus'
|
|
32
52
|
import 'element-plus/dist/index.css'
|
|
33
|
-
import App from './App.vue'
|
|
34
53
|
|
|
35
|
-
// 引入 c-admin-kit
|
|
36
54
|
import CAdminKit from 'c-admin-kit'
|
|
37
|
-
|
|
38
|
-
|
|
55
|
+
import 'c-admin-kit/dist/c-admin-kit.css'
|
|
56
|
+
|
|
57
|
+
import App from './App.vue'
|
|
39
58
|
|
|
40
59
|
const app = createApp(App)
|
|
41
60
|
app.use(ElementPlus)
|
|
42
|
-
app.use(CAdminKit) //
|
|
61
|
+
app.use(CAdminKit) // 自动全局注册所有 c- 开头组件
|
|
43
62
|
app.mount('#app')
|
|
44
63
|
```
|
|
45
64
|
|
|
46
|
-
### 2.
|
|
65
|
+
### 2. 按需局部引入 (推荐)
|
|
66
|
+
|
|
67
|
+
组件与 Hooks 均支持解构引入或子路径导入:
|
|
47
68
|
|
|
48
69
|
```vue
|
|
49
70
|
<template>
|
|
50
|
-
<c-search-box :fields="searchFields" @search="handleSearch" />
|
|
51
|
-
<c-simple-table ref="tableRef" :api="
|
|
71
|
+
<c-search-box :fields="searchFields" @search="handleSearch" @reset="handleReset" />
|
|
72
|
+
<c-simple-table ref="tableRef" :api="getUserListApi" :columns="columns" auto-height />
|
|
52
73
|
</template>
|
|
53
74
|
|
|
54
|
-
<script setup>
|
|
55
|
-
import { CSearchBox, CSimpleTable } from 'c-admin-kit'
|
|
56
|
-
import
|
|
57
|
-
import { useListPage } from 'c-admin-kit'
|
|
75
|
+
<script setup lang="ts">
|
|
76
|
+
import { CSearchBox, CSimpleTable, SearchFieldFactory, useListPage } from 'c-admin-kit'
|
|
77
|
+
import 'c-admin-kit/dist/c-admin-kit.css'
|
|
58
78
|
|
|
59
|
-
//
|
|
79
|
+
// 亦支持按子路径引用:
|
|
60
80
|
// import { CSimpleTable } from 'c-admin-kit/components'
|
|
61
|
-
// import { useListPage } from 'c-admin-kit/
|
|
81
|
+
// import { useListPage } from 'c-admin-kit/composables'
|
|
62
82
|
// import { SearchFieldFactory } from 'c-admin-kit/utils'
|
|
63
83
|
</script>
|
|
64
84
|
```
|
|
65
85
|
|
|
66
86
|
---
|
|
67
87
|
|
|
68
|
-
##
|
|
88
|
+
## 典型用法:标准 CRUD 页面
|
|
69
89
|
|
|
70
|
-
|
|
71
|
-
| :--- | :--- | :--- |
|
|
72
|
-
| **`CSimpleTable`** | `<c-simple-table>` | 800+ 行高级配置化表格:支持拖拽排序、列自定义显隐(本地缓存/API持久化)、动态自适应全屏高度、分页联动。 |
|
|
73
|
-
| **`CSearchBox`** | `<c-search-box>` | 高阶配置化多条件表单搜索栏:支持响应式栅格、展开/收起两行、级联依赖、回车搜索。 |
|
|
74
|
-
| **`CAsyncButton`** | `<c-async-button>` | 异步按钮:自动识别 Promise 并开启 loading,防止重复点击。 |
|
|
75
|
-
| **`CSelectWithAll`** | `<c-select-with-all>` | 支持全选/半选/反选与防抖远程搜索的增强下拉框。 |
|
|
76
|
-
| **`CSelectWithPage`**| `<c-select-with-page>`| 支持分页数据源、参数化键值对(`labelKey`/`valueKey`)与远程搜索的下拉框。 |
|
|
77
|
-
| **`CCollapsibleContainer`** | `<c-collapsible-container>` | 左右双栏布局容器:支持鼠标按住分隔线拖拽缩放宽度、一键收起折叠。 |
|
|
78
|
-
| **`CCustomDrawer`** | `<c-custom-drawer>` | 二次封装 el-drawer,标准化底部取消/确定按钮与事件流。 |
|
|
79
|
-
| **`CDiff`** | `<c-diff>` | 纯前端字符级与行级文本/代码 Diff 对比可视化组件。 |
|
|
80
|
-
| **`CImagePreview`** | `<c-image-preview>` | 缩略图展示与大图预览包装组件。 |
|
|
81
|
-
|
|
82
|
-
---
|
|
83
|
-
|
|
84
|
-
## 🌟 黄金组合:10行代码搞定企业级增删改查页
|
|
85
|
-
|
|
86
|
-
结合 `SearchFieldFactory`、`useListPage` 与 `CSearchBox`、`CSimpleTable`:
|
|
90
|
+
结合 `SearchFieldFactory`、`useListPage`、`CSearchBox` 与 `CSimpleTable` 快速构建后台列表页:
|
|
87
91
|
|
|
88
92
|
```vue
|
|
89
93
|
<template>
|
|
90
94
|
<div class="page-container">
|
|
91
|
-
<!-- 1.
|
|
95
|
+
<!-- 1. 结构化搜索栏 -->
|
|
92
96
|
<c-search-box
|
|
93
97
|
:fields="searchFields"
|
|
94
98
|
@search="handleSearch"
|
|
95
99
|
@reset="handleReset"
|
|
96
100
|
/>
|
|
97
101
|
|
|
98
|
-
<!-- 2.
|
|
102
|
+
<!-- 2. 高阶自适应表格 -->
|
|
99
103
|
<c-simple-table
|
|
100
104
|
ref="tableRef"
|
|
101
105
|
:api="getUserListApi"
|
|
102
106
|
:columns="columns"
|
|
103
|
-
table-key="
|
|
107
|
+
table-key="user_management_table"
|
|
104
108
|
auto-height
|
|
105
109
|
>
|
|
110
|
+
<!-- 头部操作区 -->
|
|
106
111
|
<template #headerLeft>
|
|
107
112
|
<el-button type="primary" @click="handleAdd">新增用户</el-button>
|
|
113
|
+
<el-button type="danger" @click="handleBatchDelete">批量删除</el-button>
|
|
108
114
|
</template>
|
|
109
115
|
|
|
110
116
|
<!-- 操作列插槽 -->
|
|
@@ -116,117 +122,217 @@ import { useListPage } from 'c-admin-kit'
|
|
|
116
122
|
</div>
|
|
117
123
|
</template>
|
|
118
124
|
|
|
119
|
-
<script setup>
|
|
125
|
+
<script setup lang="ts">
|
|
120
126
|
import { computed } from 'vue'
|
|
121
|
-
import {
|
|
122
|
-
CSearchBox,
|
|
123
|
-
CSimpleTable,
|
|
124
|
-
SearchFieldFactory,
|
|
125
|
-
useListPage
|
|
127
|
+
import {
|
|
128
|
+
CSearchBox,
|
|
129
|
+
CSimpleTable,
|
|
130
|
+
SearchFieldFactory,
|
|
131
|
+
useListPage,
|
|
132
|
+
type TableColumn
|
|
126
133
|
} from 'c-admin-kit'
|
|
127
|
-
import {
|
|
128
|
-
|
|
129
|
-
|
|
134
|
+
import {
|
|
135
|
+
getUserListApi,
|
|
136
|
+
deleteUserApi,
|
|
137
|
+
batchDeleteUserApi,
|
|
138
|
+
changeUserStatusApi
|
|
139
|
+
} from '@/api/user'
|
|
140
|
+
|
|
141
|
+
// 1. 标准流程控制 Hook (集成搜索联动、分页维护、单条/批量删除、状态切换、详情/新增路由)
|
|
130
142
|
const {
|
|
131
143
|
tableRef,
|
|
132
144
|
handleSearch,
|
|
133
145
|
handleReset,
|
|
134
146
|
handleDelete,
|
|
147
|
+
handleBatchDelete,
|
|
135
148
|
handleAdd,
|
|
136
149
|
handleEdit
|
|
137
150
|
} = useListPage({
|
|
138
151
|
apiList: getUserListApi,
|
|
139
152
|
apiDelete: deleteUserApi,
|
|
153
|
+
apiBatchDelete: batchDeleteUserApi,
|
|
140
154
|
apiChangeState: changeUserStatusApi,
|
|
141
155
|
addPath: '/user/add',
|
|
142
156
|
editPath: '/user/edit'
|
|
143
157
|
})
|
|
144
158
|
|
|
145
|
-
//
|
|
159
|
+
// 2. 搜索字段快速配置工厂 (支持 input、select、dateRange、cascader、级联联动等)
|
|
146
160
|
const searchFields = computed(() => [
|
|
147
|
-
SearchFieldFactory.input({ prop: '
|
|
161
|
+
SearchFieldFactory.input({ prop: 'keyword', label: '关键词' }),
|
|
148
162
|
SearchFieldFactory.select({
|
|
149
163
|
prop: 'status',
|
|
150
164
|
label: '状态',
|
|
151
165
|
options: [
|
|
152
|
-
{ label: '
|
|
166
|
+
{ label: '启用', value: 1 },
|
|
153
167
|
{ label: '停用', value: 0 }
|
|
154
168
|
]
|
|
155
169
|
}),
|
|
156
170
|
SearchFieldFactory.dateRange({ prop: 'createTime', label: '创建时间' })
|
|
157
171
|
])
|
|
158
172
|
|
|
159
|
-
//
|
|
160
|
-
const columns = [
|
|
173
|
+
// 3. 表格列配置 (原生支持 user.name 深度路径取值、空值 '-' 占位、拖拽排序、自定义列持久化)
|
|
174
|
+
const columns: TableColumn[] = [
|
|
161
175
|
{ type: 'selection' },
|
|
162
176
|
{ type: 'index', label: '序号' },
|
|
163
177
|
{ prop: 'username', label: '用户名' },
|
|
178
|
+
{ prop: 'department.name', label: '所属部门' }, // 支持嵌套深度字段
|
|
164
179
|
{ prop: 'status', label: '状态', type: 'status' },
|
|
165
180
|
{ prop: 'createTime', label: '创建时间' },
|
|
166
|
-
{ label: '操作', slot: 'actions', width:
|
|
181
|
+
{ label: '操作', slot: 'actions', width: 150, fixed: 'right' }
|
|
167
182
|
]
|
|
168
183
|
</script>
|
|
169
184
|
```
|
|
170
185
|
|
|
171
186
|
---
|
|
172
187
|
|
|
173
|
-
##
|
|
188
|
+
## 🧩 组件清单 (Components)
|
|
189
|
+
|
|
190
|
+
| 组件名 | 标签名称 | 功能特性 |
|
|
191
|
+
| :--- | :--- | :--- |
|
|
192
|
+
| **`CSimpleTable`** | `<c-simple-table>` | **高阶企业级表格**:集成拖拽排序、列自定义显隐(本地缓存/API持久化)、动态视口全屏自适应高度、嵌套属性链式取值(`dept.name`)、空单元格占位、分页联动。 |
|
|
193
|
+
| **`CSearchBox`** | `<c-search-box>` | **配置化多条件搜索栏**:响应式栅格自适应、一键展开/收起、级联下拉异步联动、回车快捷搜索、自定义插槽扩展。 |
|
|
194
|
+
| **`CAsyncButton`** | `<c-async-button>` | **异步防重按钮**:自动感知 Promise / Thenable 异步任务并开启 loading,阻断连续点击,结束自动恢复。 |
|
|
195
|
+
| **`CCollapsibleContainer`** | `<c-collapsible-container>` | **左右双栏拖拽折叠布局**:支持鼠标拖拽分隔线缩放面板宽度(消除了微动效冲突,拖拽丝滑),支持一键折叠收起。 |
|
|
196
|
+
| **`CCustomDrawer`** | `<c-custom-drawer>` | **标准化企业级抽屉**:统一底部确定/取消操作栏,内置确定按钮 `confirmLoading` 状态与 `computed` 双向绑定。 |
|
|
197
|
+
| **`CImagePreview`** | `<c-image-preview>` | **缩略图与大图预览**:支持单图 URL、逗号分隔多图字符串及数组入参,内置安全容错清洗与缩略图悬浮动效。 |
|
|
198
|
+
| **`CDiff`** | `<c-diff>` | **文本代码 Diff 视图**:纯前端实现基于编辑距离与相似度的字符级与行级差异可视化高亮。 |
|
|
199
|
+
| **`CSelectWithAll`** | `<c-select-with-all>` | **全选下拉选择器**:支持一键全选/全不选、半选状态判断及防抖远程搜索。 |
|
|
200
|
+
| **`CSelectWithPage`**| `<c-select-with-page>`| **大数据分页下拉**:支持自定义键值字段、关键词远程搜索与海量选项分页加载。 |
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## 🛠️ 组合式函数 (Composables / Hooks)
|
|
174
205
|
|
|
175
|
-
### 1. `
|
|
176
|
-
|
|
177
|
-
```
|
|
178
|
-
const {
|
|
179
|
-
|
|
206
|
+
### 1. `useListPage` (标准列表页流程控制)
|
|
207
|
+
管理列表搜索、刷新、分页、状态切换、单条/批量删除及路由跳转:
|
|
208
|
+
```typescript
|
|
209
|
+
const {
|
|
210
|
+
tableRef,
|
|
211
|
+
searchParams,
|
|
212
|
+
handleSearch,
|
|
213
|
+
handleReset,
|
|
214
|
+
handleDelete,
|
|
215
|
+
handleBatchDelete,
|
|
216
|
+
changeState,
|
|
217
|
+
exportExcel
|
|
218
|
+
} = useListPage({
|
|
219
|
+
apiList: getListApi,
|
|
220
|
+
apiDelete: deleteApi,
|
|
221
|
+
apiBatchDelete: batchDeleteApi, // 可选独立批量删除接口
|
|
222
|
+
apiChangeState: updateStatusApi,
|
|
223
|
+
apiExport: exportApi
|
|
180
224
|
})
|
|
225
|
+
```
|
|
181
226
|
|
|
182
|
-
|
|
227
|
+
### 2. `useForm` (表单状态与提交流程)
|
|
228
|
+
封装表单数据响应式模型、自动校验拦截与提交状态:
|
|
229
|
+
```typescript
|
|
230
|
+
const { formRef, formData, loading, submit, reset, setFormData } = useForm({
|
|
231
|
+
initFormData: { name: '', roleId: null }
|
|
232
|
+
})
|
|
233
|
+
|
|
234
|
+
// 提交时自动触发 form.validate(),校验失败自动提示并阻断,成功触发 loading 并调用 API
|
|
183
235
|
await submit(async (data) => await saveApi(data), '保存成功')
|
|
184
236
|
```
|
|
185
237
|
|
|
186
|
-
###
|
|
187
|
-
|
|
188
|
-
```
|
|
189
|
-
const
|
|
238
|
+
### 3. `useDownload` (安全文件导出与下载)
|
|
239
|
+
安全导出二进制文件,导出 `downloading` 响应式状态,自动从响应头提取文件名:
|
|
240
|
+
```typescript
|
|
241
|
+
const { download, downloading } = useDownload(exportApi, {
|
|
242
|
+
filename: '用户报表'
|
|
243
|
+
})
|
|
244
|
+
|
|
245
|
+
// 外部按钮可直接绑定 loading
|
|
246
|
+
// <el-button :loading="downloading" @click="download({ deptId: 1 })">导出</el-button>
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### 4. `useConfirmAction` & `useConfirmSubmit` (操作二次确认)
|
|
250
|
+
消除重复的 `ElMessageBox.confirm` 模板代码:
|
|
251
|
+
```typescript
|
|
252
|
+
const handleRemove = useConfirmSubmit(
|
|
190
253
|
async (id) => await deleteApi(id),
|
|
191
254
|
() => tableRef.value.refresh(),
|
|
192
|
-
{ message: '
|
|
255
|
+
{ message: '确定要永久删除该记录吗?' }
|
|
193
256
|
)
|
|
194
257
|
```
|
|
195
258
|
|
|
196
|
-
###
|
|
197
|
-
|
|
198
|
-
```
|
|
199
|
-
const {
|
|
200
|
-
await download({ keyword: 'test' })
|
|
259
|
+
### 5. `useDialog` (弹窗显隐与上下文传递)
|
|
260
|
+
优雅管理模态弹窗的开启、关闭与行数据传递:
|
|
261
|
+
```typescript
|
|
262
|
+
const { visible, dialogData, openDialog, closeDialog } = useDialog()
|
|
201
263
|
```
|
|
202
264
|
|
|
203
265
|
---
|
|
204
266
|
|
|
205
|
-
##
|
|
267
|
+
## 🧰 实用工具库 (Utils)
|
|
268
|
+
|
|
269
|
+
### 1. `SearchFieldFactory` (搜索字段工厂)
|
|
270
|
+
规范化、声明式生成搜索栏配置:
|
|
271
|
+
```typescript
|
|
272
|
+
import { SearchFieldFactory, CommonSearchFields } from 'c-admin-kit'
|
|
273
|
+
|
|
274
|
+
const fields = [
|
|
275
|
+
SearchFieldFactory.input({ prop: 'title', label: '标题' }),
|
|
276
|
+
SearchFieldFactory.select({ prop: 'status', label: '状态', options: [...] }),
|
|
277
|
+
SearchFieldFactory.dateRange({ prop: 'createTime', label: '创建时间' }),
|
|
278
|
+
SearchFieldFactory.cascader({ prop: 'deptId', label: '部门', options: [...] }),
|
|
279
|
+
// 常用预设快捷字段
|
|
280
|
+
CommonSearchFields.keyword(),
|
|
281
|
+
CommonSearchFields.status([...])
|
|
282
|
+
]
|
|
283
|
+
```
|
|
206
284
|
|
|
207
|
-
|
|
285
|
+
### 2. `treeManager` (高性能树结构处理)
|
|
286
|
+
```typescript
|
|
287
|
+
import {
|
|
288
|
+
listToTree,
|
|
289
|
+
treeToList,
|
|
290
|
+
findTreeNode,
|
|
291
|
+
findParentNodes,
|
|
292
|
+
filterTree,
|
|
293
|
+
mapTree
|
|
294
|
+
} from 'c-admin-kit'
|
|
208
295
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
# 3. 关联远程仓库并推送
|
|
219
|
-
git remote add origin https://your-git-server.com/frontend/c-admin-kit.git
|
|
220
|
-
git branch -M main
|
|
221
|
-
git push -u origin main
|
|
296
|
+
// 1. 扁平数组一键转树 (时间复杂度 O(n) Hash Map 算法)
|
|
297
|
+
const tree = listToTree(flatList, { id: 'id', pid: 'parentId', children: 'children' })
|
|
298
|
+
|
|
299
|
+
// 2. 根据节点 ID 查找包含自身和所有上级父节点的完整链条
|
|
300
|
+
const parentNodes = findParentNodes(tree, targetId)
|
|
301
|
+
|
|
302
|
+
// 3. 树结构过滤(保留命中节点及其祖先链路)
|
|
303
|
+
const filteredTree = filterTree(tree, (node) => node.name.includes('技术部'))
|
|
222
304
|
```
|
|
223
305
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
306
|
+
---
|
|
307
|
+
|
|
308
|
+
## 🎮 Playground 交互演练台
|
|
309
|
+
|
|
310
|
+
> 🔗 **线上演示地址**:[https://admin-kit.cheatppf.xyz](https://admin-kit.cheatppf.xyz)
|
|
311
|
+
|
|
312
|
+
本项目包含同仓物理隔离的独立演练工程 `playground/`,**100% 消费并运行 NPM 官方已发布的真实 `c-admin-kit` 远端包与产物**,包含 6 大核心场景 Demo(CRUD 页面、左右拖拽容器、文本代码比对、抽屉组件、增强选择器、树算法测试台):
|
|
313
|
+
|
|
314
|
+
```bash
|
|
315
|
+
# 启动本地演练场(真实加载 npm 已发布的 c-admin-kit)
|
|
316
|
+
pnpm run dev:playground
|
|
317
|
+
|
|
318
|
+
# 打包纯静态 SPA 站点(输出至 playground/dist/)
|
|
319
|
+
pnpm run build:playground
|
|
320
|
+
|
|
321
|
+
# 本地快速预览打包产物
|
|
322
|
+
pnpm run preview:playground
|
|
231
323
|
```
|
|
232
|
-
|
|
324
|
+
|
|
325
|
+
### 🚀 部署至 Cloudflare Pages 步骤:
|
|
326
|
+
1. 登录 Cloudflare 控制台,进入 **Workers & Pages** -> **Create application** -> **Pages** -> **Connect to Git**;
|
|
327
|
+
2. 选择本仓库,配置构建设置:
|
|
328
|
+
- **Root directory**: `playground`
|
|
329
|
+
- **Framework preset**: `Vite`
|
|
330
|
+
- **Build command**: `pnpm run build`
|
|
331
|
+
- **Build output directory**: `dist`
|
|
332
|
+
3. 点击 **Save and Deploy**,即可自动从 NPM 官方拉取最新发布的 `c-admin-kit` 并部署为全球 CDN 静态网页。
|
|
333
|
+
|
|
334
|
+
---
|
|
335
|
+
|
|
336
|
+
## 📄 授权协议
|
|
337
|
+
|
|
338
|
+
[MIT License](file:///e:/售后项目/admin-kit/LICENSE) © 2026 [wllcyg](https://github.com/wllcyg)
|
package/llms.txt
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# c-admin-kit
|
|
2
|
+
> High-level enterprise admin UI suite & composables built on Vue 3 + Element Plus + TypeScript.
|
|
3
|
+
|
|
4
|
+
## Rules
|
|
5
|
+
- All components MUST be prefixed with `c-` in template (e.g. `<c-simple-table>`, `<c-search-box>`, `<c-async-button>`).
|
|
6
|
+
- Always prioritize `SearchFieldFactory` and `useListPage` to implement standard admin CRUD list pages.
|
|
7
|
+
- Use `<c-async-button :on-click="fn">` for declarative async actions with automatic loading states.
|
|
8
|
+
|
|
9
|
+
## Key Modules
|
|
10
|
+
- `CSimpleTable`: Advanced table with column settings, auto-height, and pagination.
|
|
11
|
+
- `CSearchBox`: Structured search form with responsive grid and cascade options.
|
|
12
|
+
- `SearchFieldFactory`: Declarative factory for search fields (`input`, `select`, `dateRange`).
|
|
13
|
+
- `useListPage`: Composable for search, pagination, delete, and route coordination.
|
|
14
|
+
- `useForm`: Composable for form submission, validation, and reset.
|
|
15
|
+
- `useDownload`: Composable for file export with `downloading` status and filename auto-detect.
|
|
16
|
+
- `treeManager`: Utilities for `listToTree` (O(n)), `treeToList`, and `findParentNodes`.
|
|
17
|
+
|
|
18
|
+
## Detailed Guidelines & Standard Patterns
|
|
19
|
+
See [LLMS.md](./LLMS.md) for full contracts, component API, and standard CRUD blueprints.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "c-admin-kit",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "基于 Vue 3 + Element Plus 的中后台企业级高阶通用组件与 Hooks 套件(强制使用 c- 前缀)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/c-admin-kit.umd.cjs",
|
|
@@ -37,7 +37,9 @@
|
|
|
37
37
|
"files": [
|
|
38
38
|
"dist",
|
|
39
39
|
"src",
|
|
40
|
-
"README.md"
|
|
40
|
+
"README.md",
|
|
41
|
+
"LLMS.md",
|
|
42
|
+
"llms.txt"
|
|
41
43
|
],
|
|
42
44
|
"keywords": [
|
|
43
45
|
"vue3",
|
|
@@ -81,6 +83,9 @@
|
|
|
81
83
|
},
|
|
82
84
|
"scripts": {
|
|
83
85
|
"build": "vue-tsc --noEmit && vite build",
|
|
86
|
+
"dev:playground": "npm --prefix playground run dev",
|
|
87
|
+
"build:playground": "npm --prefix playground run build",
|
|
88
|
+
"preview:playground": "npm --prefix playground run preview",
|
|
84
89
|
"typecheck": "vue-tsc --noEmit"
|
|
85
90
|
}
|
|
86
91
|
}
|