From 5156b9ccae0db0d18d3722d03bd398573ec88b2a Mon Sep 17 00:00:00 2001 From: liushilong <2224574157@qq.com> Date: Sat, 13 Apr 2024 11:18:58 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=BB=88=E5=AE=A1?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E6=97=A0=E6=B3=95=E8=B7=B3=E8=BD=AC=E9=A6=96?= =?UTF-8?q?=E9=A1=B5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components.d.ts | 6 +- src/views/home/aside/Aside.vue | 392 +++++++++--------- src/views/home/aside/comp/Search.vue | 77 ++-- .../aside/comp/modals/CustomFilterModal.vue | 147 +++++-- 4 files changed, 353 insertions(+), 269 deletions(-) diff --git a/components.d.ts b/components.d.ts index e12f925..61136d3 100644 --- a/components.d.ts +++ b/components.d.ts @@ -23,7 +23,6 @@ declare module 'vue' { NDivider: typeof import('naive-ui')['NDivider'] NDropdown: typeof import('naive-ui')['NDropdown'] NEllipsis: typeof import('naive-ui')['NEllipsis'] - NEmpty: typeof import('naive-ui')['NEmpty'] NForm: typeof import('naive-ui')['NForm'] NFormItem: typeof import('naive-ui')['NFormItem'] NGi: typeof import('naive-ui')['NGi'] @@ -38,17 +37,14 @@ declare module 'vue' { NPopconfirm: typeof import('naive-ui')['NPopconfirm'] NPopover: typeof import('naive-ui')['NPopover'] NPopselect: typeof import('naive-ui')['NPopselect'] + NProgress: typeof import('naive-ui')['NProgress'] NScrollbar: typeof import('naive-ui')['NScrollbar'] NSelect: typeof import('naive-ui')['NSelect'] NSlider: typeof import('naive-ui')['NSlider'] NSpace: typeof import('naive-ui')['NSpace'] NSpin: typeof import('naive-ui')['NSpin'] NSwitch: typeof import('naive-ui')['NSwitch'] - NTabPane: typeof import('naive-ui')['NTabPane'] - NTabs: typeof import('naive-ui')['NTabs'] NTag: typeof import('naive-ui')['NTag'] - NTimeline: typeof import('naive-ui')['NTimeline'] - NTimelineItem: typeof import('naive-ui')['NTimelineItem'] NTooltip: typeof import('naive-ui')['NTooltip'] NUpload: typeof import('naive-ui')['NUpload'] NUploadDragger: typeof import('naive-ui')['NUploadDragger'] diff --git a/src/views/home/aside/Aside.vue b/src/views/home/aside/Aside.vue index a6b2249..04e198b 100644 --- a/src/views/home/aside/Aside.vue +++ b/src/views/home/aside/Aside.vue @@ -10,263 +10,281 @@ import { shallowRef, unref, watch, -} from "vue"; -import { CustomFilterModalVue, FilterModalVue, NewFilterModalVue } from "./comp/modals"; -import Search from "./comp/Search.vue"; -import AdvanceFilter from "./comp/AdvanceFilter.vue"; -import { getViewportOffset } from "@/utils/domUtils"; -import { useWindowSizeFn } from "@/hooks/event/useWindowSizeFn"; -import { useConfig } from "@/store/modules/asideConfig"; -import type { Filter } from "/#/home"; -import type { AsideEntity } from "@/config/aside"; -import { asideMap } from "@/config/aside"; -import type { AsideConfig } from "/#/api"; -import emitter from "@/utils/mitt"; -import { getFilterList } from "@/api/home/main"; -import dayjs from "dayjs"; -import { cloneDeep, isEqual } from "lodash-es"; - -const configStore = useConfig(); +} from 'vue' +import dayjs from 'dayjs' +import { cloneDeep, isEqual } from 'lodash-es' +import { CustomFilterModalVue, FilterModalVue, NewFilterModalVue } from './comp/modals' +import Search from './comp/Search.vue' +import AdvanceFilter from './comp/AdvanceFilter.vue' +import { getViewportOffset } from '@/utils/domUtils' +import { useWindowSizeFn } from '@/hooks/event/useWindowSizeFn' +import { useConfig } from '@/store/modules/asideConfig' +import type { Filter } from '/#/home' +import type { AsideEntity } from '@/config/aside' +import { asideMap } from '@/config/aside' +import type { AsideConfig } from '/#/api' +import emitter from '@/utils/mitt' +import { getFilterList } from '@/api/home/main' + +const configStore = useConfig() // 所有左侧模块的值 -let asideValue: Record = reactive({}); +const asideValue: Record = reactive({}) // 左侧某个模块是否显示: 显示需同时满足系统配置和个人配置 -const asideVisible: Partial> = reactive({}); +const asideVisible: Partial> = reactive({}) // 当前显示的模块,按照数组顺序显示 -const showItems = shallowRef<{ key: string; config: AsideEntity }[]>([]); +const showItems = shallowRef<{ key: string, config: AsideEntity }[]>([]) Object.keys(asideMap).forEach((key) => { - const entity = asideMap[key]; - const { defaultValue } = entity; - asideValue[key] = defaultValue; -}); - -const filterModalRef: any = ref(null); -const newFilterModalRef = ref(null); -const customModalRef = ref(null); -const customObjRef = ref(null); // 获取高级筛选获取的值 -const customTempObjRef = ref(null); // 获取高级筛选获取的值(作对比) -const configFilterRef = ref([]); // 获取排序的值 -const AdvanceFilterRef: any = ref(null); + const entity = asideMap[key] + const { defaultValue } = entity + asideValue[key] = defaultValue +}) + +const filterModalRef: any = ref(null) +const newFilterModalRef = ref(null) +const customModalRef = ref(null) +const customObjRef = ref(null) // 获取高级筛选获取的值 +const customTempObjRef = ref(null) // 获取高级筛选获取的值(作对比) +const configFilterRef = ref([]) // 获取排序的值 +const AdvanceFilterRef: any = ref(null) function showModal(modalRef: any) { - const modal = unref(modalRef)! as any; - modal.showModal(); + const modal = unref(modalRef)! as any + modal.showModal() } onMounted(() => { nextTick(() => { - computeSlideHeight(); - let tempAsideValue = cloneDeep(asideValue); + computeSlideHeight() + const tempAsideValue = cloneDeep(asideValue) // configStore.setAsideValue(tempAsideValue); - console.log("asideMap和asideValue", tempAsideValue); - }); -}); + console.log('asideMap和asideValue', tempAsideValue) + }) +}) -const collapse = ref(false); -const mousetrap = inject("mousetrap") as any; -mousetrap.bind("[", collapseHandler); +const collapse = ref(false) +const mousetrap = inject('mousetrap') as any +mousetrap.bind('[', collapseHandler) function collapseHandler() { - collapse.value = !collapse.value; + collapse.value = !collapse.value } const asideWidth = computed(() => { - return collapse.value ? 0 : 308; -}); + return collapse.value ? 0 : 308 +}) -const asideHeight = ref(500); +const asideHeight = ref(500) const asideStyle = computed(() => { return { width: `${asideWidth.value}px`, height: `${asideHeight.value}px`, - }; -}); + } +}) const collapseIcon = computed(() => { - return collapse.value ? "expand-cir" : "collapse-cir"; -}); + return collapse.value ? 'expand-cir' : 'collapse-cir' +}) function computeSlideHeight() { - const headEl = document.querySelector(".aside-header")!; - const { bottomIncludeBody } = getViewportOffset(headEl); - const height = bottomIncludeBody; - asideHeight.value = height - 24; + const headEl = document.querySelector('.aside-header')! + const { bottomIncludeBody } = getViewportOffset(headEl) + const height = bottomIncludeBody + asideHeight.value = height - 24 } -useWindowSizeFn(computeSlideHeight, 280); +useWindowSizeFn(computeSlideHeight, 280) onBeforeMount(async () => { - configStore.fetchConfig(); - configStore.fetchCustomConfig(); -}); + configStore.fetchConfig() + configStore.fetchCustomConfig() +}) -nextTick(()=>{ +nextTick(() => { configStore.$subscribe(() => { - const config = configStore.getConfig; - const customConfig = configStore.getCustomConfig; - if ( - configFilterRef.value.length > 0 && - isEqual(configFilterRef.value, configStore.getFilterConfig) && - customObjRef.value && - isEqual(customObjRef.value, customTempObjRef.value) - ) { - return; - } - if (config == null || customConfig == null) return; - // console.log("config", config, "customConfig", customConfig); - /* rao + const config = configStore.getConfig + const customConfig = configStore.getCustomConfig + if ( + configFilterRef.value.length > 0 + && isEqual(configFilterRef.value, configStore.getFilterConfig) + && customObjRef.value + && isEqual(customObjRef.value, customTempObjRef.value) + ) + return + + if (config == null || customConfig == null) + return + // console.log("config", config, "customConfig", customConfig); + /* rao const showKeys = [...customConfig].filter(key => !asideMap[key].isDefaultFilter)// 获取customConfig 非isDefaultFilter的选项 const defaultKeys = Object.keys(asideMap).filter(key => asideMap[key].isDefaultFilter)// 获取asideMap isDefaultFilter的选项 showKeys.unshift(...defaultKeys) */ - let sortKeyList: any = []; - configStore.getFilterConfig.map((item: any) => { - sortKeyList.push(item?.id); - }); - const showKeys = [...sortKeyList]; - - Object.keys(config).forEach((key) => { - if (key.startsWith("iz") && asideMap[key] !== undefined) - asideVisible[key] = - (showKeys.includes(key) || asideMap[key].isDefaultFilter) && config[key] === "Y"; - }); - if (customObjRef.value) { - // 赋值 - Object.keys(customObjRef.value).map((key) => { - if (asideMap.hasOwnProperty(key)) { - const str = key.toLowerCase(); - // console.log("customObjRef.value[str]1111111111111", customObjRef.value[str]); - if (str == "izsimilarity") { - if (typeof customObjRef.value[str] == "string") { - customObjRef.value[str] = customObjRef.value[str].split(","); + const sortKeyList: any = [] + configStore.getFilterConfig.map((item: any) => { + sortKeyList.push(item?.id) + return item + }) + const showKeys = [...sortKeyList] + + Object.keys(config).forEach((key) => { + if (key.startsWith('iz') && asideMap[key] !== undefined) { + asideVisible[key] + = (showKeys.includes(key) || asideMap[key].isDefaultFilter) + && config[key] === 'Y' + } + }) + if (customObjRef.value) { + // 赋值 + Object.keys(customObjRef.value).map((key) => { + // TODO hasOwnProperty避免直接调用 + // if (asideMap.hasOwnProperty(key)) { + if (Object.prototype.hasOwnProperty.call(customObjRef.value, key)) { + const str = key.toLowerCase() + // console.log("customObjRef.value[str]1111111111111", customObjRef.value[str]); + if (str == 'izsimilarity') { + if (typeof customObjRef.value[str] == 'string') + customObjRef.value[str] = customObjRef.value[str].split(',') + + asideValue[key] = customObjRef.value[str] // 赋值 + console.log('相似度2222222222', asideValue[key]) } - asideValue[key] = customObjRef.value[str]; // 赋值 - console.log("相似度2222222222", asideValue[key]); - } else if (str == "izyear") { - if (typeof customObjRef.value[str] == "string") { - let time = customObjRef.value[str].split("-"); - time[0] = new Date(time[0]).getTime(); - time[1] = new Date(time[1]).getTime(); - customObjRef.value[str] = time; + else if (str == 'izyear') { + if (typeof customObjRef.value[str] == 'string') { + const time = customObjRef.value[str].split('-') + time[0] = new Date(time[0]).getTime() + time[1] = new Date(time[1]).getTime() + customObjRef.value[str] = time + } + asideValue[key] = customObjRef.value[str] // 赋值 + console.log('时间2222222222', asideValue[key]) } - asideValue[key] = customObjRef.value[str]; // 赋值 - console.log("时间2222222222", asideValue[key]); - } else if (str != "izsimilarity" && str != "izyear" && customObjRef.value[str]) { - console.log("customObjRef.value[str]222222", customObjRef.value[str]); - // let list = customObjRef.value[str].split(','); - // console.log("list222222", list); - asideValue[key] = customObjRef.value[str]; // 赋值 - } else { - asideValue[key] = null; + else if ( + str != 'izsimilarity' + && str != 'izyear' + && customObjRef.value[str] + ) { + console.log('customObjRef.value[str]222222', customObjRef.value[str]) + // let list = customObjRef.value[str].split(','); + // console.log("list222222", list); + asideValue[key] = customObjRef.value[str] // 赋值 + } + else { + asideValue[key] = null + } + // asideMap[str].defaultValue = customObjRef.value[str];// 赋值 } - // asideMap[str].defaultValue = customObjRef.value[str];// 赋值 - } - }); - customTempObjRef.value = customObjRef.value; - console.log("asideValue直接处理后的结果", asideValue); - console.log("customTempObjRef.value", customTempObjRef.value); - let tempobj = cloneDeep(asideValue); - console.log("tempObj", tempobj); - configStore.setAsideValue(tempobj); - } - // console.log("showKeys", showKeys); - const items = showKeys.reduce((acc, key) => { - const currentData = asideMap[key]; - const render = currentData?.render; - if (render !== false) { - const str = key?.toLowerCase(); - - const o = { - key: str, - config: asideMap[str], - }; - return [...acc, o]; - } else { - return acc; + return key + }) + customTempObjRef.value = customObjRef.value + console.log('asideValue直接处理后的结果', asideValue) + console.log('customTempObjRef.value', customTempObjRef.value) + const tempobj = cloneDeep(asideValue) + console.log('tempObj', tempobj) + configStore.setAsideValue(tempobj) } - }, []); - console.log("showItems=================================", items); - showItems.value = items; - configFilterRef.value = configStore.getFilterConfig; -}); - + // console.log("showKeys", showKeys); + const items = showKeys.reduce((acc, key) => { + const currentData = asideMap[key] + const render = currentData?.render + if (render !== false) { + const str = key?.toLowerCase() + + const o = { + key: str, + config: asideMap[str], + } + return [...acc, o] + } + else { + return acc + } + }, []) + console.log('showItems=================================', items) + showItems.value = items + configFilterRef.value = configStore.getFilterConfig + }) }) -const asideEnter = ref(false); +const asideEnter = ref(false) const showCollapse = computed(() => { - return collapse.value ? true : asideEnter.value; -}); + return collapse.value ? true : asideEnter.value +}) -const showSearch = ref(false); +const showSearch = ref(false) function setShowSearch(value: boolean) { - showSearch.value = value; + showSearch.value = value } -const newFilterOk = () => { +function newFilterOk() { filterModalRef.value.query( filterModalRef.value.pagination.page, - filterModalRef.value.pagination.pageSize - ); - filterModalRef.value.showModal(); -}; + filterModalRef.value.pagination.pageSize, + ) + filterModalRef.value.showModal() +} // 滚动容器,让key对应模块处于可视区域 function scrollHandler(key: string) { - const element = document.querySelector(`#${key}`); - element?.scrollIntoView(true); + const element = document.querySelector(`#${key}`) + element?.scrollIntoView(true) } // 选择某个过滤配置,刷新图片墙 -> 筛选搜索条件 async function filterHandler(searchId: string) { // emitter.emit('filter', searchId) - const res = await getFilterList({ userSearchId: searchId }); + const res = await getFilterList({ userSearchId: searchId }) // console.log("顾虑结果", res); - if (res.code == "OK") { - let obj = res.data; - customObjRef.value = res.data; - let showKeys: any[] = []; + if (res.code == 'OK') { + const obj = res.data + customObjRef.value = res.data + const showKeys: any[] = [] Object.keys(obj).map((key) => { - if (asideMap.hasOwnProperty(key)) { - showKeys.push(key); - } - }); + // TODO hasOwnProperty避免直接调用 + // if (asideMap.hasOwnProperty(key)) { + if (Object.prototype.hasOwnProperty.call(asideMap, key)) + showKeys.push(key) + + return key + }) // console.log(showKeys); - configStore.setCustomConfig(showKeys); + configStore.setCustomConfig(showKeys) } } function editFilter(filter: any) { - const modal = unref(newFilterModalRef)! as any; - modal.showModal(); - modal.edit(filter); + const modal = unref(newFilterModalRef)! as any + modal.showModal() + modal.edit(filter) } function updateComponent(key, e) { - console.log("跟新值", key, e); - console.log("tempAsideValue跟新值", configStore.getAsideValue, asideValue); + console.log('跟新值', key, e) + console.log('tempAsideValue跟新值', configStore.getAsideValue, asideValue) // let tempAsideValue = configStore.getAsideValue || asideValue; - let tempobj = cloneDeep(asideValue); - console.log(tempobj, "tempobj"); - tempobj[key] = e; - console.log(tempobj, "tempobj After"); - customObjRef.value = tempobj; + const tempobj = cloneDeep(asideValue) + console.log(tempobj, 'tempobj') + tempobj[key] = e + console.log(tempobj, 'tempobj After') + customObjRef.value = tempobj // asideValue = Object.assign({}, asideValue, tempobj); - console.log("asideValue跟新值", tempobj); - configStore.setAsideValue(tempobj); + console.log('asideValue跟新值', tempobj) + configStore.setAsideValue(tempobj) } -const handleOk = (item: any) => { - console.log("handleOk", item); +function handleOk(item: any) { + console.log('handleOk', item) if (item) { - AdvanceFilterRef.value.setCurrentlySelectedAdvanced(item.searchname); - filterHandler(item.id); - } else { - AdvanceFilterRef.value.setCurrentlySelectedAdvanced("高级筛选"); - filterHandler(""); + AdvanceFilterRef.value.setCurrentlySelectedAdvanced(item.searchname) + filterHandler(item.id) + } + else { + AdvanceFilterRef.value.setCurrentlySelectedAdvanced('高级筛选') + filterHandler('') } -}; +} // watch(asideValue, (newVal) => { // console.log("asideValue处理后", newVal); @@ -297,22 +315,22 @@ const handleOk = (item: any) => { @@ -321,10 +339,10 @@ const handleOk = (item: any) => { ref="filterModalRef" @edit-filter="editFilter" @show-new-filter="showModal(newFilterModalRef)" - @handleOk="handleOk" + @handle-ok="handleOk" /> - + diff --git a/src/views/home/aside/comp/Search.vue b/src/views/home/aside/comp/Search.vue index 05278a0..8f226ac 100644 --- a/src/views/home/aside/comp/Search.vue +++ b/src/views/home/aside/comp/Search.vue @@ -1,16 +1,12 @@