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.from = '' this.isExist = true this.pagesize = 10 } async dealData() { let { name, path, params, fullPath, query } = this.app.context.route // 重定向 // if (path.indexOf('/frontend/consult/user') > -1) { // this.redirect(301, '/c/' + uid) // } let [ userInfo, balanceInfo, workPlatInfo, typeList, hotInfo, levelInfo ] = await Promise.all([ this._getUserInfo(), this._getUserBalance(), this._getWorkPlatInfo(), this._getTypeList(), this._getHotData(), this._getLevelInfo() ]) let firstType = typeList[0] let dynamicList = await this._getDynamicDetail(firstType.typeId) let isMore = dynamicList.length < this.pagesize ? false : true return { isExist: this.isExist, mobile: this.app.$deviceType.isMobile(), // head: this.dealThisMeta(), userInfo, balanceInfo, workPlatInfo, typeList, hotInfo, levelInfo, dynamicList, firstType, isMore } } // 获取用户信息 async _getUserInfo() { let res = await this.$axios.$post('/uapi/user/info') // let res = await this.$axios.$post('/api/user/getInfo') let userInfo = {} if (Number(res.status) === 1) { let { info, login } = res.data // let info = {...res.data} // let login = {...res.data} userInfo['uid'] = login.uid; userInfo['realname_re'] = info.realname_re; userInfo['realname_verify_status'] = info.realname_verify_status; userInfo['dynamic_rand'] = info.dynamic_rand userInfo['rand_score'] = info.rand_score; userInfo['is_open_mall'] = info.is_open_mall userInfo['is_open_kill'] = info.is_open_kill userInfo['is_open_consult'] = info.is_open_consult userInfo['is_open_kc'] = info.is_open_kc userInfo['nickname'] = login.nickname userInfo['icon_url'] = login.icon_url userInfo['freework_level'] = info.freework_level } else if (Number(res.status) === 40001) { this.isExist = false } return userInfo } // 获取账户余额 async _getUserBalance() { let res = await this.$axios.$post('/api/account/getBalance') let balanceInfo = {} if (Number(res.status) === 1) { let info = res.data //账户余额 balanceInfo['totalBalance'] = info['totalBalance'] //总收入 balanceInfo['historyTotalBalance'] = info['historyTotalBalance'] //冻结余额 balanceInfo['frozenBalance'] = info['frozenBalance'] //薪资余额 balanceInfo['gongMallBalance'] = info['gongMallBalance'] } else if (Number(res.status) === 40001) { this.isExist = false } return balanceInfo } // 获取工作台统计数据 async _getWorkPlatInfo() { let res = await this.$axios.$post('/api/user/getWorkPlatformCount') let workPlatInfo = {} if (Number(res.status) === 1) { let info = res.data // 待办 workPlatInfo['pendingNumber'] = info['pendingNumber'] // 工作 workPlatInfo['developerWorkNumber'] = info['developerWorkNumber'] // 整包 workPlatInfo['developerProjectNumber'] = info['developerProjectNumber'] // 沟通 workPlatInfo['recruitDeveloperCount'] = info['recruitDeveloperCount'] } else if (Number(res.status) === 40001) { this.isExist = false } return workPlatInfo } // 动态列表 async _getDynamicDetail(type_id) { let res = await this.$axios.$post('/uapi/dynamic/get_dynamic_detail', { type_id, page: 1, pagesize: this.pagesize }) let dynamicList = [] if (Number(res.status) === 1) { let info = res.data.list info = info.map((item) => { let imgList = item.img imgList = imgList.map(item => { return item.img }) return { ...item, imgList } }) dynamicList = [...info] } else if (Number(res.status) === 40001) { this.isExist = false } return dynamicList } // 圈子分类 async _getTypeList() { let res = await this.$axios.$post('/uapi/dynamic/get_type_list') let typeList = [] if (Number(res.status) === 1) { let info = res.data typeList = [...info] typeList.unshift({ "typeId": 0, "name": "推荐", // "icon": "https://filescdn.proginn.com/test/community/666700/20220228/pTZku6d4C1.png", "num": "0" }) } else if (Number(res.status) === 40001) { this.isExist = false } return typeList } // 热门资源 async _getHotData(){ let res = await this.$axios.$get('/sapi/index/index') let hotInfo = { 'works':[], 'learn':[] } if (Number(res.status) === 1) { let {works,learn} = res.data hotInfo['works'] = works.splice(0,5) hotInfo['learn'] = learn.splice(0,5) } else if (Number(res.status) === 40001) { this.isExist = false } return hotInfo } // 获取经验接口 async _getLevelInfo(){ let res = await this.$axios.$post('/uapi/dynamic/get_dynamic_experience_info') let levelInfo = {} if (Number(res.status) === 1) { let {user,dynamic_rand,dynamic_rand_task,dynamic_rand_desc} = res.data levelInfo = { user,dynamic_rand,dynamic_rand_task,dynamic_rand_desc } } else if (Number(res.status) === 40001) { this.isExist = false } return levelInfo } dealThisMeta() { let title = '' let descriptionTitle = '' let description = '' let canonical = '' if (!this.isExist) { // 页面不存在时 return { title: "页面不存在-程序员客栈", keyword: "", description: "", h1: "", canonical: "", metaLocation: "" } } const nickname = this.consultDetail.user.nickname this.consultDetail.sale_list.forEach((item, index) => { if (index === 0) { title = item.title.trim() description = item.content.trim() } // if (index !== this.consultDetail.sale_list.length - 1) { // description += `${item.title}、` // } else { // description += item.title // } }) if (description.length > 15) { description = description.substring(0, 15) } if (title.length > 15) { descriptionTitle = title.substring(0, 15) } else { descriptionTitle = title } if (this.req) { const { headers: { host }, url } = this.req //拼接canonical if (host.indexOf('local') !== -1) { canonical = 'http://' + host + url } else { canonical = 'https://' + host + url } } let head = { title: `${title}-程序员客栈咨询服务`, keyword: `${this.consultDetail.user.company},${this.consultDetail.user.direction_name},${title}`, description: `${nickname}可以为您提供:${descriptionTitle},程序员客栈邀请到国内外互联网名企资深工作者,为您提供1对1技术咨询服务。`, h1: "", canonical: canonical, metaLocation: "" } return head } }