diff --git a/src/api/user.js b/src/api/user.js index cfd24f3..f1a06c7 100644 --- a/src/api/user.js +++ b/src/api/user.js @@ -54,6 +54,14 @@ export function getInfo(params) { }) } +export function getUsername(params) { + return request({ + url: 'user/username', + method: 'get', + params + }) +} + export function userList(params) { return request({ url: 'user/userList', diff --git a/src/components/Minder/minder.vue b/src/components/Minder/minder.vue index 8c4b06c..c21ced8 100644 --- a/src/components/Minder/minder.vue +++ b/src/components/Minder/minder.vue @@ -178,7 +178,7 @@ export default { return } let request = 'previewText' - if (this.hasReadOnly) { + if (!this.$store.state.user.token) { request = 'sharePreviewText' } this.content = null @@ -411,6 +411,7 @@ export default { relativePath: encodeURI(this.file.path + this.file.name), userId: this.$store.state.user.userId, username: this.$store.state.user.name, + mountFileId: this.$store.state.user.userId !== this.file.userId ? this.file.id : '', contentText: value }).then(() => { this.saveBtnUpdating = false diff --git a/src/components/ShowFile/ShowFile.vue b/src/components/ShowFile/ShowFile.vue index 80ff4df..8cf64f3 100644 --- a/src/components/ShowFile/ShowFile.vue +++ b/src/components/ShowFile/ShowFile.vue @@ -869,6 +869,7 @@ import fileConfig from "@/utils/file-config"; import EditElement from "@/views/markdown/EditElement"; import OfficePreview from "@/components/preview/OfficePreview"; import ShareDialog from "@/components/ShareDialog/index.vue"; +import {getUsername} from "@/api/user"; export default { name: "ShowFile", @@ -2621,8 +2622,25 @@ export default { this.pageLoadCompleteList[this.pagination.pageIndex] = true; }); // 加载菜单状态 - this.loadContextMenus(); + this.loadContextMenus() // 高亮新增的文件 + this.highlightNewFile() + // 设置挂载文件的用户名(文件的所有者) + this.setMountFileOwner() + }, + // 设置挂载文件的用户名(文件的所有者) + setMountFileOwner() { + if (this.$route.query.folder && this.fileList.length > 0) { + let firstFile = this.fileList[0] + if (firstFile.userId !== this.$store.getters.userId) { + getUsername({userId: firstFile.userId}).then(res => { + localStorage.setItem('mountFileOwner', res.data) + }) + } + } + }, + // 高亮新增文件 + highlightNewFile() { if (this.onCreateFilename) { let index = this.fileList.findIndex(item => item.name === this.onCreateFilename); if (index > -1) { diff --git a/src/components/office/Drawio.vue b/src/components/office/Drawio.vue index ea08b45..932ffa4 100644 --- a/src/components/office/Drawio.vue +++ b/src/components/office/Drawio.vue @@ -101,7 +101,7 @@ export default { } this.xml = '' let request = 'previewText' - if(this.readOnly){ + if (!this.$store.state.user.token) { request = 'sharePreviewText' } api[request]({ @@ -221,6 +221,7 @@ export default { relativePath: encodeURI(this.file.path + this.file.name), userId: this.$store.state.user.userId, username: this.$store.state.user.name, + mountFileId: this.$store.state.user.userId !== this.file.userId ? this.file.id : '', contentText: value }).then(() => { this.saveBtnUpdating = false diff --git a/src/components/preview/OfficePreview.vue b/src/components/preview/OfficePreview.vue index 3361a4e..fa9e5d4 100644 --- a/src/components/preview/OfficePreview.vue +++ b/src/components/preview/OfficePreview.vue @@ -93,7 +93,7 @@ export default { this.$nextTick(() => { this.previewDocument = document.querySelector('.preview-block') }) - this.checkReadOnly(this.file.userId) + this.checkReadOnly(this.file) // 12秒后还没加载出来视为加载失败 let that = this this.delayClosing = setTimeout(function () { @@ -208,10 +208,13 @@ export default { }, /** * 检查要预览调文件是否为只读 - * @param fileUserId userId + * @param file userId */ - checkReadOnly(fileUserId){ - if(this.$store.state.user.token && this.$store.state.user.userId === fileUserId){ + checkReadOnly(file){ + if(this.$store.state.user.token && this.$store.state.user.userId === file.userId){ + this.readOnly = false + } + if (this.$store.state.user.token && file.operationPermissionList && file.operationPermissionList.indexOf('PUT') > -1) { this.readOnly = false } if (!this.$pc && this.fileType === 'office') { diff --git a/src/components/preview/SimTextPreview.vue b/src/components/preview/SimTextPreview.vue index c3d5700..7833f10 100644 --- a/src/components/preview/SimTextPreview.vue +++ b/src/components/preview/SimTextPreview.vue @@ -809,7 +809,7 @@ } else { this.mountFileId = file.id } - if (file.operationPermissionList && file.operationPermissionList.indexOf('PUT') > -1) { + if (this.$store.state.user.token && file.operationPermissionList && file.operationPermissionList.indexOf('PUT') > -1) { this.options.readOnly = false this.panelReadOnly = true return diff --git a/src/utils/file-config.js b/src/utils/file-config.js index 86cc4f8..4b40280 100644 --- a/src/utils/file-config.js +++ b/src/utils/file-config.js @@ -1,4 +1,5 @@ import fileApi from '@/api/file-api' +import store from '@/store' export default { baseUrl: '/api', @@ -20,7 +21,11 @@ export default { }, // 预览文件的url previewUrl: function(username, file, token, shareToken) { - let fileUrl = `${this.baseUrl}/file/${username}${encodeURI(file.path)}${encodeURI(file.name)}` + let owner = username + if (username !== store.getters.username) { + owner = localStorage.getItem('mountFileOwner') + } + let fileUrl = `${this.baseUrl}/file/${owner}${encodeURI(file.path)}${encodeURI(file.name)}` fileUrl = fileUrl.replace(/%5C/g, '/') if (token) { return `${fileUrl}?jmal-token=${token}&name=${username}`