Commit 70164191 authored by hzl's avatar hzl

feat: 切换账户机型设置默认值

parent 99c2a81b
......@@ -1884,7 +1884,10 @@ export default {
this.form.tiktok_json.advertiserId = this.advertiserOptions[0].advertiserId;
// 异步调用第一个账户的计划列表和设备机型列表,不等待完成
this.fetchCampaignList(this.advertiserOptions[0].advertiserId);
this.fetchDeviceModelList(this.advertiserOptions[0].advertiserId);
this.fetchDeviceModelList(this.advertiserOptions[0].advertiserId).then(() => {
// 设备机型列表加载完成后,设置默认值
this.setDefaultDeviceModels();
});
}
} else {
this.$message.error(response.data.msg || '获取账户列表失败');
......@@ -1914,13 +1917,35 @@ export default {
this.form.accountName = selectedAdvertiser.advertiserName;
}
// 只有在不保留设备机型的情况下才清空(用户主动切换账户时)
if (!preserveDeviceModels) {
this.form.tiktok_json.deviceModels = [];
}
// 保存当前设备机型选择
const currentDeviceModels = [...this.form.tiktok_json.deviceModels];
await this.fetchCampaignList(advertiserId);
await this.fetchDeviceModelList(advertiserId);
// 如果之前有选中的设备机型,且新账户的设备机型列表中包含这些机型,则保持选中状态
if (currentDeviceModels.length > 0) {
this.$nextTick(() => {
const availableDeviceModels = this.deviceModelOptions.map(item => item.device_model_id);
const validDeviceModels = currentDeviceModels.filter(modelId =>
availableDeviceModels.includes(modelId)
);
if (validDeviceModels.length > 0) {
this.form.tiktok_json.deviceModels = validDeviceModels;
console.log('保持设备机型选择:', validDeviceModels);
} else {
// 如果之前的设备机型在新账户中不可用,则设置默认值
this.setDefaultDeviceModels();
console.log('设备机型在新账户中不可用,已设置默认值');
}
});
} else {
// 如果是新增模板且没有之前的设备机型选择,设置默认值
if (!this.form.id) {
this.setDefaultDeviceModels();
}
}
},
// 修改搜索处理方法
......@@ -1983,6 +2008,16 @@ export default {
}
},
// 设置默认设备机型
setDefaultDeviceModels() {
// 默认全选所有可用的安卓设备机型
if (this.deviceModelOptions.length > 0) {
const allDeviceModelIds = this.deviceModelOptions.map(device => device.device_model_id);
this.form.tiktok_json.deviceModels = allDeviceModelIds;
console.log('设置默认全选设备机型:', allDeviceModelIds);
}
},
// 处理平台变化
async handlePlatformChange(value) {
// 当平台改变时,重新验证日预算字段
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment