dealSeoIndex.js 11 KB

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