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