detail.vue 6.7 KB

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