detail.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <template>
  2. <view>
  3. <view class="article_title">{{articleInfo.title}}</view>
  4. <view class="article_time">{{articleInfo.insert_time}}</view>
  5. <view class="rich_text">
  6. <rich-text :nodes="articleInfo.content"></rich-text>
  7. </view>
  8. <view class="read_total">阅读:{{articleInfo.read_count}}</view>
  9. <view class="handle_box">
  10. <view class="click_box" @click.stop="updateEvent(2)">
  11. <uni-icons :type="articleInfo.is_hand?'hand-up-filled':'hand-up'" :color="articleInfo.is_hand?'#e03519':'#333333'" size="20"></uni-icons>
  12. <text>{{articleInfo.hand_count}}</text>
  13. </view>
  14. <button class="click_box" open-type="share">
  15. <uni-icons type="upload" size="20"></uni-icons>
  16. <text>{{articleInfo.share_count}}</text>
  17. </button>
  18. <view class="click_box" @click.stop="updateEvent(4)" >
  19. <uni-icons :type="articleInfo.is_like?'heart-filled':'heart'" :color="articleInfo.is_like?'#e03519':'#333333'" size="20"></uni-icons>
  20. <text>{{articleInfo.like_count}}</text>
  21. </view>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. export default {
  27. data() {
  28. return {
  29. articleInfo:{
  30. 'id':0,
  31. 'title':'',
  32. 'poster':'',
  33. 'content':'',
  34. 'read_count':0,
  35. 'hand_count':0,
  36. 'like_count':0,
  37. 'share_count':0,
  38. 'is_hand':0,
  39. 'is_like':0,
  40. 'insert_time':'',
  41. },
  42. // 请求参数
  43. requestParam: {
  44. id: 0
  45. },
  46. isReqing:false,
  47. }
  48. },
  49. onLoad(param) {
  50. // 参数接收
  51. this.requestParam.id = param.id;
  52. // #ifdef MP-WEIXIN
  53. //分享按钮
  54. uni.showShareMenu({
  55. withShareTicket: true,
  56. menus: ["shareAppMessage", "shareTimeline"],
  57. });
  58. // #endif
  59. },
  60. onShareAppMessage(obj) {
  61. this.updateEvent(3);
  62. return {
  63. title: `999智控终端平台\n${this.articleInfo.title}`,
  64. path: "/pages/article/detail?id=" + this.articleInfo.id,
  65. promise: new Promise((resolve, reject) => {
  66. this.$http.request("api/share_message/get_item", { item_id: this.articleInfo.id, pages: "/pages/article/detail" }).then((callback) => {
  67. console.log(callback, "api/share_message/get_item");
  68. let obj = {
  69. title: callback.data?.title == "" ? `999智控终端平台\n${this.articleInfo.title}` : callback.data.title,
  70. path: "/pages/article/detail?id=" + this.articleInfo.id,
  71. };
  72. if (callback.data?.image_url !== "") {
  73. obj.imageUrl = callback.data.image_url;
  74. }
  75. resolve(obj);
  76. });
  77. }),
  78. };
  79. },
  80. onShow() {
  81. // 如果存在产品ID的话
  82. if (this.requestParam.id > 0) {
  83. // 请求详情
  84. this.$http.request("api/article/get_detail", this.requestParam).then((re) => {
  85. // 成功渲染数据
  86. if (re.code == "success") {
  87. // 刷新数据
  88. this.articleInfo = re.data;
  89. } else {
  90. if (re.code != "no_login") {
  91. uni.showModal({
  92. content: re.msg,
  93. showCancel: false,
  94. });
  95. }
  96. }
  97. });
  98. }
  99. },
  100. methods: {
  101. updateEvent(typeId){
  102. if( this.isReqing ) return ;
  103. this.isReqing = true;
  104. // 如果存在产品ID的话
  105. if ( this.articleInfo.id > 0 ) {
  106. // 请求详情
  107. this.$http.request("api/article/update_event", {type_id:typeId,article_id:this.articleInfo.id}).then((re) => {
  108. this.isReqing = false;
  109. // 成功渲染数据
  110. if (re.code == "success") {
  111. // 如果是点赞
  112. if( typeId == 2 ) {
  113. this.articleInfo.is_hand ? this.articleInfo.hand_count -= 1 : this.articleInfo.hand_count += 1;
  114. this.articleInfo.is_hand = this.articleInfo.is_hand ? 0 : 1;
  115. }
  116. // 如果是点赞
  117. if( typeId == 3 ) {
  118. this.articleInfo.is_hand ? this.articleInfo.share_count -= 1 : this.articleInfo.share_count += 1;
  119. }
  120. // 如果是喜欢
  121. if( typeId == 4 ) {
  122. this.articleInfo.is_like ? this.articleInfo.like_count -= 1 : this.articleInfo.like_count += 1;
  123. this.articleInfo.is_like = this.articleInfo.is_like ? 0 : 1;
  124. }
  125. } else {
  126. if (re.code != "no_login") {
  127. uni.showModal({
  128. content: re.msg,
  129. showCancel: false,
  130. });
  131. }
  132. }
  133. });
  134. }
  135. }
  136. }
  137. }
  138. </script>
  139. <style lang="less">
  140. .article_title{
  141. width: 700rpx;
  142. display: block;
  143. font-size: 36rpx;
  144. overflow: hidden;
  145. font-weight: bold;
  146. line-height: 60rpx;
  147. padding: 0rpx 25rpx;
  148. background-color: #FFFFFF;
  149. }
  150. .article_time{
  151. width: 700rpx;
  152. color: #999999;
  153. display: block;
  154. font-size: 26rpx;
  155. overflow: hidden;
  156. line-height: 40rpx;
  157. padding: 0rpx 25rpx;
  158. background-color: #FFFFFF;
  159. }
  160. .rich_text{
  161. width: 700rpx;
  162. display: block;
  163. overflow: hidden;
  164. font-size: 26rpx;
  165. margin: 0rpx auto;
  166. min-height: 600rpx;
  167. line-height: 50rpx;
  168. padding: 10rpx 25rpx;
  169. background-color: #FFFFFF;
  170. [alt] {
  171. //web_view图片
  172. max-width: 100%; // 避免图片超宽
  173. vertical-align: bottom; // 避免图片之间间隙
  174. }
  175. }
  176. .read_total{
  177. width: 700rpx;
  178. color: #999999;
  179. display: block;
  180. font-size: 26rpx;
  181. overflow: hidden;
  182. line-height: 40rpx;
  183. padding: 0rpx 25rpx;
  184. padding-bottom: 60rpx;
  185. background-color: #FFFFFF;
  186. }
  187. .handle_box {
  188. left: 0rpx;
  189. width: 700rpx;
  190. height: 120rpx;
  191. display: block;
  192. position: fixed;
  193. overflow: hidden;
  194. padding: 20rpx 25rpx;
  195. background-color: #FFFFFF;
  196. bottom: var(--window-bottom);
  197. border-top: 2rpx solid #DDDDDD;
  198. .click_box{
  199. border: none;
  200. float: right;
  201. display: block;
  202. height: 120rpx;
  203. padding: 0rpx 0rpx;
  204. line-height: 120rpx;
  205. margin-right: 20rpx;
  206. font-size: 24rpx !important;
  207. background-color: transparent;
  208. .uni-icons{
  209. font-size: 36rpx !important;
  210. }
  211. }
  212. .click_box::after{
  213. border: none;
  214. background-color: transparent;
  215. }
  216. }
  217. </style>