feat: 添加miaoMessageProvider
This commit is contained in:
1 parent
de2e53cbcf
commit
a34e27cc65
4 files changed
+193
-33
No files matched your search
@@ -1,18 +1,21 @@
|
||||
<template>
|
||||
<div class="codemirror-container" ref="rootRef" :class="`codemirror-container-${theme}`">
|
||||
<div class="codemirror-container-top">
|
||||
<div class="codemirror-container-btn codemirror-container-btn-save" @click="handleSave">保存</div>
|
||||
<div class="codemirror-container-btn codemirror-container-btn-save" @click="handleReset">恢复到上次保存</div>
|
||||
<miao-message-provider ref="miaoMessage">
|
||||
<div class="codemirror-container" ref="rootRef" :class="`codemirror-container-${theme}`">
|
||||
<div class="codemirror-container-top">
|
||||
<div class="codemirror-container-btn codemirror-container-btn-save" @click="handleSave">保存</div>
|
||||
<div class="codemirror-container-btn codemirror-container-btn-save" @click="handleReset">恢复到上次保存</div>
|
||||
</div>
|
||||
<div class="codemirror-container-main">
|
||||
<NScrollbar style="max-height: calc( 100% );">
|
||||
<codemirror v-model="codeData" :extensions="extensions" />
|
||||
</NScrollbar>
|
||||
</div>
|
||||
</div>
|
||||
<div class="codemirror-container-main">
|
||||
<NScrollbar style="max-height: calc( 100% );">
|
||||
<codemirror v-model="codeData" :extensions="extensions" />
|
||||
</NScrollbar>
|
||||
</div>
|
||||
</div>
|
||||
</miao-message-provider>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import miaoMessageProvider from '@/components/miaoMessageProvider.vue'
|
||||
import { VirtualFile } from '@/class/VirtualDirectory'
|
||||
import useMiaoFetchApi from '@/hooks/useMiaoFetchApi'
|
||||
import { onMounted, ref } from 'vue'
|
||||
@@ -25,6 +28,7 @@ const currentFiles = defineModel<VirtualFile[]>('currentFiles', {
|
||||
required: true
|
||||
})
|
||||
|
||||
const miaoMessage = ref<InstanceType<typeof miaoMessageProvider>>()
|
||||
const vFile = ref<VirtualFile>()
|
||||
const rootRef = ref<HTMLDivElement>()
|
||||
// const _key = ref(Math.random())
|
||||
@@ -36,6 +40,10 @@ const theme = ref<'light' | 'dark'>('light')
|
||||
|
||||
const handleSave = async () => {
|
||||
if (bakData.value === codeData.value || !vFile.value) {
|
||||
miaoMessage.value?.message('内容未改动', {
|
||||
timeout: 3000,
|
||||
type: 'info'
|
||||
})
|
||||
return
|
||||
}
|
||||
const parentDir = vFile.value?.parent
|
||||
@@ -45,8 +53,14 @@ const handleSave = async () => {
|
||||
)
|
||||
const file = new File([new Blob([codeData.value ?? ''])], vFile.value.name)
|
||||
bakData.value = codeData.value
|
||||
miaoFetchApi.upload(file, parentDir)
|
||||
const { response } = miaoFetchApi.upload(file, parentDir)
|
||||
false && miaoFetchApi.upload(file_bak, parentDir)
|
||||
await response
|
||||
miaoMessage.value?.message('保存成功', {
|
||||
timeout: 5000,
|
||||
type: 'success'
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
const handleReset = async () => {
|
||||
@@ -166,7 +180,7 @@ onMounted(async () => {
|
||||
}
|
||||
|
||||
.codemirror-container-main {
|
||||
height: calc( 100% - 25px );
|
||||
height: calc(100% - 25px);
|
||||
position: relative;
|
||||
}
|
||||
}
|
||||
|
||||
+23
-17
@@ -65,7 +65,7 @@ const emit = defineEmits<{
|
||||
exit: []
|
||||
}>()
|
||||
|
||||
const popupInput = ref()
|
||||
const popupInput = ref<InstanceType<typeof MiaoPopupInput>>()
|
||||
// 是否显示模态框
|
||||
const showModel = ref(0)
|
||||
const searchText = ref<string>('')
|
||||
@@ -210,9 +210,9 @@ const setCurrentDirectory = async (virtualDirectory: VirtualDirectory) => {
|
||||
handleSearchReset()
|
||||
nextTick(() => {
|
||||
miaoDirectoryItemRef.value.scrollTo({
|
||||
top: 0,
|
||||
behavior: "instant"
|
||||
})
|
||||
top: 0,
|
||||
behavior: "instant"
|
||||
})
|
||||
})
|
||||
}
|
||||
currentDirectories.value[0] = virtualDirectory
|
||||
@@ -302,9 +302,8 @@ const handleItemDelete = async (_item: VirtualDirectory | VirtualFile) => {
|
||||
}
|
||||
|
||||
const handleItemRename = async (item: VirtualDirectory | VirtualFile) => {
|
||||
const popupRes = await popupInput.value.popup({
|
||||
const popupRes = await popupInput.value?.popup({
|
||||
title: '重命名',
|
||||
showInput: true,
|
||||
inputValue: item.name,
|
||||
inputProps: {
|
||||
placeholder: item.name,
|
||||
@@ -322,10 +321,13 @@ const handleItemRename = async (item: VirtualDirectory | VirtualFile) => {
|
||||
},
|
||||
],
|
||||
})
|
||||
if (popupRes.key === false) {
|
||||
if (popupRes?.key === false) {
|
||||
return
|
||||
}
|
||||
const newName = popupRes?.text
|
||||
if (!newName) {
|
||||
return
|
||||
}
|
||||
const newName = popupRes.text
|
||||
const { response } = miaoFetchApi.rename(item, newName, {
|
||||
retry: 5,
|
||||
})
|
||||
@@ -362,7 +364,7 @@ const handleDropVDirectory = async (vDirs: VirtualDirectory[]) => {
|
||||
if (currentDirectory.value.getParents.includes(vDir)) {
|
||||
return
|
||||
}
|
||||
if(vDir.parent === currentDirectory.value) {
|
||||
if (vDir.parent === currentDirectory.value) {
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -413,9 +415,8 @@ const handlePickFilesUpload = async () => {
|
||||
}
|
||||
|
||||
const handleAddNewItem = async () => {
|
||||
const popupRes = await popupInput.value.popup({
|
||||
const popupRes = await popupInput.value?.popup({
|
||||
title: '新建文件/文件夹',
|
||||
showInput: true,
|
||||
inputProps: {
|
||||
placeholder: '',
|
||||
},
|
||||
@@ -438,12 +439,16 @@ const handleAddNewItem = async () => {
|
||||
],
|
||||
})
|
||||
// todo: 上传前如重名文件夹等等的错误提前检查
|
||||
if (popupRes.key === 'cancel' || popupRes.text === '') {
|
||||
if (popupRes?.key === 'cancel' || popupRes?.text === '') {
|
||||
return
|
||||
}
|
||||
const _currDir = currentDirectory.value
|
||||
const name = popupRes.text
|
||||
const opType: 'file' | 'dir' = popupRes.key
|
||||
const name = popupRes?.text
|
||||
if (!name) {
|
||||
return
|
||||
}
|
||||
// @ts-ignore
|
||||
const opType: 'file' | 'dir' = popupRes?.key
|
||||
if (opType === 'dir') {
|
||||
const res = await miaoFetchApi.mkdir(currentDirectory.value, name)
|
||||
if (res.message === 'success') {
|
||||
@@ -467,9 +472,8 @@ const handleItemSelect = (item: VirtualDirectory | VirtualFile) => {
|
||||
}
|
||||
|
||||
const handleSearch = async () => {
|
||||
const popupRes = await popupInput.value.popup({
|
||||
const popupRes = await popupInput.value?.popup({
|
||||
title: '搜索当前文件夹',
|
||||
showInput: true,
|
||||
inputValue: searchText.value,
|
||||
inputProps: {
|
||||
placeholder: '',
|
||||
@@ -492,7 +496,9 @@ const handleSearch = async () => {
|
||||
},
|
||||
],
|
||||
})
|
||||
console.log(popupRes)
|
||||
if (!popupRes) {
|
||||
return
|
||||
}
|
||||
if (popupRes.key === 'search') {
|
||||
searchText.value = popupRes.text
|
||||
} else if (popupRes.key === 'reset') {
|
||||
|
||||
Reference in new issue
Block a user