Przeglądaj źródła

调试移动菜单,分享菜单功能

tanshanming 8 miesięcy temu
rodzic
commit
b48661b263

+ 0 - 4
src/views/myResource/common/FileTable.vue

@@ -118,7 +118,6 @@
 			type: Boolean
 		}
 	})
-	console.log('fileList-----: ', props)
 	const emit = defineEmits(['getTableDataByType'])
 
 	const route = useRoute()
@@ -130,10 +129,7 @@
 	const officeFileType = ref(['ppt', 'pptx', 'doc', 'docx', 'xls', 'xlsx'])
 	const sortedFileList = ref([]) //  排序后的表格数据
 	const selectedRowKeys = ref([])
-	console.log('1111111111', route.query)
-	console.log('props.fileType', props.fileType)
 	const { getSelectedColumnList } = storeToRefs(myResourceStore)
-	console.log('getSelectedColumnList:---- ', getSelectedColumnList.value)
 	const selectedColumnList = computed({
 		get: () => getSelectedColumnList.value
 	})

+ 0 - 16
src/views/myResource/components/OperationMenu.vue

@@ -153,7 +153,6 @@
 	import config from '@/config/reSource'
 	import { storeToRefs } from 'pinia'
 	const { proxy } = getCurrentInstance()
-	console.log('proxy===', proxy)
 
 	// 定义组件可以触发的事件
 	const emit = defineEmits(['getTableDataByType', 'getSearchFileList'])
@@ -234,12 +233,6 @@
 
 	// 批量下载文件链接
 	const batchDownloadLink = computed(() => {
-		console.log('批量下载')
-		console.log(
-			`${config.baseContext}/filetransfer/batchDownloadFile?userFileIds=${selectedFiles.value
-				.map((item) => item.userFileId)
-				.join(',')}`
-		)
 		return `${config.baseContext}/filetransfer/batchDownloadFile?userFileIds=${selectedFiles.value
 			.map((item) => item.userFileId)
 			.join(',')}`
@@ -252,12 +245,10 @@
 			handleUploadFileBtnClick(3)
 		}
 	)
-	console.log('fileType', props.fileType)
 	watch(
 		() => props.fileType,
 		(newValue, oldValue) => {
 			if (oldValue === 1 && fileModel.value === 2) {
-				console.log('时间线模式')
 				myResourceStore.changeFileModel(0)
 				fileGroupLable.value = 0
 			}
@@ -334,9 +325,6 @@
 					break
 				}
 				case 'go': {
-					console.log('uploadWay', uploadWay)
-					console.log('params', uploadFileParams.value)
-					console.log('uploadWay', uploadWay)
 					proxy.$openBox.uploadFile({
 						params: uploadFileParams.value,
 						uploadWay,
@@ -406,18 +394,14 @@
 	 * 打包批量下载按钮点击事件
 	 */
 	const handleBatchDownloadBtnClick = () => {
-		console.log(222, window.location.host)
 		// var cookies = window.$common.getCookies(window.config.tokenKeyName)
 		var url = `${
 			'http://' + window.location.host + config.baseContext
 		}/filetransfer/batchDownloadFile?userFileIds=${selectedFiles.value.map((item) => item.userFileId).join(',')}`
-		console.log(222, url)
-
 		var newname1 = '.zip'
 		let isios = navigator.userAgent.indexOf('iPhone') > -1
 		let isAndroid = navigator.userAgent.indexOf('Android') > -1
 		if (isios) {
-			console.log(1231231)
 			window.webkit.messageHandlers.Download.postMessage({
 				params: {
 					url,

+ 1 - 2
src/views/myResource/file/box/contextMenu/Box.vue

@@ -152,7 +152,6 @@
 	const visible = ref(false) // 右键菜单是否显示
 	const sortedFileList = ref([]) // 排序后的表格数据
 	const { proxy } = getCurrentInstance()
-	console.log('proxy file', proxy.$file)
 	// 右键菜单位置
 	const rightMenu = ref({
 		top: 0,
@@ -368,7 +367,7 @@
 		visible.value = false
 		proxy.$openDialog
 			.moveFile({
-				isBatchMove: false,
+				isBatchOperation: false,
 				fileInfo
 			})
 			.then((res) => {

+ 5 - 7
src/views/myResource/file/dialog/copyFile/Dialog.vue

@@ -59,10 +59,11 @@
 		fileInfo: {
 			type: Object,
 			default: () => ({})
-		}
+		},
+		callback: Function
 	})
 
-	const emit = defineEmits(['update:visible', 'cancel', 'confirm'])
+	const emit = defineEmits(['update:visible'])
 	const internalVisible = ref(props.visible) // 使用 internalVisible 作为主要的响应式状态
 	const targetPath = ref('/') //  目标路径
 	const fileTree = ref([]) //  文件夹目录树
@@ -96,7 +97,7 @@
 	const handleDialogClose = () => {
 		internalVisible.value = false
 		emit('update:visible', false) // 如果父组件需要 .sync 修饰符或者 v-model:visible
-		emit('cancel')
+		props.callback('cancel')
 	}
 
 	/**
@@ -112,7 +113,6 @@
 	 * 初始化文件目录树
 	 */
 	const initFileTree = async (id) => {
-		console.log('复制到')
 		loading.value = true
 		try {
 			const res = await getFoldTree()
@@ -147,8 +147,6 @@
 	 */
 	const handleAddFolderBtnClick = async (data) => {
 		try {
-			// $openDialog 假设是全局挂载的,通过 proxy 访问
-			// 您需要确保 proxy.$openDialog.addFolder 返回一个 Promise
 			await proxy.$openDialog.addFolder({
 				filePath: data.filePath || '/'
 			})
@@ -176,7 +174,7 @@
 				message.success('复制成功')
 				internalVisible.value = false
 				emit('update:visible', false)
-				emit('confirm')
+				props.callback('confirm')
 			} else {
 				message.error(res.message)
 			}

+ 3 - 1
src/views/myResource/file/dialog/copyFile/index.js

@@ -2,7 +2,7 @@ import { createApp } from 'vue'
 import Antd from 'ant-design-vue'
 // 导入组件
 import CopyFileDialog from './Dialog.vue'
-
+import snowy from '@/snowy'
 let copyFileInstance = null
 let copyFileApp = null
 
@@ -19,6 +19,8 @@ const initInstanceCopyFile = (fileInfo, callback) => {
 	})
 	// 注册 Ant Design Vue 组件
 	copyFileApp.use(Antd)
+	// 注册全局函数
+	copyFileApp.use(snowy)
 	copyFileInstance = copyFileApp.mount(mountNode)
 	return mountNode
 }

+ 210 - 125
src/views/myResource/file/dialog/moveFile/Dialog.vue

@@ -1,159 +1,202 @@
 <template>
+	<!-- 移动文件-选择目标路径 -->
 	<a-modal
 		title="选择目标路径"
-		v-model:visible="visible"
-		:maskClosable="false"
+		:visible="internalVisible"
+		:confirm-loading="sureBtnLoading"
 		@ok="handleDialogSure"
 		@cancel="handleDialogClose"
-		@afterVisibleChange="handleVisibleChange"
+		:afterClose="handleDialogClose"
+		:maskClosable="false"
 	>
-		<div class="dialog-content">
-			<div class="radio-group">
-				<a-radio-group v-model:value="isFerry" @change="toggleAdvanced">
-					<a-radio-button :value="0">系统内操作</a-radio-button>
-					<a-radio-button v-show="showFerry" :value="1">摆渡至内网</a-radio-button>
-				</a-radio-group>
+		<div class="dialog-div-custom">
+			<!-- 选择的目标路径 -->
+			<div class="target-path">
+				<span class="label">目标路径:</span>
+				<a-input class="content" v-model:value="targetPath" readonly size="small"></a-input>
 			</div>
-
-			<template v-if="advanced">
-				<div class="target-path">
-					<span class="label">目标路径:</span>
-					<a-input v-model:value="targetPath" readonly size="small" />
-				</div>
-
-				<a-spin :spinning="loading">
-					<a-directory-tree
-						:treeData="fileTree"
-						:fieldNames="{
-							children: 'children',
-							title: 'label'
-						}"
-						:defaultExpandedKeys="defaultExpandedKeys"
-						@select="handleNodeClick"
-					>
-						<template #title="{ node, data }">
-							<div class="custom-tree-node">
-								<span class="label">{{ node.title }}</span>
-								<a-button type="link" size="small" class="add-folder-btn" @click.stop="handleAddFolderBtnClick(data)">
-									新建文件夹
-								</a-button>
-							</div>
-						</template>
-					</a-directory-tree>
-				</a-spin>
-			</template>
+			<!-- 文件目录树 -->
+			<a-spin :spinning="loading">
+				<a-tree
+					:tree-data="fileTree"
+					:field-names="{ children: 'children', title: 'label', key: 'id' }"
+					highlight-current
+					:expandedKeys="defaultExpandedKeys"
+					@update:expandedKeys="(val) => (defaultExpandedKeys = val)"
+					node-key="id"
+					@select="handleNodeClick"
+					:showLine="true"
+				>
+					<template #title="{ dataRef }">
+						<span class="custom-tree-node">
+							<span class="label">{{ dataRef.label }}</span>
+							<a-button class="add-folder-btn" type="link" size="small" @click.stop="handleAddFolderBtnClick(dataRef)">
+								新建文件夹
+							</a-button>
+						</span>
+					</template>
+				</a-tree>
+			</a-spin>
 		</div>
+		<template #footer>
+			<a-button @click="handleDialogClose">取 消</a-button>
+			<a-button type="primary" :loading="sureBtnLoading" @click="handleDialogSure"> 确 定 </a-button>
+		</template>
 	</a-modal>
 </template>
 
 <script setup>
-	import { ref, reactive, onMounted } from 'vue'
+	import { ref, getCurrentInstance, watch } from 'vue'
+	import { getFoldTree, moveFile, batchMoveFile } from '@/api/myResource/file'
 	import { message } from 'ant-design-vue'
-	import { getFoldTree, moveFile, batchMoveFile, getFerryStatus } from '@/api/myResource/file'
-
 	const { proxy } = getCurrentInstance()
 
 	const props = defineProps({
-		fileInfo: [Array, Object],
-		isBatchOperation: Boolean,
+		visible: {
+			type: Boolean,
+			default: false
+		},
+		fileInfo: {
+			type: [Object, Array],
+			default: () => ({})
+		},
+		isBatchOperation: {
+			type: Boolean,
+			default: false
+		},
 		callback: Function
 	})
 
-	const visible = ref(false)
-	const targetPath = ref('/')
-	const fileTree = ref([])
-	const loading = ref(false)
-	const isFerry = ref(0)
-	const advanced = ref(true)
-	const showFerry = ref(false)
+	const emit = defineEmits(['update:visible'])
+	const internalVisible = ref(props.visible) // 使用 internalVisible 作为主要的响应式状态
+	const targetPath = ref('/') //  目标路径
+	const fileTree = ref([]) //  文件夹目录树
+	const loading = ref(false) //  文件夹目录树 loading 状态
 	const defaultExpandedKeys = ref([])
-	const sureBtnLoading = ref(false)
+	const sureBtnLoading = ref(false) //  确定按钮 loading 状态
 
-	const getFerryStatusData = async () => {
-		const res = await getFerryStatus()
-		showFerry.value = res.data
-	}
+	watch(
+		internalVisible, // 监听内部的 internalVisible ref
+		(newVal, oldVal) => {
+			if (newVal && !oldVal) {
+				// 仅在从 false 变为 true 时调用,即对话框打开时
+				handleDialogOpen()
+			}
+		}
+	)
 
-	const toggleAdvanced = () => {
-		advanced.value = isFerry.value === 0
-	}
+	// 如果父组件通过 prop 更新 visible,也需要同步到 internalVisible
+	watch(
+		() => props.visible,
+		(newVal) => {
+			internalVisible.value = newVal
+		}
+	)
 
+	/**
+	 * 取消按钮点击事件 & 对话框关闭的回调
+	 */
 	const handleDialogClose = () => {
-		visible.value = false
+		internalVisible.value = false
+		emit('update:visible', false) // 如果父组件需要 .sync 修饰符或者 v-model:visible
 		props.callback('cancel')
 	}
 
-	const handleVisibleChange = (val) => {
-		if (val) {
-			initFileTree()
-		}
+	/**
+	 * 对话框打开的回调
+	 */
+	const handleDialogOpen = () => {
+		initFileTree()
+		targetPath.value = '/' // 重置目标路径
 	}
 
+	/**
+	 * 初始化文件目录树
+	 */
 	const initFileTree = async (id) => {
+		loading.value = true
 		try {
-			loading.value = true
 			const res = await getFoldTree()
 			if (res.success) {
 				fileTree.value = [res.data]
-				defaultExpandedKeys.value = id ? [id] : [fileTree.value[0].id]
+				defaultExpandedKeys.value = id ? [id] : fileTree.value.length > 0 ? [fileTree.value[0].id] : []
 			} else {
 				message.error(res.message)
 			}
+		} catch (error) {
+			message.error('获取文件夹树失败')
+			console.error(error)
 		} finally {
 			loading.value = false
 		}
 	}
 
-	const handleNodeClick = (selectedKeys, { node }) => {
-		targetPath.value = node.filePath || '/'
+	/**
+	 * 目录树节点点击回调函数
+	 * @param {Array} selectedKeys 当前选中的节点的 key
+	 * @param {object} e event 对象,包含 {selected: bool, selectedNodes, node, event}
+	 */
+	const handleNodeClick = (selectedKeys, e) => {
+		if (e.node && e.node.dataRef) {
+			targetPath.value = e.node.dataRef.filePath ? e.node.dataRef.filePath : '/'
+		}
 	}
 
+	/**
+	 * 新建文件夹按钮点击事件
+	 * @description 调用新建文件夹服务,并在弹窗确认回调事件中刷新文件夹树
+	 */
 	const handleAddFolderBtnClick = async (data) => {
-		const result = await proxy.$openDialog.addFolder({
-			filePath: data.filePath || '/'
-		})
-		if (result === 'confirm') {
+		try {
+			await proxy.$openDialog.addFolder({
+				filePath: data.filePath || '/'
+			})
 			initFileTree(data.id)
+		} catch (error) {
+			console.log('Add folder cancelled or failed', error)
 		}
 	}
 
+	/**
+	 * 确定按钮点击事件
+	 * @description 调用移动文件接口
+	 */
 	const handleDialogSure = async () => {
+		sureBtnLoading.value = true
 		try {
-			sureBtnLoading.value = true
 			let res
 
 			if (props.isBatchOperation) {
 				res = await batchMoveFile({
 					filePath: targetPath.value,
-					userFileIds: props.fileInfo.map((item) => item.userFileId).join(','),
-					isFerry: isFerry.value
+					userFileIds: props.fileInfo.map((item) => item.userFileId).join(',')
 				})
 			} else {
 				res = await moveFile({
 					userFileId: props.fileInfo.userFileId,
-					filePath: targetPath.value,
-					isFerry: isFerry.value
+					filePath: targetPath.value
 				})
 			}
 
 			if (res.success) {
 				message.success('移动成功')
-				visible.value = false
+				internalVisible.value = false
+				emit('update:visible', false)
 				props.callback('confirm')
 			} else {
 				message.error(res.message)
 			}
+		} catch (error) {
+			message.error('移动文件失败')
+			console.error(error)
 		} finally {
 			sureBtnLoading.value = false
 		}
 	}
 
-	onMounted(() => {
-		getFerryStatusData()
-	})
-
+	// 暴露给模板或者父组件(如果需要ref访问)
 	defineExpose({
-		visible
+		visible: internalVisible // 暴露 internalVisible
 	})
 </script>
 
@@ -161,63 +204,105 @@
 	@import '@/style/myResource/varibles.less';
 	@import '@/style/myResource/mixins.less';
 
-	.dialog-content {
-		height: 300px;
-		overflow: auto;
-
-		.radio-group {
-			margin-bottom: 20px;
+	// 使用 ::v-deep 替代 >>>
+	:deep(.ant-modal) {
+		.ant-modal-header {
+			display: flex; // antd 默认就是 flex,可能不需要
 		}
 
-		.target-path {
-			display: flex;
-			align-items: center;
-			margin-bottom: 16px;
+		.ant-modal-body {
+			padding: 10px 30px;
 
-			.label {
-				width: 80px;
-			}
+			.dialog-div-custom {
+				// 修改类名以避免与 antd 内部类名冲突
+				height: 300px;
+				overflow: auto;
+				&::-webkit-scrollbar {
+					width: 6px;
+				}
+				&::-webkit-scrollbar-thumb {
+					background: #ccc; // 滚动条颜色
+					border-radius: 3px;
+				}
+				&::-webkit-scrollbar-track {
+					background: #f1f1f1; // 轨道颜色
+				}
 
-			.ant-input {
-				flex: 1;
-			}
-		}
+				.target-path {
+					display: flex;
+					align-items: center;
+					margin-bottom: 10px; // 增加一些间距
 
-		.custom-tree-node {
-			width: 100%;
-			display: flex;
-			align-items: center;
-			justify-content: space-between;
+					.label {
+						width: 80px;
+						flex-shrink: 0; // 防止被压缩
+					}
 
-			.add-folder-btn {
-				display: none;
-			}
+					.content {
+						flex: 1;
+					}
+				}
+
+				.ant-tree {
+					.ant-tree-treenode {
+						width: 100%;
+						// antd v4+ 使用 .ant-tree-treenode
+						.ant-tree-node-content-wrapper {
+							height: 34px;
+							font-size: 16px;
+							display: flex; // 确保自定义内容能正确布局
+							align-items: center;
+						}
+						&:hover {
+							.add-folder-btn {
+								display: inline-block; // 或者 block,取决于布局需求
+							}
+						}
+
+						.ant-tree-switcher .ant-tree-switcher-icon svg {
+							font-size: 18px; // 调整展开/折叠图标大小
+						}
+
+						.custom-tree-node {
+							flex: 1;
+							display: flex;
+							align-items: center;
+							justify-content: space-between;
+							font-size: 14px;
+							padding-right: 8px;
 
-			&:hover .add-folder-btn {
-				display: inline-block;
+							.add-folder-btn {
+								color: #000000;
+								display: none; // 默认隐藏
+								margin-left: 8px; // 给按钮一些左边距
+							}
+						}
+					}
+				}
 			}
 		}
 	}
-
-	.ant-btn-primary {
-		&,
-		&:hover,
-		&:focus {
-			background-color: @primary-color;
-			border-color: @primary-color;
-		}
+	:deep(.ant-tree .ant-tree-treenode .custom-tree-node) {
+		display: flex;
+		justify-content: space-between;
+		width: 100%;
 	}
 
-	.ant-radio-button-wrapper-checked {
-		color: @primary-color !important;
-		border-color: @primary-color !important;
-
-		&::before {
-			background-color: @primary-color !important;
-		}
+	:deep(.ant-tree .ant-tree-treenode:hover .custom-tree-node .add-folder-btn) {
+		color: #29175b !important;
+		display: inline-block !important;
 	}
 
-	.ant-tree-node-selected {
-		// background-color: .fade(@primary-color, 10%) !important;
+	:deep(.ant-tree .ant-tree-treenode .custom-tree-node .add-folder-btn) {
+		color: #000000;
+		display: none !important;
+		margin-left: 8px;
+	}
+	:deep(.ant-tree) {
+		.ant-tree-treenode,
+		.ant-tree-node-content-wrapper,
+		.ant-tree-title {
+			width: 100%;
+		}
 	}
 </style>

+ 2 - 1
src/views/myResource/file/dialog/moveFile/index.js

@@ -2,7 +2,7 @@ import { createApp } from 'vue'
 import Antd from 'ant-design-vue'
 // 导入组件
 import MoveFileDialog from './Dialog.vue'
-
+import snowy from '@/snowy'
 let moveFileInstance = null
 let moveFileApp = null
 
@@ -21,6 +21,7 @@ const initInstanceMoveFile = (isBatchOperation, fileInfo, callback) => {
 	})
 	// 注册 Ant Design Vue 组件
 	moveFileApp.use(Antd)
+	moveFileApp.use(snowy)
 	moveFileInstance = moveFileApp.mount(mountNode)
 	return mountNode
 }

+ 0 - 1
src/views/myResource/file/dialog/renameFile/Dialog.vue

@@ -14,7 +14,6 @@
 					placeholder="请输入文件名称"
 					:auto-size="{ minRows: 1 }"
 					:maxLength="255"
-					show-count
 				/>
 			</a-form-item>
 		</a-form>

+ 110 - 87
src/views/myResource/file/dialog/shareFile/Dialog.vue

@@ -1,72 +1,74 @@
 <template>
-	<a-modal title="分享文件" v-model:visible="visible" :maskClosable="false" width="550px" @cancel="handleDialogCancel">
+	<!-- 分享对话框 -->
+	<a-modal title="分享文件" v-model:visible="visible" :maskClosable="false" width="550px" @close="handleDialogCancel">
 		<a-form
 			v-show="!shareIsSuccess"
 			class="share-file-form"
 			:model="form"
-			ref="shareFileFormRef"
-			:rules="rules"
+			ref="shareFileForm"
 			:label-col="{ span: screenWidth <= 520 ? 24 : 6 }"
 			:wrapper-col="{ span: screenWidth <= 520 ? 24 : 18 }"
+			:rules="rules"
 		>
-			<a-form-item label="链接有效期至" name="endTime">
+			<a-form-item label="链接有效期至" name="endTime">
 				<a-date-picker
 					v-model:value="form.endTime"
 					show-time
 					format="YYYY-MM-DD HH:mm:ss"
 					placeholder="选择日期时间"
-					:disabled-date="disabledDate"
-					@ok="onOk"
+					:inputReadOnly="true"
+					:allowClear="false"
 				>
 					<template #renderExtraFooter>
-						<a-space>
-							<a-button size="small" @click="() => setDate('today')">今天</a-button>
-							<a-button size="small" @click="() => setDate(1)">1天</a-button>
-							<a-button size="small" @click="() => setDate(7)">7天</a-button>
-							<a-button size="small" @click="() => setDate(30)">30天</a-button>
-						</a-space>
+						<div>
+							<a-button size="small" @click="setEndTime('today')">今天</a-button>
+							<a-button size="small" @click="setEndTime('1day')">1天</a-button>
+							<a-button size="small" @click="setEndTime('7days')">7天</a-button>
+							<a-button size="small" @click="setEndTime('30days')">30天</a-button>
+						</div>
 					</template>
 				</a-date-picker>
 			</a-form-item>
-			<a-form-item label="是否需要提取码" name="shareType">
+			<a-form-item label="是否需要提取码" name="shareType">
 				<a-radio-group v-model:value="form.shareType">
 					<a-radio :value="1">是</a-radio>
 					<a-radio :value="0">否</a-radio>
 				</a-radio-group>
 			</a-form-item>
 		</a-form>
-
 		<a-form
 			v-if="shareIsSuccess"
 			class="share-success-form"
 			:model="shareData"
-			ref="shareSuccessFormRef"
-			:label-col="{ span: screenWidth <= 520 ? 24 : 6 }"
-			:wrapper-col="{ span: screenWidth <= 520 ? 24 : 18 }"
+			ref="shareSuccessForm"
+			:label-col="{ span: screenWidth <= 520 ? 24 : 4 }"
+			:wrapper-col="{ span: screenWidth <= 520 ? 24 : 20 }"
 		>
 			<div class="success-tip">
 				<check-circle-outlined />
 				<span class="text">成功创建分享链接</span>
 			</div>
-			<a-form-item label="分享链接" name="shareBatchNum">
-				<a-textarea :value="$file.getShareLink(shareData.shareBatchNum)" :readonly="true" :auto-size="{ minRows: 1 }" />
+			<a-form-item label="分享链接:" name="shareBatchNum">
+				<a-textarea
+					:value="$file.getShareLink(shareData.shareBatchNum)"
+					:readonly="true"
+					:auto-size="{ minRows: 2, maxRows: 6 }"
+				></a-textarea>
 			</a-form-item>
-			<a-form-item label="提取码" name="extractionCode">
-				<a-input v-model:value="shareData.extractionCode" readonly />
+			<a-form-item label="提取码" name="extractionCode">
+				<a-input v-model:value="shareData.extractionCode" :readonly="true"></a-input>
 			</a-form-item>
 		</a-form>
-
 		<template #footer>
 			<a-button
 				v-if="shareIsSuccess"
 				type="primary"
 				@click="$file.copyShareLink(shareData.shareBatchNum, shareData.extractionCode)"
+				>复制链接及提取码</a-button
 			>
-				复制链接及提取码
-			</a-button>
 			<template v-else>
 				<a-button @click="handleDialogCancel">取 消</a-button>
-				<a-button type="primary" :loading="sureBtnLoading" @click="handleDialogSure"> 确 定 </a-button>
+				<a-button type="primary" :loading="sureBtnLoading" @click="handleDialogSure('shareFileForm')">确 定</a-button>
 			</template>
 		</template>
 	</a-modal>
@@ -74,84 +76,121 @@
 
 <script setup>
 	import { ref, reactive, computed } from 'vue'
+	import { shareFile } from '@/api/myResource/file.js'
+	import { useMyResourceStore } from '@/store/myResource.js'
 	import { message } from 'ant-design-vue'
 	import { CheckCircleOutlined } from '@ant-design/icons-vue'
-	import { useMyResourceStore } from '@/store/myResource'
-	import { shareFile } from '@/api/myResource/file'
+	const myResourceStore = useMyResourceStore()
 
+	// 定义props
 	const props = defineProps({
-		fileInfo: Array,
-		callback: Function
+		fileInfo: {
+			type: Array,
+			default: () => []
+		},
+		callback: {
+			type: Function,
+			default: () => {}
+		}
 	})
 
-	const store = useMyResourceStore()
-
-	const visible = ref(false)
-	const shareIsSuccess = ref(false)
-	const sureBtnLoading = ref(false)
-	const shareFileFormRef = ref(null)
-
-	const screenWidth = computed(() => store.screenWidth)
+	// 响应式状态
+	const visible = ref(false) // 对话框是否可见
+	const shareIsSuccess = ref(false) // 分享是否成功
+	const sureBtnLoading = ref(false) // 确定按钮加载状态
+	const shareFileForm = ref(null) // 表单引用
 
+	// 分享文件对话框数据
 	const form = reactive({
-		endTime: null,
+		endTime: '',
 		shareType: 0
 	})
 
-	const shareData = reactive({
-		shareBatchNum: '',
-		extractionCode: ''
-	})
-
+	// 表单验证规则
 	const rules = {
 		endTime: [{ required: true, message: '请选择链接有效期', trigger: 'change' }]
 	}
 
-	const disabledDate = (current) => {
-		return current && current < Date.now() - 8.64e7
-	}
+	// 分享成功的数据
+	const shareData = reactive({
+		shareBatchNum: '',
+		extractionCode: ''
+	})
 
-	const setDate = (days) => {
-		const date = new Date()
-		if (days === 'today') {
-			date.setHours(23, 59, 59)
-		} else {
-			date.setTime(date.getTime() + 3600 * 1000 * 24 * days)
+	// 计算属性 - 屏幕宽度
+	const screenWidth = computed(() => myResourceStore.screenWidth)
+
+	// 设置结束时间的快捷方式
+	const setEndTime = (type) => {
+		const nowDate = new Date()
+		let oneDay, sevenDays, thirtyDays
+		switch (type) {
+			case 'today':
+				form.endTime = new Date(nowDate.getFullYear(), nowDate.getMonth(), nowDate.getDate(), 23, 59, 59)
+				break
+			case '1day':
+				oneDay = new Date()
+				oneDay.setTime(oneDay.getTime() + 3600 * 1000 * 24)
+				form.endTime = oneDay
+				break
+			case '7days':
+				sevenDays = new Date()
+				sevenDays.setTime(sevenDays.getTime() + 3600 * 1000 * 24 * 7)
+				form.endTime = sevenDays
+				break
+			case '30days':
+				thirtyDays = new Date()
+				thirtyDays.setTime(thirtyDays.getTime() + 3600 * 1000 * 24 * 30)
+				form.endTime = thirtyDays
+				break
 		}
-		form.endTime = date
 	}
 
+	/**
+	 * 分享文件对话框 | 取消按钮点击事件
+	 * @description 关闭对话框,重置表单
+	 */
 	const handleDialogCancel = () => {
-		shareFileFormRef.value?.resetFields()
+		shareFileForm.value?.resetFields()
 		visible.value = false
 		props.callback('cancel')
 	}
 
-	const handleDialogSure = async () => {
+	/**
+	 * 分享文件对话框 | 确定按钮点击事件
+	 * @description 校验表单,校验通过后调用分享文件接口
+	 * @param {string} formName 表单ref值
+	 */
+	const handleDialogSure = async (formName) => {
+		sureBtnLoading.value = true
 		try {
-			sureBtnLoading.value = true
-			await shareFileFormRef.value.validate()
-
-			const res = await shareFile({
+			await shareFileForm.value.validateFields()
+			const params = {
 				...form,
 				remarks: '',
-				userFileIds: props.fileInfo.map((item) => item.userFileId).join(',')
-			})
+				userFileIds: props.fileInfo.map((res) => res.userFileId).join(',')
+			}
 
-			if (res.success) {
-				Object.assign(shareData, res.data)
-				shareIsSuccess.value = true
-				props.callback('confirm')
-			} else {
-				message.error(res.message)
+			try {
+				const res = await shareFile(params)
+				sureBtnLoading.value = false
+				if (res.success) {
+					shareData.shareBatchNum = res.data.shareBatchNum
+					shareData.extractionCode = res.data.extractionCode
+					shareIsSuccess.value = true
+					props.callback('confirm')
+				} else {
+					message.error(res.message)
+				}
+			} catch (error) {
+				sureBtnLoading.value = false
 			}
 		} catch (error) {
-			console.error(error)
-		} finally {
 			sureBtnLoading.value = false
 		}
 	}
 
+	// 暴露方法给父组件
 	defineExpose({
 		visible
 	})
@@ -167,24 +206,8 @@
 
 		.anticon {
 			margin-right: 8px;
-		}
-	}
-
-	.ant-btn-primary {
-		&,
-		&:hover,
-		&:focus {
-			background-color: @primary-color;
-			border-color: @primary-color;
-		}
-	}
-
-	.ant-radio-wrapper-checked {
-		.ant-radio-checked {
-			.ant-radio-inner {
-				background-color: @primary-color;
-				border-color: @primary-color;
-			}
+			height: 20px;
+			line-height: 20px;
 		}
 	}
 </style>

+ 2 - 1
src/views/myResource/file/dialog/shareFile/index.js

@@ -2,7 +2,7 @@ import { createApp } from 'vue'
 import Antd from 'ant-design-vue'
 // 导入组件
 import ShareFileDialog from './Dialog.vue'
-
+import snowy from '@/snowy'
 let shareFileInstance = null
 let shareFileApp = null
 
@@ -19,6 +19,7 @@ const initInstanceShareFile = (fileInfo, callback) => {
 	})
 	// 注册 Ant Design Vue 组件
 	shareFileApp.use(Antd)
+	shareFileApp.use(snowy)
 	shareFileInstance = shareFileApp.mount(mountNode)
 	return mountNode
 }