|
|
@@ -88,23 +88,35 @@ watch(
|
|
|
(val) => {
|
|
|
if (val) {
|
|
|
try {
|
|
|
- const parsedValue = JSON.parse(val);
|
|
|
+ // 使用 JSON.parse 的 reviver 函数确保大数 ID 保持为字符串
|
|
|
+ const parsedValue = JSON.parse(val, (key, value) => {
|
|
|
+ // 如果键是 id,确保它作为字符串返回
|
|
|
+ if (key === 'id' && value !== null && value !== undefined) {
|
|
|
+ return String(value);
|
|
|
+ }
|
|
|
+ return value;
|
|
|
+ });
|
|
|
+
|
|
|
+ // 确保 id 是字符串
|
|
|
+ const id = parsedValue.id ? String(parsedValue.id) : '';
|
|
|
+
|
|
|
selectedGroup.value = {
|
|
|
- id: parsedValue.id,
|
|
|
- name: parsedValue.name,
|
|
|
- itemCount: parsedValue.itemCount,
|
|
|
- duration: parsedValue.duration,
|
|
|
- createTime: parsedValue.createTime,
|
|
|
- items: parsedValue.items
|
|
|
+ id: id,
|
|
|
+ name: String(parsedValue.name || ''),
|
|
|
+ itemCount: Number(parsedValue.itemCount) || 0,
|
|
|
+ duration: Number(parsedValue.duration) || 5,
|
|
|
+ createTime: String(parsedValue.createTime || ''),
|
|
|
+ items: Array.isArray(parsedValue.items) ? parsedValue.items : []
|
|
|
};
|
|
|
- } catch {
|
|
|
+ } catch (error) {
|
|
|
+ console.error('Error parsing modelValue:', error);
|
|
|
selectedGroup.value = null;
|
|
|
}
|
|
|
} else {
|
|
|
selectedGroup.value = null;
|
|
|
}
|
|
|
},
|
|
|
- { immediate: true }
|
|
|
+ { immediate: true, deep: true }
|
|
|
);
|
|
|
|
|
|
// 查询轮播组列表
|
|
|
@@ -121,17 +133,23 @@ const getCarouselList = async () => {
|
|
|
|
|
|
const res = await listItem(query);
|
|
|
|
|
|
- // 转换数据格式,并标记已选中的项
|
|
|
- carouselList.value = (res.rows || []).map((item: ItemVO) => ({
|
|
|
- id: item.id,
|
|
|
- name: item.itemName || '',
|
|
|
- itemName: item.itemName || '', // 保持与API返回的字段名一致
|
|
|
- itemCount: item.sourceNum || 0,
|
|
|
- duration: 5, // 默认5秒,可以根据实际需求调整
|
|
|
- createTime: item.createTime || '',
|
|
|
- selected: selectedGroup.value?.id === item.id,
|
|
|
- items: [] // 不需要在UI中显示,仅用于内部处理
|
|
|
- }));
|
|
|
+ // 转换数据格式,并标记已选中的项,确保 ID 是字符串
|
|
|
+ carouselList.value = (res.rows || []).map((item: ItemVO) => {
|
|
|
+ // 确保 ID 是字符串,避免大数精度问题
|
|
|
+ const itemId = item.id ? String(item.id) : '';
|
|
|
+ const isSelected = selectedGroup.value?.id === itemId;
|
|
|
+
|
|
|
+ return {
|
|
|
+ id: itemId,
|
|
|
+ name: item.itemName || '',
|
|
|
+ itemName: item.itemName || '', // 保持与API返回的字段名一致
|
|
|
+ itemCount: item.sourceNum || 0,
|
|
|
+ duration: 5, // 默认5秒,可以根据实际需求调整
|
|
|
+ createTime: item.createTime || '',
|
|
|
+ selected: isSelected,
|
|
|
+ items: [] // 不需要在UI中显示,仅用于内部处理
|
|
|
+ };
|
|
|
+ });
|
|
|
|
|
|
// 如果当前有选中的组,确保它在列表中也被选中
|
|
|
if (selectedGroup.value?.id) {
|
|
|
@@ -182,34 +200,41 @@ const removeGroup = () => {
|
|
|
|
|
|
// 确认选择
|
|
|
const confirmSelect = () => {
|
|
|
+ console.log('confirmSelect called, currentRow:', currentRow.value);
|
|
|
+
|
|
|
if (!currentRow.value) {
|
|
|
// 无选中项,清除选中
|
|
|
+ console.log('No row selected, clearing selection');
|
|
|
selectedGroup.value = null;
|
|
|
emit('update:modelValue', '');
|
|
|
dialogVisible.value = false;
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // 确保ID是数字类型
|
|
|
- const id = typeof currentRow.value.id === 'string' ? parseInt(currentRow.value.id, 10) : currentRow.value.id;
|
|
|
+ // 保持ID为字符串,避免精度丢失
|
|
|
+ const id = String(currentRow.value.id);
|
|
|
+ console.log('Selected group ID (as string):', id, 'Type:', typeof id);
|
|
|
|
|
|
- if (isNaN(id)) {
|
|
|
+ if (!id) {
|
|
|
console.error('Invalid group ID:', currentRow.value.id);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // 只存储 id 和 name 字段
|
|
|
- selectedGroup.value = {
|
|
|
- id,
|
|
|
- name: currentRow.value.name
|
|
|
+ // 只存储 id 和 name 字段,确保id是字符串
|
|
|
+ const selectedData = {
|
|
|
+ id: id, // 已经是字符串
|
|
|
+ name: String(currentRow.value.name || '') // 确保name是字符串
|
|
|
};
|
|
|
|
|
|
+ console.log('Emitting selected data:', selectedData);
|
|
|
+ selectedGroup.value = selectedData;
|
|
|
+
|
|
|
// 更新所有行的选中状态
|
|
|
carouselList.value.forEach((item) => {
|
|
|
- item.selected = item.id === currentRow.value.id;
|
|
|
+ item.selected = String(item.id) === id; // 确保比较时类型一致
|
|
|
});
|
|
|
|
|
|
- emit('update:modelValue', JSON.stringify(selectedGroup.value));
|
|
|
+ emit('update:modelValue', JSON.stringify(selectedData));
|
|
|
dialogVisible.value = false;
|
|
|
};
|
|
|
|