深圳或然科技官网
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

133 lines
5.1 KiB

import Util from '@/libs/util'
export default {
data () {
return {
id: this.$route.query.id,
preview: this.$route.query.preview,
listPreview: this.$route.query.listPreview,
modules: [],
articles: []
}
},
computed: {
site () {
return this.$route.query.siteId || this.$store.state.content.site
}
},
mounted () {
this.getInfo && this.$route.query.id && this.init()
},
methods: {
// 初始化
async init () {
// 预览直接可以看长页
if (this.listPreview || this.preview) {
this.getInfo()
} else {
// 前台正常进入长页,则需要先判断该长页的导航菜单字段是否被禁用
const { data } = await this.$post(`${this.api.findColumn}?id=${this.id}`)
data.menuVisible || this.getInfo()
}
},
// 打开链接
async openLink (item) {
const { link } = item
if (link.linkName === '无' || link.linkName === '') return false
let href = link.linkAddress
const type = link.connectionType
if (type === 1) { // 站内链接
if (link.articleId) { // 文章
// 查询文章详情。禁用的文章要提示
const data = await this.$post(`${this.api.findArticle}?id=${link.articleId}`)
if (data.data.isDisable) {
return Util.errorMsg('该文章已禁用!')
} else {
href = '/article?articleId=' + link.articleId
}
} else { // 栏目
href = '/column?id=' + link.columnId[link.columnId.length - 1]
}
href += '&siteId=' + (this.site)
if (!link.articleId) href = this.$router.resolve(href).href
} else if (type === 3) { // 站外链接
if (link.otherArticleId) { // 文章
// 查询文章详情。禁用的文章要提示
const data = await this.$post(`${this.api.findArticle}?id=${link.otherArticleId}`)
if (data.data.isDisable) {
return Util.errorMsg('该文章已禁用!')
} else {
href = '/article?articleId=' + link.otherArticleId
}
} else { // 栏目
href = '/column?id=' + link.otherColumnId[link.otherColumnId.length - 1]
}
href += '&siteId=' + link.site
if (!link.otherArticleId) href = this.$router.resolve(href).href
}
// 如果是站内/站外链接,并且选择的是文章,则要获取当前长页名称传到文章详情里,面包屑点返回的时候需要返回到当前长页
if ((type === 1 && link.articleId) || (type === 3 && link.otherArticleId)) {
this.$post(`${this.api.findColumn}?id=${this.id}`).then(({ data }) => {
href = this.$router.resolve(href + '&id=' + this.id + '&columnName=' + data.columnName + '&path=' + this.$route.path.replace('/', '')).href
this.toHref(link.isOpen, href)
}).catch(res => { })
} else {
this.toHref(link.isOpen, href)
}
},
// 跳转地址
toHref (isOpen, href) {
if (isOpen) {
var userAgent = navigator.userAgent;
var isSafari = /Safari/.test(userAgent) && !/Chrome/.test(userAgent);
if (isSafari) {
window.location.href = href
} else {
window.open(href)
}
} else {
window.location.href = href
}
},
// 跳转文章页面
toArtice (item, form) {
if (item.articleTemplate === 24) { // 链接
let href = item.linkAddress
const cType = item.connectionType
if (cType !== 2) { // 非站外链接
const ids = href.split('-') // 栏目文章是用-分割的,栏目是必选,文章不是必选。选择了文章则跳转到文章页,否则跳转到栏目页
// 站点id:站内链接取当前站点,其他站点链接取siteSelection
const site = cType === 1 ?
(this.site) :
item.siteSelection
if (ids[1]) { // 文章
href = '/article?articleId=' + ids[1]
} else { // 栏目
const columnIds = ids[0].split(',')
href = '/column?id=' + columnIds[columnIds.length - 1]
}
href = this.$router.resolve(href + '&siteId=' + site).href
}
this.toHref(item.isOpen, href)
} else if (item.listStyleId === 73) { // 长页模板为产品中心的,该栏目下的文章全部跳产品详情页
this.$router.push(`/index/show?id=${item.id}`)
} else {
let href = `/article?articleId=${item.id}&siteId=${this.site}&id=${this.id}`
if (form) href += `&columnName=${form.columnTitle === 2 ? form.columnTitleCustom : form.columnName}&path=${this.$route.path.replace('/', '')}`
this.$router.push(href)
}
},
// 关联栏目的查看全部跳转
toAll (form) {
this.$router.push(`/column?id=${form.column[form.column.length - 1]}&siteId=${form.site}`)
},
// 判断是否有添加链接
isLink (linkName) {
return linkName !== '无' && linkName !== ''
},
// 关联栏目专用,获取栏目标题
getColumnTitle (form) {
return form.columnTitle == 1 ? form.columnName : form.columnTitleCustom
}
}
};