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

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
};