| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277 |
- 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.pagination = {
- page: 1,
- pagesize: 9,
- total: 0,
- pageCount: 1,
- loading: false,
- selectedCateIdOne: '',
- selectedCateIdTwo: '',
- noMore: true
- }
- this.cateNameOne = ''
- this.cateNameTwo = ''
- this.mobile = this.app.$deviceType.isMobile()
- this.root_type = 0
- }
- async dealData() {
- const self = this
- let {
- name,
- query: { page = 1, root_type = 0 },
- path,
- params,
- fullPath
- } = this.app.context.route
- this.pagination.page = Number(page)
- this.root_type = root_type
- // 目前仅将二级 id 拼接到 url 上
- let match = params.pathMatch || ''
- let matchList = match.split('/')
- matchList.pop();
- let lastMatch = matchList.pop() || '';
- // console.log(`match: ${match}, matchList: ${matchList}, lastMatch: ${lastMatch}`)
- // 重定向
- if (path.indexOf('/frontend/consult/list') > -1) {
- this.redirect(301, '/consult/' + lastMatch)
- }
- let consultCate = await this._getConsultCate()
- let consultCateAll = []
- consultCate.forEach(item => {
- if (item.children && item.children.length) {
- item.children.forEach(child => {
- consultCateAll.push(child)
- })
- }
- })
- if (lastMatch) {
- // 遍历分类数组
- let selectedCateIdOne = ''
- consultCate.forEach(cateOne => {
- cateOne.children.forEach(cateTwo => {
- if (cateTwo.value === lastMatch) {
- selectedCateIdOne = cateOne.value
- self.cateNameOne = cateOne.label
- if (cateTwo.label === '全部') {
- self.cateNameTwo = cateOne.label
- } else {
- self.cateNameTwo = cateTwo.label
- }
- }
- })
- })
- if (selectedCateIdOne) {
- this.pagination.selectedCateIdOne = selectedCateIdOne
- this.pagination.selectedCateIdTwo = lastMatch
- }
- }
- // 处理完分类信息,再获取数据
- let consultList = await this._getConsultList()
- // 获取最新交易数据
- let newestTradeList = await this._getNewestTradeList()
- return {
- root_type,
- consultCate,
- consultCateAll,
- consultList, //首次获取的数据
- newestTradeList,
- mobile: this.mobile,
- pagination: this.pagination,
- head: this.dealThisMeta()
- }
- }
- /** 获取技能分类 */
- async _getConsultCate () {
- let res = await this.$axios.$post('/api/sale/cateListYes', { type: 3, root_type: this.root_type })
- let consultCate = []
- if (Number(res.status) === 1) {
- consultCate = res.data || []
- consultCate = consultCate.map(item => {
- let children = item.child_list.map(child => {
- return {
- value: child.f_name,
- label: child.name
- }
- })
- return {
- value: item.f_name,
- label: item.name,
- children: children
- }
- })
- // web 端,为所有二级分类添加 “全部”
- if (!this.mobile) {
- consultCate.forEach(item => {
- if (item.children) {
- let allItem = { value: item.value, label: '全部' }
- item.children.splice(0, 0, allItem)
- }
- })
- }
- }
- return consultCate
- }
- /** 获取技能服务列表 */
- async _getConsultList () {
- // 接口参数释义:https://www.yesdev.cn/apidocs-detail-20.html
- // const data = {
- // type: 2,
- // page: this.pagination.page,
- // page_size: this.pagination.pagesize,
- // cate_id: this.pagination.selectedCateIdTwo,
- // status: 2,
- // owner_type: 1
- // }
- const data = {
- page: this.pagination.page,
- page_size: this.pagination.pagesize,
- sale_zx_open: 1,
- cate_id_two_zx: this.pagination.selectedCateIdTwo || '',
- root_type: this.root_type
- }
- // 接口地址测试
- let res = await this.$axios.$post('/api/sale/consultList', data)
- let consultList = []
- if (Number(res.status) === 1) {
- consultList = res.data.list || []
- console.log(res.data.list)
- consultList = consultList.map(item => {
- let zxRating = item.zx_rating || ''
- let zxRatingText = ''
- if (zxRating >= 0.8) {
- zxRatingText = '高'
- } else if (zxRating >= 0.6) {
- zxRatingText = '较高'
- } else if (zxRating >= 0.4) {
- zxRatingText = '中'
- } else if (zxRating >= 0.2) {
- zxRatingText = '较低'
- } else {
- zxRatingText = '低'
- }
- // 最多展示3个头像
- let zxViewInfo = item.zx_view_info || []
- if (zxViewInfo.length > 4) {
- zxViewInfo = zxViewInfo.slice(0, 4)
- }
- let zxLastOrder = item.zx_last_order || {}
- if (zxLastOrder.buy_uid) {
- let nicknameFirst = zxLastOrder.nickname.substring(0, 1)
- let nicknameLast = zxLastOrder.nickname.substring(zxLastOrder.nickname.length - 1, zxLastOrder.nickname.length)
- zxLastOrder.nickname = `${nicknameFirst}****${nicknameLast}`
- }
- return {
- uid: item.uid || '',
- nickname: item.nickname || '',
- avatar: item.icon_url || '',
- lineStatus: item.lineStatus || '',
- company: item.company || '',
- title: item.title || '',
- saleList: item.sale_list || [],
- zxTotalNum: item.zx_total_num || 0,
- zxRating: item.zx_rating || '',
- zxPriceMin: item.zx_price_min || '0.00',
- zxRatingText: zxRatingText,
- zxViewNum: item.zx_view_num || 0,
- zxViewInfo: zxViewInfo,
- zxLastOrder: zxLastOrder,
- freework_level: item.freework_level || '',
- zx_sale_img: item.zx_sale_img || ''
- }
- })
- // consultList.forEach((item) => {
- // let imageList = item.image.split(',')
- // item.coverImage = imageList[0] || ''
- // imageList.splice(0, 1)
- // item.imageList = imageList
- // })
- this.pagination.total = res.data.total
- this.pagination.pageCount = res.data.pages
- // this.pagination.pagesize = res.data.page_size || 9
- // 当前页码 大于等于 页面总数:已加载所有数据
- if (this.pagination.page >= this.pagination.pageCount) {
- this.pagination.noMore = true
- } else {
- this.pagination.noMore = false
- }
- }
- return consultList
- }
- /** 获取最近成交数据 */
- async _getNewestTradeList () {
- let res = await this.$axios.$post('/api/sale/scrollList')
- let newestTradeList = []
- if (Number(res.status) === 1) {
- newestTradeList = res.data
- newestTradeList.forEach(item => {
- let nicknameFirst = item.nickname.substring(0, 1)
- let nicknameLast = item.nickname.substring(item.nickname.length - 1, item.nickname.length)
- item.nickname = `${nicknameFirst}****${nicknameLast}`
- })
- }
- return newestTradeList
- }
- dealThisMeta() {
- let head = {
- title: "",
- keyword: "",
- description: "",
- h1: "",
- canonical: "",
- metaLocation: ""
- }
- if (this.req) {
- const { headers: { host }, url } = this.req
- //拼接canonical
- if (host.indexOf('local') !== -1) {
- head.canonical = 'http://' + host + url
- } else {
- head.canonical = 'https://' + host + url
- }
- }
- if (this.cateNameTwo) {
- // 分类页
- head.title = `${this.cateNameTwo}技术咨询-${this.cateNameTwo}大牛-程序员客栈技术咨询`;
- head.keyword = `${this.cateNameTwo}技术咨询,${this.cateNameTwo}学习,${this.cateNameTwo}大牛,${this.cateNameTwo}高级开发工程师`;
- head.description = `程序员客栈技术培训提供海量${this.cateNameTwo}专家、${this.cateNameTwo}高级高级开发工程师为你提供一对一技术咨询服务,答疑解惑,出谋划策,定制服务,更多互联网专家请访问程序员客栈APP或官网技术咨询栏目`;
- } else {
- // 列表页,无筛选参数
- head.title = "领先的互联网知识技术咨询平台-【程序员客栈技术咨询】";
- head.keyword = "程序员大牛,架构师,高级开发工程师,开发技术咨询,开发经验,解决问题,一对一,面对面";
- head.description = "程序员客栈技术咨询是国内领先的互联网知识技术咨询平台。当你遇到任何互联网项目开发的问题或是个性化的服务需求,都可以直接找到行业专家,为你答疑解惑,出谋划策,定制服务,更多互联网专家请访问程序员客栈APP或官网技术咨询栏目";
- }
- return head
- }
- }
|