64 lines
1.4 KiB
JavaScript
64 lines
1.4 KiB
JavaScript
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
|
|
};
|