fragrantLifeDetail.vue 4.9 KB

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