123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- import { mapGetters } from 'vuex'
- import { toAuthorization } from '~/utils'
- import downloadFile from '~/utils/donwload-tools'
- import { isWeChat } from '~/utils/validator'
- export default {
- layout: 'app-ross',
- filters: {
- crumbFormat(name) {
- if (name.length < 12) return name
- return name.substring(0, 10) + '…'
- },
- fileNameFormat(name) {
- return name.replace(/(.+)(.txt$)/, (match, $1, $2) => {
- return $1
- })
- },
- },
- data() {
- return {
- fileId: '',
- list: [],
- crumbList: [],
- }
- },
- computed: {
- ...mapGetters([
- 'routePrefix',
- 'supplierInfo',
- 'authUserId',
- 'accountType',
- 'appId',
- ]),
- },
- created() {
- this.fileId = this.$route.params.fileId
- this.fetchFileList()
- this.fetchCrumbsList()
- },
- methods: {
- // 处理面包屑
- generateCrumb(node) {
- const list = []
- if (!node) return list
- function recursive(node) {
- list.push(node)
- if (node.childNode) {
- recursive(node.childNode)
- }
- }
- recursive(node)
- return list
- },
- // 获取面包屑
- async fetchCrumbsList() {
- try {
- const res = await this.$http.api.fetchCrumbsList({
- authUserId: this.authUserId,
- fileId: this.fileId,
- })
- this.crumbList = this.generateCrumb(res.data)
- } catch (error) {
- console.log(error)
- }
- },
- // 下一级
- onRowClick(row) {
- if (row.fileType === 'article') {
- if (!this.checkLogin()) return
- if (row.articleType === 1) {
- const url = `${this.routePrefix}/database/article-detail?id=${row.articleId}`
- this.$router.push(url)
- } else {
- window.open(row.ossUrl, '_blank')
- }
- } else if (row.packageType === 1) {
- if (!this.checkLogin()) return
- this.$router.push(`${this.routePrefix}/docs/detail?id=${row.id}`)
- } else {
- this.$router.push(`${this.routePrefix}/docs/${row.id}`)
- }
- },
- // 获取文件列表
- async fetchFileList() {
- try {
- const res = await this.$http.api.fetchDocsList({
- fileId: this.fileId,
- authUserId: this.authUserId,
- })
- this.list = res.data
- } catch (error) {
- console.log(error)
- }
- },
- // 校验登录
- checkLogin() {
- const hasLogin = this.$store.getters.accessToken
- if (!hasLogin) {
- // 在微信浏览器中使用微信授权登录
- if (isWeChat() && this.appId && this.accountType === 2) {
- const payload = {
- authUserId: this.authUserId,
- routePrefix: this.routePrefix,
- }
- return toAuthorization(this.appId, payload)
- }
- this.$toast({ message: '请先登录', duration: 1000 })
- this.$store.commit('app/SHOW_LOGIN')
- return false
- }
- return true
- },
- // 下载文件
- onDownload(row, $event) {
- if (!this.checkLogin()) return
- let downUrl = ''
- if (row.packageType === 0) {
- downUrl = `${process.env.BASE_URL}/wx/data/path/package/zip?fileId=${
- row.id
- }&fileName=${encodeURIComponent(row.fileName)}&authUserId=${
- this.authUserId
- }`
- } else {
- downUrl = `${process.env.BASE_URL}/download/file?ossName=${
- row.ossName
- }&fileName=${encodeURIComponent(row.fileName)}`
- }
- downloadFile(downUrl, row.fileName, this, $event)
- },
- },
- }
|