developData.js 8.5 KB

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