news-detail.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <!-- 新闻 详情 -->
  2. <template>
  3. <view class="container">
  4. <view>
  5. <view style="background-color: #FFFFFF;padding: 30rpx 30rpx 30rpx 30rpx;">
  6. <view class="titleBox text-xl text-black text-bold">{{newsData.title}}</view>
  7. <view class="flex justify-between text-df text-gray margin-top-sm margin-bottom-sm">
  8. <text>{{newsData.createdAt | formatDate}}</text>
  9. <text>{{newsData.type | typeF}}</text>
  10. </view>
  11. <image mode="widthFix" :src="newsData.img"></image>
  12. <!-- 中间文章区域 -->
  13. <view class="contentBox text-lg text-black margin-top-sm margin-tb-lg">
  14. <view class="margin-top-sm" v-for="(item, index) in newsData.content.split('&')" v-html="item">
  15. </view>
  16. </view>
  17. </view>
  18. <view class="cu-bar justify-left bg-white margin-top-sm">
  19. <view class="action border-title">
  20. <text class="text-lg text-bold text-blue">图片展示</text>
  21. <text class="bg-gradual-blue" style="width:3rem"></text>
  22. </view>
  23. </view>
  24. <view style="background-color: #FFFFFF;padding: 0rpx 30rpx 30rpx 30rpx;">
  25. <!-- 图片展示 · 多条 -->
  26. <image @click="previewImage(index)" v-for="(item, index) in newsData.imgList.split(',')" :key="index"
  27. mode="widthFix" :src="item"></image>
  28. <!-- 浏览、点赞、分享数 -->
  29. <view class="text-right text-df text-gray margin-top-sm margin-bottom-sm">
  30. <text class="text-gray cuIcon-attentionfill text-df" style="margin-right: 6rpx;"></text>
  31. <text class="text-df margin-right-sm" style="margin-top: 2rpx;">{{newsData.seeNum}}</text>
  32. <text class="text-gray cuIcon-appreciatefill text-df" style="margin-right: 6rpx;"></text>
  33. <text class="text-df margin-right-sm" style="margin-top: 2rpx;">{{newsData.likesNum}}</text>
  34. <text class="text-gray cuIcon-share text-df" style="margin-right: 6rpx;"></text>
  35. <text class="text-df" style="margin-top: 2rpx;">{{newsData.commentNum}}</text>
  36. </view>
  37. </view>
  38. </view>
  39. <view class="cu-bar bg-white tabbar border shop bottomBox">
  40. <button class="action" open-type="share">
  41. <view class="cuIcon-share text-green">
  42. <view class="cu-tag badge">{{newsData.commentNum}}</view>
  43. </view>
  44. 分享
  45. </button>
  46. <button class="action" open-type="contact">
  47. <view class="cuIcon-service text-green">
  48. <view class="cu-tag badge"></view>
  49. </view>
  50. 联系我们
  51. </button>
  52. <view class="btn-group">
  53. <button style="width: 80%;height: 70rpx;" @click="praiseClick(newsData.id)"
  54. class="cu-btn bg-gradual-blue round shadow-blur">
  55. <view class="cuIcon-appreciatefill text-white margin-right-xs"></view>
  56. 赞一下吧
  57. </button>
  58. </view>
  59. </view>
  60. <view class="safe-area-inset-bottom"></view>
  61. </view>
  62. </template>
  63. <script>
  64. // import request from '@/common/request.js';
  65. export default {
  66. data() {
  67. return {
  68. newsData: [],
  69. requestStatus: false // 事件防抖
  70. }
  71. },
  72. onLoad(option) {
  73. console.log(option)
  74. this.getData(option.id);
  75. },
  76. methods: {
  77. // 点赞
  78. getData(id) {
  79. console.log(id);
  80. var data = {"data":{"id":1,"type":2,"title":"「前端铺子」开源了,前端者必备项目","img":"https://cdn.zhoukaiwen.com/Ftk7V5qMnpSAYNTXR2YaK2JFdlkt","content":"项目基于vue-uniapp,使用colorUi与uView框架,完美支持微信小程序,包含功能:自定义TabBar与顶部、地图轨迹回放、电子签名、自定义相机/键盘、拍照图片水印、在线答题、证件识别、周边定位查询、文档预览、各种图表、行政区域、海报生成器、视频播放、主题切换、时间轴、瀑布流、排行榜、渐变动画、加载动画、请求封装等~ 方便同行小伙伴参考;\n&项目链接:https://gitee.com/kevin_chou/qdpz","author":"Kevin","createdAt":1664386507006,"state":1,"seeNum":4439,"likesNum":348,"commentNum":386,"imgList":"https://cdn.zhoukaiwen.com/FuXEx9dURbfa_4TIzM1gtWYtkIYy,https://cdn.zhoukaiwen.com/FtqKFoFs0RkOwmQ25iCAqkeOdoUo,https://cdn.zhoukaiwen.com/FtqKFoFs0RkOwmQ25iCAqkeOdoUo,https://cdn.zhoukaiwen.com/Fi1OviL0gjCKP2EidMOC9Q93wz2w,https://cdn.zhoukaiwen.com/FsQAHnCVzEgqp62bC-dXSfNgD9Fc"},"code":200};
  81. this.newsData = data.data;
  82. // uni.showLoading({
  83. // title: '加载中'
  84. // });
  85. // let opts = {
  86. // url: 'api/blog/detail?id=' + id,
  87. // method: 'get'
  88. // };
  89. // request.httpRequest(opts).then(res => {
  90. // console.log(res);
  91. // uni.hideLoading();
  92. // if (res.data.data.id) {
  93. // this.newsData = res.data.data;
  94. // } else {
  95. // console.log('数据请求错误~');
  96. // }
  97. // });
  98. },
  99. // 点赞
  100. praiseClick(id) {
  101. console.log(id);
  102. if (this.requestStatus) { // 时间防抖:利用 return 终止函数继续运行
  103. return false;
  104. };
  105. this.requestStatus = true;
  106. uni.showLoading({
  107. title: '加载中'
  108. });
  109. let opts = {
  110. url: 'api/blog/like?id=' + id,
  111. method: 'get'
  112. };
  113. request.httpRequest(opts).then(res => {
  114. console.log(res);
  115. uni.hideLoading();
  116. if (res.data.code == 200) {
  117. this.newsData.likesNum++;
  118. uni.showToast({
  119. title: '点赞成功!感谢参与',
  120. duration: 2000
  121. });
  122. setTimeout(() => {
  123. // 模拟执行完毕,改变 requestStatus
  124. this.requestStatus = false;
  125. }, 2500);
  126. } else {
  127. console.log('数据请求错误~');
  128. }
  129. });
  130. },
  131. previewImage(index) {
  132. // 预览功能需要数组格式,具体查看uniapp文档:previewImage
  133. const seeImgList = this.newsData.imgList.split(',')
  134. uni.previewImage({
  135. current: index, //预览图片的下标
  136. urls: seeImgList //预览图片的地址,必须要数组形式,如果不是数组形式就转换成数组形式就可以
  137. })
  138. },
  139. },
  140. filters: {
  141. formatDate(value) {
  142. if (value == undefined) {
  143. return;
  144. }
  145. // let date = new Date(value * 1000);
  146. let date = new Date(value);
  147. //时间戳为10位需*1000,时间戳为13位的话不需乘1000
  148. let y = date.getFullYear();
  149. let MM = date.getMonth() + 1;
  150. MM = MM < 10 ? ('0' + MM) : MM; //月补0
  151. let d = date.getDate();
  152. d = d < 10 ? ('0' + d) : d; //天补0
  153. let h = date.getHours();
  154. h = h < 10 ? ('0' + h) : h; //小时补0
  155. let m = date.getMinutes();
  156. m = m < 10 ? ('0' + m) : m; //分钟补0
  157. let s = date.getSeconds();
  158. s = s < 10 ? ('0' + s) : s; //秒补0
  159. // return y + '-' + MM + '-' + d; //年月日
  160. return y + '-' + MM + '-' + d + ' ' + h + ':' + m; //年月日时分秒
  161. },
  162. typeF(value) {
  163. if (!value) {
  164. return;
  165. }
  166. if (value == 2) {
  167. return 'web前端'
  168. }
  169. if (value == 3) {
  170. return 'ui设计'
  171. }
  172. if (value == 4) {
  173. return 'Node后端'
  174. }
  175. if (value == 5) {
  176. return '面试精选'
  177. }
  178. if (value == 6) {
  179. return '技术前沿'
  180. }
  181. if (value == 7) {
  182. return '更多资讯'
  183. }
  184. }
  185. }
  186. }
  187. </script>
  188. <style lang="scss" scoped>
  189. button::after {
  190. border: none;
  191. background: transparent;
  192. }
  193. uni-button {
  194. background: transparent;
  195. }
  196. .container {
  197. background-color: #f2f2f2;
  198. width: 750rpx;
  199. }
  200. .solid {
  201. border-radius: 50rpx;
  202. text-indent: 12rpx;
  203. }
  204. image {
  205. width: 750rpx;
  206. }
  207. .bottomBox {
  208. width: 750rpx;
  209. position: fixed;
  210. left: 0;
  211. bottom: 0rpx;
  212. }
  213. </style>