mirror of
https://github.com/continew-org/continew-admin-ui.git
synced 2025-09-09 20:57:17 +08:00
Merge branch 'dev' of https://gitee.com/continew/continew-admin-ui into dev
This commit is contained in:
@@ -13,3 +13,9 @@ VITE_BASE = '/'
|
|||||||
|
|
||||||
# 是否开启开发者工具
|
# 是否开启开发者工具
|
||||||
VITE_OPEN_DEVTOOLS = false
|
VITE_OPEN_DEVTOOLS = false
|
||||||
|
|
||||||
|
# 是否开启KKFileView
|
||||||
|
FILE_OPEN_PREVIEW = true
|
||||||
|
|
||||||
|
# KKFileView服务器地址
|
||||||
|
FILE_VIEW_SERVER_URL = 'http://192.168.122.209:8012'
|
@@ -9,3 +9,9 @@ VITE_API_WS_URL = 'wss://api.continew.top'
|
|||||||
|
|
||||||
# 地址前缀
|
# 地址前缀
|
||||||
VITE_BASE = '/'
|
VITE_BASE = '/'
|
||||||
|
|
||||||
|
# 是否开启KKFileView
|
||||||
|
FILE_OPEN_PREVIEW = false
|
||||||
|
|
||||||
|
# KKFileView服务器地址
|
||||||
|
FILE_VIEW_SERVER_URL = 'http://localhost:8012'
|
@@ -14,3 +14,9 @@ VITE_BASE = '/test'
|
|||||||
|
|
||||||
# 是否开启开发者工具
|
# 是否开启开发者工具
|
||||||
VITE_OPEN_DEVTOOLS = true
|
VITE_OPEN_DEVTOOLS = true
|
||||||
|
|
||||||
|
# 是否开启KKFileView
|
||||||
|
FILE_OPEN_PREVIEW = false
|
||||||
|
|
||||||
|
# KKFileView服务器地址
|
||||||
|
FILE_VIEW_SERVER_URL = 'http://localhost:8012'
|
9578
pnpm-lock.yaml
generated
9578
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
2
src/types/env.d.ts
vendored
2
src/types/env.d.ts
vendored
@@ -5,6 +5,8 @@ interface ImportMetaEnv {
|
|||||||
readonly VITE_API_PREFIX: string
|
readonly VITE_API_PREFIX: string
|
||||||
readonly VITE_API_BASE_URL: string
|
readonly VITE_API_BASE_URL: string
|
||||||
readonly VITE_BASE: string
|
readonly VITE_BASE: string
|
||||||
|
readonly FILE_OPEN_PREVIEW: string
|
||||||
|
readonly FILE_VIEW_SERVER_URL: string
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ImportMeta {
|
interface ImportMeta {
|
||||||
|
@@ -22,7 +22,6 @@ export function downloadByUrl({
|
|||||||
url: string
|
url: string
|
||||||
target?: '_self' | '_blank'
|
target?: '_self' | '_blank'
|
||||||
fileName?: string
|
fileName?: string
|
||||||
isSameHost: boolean
|
|
||||||
}): Promise<boolean> {
|
}): Promise<boolean> {
|
||||||
// 是否同源
|
// 是否同源
|
||||||
const isSameHost = new URL(url).host === location.host
|
const isSameHost = new URL(url).host === location.host
|
||||||
|
@@ -261,3 +261,21 @@ export const copyText = (text: any) => {
|
|||||||
document.body.removeChild(textarea)
|
document.body.removeChild(textarea)
|
||||||
Message.success('复制成功')
|
Message.success('复制成功')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @desc 文件的转换base64 */
|
||||||
|
export const fileToBase64 = (file: File): Promise<string> => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const reader = new FileReader()
|
||||||
|
reader.onload = () => {
|
||||||
|
if (reader.result) {
|
||||||
|
resolve(reader.result.toString())
|
||||||
|
} else {
|
||||||
|
reject(new Error('文件转base64失败'))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reader.onerror = (error) => {
|
||||||
|
reject(error)
|
||||||
|
}
|
||||||
|
reader.readAsDataURL(file)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@@ -106,11 +106,11 @@ import {
|
|||||||
type SiteConfig,
|
type SiteConfig,
|
||||||
listOption,
|
listOption,
|
||||||
resetOptionValue,
|
resetOptionValue,
|
||||||
updateOption,
|
updateOption
|
||||||
uploadFile
|
|
||||||
} from '@/apis'
|
} from '@/apis'
|
||||||
import { useAppStore } from '@/stores'
|
import { useAppStore } from '@/stores'
|
||||||
import { useForm } from '@/hooks'
|
import { useForm } from '@/hooks'
|
||||||
|
import { fileToBase64 } from '@/utils'
|
||||||
|
|
||||||
defineOptions({ name: 'BasicSetting' })
|
defineOptions({ name: 'BasicSetting' })
|
||||||
|
|
||||||
@@ -212,15 +212,16 @@ const onResetValue = () => {
|
|||||||
// 上传 favicon
|
// 上传 favicon
|
||||||
const handleUploadFavicon = (options: RequestOption) => {
|
const handleUploadFavicon = (options: RequestOption) => {
|
||||||
const controller = new AbortController()
|
const controller = new AbortController()
|
||||||
; (async function requestWrap() {
|
;(async function requestWrap() {
|
||||||
const { onProgress, onError, onSuccess, fileItem, name = 'file' } = options
|
const { onProgress, onError, onSuccess, fileItem } = options
|
||||||
onProgress(20)
|
onProgress(20)
|
||||||
const formData = new FormData()
|
if (!fileItem.file) {
|
||||||
formData.append(name as string, fileItem.file as Blob)
|
return
|
||||||
uploadFile(formData)
|
}
|
||||||
|
fileToBase64(fileItem.file).then()
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
onSuccess(res)
|
onSuccess()
|
||||||
form.SITE_FAVICON = res.data.url
|
form.SITE_FAVICON = res
|
||||||
Message.success('上传成功')
|
Message.success('上传成功')
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
@@ -242,15 +243,16 @@ const handleChangeFavicon = (_: any, currentFile: any) => {
|
|||||||
// 上传 Logo
|
// 上传 Logo
|
||||||
const handleUploadLogo = (options: RequestOption) => {
|
const handleUploadLogo = (options: RequestOption) => {
|
||||||
const controller = new AbortController()
|
const controller = new AbortController()
|
||||||
; (async function requestWrap() {
|
;(async function requestWrap() {
|
||||||
const { onProgress, onError, onSuccess, fileItem, name = 'file' } = options
|
const { onProgress, onError, onSuccess, fileItem } = options
|
||||||
onProgress(20)
|
onProgress(20)
|
||||||
const formData = new FormData()
|
if (!fileItem.file) {
|
||||||
formData.append(name as string, fileItem.file as Blob)
|
return
|
||||||
uploadFile(formData)
|
}
|
||||||
|
fileToBase64(fileItem.file).then()
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
onSuccess(res)
|
onSuccess()
|
||||||
form.SITE_LOGO = res.data.url
|
form.SITE_LOGO = res
|
||||||
Message.success('上传成功')
|
Message.success('上传成功')
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
101
src/views/system/file/main/FileMain/FilePreview.vue
Normal file
101
src/views/system/file/main/FileMain/FilePreview.vue
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<a-modal
|
||||||
|
v-model:visible="visible"
|
||||||
|
:title="title"
|
||||||
|
:mask-closable="false"
|
||||||
|
:esc-to-close="false"
|
||||||
|
width="90%"
|
||||||
|
draggable
|
||||||
|
>
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<!-- <a-button type="primary" @click="onPrintFile"> -->
|
||||||
|
<!-- <template #icon> -->
|
||||||
|
<!-- <icon-printer /> -->
|
||||||
|
<!-- </template> -->
|
||||||
|
<!-- <template #default> -->
|
||||||
|
<!-- 打印 -->
|
||||||
|
<!-- </template> -->
|
||||||
|
<!-- </a-button> -->
|
||||||
|
<a-button type="primary" status="success" @click="onDownloadFile">
|
||||||
|
<template #icon>
|
||||||
|
<icon-download />
|
||||||
|
</template>
|
||||||
|
下载
|
||||||
|
</a-button>
|
||||||
|
</div>
|
||||||
|
<div class="iframe-container">
|
||||||
|
<iframe :src="previewUrl" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a-modal>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref } from 'vue'
|
||||||
|
import type { FileItem } from '@/apis'
|
||||||
|
import { encodeByBase64 } from '@/utils/encrypt'
|
||||||
|
|
||||||
|
const emit = defineEmits(['download'])
|
||||||
|
|
||||||
|
const visible = ref(false)
|
||||||
|
const title = ref('文件预览')
|
||||||
|
const fileObject = ref<FileItem>()
|
||||||
|
const isLoading = ref(false)
|
||||||
|
const error = ref('')
|
||||||
|
const previewUrl = ref('')
|
||||||
|
|
||||||
|
// 显示弹窗
|
||||||
|
function show(fileItem: FileItem) {
|
||||||
|
fileObject.value = fileItem
|
||||||
|
visible.value = true
|
||||||
|
title.value = `${fileItem.name}.${fileItem.extension}`
|
||||||
|
isLoading.value = true
|
||||||
|
error.value = ''
|
||||||
|
|
||||||
|
previewUrl.value = `${import.meta.env.FILE_VIEW_SERVER_URL}/onlinePreview?url=${encodeURIComponent(encodeByBase64(fileItem.url))}`
|
||||||
|
}
|
||||||
|
|
||||||
|
// 打印文件
|
||||||
|
// const onPrintFile = () => {
|
||||||
|
// }
|
||||||
|
// 下载文件
|
||||||
|
const onDownloadFile = () => {
|
||||||
|
emit('download', fileObject.value)
|
||||||
|
}
|
||||||
|
defineExpose({
|
||||||
|
show
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
.modal-content {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
height: 80vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
padding: 10px;
|
||||||
|
background: #f5f5f5;
|
||||||
|
border-bottom: 1px solid #e8e8e8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.iframe-container {
|
||||||
|
overflow: hidden;
|
||||||
|
flex: 1;
|
||||||
|
height: calc(80vh - 50px);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
iframe {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
</style>
|
@@ -17,7 +17,8 @@
|
|||||||
</a-dropdown>
|
</a-dropdown>
|
||||||
|
|
||||||
<a-input-group>
|
<a-input-group>
|
||||||
<a-input v-model="queryForm.name" placeholder="请输入文件名" allow-clear style="width: 200px" @change="search" />
|
<a-input v-model="queryForm.name" placeholder="请输入文件名" allow-clear style="width: 200px"
|
||||||
|
@change="search" />
|
||||||
<a-button type="primary" @click="search">
|
<a-button type="primary" @click="search">
|
||||||
<template #icon>
|
<template #icon>
|
||||||
<icon-search />
|
<icon-search />
|
||||||
@@ -30,7 +31,7 @@
|
|||||||
<!-- 右侧区域 -->
|
<!-- 右侧区域 -->
|
||||||
<a-space wrap>
|
<a-space wrap>
|
||||||
<a-button v-if="isBatchMode" :disabled="!selectedFileIds.length" type="primary" status="danger"
|
<a-button v-if="isBatchMode" :disabled="!selectedFileIds.length" type="primary" status="danger"
|
||||||
@click="handleMulDelete">
|
@click="handleMulDelete">
|
||||||
<template #icon>
|
<template #icon>
|
||||||
<icon-delete />
|
<icon-delete />
|
||||||
</template>
|
</template>
|
||||||
@@ -57,16 +58,17 @@
|
|||||||
<!-- 文件列表-宫格模式 -->
|
<!-- 文件列表-宫格模式 -->
|
||||||
<a-spin id="fileMain" class="file-main__list" :loading="loading">
|
<a-spin id="fileMain" class="file-main__list" :loading="loading">
|
||||||
<FileGrid v-show="fileList.length && mode === 'grid'" :data="fileList" :is-batch-mode="isBatchMode"
|
<FileGrid v-show="fileList.length && mode === 'grid'" :data="fileList" :is-batch-mode="isBatchMode"
|
||||||
:selected-file-ids="selectedFileIds" @click="handleClickFile" @select="handleSelectFile"
|
:selected-file-ids="selectedFileIds" @click="handleClickFile" @select="handleSelectFile"
|
||||||
@right-menu-click="handleRightMenuClick"></FileGrid>
|
@right-menu-click="handleRightMenuClick"></FileGrid>
|
||||||
|
|
||||||
<!-- 文件列表-列表模式 -->
|
<!-- 文件列表-列表模式 -->
|
||||||
<FileList v-show="fileList.length && mode === 'list'" :data="fileList" :is-batch-mode="isBatchMode"
|
<FileList v-show="fileList.length && mode === 'list'" :data="fileList" :is-batch-mode="isBatchMode"
|
||||||
:selected-file-ids="selectedFileIds" @click="handleClickFile" @select="handleSelectFile"
|
:selected-file-ids="selectedFileIds" @click="handleClickFile" @select="handleSelectFile"
|
||||||
@right-menu-click="handleRightMenuClick"></FileList>
|
@right-menu-click="handleRightMenuClick"></FileList>
|
||||||
|
|
||||||
<a-empty v-if="!fileList.length" />
|
<a-empty v-if="!fileList.length" />
|
||||||
</a-spin>
|
</a-spin>
|
||||||
|
<FilePreview ref="filePreviewRef" @download="args => onDownload(args)" />
|
||||||
<div class="pagination">
|
<div class="pagination">
|
||||||
<a-pagination v-bind="pagination" />
|
<a-pagination v-bind="pagination" />
|
||||||
</div>
|
</div>
|
||||||
@@ -89,6 +91,7 @@ import { type FileItem, type FileQuery, deleteFile, listFile, uploadFile } from
|
|||||||
import { ImageTypes } from '@/constant/file'
|
import { ImageTypes } from '@/constant/file'
|
||||||
import 'viewerjs/dist/viewer.css'
|
import 'viewerjs/dist/viewer.css'
|
||||||
import { downloadByUrl } from '@/utils/downloadFile'
|
import { downloadByUrl } from '@/utils/downloadFile'
|
||||||
|
import FilePreview from '@/views/system/file/main/FileMain/FilePreview.vue'
|
||||||
|
|
||||||
const FileList = defineAsyncComponent(() => import('./FileList.vue'))
|
const FileList = defineAsyncComponent(() => import('./FileList.vue'))
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
@@ -110,29 +113,43 @@ const {
|
|||||||
pagination,
|
pagination,
|
||||||
search
|
search
|
||||||
} = useTable((page) => listFile({ ...queryForm, ...page }), { immediate: false, paginationOption })
|
} = useTable((page) => listFile({ ...queryForm, ...page }), { immediate: false, paginationOption })
|
||||||
|
const filePreviewRef = ref()
|
||||||
// 点击文件
|
// 点击文件
|
||||||
const handleClickFile = (item: FileItem) => {
|
const handleClickFile = (item: FileItem) => {
|
||||||
if (ImageTypes.includes(item.extension)) {
|
if (JSON.parse(import.meta.env.FILE_OPEN_PREVIEW)) {
|
||||||
if (item.url) {
|
filePreviewRef.value.show(item)
|
||||||
const imgList: string[] = fileList.value.filter((i) => ImageTypes.includes(i.extension)).map((a) => a.url || '')
|
} else {
|
||||||
const index = imgList.findIndex((i) => i === item.url)
|
if (ImageTypes.includes(item.extension)) {
|
||||||
if (imgList.length) {
|
if (item.url) {
|
||||||
viewerApi({
|
const imgList: string[] = fileList.value.filter((i) => ImageTypes.includes(i.extension)).map((a) => a.url || '')
|
||||||
options: {
|
const index = imgList.findIndex((i) => i === item.url)
|
||||||
initialViewIndex: index
|
if (imgList.length) {
|
||||||
},
|
viewerApi({
|
||||||
images: imgList
|
options: {
|
||||||
})
|
initialViewIndex: index
|
||||||
|
},
|
||||||
|
images: imgList
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (item.extension === 'mp4') {
|
||||||
|
previewFileVideoModal(item)
|
||||||
|
}
|
||||||
|
if (item.extension === 'mp3') {
|
||||||
|
previewFileAudioModal(item)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (item.extension === 'mp4') {
|
}
|
||||||
previewFileVideoModal(item)
|
// 下载文件
|
||||||
}
|
const onDownload = async (fileInfo: FileItem) => {
|
||||||
if (item.extension === 'mp3') {
|
const res = await downloadByUrl({
|
||||||
previewFileAudioModal(item)
|
url: fileInfo.url,
|
||||||
}
|
target: '_self',
|
||||||
|
fileName: `${fileInfo.name}.${fileInfo.extension}`
|
||||||
|
})
|
||||||
|
res ? Message.success('下载成功') : Message.error('下载失败')
|
||||||
|
search()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 右键菜单
|
// 右键菜单
|
||||||
@@ -154,13 +171,7 @@ const handleRightMenuClick = async (mode: string, fileInfo: FileItem) => {
|
|||||||
} else if (mode === 'detail') {
|
} else if (mode === 'detail') {
|
||||||
openFileDetailModal(fileInfo)
|
openFileDetailModal(fileInfo)
|
||||||
} else if (mode === 'download') {
|
} else if (mode === 'download') {
|
||||||
const res = await downloadByUrl({
|
await onDownload(fileInfo)
|
||||||
url: fileInfo.url,
|
|
||||||
target: '_self',
|
|
||||||
fileName: `${fileInfo.name}.${fileInfo.extension}`
|
|
||||||
})
|
|
||||||
res ? Message.success('下载成功') : Message.error('下载失败')
|
|
||||||
search()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,7 +197,7 @@ const handleMulDelete = () => {
|
|||||||
// 上传
|
// 上传
|
||||||
const handleUpload = (options: RequestOption) => {
|
const handleUpload = (options: RequestOption) => {
|
||||||
const controller = new AbortController()
|
const controller = new AbortController()
|
||||||
; (async function requestWrap() {
|
;(async function requestWrap() {
|
||||||
const { onProgress, onError, onSuccess, fileItem, name = 'file' } = options
|
const { onProgress, onError, onSuccess, fileItem, name = 'file' } = options
|
||||||
onProgress(20)
|
onProgress(20)
|
||||||
const formData = new FormData()
|
const formData = new FormData()
|
||||||
|
@@ -1,67 +0,0 @@
|
|||||||
<template>
|
|
||||||
<a-menu class="right-menu">
|
|
||||||
<a-menu-item @click="onClick('add')">
|
|
||||||
<template #icon><icon-plus-circle :size="16" :stroke-width="3" /></template>
|
|
||||||
<span>新增</span>
|
|
||||||
</a-menu-item>
|
|
||||||
|
|
||||||
<a-menu-item v-permission="['system:dept:update']" @click="onClick('update')">
|
|
||||||
<template #icon><icon-edit :size="16" :stroke-width="3" /></template>
|
|
||||||
<span>修改</span>
|
|
||||||
</a-menu-item>
|
|
||||||
|
|
||||||
<a-menu-item v-permission="['system:dept:delete']" :title="data.isSystem ? '系统内置数据不能删除' : undefined" :disabled="data.isSystem" @click="onClick('delete')">
|
|
||||||
<template #icon><icon-delete :size="16" :stroke-width="3" /></template>
|
|
||||||
<span>删除</span>
|
|
||||||
</a-menu-item>
|
|
||||||
</a-menu>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts" setup>
|
|
||||||
import type { DeptResp } from '@/apis'
|
|
||||||
|
|
||||||
interface Props {
|
|
||||||
data: DeptResp
|
|
||||||
}
|
|
||||||
|
|
||||||
const props = withDefaults(defineProps<Props>(), {})
|
|
||||||
|
|
||||||
const emit = defineEmits<{
|
|
||||||
(e: 'on-menu-item-click', mode: string, data: DeptResp): void
|
|
||||||
}>()
|
|
||||||
|
|
||||||
// 点击菜单项
|
|
||||||
const onClick = (mode: string) => {
|
|
||||||
emit('on-menu-item-click', mode, props.data)
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
|
||||||
:deep(.arco-menu-inner) {
|
|
||||||
padding: 4px;
|
|
||||||
|
|
||||||
.arco-menu-item {
|
|
||||||
height: 34px;
|
|
||||||
|
|
||||||
&:not(.arco-menu-selected) {
|
|
||||||
color: $color-text-1;
|
|
||||||
}
|
|
||||||
|
|
||||||
&:last-child {
|
|
||||||
margin-bottom: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.right-menu {
|
|
||||||
width: 120px;
|
|
||||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
|
||||||
border-radius: 4px;
|
|
||||||
border: 1px solid var(--color-border-2);
|
|
||||||
box-sizing: border-box;
|
|
||||||
|
|
||||||
.arrow-icon {
|
|
||||||
margin-right: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
@@ -9,51 +9,27 @@
|
|||||||
<div class="left-tree__tree">
|
<div class="left-tree__tree">
|
||||||
<a-tree
|
<a-tree
|
||||||
ref="treeRef"
|
ref="treeRef"
|
||||||
:data="(treeData as unknown as TreeNodeData[])"
|
:data="deptList"
|
||||||
:field-names="{ key: 'id' }"
|
|
||||||
show-line
|
show-line
|
||||||
block-node
|
block-node
|
||||||
default-expand-all
|
default-expand-all
|
||||||
:selected-keys="selectedKeys"
|
:selected-keys="selectedKeys"
|
||||||
@select="select"
|
@select="select"
|
||||||
>
|
>
|
||||||
<template #title="node">
|
<template #switcher-icon="node, { isLeaf }">
|
||||||
<a-trigger
|
<IconCaretDown v-if="!isLeaf" />
|
||||||
v-model:popup-visible="node.popupVisible"
|
<IconIdcard v-else />
|
||||||
trigger="contextMenu"
|
|
||||||
align-point
|
|
||||||
animation-name="slide-dynamic-origin"
|
|
||||||
auto-fit-transform-origin
|
|
||||||
position="bl"
|
|
||||||
scroll-to-close
|
|
||||||
>
|
|
||||||
<a-tooltip v-if="node.description" :content="node.description" background-color="rgb(var(--primary-6))" position="right">
|
|
||||||
<div @contextmenu="onContextmenu(node)">{{ node.name }}</div>
|
|
||||||
</a-tooltip>
|
|
||||||
<div v-else @contextmenu="onContextmenu(node)">{{ node.name }}</div>
|
|
||||||
<template #content>
|
|
||||||
<RightMenu
|
|
||||||
v-if="has.hasPermOr(['system:dept:update', 'system:dept:delete'])"
|
|
||||||
:data="node"
|
|
||||||
@on-menu-item-click="onMenuItemClick"
|
|
||||||
/>
|
|
||||||
</template>
|
|
||||||
</a-trigger>
|
|
||||||
</template>
|
</template>
|
||||||
</a-tree>
|
</a-tree>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<DeptAddModal ref="DeptAddModalRef" @save-success="getTreeData" />
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="tsx">
|
<script setup lang="tsx">
|
||||||
import type { Message, Modal, TreeInstance, TreeNodeData } from '@arco-design/web-vue'
|
import type { TreeInstance } from '@arco-design/web-vue'
|
||||||
import { mapTree } from 'xe-utils'
|
import { ref } from 'vue'
|
||||||
import DeptAddModal from '../../dept/DeptAddModal.vue'
|
import { useDept } from '@/hooks/app'
|
||||||
import RightMenu from './RightMenu.vue'
|
|
||||||
import { type DeptQuery, type DeptResp, deleteDept, listDept } from '@/apis'
|
|
||||||
import has from '@/utils/has'
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
placeholder?: string
|
placeholder?: string
|
||||||
@@ -71,92 +47,25 @@ const select = (keys: Array<any>) => {
|
|||||||
emit('node-click', keys)
|
emit('node-click', keys)
|
||||||
}
|
}
|
||||||
|
|
||||||
const queryForm = reactive<DeptQuery>({
|
|
||||||
sort: ['parentId,asc', 'sort,asc', 'createTime,desc']
|
|
||||||
})
|
|
||||||
|
|
||||||
interface TreeItem extends DeptResp {
|
|
||||||
popupVisible: boolean
|
|
||||||
}
|
|
||||||
const treeRef = ref<TreeInstance>()
|
const treeRef = ref<TreeInstance>()
|
||||||
const treeData = ref<TreeItem[]>([])
|
|
||||||
const loading = ref(false)
|
|
||||||
// 查询树列表
|
// 查询树列表
|
||||||
const getTreeData = async (query: DeptQuery = { ...queryForm }) => {
|
const { deptList, getDeptList } = useDept({
|
||||||
try {
|
onSuccess: () => {
|
||||||
loading.value = true
|
nextTick(() => {
|
||||||
const { data } = await listDept(query)
|
|
||||||
treeData.value = mapTree(data, (i) => ({
|
|
||||||
...i,
|
|
||||||
popupVisible: false,
|
|
||||||
switcherIcon: (node: any) => {
|
|
||||||
if (!node.isLeaf) {
|
|
||||||
return <icon-caret-down />
|
|
||||||
}
|
|
||||||
return <icon-idcard />
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
await nextTick(() => {
|
|
||||||
treeRef.value?.expandAll(true)
|
treeRef.value?.expandAll(true)
|
||||||
select([data[0].id])
|
select([deptList.value[0]?.key])
|
||||||
})
|
})
|
||||||
} finally {
|
|
||||||
loading.value = false
|
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
// 树查询
|
// 树查询
|
||||||
const inputValue = ref('')
|
const inputValue = ref('')
|
||||||
watch(inputValue, (val) => {
|
watch(inputValue, (val) => {
|
||||||
queryForm.description = val
|
getDeptList(val)
|
||||||
getTreeData()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// 保存当前右键的节点
|
|
||||||
const contextmenuNode = ref<TreeItem | null>(null)
|
|
||||||
const onContextmenu = (node: TreeItem) => {
|
|
||||||
contextmenuNode.value = node
|
|
||||||
}
|
|
||||||
|
|
||||||
// 关闭右键菜单弹框
|
|
||||||
const closeRightMenuPopup = () => {
|
|
||||||
if (contextmenuNode.value?.popupVisible) {
|
|
||||||
contextmenuNode.value.popupVisible = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const DeptAddModalRef = ref<InstanceType<typeof DeptAddModal>>()
|
|
||||||
// 右键菜单项点击
|
|
||||||
const onMenuItemClick = (mode: string, node: DeptResp) => {
|
|
||||||
closeRightMenuPopup()
|
|
||||||
if (mode === 'add') {
|
|
||||||
DeptAddModalRef.value?.onAdd(node.id)
|
|
||||||
} else if (mode === 'update') {
|
|
||||||
DeptAddModalRef.value?.onUpdate(node.id)
|
|
||||||
} else if (mode === 'delete') {
|
|
||||||
Modal.warning({
|
|
||||||
title: '提示',
|
|
||||||
content: `是否确定删除 [${node.name}]?`,
|
|
||||||
hideCancel: false,
|
|
||||||
okButtonProps: { status: 'danger' },
|
|
||||||
onBeforeOk: async () => {
|
|
||||||
try {
|
|
||||||
const res = await deleteDept(node.id)
|
|
||||||
if (res.success) {
|
|
||||||
Message.success('删除成功')
|
|
||||||
getTreeData()
|
|
||||||
}
|
|
||||||
return res.success
|
|
||||||
} catch (error) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
getTreeData()
|
getDeptList()
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@@ -60,6 +60,8 @@ export default defineConfig(({ command, mode }) => {
|
|||||||
assetFileNames: 'static/[ext]/[name]-[hash].[ext]'
|
assetFileNames: 'static/[ext]/[name]-[hash].[ext]'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
// 以 envPrefix 开头的环境变量会通过 import.meta.env 暴露在你的客户端源码中。
|
||||||
|
envPrefix: ['VITE', 'FILE']
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user