dealSeoIndex.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. export default class DealSeoData {
  2. constructor({ $axios, req, app, redirect, error}) {
  3. this.$axios = $axios
  4. this.req = req
  5. this.app = app
  6. this.redirect = redirect
  7. this.error = error
  8. this.selected = {
  9. city: 0,
  10. industry: 0,
  11. techType: 0,
  12. }
  13. this.page = {
  14. page: 1,
  15. size: 10,
  16. total: 0,
  17. keyword: ''
  18. }
  19. this.finished = false
  20. this.dataList = []
  21. this.provinces = []
  22. }
  23. async dealData() {
  24. let { name, query: { page = 1, keyword='' }, path, params, fullPath } = this.app.context.route
  25. this.page.page = page
  26. this.page.keyword = keyword
  27. if (path && path[path.length-1] !== '/') {
  28. let reditUrl = fullPath
  29. reditUrl = reditUrl.replace(path, path+'/')
  30. this.redirect(301, reditUrl)
  31. }
  32. let isSeoList = false
  33. let typeList = await this.getTypeList()
  34. switch (name) {
  35. case "kaifainSeoAll":
  36. //kaifain/s页面进入
  37. isSeoList = true
  38. break
  39. case "kaifainSeoIndex":
  40. //kaifain路由匹配进入
  41. try {
  42. let match = params.pathMatch || ''
  43. let list = match.split('/').map(item => item.toLocaleLowerCase())
  44. list.length = Math.min(list.length, 3) //防止url超出
  45. list.filter(item => !!item)
  46. let urlCheck = ""
  47. let keys = Object.keys(typeList)
  48. //3 * 3 * n的循环 n < 100
  49. list.forEach(item=>{
  50. keys.forEach(keys => {
  51. typeList[keys].list.forEach(typeItem => {
  52. if (typeItem.slug === item) {
  53. urlCheck += item
  54. this.selected[keys] = typeItem.id
  55. this.selected[keys+'Name'] = typeItem.name
  56. this.selected[keys+'Slug'] = typeItem.slug
  57. if (keys === 'city') {
  58. this.selected["provice"] = typeItem.prov_id
  59. }
  60. }
  61. })
  62. })
  63. })
  64. if (urlCheck !== list.join("")) {
  65. this.error({statusCode: 404, message: "您要访问的页面不存在"})
  66. return
  67. }
  68. if (this.selected["provice"]) {
  69. let item = this.provinces.filter(item=>item.id===this.selected["provice"])[0]
  70. this.selected["proviceName"] = item && item.name
  71. }
  72. } catch (e) {
  73. console.log("解决方案列表", e)
  74. }
  75. break
  76. default:
  77. //其他
  78. page = 1
  79. }
  80. await this.getList()
  81. return {
  82. typeList,
  83. isSeoList, //是否是 /kaifain/s/页面进入
  84. dataList:this.dataList, //首次获取的数据
  85. mobile: this.app.$deviceType.isMobile(),
  86. selected: this.selected,
  87. page: this.page,
  88. finished: this.finished,
  89. head: this.dealThisMeta(isSeoList),
  90. }
  91. }
  92. async getTypeList() {
  93. let res = await this.$axios.get('/api/kaifawu/get_options')
  94. let typeList = {
  95. city: {
  96. title: '地区',
  97. list: []
  98. },
  99. industry: {
  100. title: '行业领域',
  101. list: []
  102. },
  103. techType: {
  104. title: '技术分类',
  105. list: []
  106. }
  107. }
  108. if (Number(res.data.status) === 1) {
  109. res.data.data.cities.unshift({ id: 0, name: "全部地区" })
  110. res.data.data.industries.unshift({ id: 0, name: "全部行业" })
  111. res.data.data.tech_types.unshift({ id: 0, name: "全部分类" })
  112. Object.keys(res.data.data).forEach(key => {
  113. let item = res.data.data[ key ]
  114. if (Array.isArray(item)) {
  115. item.forEach(ii => {
  116. ii.text = ii.name
  117. ii.value = ii.id
  118. })
  119. }
  120. })
  121. typeList.city.list = [ ...res.data.data.cities ]
  122. typeList.industry.list = [ ...res.data.data.industries ]
  123. typeList.techType.list = [ ...res.data.data.tech_types ]
  124. this.provinces = [] = [ ...res.data.data.provinces ]
  125. }
  126. return typeList
  127. }
  128. async getList() {
  129. const { page, selected } = this
  130. let p = {
  131. city: selected.city,
  132. tech_type: selected.techType,
  133. industry: selected.industry,
  134. ...page
  135. }
  136. // console.log("*****", p)
  137. let res = await this.$axios.post('/api/kaifawu/index', p)
  138. if (Number(res.data.status) === 1) {
  139. let data = res.data.data
  140. this.page.total = data.total
  141. let dataList = data.providers || []
  142. dataList.forEach(item => {
  143. item[ 'successCase' ] = ''
  144. if (Array.isArray(item.successful_case)) {
  145. let tem = item.successful_case.map(item => item.title)
  146. item[ 'successCase' ] = tem.join('、')
  147. }
  148. })
  149. if (this.page.page === 1) {
  150. this.dataList = [...data.providers]
  151. } else {
  152. this.dataList = [ ...this.dataList, ...data.providers ]
  153. }
  154. this.page.page += 1
  155. if (this.page.total <= this.dataList.length) {
  156. this.finished = true
  157. }
  158. }
  159. }
  160. dealThisMeta(isSeoList) {
  161. let { city, industry, techType, cityName="", industryName="", techTypeName="", proviceName} = this.selected
  162. const {headers: {host}, url} = this.req
  163. let head = {
  164. title:"", keyword: "", descrption: "", h1: "", canonical: "", metaLocation: ""
  165. }
  166. //拼接canonical
  167. if (host.indexOf('local') !== -1) {
  168. head.canonical = 'http://' + host + url
  169. } else {
  170. head.canonical = 'https://' + host + url
  171. }
  172. if (techTypeName) {
  173. techTypeName = techTypeName.replace("定制化", "")
  174. }
  175. if (city && !industry && !techType) {
  176. //只有城市的
  177. head.title = `${cityName}软件、网站、APP、小程序开发及SaaS、PaaS、IaaS、API服务平台-开发屋`
  178. head.keyword = `${cityName}软件开发,${cityName}APP开发,${cityName}小程序开发,${cityName}SaaS服务商`
  179. head.descrption = `开发屋为${cityName}中小型企业企业提供各行业软件、APP、小程序开发服务,并整合开发项目所需的各种SaaS、PaaS,LaaS以及API服务商供选择,全程解决开发需求!`
  180. head.h1 = `${cityName}软件开发`
  181. head.metaLocation = `province=${proviceName};city=${cityName}`
  182. } else if (!city && industry && !techType) {
  183. //只有行业的
  184. head.title = `${industryName}软件、网站、APP、小程序开发及SaaS、PaaS、IaaS、API服务平台-开发屋`
  185. head.keyword = `${industryName}软件开发,${industryName}APP开发,${industryName}小程序开发,${industryName}SaaS服务商`
  186. head.descrption = `开发屋为${industryName}中小型企业企业提供各行业软件、APP、小程序开发服务,并整合开发项目所需的各种SaaS、PaaS,LaaS以及API服务商供选择,全程解决开发需求!`
  187. head.h1 = `${industryName}软件开发`
  188. } else if (!city && !industry && techType) {
  189. //只有技术分类
  190. head.title = `定制化${techTypeName}系统服务商、${techTypeName} 解决方案平台-开发屋`
  191. head.keyword = `${techTypeName},${techTypeName}服务商,${techTypeName}解决方案`
  192. head.descrption = `开发屋提供${techTypeName}定制化服务,方便有${techTypeName}需求的开发商挑选较为合适的${techTypeName}解决方案完成项目开发和应用!`
  193. head.h1 = `${techTypeName}解决方案服务商`
  194. } else if (city && industry && !techType) {
  195. //${cityName}${industryName}
  196. head.title = `${cityName}${industryName}软件、网站、APP、小程序开发及SaaS、PaaS、IaaS、API服务平台-开发屋`
  197. head.keyword = `${cityName}${industryName}软件开发,${cityName}${industryName}APP开发,${cityName}${industryName}小程序开发,${cityName}${industryName}SaaS服务商`
  198. head.descrption = `开发屋为${cityName}${industryName}中小型企业企业提供各行业软件、APP、小程序开发服务,并整合开发项目所需的各种SaaS、PaaS,、IaaS以及API服务商供选择,全程解决开发需求!`
  199. head.h1 = `${cityName}${industryName}软件开发`
  200. head.metaLocation = `province=${proviceName};city=${cityName}`
  201. } else if (city && !industry && techType) {
  202. //${cityName}${techTypeName}
  203. head.title = `${cityName}定制化${techTypeName.replace("", "")}系统开发、${cityName}${techTypeName}解决方案-开发屋`
  204. head.keyword = `${cityName}${techTypeName},${cityName}${techTypeName}服务商,${cityName}${techTypeName}解决方案`
  205. head.descrption = `开发屋提供${cityName}${techTypeName}定制化服务,方便有${cityName}${techTypeName}需求的开发商挑选较为合适的${cityName}${techTypeName}解决方案完成项目开发和应用!`
  206. head.h1 = `${cityName}${techTypeName}解决方案服务商`
  207. head.metaLocation = `province=${proviceName};city=${cityName}`
  208. } else if (!city && industry && techType) {
  209. //${industryName}${techTypeName}
  210. head.title = `${industryName}定制化${techTypeName}系统服务商、${industryName}${techTypeName}解决方案-开发屋`
  211. head.keyword = `${industryName}${techTypeName},${industryName}${techTypeName}服务商,${industryName}${techTypeName}解决方案`
  212. head.descrption = `开发屋提供${industryName}${techTypeName}定制化服务,方便有${industryName}${techTypeName}需求的开发商挑选较为合适的${industryName}${techTypeName}解决方案完成项目开发和应用!`
  213. head.h1 = `${industryName}${techTypeName}解决方案服务商`
  214. } else if (city && industry && techType) {
  215. // 开发屋城市&行业领域&技术分类页
  216. head.title = `${cityName}${industryName}定制化${techTypeName}系统服务商、${cityName}${industryName}${techTypeName}解决方案平台-开发屋`
  217. head.keyword = `${cityName}${industryName}${techTypeName},${cityName}${industryName}${techTypeName}服务商,${cityName}${industryName}${techTypeName}解决方案`
  218. head.descrption = `开发屋提供${cityName}${industryName}${techTypeName}定制化服务,方便有${cityName}${industryName}${techTypeName}需求的开发商挑选较为合适的${cityName}${industryName}${techTypeName}解决方案完成项目开发和应用!`
  219. head.h1 = `${cityName}${industryName}${techTypeName}解决方案服务商`
  220. head.metaLocation = `province=${proviceName};city=${cityName}`
  221. } else {
  222. //非特定的url
  223. if (isSeoList) {
  224. head.title = "解决方案大全"
  225. } else {
  226. head.title = "开发屋-提供网站建设、APP软件、小程序开发及SaaS、PasS、IaaS服务"
  227. head.keyword = "网站开发,软件APP开发,SaaS,PaaS"
  228. head.descrption = "开发屋为企业提供行业内领先的技术解决方案,包括行业定制化SaaS、PasS、API数据接口服务以及技术组织,保障企业在降低人力开发成本的同时,得到优质的项目开发实力。"
  229. }
  230. }
  231. return head
  232. }
  233. }