workDetail.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <template>
  2. <view class="page">
  3. <!-- 引入FontAwesome -->
  4. <view>
  5. <link rel="stylesheet"
  6. href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  7. </view>
  8. <!-- 文章头图区域 -->
  9. <view class="topUser">
  10. <image :src="home_image" class="home_image" mode="aspectFill"></image>
  11. <!-- 图片指示器 -->
  12. <view class="image-indicator" v-if="image_list.length > 1">
  13. <text>{{ selImg + 1 }}/{{ image_list.length }}</text>
  14. </view>
  15. <!-- 音乐类型时显示歌词 -->
  16. <view class="lyrics-overlay" v-if="articleInfo.task_type == 2">
  17. <text class="lyrics-text">{{ articleInfo.lyrics }}</text>
  18. </view>
  19. <!-- 音乐类型时显示播放按钮 -->
  20. <view class="play-button" v-if="articleInfo.task_type == 2 && articleInfo.result_audio" @click="toggleAudio">
  21. <text class="fa" :class="isPlaying ? 'fa-pause' : 'fa-play'"></text>
  22. </view>
  23. <!-- 缩略图列表 -->
  24. <view class="list">
  25. <view class="img" :class="selImg==index?'active':''" v-for="(item,index) in image_list" :key="index"
  26. @click="selPhoto(item,index)">
  27. <image :src="item" mode="aspectFill"></image>
  28. </view>
  29. </view>
  30. </view>
  31. <!-- 音频元素 -->
  32. <audio id="audioPlayer" :src="articleInfo.result_audio" style="display:none;"></audio>
  33. <!-- 文章内容区域 -->
  34. <view class="body">
  35. <!-- 文章标题与元信息 -->
  36. <view class="article-header">
  37. <view class="title">
  38. {{ articleInfo.title || '暂无标题' }}
  39. </view>
  40. <view class="meta-info">
  41. <view class="meta-item">
  42. <text class="fa fa-calendar"></text>
  43. <text class="meta-text">{{ articleInfo.create_time || '暂无时间' }}</text>
  44. </view>
  45. <view class="meta-item">
  46. <text class="fa fa-eye"></text>
  47. <text class="meta-text">{{ articleInfo.num_view || 0 }}次阅读</text>
  48. </view>
  49. <view class="meta-item" v-if="articleInfo.author">
  50. <text class="fa fa-user"></text>
  51. <text class="meta-text">{{ articleInfo.author }}</text>
  52. </view>
  53. </view>
  54. </view>
  55. <!-- 内容分隔线 -->
  56. <view class="divider"></view>
  57. <!-- 文章内容 -->
  58. <!-- <view class="article-content" v-if="articleInfo.type == 'user'">
  59. <view class="content">{{ articleInfo.content || '暂无内容' }}</view>
  60. </view> -->
  61. <view class="article-content">
  62. <view class="content">
  63. <rich-text :nodes="content" style="font-size: 14px;"></rich-text>
  64. </view>
  65. </view>
  66. <!-- 文章底部区域 -->
  67. <view class="article-footer">
  68. <view class="action-bar">
  69. <view class="action-item" @tap="likeArticle">
  70. <text class="fa" :class="articleInfo.is_like ? 'fa-thumbs-up liked' : 'fa-thumbs-o-up'"></text>
  71. <text class="action-text">{{ articleInfo.like_count || 0 }}</text>
  72. </view>
  73. <view class="action-item" @tap="openComment">
  74. <text class="fa fa-comment-o"></text>
  75. <text class="action-text">{{ tableTotal || 0 }}</text>
  76. </view>
  77. <view class="action-item" @tap="shareArticle">
  78. <text class="fa fa-share-alt"></text>
  79. <text class="action-text">分享</text>
  80. </view>
  81. </view>
  82. </view>
  83. <!-- 空白占位 -->
  84. <view class="list_info">
  85. <view class="blankHeight"></view>
  86. </view>
  87. </view>
  88. <!-- <view class="btn_submit" @click="chatTA()">
  89. <image class="icon" src="../../static/icon/icon_chat_white.png" mode="widthFix"></image>
  90. 私聊
  91. </view> -->
  92. <view class="thread2"></view>
  93. <view class="thread2"></view>
  94. <previewImage ref="previewImage" :opacity="0.8" :circular="true" :imgs="imgs" :descs="descs"></previewImage>
  95. <!-- 评论区域 -->
  96. <CommentSection ref="commentSection" :myInfo="myInfo" :userInfo="userInfo" :articleId="arcID"></CommentSection>
  97. <view class="thread2"></view>
  98. </view>
  99. </template>
  100. <script>
  101. import htmlParser from '../../common/html-parser'
  102. import previewImage from '@/components/kxj-previewImage/kxj-previewImage.vue'; //引用插件
  103. import CommentSection from '@/components/CommentSection/CommentSection.vue';
  104. function parseImgs(nodes) {
  105. nodes.forEach(node => {
  106. if (
  107. node.name === 'img' &&
  108. node.attrs &&
  109. node.attrs['data-img-size-val']
  110. ) {
  111. const sizes = node.attrs['data-img-size-val'].split(',')
  112. const width = uni.upx2px(720 * 0.9)
  113. const height = parseInt(width * (sizes[1] / sizes[0]))
  114. node.attrs.style = `width:${width};height:${height};`
  115. }
  116. if (Array.isArray(node.children)) {
  117. parseImgs(node.children)
  118. }
  119. })
  120. return nodes
  121. }
  122. export default {
  123. components: {
  124. previewImage,
  125. CommentSection,
  126. },
  127. data() {
  128. return {
  129. title: '',
  130. arcID: 0,
  131. selImg: 0,
  132. home_image: '',
  133. myinfo: {},
  134. tag_list: [],
  135. image_list: [],
  136. imgs: [],
  137. descs: [],
  138. list_wish: [],
  139. content: '',
  140. // 添加文章信息字段
  141. articleInfo: {
  142. title: '',
  143. content: '',
  144. create_time: '',
  145. images: '',
  146. view_count: 0,
  147. author: '',
  148. like_count: 0,
  149. is_like: false
  150. },
  151. myInfo: {
  152. user_id: 1, // 用户id
  153. user_name: "cc", // 用户名
  154. user_avatar: "https://img0.baidu.com/it/u=2836960144,3650263035&fm=253&fmt=auto&app=138&f=JPEG?w=474&h=474", // 用户头像地址
  155. },
  156. // 文章作者信息(提示: 一般来自localstorage, 如果是实时获取的话, 那么获取到数据后再v-if显示评论组件)
  157. userInfo: {
  158. user_id: 2, // 用户id
  159. user_name: "ikun", // 用户名
  160. user_avatar: "https://pic1.zhimg.com/80/v2-a79071a705f55c5d88f6c74e6111fe84_720w.webp", // 用户头像地址
  161. },
  162. deleteMode: "all", //删除模式
  163. // 评论总数
  164. tableTotal: 4,
  165. // 评论表
  166. tableData: [],
  167. isPlaying: false, // 添加播放状态
  168. audioPlayer: null, // 添加音频播放器实例
  169. }
  170. },
  171. onLoad(parms) {
  172. let self = this;
  173. this.arcID = parms.id || 393;
  174. },
  175. onShow() {
  176. uni.$emit('check_update');
  177. this.loadData();
  178. this.$nextTick(() => {
  179. if (this.$refs.commentSection) {
  180. this.$refs.commentSection.loadCommentData();
  181. }
  182. });
  183. },
  184. onReady() {
  185. // 初始化音频播放器
  186. this.audioPlayer = uni.createInnerAudioContext();
  187. this.audioPlayer.onEnded(() => {
  188. this.isPlaying = false;
  189. });
  190. },
  191. onUnload() {
  192. // 页面卸载时停止音频播放
  193. if (this.audioPlayer) {
  194. this.audioPlayer.stop();
  195. this.audioPlayer.destroy();
  196. }
  197. },
  198. methods: {
  199. onLinqu(item) {
  200. uni.navigateTo({
  201. url: '/pages/my/wishHelp?id=' + item.myid,
  202. })
  203. },
  204. selPhoto(item, sel) {
  205. this.selImg = sel;
  206. this.home_image = this.image_list[sel];
  207. },
  208. toArr(imgs) {
  209. let arr = imgs.split("|");
  210. return arr;
  211. },
  212. previewOpen(imgs1, index) {
  213. this.imgs = imgs1.split("|");
  214. setTimeout(() => this.$refs.previewImage.open(index), 0)
  215. // 传入当前选中的图片地址或序号
  216. return; //如需测试和uni原生预览差别可注释这两行
  217. },
  218. loadData() {
  219. uni.request({
  220. url: this.$apiHost + '/Work/getinfo',
  221. data: {
  222. uuid: getApp().globalData.uuid,
  223. id: this.arcID
  224. },
  225. header: {
  226. "content-type": "application/json",
  227. 'sign': getApp().globalData.headerSign
  228. },
  229. success: (res) => {
  230. console.log("文章信息:", res.data);
  231. if (res.data.success === "yes") {
  232. // 更新文章信息
  233. this.articleInfo = res.data.data;
  234. this.content = res.data.data.content;
  235. this.home_image = res.data.data.images;
  236. } else {
  237. uni.showToast({
  238. title: '获取信息失败',
  239. icon: 'none'
  240. });
  241. }
  242. },
  243. complete: (com) => {
  244. // uni.hideLoading();
  245. },
  246. fail: (e) => {
  247. console.log("请求失败:", e);
  248. uni.showToast({
  249. title: '网络请求失败',
  250. icon: 'none'
  251. });
  252. }
  253. });
  254. },
  255. // 唤起新评论弹框
  256. openComment() {
  257. if (this.$refs.commentSection) {
  258. this.$refs.commentSection.openComment();
  259. }
  260. },
  261. // 文章点赞
  262. likeArticle() {
  263. uni.request({
  264. url: this.$apiHost + '/Work/zanTA',
  265. data: {
  266. uuid: getApp().globalData.uuid,
  267. id: this.arcID
  268. },
  269. header: {
  270. "content-type": "application/json",
  271. 'sign': getApp().globalData.headerSign
  272. },
  273. success: (res) => {
  274. console.log("点赞结果:", res.data);
  275. if (res.data.success === "yes") {
  276. // 更新点赞状态
  277. if (!this.articleInfo.is_like) {
  278. this.articleInfo.like_count = (this.articleInfo.like_count || 0) + 1;
  279. this.articleInfo.is_like = true;
  280. uni.showToast({
  281. title: '点赞成功',
  282. icon: 'none'
  283. });
  284. } else {
  285. this.articleInfo.like_count = (this.articleInfo.like_count || 0) - 1;
  286. this.articleInfo.is_like = false;
  287. uni.showToast({
  288. title: res.data.str,
  289. icon: 'none'
  290. });
  291. }
  292. } else {
  293. uni.showToast({
  294. title: res.data.str,
  295. icon: 'none'
  296. });
  297. }
  298. },
  299. fail: (e) => {
  300. console.log("点赞失败:", e);
  301. uni.showToast({
  302. title: '网络请求失败',
  303. icon: 'none'
  304. });
  305. }
  306. });
  307. },
  308. // 分享文章
  309. shareArticle() {
  310. // 如果在微信小程序环境
  311. if (uni.getSystemInfoSync().platform === 'mp-weixin') {
  312. uni.showShareMenu({
  313. withShareTicket: true,
  314. menus: ['shareAppMessage', 'shareTimeline']
  315. });
  316. } else {
  317. // 其他环境,如APP
  318. uni.share({
  319. provider: "weixin",
  320. scene: "WXSceneSession",
  321. type: 0,
  322. title: this.articleInfo.title,
  323. summary: this.articleInfo.content.substring(0, 40) + "...",
  324. imageUrl: this.home_image,
  325. success: function(res) {
  326. console.log("分享成功:" + JSON.stringify(res));
  327. },
  328. fail: function(err) {
  329. console.log("分享失败:" + JSON.stringify(err));
  330. }
  331. });
  332. }
  333. },
  334. // 切换音频播放状态
  335. toggleAudio() {
  336. if (!this.articleInfo.result_audio) return;
  337. if (this.isPlaying) {
  338. this.audioPlayer.pause();
  339. this.isPlaying = false;
  340. } else {
  341. this.audioPlayer.src = this.articleInfo.result_audio;
  342. this.audioPlayer.play();
  343. this.isPlaying = true;
  344. }
  345. },
  346. }
  347. }
  348. </script>
  349. <style scoped lang="scss">
  350. @import 'workDetail.scss';
  351. </style>