perf: 优化挂载的文件的访问
This commit is contained in:
parent
14ea2ac105
commit
9206bbec4a
@ -54,6 +54,14 @@ export function getInfo(params) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getUsername(params) {
|
||||||
|
return request({
|
||||||
|
url: 'user/username',
|
||||||
|
method: 'get',
|
||||||
|
params
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export function userList(params) {
|
export function userList(params) {
|
||||||
return request({
|
return request({
|
||||||
url: 'user/userList',
|
url: 'user/userList',
|
||||||
|
|||||||
@ -178,7 +178,7 @@ export default {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
let request = 'previewText'
|
let request = 'previewText'
|
||||||
if (this.hasReadOnly) {
|
if (!this.$store.state.user.token) {
|
||||||
request = 'sharePreviewText'
|
request = 'sharePreviewText'
|
||||||
}
|
}
|
||||||
this.content = null
|
this.content = null
|
||||||
@ -411,6 +411,7 @@ export default {
|
|||||||
relativePath: encodeURI(this.file.path + this.file.name),
|
relativePath: encodeURI(this.file.path + this.file.name),
|
||||||
userId: this.$store.state.user.userId,
|
userId: this.$store.state.user.userId,
|
||||||
username: this.$store.state.user.name,
|
username: this.$store.state.user.name,
|
||||||
|
mountFileId: this.$store.state.user.userId !== this.file.userId ? this.file.id : '',
|
||||||
contentText: value
|
contentText: value
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
this.saveBtnUpdating = false
|
this.saveBtnUpdating = false
|
||||||
|
|||||||
@ -869,6 +869,7 @@ import fileConfig from "@/utils/file-config";
|
|||||||
import EditElement from "@/views/markdown/EditElement";
|
import EditElement from "@/views/markdown/EditElement";
|
||||||
import OfficePreview from "@/components/preview/OfficePreview";
|
import OfficePreview from "@/components/preview/OfficePreview";
|
||||||
import ShareDialog from "@/components/ShareDialog/index.vue";
|
import ShareDialog from "@/components/ShareDialog/index.vue";
|
||||||
|
import {getUsername} from "@/api/user";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "ShowFile",
|
name: "ShowFile",
|
||||||
@ -2621,8 +2622,25 @@ export default {
|
|||||||
this.pageLoadCompleteList[this.pagination.pageIndex] = true;
|
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) {
|
if (this.onCreateFilename) {
|
||||||
let index = this.fileList.findIndex(item => item.name === this.onCreateFilename);
|
let index = this.fileList.findIndex(item => item.name === this.onCreateFilename);
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
|
|||||||
@ -101,7 +101,7 @@ export default {
|
|||||||
}
|
}
|
||||||
this.xml = ''
|
this.xml = ''
|
||||||
let request = 'previewText'
|
let request = 'previewText'
|
||||||
if(this.readOnly){
|
if (!this.$store.state.user.token) {
|
||||||
request = 'sharePreviewText'
|
request = 'sharePreviewText'
|
||||||
}
|
}
|
||||||
api[request]({
|
api[request]({
|
||||||
@ -221,6 +221,7 @@ export default {
|
|||||||
relativePath: encodeURI(this.file.path + this.file.name),
|
relativePath: encodeURI(this.file.path + this.file.name),
|
||||||
userId: this.$store.state.user.userId,
|
userId: this.$store.state.user.userId,
|
||||||
username: this.$store.state.user.name,
|
username: this.$store.state.user.name,
|
||||||
|
mountFileId: this.$store.state.user.userId !== this.file.userId ? this.file.id : '',
|
||||||
contentText: value
|
contentText: value
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
this.saveBtnUpdating = false
|
this.saveBtnUpdating = false
|
||||||
|
|||||||
@ -93,7 +93,7 @@ export default {
|
|||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
this.previewDocument = document.querySelector('.preview-block')
|
this.previewDocument = document.querySelector('.preview-block')
|
||||||
})
|
})
|
||||||
this.checkReadOnly(this.file.userId)
|
this.checkReadOnly(this.file)
|
||||||
// 12秒后还没加载出来视为加载失败
|
// 12秒后还没加载出来视为加载失败
|
||||||
let that = this
|
let that = this
|
||||||
this.delayClosing = setTimeout(function () {
|
this.delayClosing = setTimeout(function () {
|
||||||
@ -208,10 +208,13 @@ export default {
|
|||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* 检查要预览调文件是否为只读
|
* 检查要预览调文件是否为只读
|
||||||
* @param fileUserId userId
|
* @param file userId
|
||||||
*/
|
*/
|
||||||
checkReadOnly(fileUserId){
|
checkReadOnly(file){
|
||||||
if(this.$store.state.user.token && this.$store.state.user.userId === fileUserId){
|
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
|
this.readOnly = false
|
||||||
}
|
}
|
||||||
if (!this.$pc && this.fileType === 'office') {
|
if (!this.$pc && this.fileType === 'office') {
|
||||||
|
|||||||
@ -809,7 +809,7 @@
|
|||||||
} else {
|
} else {
|
||||||
this.mountFileId = file.id
|
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.options.readOnly = false
|
||||||
this.panelReadOnly = true
|
this.panelReadOnly = true
|
||||||
return
|
return
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import fileApi from '@/api/file-api'
|
import fileApi from '@/api/file-api'
|
||||||
|
import store from '@/store'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
baseUrl: '/api',
|
baseUrl: '/api',
|
||||||
@ -20,7 +21,11 @@ export default {
|
|||||||
},
|
},
|
||||||
// 预览文件的url
|
// 预览文件的url
|
||||||
previewUrl: function(username, file, token, shareToken) {
|
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, '/')
|
fileUrl = fileUrl.replace(/%5C/g, '/')
|
||||||
if (token) {
|
if (token) {
|
||||||
return `${fileUrl}?jmal-token=${token}&name=${username}`
|
return `${fileUrl}?jmal-token=${token}&name=${username}`
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user