|
@@ -89,6 +89,7 @@
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
<script setup lang="ts">
|
|
|
import { ref, onMounted, computed, watch } from 'vue'
|
|
import { ref, onMounted, computed, watch } from 'vue'
|
|
|
|
|
+import { getIssuingAuthorities } from '@/api/retrieval'
|
|
|
|
|
|
|
|
interface Authority {
|
|
interface Authority {
|
|
|
shortName: string
|
|
shortName: string
|
|
@@ -96,45 +97,37 @@ interface Authority {
|
|
|
count: number
|
|
count: number
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// 写死的发布单位列表
|
|
|
|
|
-const HARD_CODED_AUTHORITIES: string[] = [
|
|
|
|
|
-
|
|
|
|
|
- '中华人民共和国住房和城乡建设部',
|
|
|
|
|
- '中华人民共和国交通运输部',
|
|
|
|
|
- '中华人民共和国建设部',
|
|
|
|
|
- '中华人民共和国国家质量监督检验检疫总局',
|
|
|
|
|
- '中国国家标准化管理委员会',
|
|
|
|
|
-]
|
|
|
|
|
-
|
|
|
|
|
const docTypes = ['全部', '法规制度', '技术标准', '操作指南', '通知公告', '工作报告']
|
|
const docTypes = ['全部', '法规制度', '技术标准', '操作指南', '通知公告', '工作报告']
|
|
|
|
|
|
|
|
-// 初始化所有发布单位
|
|
|
|
|
-const allAuthorities = ref<Authority[]>(
|
|
|
|
|
- HARD_CODED_AUTHORITIES.map((name) => ({ shortName: name, fullName: name, count: 0 }))
|
|
|
|
|
-)
|
|
|
|
|
|
|
+// 所有发布单位(从后端 API 获取)
|
|
|
|
|
+const allAuthorities = ref<Authority[]>([])
|
|
|
|
|
+const authoritiesLoading = ref(false)
|
|
|
|
|
|
|
|
-// 前5发布单位(用于按钮展示)
|
|
|
|
|
-const topAuthorities = computed(() => allAuthorities.value.slice(0, 5))
|
|
|
|
|
-
|
|
|
|
|
-// 本地过滤发布单位(替代原来的 API 请求)
|
|
|
|
|
-function filterAuthorities(keyword: string) {
|
|
|
|
|
- const kw = keyword.trim()
|
|
|
|
|
- if (!kw) {
|
|
|
|
|
- allAuthorities.value = HARD_CODED_AUTHORITIES.map((name) => ({
|
|
|
|
|
- shortName: name,
|
|
|
|
|
- fullName: name,
|
|
|
|
|
- count: 0,
|
|
|
|
|
|
|
+// 加载全部发布单位(无关键词,取前50个)
|
|
|
|
|
+async function loadAuthorities(keyword = '') {
|
|
|
|
|
+ authoritiesLoading.value = true
|
|
|
|
|
+ try {
|
|
|
|
|
+ const res = await getIssuingAuthorities(keyword)
|
|
|
|
|
+ const items = (res.data?.authorities || []) as Array<{ full_name: string; count: number }>
|
|
|
|
|
+ allAuthorities.value = items.slice(0, 50).map((a) => ({
|
|
|
|
|
+ shortName: a.full_name.length > 12 ? a.full_name.substring(0, 12) + '…' : a.full_name,
|
|
|
|
|
+ fullName: a.full_name,
|
|
|
|
|
+ count: a.count,
|
|
|
}))
|
|
}))
|
|
|
- return
|
|
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ console.warn('[FilterPanel] 加载发布单位失败:', e)
|
|
|
|
|
+ allAuthorities.value = []
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ authoritiesLoading.value = false
|
|
|
}
|
|
}
|
|
|
- allAuthorities.value = HARD_CODED_AUTHORITIES.filter((name) => name.includes(kw)).map(
|
|
|
|
|
- (name) => ({ shortName: name, fullName: name, count: 0 })
|
|
|
|
|
- )
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// 页面加载时初始化发布单位
|
|
|
|
|
|
|
+// 前5发布单位(用于按钮展示)
|
|
|
|
|
+const topAuthorities = computed(() => allAuthorities.value.slice(0, 5))
|
|
|
|
|
+
|
|
|
|
|
+// 页面加载时获取发布单位列表
|
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
|
- filterAuthorities('')
|
|
|
|
|
|
|
+ loadAuthorities('')
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
const props = defineProps<{
|
|
@@ -205,17 +198,31 @@ function onSearchInput(val: string) {
|
|
|
hasSearched.value = val.trim() !== ''
|
|
hasSearched.value = val.trim() !== ''
|
|
|
if (debounceTimer) clearTimeout(debounceTimer)
|
|
if (debounceTimer) clearTimeout(debounceTimer)
|
|
|
debounceTimer = setTimeout(() => {
|
|
debounceTimer = setTimeout(() => {
|
|
|
- if (!val.trim()) {
|
|
|
|
|
|
|
+ const kw = val.trim()
|
|
|
|
|
+ if (!kw) {
|
|
|
searchResults.value = []
|
|
searchResults.value = []
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
- // 本地搜索
|
|
|
|
|
- searchResults.value = allAuthorities.value.filter((a) =>
|
|
|
|
|
- a.fullName.includes(val.trim()) || a.shortName.includes(val.trim())
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ // 调用后端 API 搜索发布单位
|
|
|
|
|
+ loadSearchResults(kw)
|
|
|
}, 300)
|
|
}, 300)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+async function loadSearchResults(keyword: string) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const res = await getIssuingAuthorities(keyword)
|
|
|
|
|
+ const items = (res.data?.authorities || []) as Array<{ full_name: string; count: number }>
|
|
|
|
|
+ searchResults.value = items.slice(0, 50).map((a) => ({
|
|
|
|
|
+ shortName: a.full_name.length > 12 ? a.full_name.substring(0, 12) + '…' : a.full_name,
|
|
|
|
|
+ fullName: a.full_name,
|
|
|
|
|
+ count: a.count,
|
|
|
|
|
+ }))
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ console.warn('[FilterPanel] 搜索发布单位失败:', e)
|
|
|
|
|
+ searchResults.value = []
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
function onDateRangeChange(val: [string, string] | null) {
|
|
function onDateRangeChange(val: [string, string] | null) {
|
|
|
emit('update:dateRange', val)
|
|
emit('update:dateRange', val)
|
|
|
emitChange(undefined, undefined, val)
|
|
emitChange(undefined, undefined, val)
|