perf: 完善首页预览功能

This commit is contained in:
奔跑的面条 2022-08-30 15:03:25 +08:00
parent 52009a415b
commit 171e0aa408
5 changed files with 29 additions and 28 deletions

View File

@ -205,9 +205,9 @@ export const loginCheck = () => {
* * * *
* @returns * @returns
*/ */
export const previewPath = () => { export const previewPath = (id?: string | number) => {
const { origin, pathname } = document.location const { origin, pathname } = document.location
const path = fetchPathByName(PreviewEnum.CHART_PREVIEW_NAME, 'href') const path = fetchPathByName(PreviewEnum.CHART_PREVIEW_NAME, 'href')
const previewPath = `${origin}${pathname}${path}/${fetchRouteParamsLocation()}` const previewPath = `${origin}${pathname}${path}/${id || fetchRouteParamsLocation()}`
return previewPath return previewPath
} }

View File

@ -16,7 +16,7 @@ export const getSessionStorageInfo = async () => {
) )
// 是否本地预览 // 是否本地预览
if (!storageList) { if (!storageList || storageList.findIndex(e => e.id === id.toString()) === -1) {
// 接口调用 // 接口调用
const res = await fetchProjectApi({ projectId: id }) as unknown as MyResponseType const res = await fetchProjectApi({ projectId: id }) as unknown as MyResponseType
if (res.code === ResultEnum.SUCCESS) { if (res.code === ResultEnum.SUCCESS) {

View File

@ -7,7 +7,7 @@
<mac-os-control-btn <mac-os-control-btn
class="top-btn" class="top-btn"
:hidden="['remove']" :hidden="['remove']"
@close="deleteHanlde" @close="deleteHandle"
@resize="resizeHandle" @resize="resizeHandle"
></mac-os-control-btn> ></mac-os-control-btn>
</div> </div>
@ -98,7 +98,7 @@ const {
SendIcon SendIcon
} = icon.ionicons5 } = icon.ionicons5
const emit = defineEmits(['delete', 'resize', 'edit', 'release']) const emit = defineEmits(['preview', 'delete', 'resize', 'edit', 'release'])
const props = defineProps({ const props = defineProps({
cardData: Object as PropType<Chartype> cardData: Object as PropType<Chartype>
@ -165,8 +165,11 @@ const selectOptions = ref([
const handleSelect = (key: string) => { const handleSelect = (key: string) => {
switch (key) { switch (key) {
case 'preview':
previewHandle()
break
case 'delete': case 'delete':
deleteHanlde() deleteHandle()
break break
case 'release': case 'release':
releaseHandle() releaseHandle()
@ -177,8 +180,13 @@ const handleSelect = (key: string) => {
} }
} }
//
const previewHandle = () => {
emit('preview', props.cardData)
}
// //
const deleteHanlde = () => { const deleteHandle = () => {
emit('delete', props.cardData) emit('delete', props.cardData)
} }

View File

@ -1,6 +1,6 @@
import { ref } from 'vue' import { ref } from 'vue'
import { ChartEnum } from '@/enums/pageEnum' import { ChartEnum } from '@/enums/pageEnum'
import { fetchPathByName, routerTurnByPath } from '@/utils' import { fetchPathByName, routerTurnByPath, openNewWindow, previewPath } from '@/utils'
import { Chartype } from '../../../index.d' import { Chartype } from '../../../index.d'
export const useModalDataInit = () => { export const useModalDataInit = () => {
const modalShow = ref<boolean>(false) const modalShow = ref<boolean>(false)
@ -12,25 +12,31 @@ export const useModalDataInit = () => {
modalData.value = null modalData.value = null
} }
// 打开 modal // 缩放处理
const resizeHandle = (cardData: Chartype) => { const resizeHandle = (cardData: Chartype) => {
if (!cardData) return if (!cardData) return
modalShow.value = true modalShow.value = true
modalData.value = cardData modalData.value = cardData
} }
// 打开 modal // 编辑处理
const editHandle = (cardData: Chartype) => { const editHandle = (cardData: Chartype) => {
if (!cardData) return if (!cardData) return
const path = fetchPathByName(ChartEnum.CHART_HOME_NAME, 'href') const path = fetchPathByName(ChartEnum.CHART_HOME_NAME, 'href')
routerTurnByPath(path, [cardData.id], undefined, true) routerTurnByPath(path, [cardData.id], undefined, true)
} }
// 预览处理
const previewHandle = (cardData: Chartype) => {
openNewWindow(previewPath(cardData.id))
}
return { return {
modalData, modalData,
modalShow, modalShow,
closeModal, closeModal,
resizeHandle, resizeHandle,
editHandle editHandle,
previewHandle
} }
} }

View File

@ -6,15 +6,11 @@
</div> </div>
<!-- 列表 --> <!-- 列表 -->
<div v-show="!loading"> <div v-show="!loading">
<n-grid <n-grid :x-gap="20" :y-gap="20" cols="2 s:2 m:3 l:4 xl:4 xxl:4" responsive="screen">
:x-gap="20"
:y-gap="20"
cols="2 s:2 m:3 l:4 xl:4 xxl:4"
responsive="screen"
>
<n-grid-item v-for="(item, index) in list" :key="item.id"> <n-grid-item v-for="(item, index) in list" :key="item.id">
<project-items-card <project-items-card
:cardData="item" :cardData="item"
@preview="previewHandle"
@resize="resizeHandle" @resize="resizeHandle"
@delete="deleteHandle(item)" @delete="deleteHandle(item)"
@release="releaseHandle(item, index)" @release="releaseHandle(item, index)"
@ -56,17 +52,8 @@ import { useModalDataInit } from './hooks/useModal.hook'
import { useDataListInit } from './hooks/useData.hook' import { useDataListInit } from './hooks/useData.hook'
const { CopyIcon, EllipsisHorizontalCircleSharpIcon } = icon.ionicons5 const { CopyIcon, EllipsisHorizontalCircleSharpIcon } = icon.ionicons5
const { modalData, modalShow, closeModal, resizeHandle, editHandle } = const { modalData, modalShow, closeModal, previewHandle, resizeHandle, editHandle } = useModalDataInit()
useModalDataInit() const { loading, paginat, list, changeSize, changePage, releaseHandle, deleteHandle } = useDataListInit()
const {
loading,
paginat,
list,
changeSize,
changePage,
releaseHandle,
deleteHandle,
} = useDataListInit()
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>