@ebiz/designer-components 0.0.18-beta.3 → 0.0.18-beta.30

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ebiz/designer-components",
3
- "version": "0.0.18-beta.3",
3
+ "version": "0.0.18-beta.30",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -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,11 @@
4
4
  * 所有接口均使用POST方法提交
5
5
  */
6
6
 
7
- import axios from "axios";
8
- import { TinyNotify } from "@opentiny/vue";
7
+ import axios from 'axios'
8
+ import { TinyNotify } from '@opentiny/vue'
9
9
 
10
10
  // 从环境变量获取API基础URL
11
- const API_BASE_URL = "http://localhost:8090/api";
11
+ const API_BASE_URL = 'http://' + window.location.host + '/api'
12
12
 
13
13
  /**
14
14
  * 创建axios实例
@@ -17,10 +17,10 @@ const axiosInstance = axios.create({
17
17
  baseURL: API_BASE_URL,
18
18
  timeout: 30000,
19
19
  headers: {
20
- "Content-Type": "application/json",
21
- Accept: "application/json",
22
- },
23
- });
20
+ 'Content-Type': 'application/json',
21
+ Accept: 'application/json'
22
+ }
23
+ })
24
24
 
25
25
  /**
26
26
  * 请求拦截器
@@ -28,117 +28,120 @@ const axiosInstance = axios.create({
28
28
  axiosInstance.interceptors.request.use(
29
29
  (config) => {
30
30
  // 添加认证信息
31
- const token = localStorage.getItem("token");
31
+ const token = localStorage.getItem('token')
32
32
  if (token) {
33
- config.headers["Authorization"] = `Bearer ${token}`;
33
+ config.headers['AppDataAuthorization'] = `Bearer ${token}`
34
34
  }
35
-
35
+
36
36
  // 如果是FormData格式,不设置Content-Type,让浏览器自动设置
37
37
  if (config.data instanceof FormData) {
38
- config.headers["Content-Type"] = undefined;
38
+ config.headers['Content-Type'] = undefined
39
39
  }
40
-
41
- return config;
40
+
41
+ return config
42
42
  },
43
43
  (error) => {
44
- return Promise.reject(error);
44
+ return Promise.reject(error)
45
45
  }
46
- );
46
+ )
47
47
 
48
48
  /**
49
49
  * 响应拦截器
50
50
  */
51
51
  axiosInstance.interceptors.response.use(
52
52
  (response) => {
53
- const { data } = response;
53
+ const { data } = response
54
54
 
55
55
  // 根据后端API的响应格式进行调整
56
56
  if (data.code === 0) {
57
- return data.data;
57
+ return data.data
58
58
  } else {
59
59
  // message.error(data.message || '请求失败');
60
- return Promise.reject(new Error(data.message || data.msg || "请求失败"));
60
+ return Promise.reject({
61
+ code: data.code,
62
+ message: data.message || data.msg || '请求失败'
63
+ })
61
64
  }
62
65
  },
63
66
  (error) => {
64
67
  // 错误处理
65
68
  if (error.response) {
66
- const { status } = error.response;
69
+ const { status } = error.response
67
70
 
68
71
  switch (status) {
69
72
  case 401:
70
73
  TinyNotify({
71
- type: "warning",
72
- title: "未授权",
73
- message: "您无权限访问,请授权后重试",
74
- position: "top-right",
75
- duration: 2000,
76
- });
77
- break;
74
+ type: 'warning',
75
+ title: '未授权',
76
+ message: '您无权限访问,请授权后重试',
77
+ position: 'top-right',
78
+ duration: 2000
79
+ })
80
+ break
78
81
  case 403:
79
82
  TinyNotify({
80
- type: "warning",
81
- title: "权限不足",
82
- message: "禁止访问,权限不足",
83
- position: "top-right",
84
- duration: 2000,
85
- });
86
- break;
83
+ type: 'warning',
84
+ title: '权限不足',
85
+ message: '禁止访问,权限不足',
86
+ position: 'top-right',
87
+ duration: 2000
88
+ })
89
+ break
87
90
  case 404:
88
91
  TinyNotify({
89
- type: "warning",
90
- title: "404",
91
- message: "请求的资源不存在",
92
- position: "top-right",
93
- duration: 2000,
94
- });
95
- break;
92
+ type: 'warning',
93
+ title: '404',
94
+ message: '请求的资源不存在',
95
+ position: 'top-right',
96
+ duration: 2000
97
+ })
98
+ break
96
99
  case 500:
97
100
  TinyNotify({
98
- type: "warning",
99
- title: "错误",
100
- message: "服务器内部错误",
101
- position: "top-right",
102
- duration: 2000,
103
- });
104
- break;
101
+ type: 'warning',
102
+ title: '错误',
103
+ message: '服务器内部错误',
104
+ position: 'top-right',
105
+ duration: 2000
106
+ })
107
+ break
105
108
  default:
106
109
  TinyNotify({
107
- type: "warning",
108
- title: "请求失败",
110
+ type: 'warning',
111
+ title: '请求失败',
109
112
  message: error.message,
110
- position: "top-right",
111
- duration: 2000,
112
- });
113
+ position: 'top-right',
114
+ duration: 2000
115
+ })
113
116
  }
114
117
  } else {
115
118
  TinyNotify({
116
- type: "error",
117
- title: "网络错误",
119
+ type: 'error',
120
+ title: '网络错误',
118
121
  message: error.message,
119
- position: "top-right",
120
- duration: 2000,
121
- });
122
+ position: 'top-right',
123
+ duration: 2000
124
+ })
122
125
  // message.error('网络错误,请检查您的网络连接');
123
126
  }
124
127
 
125
- return Promise.reject(error);
128
+ return Promise.reject(error)
126
129
  }
127
- );
130
+ )
128
131
 
129
132
  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
- };
133
+ MULTIPLE_DATA_SEARCH: '/appdata/select',
134
+ DETAILS_DATA: '/appdata/detailData',
135
+ INTERFACE_PLUGIN: '/appdata/plugin',
136
+ DATA_INSERT: '/appdata/addData',
137
+ BATCH_DATA_INSERT: '/appdata/addDatas',
138
+ DATA_MODIFY: '/appdata/updateData',
139
+ BATCH_DATA_MODIFY: '/appdata/updateDatas',
140
+ DEL_DATA: '/appdata/delData',
141
+ BATCH_DEL_DATA: '/appdata/delDatas',
142
+ MULTIPLE_DATA_LINK_SEARCH: '/api/appdata/link/select',
143
+ FILE_UPLOAD: '/api/file/upload' // 文件上传API
144
+ }
142
145
 
143
146
  /**
144
147
  * 数据服务
@@ -154,29 +157,32 @@ const dataService = {
154
157
  * @returns {Promise<any>} 响应数据
155
158
  * @example
156
159
  */
157
- fetch: (params = {}, apiConfig = {}, url = "") => {
160
+ fetch: (params = {}, apiConfig = {}, url = '') => {
158
161
  if (!url) {
159
- url = apiMap[apiConfig.apiType];
162
+ url = apiMap[apiConfig.apiType]
160
163
  }
161
164
 
162
- const { apiId = "", ...restConfig } = apiConfig;
165
+ const { apiId = '', ...restConfig } = apiConfig
163
166
 
164
167
  const defaultConfig = {
165
168
  // 默认列表查询配置
166
169
  headers: {
167
- "X-List-Query": "true",
170
+ 'X-List-Query': 'true'
168
171
  },
169
- timeout: 20000,
170
- };
172
+ timeout: 20000
173
+ }
171
174
  if (!params) {
172
- params = {};
175
+ params = {}
176
+ }
177
+ params.apiId = apiConfig.apiId
178
+ if (apiConfig.key) {
179
+ params.apiKey = apiConfig.key
173
180
  }
174
- params.apiId = apiConfig.apiId;
175
181
 
176
- const config = { ...defaultConfig, ...restConfig };
177
- return axiosInstance.post(url, params, config);
182
+ const config = { ...defaultConfig, ...restConfig }
183
+ return axiosInstance.post(url, params, config)
178
184
  },
179
-
185
+
180
186
  /**
181
187
  * 文件上传
182
188
  * @param {string} url - 上传URL,默认使用apiMap中的FILE_UPLOAD
@@ -184,16 +190,16 @@ const dataService = {
184
190
  * @param {Function} onProgress - 上传进度回调函数,参数为0-100的进度百分比
185
191
  * @returns {Promise<any>} 上传响应数据
186
192
  */
187
- upload: (url = "", formData, onProgress = () => {}) => {
193
+ upload: (url = '', formData, onProgress = () => {}) => {
188
194
  // 如果没有指定URL,使用默认的文件上传URL
189
195
  if (!url) {
190
- url = apiMap.FILE_UPLOAD;
196
+ url = apiMap.FILE_UPLOAD
191
197
  }
192
-
198
+
193
199
  // 确保FormData中的文件字段名是'file'
194
- const fixedFormData = new FormData();
195
- let fileFound = false;
196
-
200
+ let fixedFormData = new FormData()
201
+ let fileFound = false
202
+
197
203
  // 检查并修复FormData
198
204
  if (formData instanceof FormData) {
199
205
  // 由于FormData不能直接检查内容,我们使用迭代器
@@ -201,40 +207,40 @@ const dataService = {
201
207
  // 在某些旧浏览器中可能不支持entries()
202
208
  if (typeof formData.entries === 'function') {
203
209
  for (let pair of formData.entries()) {
204
- const [key, value] = pair;
205
-
210
+ const [key, value] = pair
211
+
206
212
  if (value instanceof File || value instanceof Blob) {
207
213
  // 找到文件,使用正确的字段名
208
- console.log(`Found file in field ${key}, adding as 'file'`);
209
- fixedFormData.append('file', value);
210
- fileFound = true;
214
+ console.log(`Found file in field ${key}, adding as 'file'`)
215
+ fixedFormData.append('file', value)
216
+ fileFound = true
211
217
  } else {
212
218
  // 保留其他字段
213
- fixedFormData.append(key, value);
219
+ fixedFormData.append(key, value)
214
220
  }
215
221
  }
216
222
  } else {
217
223
  // 如果不支持entries(),假设formData已经是正确的,直接使用
218
- console.log('FormData.entries() not supported, using original FormData');
219
- fixedFormData = formData;
220
- fileFound = true;
224
+ console.log('FormData.entries() not supported, using original FormData')
225
+ fixedFormData = formData
226
+ fileFound = true
221
227
  }
222
228
  } catch (e) {
223
- console.error('Error processing FormData:', e);
229
+ console.error('Error processing FormData:', e)
224
230
  // 出错时使用原始FormData
225
- fixedFormData = formData;
231
+ fixedFormData = formData
226
232
  }
227
233
  } else {
228
- console.error('Invalid FormData:', formData);
229
- return Promise.reject(new Error('FormData is required for file upload'));
234
+ console.error('Invalid FormData:', formData)
235
+ return Promise.reject(new Error('FormData is required for file upload'))
230
236
  }
231
-
237
+
232
238
  // 如果没有找到文件,返回错误
233
239
  if (!fileFound && typeof formData.entries === 'function') {
234
- console.error('No file found in FormData');
235
- return Promise.reject(new Error('No file found in FormData'));
240
+ console.error('No file found in FormData')
241
+ return Promise.reject(new Error('No file found in FormData'))
236
242
  }
237
-
243
+
238
244
  // 上传配置
239
245
  const config = {
240
246
  timeout: 60000, // 上传超时时间加长
@@ -244,33 +250,32 @@ const dataService = {
244
250
  },
245
251
  onUploadProgress: (progressEvent) => {
246
252
  // 计算上传进度百分比
247
- const percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total);
248
- onProgress(percentCompleted);
253
+ const percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total)
254
+ onProgress(percentCompleted)
249
255
  }
250
- };
251
-
256
+ }
257
+
252
258
  // 发起上传请求
253
- console.log('Sending file upload request to:', url);
254
- return axiosInstance.post(url, fixedFormData, config)
255
- .then(response => {
256
- console.log('Upload server response:', response);
257
-
258
- // 处理文件路径
259
- // 如果返回的是相对路径,转换为完整URL
260
- if (typeof response === 'string' && !response.startsWith('http')) {
261
- // 判断路径是否以斜杠开头
262
- const baseUrl = API_BASE_URL.endsWith('/') ? API_BASE_URL.slice(0, -1) : API_BASE_URL;
263
- const filePath = response.startsWith('/') ? response : `/${response}`;
264
-
265
- // 构建完整URL
266
- const fullUrl = `${baseUrl}/files${filePath}`;
267
- console.log('Converted file path to full URL:', fullUrl);
268
- return fullUrl;
269
- }
270
-
271
- return response;
272
- });
259
+ console.log('Sending file upload request to:', url)
260
+ return axiosInstance.post(url, fixedFormData, config).then((response) => {
261
+ console.log('Upload server response:', response)
262
+
263
+ // 处理文件路径
264
+ // 如果返回的是相对路径,转换为完整URL
265
+ if (typeof response === 'string' && !response.startsWith('http')) {
266
+ // 判断路径是否以斜杠开头
267
+ const baseUrl = API_BASE_URL.endsWith('/') ? API_BASE_URL.slice(0, -1) : API_BASE_URL
268
+ const filePath = response.startsWith('/') ? response : `/${response}`
269
+
270
+ // 构建完整URL
271
+ const fullUrl = `${baseUrl}/files${filePath}`
272
+ console.log('Converted file path to full URL:', fullUrl)
273
+ return fullUrl
274
+ }
275
+
276
+ return response
277
+ })
273
278
  }
274
- };
279
+ }
275
280
 
276
- export default dataService;
281
+ export default dataService
@@ -46,6 +46,7 @@ const props = defineProps({
46
46
  apiConfig: {//接口配置
47
47
  type: Object,
48
48
  default: {
49
+ key: null,
49
50
  apiId: null,
50
51
  apiType: ''
51
52
  }
@@ -91,7 +92,7 @@ const click = () => {
91
92
  props.onClick()
92
93
  if (!isNormal.value && apiConfig.value.apiId) {
93
94
  props.onPrepare()
94
- dataService.fetch(data.value, { apiId: apiConfig.value.apiId, apiType: apiMap[apiConfig.value.apiType] }).then((res) => {
95
+ dataService.fetch(data.value, { key: apiConfig.value.key, apiId: apiConfig.value.apiId, apiType: apiMap[apiConfig.value.apiType] }).then((res) => {
95
96
  emit('click', res)
96
97
  props.onFinish()
97
98
  })
@@ -0,0 +1,82 @@
1
+ <template>
2
+ <div class="ebiz-detail-block">
3
+ <t-row v-for="(item, index) in detailItems" :key="index" class="detail-item">
4
+ <t-col :span="6" class="label" :style="labelStyle">{{ item.label }}</t-col>
5
+ <t-col :span="18" class="value" :style="valueStyle">{{ item.value }}</t-col>
6
+ </t-row>
7
+ </div>
8
+ </template>
9
+
10
+ <script lang="js" setup>
11
+ import { computed, toRefs } from 'vue'
12
+ import { Row as TRow, Col as TCol } from 'tdesign-vue-next'
13
+
14
+ const props = defineProps({
15
+ model: {
16
+ type: Object,
17
+ default: () => { }
18
+ },
19
+ labelMap: {
20
+ type: Object,
21
+ default: () => { }
22
+ },
23
+ gap: {
24
+ type: [String, Number],
25
+ default: '0'
26
+ },
27
+ labelSize: {
28
+ type: [String, Number],
29
+ default: '14'
30
+ },
31
+ labelColor: {
32
+ type: String,
33
+ default: '#86909C'
34
+ },
35
+ valueSize: {
36
+ type: [String, Number],
37
+ default: '14'
38
+ },
39
+ valueColor: {
40
+ type: String,
41
+ default: '#0A0A0A'
42
+ }
43
+ })
44
+
45
+ const { model, labelMap, gap, labelSize, labelColor, valueSize, valueColor } = toRefs(props)
46
+
47
+ const labelStyle = computed(() => ({
48
+ fontSize: typeof labelSize.value === 'number' ? `${labelSize.value}px` : labelSize.value,
49
+ color: labelColor.value,
50
+ marginBottom: typeof gap.value === 'number' ? `${gap.value}px` : gap.value
51
+ }))
52
+
53
+ const valueStyle = computed(() => ({
54
+ fontSize: typeof valueSize.value === 'number' ? `${valueSize.value}px` : valueSize.value,
55
+ color: valueColor.value
56
+ }))
57
+
58
+ const detailItems = computed(() => {
59
+ return Object.entries(model.value).map(([key, value]) => ({
60
+ label: labelMap.value[key] || key,
61
+ value: value || '--'
62
+ }))
63
+ })
64
+ </script>
65
+
66
+ <style scoped>
67
+ .ebiz-detail-block {
68
+ padding: 16px;
69
+ }
70
+
71
+ .detail-item {
72
+ line-height: 32px;
73
+ }
74
+
75
+ .label {
76
+ width: 50%;
77
+ }
78
+
79
+ .value {
80
+ width: 50%;
81
+ }
82
+ </style>