123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304 |
- <template>
- <div class="share-wrapper">
- <div class="share-file-wrapper" v-if="shareStep === 3">
- <div class="operation-wrapper">
- <!-- 面包屑导航栏 -->
- <BreadCrumb class="breadcrumb" :fileType="7"></BreadCrumb>
- <el-button type="primary" size="mini" icon="el-icon-takeaway-box" @click="handleSaveBtnClick"
- >保存到网盘</el-button
- >
- </div>
- <!-- 文件列表-表格模式 -->
- <FileTable
- ref="fileTableInstance"
- :fileType="7"
- :filePath="filePath"
- :fileList="fileList"
- :loading="loading"
- @setSelectionFile="setSelectionFile"
- ></FileTable>
- </div>
- <!-- 文件分享对话框 -->
- <el-dialog
- title="文件分享"
- :visible.sync="dialogShareFile.visible"
- :show-close="false"
- :close-on-click-modal="false"
- :close-on-press-escape="false"
- width="500px"
- >
- <div class="end-time" v-if="shareStep === 1">此分享链接已过期</div>
- <el-form
- class="extraction-code-form"
- v-if="shareStep === 2"
- ref="codeForm"
- :model="dialogShareFile.codeForm"
- :rules="dialogShareFile.codeFormRules"
- label-width="80px"
- >
- <el-form-item label="提取码" prop="extractionCode">
- <el-input v-model="dialogShareFile.codeForm.extractionCode"></el-input>
- </el-form-item>
- </el-form>
- <span slot="footer" class="dialog-footer">
- <el-button v-if="shareStep === 1" @click="handleCloseBtnClick()">关 闭</el-button>
- <el-button v-else type="primary" @click="handleSubmitBtnClick('codeForm')">提 交</el-button>
- </span>
- </el-dialog>
- <!-- 保存到网盘 路径选择对话框 -->
- <MoveFileDialog
- :dialogData="dialogSelectPath"
- @setSelectFilePath="setSelectFilePath"
- @confirmDialog="confirmSelectPathDialog"
- @setDialogData="setSelectPathDialogData"
- ></MoveFileDialog>
- </div>
- </template>
- <script>
- import BreadCrumb from '_c/BreadCrumb'
- import FileTable from '_c/File/FileTable'
- import MoveFileDialog from '_c/File/MoveFileDialog'
- import {
- checkShareLinkEndtime,
- checkShareLinkType,
- checkShareLinkCode,
- getShareFileList,
- saveShareFile
- } from '_r/file.js'
- export default {
- name: 'Share',
- components: {
- BreadCrumb,
- FileTable,
- MoveFileDialog
- },
- data() {
- return {
- // 文件分享对话框数据
- dialogShareFile: {
- visible: false,
- codeForm: {
- extractionCode: ''
- },
- codeFormRules: {
- extractionCode: [
- {
- required: true,
- message: '请输入提取码',
- trigger: 'blur'
- }
- ]
- }
- },
- shareStep: 0,
- fileList: [],
- loading: false,
- // 保存到网盘对话框数据
- dialogSelectPath: {
- visible: false // 是否可见
- },
- selectFilePath: '', // 保存到网盘的目标路径
- selectionFile: [] // 表格勾选的文件列表
- }
- },
- computed: {
- shareBatchNum() {
- return this.$route.params.shareBatchNum
- },
- filePath() {
- return this.$route.query.filePath
- },
- shareFilePath() {
- return this.$route.query.filePath
- }
- },
- watch: {
- filePath() {
- this.getShareList()
- }
- },
- created() {
- if (!this.filePath) {
- this.$router.replace({
- query: {
- filePath: '/'
- }
- })
- }
- },
- mounted() {
- this.checkEndTime()
- },
- methods: {
- /**
- * 表格勾选框事件 | 保存被勾选的文件
- * @param {object[]} selection 被勾选的文件数组
- */
- setSelectionFile(selection) {
- this.selectionFile = selection
- },
- /**
- * 校验分享链接过期时间
- */
- checkEndTime() {
- checkShareLinkEndtime({
- shareBatchNum: this.shareBatchNum
- }).then((res) => {
- if (res.success) {
- if (this.getCookies(`share_${this.shareBatchNum}`) === 'true') {
- this.checkShareComplete()
- } else {
- this.dialogShareFile.visible = true
- this.checkShareType()
- }
- } else {
- this.dialogShareFile.visible = true
- this.shareStep = 1 // 链接已过期
- }
- })
- },
- /**
- * 校验分享类型
- * @description 校验分享链接是公共还是私密
- */
- checkShareType() {
- checkShareLinkType({
- shareBatchNum: this.shareBatchNum
- }).then((res) => {
- if (res.success) {
- // 0 公共 1 私密
- if (res.data.shareType === 0) {
- this.shareStep = 3 // 不是私密链接,直接展示文件列表
- this.getShareList()
- this.dialogShareFile.visible = false
- }
- if (res.data.shareType === 1) {
- this.shareStep = 2 // 是私密链接时,让用户输入提取码
- }
- } else {
- this.$message.error(res.message)
- }
- })
- },
- /**
- * 分享文件验证对话框 取消按钮
- */
- handleCloseBtnClick() {
- this.dialogShareFile.visible = false
- this.$router.push({ name: 'File', query: { fileType: 0, filePath: '/' } })
- },
- /**
- * 提交按钮点击事件
- */
- handleSubmitBtnClick(formName) {
- this.$refs[formName].validate((valid) => {
- if (valid) {
- checkShareLinkCode({
- extractionCode: this.dialogShareFile.codeForm.extractionCode,
- shareBatchNum: this.shareBatchNum
- }).then((res) => {
- if (res.success) {
- this.setCookies(`share_${this.shareBatchNum}`, true)
- this.$refs[formName].resetFields() // 清空表单
- this.checkShareComplete()
- } else {
- this.$message.error(res.message)
- }
- })
- } else {
- return false
- }
- })
- },
- /**
- * 校验全部通过
- */
- checkShareComplete() {
- this.shareStep = 3 // 展示文件列表
- this.dialogShareFile.visible = false
- this.getShareList()
- },
- /**
- * 获取分享文件列表
- */
- getShareList() {
- this.loading = true
- getShareFileList({
- shareFilePath: this.shareFilePath,
- shareBatchNum: this.shareBatchNum
- }).then((res) => {
- if (res.success) {
- this.fileList = res.data
- this.loading = false
- } else {
- this.$message.error(res.message)
- }
- })
- },
- /**
- * 保存到网盘按钮点击事件
- */
- handleSaveBtnClick() {
- if (this.selectionFile.length) {
- this.dialogSelectPath.visible = true
- } else {
- this.$message.warning('请先勾选要保存的文件')
- }
- },
- /**
- * 移动文件模态框 | 设置移动后的文件路径
- * @param {string} selectFilePath 目标文件夹路径
- */
- setSelectFilePath(selectFilePath) {
- this.selectFilePath = selectFilePath
- },
- /**
- * 移动文件模态框 | 确定按钮事件
- */
- confirmSelectPathDialog() {
- saveShareFile({
- filePath: this.selectFilePath,
- files: JSON.stringify(
- this.selectionFile.map((item) => {
- return {
- userFileId: item.userFileId
- }
- })
- )
- }).then((res) => {
- if (res.success) {
- this.$message.success('保存成功')
- this.dialogSelectPath.visible = false
- this.$refs.fileTableInstance.clearSelectedTable() // 清空表格已选项
- } else {
- this.$message.error(res.message)
- }
- })
- },
- /**
- * 设置移动文件模态框相关数据
- * @param {boolean} isBatchMove 是否批量移动,为 null时是确认移动,值由之前的值而定,在此业务中此致无用
- * @param {boolean} visible 移动文件对话框状态
- */
- setSelectPathDialogData(isBatchMove, visible) {
- this.dialogSelectPath.visible = visible
- }
- }
- }
- </script>
- <style lang="stylus" scoped>
- .share-wrapper {
- .share-file-wrapper {
- width: 100%;
- .operation-wrapper {
- display: flex;
- justify-content: space-between;
- padding: 8px 0;
- }
- }
- }
- </style>
|