添加字典功能及初始化数据

This commit is contained in:
2025-12-22 21:56:10 +08:00
parent 180fe20347
commit 7d53a059d7
31 changed files with 1894 additions and 79 deletions
+63
View File
@@ -0,0 +1,63 @@
import api from './api';
/**
* 字典服务
* 处理字典数据的获取
*/
/**
* 根据字典类型获取启用的字典列表
* @param {string} dictType - 字典类型
* @returns {Promise<Array>} 字典列表
*/
export const getEnabledDictionariesByType = async (dictType) => {
const response = await api.get('/dictionary/enabledByType', {
params: { dictType }
});
return response.data || [];
};
/**
* 获取星座字典
* @returns {Promise<Array>} 星座列表
*/
export const getZodiacList = async () => {
return getEnabledDictionariesByType('constellation');
};
/**
* 获取MBTI字典
* @returns {Promise<Array>} MBTI列表
*/
export const getMbtiList = async () => {
return getEnabledDictionariesByType('mbti');
};
/**
* 获取性别字典
* @returns {Promise<Array>} 性别列表
*/
export const getGenderList = async () => {
return getEnabledDictionariesByType('gender');
};
/**
* 将字典数据转换为下拉选项格式
* @param {Array} dictList - 字典列表
* @returns {Array<{value: string, label: string}>} 选项列表
*/
export const transformToOptions = (dictList) => {
if (!Array.isArray(dictList)) return [];
return dictList.map(item => ({
value: item.dictValue || item.dictCode || '',
label: item.dictName || item.dictValue || ''
}));
};
export default {
getEnabledDictionariesByType,
getZodiacList,
getMbtiList,
getGenderList,
transformToOptions
};
+4
View File
@@ -72,6 +72,7 @@ const transformToBackendFormat = (frontendData) => {
nickname,
gender,
zodiac,
profession,
mbti,
hobbies,
childhood,
@@ -85,6 +86,7 @@ const transformToBackendFormat = (frontendData) => {
nickname,
gender,
zodiac,
profession,
mbti,
// 兴趣爱好转为 JSON 字符串
hobbies: Array.isArray(hobbies) ? JSON.stringify(hobbies) : hobbies,
@@ -118,6 +120,7 @@ export const transformToFrontendFormat = (backendData) => {
nickname,
gender,
zodiac,
profession,
mbti,
hobbies,
childhoodDate,
@@ -136,6 +139,7 @@ export const transformToFrontendFormat = (backendData) => {
nickname: nickname || '',
gender: gender || '',
zodiac: zodiac || '',
profession: profession || '',
mbti: mbti || '',
// 兴趣爱好从 JSON 字符串解析
hobbies: hobbies ? (typeof hobbies === 'string' ? JSON.parse(hobbies) : hobbies) : [],