feat(shop): 完善分销商设置功能
- 集成新增和列表查询API接口 - 添加设置数据模型类型定义 - 实现设置数据的加载和保存逻辑 - 添加设置分组应用工具函数 - 实现JSON数据解析和序列化处理 - 更新开发环境API配置地址 - 优化设置数据结构深拷贝处理
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
VITE_APP_NAME=后台管理(开发环境)
|
||||
#VITE_API_URL=http://127.0.0.1:9200/api
|
||||
VITE_API_URL=http://127.0.0.1:9200/api
|
||||
#VITE_SERVER_API_URL=http://127.0.0.1:8000/api
|
||||
|
||||
|
||||
|
||||
@@ -235,14 +235,20 @@
|
||||
import { PlusOutlined } from '@ant-design/icons-vue';
|
||||
import { getPageTitle } from '@/utils/common';
|
||||
import {
|
||||
addShopDealerSetting,
|
||||
updateShopDealerSetting,
|
||||
getShopDealerSetting
|
||||
listShopDealerSetting
|
||||
} from '@/api/shop/shopDealerSetting';
|
||||
import type { ShopDealerSetting } from '@/api/shop/shopDealerSetting/model';
|
||||
|
||||
// 当前激活的标签页
|
||||
const activeTab = ref('basic');
|
||||
// 保存状态
|
||||
const saving = ref(false);
|
||||
const currentSetting = ref<ShopDealerSetting | null>(null);
|
||||
const hasSetting = ref(false);
|
||||
const SETTING_KEY = 'dealer_setting';
|
||||
const SETTING_DESCRIPTION = '分销商设置';
|
||||
|
||||
// 基础设置
|
||||
const basicSettings = reactive({
|
||||
@@ -283,6 +289,21 @@
|
||||
backgroundImages: []
|
||||
});
|
||||
|
||||
const applySettingGroup = (target: Record<string, any>, source?: any) => {
|
||||
if (source && typeof source === 'object') {
|
||||
Object.assign(target, source);
|
||||
}
|
||||
};
|
||||
|
||||
const applySettingValues = (values: any) => {
|
||||
applySettingGroup(basicSettings, values?.basic);
|
||||
applySettingGroup(commissionSettings, values?.commission);
|
||||
applySettingGroup(withdrawSettings, values?.withdraw);
|
||||
applySettingGroup(agreementSettings, values?.agreement);
|
||||
applySettingGroup(notificationSettings, values?.notification);
|
||||
applySettingGroup(pageSettings, values?.page);
|
||||
};
|
||||
|
||||
/* 图片预览 */
|
||||
const handlePreview = (file: any) => {
|
||||
console.log('预览图片:', file);
|
||||
@@ -291,12 +312,30 @@
|
||||
/* 加载设置 */
|
||||
const loadSettings = async () => {
|
||||
try {
|
||||
// 这里应该调用API获取设置数据
|
||||
// const settings = await getShopDealerSetting();
|
||||
// 然后将数据分配到各个设置对象中
|
||||
console.log('加载设置数据');
|
||||
const list = await listShopDealerSetting();
|
||||
const setting =
|
||||
list.find((item) => item.key === SETTING_KEY) ?? list[0];
|
||||
if (!setting) {
|
||||
hasSetting.value = false;
|
||||
currentSetting.value = null;
|
||||
return;
|
||||
}
|
||||
|
||||
currentSetting.value = setting;
|
||||
hasSetting.value = true;
|
||||
if (setting.values) {
|
||||
try {
|
||||
const parsed = JSON.parse(setting.values);
|
||||
applySettingValues(parsed);
|
||||
} catch (error) {
|
||||
console.warn('解析设置失败:', error);
|
||||
message.warning('设置数据解析失败,已使用默认值');
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载设置失败:', error);
|
||||
hasSetting.value = false;
|
||||
currentSetting.value = null;
|
||||
message.error('加载设置失败');
|
||||
}
|
||||
};
|
||||
@@ -307,18 +346,37 @@
|
||||
try {
|
||||
// 收集所有设置数据
|
||||
const allSettings = {
|
||||
basic: basicSettings,
|
||||
commission: commissionSettings,
|
||||
withdraw: withdrawSettings,
|
||||
agreement: agreementSettings,
|
||||
notification: notificationSettings,
|
||||
page: pageSettings
|
||||
basic: { ...basicSettings },
|
||||
commission: { ...commissionSettings },
|
||||
withdraw: { ...withdrawSettings },
|
||||
agreement: { ...agreementSettings },
|
||||
notification: { ...notificationSettings },
|
||||
page: {
|
||||
...pageSettings,
|
||||
backgroundImages: [...pageSettings.backgroundImages]
|
||||
}
|
||||
};
|
||||
|
||||
console.log('保存设置:', allSettings);
|
||||
|
||||
// 这里应该调用API保存设置
|
||||
// await updateShopDealerSetting(allSettings);
|
||||
const payload: ShopDealerSetting = {
|
||||
...currentSetting.value,
|
||||
key: currentSetting.value?.key ?? SETTING_KEY,
|
||||
describe: currentSetting.value?.describe ?? SETTING_DESCRIPTION,
|
||||
values: JSON.stringify(allSettings),
|
||||
updateTime: Date.now()
|
||||
};
|
||||
|
||||
const saveOrUpdate = hasSetting.value
|
||||
? updateShopDealerSetting
|
||||
: addShopDealerSetting;
|
||||
await saveOrUpdate(payload);
|
||||
|
||||
if (!hasSetting.value) {
|
||||
await loadSettings();
|
||||
} else {
|
||||
currentSetting.value = payload;
|
||||
}
|
||||
|
||||
// 模拟保存
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
|
||||
Reference in New Issue
Block a user