perf: 分享操作

This commit is contained in:
jmal 2024-05-25 16:46:52 +08:00
parent 7f580897f7
commit d8d2648592
4 changed files with 153 additions and 60 deletions

View File

@ -241,9 +241,9 @@ export default {
}) })
}, },
// 获取分享信息 // 获取分享信息
getShare: function(params) { getShareByFileId: function(params) {
return request({ return request({
url: '/get/share', url: '/get/share/by/fileId',
method: 'get', method: 'get',
params params
}) })

View File

@ -28,7 +28,6 @@
<el-col :span="12" v-if="shareOptionConfig.shared" class="shared-expires-text">到期时间</el-col> <el-col :span="12" v-if="shareOptionConfig.shared" class="shared-expires-text">到期时间</el-col>
<el-col :span="1" v-if="!shareOptionConfig.shared">&nbsp</el-col> <el-col :span="1" v-if="!shareOptionConfig.shared">&nbsp</el-col>
<el-col v-if="shareOption.expiresDateOption === 2" :span="12" class="share-expires-data"> <el-col v-if="shareOption.expiresDateOption === 2" :span="12" class="share-expires-data">
<el-form-item prop="expiresDate">
<el-date-picker <el-date-picker
ref="expiresDatePicker" ref="expiresDatePicker"
size="small" size="small"
@ -42,9 +41,19 @@
@change="pickerChange" @change="pickerChange"
:picker-options="pickerOptions"> :picker-options="pickerOptions">
</el-date-picker> </el-date-picker>
</el-form-item>
</el-col> </el-col>
</el-form-item> </el-form-item>
<el-form-item v-if="shareOptionConfig.shared" label="">
<el-col :span="12" class="shared-expires-text">分享形式</el-col>
<el-col :span="12">
<el-select size="small" v-model="shareOption.isPrivacy" style="width: 100%" @change="shareFormChange">
<el-option label="公开链接" :value="false"></el-option>
<el-option label="私密链接" :value="true"></el-option>
</el-select>
</el-col>
</el-form-item>
<el-form-item v-if="!shareOptionConfig.shared" class="share-option-form" label="分享形式" width="100"> <el-form-item v-if="!shareOptionConfig.shared" class="share-option-form" label="分享形式" width="100">
<el-col :span="20"> <el-col :span="20">
<el-select size="small" v-model="shareOption.isPrivacy" style="width: 100%"> <el-select size="small" v-model="shareOption.isPrivacy" style="width: 100%">
@ -89,6 +98,7 @@
</div> </div>
</div> </div>
<div slot="footer" class="dialog-footer"> <div slot="footer" class="dialog-footer">
<el-button size="small" v-if="shareOptionConfig.shared" type="danger" @click="cancelShare">取消分享</el-button>
<el-button size="small" v-if="!shareOptionConfig.shared" type="primary" @click="submitShare" <el-button size="small" v-if="!shareOptionConfig.shared" type="primary" @click="submitShare"
v-loading="generateShareLinkLoading">创建分享 v-loading="generateShareLinkLoading">创建分享
</el-button> </el-button>
@ -202,7 +212,8 @@ export default {
shared: false, shared: false,
linkLabel: "选择有效期", linkLabel: "选择有效期",
}, },
filename: '',// 文件名 filename: '',
shareId: ''
} }
}, },
computed: { computed: {
@ -221,23 +232,17 @@ export default {
}).then(res => { }).then(res => {
this.filename = res.data.path + this.file.name this.filename = res.data.path + this.file.name
}) })
this.showSharedPage(this.file)
this.shareOptionConfig.shared = true
this.shareOptionConfig.linkLabel = '分享链接'
this.setShareLink(this.getShareLink(this.file.shareId))
this.shareOption.isPrivacy = this.file.isPrivacy
this.shareOption.operationPermissionList = this.file.operationPermissionList || []
if (this.file.expireDate) {
this.shareOption.expiresDate = moment(this.file.expireDate).format('x')
}
this.shareOption.expiresDateOption = 2
this.extractionCode = this.file.extractionCode
} else { } else {
this.shareOptionConfig.shared = false if (this.file.shareBase) {
this.shareOptionConfig.linkLabel = '选择有效期' api.getShareByFileId({fileId: this.file.fileId}).then(res => {
this.shareOption.isPrivacy = false const shareObject = res.data
this.shareOption.expiresDate = null shareObject.shareId = res.data.id
this.shareOption.expiresDateOption = 1 this.showSharedPage(shareObject)
})
} else {
this.showNotSharedPage()
}
} }
} }
} }
@ -256,6 +261,26 @@ export default {
console.error(error) console.error(error)
}) })
}, },
showSharedPage(shareObject) {
this.shareOptionConfig.shared = true
this.shareOptionConfig.linkLabel = '分享链接'
this.setShareLink(this.getShareLink(shareObject.shareId))
this.shareOption.isPrivacy = shareObject.isPrivacy
this.shareOption.operationPermissionList = shareObject.operationPermissionList || []
if (shareObject.expireDate) {
this.shareOption.expiresDate = moment(shareObject.expireDate).format('x')
}
this.shareOption.expiresDateOption = 2
this.extractionCode = shareObject.extractionCode
this.shareId = shareObject.shareId
},
showNotSharedPage() {
this.shareOptionConfig.shared = false
this.shareOptionConfig.linkLabel = '选择有效期'
this.shareOption.isPrivacy = false
this.shareOption.expiresDate = null
this.shareOption.expiresDateOption = 1
},
shareDialogClose() { shareDialogClose() {
this.shareOptionConfig.shared = false this.shareOptionConfig.shared = false
this.$emit('update:status', this.shareDialogVisible) this.$emit('update:status', this.shareDialogVisible)
@ -272,9 +297,31 @@ export default {
this.shareOption.expiresDate = null this.shareOption.expiresDate = null
} }
if (this.shareOptionConfig.shared) { if (this.shareOptionConfig.shared) {
this.createShare(true) this.createShare('pickerChange')
} }
}, },
// 切换分享形式
shareFormChange() {
this.createShare('shareFormChange')
},
// 取消分享
cancelShare() {
let title = '确定要取消分享 "' + this.filename + '" 吗?'
this.$confirm(title, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
api.cancelShareLink({
userId: this.$store.state.user.userId,
shareId: [this.shareId]
}).then(() => {
this.$emit('onCancelShare')
this.shareDialogVisible = false
this.shareDialogClose()
})
})
},
submitShare() { submitShare() {
this.$refs.form.validate((valid) => { this.$refs.form.validate((valid) => {
if (valid) { if (valid) {
@ -303,6 +350,9 @@ export default {
break break
case 2: case 2:
if (this.shareOption.expiresDate) { if (this.shareOption.expiresDate) {
if (typeof this.shareOption.expiresDate === 'string') {
this.shareOption.expiresDate = Number(this.shareOption.expiresDate)
}
expireDate = this.timeFormat(this.shareOption.expiresDate) expireDate = this.timeFormat(this.shareOption.expiresDate)
} }
} }
@ -317,6 +367,7 @@ export default {
if (res.data) { if (res.data) {
let {shareId, extractionCode, operationPermissionList} = res.data let {shareId, extractionCode, operationPermissionList} = res.data
this.setShareLink(this.getShareLink(shareId)) this.setShareLink(this.getShareLink(shareId))
this.shareId = shareId
this.generateShareLinkLoading = false this.generateShareLinkLoading = false
this.shareOptionConfig.shared = true this.shareOptionConfig.shared = true
this.shareOption.expiresDateOption = 2 this.shareOption.expiresDateOption = 2
@ -324,7 +375,18 @@ export default {
this.extractionCode = extractionCode this.extractionCode = extractionCode
this.shareOption.operationPermissionList = operationPermissionList || [] this.shareOption.operationPermissionList = operationPermissionList || []
this.$emit('onSuccess', shareId) this.$emit('onSuccess', shareId)
if (update) { if (update === 'pickerChange') {
this.afterPickerChange(shareId, expireDate)
}
if (update === 'shareFormChange') {
this.afterShareFormChange(shareId)
}
}
}).catch(() => {
this.generateShareLinkLoading = false
})
},
afterPickerChange (shareId, expireDate) {
if (!expireDate) { if (!expireDate) {
expireDate = '永久有效' expireDate = '永久有效'
} }
@ -335,11 +397,15 @@ export default {
iconClass: 'el-icon-success', iconClass: 'el-icon-success',
message: '<strong>&nbsp;&nbsp;有效期已设置为: <span>' + expireDate + '</span> </strong>' message: '<strong>&nbsp;&nbsp;有效期已设置为: <span>' + expireDate + '</span> </strong>'
}); });
} },
} afterShareFormChange(shareId) {
}).catch(() => { this.$emit("onUpdateShareForm", shareId, this.shareOption.isPrivacy);
this.generateShareLinkLoading = false this.$message({
}) duration: 3000,
dangerouslyUseHTMLString: true,
iconClass: 'el-icon-success',
message: '<strong>&nbsp;&nbsp;链接已设置为: <span>' + (this.shareOption.isPrivacy ? '私密链接' : '公开链接') + '</span> </strong>'
});
}, },
// 复制分享链接 // 复制分享链接
copyShareLink(msg) { copyShareLink(msg) {
@ -441,7 +507,6 @@ export default {
} }
.share-link { .share-link {
margin-top: -10px;
margin-bottom: 25px; margin-bottom: 25px;
.share-link-code { .share-link-code {

View File

@ -834,6 +834,7 @@
:file.sync="shareDialogObject" :file.sync="shareDialogObject"
:status.sync="shareDialogVisible" :status.sync="shareDialogVisible"
@onSuccess="shareSuccess" @onSuccess="shareSuccess"
@onCancelShare="onCancelShare"
></share-dialog> ></share-dialog>
<el-dialog <el-dialog
class="new-text-file-dialog" class="new-text-file-dialog"
@ -4009,12 +4010,20 @@ export default {
this.shareDialogVisible = true this.shareDialogVisible = true
}, },
shareSuccess(shareBase) { shareSuccess(shareBase) {
this.updateRowContextData()
this.rowContextData.shareBase = shareBase
this.rowContextData.isShare = true
},
onCancelShare() {
this.updateRowContextData()
delete this.rowContextData.shareBase
delete this.rowContextData.isShare
},
updateRowContextData() {
// 这3行代码是为了让vue刷新数据 // 这3行代码是为了让vue刷新数据
const isFavorite = this.rowContextData.isFavorite const isFavorite = this.rowContextData.isFavorite
this.rowContextData.isFavorite = !isFavorite this.rowContextData.isFavorite = !isFavorite
this.rowContextData.isFavorite = isFavorite this.rowContextData.isFavorite = isFavorite
this.rowContextData.shareBase = shareBase
this.rowContextData.isShare = true
}, },
downloadFile() { downloadFile() {
let fileIds = [] let fileIds = []

View File

@ -1,6 +1,6 @@
<template> <template>
<div class="container"> <div class="container">
<share-dialog :file.sync="shareDialogObject" :status.sync="shareDialogVisible" @onUpdateExpireData="onUpdateExpireData"></share-dialog> <share-dialog :file.sync="shareDialogObject" :status.sync="shareDialogVisible" @onUpdateExpireData="onUpdateExpireData" @onUpdateShareForm="onUpdateShareForm"></share-dialog>
<!--list布局--> <!--list布局-->
<div v-show="fileList.length > 0" :style="{'width':'100%','height': clientHeight+'px'}"> <div v-show="fileList.length > 0" :style="{'width':'100%','height': clientHeight+'px'}">
<pl-table <pl-table
@ -138,7 +138,7 @@
header-align="left" header-align="left"
> >
<template slot-scope="scope"> <template slot-scope="scope">
<span>{{expireInfo(scope.row)}}</span> <span :style="{color: expireColor(scope.row)}">{{expireInfo(scope.row)}}</span>
</template> </template>
</pl-table-column> </pl-table-column>
</template> </template>
@ -271,6 +271,19 @@
return '永久有效' return '永久有效'
} }
}, },
expireColor(row) {
if (row.expireDate) {
let currentTime = new Date();
let targetTime = new Date(row.expireDate);
if (currentTime > targetTime) {
return '#F56C6C'
} else {
return '#606266'
}
} else {
return '#67C23A'
}
},
// 请求之前的准备 // 请求之前的准备
beforeLoadData(onLoad){ beforeLoadData(onLoad){
if (onLoad) { if (onLoad) {
@ -474,6 +487,12 @@
share.expireDate = expireDate share.expireDate = expireDate
this.fileList.splice(index, 1, share) this.fileList.splice(index, 1, share)
}, },
onUpdateShareForm(shareId, isPrivacy) {
let index = this.fileList.findIndex(item => item.id === shareId)
let share = this.fileList[index]
share.isPrivacy = isPrivacy
this.fileList.splice(index, 1, share)
}
} }
} }
</script> </script>