@ebiz/designer-components 0.0.18-beta.6 → 0.0.18-beta.8
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 +1 -1
- package/src/apiService/mockDataService.js +116 -0
- package/src/apiService/simpleDataService.js +1 -1
- package/src/apiService/simpleDataServiceAppData.js +278 -0
- package/src/components/Button.vue +2 -2
- package/src/components/EbizRemoteSelect.vue +98 -41
- package/src/components/EbizTabHeader.vue +2 -2
- package/src/components/TdesignCalendar/index.vue +6 -3
- package/src/components/TdesignDialog.vue +249 -0
- package/src/components/TdesignUpload.vue +68 -99
- package/src/index.js +61 -56
- package/src/main.js +5 -3
- package/src/router/index.js +6 -0
- package/src/views/DialogDemo.vue +126 -0
- package/src/views/Home.vue +2 -1
- package/src/views/RemoteSelect.vue +336 -5
package/package.json
CHANGED
@@ -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
|
+
};
|
@@ -0,0 +1,278 @@
|
|
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
|
@@ -19,7 +19,7 @@ export default {
|
|
19
19
|
|
20
20
|
import { ref, reactive, computed, toRef, toRefs } from 'vue';
|
21
21
|
import { TinyButton, TinyTooltip, TinyNotify } from '@opentiny/vue';
|
22
|
-
import
|
22
|
+
import dataServiceAppData from '../apiService/simpleDataServiceAppData';
|
23
23
|
|
24
24
|
|
25
25
|
const props = defineProps({
|
@@ -92,7 +92,7 @@ const click = () => {
|
|
92
92
|
props.onClick()
|
93
93
|
if (!isNormal.value && apiConfig.value.apiId) {
|
94
94
|
props.onPrepare()
|
95
|
-
|
95
|
+
dataServiceAppData.fetch(data.value, { key: apiConfig.value.key, apiId: apiConfig.value.apiId, apiType: apiMap[apiConfig.value.apiType] }).then((res) => {
|
96
96
|
emit('click', res)
|
97
97
|
props.onFinish()
|
98
98
|
})
|
@@ -1,14 +1,15 @@
|
|
1
1
|
<template>
|
2
|
-
<
|
3
|
-
|
4
|
-
:disabled="disabled"
|
5
|
-
|
2
|
+
<t-select ref="selectRef" v-model="selectedValue" :options="options" :loading="loading" :filterable="true"
|
3
|
+
@search="handleRemoteSearch" :multiple="multiple" :placeholder="placeholder" :clearable="clearable"
|
4
|
+
:disabled="disabled" :size="size" :empty="emptyText" :popupProps="popupProps" @change="handleChange"
|
5
|
+
@focus="handleFocus" @blur="handleBlur">
|
6
|
+
<template #prefixIcon v-if="$slots.prefix">
|
6
7
|
<slot name="prefix"></slot>
|
7
8
|
</template>
|
8
|
-
<template #suffix>
|
9
|
+
<template #suffixIcon v-if="$slots.suffix">
|
9
10
|
<slot name="suffix"></slot>
|
10
11
|
</template>
|
11
|
-
</
|
12
|
+
</t-select>
|
12
13
|
</template>
|
13
14
|
|
14
15
|
<script>
|
@@ -19,8 +20,8 @@ export default {
|
|
19
20
|
|
20
21
|
<script setup>
|
21
22
|
import { ref, onMounted, toRefs, computed } from 'vue';
|
22
|
-
import { Select as
|
23
|
-
import
|
23
|
+
import { Select as TSelect } from 'tdesign-vue-next';
|
24
|
+
import dataServiceAppData from '../apiService/simpleDataServiceAppData';
|
24
25
|
|
25
26
|
const props = defineProps({
|
26
27
|
/**
|
@@ -40,7 +41,7 @@ const props = defineProps({
|
|
40
41
|
*/
|
41
42
|
queryParams: {
|
42
43
|
type: Object,
|
43
|
-
default: {}
|
44
|
+
default: () => ({})
|
44
45
|
},
|
45
46
|
/**
|
46
47
|
* 是否多选
|
@@ -74,21 +75,54 @@ const props = defineProps({
|
|
74
75
|
* 默认值
|
75
76
|
*/
|
76
77
|
modelValue: {
|
77
|
-
type: [String, Number],
|
78
|
+
type: [String, Number, Array],
|
78
79
|
default: ''
|
79
80
|
},
|
81
|
+
/**
|
82
|
+
* 选项配置
|
83
|
+
*/
|
80
84
|
optionsConfig: {
|
81
|
-
|
82
|
-
|
85
|
+
type: Object,
|
86
|
+
default: () => ({
|
87
|
+
labelField: '',
|
88
|
+
valueField: ''
|
89
|
+
})
|
90
|
+
},
|
91
|
+
/**
|
92
|
+
* 组件尺寸
|
93
|
+
*/
|
94
|
+
size: {
|
95
|
+
type: String,
|
96
|
+
default: 'medium',
|
97
|
+
validator: (val) => ['small', 'medium', 'large'].includes(val)
|
98
|
+
},
|
99
|
+
/**
|
100
|
+
* 空数据文本
|
101
|
+
*/
|
102
|
+
emptyText: {
|
103
|
+
type: String,
|
104
|
+
default: '暂无数据'
|
105
|
+
},
|
106
|
+
/**
|
107
|
+
* 弹出层配置
|
108
|
+
*/
|
109
|
+
popupProps: {
|
110
|
+
type: Object,
|
111
|
+
default: () => ({})
|
83
112
|
}
|
84
113
|
});
|
85
114
|
|
86
115
|
const { modelValue, apiConfig, queryParams } = toRefs(props)
|
87
116
|
|
88
|
-
const emit = defineEmits(['update:modelValue', 'change']);
|
117
|
+
const emit = defineEmits(['update:modelValue', 'change', 'focus', 'blur']);
|
89
118
|
|
90
119
|
// 选中的值
|
91
|
-
const selectedValue = computed(
|
120
|
+
const selectedValue = computed({
|
121
|
+
get: () => modelValue.value,
|
122
|
+
set: (val) => {
|
123
|
+
emit('update:modelValue', val);
|
124
|
+
}
|
125
|
+
});
|
92
126
|
|
93
127
|
// 选项列表
|
94
128
|
const options = ref([]);
|
@@ -105,37 +139,55 @@ const focus = () => {
|
|
105
139
|
};
|
106
140
|
|
107
141
|
defineExpose({
|
108
|
-
focus
|
142
|
+
focus,
|
143
|
+
selectRef
|
109
144
|
});
|
110
145
|
|
111
146
|
// 远程搜索处理函数
|
112
|
-
const handleRemoteSearch = async () => {
|
113
|
-
//if (options.value?.length > 0) return
|
114
|
-
|
147
|
+
const handleRemoteSearch = async (keyword) => {
|
115
148
|
loading.value = true;
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
149
|
+
console.log('handleRemoteSearch', keyword);
|
150
|
+
try {
|
151
|
+
const params = {
|
152
|
+
queryParams: {
|
153
|
+
...queryParams.value,
|
154
|
+
keyword
|
155
|
+
}
|
156
|
+
};
|
157
|
+
const res = await dataServiceAppData.fetch(params, props.apiConfig);
|
158
|
+
const { labelField, valueField } = props.optionsConfig;
|
159
|
+
|
160
|
+
options.value = res.data.map(item => ({
|
161
|
+
label: labelField ? item[labelField] : (item.label || item.name),
|
162
|
+
value: valueField ? item[valueField] : (item.value || item.id)
|
163
|
+
}));
|
164
|
+
} catch (error) {
|
165
|
+
console.error('远程搜索失败:', error);
|
166
|
+
options.value = [];
|
167
|
+
} finally {
|
168
|
+
loading.value = false;
|
169
|
+
}
|
170
|
+
|
171
|
+
};
|
172
|
+
|
173
|
+
// 处理获取焦点事件
|
174
|
+
const handleFocus = (value, context) => {
|
175
|
+
emit('focus', value, context);
|
176
|
+
// 当选项为空时,初始加载数据
|
177
|
+
if (options.value.length === 0) {
|
178
|
+
handleRemoteSearch('');
|
132
179
|
}
|
133
180
|
};
|
134
181
|
|
182
|
+
// 处理失去焦点事件
|
183
|
+
const handleBlur = (value, context) => {
|
184
|
+
emit('blur', value, context);
|
185
|
+
};
|
186
|
+
|
135
187
|
// 值变化处理函数
|
136
|
-
const handleChange = (value) => {
|
188
|
+
const handleChange = (value, context) => {
|
137
189
|
emit('update:modelValue', value);
|
138
|
-
emit('change', value);
|
190
|
+
emit('change', value, context);
|
139
191
|
};
|
140
192
|
|
141
193
|
// 组件挂载时,如果有默认值则加载对应的选项
|
@@ -146,10 +198,16 @@ onMounted(async () => {
|
|
146
198
|
const params = {
|
147
199
|
queryParams: queryParams.value
|
148
200
|
};
|
149
|
-
const res = await
|
201
|
+
const res = await dataServiceAppData.fetch(params, {
|
202
|
+
key: props.apiConfig.key,
|
203
|
+
apiId: props.apiConfig.apiId,
|
204
|
+
apiType: 'MULTIPLE_DATA_SEARCH'
|
205
|
+
});
|
206
|
+
const { labelField, valueField } = props.optionsConfig;
|
207
|
+
|
150
208
|
options.value = res.data.map(item => ({
|
151
|
-
label: item.label || item.name,
|
152
|
-
value: item.value || item.id
|
209
|
+
label: labelField ? item[labelField] : (item.label || item.name),
|
210
|
+
value: valueField ? item[valueField] : (item.value || item.id)
|
153
211
|
}));
|
154
212
|
} catch (error) {
|
155
213
|
console.error('加载默认选项失败:', error);
|
@@ -157,12 +215,11 @@ onMounted(async () => {
|
|
157
215
|
loading.value = false;
|
158
216
|
}
|
159
217
|
}
|
160
|
-
|
161
218
|
});
|
162
219
|
</script>
|
163
220
|
|
164
221
|
<style scoped>
|
165
|
-
.
|
222
|
+
.t-select {
|
166
223
|
width: 100%;
|
167
224
|
}
|
168
225
|
</style>
|
@@ -8,7 +8,7 @@
|
|
8
8
|
<script setup>
|
9
9
|
import { ref, computed, watch } from 'vue'
|
10
10
|
import { TinyTabs, TinyTabItem } from '@opentiny/vue'
|
11
|
-
import {
|
11
|
+
import { dataServiceAppData } from "../index.js"
|
12
12
|
|
13
13
|
const emit = defineEmits(['tabChange'])
|
14
14
|
|
@@ -83,7 +83,7 @@ watch(() => showTabs.value, () => {
|
|
83
83
|
|
84
84
|
watch(() => props.apiConfig, (nVal) => {
|
85
85
|
if (!nVal?.apiId) return
|
86
|
-
|
86
|
+
dataServiceAppData.fetch({}, { key: nVal.key, apiId: nVal.apiId, apiType: 'MULTIPLE_DATA_SEARCH' }).then(res => {
|
87
87
|
remoteTabs.value = (res.data ?? []).map(i => ({
|
88
88
|
label: i[props.labelKey],
|
89
89
|
value: i[props.valueKey],
|