@tongfun/ui 0.0.1-alpha.3 → 0.0.1-alpha.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/dist/agent-schema/index.d.ts +12 -0
- package/dist/agent-schema/index.js +33 -0
- package/dist/agent-schema/types.d.ts +27 -0
- package/dist/formula/index.d.ts +17 -0
- package/dist/formula/types.d.ts +136 -0
- package/dist/index.d.ts +55 -4
- package/dist/index.js +142216 -125508
- package/dist/lowcode-agent/index.js +9409 -3792
- package/dist/lowcode-agent/types.d.ts +312 -312
- package/dist/skill/golden-examples/dashboard-workbench.md +224 -0
- package/dist/skill/golden-examples/form-create.md +227 -0
- package/dist/skill/golden-examples/management-list.md +264 -0
- package/dist/skill/golden-examples/new-document.md +748 -0
- package/dist/skill/tongfun-ui-skill.json +470 -0
- package/dist/skill/tongfun-ui-skill.md +297 -0
- package/dist/style.css +1 -1
- package/package.json +99 -91
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
# Golden Example: Dashboard / 工作台
|
|
2
|
+
|
|
3
|
+
## 场景
|
|
4
|
+
|
|
5
|
+
用于企业后台首页、业务工作台、运营概览页。Agent 应生成高密度信息概览,而不是营销式大屏或宣传页。
|
|
6
|
+
|
|
7
|
+
## 推荐结构
|
|
8
|
+
|
|
9
|
+
1. `TfPageHeader` 放页面标题、说明、刷新和时间范围。
|
|
10
|
+
2. `TfGrid` + `TfMetric` 展示核心指标。
|
|
11
|
+
3. `TfCard` 展示待办任务、异常提醒、最近记录。
|
|
12
|
+
4. `TfTable` 展示结构化待办或异常数据。
|
|
13
|
+
5. 局部加载失败时只影响对应卡片,不阻断整个页面。
|
|
14
|
+
|
|
15
|
+
## 推荐组件
|
|
16
|
+
|
|
17
|
+
- `TfPageHeader`
|
|
18
|
+
- `TfGrid`
|
|
19
|
+
- `TfMetric`
|
|
20
|
+
- `TfCard`
|
|
21
|
+
- `TfButton`
|
|
22
|
+
- `TfTable`
|
|
23
|
+
- `TfTag`
|
|
24
|
+
- `TfProgress`
|
|
25
|
+
- `TfSkeleton`
|
|
26
|
+
- `TfEmpty`
|
|
27
|
+
- `TfAlert`
|
|
28
|
+
|
|
29
|
+
## 可替换区域
|
|
30
|
+
|
|
31
|
+
- 指标名称、数值、趋势。
|
|
32
|
+
- 待办列表字段。
|
|
33
|
+
- 异常提醒类型。
|
|
34
|
+
- 时间范围和刷新 API。
|
|
35
|
+
|
|
36
|
+
## 不建议改动区域
|
|
37
|
+
|
|
38
|
+
- 不做全屏 hero。
|
|
39
|
+
- 不使用大面积渐变背景。
|
|
40
|
+
- 不使用装饰性图形替代真实业务数据。
|
|
41
|
+
- 指标区必须可快速扫描。
|
|
42
|
+
- 每个模块必须有 loading、empty 或 error 处理。
|
|
43
|
+
|
|
44
|
+
## 状态覆盖
|
|
45
|
+
|
|
46
|
+
- loading:整体或模块加载。
|
|
47
|
+
- empty:无待办、无异常。
|
|
48
|
+
- error:局部模块加载失败。
|
|
49
|
+
- refreshing:刷新按钮 loading。
|
|
50
|
+
- partial-error:某个模块失败不影响其他模块。
|
|
51
|
+
|
|
52
|
+
## Vue SFC 示例代码
|
|
53
|
+
|
|
54
|
+
```vue
|
|
55
|
+
<template>
|
|
56
|
+
<div class="space-y-4">
|
|
57
|
+
<TfPageHeader title="业务工作台" description="查看今日任务、异常提醒和关键指标">
|
|
58
|
+
<template #actions>
|
|
59
|
+
<TfButton :loading="refreshing" @click="refreshAll">
|
|
60
|
+
<RefreshCw class="h-4 w-4" />
|
|
61
|
+
刷新
|
|
62
|
+
</TfButton>
|
|
63
|
+
</template>
|
|
64
|
+
</TfPageHeader>
|
|
65
|
+
|
|
66
|
+
<TfGrid :cols="4" :gap="16">
|
|
67
|
+
<TfMetric label="今日新增" :value="metrics.todayCreated" unit="条" />
|
|
68
|
+
<TfMetric label="待处理" :value="metrics.pending" unit="条" />
|
|
69
|
+
<TfMetric label="异常单据" :value="metrics.exceptions" unit="条" theme="warning" />
|
|
70
|
+
<TfMetric label="完成率" :value="metrics.completionRate" unit="%" theme="success" />
|
|
71
|
+
</TfGrid>
|
|
72
|
+
|
|
73
|
+
<div class="grid gap-4 lg:grid-cols-2">
|
|
74
|
+
<TfCard title="我的待办">
|
|
75
|
+
<TfAlert v-if="todoError" type="error" title="待办加载失败" :description="todoError" show-icon>
|
|
76
|
+
<template #action>
|
|
77
|
+
<TfButton size="sm" @click="loadTodos">重试</TfButton>
|
|
78
|
+
</template>
|
|
79
|
+
</TfAlert>
|
|
80
|
+
|
|
81
|
+
<TfSkeleton v-else-if="todoLoading" :rows="5" />
|
|
82
|
+
<TfEmpty v-else-if="!todos.length" description="暂无待办任务" />
|
|
83
|
+
<TfTable v-else :columns="todoColumns" :data="todos" row-key="id" />
|
|
84
|
+
</TfCard>
|
|
85
|
+
|
|
86
|
+
<TfCard title="异常提醒">
|
|
87
|
+
<TfAlert v-if="exceptionError" type="error" title="异常提醒加载失败" :description="exceptionError" show-icon>
|
|
88
|
+
<template #action>
|
|
89
|
+
<TfButton size="sm" @click="loadExceptions">重试</TfButton>
|
|
90
|
+
</template>
|
|
91
|
+
</TfAlert>
|
|
92
|
+
|
|
93
|
+
<TfSkeleton v-else-if="exceptionLoading" :rows="5" />
|
|
94
|
+
<TfEmpty v-else-if="!exceptions.length" description="暂无异常提醒" />
|
|
95
|
+
<TfTable v-else :columns="exceptionColumns" :data="exceptions" row-key="id" />
|
|
96
|
+
</TfCard>
|
|
97
|
+
</div>
|
|
98
|
+
</div>
|
|
99
|
+
</template>
|
|
100
|
+
|
|
101
|
+
<script setup lang="ts">
|
|
102
|
+
import { computed, h, onMounted, reactive, ref } from 'vue'
|
|
103
|
+
import { RefreshCw } from 'lucide-vue-next'
|
|
104
|
+
import {
|
|
105
|
+
TfAlert,
|
|
106
|
+
TfButton,
|
|
107
|
+
TfCard,
|
|
108
|
+
TfEmpty,
|
|
109
|
+
TfGrid,
|
|
110
|
+
TfMetric,
|
|
111
|
+
TfPageHeader,
|
|
112
|
+
TfSkeleton,
|
|
113
|
+
TfTable,
|
|
114
|
+
TfTag
|
|
115
|
+
} from '@tongfun/ui'
|
|
116
|
+
|
|
117
|
+
interface TodoItem {
|
|
118
|
+
id: number
|
|
119
|
+
title: string
|
|
120
|
+
type: string
|
|
121
|
+
deadline: string
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
interface ExceptionItem {
|
|
125
|
+
id: number
|
|
126
|
+
title: string
|
|
127
|
+
level: 'warning' | 'error'
|
|
128
|
+
count: number
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const refreshing = ref(false)
|
|
132
|
+
const todoLoading = ref(false)
|
|
133
|
+
const exceptionLoading = ref(false)
|
|
134
|
+
const todoError = ref('')
|
|
135
|
+
const exceptionError = ref('')
|
|
136
|
+
|
|
137
|
+
const metrics = reactive({
|
|
138
|
+
todayCreated: 0,
|
|
139
|
+
pending: 0,
|
|
140
|
+
exceptions: 0,
|
|
141
|
+
completionRate: 0
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
const todos = ref<TodoItem[]>([])
|
|
145
|
+
const exceptions = ref<ExceptionItem[]>([])
|
|
146
|
+
|
|
147
|
+
const todoColumns = computed(() => [
|
|
148
|
+
{ title: '任务', key: 'title', minWidth: 180 },
|
|
149
|
+
{ title: '类型', key: 'type', width: 120 },
|
|
150
|
+
{ title: '截止时间', key: 'deadline', width: 160 }
|
|
151
|
+
])
|
|
152
|
+
|
|
153
|
+
const exceptionColumns = computed(() => [
|
|
154
|
+
{ title: '异常', key: 'title', minWidth: 180 },
|
|
155
|
+
{
|
|
156
|
+
title: '级别',
|
|
157
|
+
key: 'level',
|
|
158
|
+
width: 100,
|
|
159
|
+
render: ({ row }: { row: ExceptionItem }) => h(TfTag, { type: row.level === 'error' ? 'danger' : 'warning' }, () => row.level === 'error' ? '严重' : '提醒')
|
|
160
|
+
},
|
|
161
|
+
{ title: '数量', key: 'count', width: 100 }
|
|
162
|
+
])
|
|
163
|
+
|
|
164
|
+
onMounted(() => {
|
|
165
|
+
refreshAll()
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
async function refreshAll() {
|
|
169
|
+
refreshing.value = true
|
|
170
|
+
try {
|
|
171
|
+
await Promise.allSettled([
|
|
172
|
+
loadMetrics(),
|
|
173
|
+
loadTodos(),
|
|
174
|
+
loadExceptions()
|
|
175
|
+
])
|
|
176
|
+
} finally {
|
|
177
|
+
refreshing.value = false
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
async function loadMetrics() {
|
|
182
|
+
// Replace with metric API.
|
|
183
|
+
metrics.todayCreated = 0
|
|
184
|
+
metrics.pending = 0
|
|
185
|
+
metrics.exceptions = 0
|
|
186
|
+
metrics.completionRate = 0
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
async function loadTodos() {
|
|
190
|
+
todoLoading.value = true
|
|
191
|
+
todoError.value = ''
|
|
192
|
+
|
|
193
|
+
try {
|
|
194
|
+
// Replace with todo API.
|
|
195
|
+
todos.value = []
|
|
196
|
+
} catch (err) {
|
|
197
|
+
todoError.value = err instanceof Error ? err.message : '请稍后重试'
|
|
198
|
+
} finally {
|
|
199
|
+
todoLoading.value = false
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
async function loadExceptions() {
|
|
204
|
+
exceptionLoading.value = true
|
|
205
|
+
exceptionError.value = ''
|
|
206
|
+
|
|
207
|
+
try {
|
|
208
|
+
// Replace with exception API.
|
|
209
|
+
exceptions.value = []
|
|
210
|
+
} catch (err) {
|
|
211
|
+
exceptionError.value = err instanceof Error ? err.message : '请稍后重试'
|
|
212
|
+
} finally {
|
|
213
|
+
exceptionLoading.value = false
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
</script>
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## 设计说明
|
|
220
|
+
|
|
221
|
+
- 工作台首屏直接呈现指标和待办,不做营销式 hero。
|
|
222
|
+
- 指标卡片用于快速扫描,待办和异常使用结构化列表。
|
|
223
|
+
- 每个模块独立处理 loading、empty、error,允许局部失败。
|
|
224
|
+
- 页面只使用少量布局 class,不硬编码品牌色或状态色。
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
# Golden Example: 创建/编辑表单页
|
|
2
|
+
|
|
3
|
+
## 场景
|
|
4
|
+
|
|
5
|
+
用于创建或编辑业务单据、客户、合同、订单等主数据。Agent 应生成可校验、可保存、可分组、可切换只读态的表单页面。
|
|
6
|
+
|
|
7
|
+
## 推荐结构
|
|
8
|
+
|
|
9
|
+
1. `TfPageHeader` 放返回、标题、保存、提交。
|
|
10
|
+
2. `TfForm` 统一管理 model、rules、disabled。
|
|
11
|
+
3. 多个 `TfCard` 承载业务分组。
|
|
12
|
+
4. `TfFormLayout` 控制字段列数和 label 宽度。
|
|
13
|
+
5. 字段使用 `TfFormInput`、`TfFormSelect`、`TfFormTextarea`、`TfFormDatePicker` 等表单字段组件。
|
|
14
|
+
|
|
15
|
+
## 推荐组件
|
|
16
|
+
|
|
17
|
+
- `TfPageHeader`
|
|
18
|
+
- `TfCard`
|
|
19
|
+
- `TfForm`
|
|
20
|
+
- `TfFormLayout`
|
|
21
|
+
- `TfFormInput`
|
|
22
|
+
- `TfFormSelect`
|
|
23
|
+
- `TfFormTextarea`
|
|
24
|
+
- `TfFormDatePicker`
|
|
25
|
+
- `TfButton`
|
|
26
|
+
- `TfAlert`
|
|
27
|
+
- `TfSkeleton`
|
|
28
|
+
|
|
29
|
+
## 可替换区域
|
|
30
|
+
|
|
31
|
+
- 表单模型字段。
|
|
32
|
+
- 表单校验规则。
|
|
33
|
+
- 分组卡片标题和字段排列。
|
|
34
|
+
- 保存、提交、详情接口。
|
|
35
|
+
|
|
36
|
+
## 不建议改动区域
|
|
37
|
+
|
|
38
|
+
- 保存/提交前先校验。
|
|
39
|
+
- 保存中禁用表单和按钮。
|
|
40
|
+
- 必填字段必须有规则和错误反馈。
|
|
41
|
+
- 超过 8 个字段时必须分组。
|
|
42
|
+
|
|
43
|
+
## 状态覆盖
|
|
44
|
+
|
|
45
|
+
- loading:编辑模式加载详情。
|
|
46
|
+
- saving:保存中。
|
|
47
|
+
- submitting:提交中。
|
|
48
|
+
- validation-error:校验失败时阻止提交。
|
|
49
|
+
- disabled:查看模式或流程锁定。
|
|
50
|
+
- save-success:保存成功反馈。
|
|
51
|
+
- save-error:保存失败保留输入并展示错误。
|
|
52
|
+
|
|
53
|
+
## Vue SFC 示例代码
|
|
54
|
+
|
|
55
|
+
```vue
|
|
56
|
+
<template>
|
|
57
|
+
<div class="space-y-4">
|
|
58
|
+
<TfPageHeader :title="pageTitle" description="维护业务基础信息与审批信息">
|
|
59
|
+
<template #actions>
|
|
60
|
+
<TfButton :disabled="busy" @click="handleBack">返回</TfButton>
|
|
61
|
+
<TfButton :loading="saving" :disabled="isViewMode" @click="handleSave">保存</TfButton>
|
|
62
|
+
<TfButton type="primary" :loading="submitting" :disabled="isViewMode" @click="handleSubmit">提交</TfButton>
|
|
63
|
+
</template>
|
|
64
|
+
</TfPageHeader>
|
|
65
|
+
|
|
66
|
+
<TfAlert v-if="error" type="error" title="操作失败" :description="error" show-icon />
|
|
67
|
+
|
|
68
|
+
<TfSkeleton v-if="loading" :rows="8" />
|
|
69
|
+
|
|
70
|
+
<TfForm v-else ref="formRef" :model="form" :rules="rules" :disabled="isViewMode || busy">
|
|
71
|
+
<TfCard title="基础信息">
|
|
72
|
+
<TfFormLayout :columns="2" label-width="96px">
|
|
73
|
+
<TfFormInput v-model="form.name" label="名称" prop="name" required placeholder="请输入名称" />
|
|
74
|
+
<TfFormSelect v-model="form.type" label="类型" prop="type" required :options="typeOptions" />
|
|
75
|
+
<TfFormInput v-model="form.owner" label="负责人" prop="owner" placeholder="请输入负责人" />
|
|
76
|
+
<TfFormDatePicker v-model="form.effectiveDate" label="生效日期" prop="effectiveDate" />
|
|
77
|
+
</TfFormLayout>
|
|
78
|
+
</TfCard>
|
|
79
|
+
|
|
80
|
+
<TfCard class="mt-4" title="补充信息">
|
|
81
|
+
<TfFormLayout :columns="1" label-width="96px">
|
|
82
|
+
<TfFormTextarea v-model="form.remark" label="备注" prop="remark" :rows="4" placeholder="请输入备注" />
|
|
83
|
+
</TfFormLayout>
|
|
84
|
+
</TfCard>
|
|
85
|
+
</TfForm>
|
|
86
|
+
</div>
|
|
87
|
+
</template>
|
|
88
|
+
|
|
89
|
+
<script setup lang="ts">
|
|
90
|
+
import { computed, onMounted, reactive, ref } from 'vue'
|
|
91
|
+
import {
|
|
92
|
+
TfAlert,
|
|
93
|
+
TfButton,
|
|
94
|
+
TfCard,
|
|
95
|
+
TfForm,
|
|
96
|
+
TfFormDatePicker,
|
|
97
|
+
TfFormInput,
|
|
98
|
+
TfFormLayout,
|
|
99
|
+
TfFormSelect,
|
|
100
|
+
TfFormTextarea,
|
|
101
|
+
TfPageHeader,
|
|
102
|
+
TfSkeleton
|
|
103
|
+
} from '@tongfun/ui'
|
|
104
|
+
|
|
105
|
+
interface BusinessForm {
|
|
106
|
+
id?: number
|
|
107
|
+
name: string
|
|
108
|
+
type: string
|
|
109
|
+
owner: string
|
|
110
|
+
effectiveDate: string
|
|
111
|
+
remark: string
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const props = withDefaults(defineProps<{
|
|
115
|
+
mode?: 'create' | 'edit' | 'view'
|
|
116
|
+
id?: number
|
|
117
|
+
}>(), {
|
|
118
|
+
mode: 'create'
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
const emit = defineEmits<{
|
|
122
|
+
back: []
|
|
123
|
+
saved: [BusinessForm]
|
|
124
|
+
submitted: [BusinessForm]
|
|
125
|
+
}>()
|
|
126
|
+
|
|
127
|
+
const formRef = ref()
|
|
128
|
+
const loading = ref(false)
|
|
129
|
+
const saving = ref(false)
|
|
130
|
+
const submitting = ref(false)
|
|
131
|
+
const error = ref('')
|
|
132
|
+
|
|
133
|
+
const form = reactive<BusinessForm>({
|
|
134
|
+
name: '',
|
|
135
|
+
type: '',
|
|
136
|
+
owner: '',
|
|
137
|
+
effectiveDate: '',
|
|
138
|
+
remark: ''
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
const rules = {
|
|
142
|
+
name: [{ required: true, message: '请输入名称' }],
|
|
143
|
+
type: [{ required: true, message: '请选择类型' }]
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const typeOptions = [
|
|
147
|
+
{ label: '标准业务', value: 'standard' },
|
|
148
|
+
{ label: '专项业务', value: 'special' }
|
|
149
|
+
]
|
|
150
|
+
|
|
151
|
+
const isViewMode = computed(() => props.mode === 'view')
|
|
152
|
+
const busy = computed(() => loading.value || saving.value || submitting.value)
|
|
153
|
+
const pageTitle = computed(() => {
|
|
154
|
+
if (props.mode === 'edit') return '编辑业务对象'
|
|
155
|
+
if (props.mode === 'view') return '查看业务对象'
|
|
156
|
+
return '新建业务对象'
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
onMounted(() => {
|
|
160
|
+
if (props.mode !== 'create' && props.id) {
|
|
161
|
+
loadDetail()
|
|
162
|
+
}
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
async function loadDetail() {
|
|
166
|
+
loading.value = true
|
|
167
|
+
error.value = ''
|
|
168
|
+
|
|
169
|
+
try {
|
|
170
|
+
// Replace with detail API.
|
|
171
|
+
} catch (err) {
|
|
172
|
+
error.value = err instanceof Error ? err.message : '详情加载失败'
|
|
173
|
+
} finally {
|
|
174
|
+
loading.value = false
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
async function validateForm() {
|
|
179
|
+
if (!formRef.value?.validate) return true
|
|
180
|
+
return formRef.value.validate()
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
async function handleSave() {
|
|
184
|
+
error.value = ''
|
|
185
|
+
const valid = await validateForm()
|
|
186
|
+
if (!valid) return
|
|
187
|
+
|
|
188
|
+
saving.value = true
|
|
189
|
+
try {
|
|
190
|
+
// Replace with save API.
|
|
191
|
+
emit('saved', { ...form })
|
|
192
|
+
} catch (err) {
|
|
193
|
+
error.value = err instanceof Error ? err.message : '保存失败'
|
|
194
|
+
} finally {
|
|
195
|
+
saving.value = false
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
async function handleSubmit() {
|
|
200
|
+
error.value = ''
|
|
201
|
+
const valid = await validateForm()
|
|
202
|
+
if (!valid) return
|
|
203
|
+
|
|
204
|
+
submitting.value = true
|
|
205
|
+
try {
|
|
206
|
+
// Replace with submit API.
|
|
207
|
+
emit('submitted', { ...form })
|
|
208
|
+
} catch (err) {
|
|
209
|
+
error.value = err instanceof Error ? err.message : '提交失败'
|
|
210
|
+
} finally {
|
|
211
|
+
submitting.value = false
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function handleBack() {
|
|
216
|
+
emit('back')
|
|
217
|
+
}
|
|
218
|
+
</script>
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## 设计说明
|
|
222
|
+
|
|
223
|
+
- `TfForm` 是表单状态和校验的唯一入口。
|
|
224
|
+
- 分组使用 `TfCard`,字段布局使用 `TfFormLayout`。
|
|
225
|
+
- 保存和提交都必须先校验,再进入业务 API。
|
|
226
|
+
- 查看模式通过 `disabled` 传给 `TfForm`,避免逐个字段控制。
|
|
227
|
+
- 失败时保留用户输入,不清空表单。
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
# Golden Example: 管理列表页
|
|
2
|
+
|
|
3
|
+
## 场景
|
|
4
|
+
|
|
5
|
+
用于订单、客户、合同、单据、用户等业务对象的管理列表。Agent 应生成高信息密度、可查询、可分页、可批量操作的企业后台页面。
|
|
6
|
+
|
|
7
|
+
## 推荐结构
|
|
8
|
+
|
|
9
|
+
1. `TfPageHeader` 放页面标题、描述和主操作。
|
|
10
|
+
2. `TfCard` 承载筛选区、工具栏、表格和分页。
|
|
11
|
+
3. `TfForm` + `TfFormLayout` 组织筛选字段。
|
|
12
|
+
4. `TfToolbar` 放刷新、导出、批量操作。
|
|
13
|
+
5. `TfTable` 展示数据。
|
|
14
|
+
6. `TfPagination` 放在表格下方。
|
|
15
|
+
|
|
16
|
+
## 推荐组件
|
|
17
|
+
|
|
18
|
+
- `TfPageHeader`
|
|
19
|
+
- `TfCard`
|
|
20
|
+
- `TfForm`
|
|
21
|
+
- `TfFormLayout`
|
|
22
|
+
- `TfFormInput`
|
|
23
|
+
- `TfFormSelect`
|
|
24
|
+
- `TfButton`
|
|
25
|
+
- `TfToolbar`
|
|
26
|
+
- `TfTable`
|
|
27
|
+
- `TfPagination`
|
|
28
|
+
- `TfEmpty`
|
|
29
|
+
- `TfSkeleton`
|
|
30
|
+
- `TfAlert`
|
|
31
|
+
- `TfTag`
|
|
32
|
+
|
|
33
|
+
## 可替换区域
|
|
34
|
+
|
|
35
|
+
- 筛选字段可替换为当前业务实体字段。
|
|
36
|
+
- 表格 columns 可替换为当前业务对象字段。
|
|
37
|
+
- 行操作可替换为详情、编辑、删除、审核等业务动作。
|
|
38
|
+
- API 请求函数由业务项目提供。
|
|
39
|
+
|
|
40
|
+
## 不建议改动区域
|
|
41
|
+
|
|
42
|
+
- 页面标题区、筛选区、工具栏、表格、分页的顺序。
|
|
43
|
+
- loading、empty、error 的状态覆盖。
|
|
44
|
+
- token 驱动的颜色和间距规则。
|
|
45
|
+
- `@tongfun/ui` 组件优先级。
|
|
46
|
+
|
|
47
|
+
## 状态覆盖
|
|
48
|
+
|
|
49
|
+
- loading:首次加载和查询加载。
|
|
50
|
+
- empty:无数据时展示 `TfEmpty`。
|
|
51
|
+
- error:查询失败时展示 `TfAlert` 和重试按钮。
|
|
52
|
+
- disabled:加载中禁用查询、重置和批量操作。
|
|
53
|
+
- permission:无新增权限时隐藏新增按钮。
|
|
54
|
+
- pagination:分页变化保留筛选条件。
|
|
55
|
+
- filter reset:重置筛选后回到第一页。
|
|
56
|
+
|
|
57
|
+
## Vue SFC 示例代码
|
|
58
|
+
|
|
59
|
+
```vue
|
|
60
|
+
<template>
|
|
61
|
+
<div class="space-y-4">
|
|
62
|
+
<TfPageHeader title="订单管理" description="查询、维护和跟踪业务订单">
|
|
63
|
+
<template #actions>
|
|
64
|
+
<TfButton v-if="permissions.create" type="primary" @click="handleCreate">
|
|
65
|
+
<Plus class="h-4 w-4" />
|
|
66
|
+
新建订单
|
|
67
|
+
</TfButton>
|
|
68
|
+
</template>
|
|
69
|
+
</TfPageHeader>
|
|
70
|
+
|
|
71
|
+
<TfCard>
|
|
72
|
+
<TfForm :model="filters" :disabled="loading">
|
|
73
|
+
<TfFormLayout :columns="3" label-width="88px">
|
|
74
|
+
<TfFormInput v-model="filters.keyword" label="关键词" prop="keyword" placeholder="订单号 / 客户名称" />
|
|
75
|
+
<TfFormSelect v-model="filters.status" label="状态" prop="status" :options="statusOptions" clearable />
|
|
76
|
+
<TfFormSelect v-model="filters.owner" label="负责人" prop="owner" :options="ownerOptions" clearable />
|
|
77
|
+
</TfFormLayout>
|
|
78
|
+
</TfForm>
|
|
79
|
+
|
|
80
|
+
<div class="mt-4 flex items-center justify-between gap-3">
|
|
81
|
+
<TfToolbar>
|
|
82
|
+
<TfButton :loading="loading" @click="fetchList">
|
|
83
|
+
<RefreshCw class="h-4 w-4" />
|
|
84
|
+
刷新
|
|
85
|
+
</TfButton>
|
|
86
|
+
<TfButton :disabled="!selectedIds.length || loading">批量导出</TfButton>
|
|
87
|
+
</TfToolbar>
|
|
88
|
+
|
|
89
|
+
<div class="flex items-center gap-2">
|
|
90
|
+
<TfButton :disabled="loading" @click="handleReset">重置</TfButton>
|
|
91
|
+
<TfButton type="primary" :loading="loading" @click="handleSearch">查询</TfButton>
|
|
92
|
+
</div>
|
|
93
|
+
</div>
|
|
94
|
+
|
|
95
|
+
<TfAlert v-if="error" class="mt-4" type="error" title="列表加载失败" :description="error" show-icon>
|
|
96
|
+
<template #action>
|
|
97
|
+
<TfButton size="sm" @click="fetchList">重试</TfButton>
|
|
98
|
+
</template>
|
|
99
|
+
</TfAlert>
|
|
100
|
+
|
|
101
|
+
<div class="mt-4">
|
|
102
|
+
<TfSkeleton v-if="loading && !rows.length" :rows="6" />
|
|
103
|
+
|
|
104
|
+
<TfEmpty v-else-if="!rows.length" description="暂无订单数据">
|
|
105
|
+
<TfButton v-if="permissions.create" type="primary" @click="handleCreate">新建订单</TfButton>
|
|
106
|
+
</TfEmpty>
|
|
107
|
+
|
|
108
|
+
<TfTable
|
|
109
|
+
v-else
|
|
110
|
+
:columns="columns"
|
|
111
|
+
:data="rows"
|
|
112
|
+
:loading="loading"
|
|
113
|
+
row-key="id"
|
|
114
|
+
@selection-change="selectedIds = $event"
|
|
115
|
+
/>
|
|
116
|
+
</div>
|
|
117
|
+
|
|
118
|
+
<div class="mt-4 flex justify-end">
|
|
119
|
+
<TfPagination
|
|
120
|
+
v-model:current="pagination.page"
|
|
121
|
+
v-model:page-size="pagination.pageSize"
|
|
122
|
+
:total="pagination.total"
|
|
123
|
+
:disabled="loading"
|
|
124
|
+
@change="fetchList"
|
|
125
|
+
/>
|
|
126
|
+
</div>
|
|
127
|
+
</TfCard>
|
|
128
|
+
</div>
|
|
129
|
+
</template>
|
|
130
|
+
|
|
131
|
+
<script setup lang="ts">
|
|
132
|
+
import { computed, h, reactive, ref } from 'vue'
|
|
133
|
+
import { Plus, RefreshCw } from 'lucide-vue-next'
|
|
134
|
+
import {
|
|
135
|
+
TfAlert,
|
|
136
|
+
TfButton,
|
|
137
|
+
TfCard,
|
|
138
|
+
TfEmpty,
|
|
139
|
+
TfForm,
|
|
140
|
+
TfFormInput,
|
|
141
|
+
TfFormLayout,
|
|
142
|
+
TfFormSelect,
|
|
143
|
+
TfPageHeader,
|
|
144
|
+
TfPagination,
|
|
145
|
+
TfSkeleton,
|
|
146
|
+
TfTable,
|
|
147
|
+
TfTag,
|
|
148
|
+
TfToolbar
|
|
149
|
+
} from '@tongfun/ui'
|
|
150
|
+
|
|
151
|
+
interface OrderRow {
|
|
152
|
+
id: number
|
|
153
|
+
code: string
|
|
154
|
+
customerName: string
|
|
155
|
+
status: 'draft' | 'submitted' | 'approved'
|
|
156
|
+
amount: number
|
|
157
|
+
owner: string
|
|
158
|
+
updatedAt: string
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
interface QueryFilters {
|
|
162
|
+
keyword: string
|
|
163
|
+
status: string
|
|
164
|
+
owner: string
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const loading = ref(false)
|
|
168
|
+
const error = ref('')
|
|
169
|
+
const rows = ref<OrderRow[]>([])
|
|
170
|
+
const selectedIds = ref<number[]>([])
|
|
171
|
+
|
|
172
|
+
const filters = reactive<QueryFilters>({
|
|
173
|
+
keyword: '',
|
|
174
|
+
status: '',
|
|
175
|
+
owner: ''
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
const pagination = reactive({
|
|
179
|
+
page: 1,
|
|
180
|
+
pageSize: 20,
|
|
181
|
+
total: 0
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
const permissions = reactive({
|
|
185
|
+
create: true,
|
|
186
|
+
export: true
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
const statusOptions = [
|
|
190
|
+
{ label: '草稿', value: 'draft' },
|
|
191
|
+
{ label: '已提交', value: 'submitted' },
|
|
192
|
+
{ label: '已审核', value: 'approved' }
|
|
193
|
+
]
|
|
194
|
+
|
|
195
|
+
const ownerOptions = [
|
|
196
|
+
{ label: '张三', value: 'zhangsan' },
|
|
197
|
+
{ label: '李四', value: 'lisi' }
|
|
198
|
+
]
|
|
199
|
+
|
|
200
|
+
const columns = computed(() => [
|
|
201
|
+
{ type: 'selection', width: 48 },
|
|
202
|
+
{ title: '订单号', key: 'code', width: 160 },
|
|
203
|
+
{ title: '客户名称', key: 'customerName', minWidth: 180 },
|
|
204
|
+
{
|
|
205
|
+
title: '状态',
|
|
206
|
+
key: 'status',
|
|
207
|
+
width: 120,
|
|
208
|
+
render: ({ row }: { row: OrderRow }) => h(TfTag, { type: row.status === 'approved' ? 'success' : 'info' }, () => statusText(row.status))
|
|
209
|
+
},
|
|
210
|
+
{ title: '金额', key: 'amount', width: 120 },
|
|
211
|
+
{ title: '负责人', key: 'owner', width: 120 },
|
|
212
|
+
{ title: '更新时间', key: 'updatedAt', width: 180 }
|
|
213
|
+
])
|
|
214
|
+
|
|
215
|
+
function statusText(status: OrderRow['status']) {
|
|
216
|
+
const map = {
|
|
217
|
+
draft: '草稿',
|
|
218
|
+
submitted: '已提交',
|
|
219
|
+
approved: '已审核'
|
|
220
|
+
}
|
|
221
|
+
return map[status]
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
async function fetchList() {
|
|
225
|
+
loading.value = true
|
|
226
|
+
error.value = ''
|
|
227
|
+
|
|
228
|
+
try {
|
|
229
|
+
// Replace with business API.
|
|
230
|
+
rows.value = []
|
|
231
|
+
pagination.total = 0
|
|
232
|
+
} catch (err) {
|
|
233
|
+
error.value = err instanceof Error ? err.message : '请稍后重试'
|
|
234
|
+
} finally {
|
|
235
|
+
loading.value = false
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function handleSearch() {
|
|
240
|
+
pagination.page = 1
|
|
241
|
+
fetchList()
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function handleReset() {
|
|
245
|
+
filters.keyword = ''
|
|
246
|
+
filters.status = ''
|
|
247
|
+
filters.owner = ''
|
|
248
|
+
pagination.page = 1
|
|
249
|
+
fetchList()
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function handleCreate() {
|
|
253
|
+
// Navigate to create page.
|
|
254
|
+
}
|
|
255
|
+
</script>
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## 设计说明
|
|
259
|
+
|
|
260
|
+
- 筛选、工具栏、表格和分页放在同一个 `TfCard` 内,减少页面跳动。
|
|
261
|
+
- 表格页必须覆盖 loading、empty、error,不允许只渲染表格。
|
|
262
|
+
- 主操作放在 `TfPageHeader`,批量和辅助操作放在 `TfToolbar`。
|
|
263
|
+
- Tailwind 只用于 `space-y-4`、`mt-4`、`flex` 等布局辅助。
|
|
264
|
+
- 颜色和状态样式交给 `@tongfun/ui` 组件和 tokens。
|