dealSeoIndex.js 10 KB

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