Browse Source

fix: 文档管理的一些修改

master
taqi be 1 month ago
parent
commit
ac3f0d60a7
  1. 19
      src/components/dashboard/Edfs-context-menu/index.vue
  2. 3
      src/pages/fileDoc/components/markdownDrawer.vue
  3. 43
      src/pages/fileDoc/index.vue

19
src/components/dashboard/Edfs-context-menu/index.vue

@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
:class="{ active: menuStatus.show }"
v-show="menuStatus.show"
>
<slot name="menu" :menuData></slot>
<slot name="menu" :eventData :menuData></slot>
</div>
</Teleport>
</div>
@ -19,14 +19,15 @@ @@ -19,14 +19,15 @@
import { useWindowResize } from '@/tools/common/hooks'
import { useSlots } from 'vue'
interface Props {
eventSourceClass: string
menuList?: any
disabledEmpty?: boolean
eventSourceClass: string //
menuList?: any //
disabledEmpty?: boolean //
}
const slotMenu = !!useSlots().menu
const emit = defineEmits<{
visibleChange: [boolean, HTMLElement | null]
visibleChange: [boolean, HTMLElement | null],
beforeContextmenu:[any]
}>()
const props = withDefaults(defineProps<Props>(), {
@ -42,9 +43,7 @@ const menuStatus = reactive({ @@ -42,9 +43,7 @@ const menuStatus = reactive({
})
const menuData = computed(() => {
// if (!props.menuList && !eventData.value)
// console.warn('menuList 使v-setItem')
return props?.menuList || eventData?.value || {}
return props?.menuList ?? []
})
watch(
@ -55,6 +54,7 @@ watch( @@ -55,6 +54,7 @@ watch(
)
async function onContextmenu(e: any) {
eventData.value = null
menuStatus.show = false
e.preventDefault()
@ -67,6 +67,9 @@ async function onContextmenu(e: any) { @@ -67,6 +67,9 @@ async function onContextmenu(e: any) {
}
const data = sourceElement ? (sourceElement as any)._vItem : 'custom'
eventData.value = data
emit('before-contextmenu', eventData.value)
await nextTick()
currentElement.value = sourceElement
setMenuPosition(e)
}

3
src/pages/fileDoc/components/markdownDrawer.vue

@ -11,7 +11,7 @@ @@ -11,7 +11,7 @@
<div class="header">
<span>{{ data.fileName }}</span>
<div>
<EDFSButton innerText="保存为草稿" type="info" @click="onSave(1)" />
<EDFSButton innerText="保存为草稿" type="info" v-if="!isRootMd" @click="onSave(1)" />
<EDFSButton innerText="发布文章" type="primary" @click="onSave(0)" />
</div>
</div>
@ -32,6 +32,7 @@ import 'vditor/dist/index.css' @@ -32,6 +32,7 @@ import 'vditor/dist/index.css'
import { vditorToolbar } from '../utils'
interface Props {
data: ContentType & { fileName: string }
isRootMd: boolean
}
const emits = defineEmits(['on-save'])
const props = withDefaults(defineProps<Props>(), {})

43
src/pages/fileDoc/index.vue

@ -17,6 +17,8 @@ @@ -17,6 +17,8 @@
:disabledEmpty="false"
@visibleChange="onVisibleChange"
ref="contextMenuRef"
:menuList="dropdownMenu"
@beforeContextmenu="onBeforeContextmenu"
>
<div class="file-list">
<div v-for="item in dataList" :key="item.id" @click="onFileOpen(item)">
@ -56,11 +58,11 @@ @@ -56,11 +58,11 @@
</div>
</div>
</div>
<template #menu="{ menuData }">
<template #menu="{ eventData, menuData }">
<div
v-for="menu in dropdownMenu"
v-for="menu in menuData"
:key="menu.command"
@click="onCommand(menu.command, menuData)"
@click="onCommand(menu.command, eventData)"
>
<img
v-if="menu?.icon"
@ -80,6 +82,7 @@ @@ -80,6 +82,7 @@
v-model="isShowMdDrawer"
v-if="isShowMdDrawer"
:data="curMarkdown"
:isRootMd="isRootMd"
@onSave="onSaveMd"
/>
</template>
@ -117,6 +120,9 @@ import EdfsContextMenu from '@/components/dashboard/Edfs-context-menu/index.vue' @@ -117,6 +120,9 @@ import EdfsContextMenu from '@/components/dashboard/Edfs-context-menu/index.vue'
import markdownDrawer from './components/markdownDrawer.vue'
const dropdownMenu = computed(() => {
if (isRootMd.value) {
return fileDropdownMenu.filter(v => v.command === 'open')
}
return menuTarget.value
? fileDropdownMenu
: currentFolderId.value === 0
@ -134,6 +140,10 @@ watch( @@ -134,6 +140,10 @@ watch(
}
)
const isRootMd = computed(
() => currentMenu.value?.type === floeType.file && currentFolderId.value === 0
)
const dataList = ref<any>([])
const loading = ref(false)
async function loadData(id: number = 0) {
@ -195,8 +205,9 @@ function onNewMarkdown() { @@ -195,8 +205,9 @@ function onNewMarkdown() {
dataList.value.push(markdown)
onRename(markdown)
}
const curCommand = ref('')
function onCommand(command: string, item: any) {
curCommand.value = command
switch (command) {
case 'delete':
onDelete(item)
@ -223,6 +234,12 @@ function onVisibleChange(visible: boolean, currentElement: HTMLElement | null) { @@ -223,6 +234,12 @@ function onVisibleChange(visible: boolean, currentElement: HTMLElement | null) {
menuTarget.value = currentElement
}
const currentMenu = ref<any>(null)
function onBeforeContextmenu(item: any) {
currentMenu.value = item
}
function onCrumb(item: any) {
const isLast = breadcrumbList.value[breadcrumbList.value.length - 1].id === item.id
if (isLast) return
@ -251,19 +268,25 @@ function setInputRefs(el: any, id: number) { @@ -251,19 +268,25 @@ function setInputRefs(el: any, id: number) {
const editFileName = ref('')
async function onSaveRename(item: any) {
if (!item.isEdit) return
item.name = editFileName.value
await nextTick()
const find = findItem(item.id)
if (!find.isEdit) return
await nextTick()
find.isEdit = false
await onSaveFile(item)
if (!editFileName.value.endsWith('.md')) {
editFileName.value += '.md'
}
if (find.name !== editFileName.value) {
find.name = editFileName.value
await onSaveFile(find)
}
editFileName.value = ''
}
async function onRename(item: any) {
if (!item) return
const find = findItem(item.id)
find.isEdit = true
editFileName.value = item.name
editFileName.value = find.name
await nextTick()
editInputRefs.value[`editInputRef_${item.id}`].focus()
editInputRefs.value[`editInputRef_${item.id}`].select()
@ -321,7 +344,7 @@ async function saveFile(isAdd: boolean, item: any) { @@ -321,7 +344,7 @@ async function saveFile(isAdd: boolean, item: any) {
let res
if (isAdd) {
res = await createdFile({
name: item.name + '.md',
name: item.name,
parentId: currentFolderId.value,
isDraft: 1,
path: getPath(),

Loading…
Cancel
Save