@ebiz/designer-components 0.0.18 → 0.0.19

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.
Files changed (99) hide show
  1. package/package.json +3 -2
  2. package/src/apiService/mockDataService.js +116 -0
  3. package/src/apiService/simpleDataService.js +186 -80
  4. package/src/components/Button.vue +72 -22
  5. package/src/components/EbizAvatar.vue +116 -0
  6. package/src/components/EbizCheckbox.vue +94 -0
  7. package/src/components/EbizCheckboxGroup.vue +70 -0
  8. package/src/components/EbizDetailBlock.vue +82 -0
  9. package/src/components/EbizDialog.vue +244 -56
  10. package/src/components/EbizEmployeeInfo.vue +139 -0
  11. package/src/components/EbizFileUpload.vue +202 -0
  12. package/src/components/EbizPageHeader.vue +96 -0
  13. package/src/components/EbizPagination.vue +163 -0
  14. package/src/components/EbizRadio.vue +87 -0
  15. package/src/components/EbizRadioGroup.vue +84 -0
  16. package/src/components/EbizRemoteSelect.vue +118 -40
  17. package/src/components/EbizSpace.vue +101 -0
  18. package/src/components/EbizStatistic.vue +150 -0
  19. package/src/components/EbizSwiper.vue +114 -0
  20. package/src/components/EbizSwiperItem.vue +14 -0
  21. package/src/components/EbizSwitch.vue +86 -0
  22. package/src/components/EbizTabHeader.vue +145 -0
  23. package/src/components/EbizTabPanel.vue +23 -0
  24. package/src/components/EbizTable.vue +466 -0
  25. package/src/components/EbizTableColumn.vue +117 -0
  26. package/src/components/EbizTableSort.vue +181 -0
  27. package/src/components/EbizTabs.vue +133 -91
  28. package/src/components/EbizTimePicker.vue +144 -0
  29. package/src/components/EbizTitle.vue +3 -10
  30. package/src/components/EbizTree.vue +153 -0
  31. package/src/components/EbizTreeSelector.vue +423 -0
  32. package/src/components/Home.vue +8 -0
  33. package/src/components/TdesignAlert.vue +116 -0
  34. package/src/components/TdesignButton.vue +130 -0
  35. package/src/components/TdesignCalendar/index.vue +146 -0
  36. package/src/components/TdesignCard.vue +196 -0
  37. package/src/components/TdesignCol.vue +102 -0
  38. package/src/components/TdesignCollapse.vue +143 -0
  39. package/src/components/TdesignCollapsePanel.vue +80 -0
  40. package/src/components/TdesignDatePicker.vue +125 -0
  41. package/src/components/TdesignDialog.vue +226 -0
  42. package/src/components/TdesignForm.vue +134 -0
  43. package/src/components/TdesignFormItem.vue +106 -0
  44. package/src/components/TdesignGrid.vue +56 -0
  45. package/src/components/TdesignIcon.vue +68 -0
  46. package/src/components/TdesignImage.vue +163 -0
  47. package/src/components/TdesignImageViewer.vue +201 -0
  48. package/src/components/TdesignInput.vue +243 -0
  49. package/src/components/TdesignSelect.vue +445 -0
  50. package/src/components/TdesignTag.vue +118 -0
  51. package/src/components/TdesignTextarea.vue +143 -0
  52. package/src/components/TdesignTimeline.vue +58 -0
  53. package/src/components/TdesignTimelineItem.vue +72 -0
  54. package/src/components/TdesignUpload.vue +757 -0
  55. package/src/components/TdesignWatermark.vue +108 -0
  56. package/src/index.js +130 -0
  57. package/src/main.js +20 -4
  58. package/src/router/index.js +244 -5
  59. package/src/views/Button.vue +7 -3
  60. package/src/views/CheckboxDemo.vue +105 -0
  61. package/src/views/DialogDemo.vue +126 -0
  62. package/src/views/EbizAvatar.vue +224 -0
  63. package/src/views/EbizDetailBlockDemo.vue +31 -0
  64. package/src/views/EbizEmployeeInfo.vue +250 -0
  65. package/src/views/EbizRadioDemo.vue +152 -0
  66. package/src/views/EbizSpace.vue +186 -0
  67. package/src/views/EbizSwiper.vue +158 -0
  68. package/src/views/GridDemo.vue +239 -0
  69. package/src/views/Home.vue +63 -2
  70. package/src/views/PageHeaderDemo.vue +105 -0
  71. package/src/views/PaginationDemo.vue +97 -0
  72. package/src/views/RemoteSelect.vue +336 -5
  73. package/src/views/StatisticDemo.vue +191 -0
  74. package/src/views/SwitchDemo.vue +80 -0
  75. package/src/views/TableDemo.vue +335 -0
  76. package/src/views/TableSortDemo.vue +144 -0
  77. package/src/views/TableView.vue +69 -0
  78. package/src/views/TabsDemo.vue +283 -0
  79. package/src/views/TagDemo.vue +102 -0
  80. package/src/views/TdesignAlert.vue +99 -0
  81. package/src/views/TdesignButton.vue +191 -0
  82. package/src/views/TdesignCalendar.vue +95 -0
  83. package/src/views/TdesignCard.vue +297 -0
  84. package/src/views/TdesignCollapse.vue +294 -0
  85. package/src/views/TdesignDatePicker.vue +188 -0
  86. package/src/views/TdesignForm.vue +249 -0
  87. package/src/views/TdesignIcon.vue +204 -0
  88. package/src/views/TdesignImage.vue +216 -0
  89. package/src/views/TdesignImageViewer.vue +199 -0
  90. package/src/views/TdesignInput.vue +253 -0
  91. package/src/views/TdesignSelect.vue +474 -0
  92. package/src/views/TdesignSwiper.vue +158 -0
  93. package/src/views/TextareaDemo.vue +94 -0
  94. package/src/views/TimePickerDemo.vue +147 -0
  95. package/src/views/TimelineDemo.vue +161 -0
  96. package/src/views/TreeDemo.vue +255 -0
  97. package/src/views/TreeSelectorDemo.vue +246 -0
  98. package/src/views/UploadDemo.vue +122 -0
  99. package/src/views/WatermarkDemo.vue +86 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ebiz/designer-components",
3
- "version": "0.0.18",
3
+ "version": "0.0.19",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -22,7 +22,7 @@
22
22
  "@opentiny/vue-icon": "~3.20.0",
23
23
  "axios": "^1.8.1",
24
24
  "echarts": "^5.6.0",
25
- "tdesign-vue-next": "^1.10.6",
25
+ "tdesign-vue-next": "^1.11.5",
26
26
  "unplugin-auto-import": "^19.0.0",
27
27
  "unplugin-vue-components": "^28.0.0",
28
28
  "vue": "^3.5.13",
@@ -32,6 +32,7 @@
32
32
  "@opentiny/tiny-engine-mock": "^2.1.0",
33
33
  "@opentiny/tiny-engine-vite-config": "^2.1.0",
34
34
  "@vitejs/plugin-vue": "^5.2.1",
35
+ "@vitejs/plugin-vue-jsx": "^4.0.1",
35
36
  "less": "^4.2.0",
36
37
  "vite": "^6.0.5",
37
38
  "vite-plugin-proxy": "^0.5.0"
@@ -0,0 +1,116 @@
1
+ /**
2
+ * 模拟数据服务
3
+ * 用于组件演示,提供模拟的远程数据查询
4
+ */
5
+
6
+ // 模拟用户数据
7
+ const mockUsers = [
8
+ { id: '1', name: '张三', email: 'zhangsan@example.com', department: '研发部' },
9
+ { id: '2', name: '李四', email: 'lisi@example.com', department: '市场部' },
10
+ { id: '3', name: '王五', email: 'wangwu@example.com', department: '设计部' },
11
+ { id: '4', name: '赵六', email: 'zhaoliu@example.com', department: '人力资源部' },
12
+ { id: '5', name: '钱七', email: 'qianqi@example.com', department: '财务部' },
13
+ { id: '6', name: '孙八', email: 'sunba@example.com', department: '行政部' },
14
+ { id: '7', name: '周九', email: 'zhoujiu@example.com', department: '销售部' },
15
+ { id: '8', name: '吴十', email: 'wushi@example.com', department: '客服部' },
16
+ { id: '9', name: '郑十一', email: 'zhengshiyi@example.com', department: '研发部' },
17
+ { id: '10', name: '王十二', email: 'wangshier@example.com', department: '市场部' },
18
+ { id: '11', name: '刘十三', email: 'liushisan@example.com', department: '设计部' },
19
+ { id: '12', name: '陈十四', email: 'chenshisi@example.com', department: '人力资源部' },
20
+ { id: '13', name: '杨十五', email: 'yangshiwu@example.com', department: '财务部' },
21
+ { id: '14', name: '黄十六', email: 'huangshiliu@example.com', department: '行政部' },
22
+ { id: '15', name: '赵十七', email: 'zhaoshiqi@example.com', department: '销售部' }
23
+ ];
24
+
25
+ // 模拟产品数据
26
+ const mockProducts = [
27
+ { id: 'p1', name: '笔记本电脑', price: 5999, category: '电子产品' },
28
+ { id: 'p2', name: '智能手机', price: 3999, category: '电子产品' },
29
+ { id: 'p3', name: '平板电脑', price: 2999, category: '电子产品' },
30
+ { id: 'p4', name: '智能手表', price: 1999, category: '电子产品' },
31
+ { id: 'p5', name: '耳机', price: 799, category: '电子产品' },
32
+ { id: 'p6', name: '办公桌', price: 1299, category: '办公家具' },
33
+ { id: 'p7', name: '办公椅', price: 899, category: '办公家具' },
34
+ { id: 'p8', name: '文件柜', price: 1099, category: '办公家具' },
35
+ { id: 'p9', name: '书架', price: 799, category: '办公家具' },
36
+ { id: 'p10', name: '打印机', price: 1599, category: '办公设备' }
37
+ ];
38
+
39
+ // 模拟城市数据
40
+ const mockCities = [
41
+ { id: 'c1', name: '北京', code: 'BJ', population: 21893095 },
42
+ { id: 'c2', name: '上海', code: 'SH', population: 24870895 },
43
+ { id: 'c3', name: '广州', code: 'GZ', population: 18676605 },
44
+ { id: 'c4', name: '深圳', code: 'SZ', population: 17494398 },
45
+ { id: 'c5', name: '成都', code: 'CD', population: 16580376 },
46
+ { id: 'c6', name: '杭州', code: 'HZ', population: 10360391 },
47
+ { id: 'c7', name: '武汉', code: 'WH', population: 12326500 },
48
+ { id: 'c8', name: '西安', code: 'XA', population: 12952907 },
49
+ { id: 'c9', name: '重庆', code: 'CQ', population: 31243200 },
50
+ { id: 'c10', name: '南京', code: 'NJ', population: 8335000 }
51
+ ];
52
+
53
+ // 数据映射
54
+ const dataMap = {
55
+ mockUserList: mockUsers.map(user => ({
56
+ id: user.id,
57
+ name: user.name,
58
+ label: `${user.name} (${user.department})`,
59
+ value: user.id
60
+ })),
61
+ mockProductList: mockProducts.map(product => ({
62
+ id: product.id,
63
+ name: product.name,
64
+ label: `${product.name} - ¥${product.price}`,
65
+ value: product.id
66
+ })),
67
+ mockCityList: mockCities.map(city => ({
68
+ id: city.id,
69
+ name: city.name,
70
+ label: city.name,
71
+ value: city.id
72
+ }))
73
+ };
74
+
75
+ /**
76
+ * 模拟数据获取函数
77
+ * @param {Object} params - 请求参数
78
+ * @param {Object} apiConfig - API配置
79
+ * @returns {Promise<Object>} 响应数据
80
+ */
81
+ const mockFetch = (params, apiConfig) => {
82
+ return new Promise((resolve) => {
83
+ console.log('Mock fetch params:', params);
84
+ console.log('Mock fetch apiConfig:', apiConfig);
85
+
86
+ // 模拟网络延迟
87
+ setTimeout(() => {
88
+ let result = [];
89
+ const { apiId } = apiConfig;
90
+ const keyword = params?.queryParams?.keyword || '';
91
+
92
+ // 根据API ID获取对应的数据
93
+ if (dataMap[apiId]) {
94
+ result = dataMap[apiId];
95
+
96
+ // 如果有关键字,进行筛选
97
+ if (keyword) {
98
+ result = result.filter(item =>
99
+ item.label.toLowerCase().includes(keyword.toLowerCase()) ||
100
+ item.name.toLowerCase().includes(keyword.toLowerCase())
101
+ );
102
+ }
103
+ }
104
+
105
+ resolve({
106
+ code: 0,
107
+ data: result,
108
+ message: 'success'
109
+ });
110
+ }, 500); // 模拟 500ms 延迟
111
+ });
112
+ };
113
+
114
+ export default {
115
+ fetch: mockFetch
116
+ };
@@ -4,11 +4,10 @@
4
4
  * 所有接口均使用POST方法提交
5
5
  */
6
6
 
7
- import axios from "axios";
8
- import { TinyNotify } from "@opentiny/vue";
9
-
7
+ import axios from 'axios'
8
+ import { TinyNotify } from '@opentiny/vue'
10
9
  // 从环境变量获取API基础URL
11
- const API_BASE_URL = "http://localhost:8090/api";
10
+ const API_BASE_URL = 'http://' + window.location.host + '/api'
12
11
 
13
12
  /**
14
13
  * 创建axios实例
@@ -17,10 +16,10 @@ const axiosInstance = axios.create({
17
16
  baseURL: API_BASE_URL,
18
17
  timeout: 30000,
19
18
  headers: {
20
- "Content-Type": "application/json",
21
- Accept: "application/json",
22
- },
23
- });
19
+ 'Content-Type': 'application/json',
20
+ Accept: 'application/json'
21
+ }
22
+ })
24
23
 
25
24
  /**
26
25
  * 请求拦截器
@@ -28,110 +27,120 @@ const axiosInstance = axios.create({
28
27
  axiosInstance.interceptors.request.use(
29
28
  (config) => {
30
29
  // 添加认证信息
31
- const token = localStorage.getItem("token");
30
+ const token = localStorage.getItem('token')
32
31
  if (token) {
33
- config.headers["Authorization"] = `Bearer ${token}`;
32
+ config.headers['AppDataAuthorization'] = `Bearer ${token}`
33
+ }
34
+
35
+ // 如果是FormData格式,不设置Content-Type,让浏览器自动设置
36
+ if (config.data instanceof FormData) {
37
+ config.headers['Content-Type'] = undefined
34
38
  }
35
- return config;
39
+
40
+ return config
36
41
  },
37
42
  (error) => {
38
- return Promise.reject(error);
43
+ return Promise.reject(error)
39
44
  }
40
- );
45
+ )
41
46
 
42
47
  /**
43
48
  * 响应拦截器
44
49
  */
45
50
  axiosInstance.interceptors.response.use(
46
51
  (response) => {
47
- const { data } = response;
52
+ const { data } = response
48
53
 
49
54
  // 根据后端API的响应格式进行调整
50
55
  if (data.code === 0) {
51
- return data.data;
56
+ return data.data
52
57
  } else {
53
58
  // message.error(data.message || '请求失败');
54
- return Promise.reject(new Error(data.message || "请求失败"));
59
+ return Promise.reject({
60
+ code: data.code,
61
+ message: data.message || data.msg || '请求失败'
62
+ })
55
63
  }
56
64
  },
57
65
  (error) => {
58
66
  // 错误处理
59
67
  if (error.response) {
60
- const { status } = error.response;
68
+ const { status } = error.response
61
69
 
62
70
  switch (status) {
63
71
  case 401:
64
72
  TinyNotify({
65
- type: "warning",
66
- title: "未授权",
67
- message: "您无权限访问,请授权后重试",
68
- position: "top-right",
69
- duration: 2000,
70
- });
71
- break;
73
+ type: 'warning',
74
+ title: '未授权',
75
+ message: '您无权限访问,请授权后重试',
76
+ position: 'top-right',
77
+ duration: 2000
78
+ })
79
+ break
72
80
  case 403:
73
81
  TinyNotify({
74
- type: "warning",
75
- title: "权限不足",
76
- message: "禁止访问,权限不足",
77
- position: "top-right",
78
- duration: 2000,
79
- });
80
- break;
82
+ type: 'warning',
83
+ title: '权限不足',
84
+ message: '禁止访问,权限不足',
85
+ position: 'top-right',
86
+ duration: 2000
87
+ })
88
+ break
81
89
  case 404:
82
90
  TinyNotify({
83
- type: "warning",
84
- title: "404",
85
- message: "请求的资源不存在",
86
- position: "top-right",
87
- duration: 2000,
88
- });
89
- break;
91
+ type: 'warning',
92
+ title: '404',
93
+ message: '请求的资源不存在',
94
+ position: 'top-right',
95
+ duration: 2000
96
+ })
97
+ break
90
98
  case 500:
91
99
  TinyNotify({
92
- type: "warning",
93
- title: "错误",
94
- message: "服务器内部错误",
95
- position: "top-right",
96
- duration: 2000,
97
- });
98
- break;
100
+ type: 'warning',
101
+ title: '错误',
102
+ message: '服务器内部错误',
103
+ position: 'top-right',
104
+ duration: 2000
105
+ })
106
+ break
99
107
  default:
100
108
  TinyNotify({
101
- type: "warning",
102
- title: "请求失败",
109
+ type: 'warning',
110
+ title: '请求失败',
103
111
  message: error.message,
104
- position: "top-right",
105
- duration: 2000,
106
- });
112
+ position: 'top-right',
113
+ duration: 2000
114
+ })
107
115
  }
108
116
  } else {
109
117
  TinyNotify({
110
- type: "error",
111
- title: "网络错误",
118
+ type: 'error',
119
+ title: '网络错误',
112
120
  message: error.message,
113
- position: "top-right",
114
- duration: 2000,
115
- });
121
+ position: 'top-right',
122
+ duration: 2000
123
+ })
116
124
  // message.error('网络错误,请检查您的网络连接');
117
125
  }
118
126
 
119
- return Promise.reject(error);
127
+ return Promise.reject(error)
120
128
  }
121
- );
129
+ )
122
130
 
123
131
  let apiMap = {
124
- MULTIPLE_DATA_SEARCH: "/appdata/select",
125
- DETAILS_DATA: "/appdata/detailData",
126
- INTERFACE_PLUGIN: "/appdata/plugin",
127
- DATA_INSERT: "/appdata/addData",
128
- BATCH_DATA_INSERT: "/appdata/addDatas",
129
- DATA_MODIFY: "/appdata/updateData",
130
- BATCH_DATA_MODIFY: "/appdata/updateDatas",
131
- DEL_DATA: "/appdata/delData",
132
- BATCH_DEL_DATA: "/appdata/delDatas",
133
- MULTIPLE_DATA_LINK_SEARCH: "/api/appdata/link/select",
134
- };
132
+ MULTIPLE_DATA_SEARCH: '/appdata/select',
133
+ DETAILS_DATA: '/appdata/detailData',
134
+ INTERFACE_PLUGIN: '/appdata/plugin',
135
+ DATA_INSERT: '/appdata/addData',
136
+ BATCH_DATA_INSERT: '/appdata/addDatas',
137
+ DATA_MODIFY: '/appdata/updateData',
138
+ BATCH_DATA_MODIFY: '/appdata/updateDatas',
139
+ DEL_DATA: '/appdata/delData',
140
+ BATCH_DEL_DATA: '/appdata/delDatas',
141
+ MULTIPLE_DATA_LINK_SEARCH: '/api/appdata/link/select',
142
+ FILE_UPLOAD: '/api/file/upload' // 文件上传API
143
+ }
135
144
 
136
145
  /**
137
146
  * 数据服务
@@ -147,28 +156,125 @@ const dataService = {
147
156
  * @returns {Promise<any>} 响应数据
148
157
  * @example
149
158
  */
150
- fetch: (params = {}, apiConfig = {}, url = "") => {
159
+ fetch: (params = {}, apiConfig = {}, url = '') => {
151
160
  if (!url) {
152
- url = apiMap[apiConfig.apiType];
161
+ url = apiMap[apiConfig.apiType]
153
162
  }
154
163
 
155
- const { apiId = "", ...restConfig } = apiConfig;
164
+ const { apiId = '', ...restConfig } = apiConfig
156
165
 
157
166
  const defaultConfig = {
158
167
  // 默认列表查询配置
159
168
  headers: {
160
- "X-List-Query": "true",
169
+ 'X-List-Query': 'true'
161
170
  },
162
- timeout: 20000,
163
- };
171
+ timeout: 20000
172
+ }
164
173
  if (!params) {
165
- params = {};
174
+ params = {}
175
+ }
176
+ params.apiId = apiConfig.apiId
177
+ if (apiConfig.key) {
178
+ params.apiKey = apiConfig.key
166
179
  }
167
- params.apiId = apiConfig.apiId;
168
180
 
169
- const config = { ...defaultConfig, ...restConfig };
170
- return axiosInstance.post(url, params, config);
181
+ const config = { ...defaultConfig, ...restConfig }
182
+ return axiosInstance.post(url, params, config)
171
183
  },
172
- };
173
184
 
174
- export default dataService;
185
+ /**
186
+ * 文件上传
187
+ * @param {string} url - 上传URL,默认使用apiMap中的FILE_UPLOAD
188
+ * @param {FormData} formData - 包含文件和其他数据的FormData
189
+ * @param {Function} onProgress - 上传进度回调函数,参数为0-100的进度百分比
190
+ * @returns {Promise<any>} 上传响应数据
191
+ */
192
+ upload: (url = '', formData, onProgress = () => {}) => {
193
+ // 如果没有指定URL,使用默认的文件上传URL
194
+ if (!url) {
195
+ url = apiMap.FILE_UPLOAD
196
+ }
197
+
198
+ // 确保FormData中的文件字段名是'file'
199
+ let fixedFormData = new FormData()
200
+ let fileFound = false
201
+
202
+ // 检查并修复FormData
203
+ if (formData instanceof FormData) {
204
+ // 由于FormData不能直接检查内容,我们使用迭代器
205
+ try {
206
+ // 在某些旧浏览器中可能不支持entries()
207
+ if (typeof formData.entries === 'function') {
208
+ for (let pair of formData.entries()) {
209
+ const [key, value] = pair
210
+
211
+ if (value instanceof File || value instanceof Blob) {
212
+ // 找到文件,使用正确的字段名
213
+ console.log(`Found file in field ${key}, adding as 'file'`)
214
+ fixedFormData.append('file', value)
215
+ fileFound = true
216
+ } else {
217
+ // 保留其他字段
218
+ fixedFormData.append(key, value)
219
+ }
220
+ }
221
+ } else {
222
+ // 如果不支持entries(),假设formData已经是正确的,直接使用
223
+ console.log('FormData.entries() not supported, using original FormData')
224
+ fixedFormData = formData
225
+ fileFound = true
226
+ }
227
+ } catch (e) {
228
+ console.error('Error processing FormData:', e)
229
+ // 出错时使用原始FormData
230
+ fixedFormData = formData
231
+ }
232
+ } else {
233
+ console.error('Invalid FormData:', formData)
234
+ return Promise.reject(new Error('FormData is required for file upload'))
235
+ }
236
+
237
+ // 如果没有找到文件,返回错误
238
+ if (!fileFound && typeof formData.entries === 'function') {
239
+ console.error('No file found in FormData')
240
+ return Promise.reject(new Error('No file found in FormData'))
241
+ }
242
+
243
+ // 上传配置
244
+ const config = {
245
+ timeout: 60000, // 上传超时时间加长
246
+ headers: {
247
+ // 让浏览器自动设置Content-Type和boundary
248
+ 'Content-Type': undefined
249
+ },
250
+ onUploadProgress: (progressEvent) => {
251
+ // 计算上传进度百分比
252
+ const percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total)
253
+ onProgress(percentCompleted)
254
+ }
255
+ }
256
+
257
+ // 发起上传请求
258
+ console.log('Sending file upload request to:', url)
259
+ return axiosInstance.post(url, fixedFormData, config).then((response) => {
260
+ console.log('Upload server response:', response)
261
+
262
+ // 处理文件路径
263
+ // 如果返回的是相对路径,转换为完整URL
264
+ if (typeof response === 'string' && !response.startsWith('http')) {
265
+ // 判断路径是否以斜杠开头
266
+ const baseUrl = API_BASE_URL.endsWith('/') ? API_BASE_URL.slice(0, -1) : API_BASE_URL
267
+ const filePath = response.startsWith('/') ? response : `/${response}`
268
+
269
+ // 构建完整URL
270
+ const fullUrl = `${baseUrl}/files${filePath}`
271
+ console.log('Converted file path to full URL:', fullUrl)
272
+ return fullUrl
273
+ }
274
+
275
+ return response
276
+ })
277
+ }
278
+ }
279
+
280
+ export default dataService
@@ -1,10 +1,8 @@
1
1
  <template>
2
2
  <tiny-tooltip :content="!isNormal && !apiConfig.apiId ? tooltipText : ''" placement="top">
3
-
4
- <tiny-button :disabled="disabled" :type="type" :size="size" @click="click">
3
+ <t-button :disabled="disabled || loading" :theme="type" :size="size" @click="click">
5
4
  <slot>{{ text }}</slot>
6
- </tiny-button>
7
-
5
+ </t-button>
8
6
  </tiny-tooltip>
9
7
  </template>
10
8
 
@@ -18,10 +16,10 @@ export default {
18
16
  <script lang='js' setup>
19
17
 
20
18
  import { ref, reactive, computed, toRef, toRefs } from 'vue';
21
- import { TinyButton, TinyTooltip, TinyNotify } from '@opentiny/vue';
19
+ import { Button as TButton } from 'tdesign-vue-next';
20
+ import { TinyTooltip } from '@opentiny/vue';
22
21
  import dataService from '../apiService/simpleDataService';
23
22
 
24
-
25
23
  const props = defineProps({
26
24
  text: {
27
25
  type: String,
@@ -35,24 +33,25 @@ const props = defineProps({
35
33
  type: Boolean,
36
34
  default: false
37
35
  },
38
- type: {//'default' | 'primary' | 'success' | 'warning' | 'danger' | 'info' | 'text'
36
+ type: {//'default' | 'primary' | 'success' | 'warning' | 'danger' | 'info'
39
37
  type: String,
40
- default: 'default'
38
+ default: 'primary'
41
39
  },
42
- size: {//'large' | 'medium' | 'small' | 'mini'
40
+ size: {//'large' | 'medium' | 'small'
43
41
  type: String,
44
42
  default: 'medium'
45
43
  },
46
44
  apiConfig: {//接口配置
47
45
  type: Object,
48
- default: {
46
+ default: () => ({
47
+ key: null,
49
48
  apiId: null,
50
49
  apiType: ''
51
- }
50
+ })
52
51
  },
53
52
  data: {
54
53
  type: Object,
55
- default: {}
54
+ default: () => ({})
56
55
  },
57
56
  onClick: {
58
57
  type: Function,
@@ -60,11 +59,15 @@ const props = defineProps({
60
59
  },
61
60
  onPrepare: {//调用接口前置事件
62
61
  type: Function,
63
- default: () => { }
62
+ default: () => true // 默认返回true,允许继续执行
64
63
  },
65
64
  onFinish: {//调用接口后置事件
66
65
  type: Function,
67
66
  default: () => { }
67
+ },
68
+ onError: {
69
+ type: Function,
70
+ default: () => { }
68
71
  }
69
72
  })
70
73
 
@@ -81,23 +84,70 @@ const apiMap = [
81
84
  'MULTIPLE_DATA_LINK_SEARCH'
82
85
  ];
83
86
 
84
- const emit = defineEmits(['click'])
87
+ const emit = defineEmits(['click', 'success', 'error', 'loading', 'prepare'])
85
88
 
86
- const { text, isNormal, disabled, type, size, apiConfig, data, isUseMethod } = toRefs(props)
89
+ const { text, isNormal, disabled, type, size, variant, apiConfig, data } = toRefs(props)
87
90
 
88
91
  const tooltipText = ref('请先设置接口配置')
92
+ const loading = ref(false)
93
+
94
+ // 检查API配置是否有效
95
+ const isValidApiConfig = () => {
96
+ return apiConfig.value && apiConfig.value.apiId &&
97
+ typeof apiConfig.value.apiType === 'number' &&
98
+ apiConfig.value.apiType >= 0 &&
99
+ apiConfig.value.apiType < apiMap.length;
100
+ }
89
101
 
90
- const click = () => {
102
+ const click = async (e) => {
103
+ // 总是调用onClick回调
91
104
  props.onClick()
92
- if (!isNormal.value && apiConfig.value.apiId) {
93
- props.onPrepare()
94
- dataService.fetch(data.value, { apiId: apiConfig.value.apiId, apiType: apiMap[apiConfig.value.apiType] }).then((res) => {
95
- emit('click', res)
96
- props.onFinish()
105
+ emit('click', e)
106
+
107
+ // 如果是普通按钮或API配置无效,不调用接口
108
+ if (isNormal.value || !isValidApiConfig()) {
109
+ return
110
+ }
111
+
112
+ try {
113
+ // 设置加载状态
114
+ loading.value = true
115
+ emit('loading', true)
116
+
117
+ // 调用前置处理并获取返回值
118
+ const shouldContinue = props.onPrepare()
119
+ emit('prepare', shouldContinue)
120
+
121
+ // 只有当返回值明确为false时才中断,undefined或其他值都继续执行
122
+ if (shouldContinue === false) {
123
+ return null
124
+ }
125
+
126
+ // 调用接口
127
+ const apiType = apiMap[apiConfig.value.apiType]
128
+ const res = await dataService.fetch(data.value, {
129
+ key: apiConfig.value.key,
130
+ apiId: apiConfig.value.apiId,
131
+ apiType
97
132
  })
133
+
134
+ // 成功处理
135
+ emit('success', res)
136
+ props.onFinish(res)
137
+
138
+ return res
139
+ } catch (error) {
140
+ // 错误处理
141
+ emit('error', error)
142
+ props.onError(error)
143
+
144
+ return null
145
+ } finally {
146
+ // 清除加载状态
147
+ loading.value = false
148
+ emit('loading', false)
98
149
  }
99
150
  }
100
-
101
151
  </script>
102
152
 
103
153
  <style lang='less' scoped></style>