artInfo.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template>
  2. <gracePage headerBG="#FFFFFF" :customHeader="false">
  3. <view slot="gBody" class="grace-body">
  4. <!-- 标题 -->
  5. <text :class="['grace-art-margin', 'grace-art-title', graceSkeleton ? 'grace-skeletons' : '']">{{article.title}}</text>
  6. <!-- 作者信息 -->
  7. <view class="grace-art-margin grace-nowrap grace-flex-vcenter">
  8. <view :class="['grace-art-author','grace-nowrap','grace-flex-vcenter', graceSkeleton ? 'grace-skeletons' : '']">
  9. <image class="grace-art-author-face" :src="article.authorFace" mode="widthFix"></image>
  10. <text v-if="article.authorName" class="grace-art-author-name">{{article.authorName}}</text>
  11. </view>
  12. <text class="grace-art-btn grace-bg-green">+ 关注</text>
  13. </view>
  14. <!-- 其他基本信息 -->
  15. <view :class="['grace-art-info-line','grace-art-margin','grace-space-between', graceSkeleton ? 'grace-skeletons' : '']">
  16. <text class="grace-art-info-line-text grace-icons icon-eye icon-right-margin" v-if="article.viewNumber"> {{article.viewNumber}}</text>
  17. <text class="grace-art-info-line-text" v-if="article.date">发布于 : {{article.date}}</text>
  18. </view>
  19. <!-- 文章内容 -->
  20. <view class="grace-art-contents">
  21. <block v-for="(item, index) in article.contents" :key="index">
  22. <view :class="[graceSkeleton ? 'grace-skeletons-img' : 'grace-img-in']" v-if="item.type == 'img'">
  23. <image :src="item.content" class="grace-art-img" mode="widthFix" :data-imgurl="item.content" @tap="prevImg"></image>
  24. </view>
  25. <view :class="[graceSkeleton ? 'grace-skeletons' : 'grace-art-content']" v-if="item.type == 'text'">{{item.content}}</view>
  26. </block>
  27. </view>
  28. </view>
  29. </gracePage>
  30. </template>
  31. <script>
  32. import gracePage from "../../graceUI/components/gracePage.vue";
  33. export default {
  34. data() {
  35. return {
  36. graceSkeleton : true,
  37. //文章对象格式
  38. //{
  39. // title : "标题",
  40. // authorFcae : "作者头像",
  41. // authorName : "作者姓名",
  42. // viewNumber : "浏览次数",
  43. // date : "日期",
  44. // contents : [
  45. // {type : "text", content : "文本内容"},
  46. // {type : "img", content : "图片路径"},
  47. // //.....
  48. // ]
  49. //}
  50. article : {}
  51. }
  52. },
  53. onLoad : function(){
  54. // 加载文章详情
  55. uni.showLoading({});
  56. uni.request({
  57. url: 'http://grace.hcoder.net/api/news/info',
  58. method: 'GET',
  59. data: {},
  60. success: res => {
  61. var news = res.data.data;
  62. uni.setNavigationBarTitle({title:news.title});
  63. // 此处先规划骨架
  64. var art = {contents : []};
  65. for(var i = 0; i < news.contents.length; i++){
  66. art.contents.push({'type': news.contents[i].type});
  67. }
  68. this.article = art;
  69. // 骨架屏规划后延长 500 毫秒进行数据替换
  70. setTimeout(() => {
  71. this.article = news;
  72. this.graceSkeleton = false;
  73. }, 500);
  74. },
  75. fail: () => {},
  76. complete: () => {
  77. uni.hideLoading();
  78. }
  79. });
  80. },
  81. methods:{
  82. prevImg : function(e){
  83. var imgs = [];
  84. var currentUrl = e.currentTarget.dataset.imgurl;
  85. for(let i = 0; i < this.article.contents.length; i++){
  86. if(this.article.contents[i].type == 'img'){
  87. imgs.push(this.article.contents[i].content);
  88. }
  89. }
  90. uni.previewImage({
  91. urls : imgs,
  92. current : currentUrl
  93. })
  94. }
  95. },
  96. components:{gracePage}
  97. }
  98. </script>
  99. <style>
  100. .grace-art-margin{margin-top:20rpx;}
  101. .grace-art-title{display:block; width:100%; font-size:38rpx; font-weight:bold; line-height:56rpx;}
  102. .grace-skeletons{background-color:#F8F8F8; border-radius:8rpx; height:60rpx;}
  103. .grace-skeletons-img{width:100%; background-color:#F8F8F8; height:300rpx; border-radius:8rpx;}
  104. .grace-art-author{width:700rpx; font-size:0;}
  105. .grace-art-author-face{width:66rpx; height:66rpx; border-radius:66rpx; margin-right:20rpx; flex-shrink:0;}
  106. .grace-art-author-name{display:block; line-height:80rpx; font-size:26rpx;}
  107. .grace-art-btn{width:120rpx; line-height:60rpx; text-align:center; border-radius:50rpx; font-size:26rpx; display:block; flex-shrink:0; margin-left:30rpx;}
  108. .grace-art-info-line{}
  109. .grace-art-info-line-text{font-size:22rpx; line-height:50rpx; color:#888888;}
  110. .grace-art-contents{padding:20rpx 0;}
  111. .grace-art-img{width:100%; margin:10rpx 0;}
  112. .grace-art-content{line-height:52rpx; font-size:28rpx;}
  113. </style>