fix: 移除demo接口

This commit is contained in:
chansee97 2025-09-04 18:50:16 +08:00
parent 4b7946867e
commit cf41abc5a5
4 changed files with 126 additions and 95 deletions

View File

@ -1,31 +0,0 @@
import { request } from '../utils/alova'
/* 示例列表接口 */
export function fetchUserList() {
return request.Get('/userList')
}
// 获取所有路由信息
export function fetchAllRoutes() {
return request.Get<Api.Response<AppRoute.RowRoute[]>>('/getUserRoutes')
}
// 获取所有用户信息
export function fetchUserPage() {
return request.Get<Api.Response<Entity.User[]>>('/userPage')
}
// 获取所有角色列表
export function fetchRoleList() {
return request.Get<Api.Response<Entity.Role[]>>('/role/list')
}
/**
*
*
* @param code -
* @returns
*/
export function fetchDictList(code?: string) {
const params = { code }
return request.Get<Api.Response<Entity.DictType[]>>('/dict/list', { params })
}

View File

@ -1,4 +1,3 @@
export * from './login' export * from './login'
export * from './demo'
export * from './test' export * from './test'
export * from './system' export * from './system'

View File

@ -1,109 +1,172 @@
<script setup lang="ts"> <script setup lang="ts">
import { fetchDictList } from '@/api' import { getDictTypeList } from '@/api'
import { useDict } from '@/hooks/useDict'
import { useDictStore } from '@/store' import { useDictStore } from '@/store'
const { dict } = useDictStore() const dictStore = useDictStore()
const dictKey = ref('') const selectedDictType = ref('')
const options = ref() const selectedDictValue = ref('')
const subOptions = ref() const dictTypeOptions = ref<Array<{ label: string; value: string }>>([])
const currentDict = ref() const displayData = ref<Entity.DictData[] | Record<string, any>>([])
async function getAlldict() { // 使 useDict hook
const { data } = await fetchDictList() const dictUtils = computed(() => {
options.value = data.map((item) => { if (!selectedDictType.value) {
return { return {
label: item.label, rawData: ref([]),
value: item.code, enumMap: ref({}),
valueMap: ref({}),
labelMap: ref({}),
options: ref([])
} }
}) }
return useDict(selectedDictType.value)
})
//
async function getAllDictTypes() {
try {
const { data } = await getDictTypeList()
dictTypeOptions.value = data.list.map((item: Entity.DictType) => ({
label: item.name,
value: item.type,
}))
}
catch (error) {
console.error('获取字典类型失败:', error)
}
} }
function changeSelect(v: string) {
dict(v).then((data) => { //
currentDict.value = data function changeSelect(dictType: string) {
subOptions.value = data.data() selectedDictType.value = dictType
selectedDictValue.value = ''
//
nextTick(() => {
if (dictUtils.value.rawData.value.length > 0) {
displayData.value = dictUtils.value.rawData.value
}
}) })
} }
onMounted(() => { onMounted(() => {
getAlldict() getAllDictTypes()
}) })
const data = ref() //
async function getDict() { function showRawData() {
data.value = currentDict.value.data() displayData.value = dictUtils.value.rawData.value
} }
async function getEnum() { // value -> name
data.value = currentDict.value.enum() function showEnumMap() {
displayData.value = dictUtils.value.enumMap.value
} }
async function getValueMap() { // value -> dictData
data.value = currentDict.value.valueMap() function showValueMap() {
displayData.value = dictUtils.value.valueMap.value
} }
async function getLabelMap() { // name -> dictData
data.value = currentDict.value.labelMap() function showLabelMap() {
displayData.value = dictUtils.value.labelMap.value
} }
const dictValue = ref() //
function showOptions() {
displayData.value = dictUtils.value.options.value
}
// 使 enumMap
const dictLabel = computed(() => { const dictLabel = computed(() => {
if (data.value && data.value[dictValue.value]) { if (!selectedDictValue.value || !dictUtils.value.enumMap.value) return '--'
return data.value[dictValue.value].label return dictUtils.value.enumMap.value[selectedDictValue.value] || '--'
}
return '--'
}) })
const enumValue = ref() //
function clearCache() {
dictStore.cleanDict()
window.$message?.success('字典缓存已清理')
}
const enumLabel = computed(() => { //
if (data.value && data.value[enumValue.value]) { function removeCache() {
return data.value[enumValue.value] if (selectedDictType.value) {
dictStore.removeDict(selectedDictType.value)
window.$message?.success(`已移除 ${selectedDictType.value} 的缓存`)
} }
return '--' }
})
</script> </script>
<template> <template>
<n-card title="字典"> <n-card title="字典示">
<n-flex vertical> <n-flex vertical>
<n-flex> <n-flex align="center">
<n-select v-model:value="dictKey" class="w-1/3" :options="options" @update:value="changeSelect" /> <n-select
子字典下拉框 v-model:value="selectedDictType"
<n-select class="w-1/3" :options="subOptions" /> :options="dictTypeOptions"
placeholder="请选择字典类型"
@update:value="changeSelect"
/>
<n-select
v-model:value="selectedDictValue"
:options="dictUtils.options.value"
placeholder="请选择字典项"
/>
</n-flex> </n-flex>
<n-flex> <n-flex>
<n-button @click="getDict"> <n-button @click="showRawData">
获取当前字典数据 显示原始数据 (rawData)
</n-button> </n-button>
<n-button @click="getEnum"> <n-button @click="showEnumMap">
获取当前字典枚举 显示枚举映射 (enumMap)
</n-button> </n-button>
<n-button @click="getValueMap"> <n-button @click="showValueMap">
获取当前字典ValueMap 显示值映射 (valueMap)
</n-button> </n-button>
<n-button @click="getLabelMap"> <n-button @click="showLabelMap">
获取当前字典LabelMap 显示标签映射 (labelMap)
</n-button>
<n-button @click="showOptions">
显示选项格式 (options)
</n-button> </n-button>
</n-flex> </n-flex>
<pre class="bg-#eee:30"> <n-flex>
{{ data }} <n-button @click="clearCache" type="warning">
</pre> 清理所有缓存
</n-button>
<n-button @click="removeCache" type="error" :disabled="!selectedDictType">
移除当前字典缓存
</n-button>
</n-flex>
<n-flex align="center"> <pre class="bg-gray-100 p-4 rounded text-sm overflow-auto max-h-96">
<n-input-number v-model:value="dictValue" :min="0" /> {{ JSON.stringify(displayData, null, 2) }}</pre>
<n-flex align="center" v-if="selectedDictValue">
<n-text>选中值: {{ selectedDictValue }}</n-text>
<n-text type="info"> <n-text type="info">
Map回显结果 {{ dictLabel }} 对应标签: {{ dictLabel }}
</n-text>
</n-flex>
<n-flex align="center">
<n-input-number v-model:value="enumValue" :min="0" />
<n-text type="info">
Enum回显结果 {{ enumLabel }}
</n-text> </n-text>
</n-flex> </n-flex>
<n-divider />
<n-text depth="3">useDict Hook 使用说明</n-text>
<n-ul>
<n-li><n-text code>useDict(dictType)</n-text> - 使用字典类型获取字典工具对象</n-li>
<n-li><n-text code>rawData</n-text> - 原始字典数据数组 Entity.DictData[]</n-li>
<n-li><n-text code>enumMap</n-text> - 枚举映射 { value: name }</n-li>
<n-li><n-text code>valueMap</n-text> - 值映射 { value: dictData }</n-li>
<n-li><n-text code>labelMap</n-text> - 标签映射 { name: dictData }</n-li>
<n-li><n-text code>options</n-text> - 选项数组 [{ label: name, value }]</n-li>
<n-li>字典数据会自动缓存60分钟支持手动清理缓存</n-li>
<n-li>推荐使用 useDict hook 而不是直接调用 API store</n-li>
</n-ul>
</n-flex> </n-flex>
</n-card> </n-card>
</template> </template>

View File

@ -21,7 +21,7 @@ const modalForm = createProModalForm<Partial<Entity.DictData>>({
omitEmptyString: false, omitEmptyString: false,
initialValues: { initialValues: {
sort: 0, sort: 0,
status: 1, status: 0,
}, },
onSubmit: submitModal, onSubmit: submitModal,
}) })