search.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. <script setup>
  2. import MomentLayout from "~/components/MomentLayout/index.vue";
  3. import ChooseSubjectToTalk from "~/components/ChooseSubjectToTalk/index.vue";
  4. import Login from "~/components/Login/Login.vue";
  5. import { ref, onMounted, reactive, onActivated, watch } from "vue";
  6. import * as userApi from "~/api/user";
  7. import * as summary from "~/api/gather";
  8. import { useRouter, useRoute } from "vue-router";
  9. import { useUser } from "~/store/user";
  10. import IndexTitle from "~/components/IndexTitle/index.vue";
  11. import IndexNews from "~/components/IndexNews/index.vue";
  12. import IndexSection from "~/components/IndexSection/index.vue";
  13. import * as summaryApi from "~/api/gather";
  14. import * as newsApi from "~/api/news";
  15. import * as articleApi from "~/api/article";
  16. import * as videoApi from "~/api/video";
  17. import * as topicApi from "~/api/forum";
  18. const User = useUser()
  19. const router = useRouter();
  20. const route = useRoute();
  21. const keyword = ref();
  22. if (route.query) {
  23. keyword.value = route.query.keyword;
  24. }
  25. // 获取咨询列表
  26. let newsList = ref([]);
  27. const __news__ = async () => {
  28. try {
  29. const { data } = await newsApi.list({
  30. is_page: 0,
  31. status: "normal",
  32. title: keyword.value,
  33. });
  34. newsList.value = data;
  35. } catch (error) {}
  36. };
  37. onMounted(__news__);
  38. //获取文章列表
  39. let articleList = ref([]);
  40. const __articles__ = async () => {
  41. try {
  42. const { data } = await articleApi.list({
  43. is_page: 0,
  44. status: "normal",
  45. title: keyword.value,
  46. });
  47. articleList.value = data;
  48. } catch (error) {}
  49. };
  50. onMounted(__articles__);
  51. //获取视频列表
  52. let videoList = ref([]);
  53. const __videos__ = async () => {
  54. try {
  55. const { data } = await videoApi.list({
  56. is_page: 0,
  57. status: "normal",
  58. title: keyword.value,
  59. });
  60. videoList.value = data;
  61. } catch (error) {}
  62. };
  63. onMounted(__videos__);
  64. //帖子列表
  65. let postList = ref([]);
  66. const __post__ = async () => {
  67. try {
  68. const { data } = await topicApi.list({
  69. is_page: 0,
  70. status: "normal",
  71. content: keyword.value,
  72. });
  73. postList.value = data;
  74. } catch (error) {}
  75. };
  76. onMounted(__post__);
  77. //用户列表
  78. let userList = ref([]);
  79. const __user__ = async () => {
  80. try {
  81. const { data } = await summaryApi.summary({
  82. is_page: 0,
  83. source_type: "user",
  84. type: "single",
  85. // is_boutique: 0,
  86. title: keyword.value,
  87. });
  88. userList.value = data;
  89. } catch (error) {}
  90. };
  91. onMounted(__user__);
  92. //跳转到详情
  93. const todetails = (id) => {
  94. router.push({
  95. name: "news",
  96. query: {
  97. id: id,
  98. },
  99. });
  100. };
  101. //跳转到帖子详情
  102. const details = (id) => {
  103. router.push({
  104. name: "post",
  105. query: {
  106. id: id,
  107. },
  108. });
  109. };
  110. //跳转文章详情
  111. const todetail = (id) => {
  112. router.push({
  113. name: "articles",
  114. query: {
  115. id: id,
  116. },
  117. });
  118. };
  119. //跳转视频详情
  120. const detail = (id, type) => {
  121. router.push({
  122. name: "videos",
  123. query: {
  124. id: id,
  125. type: type,
  126. },
  127. });
  128. };
  129. watch(
  130. () => route.query,
  131. (newVal) => {
  132. console.log(newVal);
  133. keyword.value = newVal.keyword;
  134. __news__();
  135. __user__();
  136. __post__();
  137. __articles__();
  138. __videos__();
  139. }
  140. );
  141. //关注
  142. const about = async (id) => {
  143. try {
  144. const { msg } = await userApi.userfollow({
  145. id: id,
  146. });
  147. ElMessage.success({
  148. message: msg,
  149. type: "success",
  150. });
  151. __user__();
  152. User.getUser()
  153. } catch (error) {}
  154. };
  155. const other = (id) => {
  156. router.push({
  157. path: "/rest",
  158. query: {
  159. id: id,
  160. },
  161. });
  162. };
  163. </script>
  164. <template>
  165. <div class="index-follow-container flex-row flex-jc-sb">
  166. <div class="context" style="margin-top: 40px">
  167. <!-- 资讯 -->
  168. <div
  169. v-if="
  170. newsList.length > 0 &&
  171. (route.query.type == 'first' || route.query.type == 'second')
  172. "
  173. >
  174. <div>资讯</div>
  175. <div
  176. class="content-list flex-row"
  177. style="margin-top: 14px; margin-bottom: 10px"
  178. >
  179. <template v-for="(item, idx) in newsList" :key="idx">
  180. <IndexNews
  181. @update="todetails(item.id)"
  182. :title="item.title"
  183. :time-ago="item.published_at"
  184. :like-count="item.like_count || '0'"
  185. :comment-count="item.comment_count || '0'"
  186. :image="item.image"
  187. :is_like="item.is_like"
  188. :is_collect="item.is_collect"
  189. />
  190. </template>
  191. </div>
  192. </div>
  193. <!-- 文章 -->
  194. <div
  195. v-if="
  196. articleList.length > 0 &&
  197. (route.query.type == 'first' || route.query.type == 'fourth')
  198. "
  199. >
  200. <!-- <div v-if="articleList.length > 0"> -->
  201. <div>文章</div>
  202. <div
  203. class="content-list content-list--c2 flex-row"
  204. style="margin-top: 14px"
  205. >
  206. <template v-for="(item, idx) in articleList" :key="idx">
  207. <IndexSection
  208. @article="__articles__()"
  209. @update="todetail(item.id)"
  210. @other="other(item.user_id)"
  211. :type="!item.image ? 'article' : 'common'"
  212. :title="item.title"
  213. :time-ago="item.published_at"
  214. :descs="item.description"
  215. :topic-name="item.topic?.title"
  216. :author="item.user?.username"
  217. :author-avatar="item.user?.avatar"
  218. :view_count="item.view_count || 0"
  219. :comment_count="item.comment_count || 0"
  220. :collect_count="item.collect_count || 0"
  221. :share_count="item.share_count || 0"
  222. :like_count="item.like_count"
  223. :image="item.image"
  224. :is_like="item.is_like"
  225. :is_collect="item.is_collect"
  226. :source_id="item.id"
  227. source_type="article"
  228. />
  229. </template>
  230. </div>
  231. </div>
  232. <!-- 视频 -->
  233. <div
  234. v-if="
  235. videoList.length > 0 &&
  236. (route.query.type == 'first' || route.query.type == 'third')
  237. "
  238. >
  239. <div>视频</div>
  240. <div
  241. class="content-list content-list--c2 flex-row"
  242. style="margin-top: 14px"
  243. >
  244. <template v-for="(item, idx) in videoList" :key="idx">
  245. <IndexSection
  246. @video="__videos__()"
  247. @update="detail(item.id, 'common')"
  248. @other="other(item.user_id)"
  249. :type="!item.image ? 'article' : 'common'"
  250. :title="item?.title"
  251. :time-ago="item.published_at"
  252. :descs="item.description"
  253. :topic-name="item.topic?.title"
  254. :author="item.user?.username"
  255. :author-avatar="item.user?.avatar"
  256. :view_count="item.view_count || 0"
  257. :comment_count="item.comment_count || 0"
  258. :collect_count="item.collect_count || 0"
  259. :share_count="item.share_count || 0"
  260. :image="item.image"
  261. :is_like="item.is_like"
  262. :is_collect="item.is_collect"
  263. :source_id="item.id"
  264. source_type="video"
  265. :like_count="item.like_count"
  266. />
  267. </template>
  268. </div>
  269. </div>
  270. <!-- 帖子 -->
  271. <div
  272. v-if="
  273. postList.length > 0 &&
  274. (route.query.type == 'first' || route.query.type == 'firse')
  275. "
  276. >
  277. <div>帖子</div>
  278. <div
  279. class="content-list flex-row"
  280. style="margin-top: 14px; margin-bottom: 10px"
  281. >
  282. <template v-for="(item, idx) in postList" :key="idx">
  283. <IndexNews
  284. @update="details(item.id)"
  285. :time-ago="item.published_at"
  286. :like-count="item.like_count || '0'"
  287. :comment-count="item.comment_count || '0'"
  288. :image="item.images?item.images[0]:''"
  289. :is_like="item.is_like"
  290. :title="item.content"
  291. :is_collect="item.is_collect"
  292. />
  293. <!-- aaaaaaaaaaaaa -->
  294. </template>
  295. </div>
  296. </div>
  297. <!-- 用户 -->
  298. <div
  299. v-if="
  300. userList.length > 0 &&
  301. (route.query.type == 'first' || route.query.type == 'six')
  302. "
  303. >
  304. <div>用户</div>
  305. <!-- <div>{{ postList }}</div> -->
  306. <div
  307. class="content-lista flex-row"
  308. style="margin-top: 14px; margin-bottom: 10px; column-gap: 65px"
  309. >
  310. <template v-for="(item, idx) in userList" :key="idx">
  311. <div class="usebox">
  312. <div>
  313. <img @click="other(item.id)" :src="item.avatar" style="width: 40px;height: 40px;border-radius: 50%;cursor: pointer;" alt="" />
  314. <span>{{ item.username }}</span>
  315. </div>
  316. <div
  317. :class="item.is_follow == 0 ? 'abt' : 'about'"
  318. @click="about(item.id)"
  319. >
  320. {{ item.is_follow == 0 ? "关注" : "已关注" }}
  321. </div>
  322. </div>
  323. </template>
  324. </div>
  325. </div>
  326. <!-- <div v-else style="height: 80vh; line-height: 80vh">
  327. <div>暂无数据</div>
  328. </div> -->
  329. </div>
  330. </div>
  331. </template>
  332. <style lang="scss" scoped>
  333. .abt {
  334. width: 88px;
  335. height: 38px;
  336. background: #00b0b0;
  337. border-radius: 4px;
  338. font-family: PingFangSC, PingFang SC;
  339. font-weight: 400;
  340. font-size: 14px;
  341. color: #ffffff;
  342. line-height: 38px;
  343. text-align: center;
  344. font-style: normal;
  345. cursor: pointer;
  346. }
  347. .about {
  348. width: 88px;
  349. height: 38px;
  350. background: #c7cbcc;
  351. border-radius: 4px;
  352. font-family: PingFangSC, PingFang SC;
  353. font-weight: 400;
  354. font-size: 14px;
  355. color: #ffffff;
  356. line-height: 38px;
  357. text-align: center;
  358. font-style: normal;
  359. cursor: pointer;
  360. }
  361. .usebox {
  362. width: 346px;
  363. height: 62px;
  364. background: #ffffff;
  365. border-radius: 4px;
  366. padding: 11px 16px;
  367. box-sizing: border-box;
  368. display: flex;
  369. justify-content: space-between;
  370. flex-wrap: wrap;
  371. align-items: center;
  372. }
  373. .row-gap {
  374. height: 20px;
  375. }
  376. .index-follow-container {
  377. width: 1440px;
  378. max-width: 1440px;
  379. // padding: 0 76px;
  380. column-gap: 24px;
  381. margin: 0 auto;
  382. // .context {
  383. // width: 0;
  384. // flex: 1;
  385. // }
  386. .right-aside {
  387. width: 334px;
  388. }
  389. }
  390. .content-list {
  391. margin-bottom: 30px;
  392. column-gap: 18px;
  393. flex-wrap: wrap;
  394. // height: 280px;
  395. overflow: hidden;
  396. // &--c2 {
  397. // // height: 337px;
  398. // }
  399. }
  400. .content-lista {
  401. margin-bottom: 30px;
  402. column-gap: 18px;
  403. flex-wrap: wrap;
  404. min-height: 160px;
  405. // &--c2 {
  406. // // height: 337px;
  407. // }
  408. }
  409. </style>