| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- export default class DealSeoData {
- constructor({$axios, req, app, redirect, error}) {
- this.$axios = $axios
- this.req = req
- this.app = app
- this.redirect = redirect
- this.error = error
- this.learnDetail = {}
- this.isExist = true
- }
- async dealData() {
- let {
- name,
- query: { act },
- path,
- params,
- fullPath
- } = this.app.context.route
- const sale_id = params.id || ''
- // 重定向
- if (path.indexOf('/frontend/learn/detail') > -1) {
- this.redirect(301, '/l/' + sale_id)
- }
- const learnDetail = await this._getLearnDetail(sale_id)
- const collectObj = await this._getLearnDetailCollected(sale_id)
- return {
- isExist: this.isExist,
- sale_id,
- learnDetail,
- collectObj,
- mobile: this.app.$deviceType.isMobile(),
- head: this.dealThisMeta(),
- act
- }
- }
- /** 获取课程详情 */
- async _getLearnDetail (sale_id="999") {
- let res = await this.$axios.$post('/sapi/learn/info', { sale_id })
- let learnDetail = {}
- // console.log(res)
- if (Number(res.status) === 1) {
- learnDetail = res.data
- } else if (Number(res.status) === 40001) {
- this.isExist = false
- }
- this.learnDetail=learnDetail;
- return learnDetail
- }
- async _getLearnDetailCollected(sale_id){
- let params = {
- type: '100',
- item_id: sale_id+''
- }
- let collectObj = {}
- let res = await this.$axios.$post('/uapi/collection/check', params)
- if(res.status==1){
- collectObj = res.data
- }
- return collectObj
- }
- dealThisMeta() {
- if (!this.isExist) {
- // 页面不存在时
- return {
- title: "页面不存在-程序员客栈",
- keyword: "",
- description: "",
- h1: "",
- canonical: "",
- metaLocation: ""
- }
- }
- let head = {
- title: `客栈学院`,
- keyword: `客栈学院`,
- description: `客栈学院`,
- h1: "",
- canonical: "",
- metaLocation: ""
- }
- head.title = `${this.learnDetail.seo.title}`
- head.keyword = `${this.learnDetail.seo.keywords}`;
- head.description = `${this.learnDetail.seo.description}`;
- return head
- }
- }
|