personalData.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. export default class PersonalData {
  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. let [
  21. personalUserInfo,
  22. dynamicData,
  23. articleCount,
  24. courseCount,
  25. adList,
  26. isFollowing
  27. ] = await Promise.all([
  28. this._getPersonalUserInfo(),
  29. this._getDynamicCount(),
  30. this._getArticleCount(),
  31. this._getCourseCount(),
  32. this._getAdvert(),
  33. this._getFollowStatus()
  34. ])
  35. return {
  36. isExist: this.isExist,
  37. mobile: this.app.$deviceType.isMobile(),
  38. // head: this.dealThisMeta(),
  39. personalUserInfo,
  40. dynamicCount:dynamicData.dynamicCount,
  41. list:dynamicData.dynamicList,
  42. page:1,
  43. articleCount,
  44. courseCount,
  45. adList,
  46. isFollowing
  47. }
  48. }
  49. // 获取开发者个人信息
  50. async _getPersonalUserInfo() {
  51. let {
  52. name,
  53. path,
  54. params,
  55. fullPath,
  56. query
  57. } = this.app.context.route
  58. let res = await this.$axios.post('/uapi/user/info/action/other', {
  59. uid: params.uid
  60. })
  61. let personalUserInfo = {}
  62. if (Number(res.data.status) === 1) {
  63. personalUserInfo = {
  64. ...res.data.data
  65. }
  66. } else if (Number(res.status) === 40001) {
  67. this.isExist = false
  68. }
  69. return personalUserInfo
  70. }
  71. async _getDynamicCount(){
  72. let {
  73. name,
  74. path,
  75. params,
  76. fullPath,
  77. query
  78. } = this.app.context.route
  79. let uid = params.uid
  80. let res = await this.$axios.post('/uapi/dynamic/get_dynamic_list_my', {
  81. to_uid: params.uid,
  82. page:1,
  83. pagesize:10
  84. })
  85. let count = 0
  86. let dynamicList = []
  87. if (Number(res.data.status) === 1) {
  88. count = res.data.data.user.dynamic_num
  89. dynamicList = res.data.data.list
  90. } else if (Number(res.status) === 40001) {
  91. this.isExist = false
  92. }
  93. return {
  94. dynamicList,
  95. dynamicCount:count
  96. }
  97. }
  98. async _getArticleCount(){
  99. let {
  100. name,
  101. path,
  102. params,
  103. fullPath,
  104. query
  105. } = this.app.context.route
  106. let uid = params.uid
  107. let res = await this.$axios.post('/uapi/news/index/list', {
  108. uid: params.uid,
  109. page:1,
  110. pagesize:1
  111. })
  112. let count = 0
  113. if (Number(res.data.status) === 1) {
  114. count = res.data.data.total
  115. } else if (Number(res.status) === 40001) {
  116. this.isExist = false
  117. }
  118. return count
  119. }
  120. async _getCourseCount(){
  121. let {
  122. name,
  123. path,
  124. params,
  125. fullPath,
  126. query
  127. } = this.app.context.route
  128. let uid = params.uid
  129. let res = await this.$axios.post('/uapi/goods/video/list', {
  130. to_uid: params.uid,
  131. page:1,
  132. pagesize:1
  133. })
  134. let count = 0
  135. if (Number(res.data.status) === 1) {
  136. count = res.data.data.total
  137. } else if (Number(res.status) === 40001) {
  138. this.isExist = false
  139. }
  140. return count
  141. }
  142. // 获取广告位
  143. async _getAdvert() {
  144. let res = await this.$axios.post('/uapi/pub/adInfo', {
  145. position: 'personal'
  146. })
  147. let adList = []
  148. if (Number(res.data.status) === 1) {
  149. adList = {
  150. ...res.data.data.list
  151. }
  152. } else if (Number(res.status) === 40001) {
  153. this.isExist = false
  154. }
  155. return adList
  156. }
  157. // 获取当前关注状态
  158. async _getFollowStatus() {
  159. let {
  160. name,
  161. path,
  162. params,
  163. fullPath,
  164. query
  165. } = this.app.context.route
  166. let uid = params.uid
  167. let res = await this.$axios.post('/uapi/dynamic/check_followers', {
  168. to_uid: uid
  169. })
  170. let isFollowing = false
  171. if (Number(res.data.status) === 1) {
  172. if(res.data.data.result == 1){
  173. isFollowing = true
  174. }
  175. } else if (Number(res.status) === 40001) {
  176. this.isExist = false
  177. }
  178. return isFollowing
  179. }
  180. dealThisMeta() {
  181. let title = ''
  182. let descriptionTitle = ''
  183. let description = ''
  184. let canonical = ''
  185. if (!this.isExist) {
  186. // 页面不存在时
  187. return {
  188. title: "页面不存在-程序员客栈",
  189. keyword: "",
  190. description: "",
  191. h1: "",
  192. canonical: "",
  193. metaLocation: ""
  194. }
  195. }
  196. const nickname = this.consultDetail.user.nickname
  197. this.consultDetail.sale_list.forEach((item, index) => {
  198. if (index === 0) {
  199. title = item.title.trim()
  200. description = item.content.trim()
  201. }
  202. // if (index !== this.consultDetail.sale_list.length - 1) {
  203. // description += `${item.title}、`
  204. // } else {
  205. // description += item.title
  206. // }
  207. })
  208. if (description.length > 15) {
  209. description = description.substring(0, 15)
  210. }
  211. if (title.length > 15) {
  212. descriptionTitle = title.substring(0, 15)
  213. } else {
  214. descriptionTitle = title
  215. }
  216. if (this.req) {
  217. const { headers: { host }, url } = this.req
  218. //拼接canonical
  219. if (host.indexOf('local') !== -1) {
  220. canonical = 'http://' + host + url
  221. } else {
  222. canonical = 'https://' + host + url
  223. }
  224. }
  225. let head = {
  226. title: `${title}-程序员客栈咨询服务`,
  227. keyword: `${this.consultDetail.user.company},${this.consultDetail.user.direction_name},${title}`,
  228. description: `${nickname}可以为您提供:${descriptionTitle},程序员客栈邀请到国内外互联网名企资深工作者,为您提供1对1技术咨询服务。`,
  229. h1: "",
  230. canonical: canonical,
  231. metaLocation: ""
  232. }
  233. return head
  234. }
  235. }