developData.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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.from = ''
  9. this.isExist = true
  10. this.pagesize = 10
  11. }
  12. async dealData() {
  13. let {
  14. name,
  15. path,
  16. params,
  17. fullPath,
  18. query
  19. } = this.app.context.route
  20. // 重定向
  21. // if (path.indexOf('/frontend/consult/user') > -1) {
  22. // this.redirect(301, '/c/' + uid)
  23. // }
  24. let [
  25. userInfo,
  26. balanceInfo,
  27. workPlatInfo,
  28. typeList,
  29. hotInfo
  30. ] = await Promise.all([
  31. this._getUserInfo(),
  32. this._getUserBalance(),
  33. this._getWorkPlatInfo(),
  34. this._getTypeList(),
  35. this._getHotData()
  36. ])
  37. let firstType = typeList[0]
  38. let dynamicList = await this._getDynamicDetail(firstType.typeId)
  39. let isMore = dynamicList.length < this.pagesize ? false : true
  40. return {
  41. isExist: this.isExist,
  42. mobile: this.app.$deviceType.isMobile(),
  43. // head: this.dealThisMeta(),
  44. userInfo,
  45. balanceInfo,
  46. workPlatInfo,
  47. typeList,
  48. hotInfo,
  49. dynamicList,
  50. firstType,
  51. isMore
  52. }
  53. }
  54. // 获取用户信息
  55. async _getUserInfo() {
  56. let res = await this.$axios.$post('/uapi/user/info')
  57. // let res = await this.$axios.$post('/api/user/getInfo')
  58. let userInfo = {}
  59. if (Number(res.status) === 1) {
  60. let { info, login } = res.data
  61. // let info = {...res.data}
  62. // let login = {...res.data}
  63. userInfo['realname_re'] = info.realname_re;
  64. userInfo['realname_verify_status'] = info.realname_verify_status;
  65. userInfo['dynamic_rand'] = info.dynamic_rand
  66. userInfo['is_open_mall'] = info.is_open_mall
  67. userInfo['is_open_kill'] = info.is_open_kill
  68. userInfo['is_open_consult'] = info.is_open_consult
  69. userInfo['is_open_kc'] = info.is_open_kc
  70. userInfo['nickname'] = login.nickname
  71. userInfo['icon_url'] = login.icon_url
  72. userInfo['freework_level'] = login.freework_level
  73. } else if (Number(res.status) === 40001) {
  74. this.isExist = false
  75. }
  76. return userInfo
  77. }
  78. // 获取账户余额
  79. async _getUserBalance() {
  80. let res = await this.$axios.$post('/api/account/getBalance')
  81. let balanceInfo = {}
  82. if (Number(res.status) === 1) {
  83. let info = res.data
  84. //账户余额
  85. balanceInfo['totalBalance'] = info['totalBalance']
  86. //总收入
  87. balanceInfo['historyTotalBalance'] = info['historyTotalBalance']
  88. //冻结余额
  89. balanceInfo['frozenBalance'] = info['frozenBalance']
  90. //薪资余额
  91. balanceInfo['gongMallBalance'] = info['gongMallBalance']
  92. } else if (Number(res.status) === 40001) {
  93. this.isExist = false
  94. }
  95. return balanceInfo
  96. }
  97. // 获取工作台统计数据
  98. async _getWorkPlatInfo() {
  99. let res = await this.$axios.$post('/api/user/getWorkPlatformCount')
  100. let workPlatInfo = {}
  101. if (Number(res.status) === 1) {
  102. let info = res.data
  103. // 待办
  104. workPlatInfo['pendingNumber'] = info['pendingNumber']
  105. // 工作
  106. workPlatInfo['developerWorkNumber'] = info['developerWorkNumber']
  107. // 整包
  108. workPlatInfo['developerProjectNumber'] = info['developerProjectNumber']
  109. // 沟通
  110. workPlatInfo['recruitDeveloperCount'] = info['recruitDeveloperCount']
  111. } else if (Number(res.status) === 40001) {
  112. this.isExist = false
  113. }
  114. return workPlatInfo
  115. }
  116. // 动态列表
  117. async _getDynamicDetail(type_id) {
  118. let res = await this.$axios.$post('/uapi/dynamic/get_dynamic_detail', {
  119. type_id,
  120. page: 1,
  121. pagesize: this.pagesize
  122. })
  123. let dynamicList = []
  124. if (Number(res.status) === 1) {
  125. let info = res.data.list
  126. info = info.map((item) => {
  127. let imgList = item.img
  128. imgList = imgList.map(item => {
  129. return item.img
  130. })
  131. return {
  132. ...item,
  133. imgList
  134. }
  135. })
  136. dynamicList = [...info]
  137. } else if (Number(res.status) === 40001) {
  138. this.isExist = false
  139. }
  140. return dynamicList
  141. }
  142. // 圈子分类
  143. async _getTypeList() {
  144. let res = await this.$axios.$post('/uapi/dynamic/get_type_list')
  145. let typeList = []
  146. if (Number(res.status) === 1) {
  147. let info = res.data
  148. typeList = [...info]
  149. } else if (Number(res.status) === 40001) {
  150. this.isExist = false
  151. }
  152. return typeList
  153. }
  154. // 热门资源
  155. async _getHotData(){
  156. let res = await this.$axios.$get('/sapi/index/index')
  157. let hotInfo = {
  158. 'works':[],
  159. 'learn':[]
  160. }
  161. if (Number(res.status) === 1) {
  162. let {works,learn} = res.data
  163. hotInfo['works'] = works.splice(0,5)
  164. hotInfo['learn'] = learn.splice(0,5)
  165. } else if (Number(res.status) === 40001) {
  166. this.isExist = false
  167. }
  168. return hotInfo
  169. }
  170. dealThisMeta() {
  171. let title = ''
  172. let descriptionTitle = ''
  173. let description = ''
  174. let canonical = ''
  175. if (!this.isExist) {
  176. // 页面不存在时
  177. return {
  178. title: "页面不存在-程序员客栈",
  179. keyword: "",
  180. description: "",
  181. h1: "",
  182. canonical: "",
  183. metaLocation: ""
  184. }
  185. }
  186. const nickname = this.consultDetail.user.nickname
  187. this.consultDetail.sale_list.forEach((item, index) => {
  188. if (index === 0) {
  189. title = item.title.trim()
  190. description = item.content.trim()
  191. }
  192. // if (index !== this.consultDetail.sale_list.length - 1) {
  193. // description += `${item.title}、`
  194. // } else {
  195. // description += item.title
  196. // }
  197. })
  198. if (description.length > 15) {
  199. description = description.substring(0, 15)
  200. }
  201. if (title.length > 15) {
  202. descriptionTitle = title.substring(0, 15)
  203. } else {
  204. descriptionTitle = title
  205. }
  206. if (this.req) {
  207. const { headers: { host }, url } = this.req
  208. //拼接canonical
  209. if (host.indexOf('local') !== -1) {
  210. canonical = 'http://' + host + url
  211. } else {
  212. canonical = 'https://' + host + url
  213. }
  214. }
  215. let head = {
  216. title: `${title}-程序员客栈咨询服务`,
  217. keyword: `${this.consultDetail.user.company},${this.consultDetail.user.direction_name},${title}`,
  218. description: `${nickname}可以为您提供:${descriptionTitle},程序员客栈邀请到国内外互联网名企资深工作者,为您提供1对1技术咨询服务。`,
  219. h1: "",
  220. canonical: canonical,
  221. metaLocation: ""
  222. }
  223. return head
  224. }
  225. }