feat: 选择Library图片组件如果传入类型,只显示对应类型

This commit is contained in:
zhangyh
2025-09-24 13:42:27 +08:00
parent bdb3c50650
commit 96ae993ab0
3 changed files with 14 additions and 8 deletions

2
components.d.ts vendored
View File

@@ -18,6 +18,7 @@ declare module 'vue' {
AMenu: typeof import('ant-design-vue/es')['Menu'] AMenu: typeof import('ant-design-vue/es')['Menu']
AMenuItem: typeof import('ant-design-vue/es')['MenuItem'] AMenuItem: typeof import('ant-design-vue/es')['MenuItem']
AModal: typeof import('ant-design-vue/es')['Modal'] AModal: typeof import('ant-design-vue/es')['Modal']
APagination: typeof import('ant-design-vue/es')['Pagination']
APopover: typeof import('ant-design-vue/es')['Popover'] APopover: typeof import('ant-design-vue/es')['Popover']
ARangePicker: typeof import('ant-design-vue/es')['RangePicker'] ARangePicker: typeof import('ant-design-vue/es')['RangePicker']
ASelect: typeof import('ant-design-vue/es')['Select'] ASelect: typeof import('ant-design-vue/es')['Select']
@@ -29,6 +30,7 @@ declare module 'vue' {
ATabPane: typeof import('ant-design-vue/es')['TabPane'] ATabPane: typeof import('ant-design-vue/es')['TabPane']
ATabs: typeof import('ant-design-vue/es')['Tabs'] ATabs: typeof import('ant-design-vue/es')['Tabs']
AUpload: typeof import('ant-design-vue/es')['Upload'] AUpload: typeof import('ant-design-vue/es')['Upload']
ElCascader: typeof import('element-plus/es')['ElCascader']
RouterLink: typeof import('vue-router')['RouterLink'] RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView'] RouterView: typeof import('vue-router')['RouterView']
} }

View File

@@ -228,7 +228,9 @@
ref="selectImages" ref="selectImages"
@select="handleImageSelect" @select="handleImageSelect"
:api="Https.httpUrls.queryLibraryPage" :api="Https.httpUrls.queryLibraryPage"
isLibrary/> isLibrary
:libraryType="type_.type2"
/>
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts">

View File

@@ -106,7 +106,7 @@ const props = defineProps({
type: Boolean, type: Boolean,
default: false default: false
}, },
level1Type: { libraryType: {
type: String, type: String,
default: '' default: ''
} }
@@ -119,12 +119,12 @@ const libraryTypeList = ref([
...navTypeList(t).library.list.filter(item => item.value !== 'MyBrand') ...navTypeList(t).library.list.filter(item => item.value !== 'MyBrand')
]) ])
// 根据传入的level1Type参数确定默认选中的分类 // 根据传入的libraryType参数确定默认选中的分类
const getDefaultCategory = () => { const getDefaultCategory = () => {
if (props.level1Type) { if (props.libraryType) {
// 如果传入了level1Type查找匹配的category // 如果传入了libraryType查找匹配的category
const matchedCategory = libraryTypeList.value.find( const matchedCategory = libraryTypeList.value.find(
item => item.value === props.level1Type item => item.value === props.libraryType
) )
return matchedCategory ? matchedCategory.label : libraryTypeList.value[0]?.label || '' return matchedCategory ? matchedCategory.label : libraryTypeList.value[0]?.label || ''
} }
@@ -154,7 +154,7 @@ const categories = computed(() => {
// 计算属性:是否显示分类选择器 // 计算属性:是否显示分类选择器
const showCategories = computed(() => { const showCategories = computed(() => {
return !props.level1Type // 如果没有传入level1Type参数则显示分类选择器 return !props.libraryType // 如果没有传入libraryType参数则显示分类选择器
}) })
// 新增API请求函数 // 新增API请求函数
@@ -169,7 +169,7 @@ const fetchImages = async (
const type = libraryTypeList.value.find(item => item.label === category)?.value const type = libraryTypeList.value.find(item => item.label === category)?.value
const params = { const params = {
classificationIdList: [], classificationIdList: [],
level1Type: props.level1Type || type, level1Type: props.libraryType || type,
level2Type: '', level2Type: '',
page, page,
ageGroup: '', ageGroup: '',
@@ -242,6 +242,8 @@ const resetAndLoad = (category = selectedCategory.value) => {
list.value = [] list.value = []
hasMore.value = true hasMore.value = true
currentPage.value = 0 currentPage.value = 0
console.log('默认选择----',getDefaultCategory())
selectedCategory.value = getDefaultCategory()
fetchImages(1, category, true) fetchImages(1, category, true)
// 检查是否需要自动加载更多数据 // 检查是否需要自动加载更多数据