Merge pull request #356 from jamebal/dev

perf: 优化分享操作
This commit is contained in:
jmal 2025-01-12 00:42:07 +08:00 committed by GitHub
commit f15fbea449
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 133 additions and 37 deletions

View File

@ -237,6 +237,25 @@ export default {
params params
}) })
}, },
// 检测分享文件下是否含有子分享
hasSubShare: function(params) {
return request({
url: '/share/has-sub-share',
method: 'get',
params,
paramsSerializer: function(params) {
return qs.stringify(params, { arrayFormat: 'repeat' })
}
})
},
// 检测文件下是否含有子分享
folderSubShare: function(params) {
return request({
url: '/share/folder-sub-share',
method: 'get',
params
})
},
// 取消分享 // 取消分享
cancelShareLink: function(params) { cancelShareLink: function(params) {
return request({ return request({

View File

@ -108,7 +108,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="danger" @click="cancelShare" v-loading="cancelSharing">取消分享</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>
@ -164,6 +164,7 @@ export default {
audioCoverUrl: `${process.env.VUE_APP_BASE_API}/view/cover?jmal-token=${this.$store.state.user.token}&name=${this.$store.state.user.name}&id=`, audioCoverUrl: `${process.env.VUE_APP_BASE_API}/view/cover?jmal-token=${this.$store.state.user.token}&name=${this.$store.state.user.name}&id=`,
shareDialogVisible: false, shareDialogVisible: false,
generateShareLinkLoading: false, generateShareLinkLoading: false,
cancelSharing: false,
pickerOptions: { pickerOptions: {
disabledDate(time) { disabledDate(time) {
const dateTime = new Date(); const dateTime = new Date();
@ -260,7 +261,7 @@ export default {
this.showSharedPage(shareObject) this.showSharedPage(shareObject)
}) })
} else { } else {
this.showNotSharedPage() this.showNotSharedPage(this.file)
} }
} }
} }
@ -293,14 +294,24 @@ export default {
this.extractionCode = shareObject.extractionCode this.extractionCode = shareObject.extractionCode
this.shareId = shareObject.shareId this.shareId = shareObject.shareId
}, },
showNotSharedPage() { showNotSharedPage(file) {
this.shareOptionConfig.shared = false this.shareOptionConfig.shared = false
this.shareOptionConfig.linkLabel = '选择有效期' this.shareOptionConfig.linkLabel = '选择有效期'
this.shareOption.isPrivacy = false this.shareOption.isPrivacy = false
this.shareOption.expiresDate = null this.shareOption.expiresDate = null
this.shareOption.expiresDateOption = 1 this.shareOption.expiresDateOption = 1
if (file.isShare) {
this.shareOption.isPrivacy = file.isPrivacy
if (file.expiresAt > 253398735999000) {
this.shareOption.expiresDateOption = 1
} else {
this.shareOption.expiresDate = file.expiresAt
this.shareOption.expiresDateOption = 2
}
}
}, },
shareDialogClose() { shareDialogClose() {
this.cancelSharing = false
this.shareOptionConfig.shared = false this.shareOptionConfig.shared = false
this.$emit('update:status', this.shareDialogVisible) this.$emit('update:status', this.shareDialogVisible)
}, },
@ -328,12 +339,36 @@ export default {
}, },
// 取消分享 // 取消分享
cancelShare() { cancelShare() {
this.cancelSharing = true
api.hasSubShare({shareIds: [this.shareId]}).then(res => {
if (res.data) {
this.$confirm('所选的文件夹下存其他分享,取消分享后其下的所有分享链接都将被删除,是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.doCancelShareLink()
}).catch(() => {
this.cancelSharing = false
})
} else {
let title = '确定要取消分享 "' + this.file.name + '" 吗?' let title = '确定要取消分享 "' + this.file.name + '" 吗?'
this.$confirm(title, '提示', { this.$confirm(title, '提示', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
this.doCancelShareLink()
}).catch(() => {
this.cancelSharing = false
})
}
}).catch(() => {
this.cancelSharing = false
})
},
doCancelShareLink() {
api.cancelShareLink({ api.cancelShareLink({
userId: this.$store.state.user.userId, userId: this.$store.state.user.userId,
shareId: [this.shareId] shareId: [this.shareId]
@ -341,7 +376,8 @@ export default {
this.$emit('onCancelShare') this.$emit('onCancelShare')
this.shareDialogVisible = false this.shareDialogVisible = false
this.shareDialogClose() this.shareDialogClose()
}) }).catch(() => {
this.cancelSharing = false
}) })
}, },
submitShare() { submitShare() {
@ -389,7 +425,30 @@ export default {
this.generateShareLinkLoading = false this.generateShareLinkLoading = false
return return
} }
// 检查文件夹下是否有其他分享
if (this.file.isFolder) {
api.folderSubShare({fileId: this.file.id}).then(res => {
if (res.data) {
this.$confirm('所选的文件夹下存其他分享,创建分享后将会覆盖其下所有已分享的链接参数,是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.doCreateShare(update, expireDate)
}).catch(() => {
this.generateShareLinkLoading = false
})
} else {
this.doCreateShare(update, expireDate)
}
}).catch(() => {
this.generateShareLinkLoading = false
})
} else {
this.doCreateShare(update, expireDate)
}
},
doCreateShare(update, expireDate) {
api.generate({ api.generate({
shortId: this.shareOption.customAddr, shortId: this.shareOption.customAddr,
userId: this.$store.state.user.userId, userId: this.$store.state.user.userId,

View File

@ -79,6 +79,7 @@
</template> </template>
<template slot-scope="scope"> <template slot-scope="scope">
<span class="table-file-name">{{ scope.row.fileName }}</span> <span class="table-file-name">{{ scope.row.fileName }}</span>
<span v-if="scope.row.fatherShareId" style="color: #9a9a9a">(子分享)</span>
</template> </template>
</pl-table-column> </pl-table-column>
<!--取消分享--> <!--取消分享-->
@ -448,12 +449,7 @@
}, },
// 取消分享 // 取消分享
cancelShare(row) { cancelShare(row) {
let title = row === false ? '确定要取消选中的' + this.selectRowData.length + '项分享吗?' : '确定要取消分享 "' + row.fileName + '" 吗?'
this.$confirm(title, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
let shareIds = [] let shareIds = []
if(row){ if(row){
shareIds.push(row.id) shareIds.push(row.id)
@ -462,6 +458,29 @@
shareIds.push(row.id) shareIds.push(row.id)
}) })
} }
api.hasSubShare({shareIds: shareIds}).then(res => {
if (res.data) {
this.$confirm('所选的文件夹下存其他分享,取消分享后其下的所有分享链接都将被删除,是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.doCancelShare(shareIds)
})
} else {
let title = row === false ? '确定要取消选中的' + this.selectRowData.length + '项分享吗?' : '确定要取消分享 "' + row.fileName + '" 吗?'
this.$confirm(title, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.doCancelShare(shareIds)
})
}
})
},
doCancelShare(shareIds) {
api.cancelShareLink({ api.cancelShareLink({
userId: this.$store.state.user.userId, userId: this.$store.state.user.userId,
shareId: shareIds shareId: shareIds
@ -472,7 +491,6 @@
this.getFileList() this.getFileList()
} }
}) })
})
}, },
onCancelShare() { onCancelShare() {
this.getFileList() this.getFileList()