artInfo.nvue 4.1 KB

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