workDetail.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  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. <view class="comment-section">
  97. <view class="section-header">
  98. <text class="fa fa-comments"></text>
  99. <text class="section-title">评论区</text>
  100. <text class="comment-count">({{ tableTotal }})</text>
  101. </view>
  102. <CComment ref="ccRef" :myInfo="myInfo" :userInfo="userInfo" :tableData="tableData"
  103. :tableTotal.sync="tableTotal" :deleteMode="deleteMode" @likeFun="likeFun" @replyFun="replyFun"
  104. @deleteFun="deleteFun"></CComment>
  105. <view class="comment-button" @tap="openComment">
  106. <text class="fa fa-pencil"></text>
  107. <text>发表新评论</text>
  108. </view>
  109. </view>
  110. <view class="thread2"></view>
  111. </view>
  112. </template>
  113. <script>
  114. import htmlParser from '../../common/html-parser'
  115. import CComment from "@/components/cc-comment/cc-comment.vue";
  116. import previewImage from '@/components/kxj-previewImage/kxj-previewImage.vue'; //引用插件
  117. function parseImgs(nodes) {
  118. nodes.forEach(node => {
  119. if (
  120. node.name === 'img' &&
  121. node.attrs &&
  122. node.attrs['data-img-size-val']
  123. ) {
  124. const sizes = node.attrs['data-img-size-val'].split(',')
  125. const width = uni.upx2px(720 * 0.9)
  126. const height = parseInt(width * (sizes[1] / sizes[0]))
  127. node.attrs.style = `width:${width};height:${height};`
  128. }
  129. if (Array.isArray(node.children)) {
  130. parseImgs(node.children)
  131. }
  132. })
  133. return nodes
  134. }
  135. export default {
  136. components: {
  137. previewImage,
  138. CComment
  139. },
  140. data() {
  141. return {
  142. title: '',
  143. arcID: 0,
  144. selImg: 0,
  145. home_image: '',
  146. myinfo: {},
  147. tag_list: [],
  148. image_list: [],
  149. imgs: [],
  150. descs: [],
  151. list_wish: [],
  152. content: '',
  153. // 添加文章信息字段
  154. articleInfo: {
  155. title: '',
  156. content: '',
  157. create_time: '',
  158. images: '',
  159. view_count: 0,
  160. author: '',
  161. like_count: 0,
  162. is_like: false
  163. },
  164. myInfo: {
  165. user_id: 1, // 用户id
  166. user_name: "cc", // 用户名
  167. user_avatar: "https://img0.baidu.com/it/u=2836960144,3650263035&fm=253&fmt=auto&app=138&f=JPEG?w=474&h=474", // 用户头像地址
  168. },
  169. // 文章作者信息(提示: 一般来自localstorage, 如果是实时获取的话, 那么获取到数据后再v-if显示评论组件)
  170. userInfo: {
  171. user_id: 2, // 用户id
  172. user_name: "ikun", // 用户名
  173. user_avatar: "https://pic1.zhimg.com/80/v2-a79071a705f55c5d88f6c74e6111fe84_720w.webp", // 用户头像地址
  174. },
  175. deleteMode: "all", //删除模式
  176. // 评论总数
  177. tableTotal: 4,
  178. // 评论表
  179. tableData: [],
  180. isPlaying: false, // 添加播放状态
  181. audioPlayer: null, // 添加音频播放器实例
  182. }
  183. },
  184. onLoad(parms) {
  185. let self = this;
  186. this.arcID = parms.id || 393;
  187. },
  188. onShow() {
  189. uni.$emit('check_update');
  190. this.loadData();
  191. this.loadCommentData();
  192. },
  193. onReady() {
  194. // 初始化音频播放器
  195. this.audioPlayer = uni.createInnerAudioContext();
  196. this.audioPlayer.onEnded(() => {
  197. this.isPlaying = false;
  198. });
  199. },
  200. onUnload() {
  201. // 页面卸载时停止音频播放
  202. if (this.audioPlayer) {
  203. this.audioPlayer.stop();
  204. this.audioPlayer.destroy();
  205. }
  206. },
  207. methods: {
  208. onLinqu(item) {
  209. uni.navigateTo({
  210. url: '/pages/my/wishHelp?id=' + item.myid,
  211. })
  212. },
  213. selPhoto(item, sel) {
  214. this.selImg = sel;
  215. this.home_image = this.image_list[sel];
  216. },
  217. toArr(imgs) {
  218. let arr = imgs.split("|");
  219. return arr;
  220. },
  221. previewOpen(imgs1, index) {
  222. this.imgs = imgs1.split("|");
  223. setTimeout(() => this.$refs.previewImage.open(index), 0)
  224. // 传入当前选中的图片地址或序号
  225. return; //如需测试和uni原生预览差别可注释这两行
  226. },
  227. loadData() {
  228. uni.request({
  229. url: this.$apiHost + '/Work/getinfo',
  230. data: {
  231. uuid: getApp().globalData.uuid,
  232. id: this.arcID
  233. },
  234. header: {
  235. "content-type": "application/json",
  236. 'sign': getApp().globalData.headerSign
  237. },
  238. success: (res) => {
  239. console.log("文章信息:", res.data);
  240. if (res.data.success === "yes") {
  241. // 更新文章信息
  242. this.articleInfo = res.data.data;
  243. this.content = res.data.data.content;
  244. this.home_image = res.data.data.images;
  245. } else {
  246. uni.showToast({
  247. title: '获取信息失败',
  248. icon: 'none'
  249. });
  250. }
  251. },
  252. complete: (com) => {
  253. // uni.hideLoading();
  254. },
  255. fail: (e) => {
  256. console.log("请求失败:", e);
  257. uni.showToast({
  258. title: '网络请求失败',
  259. icon: 'none'
  260. });
  261. }
  262. });
  263. },
  264. loadCommentData() {
  265. uni.request({
  266. url: this.$apiHost + '/Article/getcomments',
  267. data: {
  268. uuid: getApp().globalData.uuid,
  269. type: 'work',
  270. id: this.arcID,
  271. page: 1,
  272. limit: 10
  273. },
  274. header: {
  275. "content-type": "application/json",
  276. 'sign': getApp().globalData.headerSign
  277. },
  278. success: (res) => {
  279. console.log("评论列表:", res.data);
  280. if (res.data.success == "yes") {
  281. this.$set(this, 'tableData', res.data.list);
  282. this.tableTotal = res.data.total;
  283. console.log("tabddd", this.tableData)
  284. } else {
  285. uni.showToast({
  286. title: '获取评论列表失败',
  287. icon: 'none'
  288. });
  289. }
  290. },
  291. complete: (com) => {
  292. // uni.hideLoading();
  293. },
  294. fail: (e) => {
  295. console.log("----e:", e);
  296. }
  297. });
  298. },
  299. // 唤起新评论弹框
  300. openComment() {
  301. let ccRef = this.$refs["ccRef"];
  302. ccRef.newCommentFun();
  303. },
  304. // 点赞回调事件
  305. likeFun({
  306. params
  307. }, callback) {
  308. console.log("likeFun", params);
  309. uni.request({
  310. url: this.$apiHost + '/Article/zanComment',
  311. data: {
  312. uuid: getApp().globalData.uuid,
  313. id: params.id
  314. },
  315. header: {
  316. "content-type": "application/json",
  317. 'sign': getApp().globalData.headerSign
  318. },
  319. success: (res) => {
  320. console.log("点赞结果:", res.data);
  321. if (res.data.success !== "yes") {
  322. callback(res); // 请求失败时重置点赞效果
  323. }
  324. },
  325. fail: (e) => {
  326. console.log("点赞失败:", e);
  327. callback(e); // 请求失败时重置点赞效果
  328. }
  329. });
  330. },
  331. // 文章点赞
  332. likeArticle() {
  333. uni.request({
  334. url: this.$apiHost + '/Work/zanTA',
  335. data: {
  336. uuid: getApp().globalData.uuid,
  337. id: this.arcID
  338. },
  339. header: {
  340. "content-type": "application/json",
  341. 'sign': getApp().globalData.headerSign
  342. },
  343. success: (res) => {
  344. console.log("点赞结果:", res.data);
  345. if (res.data.success === "yes") {
  346. // 更新点赞状态
  347. if (!this.articleInfo.is_like) {
  348. this.articleInfo.like_count = (this.articleInfo.like_count || 0) + 1;
  349. this.articleInfo.is_like = true;
  350. uni.showToast({
  351. title: '点赞成功',
  352. icon: 'none'
  353. });
  354. } else {
  355. this.articleInfo.like_count = (this.articleInfo.like_count || 0) - 1;
  356. this.articleInfo.is_like = false;
  357. uni.showToast({
  358. title: res.data.str,
  359. icon: 'none'
  360. });
  361. }
  362. } else {
  363. uni.showToast({
  364. title: res.data.str,
  365. icon: 'none'
  366. });
  367. }
  368. },
  369. fail: (e) => {
  370. console.log("点赞失败:", e);
  371. uni.showToast({
  372. title: '网络请求失败',
  373. icon: 'none'
  374. });
  375. }
  376. });
  377. },
  378. // 分享文章
  379. shareArticle() {
  380. // 如果在微信小程序环境
  381. if (uni.getSystemInfoSync().platform === 'mp-weixin') {
  382. uni.showShareMenu({
  383. withShareTicket: true,
  384. menus: ['shareAppMessage', 'shareTimeline']
  385. });
  386. } else {
  387. // 其他环境,如APP
  388. uni.share({
  389. provider: "weixin",
  390. scene: "WXSceneSession",
  391. type: 0,
  392. title: this.articleInfo.title,
  393. summary: this.articleInfo.content.substring(0, 40) + "...",
  394. imageUrl: this.home_image,
  395. success: function(res) {
  396. console.log("分享成功:" + JSON.stringify(res));
  397. },
  398. fail: function(err) {
  399. console.log("分享失败:" + JSON.stringify(err));
  400. }
  401. });
  402. }
  403. },
  404. // 评论回调事件
  405. replyFun({
  406. params
  407. }, callback) {
  408. // params = {
  409. // ...params,
  410. // user_id: this.myInfo.user_id, // 用户id
  411. // user_name: this.myInfo.user_name, // 用户名
  412. // user_avatar: this.myInfo.user_avatar, // 用户头像地址
  413. // user_content: this.commentValue, // 用户评论内容
  414. // is_like: false, // 是否点赞
  415. // like_count: 0, // 点赞数统计
  416. // create_time: "刚刚", // 创建时间
  417. // owner: true, // 是否为所有者 所有者可以进行删除 管理员默认true
  418. // };
  419. console.log("replyFun", {
  420. uuid: getApp().globalData.uuid,
  421. type: 'work',
  422. article_id: this.arcID, // 文章ID
  423. content: params.user_content, // 评论内容
  424. parent_id: params.parent_id || 0, // 父评论ID
  425. reply_id: params.reply_id || 0, // 回复的评论ID
  426. reply_name: params.reply_name || '' // 被回复人名称
  427. });
  428. uni.request({
  429. url: this.$apiHost + '/Article/newComment',
  430. data: {
  431. uuid: getApp().globalData.uuid,
  432. type: 'work',
  433. article_id: this.arcID, // 文章ID
  434. content: params.user_content, // 评论内容
  435. parent_id: params.parent_id || 0, // 父评论ID
  436. reply_id: params.reply_id || 0, // 回复的评论ID
  437. reply_name: params.reply_name || '' // 被回复人名称
  438. },
  439. header: {
  440. "content-type": "application/json",
  441. 'sign': getApp().globalData.headerSign
  442. },
  443. success: (res) => {
  444. console.log("评论结果:", res.data);
  445. if (res.data.success === "yes") {
  446. callback(res.data); // 评论成功,传入后端返回的数据
  447. }
  448. },
  449. fail: (e) => {
  450. console.log("评论失败:", e);
  451. uni.showToast({
  452. title: '评论失败,请重试',
  453. icon: 'none'
  454. });
  455. }
  456. });
  457. },
  458. /** 删除回调事件
  459. * mode 删除模式
  460. * -- bind: 当被删除的一级评论存在回复评论, 那么该评论内容变更显示为[当前评论内容已被移除]
  461. * -- only: 仅删除当前评论(后端删除相关联的回复评论, 否则总数显示不对)
  462. * -- all : 删除所有评论包括回复评论 前端遍历子评论上报
  463. */
  464. deleteFun({
  465. params,
  466. mode
  467. }, callback) {
  468. console.log("deleteFun", {
  469. params,
  470. mode
  471. });
  472. // 将params转换为逗号分隔的字符串
  473. const idsString = Array.isArray(params) ? params.join(',') : params.toString();
  474. console.log("删除评论", idsString, mode)
  475. uni.request({
  476. url: this.$apiHost + '/Article/delComment',
  477. data: {
  478. uuid: getApp().globalData.uuid,
  479. ids: idsString, // 将params转换为逗号分隔的字符串传递给ids
  480. mode: mode
  481. },
  482. header: {
  483. "content-type": "application/json",
  484. 'sign': getApp().globalData.headerSign
  485. },
  486. success: (res) => {
  487. console.log("删除结果:", res.data);
  488. if (res.data.success === "yes") {
  489. callback(res);
  490. }
  491. },
  492. fail: (e) => {}
  493. });
  494. // switch (mode) {
  495. // case "bind":
  496. // // 逻辑: 调用接口进行评论内容修改 update
  497. // setTimeout(() => callback(), 500); // 目前为了展示效果, 直接执行callback
  498. // break;
  499. // case "only":
  500. // // 逻辑: 调用接口删除一个评论 delete
  501. // setTimeout(() => callback(), 500); // 目前为了展示效果, 直接执行callback
  502. // break;
  503. // default:
  504. // // all
  505. // // 逻辑: 调用接口删除多个评论 [delete]
  506. // setTimeout(() => callback(), 500); // 目前为了展示效果, 直接执行callback
  507. // break;
  508. // }
  509. },
  510. // 切换音频播放状态
  511. toggleAudio() {
  512. if (!this.articleInfo.result_audio) return;
  513. if (this.isPlaying) {
  514. this.audioPlayer.pause();
  515. this.isPlaying = false;
  516. } else {
  517. this.audioPlayer.src = this.articleInfo.result_audio;
  518. this.audioPlayer.play();
  519. this.isPlaying = true;
  520. }
  521. },
  522. }
  523. }
  524. </script>
  525. <style scoped lang="scss">
  526. @import 'workDetail.scss';
  527. </style>