dataease/frontend/src/views/link/index.vue

96 lines
2.2 KiB
Vue
Raw Normal View History

2021-03-25 18:58:05 +08:00
<template>
2021-04-20 11:21:53 +08:00
<div style="height: 100%;">
2021-03-29 14:15:39 +08:00
<link-error v-if="showIndex===0" :resource-id="resourceId" />
2021-12-19 14:46:33 +08:00
<link-pwd v-if="showIndex===1" :resource-id="resourceId" :user="user" @fresh-token="refreshToken" />
<link-view v-if="showIndex===2" :resource-id="resourceId" :user="user"/>
<link-expire v-if="showIndex===3" :resource-id="resourceId" :user="user"/>
2021-03-25 18:58:05 +08:00
</div>
</template>
<script>
import { getQueryVariable } from '@/utils/index'
import { validate } from '@/api/link'
import LinkView from './view'
import LinkError from './error'
import LinkPwd from './pwd'
2021-10-20 14:03:50 +08:00
import LinkExpire from './overtime'
2021-03-25 18:58:05 +08:00
export default {
components: {
2021-10-20 14:03:50 +08:00
LinkError, LinkPwd, LinkView, LinkExpire
2021-03-25 18:58:05 +08:00
},
2021-11-26 11:38:25 +08:00
2021-03-25 18:58:05 +08:00
data() {
return {
2021-03-29 14:15:39 +08:00
resourceId: null,
2021-03-25 18:58:05 +08:00
PARAMKEY: 'link',
link: null,
2021-12-19 14:46:33 +08:00
user: null,
2021-03-25 18:58:05 +08:00
showIndex: -1
}
},
created() {
this.loadInit()
},
methods: {
loadInit() {
this.$store.commit('setPublicLinkStatus', true)
2021-11-26 11:38:25 +08:00
this.link = this.$route.query.link
2021-12-19 14:46:33 +08:00
this.user = this.$route.query.user
2021-11-26 11:38:25 +08:00
if (!this.link) {
this.link = getQueryVariable(this.PARAMKEY)
}
2021-12-19 14:46:33 +08:00
if (!this.user) {
this.user = getQueryVariable('user')
}
2021-11-26 11:38:25 +08:00
if (!this.link) {
this.showError()
return
}
2021-12-19 14:46:33 +08:00
let params = this.user ? { link: encodeURIComponent(this.link), user: this.user} : { link: encodeURIComponent(this.link)};
validate(params).then(res => {
2021-10-20 14:03:50 +08:00
const { resourceId, valid, enablePwd, passPwd, expire } = res.data
2021-03-29 14:15:39 +08:00
this.resourceId = resourceId
2021-03-25 18:58:05 +08:00
// 如果链接无效 直接显示无效页面
2021-03-29 14:15:39 +08:00
if (!valid || !resourceId) {
2021-03-26 18:44:41 +08:00
this.showError()
return
}
2021-03-25 18:58:05 +08:00
2021-10-20 14:03:50 +08:00
if (expire) {
this.showExpire()
return
}
2021-03-26 18:44:41 +08:00
if (enablePwd && !passPwd) {
this.showPwd()
return
}
2021-03-25 18:58:05 +08:00
this.showView()
2021-03-29 14:15:39 +08:00
}).catch(() => {
this.showError()
2021-03-25 18:58:05 +08:00
})
},
2021-08-13 14:00:12 +08:00
refreshToken() {
this.loadInit()
},
2021-03-26 18:44:41 +08:00
2021-03-25 18:58:05 +08:00
// 显示无效链接
showError() {
this.showIndex = 0
},
// 显示密码框
showPwd() {
this.showIndex = 1
},
// 显示仪表板
showView() {
this.showIndex = 2
2021-10-20 14:03:50 +08:00
},
showExpire() {
this.showIndex = 3
2021-03-25 18:58:05 +08:00
}
}
}
</script>