@ebiz/designer-components 0.0.18-beta.9 → 0.0.18-kzy.1

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.
@@ -234,6 +234,12 @@ const routes = [
234
234
  name: 'TdesignDialog',
235
235
  component: () => import('../views/DialogDemo.vue'),
236
236
  meta: { title: 'TDesign对话框组件示例' }
237
+ },
238
+ {
239
+ path: '/table-demo',
240
+ name: 'TableDemo',
241
+ component: () => import('../views/TableDemo.vue'),
242
+ meta: { title: 'Ebiz表格组件示例' }
237
243
  }
238
244
  ]
239
245
 
@@ -53,7 +53,8 @@ export default {
53
53
  { path: '/ebiz-avatar', title: 'Ebiz头像组件示例' },
54
54
  { path: '/ebiz-employee-info', title: 'Ebiz员工信息组件示例' },
55
55
  { path: '/tdesign-alert', title: 'TDesign提示组件示例' },
56
- { path: '/tdesign-dialog', title: 'TDesign对话框组件示例' }
56
+ { path: '/tdesign-dialog', title: 'TDesign对话框组件示例' },
57
+ { path: '/table-demo', title: 'Ebiz表格组件示例' }
57
58
  ]
58
59
 
59
60
  return {
@@ -0,0 +1,335 @@
1
+ <template>
2
+ <div class="container">
3
+ <h1>EbizTable 表格组件</h1>
4
+ <p>高性能表格组件,用于展示结构化数据,支持多种功能特性。</p>
5
+
6
+ <h2>基础用法</h2>
7
+ <div class="demo-block">
8
+ <EbizTable
9
+ :data="basicData"
10
+ :columns="basicColumns"
11
+ :bordered="true"
12
+ row-key="id"
13
+ />
14
+ </div>
15
+
16
+ <h2>带斑马纹和高亮行</h2>
17
+ <div class="demo-block">
18
+ <EbizTable
19
+ :data="basicData"
20
+ :columns="basicColumns"
21
+ :bordered="true"
22
+ :stripe="true"
23
+ :hover="true"
24
+ row-key="id"
25
+ />
26
+ </div>
27
+
28
+ <h2>可排序表格</h2>
29
+ <div class="demo-block">
30
+ <EbizTable
31
+ :data="basicData"
32
+ :columns="sortableColumns"
33
+ :sort="sortInfo"
34
+ @sort-change="onSortChange"
35
+ :bordered="true"
36
+ row-key="id"
37
+ />
38
+ </div>
39
+
40
+ <h2>表格尺寸</h2>
41
+ <div class="demo-block">
42
+ <div class="mb-2">
43
+ <span>选择尺寸:</span>
44
+ <t-radio-group v-model="size">
45
+ <t-radio value="small">小尺寸</t-radio>
46
+ <t-radio value="medium">中尺寸</t-radio>
47
+ <t-radio value="large">大尺寸</t-radio>
48
+ </t-radio-group>
49
+ </div>
50
+ <EbizTable
51
+ :data="basicData"
52
+ :columns="basicColumns"
53
+ :bordered="true"
54
+ :size="size"
55
+ row-key="id"
56
+ />
57
+ </div>
58
+
59
+ <h2>可选择表格</h2>
60
+ <div class="demo-block">
61
+ <EbizTable
62
+ :data="basicData"
63
+ :columns="selectableColumns"
64
+ :bordered="true"
65
+ row-key="id"
66
+ @select-change="onSelectChange"
67
+ />
68
+ <div class="mt-2">
69
+ <p>已选择的行:{{ selectedRows.map(item => item.name).join(', ') || '无' }}</p>
70
+ </div>
71
+ </div>
72
+
73
+ <h2>分页表格</h2>
74
+ <div class="demo-block">
75
+ <EbizTable
76
+ :data="paginationData"
77
+ :columns="basicColumns"
78
+ :bordered="true"
79
+ :pagination="pagination"
80
+ @page-change="onPageChange"
81
+ row-key="id"
82
+ />
83
+ </div>
84
+
85
+ <h2>树形表格</h2>
86
+ <div class="demo-block">
87
+ <EbizTable
88
+ :data="treeData"
89
+ :columns="basicColumns"
90
+ :tree="{ childrenKey: 'children', treeNodeColumnIndex: 0 }"
91
+ :bordered="true"
92
+ row-key="id"
93
+ />
94
+ </div>
95
+
96
+ <h2>API 参考</h2>
97
+ <div>
98
+ <h3>属性</h3>
99
+ <EbizTable
100
+ :data="propsData"
101
+ :columns="propsColumns"
102
+ :bordered="true"
103
+ :stripe="true"
104
+ row-key="id"
105
+ />
106
+
107
+ <h3>事件</h3>
108
+ <EbizTable
109
+ :data="eventsData"
110
+ :columns="eventsColumns"
111
+ :bordered="true"
112
+ :stripe="true"
113
+ row-key="id"
114
+ />
115
+
116
+ <h3>插槽</h3>
117
+ <EbizTable
118
+ :data="slotsData"
119
+ :columns="slotsColumns"
120
+ :bordered="true"
121
+ :stripe="true"
122
+ row-key="id"
123
+ />
124
+ </div>
125
+ </div>
126
+ </template>
127
+
128
+ <script setup>
129
+ import { ref, reactive, computed } from 'vue';
130
+ import { EbizTable } from '../index.js';
131
+ import { RadioGroup as TRadioGroup, Radio as TRadio } from 'tdesign-vue-next';
132
+
133
+ // 基础数据
134
+ const basicData = [
135
+ { id: 1, name: '张三', age: 28, address: '北京市朝阳区' },
136
+ { id: 2, name: '李四', age: 35, address: '上海市浦东新区' },
137
+ { id: 3, name: '王五', age: 42, address: '广州市天河区' },
138
+ { id: 4, name: '赵六', age: 31, address: '深圳市南山区' },
139
+ { id: 5, name: '钱七', age: 26, address: '杭州市西湖区' },
140
+ ];
141
+
142
+ // 基础列配置
143
+ const basicColumns = [
144
+ { colKey: 'name', title: '姓名', width: 100 },
145
+ { colKey: 'age', title: '年龄', width: 100 },
146
+ { colKey: 'address', title: '地址' },
147
+ ];
148
+
149
+ // 可排序列配置
150
+ const sortableColumns = [
151
+ { colKey: 'name', title: '姓名', width: 100 },
152
+ { colKey: 'age', title: '年龄', width: 100, sorter: true },
153
+ { colKey: 'address', title: '地址' },
154
+ ];
155
+
156
+ // 可选择列配置
157
+ const selectableColumns = [
158
+ { colKey: 'row-select', type: 'multiple', width: 50 },
159
+ { colKey: 'name', title: '姓名', width: 100 },
160
+ { colKey: 'age', title: '年龄', width: 100 },
161
+ { colKey: 'address', title: '地址' },
162
+ ];
163
+
164
+ // 排序信息
165
+ const sortInfo = reactive({
166
+ sortBy: 'age',
167
+ descending: true,
168
+ });
169
+
170
+ // 选择的行
171
+ const selectedRows = ref([]);
172
+
173
+ // 分页配置
174
+ const pagination = reactive({
175
+ current: 1,
176
+ pageSize: 5,
177
+ total: 20,
178
+ showJumper: true,
179
+ showTotal: true,
180
+ });
181
+
182
+ // 分页数据
183
+ const allPaginationData = Array.from({ length: 20 }, (_, i) => ({
184
+ id: i + 1,
185
+ name: `用户${i + 1}`,
186
+ age: Math.floor(Math.random() * 50) + 18,
187
+ address: ['北京', '上海', '广州', '深圳', '杭州'][Math.floor(Math.random() * 5)] + '市'
188
+ }));
189
+
190
+ // 当前展示的分页数据
191
+ const paginationData = computed(() => {
192
+ const start = (pagination.current - 1) * pagination.pageSize;
193
+ return allPaginationData.slice(start, start + pagination.pageSize);
194
+ });
195
+
196
+ // 树形数据
197
+ const treeData = [
198
+ {
199
+ id: 1,
200
+ name: '北京总部',
201
+ age: '-',
202
+ address: '北京市海淀区',
203
+ children: [
204
+ { id: 11, name: '研发部', age: 20, address: '北京市海淀区' },
205
+ { id: 12, name: '销售部', age: 15, address: '北京市朝阳区' },
206
+ ]
207
+ },
208
+ {
209
+ id: 2,
210
+ name: '上海分部',
211
+ age: '-',
212
+ address: '上海市浦东新区',
213
+ children: [
214
+ { id: 21, name: '研发部', age: 12, address: '上海市浦东新区' },
215
+ { id: 22, name: '销售部', age: 8, address: '上海市静安区' },
216
+ ]
217
+ }
218
+ ];
219
+
220
+ // 表格尺寸
221
+ const size = ref('medium');
222
+
223
+ // 排序变化处理
224
+ const onSortChange = (sort, options) => {
225
+ Object.assign(sortInfo, sort);
226
+ console.log('排序变化', sort, options);
227
+ };
228
+
229
+ // 选择变化处理
230
+ const onSelectChange = (selectedRowData) => {
231
+ selectedRows.value = selectedRowData;
232
+ console.log('选择变化', selectedRowData);
233
+ };
234
+
235
+ // 分页变化处理
236
+ const onPageChange = (pageInfo) => {
237
+ pagination.current = pageInfo.current;
238
+ pagination.pageSize = pageInfo.pageSize;
239
+ console.log('分页变化', pageInfo);
240
+ };
241
+
242
+ // API props 数据
243
+ const propsData = [
244
+ { id: 1, name: 'data', type: 'Array', default: '[]', desc: '表格数据' },
245
+ { id: 2, name: 'columns', type: 'Array', default: '[]', desc: '表格列配置' },
246
+ { id: 3, name: 'rowKey', type: 'String', default: 'id', desc: '表格行唯一标识字段' },
247
+ { id: 4, name: 'bordered', type: 'Boolean', default: 'false', desc: '是否显示边框' },
248
+ { id: 5, name: 'stripe', type: 'Boolean', default: 'false', desc: '是否显示斑马纹' },
249
+ { id: 6, name: 'hover', type: 'Boolean', default: 'true', desc: '是否开启行悬停效果' },
250
+ { id: 7, name: 'size', type: 'String', default: 'medium', desc: '表格尺寸,可选值:small/medium/large' },
251
+ { id: 8, name: 'loading', type: 'Boolean', default: 'false', desc: '是否处于加载状态' },
252
+ { id: 9, name: 'pagination', type: 'Object', default: '-', desc: '分页配置' },
253
+ { id: 10, name: 'tree', type: 'Object', default: '-', desc: '树形结构配置' },
254
+ ];
255
+
256
+ const propsColumns = [
257
+ { colKey: 'name', title: '属性名', width: 120 },
258
+ { colKey: 'type', title: '类型', width: 120 },
259
+ { colKey: 'default', title: '默认值', width: 120 },
260
+ { colKey: 'desc', title: '说明' },
261
+ ];
262
+
263
+ // API events 数据
264
+ const eventsData = [
265
+ { id: 1, name: 'page-change', params: 'pageInfo', desc: '分页发生变化时触发' },
266
+ { id: 2, name: 'sort-change', params: 'sort, options', desc: '排序发生变化时触发' },
267
+ { id: 3, name: 'filter-change', params: 'filterValue, col', desc: '过滤条件发生变化时触发' },
268
+ { id: 4, name: 'select-change', params: 'selectedRowData, options', desc: '选中行发生变化时触发' },
269
+ { id: 5, name: 'row-click', params: 'rowData, rowIndex, row', desc: '点击行时触发' },
270
+ { id: 6, name: 'cell-click', params: 'context', desc: '点击单元格时触发' },
271
+ ];
272
+
273
+ const eventsColumns = [
274
+ { colKey: 'name', title: '事件名', width: 150 },
275
+ { colKey: 'params', title: '参数', width: 220 },
276
+ { colKey: 'desc', title: '说明' },
277
+ ];
278
+
279
+ // API slots 数据
280
+ const slotsData = [
281
+ { id: 1, name: 'topContent', desc: '表格顶部内容' },
282
+ { id: 2, name: 'bottomContent', desc: '表格底部内容' },
283
+ { id: 3, name: 'empty', desc: '表格数据为空时的显示内容' },
284
+ { id: 4, name: 'loadMore', desc: '加载更多按钮' },
285
+ { id: 5, name: 'header', desc: '自定义表头' },
286
+ { id: 6, name: 'footer', desc: '自定义表尾' },
287
+ { id: 7, name: 'cell', desc: '自定义单元格内容' },
288
+ { id: 8, name: 'expandedRow', desc: '展开行内容' },
289
+ { id: 9, name: 'pagination', desc: '自定义分页器' },
290
+ ];
291
+
292
+ const slotsColumns = [
293
+ { colKey: 'name', title: '插槽名', width: 150 },
294
+ { colKey: 'desc', title: '说明' },
295
+ ];
296
+ </script>
297
+
298
+ <style scoped>
299
+ .container {
300
+ padding: 20px;
301
+ max-width: 1200px;
302
+ margin: 0 auto;
303
+ }
304
+
305
+ .demo-block {
306
+ margin-bottom: 24px;
307
+ border: 1px solid #e9e9e9;
308
+ border-radius: 2px;
309
+ padding: 24px;
310
+ background-color: #fafafa;
311
+ }
312
+
313
+ h1 {
314
+ font-size: 28px;
315
+ margin-bottom: 16px;
316
+ }
317
+
318
+ h2 {
319
+ font-size: 20px;
320
+ margin: 24px 0 16px;
321
+ }
322
+
323
+ h3 {
324
+ font-size: 18px;
325
+ margin: 24px 0 16px;
326
+ }
327
+
328
+ .mb-2 {
329
+ margin-bottom: 16px;
330
+ }
331
+
332
+ .mt-2 {
333
+ margin-top: 16px;
334
+ }
335
+ </style>
@@ -1,278 +0,0 @@
1
- /**
2
- * 简洁数据服务
3
- * 提供基本的数据操作方法,包含列表查询、详情查询、数据写入、数据修改、数据删除
4
- * 所有接口均使用POST方法提交
5
- */
6
-
7
- import axios from 'axios'
8
- import { TinyNotify } from '@opentiny/vue'
9
-
10
- // 从环境变量获取API基础URL
11
- const API_BASE_URL = 'http://' + window.location.host + '/api'
12
-
13
- /**
14
- * 创建axios实例
15
- */
16
- const axiosInstance = axios.create({
17
- baseURL: API_BASE_URL,
18
- timeout: 30000,
19
- headers: {
20
- 'Content-Type': 'application/json',
21
- Accept: 'application/json'
22
- }
23
- })
24
-
25
- /**
26
- * 请求拦截器
27
- */
28
- axiosInstance.interceptors.request.use(
29
- (config) => {
30
- // 添加认证信息
31
- const token = localStorage.getItem('token')
32
- if (token) {
33
- config.headers['AppDataAuthorization'] = `Bearer ${token}`
34
- }
35
-
36
- // 如果是FormData格式,不设置Content-Type,让浏览器自动设置
37
- if (config.data instanceof FormData) {
38
- config.headers['Content-Type'] = undefined
39
- }
40
-
41
- return config
42
- },
43
- (error) => {
44
- return Promise.reject(error)
45
- }
46
- )
47
-
48
- /**
49
- * 响应拦截器
50
- */
51
- axiosInstance.interceptors.response.use(
52
- (response) => {
53
- const { data } = response
54
-
55
- // 根据后端API的响应格式进行调整
56
- if (data.code === 0) {
57
- return data.data
58
- } else {
59
- // message.error(data.message || '请求失败');
60
- return Promise.reject(new Error(data.message || data.msg || '请求失败'))
61
- }
62
- },
63
- (error) => {
64
- // 错误处理
65
- if (error.response) {
66
- const { status } = error.response
67
-
68
- switch (status) {
69
- case 401:
70
- TinyNotify({
71
- type: 'warning',
72
- title: '未授权',
73
- message: '您无权限访问,请授权后重试',
74
- position: 'top-right',
75
- duration: 2000
76
- })
77
- break
78
- case 403:
79
- TinyNotify({
80
- type: 'warning',
81
- title: '权限不足',
82
- message: '禁止访问,权限不足',
83
- position: 'top-right',
84
- duration: 2000
85
- })
86
- break
87
- case 404:
88
- TinyNotify({
89
- type: 'warning',
90
- title: '404',
91
- message: '请求的资源不存在',
92
- position: 'top-right',
93
- duration: 2000
94
- })
95
- break
96
- case 500:
97
- TinyNotify({
98
- type: 'warning',
99
- title: '错误',
100
- message: '服务器内部错误',
101
- position: 'top-right',
102
- duration: 2000
103
- })
104
- break
105
- default:
106
- TinyNotify({
107
- type: 'warning',
108
- title: '请求失败',
109
- message: error.message,
110
- position: 'top-right',
111
- duration: 2000
112
- })
113
- }
114
- } else {
115
- TinyNotify({
116
- type: 'error',
117
- title: '网络错误',
118
- message: error.message,
119
- position: 'top-right',
120
- duration: 2000
121
- })
122
- // message.error('网络错误,请检查您的网络连接');
123
- }
124
-
125
- return Promise.reject(error)
126
- }
127
- )
128
-
129
- let apiMap = {
130
- MULTIPLE_DATA_SEARCH: '/appdata/select',
131
- DETAILS_DATA: '/appdata/detailData',
132
- INTERFACE_PLUGIN: '/appdata/plugin',
133
- DATA_INSERT: '/appdata/addData',
134
- BATCH_DATA_INSERT: '/appdata/addDatas',
135
- DATA_MODIFY: '/appdata/updateData',
136
- BATCH_DATA_MODIFY: '/appdata/updateDatas',
137
- DEL_DATA: '/appdata/delData',
138
- BATCH_DEL_DATA: '/appdata/delDatas',
139
- MULTIPLE_DATA_LINK_SEARCH: '/api/appdata/link/select',
140
- FILE_UPLOAD: '/api/file/upload' // 文件上传API
141
- }
142
-
143
- /**
144
- * 数据服务
145
- */
146
- const dataServiceAppData = {
147
- /**
148
- * 请求数据 (POST方法)
149
- * @param {string} url - 请求URL
150
- * @param {Object} [params] - 查询参数
151
- * @param {Object} [apiConfig] - API配置
152
- * @param {string} [apiConfig.apiId] - API标识
153
- * @param {string} [apiConfig.apiType] - API类型
154
- * @returns {Promise<any>} 响应数据
155
- * @example
156
- */
157
- fetch: (params = {}, apiConfig = {}, url = '') => {
158
- if (!url) {
159
- url = apiMap[apiConfig.apiType]
160
- }
161
-
162
- const { apiId = '', ...restConfig } = apiConfig
163
-
164
- const defaultConfig = {
165
- // 默认列表查询配置
166
- headers: {
167
- 'X-List-Query': 'true'
168
- },
169
- timeout: 20000
170
- }
171
- if (!params) {
172
- params = {}
173
- }
174
- params.apiId = apiConfig.apiId
175
- if (apiConfig.key) {
176
- params.key = apiConfig.key
177
- }
178
-
179
- const config = { ...defaultConfig, ...restConfig }
180
- return axiosInstance.post(url, params, config)
181
- },
182
-
183
- /**
184
- * 文件上传
185
- * @param {string} url - 上传URL,默认使用apiMap中的FILE_UPLOAD
186
- * @param {FormData} formData - 包含文件和其他数据的FormData
187
- * @param {Function} onProgress - 上传进度回调函数,参数为0-100的进度百分比
188
- * @returns {Promise<any>} 上传响应数据
189
- */
190
- upload: (url = '', formData, onProgress = () => {}) => {
191
- // 如果没有指定URL,使用默认的文件上传URL
192
- if (!url) {
193
- url = apiMap.FILE_UPLOAD
194
- }
195
-
196
- // 确保FormData中的文件字段名是'file'
197
- let fixedFormData = new FormData()
198
- let fileFound = false
199
-
200
- // 检查并修复FormData
201
- if (formData instanceof FormData) {
202
- // 由于FormData不能直接检查内容,我们使用迭代器
203
- try {
204
- // 在某些旧浏览器中可能不支持entries()
205
- if (typeof formData.entries === 'function') {
206
- for (let pair of formData.entries()) {
207
- const [key, value] = pair
208
-
209
- if (value instanceof File || value instanceof Blob) {
210
- // 找到文件,使用正确的字段名
211
- console.log(`Found file in field ${key}, adding as 'file'`)
212
- fixedFormData.append('file', value)
213
- fileFound = true
214
- } else {
215
- // 保留其他字段
216
- fixedFormData.append(key, value)
217
- }
218
- }
219
- } else {
220
- // 如果不支持entries(),假设formData已经是正确的,直接使用
221
- console.log('FormData.entries() not supported, using original FormData')
222
- fixedFormData = formData
223
- fileFound = true
224
- }
225
- } catch (e) {
226
- console.error('Error processing FormData:', e)
227
- // 出错时使用原始FormData
228
- fixedFormData = formData
229
- }
230
- } else {
231
- console.error('Invalid FormData:', formData)
232
- return Promise.reject(new Error('FormData is required for file upload'))
233
- }
234
-
235
- // 如果没有找到文件,返回错误
236
- if (!fileFound && typeof formData.entries === 'function') {
237
- console.error('No file found in FormData')
238
- return Promise.reject(new Error('No file found in FormData'))
239
- }
240
-
241
- // 上传配置
242
- const config = {
243
- timeout: 60000, // 上传超时时间加长
244
- headers: {
245
- // 让浏览器自动设置Content-Type和boundary
246
- 'Content-Type': undefined
247
- },
248
- onUploadProgress: (progressEvent) => {
249
- // 计算上传进度百分比
250
- const percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total)
251
- onProgress(percentCompleted)
252
- }
253
- }
254
-
255
- // 发起上传请求
256
- console.log('Sending file upload request to:', url)
257
- return axiosInstance.post(url, fixedFormData, config).then((response) => {
258
- console.log('Upload server response:', response)
259
-
260
- // 处理文件路径
261
- // 如果返回的是相对路径,转换为完整URL
262
- if (typeof response === 'string' && !response.startsWith('http')) {
263
- // 判断路径是否以斜杠开头
264
- const baseUrl = API_BASE_URL.endsWith('/') ? API_BASE_URL.slice(0, -1) : API_BASE_URL
265
- const filePath = response.startsWith('/') ? response : `/${response}`
266
-
267
- // 构建完整URL
268
- const fullUrl = `${baseUrl}/files${filePath}`
269
- console.log('Converted file path to full URL:', fullUrl)
270
- return fullUrl
271
- }
272
-
273
- return response
274
- })
275
- }
276
- }
277
-
278
- export default dataServiceAppData