accompanyingCampDetail.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <template>
  2. <view>
  3. <view class="shopping-wrapper">
  4. <view class="list-item">
  5. <view class="list-item-title">
  6. {{ item.name }}
  7. </view>
  8. <view class="list-item-read mt10 display-flex-between">
  9. <view class="display-flex">
  10. <image :src="shop_logo" class="list-item-read-img mr8" mode="aspectFit"></image>
  11. <view class="list-item-read-text">
  12. {{shopName}}
  13. </view>
  14. </view>
  15. <view class="display-flex">
  16. <view>
  17. <u-icon
  18. size="14"
  19. name="eye"
  20. ></u-icon>
  21. </view>
  22. <view class="list-item-read-text2 ml8">
  23. {{ item.num_read }}
  24. </view>
  25. </view>
  26. </view>
  27. <u-divider ></u-divider>
  28. <view class="list-item-remark ">
  29. {{ item.remark }}
  30. </view>
  31. </view>
  32. <view class="list-item mt10">
  33. <view class="list-item-content ">
  34. <u-parse :content="item.content" :tagStyle="contentStyle"></u-parse>
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. </template>
  40. <script>
  41. import {getNewsRead} from "@/common/api/news";
  42. export default {
  43. data() {
  44. return {
  45. item: {},
  46. itemId: 0,
  47. shopName: '',
  48. shop_logo: '',
  49. contentStyle:{
  50. p: "font-size:24rpx; background-color: #FFFFFF;",
  51. span: "font-size: 24rpx; background-color: #FFFFFF;",
  52. text:"font-size: 24rpx; background-color: #FFFFFF;"
  53. }
  54. };
  55. },
  56. created() {
  57. const configs = uni.getStorageSync("configs");
  58. if (configs) {
  59. console.log(configs)
  60. this.shopName = configs.shop_name
  61. this.shop_logo = configs.shop_logo
  62. }
  63. },
  64. onLoad(options) {
  65. console.log(options)
  66. this.itemId = options.id
  67. this.getData(options.id)
  68. },
  69. onShow() {
  70. this.getData(this.itemId)
  71. },
  72. methods: {
  73. setContent: function () {
  74. if (this.item.content) {
  75. this.item.content = this.item.content.replace(/\/apihttps:/g, 'https:');
  76. // 使用正则表达式匹配和修改 img 标签的 style 属性
  77. this.item.content = this.item.content.replace(/<img([^>]*)>/gi, (match, attributes) => {
  78. // 检查是否已经存在 style 属性
  79. if (attributes.includes('style')) {
  80. // 如果存在 style 属性,添加 width: 100%;
  81. return match.replace(/style="([^"]*)"/i, (styleMatch, styleContent) => {
  82. if (!styleContent.includes('width: 100%')) {
  83. return `style="${styleContent}; width: 100%;"`;
  84. }
  85. return styleMatch;
  86. });
  87. } else {
  88. // 如果不存在 style 属性,添加 style="width: 100%;"
  89. return match.replace(/<img/i, '<img style="width: 100%;"');
  90. }
  91. });
  92. }
  93. }, getData(id) {
  94. getNewsRead(
  95. {
  96. "id": id,
  97. }).then(({data}) => {
  98. if (data) {
  99. this.item = data
  100. this.setContent();
  101. }
  102. })
  103. },
  104. }
  105. }
  106. </script>
  107. <style lang="scss">
  108. .shopping-wrapper {
  109. width: calc(100% - 40rpx);
  110. margin: 20rpx auto 0rpx;
  111. padding: 0rpx 20rpx 60rpx;
  112. .list-item {
  113. background: #FFFFFF;
  114. border-radius: 16rpx 16rpx 16rpx 16rpx;
  115. width: calc(100% - 60rpx);
  116. padding:30rpx;
  117. &-title {
  118. font-family: PingFang SC, PingFang SC;
  119. font-weight: 600;
  120. font-size: 32rpx;
  121. color: #333333;
  122. line-height: 40rpx;
  123. text-align: left;
  124. font-style: normal;
  125. text-transform: none;
  126. }
  127. &-read{
  128. &-img{
  129. width: 36rpx;
  130. height: 36rpx;
  131. }
  132. &-text{
  133. font-family: PingFang SC-Medium, PingFang SC;
  134. font-weight: 400;
  135. font-size: 24rpx;
  136. color: #333333;
  137. line-height: 36rpx;
  138. text-align: left;
  139. font-style: normal;
  140. text-transform: none;
  141. }
  142. &-text2{
  143. font-family: PingFang SC-Medium, PingFang SC;
  144. font-weight: 400;
  145. font-size: 22rpx;
  146. color: #666666;
  147. line-height: 40rpx;
  148. text-align: left;
  149. font-style: normal;
  150. text-transform: none;
  151. }
  152. }
  153. &-remark{
  154. font-weight: 400;
  155. font-size: 24rpx;
  156. color: #666666;
  157. line-height: 40rpx;
  158. text-align: justify;
  159. font-style: normal;
  160. text-transform: none;
  161. }
  162. }
  163. .list-item-content{
  164. background-color: #FFFFFF;
  165. }
  166. }
  167. </style>