Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: 美化分享链接URL #162

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<script>
const pcList = ['/', '/s']
const mobileList = ['/_m', '/_m/', '/s_m', '/s_m/']
const mobileList = ['/_m', '/_m/']
export default {
name: 'App',
components: {},
Expand Down
13 changes: 8 additions & 5 deletions src/components/ShareDialog/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ export default {
showSharedPage(shareObject) {
this.shareOptionConfig.shared = true
this.shareOptionConfig.linkLabel = '分享链接'
this.setShareLink(this.getShareLink(shareObject.shareId))
this.setShareLink(this.getShareLink(shareObject.shareId, shareObject.shortId))
this.shareOption.isPrivacy = shareObject.isPrivacy
this.shareOption.operationPermissionList = shareObject.operationPermissionList || []
if (shareObject.expireDate) {
Expand Down Expand Up @@ -339,8 +339,11 @@ export default {
timeFormat(time) {
return moment(time).format("yyyy-MM-DD HH:mm")
},
getShareLink(shareId) {
return window.location.origin + '/s?s=' + shareId
getShareLink(shareId, shortId) {
if (!shortId) {
shortId = shareId
}
return `${window.location.origin}/s/${shortId}`
},
createShare(update) {
this.generateShareLinkLoading = true
Expand Down Expand Up @@ -368,8 +371,8 @@ export default {
operationPermissionList: this.shareOption.operationPermissionList
}).then(res => {
if (res.data) {
let {shareId, extractionCode, operationPermissionList} = res.data
this.setShareLink(this.getShareLink(shareId))
let {shareId, shortId, extractionCode, operationPermissionList} = res.data
this.setShareLink(this.getShareLink(shareId, shortId))
this.shareId = shareId
this.generateShareLinkLoading = false
this.shareOptionConfig.shared = true
Expand Down
13 changes: 11 additions & 2 deletions src/permission.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import getPageTitle from '@/utils/get-page-title'

NProgress.configure({ showSpinner: false }) // NProgress配置

const whiteList = ['/login','/s','/s/','/s_m','/s_m/'] // 白名单
const whiteList = ['/login','/s','/s/'] // 白名单

router.beforeEach(async(to, from, next) => {
// 开始进度条
Expand Down Expand Up @@ -51,7 +51,7 @@ router.beforeEach(async(to, from, next) => {
}
} else {
// 没有登录的情况
if (whiteList.indexOf(to.path) !== -1) {
if (hasWhiteList(to.path)) {
// 没有token但是在白名单中,直接进入
next()
} else {
Expand All @@ -65,6 +65,15 @@ router.beforeEach(async(to, from, next) => {
}
})

function hasWhiteList(path) {
for (let i = 0; i < whiteList.length; i++) {
if (path.indexOf(whiteList[i]) !== -1) {
return true
}
}
return false
}

function setMenuList(next, to){
if(store.getters.menuList.length === 0){
store.dispatch('user/setMenuList').then((res) => {
Expand Down
15 changes: 2 additions & 13 deletions src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ export const constantRoutes = [
hidden: true
},
{
path: '/s',
path: '/s/:id',
component: Layout,
children: [
{
path: '',
name: 's',
name: 'share',
component: () => import('@/views/public/share/shareList'),
}
]
Expand Down Expand Up @@ -85,17 +85,6 @@ export const dynamicRouters = [
meta: { title: '文件传输' }
}]
},
{
path: '/s_m',
component: Layout,
children: [
{
path: '',
name: 's_m',
component: () => import('@/views/public/share/shareList'),
}
]
},
{
path: '/tag',
component: Layout,
Expand Down
27 changes: 19 additions & 8 deletions src/views/public/share/shareList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
</van-grid>
</van-checkbox-group>
</div>
<div v-if="linkFailed && !showShareCode" class="share-header">
<div v-if="linkFailed && !showShareCode" class="share-header-prompt">
<p v-if="prompt !== ''">温馨提示:</p>
<p>{{ prompt }}</p>
</div>
Expand Down Expand Up @@ -401,7 +401,8 @@ export default {
shareLink: '',
shareFileName: '',
generateShareLinkLoading: true,
shareId: this.$route.query.s,
shareId: '',
shortId: this.$route.params.id,
currentDirName: '',
linkFailed: true,
textPreviewVisible: false,
Expand Down Expand Up @@ -584,7 +585,7 @@ export default {
if (index === 0) {
this.pathList.splice(this.pathList.findIndex((v, i) => i === index + 1), this.pathList.length - (index + 1))
this.getFileList(null, true);
this.$router.push(`/s?s=${this.shareId}&vmode=${this.vmode}`)
this.pushRouter()
}
if (item && item.fileId) {
this.accessShareOpenDir(item.fileId)
Expand All @@ -598,8 +599,7 @@ export default {
if (this.grid) {
this.vmode = 'grid'
}
let f = ''
this.$router.push(`/s?s=${this.shareId}&vmode=${this.vmode}`)
this.pushRouter()
},
accessShareOpenDir(fileId) {
this.tableLoading = true
Expand Down Expand Up @@ -627,7 +627,7 @@ export default {
getFileList(pagination, overload) {
this.tableLoading = true
api.accessShare({
share: this.shareId,
share: this.shortId,
pageIndex: this.pagination.pageIndex,
pageSize: this.pagination.pageSize,
showFolderSize: true
Expand Down Expand Up @@ -689,10 +689,11 @@ export default {
})
},
getSharer() {
api.getSharer({shareId: this.shareId}).then(res => {
api.getSharer({shareId: this.shortId}).then(res => {
this.sharer = res.data
this.setLoginTitle()
if (res.data) {
this.shareId = res.data.shareId
this.sharerAvatarUrl = window.location.origin + this.imageUrl + res.data.avatar
if (this.sharer.netdiskName) {
this.netdiskName = this.sharer.netdiskName
Expand Down Expand Up @@ -1046,6 +1047,9 @@ export default {
clipboard.destroy()
})
},
pushRouter() {
this.$router.push(`/s/${this.shortId}/?vmode=${this.vmode}`)
},
// 点击文件或文件夹
fileClick(row) {
window.shareId = this.shareId
Expand All @@ -1057,7 +1061,7 @@ export default {
item['index'] = this.pathList.length
this.pathList.push(item)
this.pagination.pageIndex = 1
this.$router.push(`?s=${this.shareId}&vmode=${this.vmode}`)
this.pushRouter()
this.accessShareOpenDir(row.id)
} else {
if (row.contentType.startsWith('image')) {
Expand Down Expand Up @@ -1133,6 +1137,13 @@ export default {
padding: 0 15px;
}

.share-header-prompt {
text-align: center;
font-size: 18px;
font-weight: 500;
margin-bottom: 10px;
}

.share-header {
text-align: center;
font-size: 18px;
Expand Down