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

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

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

43
src/pages/fileDoc/index.vue

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

Loading…
Cancel
Save