fix(exports): 优化导出表单创建者选择逻辑

- 修改创建者选择组件,支持通过 URL 中的 userId 自动选中并禁用创建者字段
- 更新导出逻辑,确保在对话框打开后重新设置 creatorId 和 ymtCreatorId
- 增强日志记录,提供创建者选择的调试信息,确保用户体验的流畅性
This commit is contained in:
zhouyonggao 2025-12-19 14:35:52 +08:00
parent 61a3b17c09
commit 6df550beb9
2 changed files with 60 additions and 8 deletions

View File

@ -272,7 +272,7 @@
<el-row :gutter="8" v-if="isOrder && exportForm.datasource==='marketing'">
<el-col :span="12">
<el-form-item label="订单数据创建者" prop="creator">
<el-select v-model="exportForm.creatorId" clearable filterable :disabled="hasOnlyUserId" :teleported="false" placeholder="请选择创建者" style="width:100%">
<el-select v-model.number="exportForm.creatorId" clearable filterable :disabled="hasOnlyUserId" :teleported="false" placeholder="请选择创建者" style="width:100%">
<el-option v-for="opt in creatorOptions" :key="opt.value" :label="opt.label" :value="opt.value" />
</el-select>
</el-form-item>

View File

@ -664,18 +664,50 @@ const app = createApp({
state.exportForm.datasource = state.exportTpl.datasource || row.datasource || 'marketing';
state.exportForm.file_format = state.exportTpl.file_format || row.file_format || 'xlsx';
// 当 URL 中有 userId 时,自动选中并禁用创建者字段
const userId = Api.getUserId();
const shouldAutoSelectCreator = userId && hasOnlyUserId.value;
console.log('[openExport] userId:', userId, 'hasOnlyUserId:', hasOnlyUserId.value, 'shouldAutoSelectCreator:', shouldAutoSelectCreator);
if (state.exportForm.datasource === 'marketing') {
loadCreators();
// 注意:不再自动从 current_user_id 设置 creatorId/creatorIds
// 用户需要手动选择 creator 进行过滤
await loadCreators();
if (shouldAutoSelectCreator) {
const userIdNum = Number(userId);
console.log('[openExport] 设置 marketing creatorId:', userIdNum);
// 直接设置 userId即使创建者列表中暂时没有该选项
state.exportForm.creatorId = userIdNum;
// 等待 Vue 更新
await Vue.nextTick();
const creatorExists = creatorOptions.value.some(opt => opt.value === userIdNum);
console.log('[openExport] creatorOptions:', creatorOptions.value.length, 'creatorExists:', creatorExists);
if (!creatorExists) {
console.log(`警告: 创建者列表中未找到 userId=${userIdNum},但已自动设置`);
}
}
}
if (state.exportForm.datasource === 'ymt') {
await loadYmtCreators();
if (shouldAutoSelectCreator) {
const userIdNum = Number(userId);
console.log('[openExport] 设置 ymt ymtCreatorId:', userIdNum);
// 直接设置 userId即使创建者列表中暂时没有该选项
state.exportForm.ymtCreatorId = userIdNum;
// 加载相关的商户和活动
await loadYmtMerchants();
await loadYmtActivities();
// 注意:不再自动从 current_user_id 设置 ymtCreatorId
// 用户需要手动选择 creator 进行过滤
// 等待 Vue 更新
await Vue.nextTick();
const creatorExists = ymtCreatorOptions.value.some(opt => opt.value === userIdNum);
console.log('[openExport] ymtCreatorOptions:', ymtCreatorOptions.value.length, 'creatorExists:', creatorExists);
if (!creatorExists) {
console.log(`警告: 易码通用户列表中未找到 userId=${userIdNum},但已自动设置`);
}
} else {
await loadYmtMerchants();
await loadYmtActivities();
}
}
if (!state.exportForm.dateRange?.length) {
@ -683,6 +715,26 @@ const app = createApp({
}
state.exportVisible = true;
// 对话框打开后,再次确保值已设置(处理异步加载和渲染的情况)
await Vue.nextTick();
// 使用 setTimeout 确保在对话框完全渲染后再设置值
setTimeout(() => {
if (shouldAutoSelectCreator) {
const userIdNum = Number(userId);
if (state.exportForm.datasource === 'marketing') {
if (state.exportForm.creatorId !== userIdNum) {
console.log('[openExport] 对话框打开后重新设置 marketing creatorId:', userIdNum);
state.exportForm.creatorId = userIdNum;
}
} else if (state.exportForm.datasource === 'ymt') {
if (state.exportForm.ymtCreatorId !== userIdNum) {
console.log('[openExport] 对话框打开后重新设置 ymt ymtCreatorId:', userIdNum);
state.exportForm.ymtCreatorId = userIdNum;
}
}
}
}, 100);
};
/**