import { GetDictionaryidDicItems } from '@/api/system/index'
export const getDictionaryItems = async (dicName, refArray, type) => {
    const dictionarys = JSON.parse(sessionStorage.getItem('dictionarys'))
    if (dictionarys) {
        const dictionary = dictionarys.find(item => item.DicName === dicName)
        if (dictionary) {
            const params = {
                DictionaryId: dictionary.Id,
                LambdaExp: `IsDeleted==false`,
                SelectSorts: '[{ "FieldName": "CreateTime", "IsAsc": false }]',
            }
            try {
                const res = await GetDictionaryidDicItems(params)
                if (res.StatusCode === 200) {
                    if (type === 'number') {
                        res.Data.forEach(item => {
                            item.Value = Number(item.Value)
                        })
                    }
                    refArray.value = res.Data
                } else {
                    refArray.value = []
                }
            } catch (error) {
                refArray.value = []
            }
        } else {
            refArray.value = []
        }
    } else {
        refArray.value = []
    }
}