personalData.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. articleCount,
  42. courseCount,
  43. list:dynamicData.dynamicList,
  44. adList,
  45. isFollowing
  46. }
  47. }
  48. // 获取开发者个人信息
  49. async _getPersonalUserInfo() {
  50. let {
  51. name,
  52. path,
  53. params,
  54. fullPath,
  55. query
  56. } = this.app.context.route
  57. let res = await this.$axios.post('/uapi/user/info/action/other', {
  58. uid: params.uid
  59. })
  60. let personalUserInfo = {}
  61. if (Number(res.data.status) === 1) {
  62. personalUserInfo = {
  63. ...res.data.data
  64. }
  65. } else if (Number(res.status) === 40001) {
  66. this.isExist = false
  67. }
  68. return personalUserInfo
  69. }
  70. async _getDynamicCount(){
  71. let {
  72. name,
  73. path,
  74. params,
  75. fullPath,
  76. query
  77. } = this.app.context.route
  78. let uid = params.uid
  79. let res = await this.$axios.post('/uapi/dynamic/get_dynamic_list_my', {
  80. to_uid: params.uid,
  81. page:1,
  82. pagesize:10
  83. })
  84. let count = 0
  85. let dynamicList = []
  86. if (Number(res.data.status) === 1) {
  87. count = res.data.data.user.dynamic_num
  88. dynamicList = res.data.data.list
  89. } else if (Number(res.status) === 40001) {
  90. this.isExist = false
  91. }
  92. return {
  93. dynamicList,
  94. dynamicCount:count
  95. }
  96. }
  97. async _getArticleCount(){
  98. let {
  99. name,
  100. path,
  101. params,
  102. fullPath,
  103. query
  104. } = this.app.context.route
  105. let uid = params.uid
  106. let res = await this.$axios.post('/uapi/news/index/list', {
  107. uid: params.uid,
  108. page:1,
  109. pagesize:1
  110. })
  111. let count = 0
  112. if (Number(res.data.status) === 1) {
  113. count = res.data.data.total
  114. } else if (Number(res.status) === 40001) {
  115. this.isExist = false
  116. }
  117. return count
  118. }
  119. async _getCourseCount(){
  120. let {
  121. name,
  122. path,
  123. params,
  124. fullPath,
  125. query
  126. } = this.app.context.route
  127. let uid = params.uid
  128. let res = await this.$axios.post('/uapi/goods/video/list', {
  129. to_uid: params.uid,
  130. page:1,
  131. pagesize:1
  132. })
  133. let count = 0
  134. if (Number(res.data.status) === 1) {
  135. count = res.data.data.total
  136. } else if (Number(res.status) === 40001) {
  137. this.isExist = false
  138. }
  139. return count
  140. }
  141. // 获取广告位
  142. async _getAdvert() {
  143. let res = await this.$axios.post('/uapi/pub/adInfo', {
  144. position: 'personal'
  145. })
  146. let adList = []
  147. if (Number(res.data.status) === 1) {
  148. adList = {
  149. ...res.data.data.list
  150. }
  151. } else if (Number(res.status) === 40001) {
  152. this.isExist = false
  153. }
  154. return adList
  155. }
  156. // 获取当前关注状态
  157. async _getFollowStatus() {
  158. let {
  159. name,
  160. path,
  161. params,
  162. fullPath,
  163. query
  164. } = this.app.context.route
  165. let uid = params.uid
  166. let res = await this.$axios.post('/uapi/dynamic/check_followers', {
  167. to_uid: uid
  168. })
  169. let isFollowing = false
  170. if (Number(res.data.status) === 1) {
  171. if(res.data.data.result == 1){
  172. isFollowing = true
  173. }
  174. } else if (Number(res.status) === 40001) {
  175. this.isExist = false
  176. }
  177. return isFollowing
  178. }
  179. }