collection_component.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <template>
  2. <div class="item-img" v-if="collectionList.length == 0">
  3. <img @click="collection" v-if="collectionList.length == 0" src="@/assets/images/environment/collage.png">
  4. <p @click="collection" v-if="collectionList.length == 0">收藏</p>
  5. </div>
  6. <div class="item-img" v-if="collectionList.length >= 1">
  7. <img @click="cancle_collection" v-if="collectionList.length >= 1" src="@/assets/images/environment/collaged.png">
  8. <p @click="cancle_collection" v-if="collectionList.length >= 1">取消收藏</p>
  9. </div>
  10. <div class="item-img">
  11. <img src="@/assets/images/environment/contrast.png">
  12. <!-- <img src="@/assets/images/environment/contrasted.png">-->
  13. <p>对比</p>
  14. </div>
  15. </template>
  16. <script setup>
  17. import {addCollection, getCollection, removeCollection} from '@/api/xjc-integratedmachine/environment/university.js'
  18. const props = defineProps({
  19. collection: {
  20. contentType: null,
  21. contentId: null
  22. }
  23. })
  24. const collectionList = ref([])
  25. function collection() {
  26. let data = {
  27. contentType: props.collection.contentType,
  28. contentId: props.collection.contentId
  29. }
  30. addCollection(data).then(resp => {
  31. queryConnection()
  32. })
  33. }
  34. function queryConnection() {
  35. let data = {
  36. contentType: props.collection.contentType,
  37. contentId: props.collection.contentId
  38. }
  39. getCollection(data).then(resp => {
  40. collectionList.value = resp.collection
  41. })
  42. }
  43. function cancle_collection() {
  44. let data = {
  45. id: collectionList.value[0].id,
  46. }
  47. removeCollection(data).then(resp => {
  48. queryConnection()
  49. })
  50. }
  51. </script>
  52. <style scoped lang="scss">
  53. p,div{
  54. margin: 0;
  55. padding: 0;
  56. }
  57. .item-img {
  58. display: flex;
  59. flex-direction: column;
  60. align-items: center;
  61. width: 400px;
  62. border: 1px solid;
  63. p {
  64. font-weight: 400;
  65. font-size: 20px;
  66. color: #515F6A;
  67. }
  68. img {
  69. width: 36px;
  70. height: 36px;
  71. border: 1px solid;
  72. }
  73. }
  74. </style>