rich_card.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <template>
  2. <div class="card-situation">
  3. <div class="card-title">{{ model.title }}</div>
  4. <div class="card-text" :class="{ isfold: isfold }">
  5. <u-parse :content="model.text" @navigate="navigateUrl" />
  6. </div>
  7. <div class="fold" v-if="isFold && localIsFold" @click="changeFoldState">
  8. 点击{{ foldText }}
  9. </div>
  10. </div>
  11. </template>
  12. <script>
  13. import uParse from '@/components/gaoyia-parse/parse.vue'
  14. export default {
  15. components: {
  16. uParse
  17. },
  18. props: ["model", "isFold"],
  19. data() {
  20. return {
  21. isfold: false,
  22. height: 0,
  23. foldText: "展开",
  24. scrollTop: 0,
  25. localIsFold: true,
  26. };
  27. },
  28. mounted() {
  29. let query = uni.createSelectorQuery().in(this);
  30. let cardText = query.select(".card-text");
  31. cardText
  32. .boundingClientRect((res) => {
  33. this.height = res.height;
  34. })
  35. .exec(() => {
  36. if (this.height < 500) {
  37. this.localIsFold = false;
  38. } else {
  39. this.isfold = true;
  40. }
  41. });
  42. },
  43. watch: {
  44. isfold(newValue, oldValue) {
  45. if (newValue) {
  46. this.foldText = "展开";
  47. } else {
  48. this.foldText = "收起";
  49. }
  50. },
  51. },
  52. methods: {
  53. navigateUrl(href, e) {
  54. uni.setClipboardData({
  55. data:href,//要被复制的内容
  56. success:()=>{//复制成功的回调函数
  57. uni.showToast({//提示
  58. title:'复制成功'
  59. })
  60. }
  61. });
  62. },
  63. changeFoldState() {
  64. let poor = 0,
  65. Bheight = 0,
  66. Eheight = 0;
  67. let query = uni.createSelectorQuery().in(this);
  68. let con = query.select(".card-situation");
  69. con
  70. .fields({ size: true }, (e) => {
  71. Bheight = e.height;
  72. })
  73. .exec(() => {
  74. console.log("开始高度", Bheight);
  75. });
  76. this.isfold = !this.isfold;
  77. con
  78. .fields({ size: true }, (e) => {
  79. Eheight = e.height;
  80. })
  81. .exec(() => {
  82. // this.$emit("changeScroll", Bheight - Eheight);
  83. console.log("结束高度", Eheight);
  84. });
  85. this.$emit("changeScroll");
  86. },
  87. },
  88. };
  89. </script>
  90. <style lang="scss" scoped>
  91. .card-situation {
  92. // margin-top: 20rpx;
  93. padding: 20rpx;
  94. border-top: 8rpx solid #f2f2f2;
  95. box-shadow: 0px 4rpx 32rpx rgba(0, 0, 0, 0.1);
  96. border-radius: 32rpx;
  97. .card-title {
  98. font-weight: 600;
  99. padding: 20rpx 20rpx 0rpx 20rpx;
  100. }
  101. .card-text {
  102. padding: 20rpx;
  103. margin-top: 20rpx;
  104. font-size: 32rpx;
  105. letter-spacing: 1rpx;
  106. line-height: 50rpx;
  107. overflow: hidden;
  108. }
  109. .fold {
  110. display: flex;
  111. justify-content: center;
  112. align-items: center;
  113. color: $uni-color-primary;
  114. }
  115. }
  116. .isfold {
  117. max-height: 340rpx;
  118. }
  119. </style>