articleDetail.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. <template>
  2. <view class="page">
  3. <!-- 引入FontAwesome -->
  4. <view>
  5. <link
  6. rel="stylesheet"
  7. href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"
  8. />
  9. </view>
  10. <!-- 顶部导航栏 -->
  11. <view class="custom-navbar">
  12. <view class="navbar-left" @click="goBack">
  13. <text class="fa fa-angle-left"></text>
  14. </view>
  15. <view class="navbar-center">
  16. <view class="navbar-title">
  17. <image
  18. class="navbar-avatar"
  19. :src="author.avator"
  20. mode="aspectFill"
  21. ></image>
  22. <text class="navbar-text">{{ author.nickname }}</text>
  23. <!-- <text class="navbar-badge" v-if="author.is_vip > 0">VIP</text> -->
  24. </view>
  25. </view>
  26. <view class="navbar-right">
  27. <text
  28. class="followTheAuthor followTheAuthor1"
  29. v-if="author.is_attention == 0"
  30. @click="followTheAuthor(1)"
  31. >+关注</text
  32. >
  33. <text
  34. class="followTheAuthor followTheAuthor0"
  35. v-if="author.is_attention == 1"
  36. @click="followTheAuthor(0)"
  37. >已关注</text
  38. >
  39. <image
  40. v-if="false"
  41. @click="showActionSheet(0)"
  42. src="@/static/icon/sy_icon_fenxiang.png"
  43. mode="widthFix"
  44. ></image>
  45. <view v-else class="navbar-right" @click="showActionSheet(1)">
  46. <text class="fa fa-ellipsis-h"></text>
  47. </view>
  48. </view>
  49. </view>
  50. <view class="topStatusBar inProgress" v-if="0"> 审核中</view>
  51. <view class="topStatusBar fail" v-if="0" @click="openConfirmationBox">
  52. 审核未通过,点击查看原因</view
  53. >
  54. <!-- 轮播图部分 -->
  55. <uv-swiper
  56. v-if="articleInfo.type == 'user'"
  57. class="swiper-box"
  58. height="1032rpx"
  59. :list="swperImages"
  60. indicator
  61. indicatorMode="dot"
  62. bgColor="#fff"
  63. :autoplay="false"
  64. >
  65. </uv-swiper>
  66. <!-- 文章内容区域 -->
  67. <view class="body">
  68. <!-- 文章标题与元信息 -->
  69. <view class="article-header">
  70. <view class="title">
  71. {{ articleInfo.title || "暂无标题" }}
  72. </view>
  73. <view class="article-content">
  74. <view class="content">
  75. <rich-text :nodes="content" style="font-size: 14px"></rich-text>
  76. </view>
  77. </view>
  78. <view class="cardLink" @click="goToDetails(workInfo.id)">
  79. <image :src="workInfo.images" mode="heightFix"></image>
  80. <view class="content">
  81. <view class="tit">作品一号</view>
  82. <view class="tex">{{
  83. cutTime(workInfo.create_time) || "暂无时间"
  84. }}</view>
  85. </view>
  86. </view>
  87. <view v-if="false" class="meta-info">
  88. <view class="meta-item">
  89. <text class="fa fa-calendar"></text>
  90. <text class="meta-text">{{
  91. articleInfo.create_time || "暂无时间"
  92. }}</text>
  93. </view>
  94. <view class="meta-item">
  95. <text class="fa fa-eye"></text>
  96. <text class="meta-text">{{ articleInfo.num_view || 0 }}次阅读</text>
  97. </view>
  98. <view class="meta-item" v-if="articleInfo.author">
  99. <text class="fa fa-user"></text>
  100. <text class="meta-text">{{ articleInfo.author }}</text>
  101. </view>
  102. </view>
  103. </view>
  104. <!-- 文章底部区域 -->
  105. <view class="article-footer" v-if="false">
  106. <view class="action-bar">
  107. <view class="action-item" @tap="likeArticle">
  108. <text
  109. class="fa"
  110. :class="
  111. articleInfo.is_like ? 'fa-thumbs-up liked' : 'fa-thumbs-o-up'
  112. "
  113. ></text>
  114. <text class="action-text">{{ articleInfo.like_count || 0 }}</text>
  115. </view>
  116. <view class="action-item" @tap="openComment">
  117. <text class="fa fa-comment-o"></text>
  118. <text class="action-text">{{ tableTotal || 0 }}</text>
  119. </view>
  120. <view class="action-item" @tap="shareArticle">
  121. <text class="fa fa-share-alt"></text>
  122. <text class="action-text">分享</text>
  123. </view>
  124. </view>
  125. </view>
  126. </view>
  127. <!-- <view class="btn_submit" @click="chatTA()">
  128. <image class="icon" src="../../static/icon/icon_chat_white.png" mode="widthFix"></image>
  129. 私聊
  130. </view> -->
  131. <previewImage
  132. ref="previewImage"
  133. :opacity="0.8"
  134. :circular="true"
  135. :imgs="imgs"
  136. :descs="descs"
  137. ></previewImage>
  138. <!-- 评论区域 -->
  139. <CommentSection
  140. v-if="userInfo.id != 0"
  141. ref="commentSection"
  142. @totalNumberOfComments="totalNumberOfComments"
  143. :articleInfo="articleInfo"
  144. :myInfo="myInfo"
  145. :userInfo="userInfo"
  146. :articleId="arcID"
  147. :type="'article'"
  148. >
  149. </CommentSection>
  150. <view class="thread2"></view>
  151. <!-- 自定义 ActionSheet -->
  152. <ActionSheet
  153. ref="actionSheet"
  154. :items="items"
  155. @select="handleActionSelect"
  156. @cancel="handleActionCancel"
  157. />
  158. <CustomPopup ref="confirmationBox">
  159. <view class="failureReason">
  160. <view class="title"> 审核未通关</view>
  161. <view class="reviewContent">
  162. <!-- {{ fileInformation.reason }} -->
  163. 不通过原因
  164. </view>
  165. <view class="btn-box" @click="closeConfirmationBox">知道了</view>
  166. </view>
  167. </CustomPopup>
  168. </view>
  169. </template>
  170. <script>
  171. import htmlParser from "../../common/html-parser";
  172. import CommentSection from "@/components/CommentSection/CommentSection.vue";
  173. import previewImage from "@/components/kxj-previewImage/kxj-previewImage.vue"; //引用插件
  174. import CustomPopup from "@/components/CustomPopup/CustomPopup.vue";
  175. function parseImgs(nodes) {
  176. nodes.forEach((node) => {
  177. if (node.name === "img" && node.attrs && node.attrs["data-img-size-val"]) {
  178. const sizes = node.attrs["data-img-size-val"].split(",");
  179. const width = uni.upx2px(720 * 0.9);
  180. const height = parseInt(width * (sizes[1] / sizes[0]));
  181. node.attrs.style = `width:${width};height:${height};`;
  182. }
  183. if (Array.isArray(node.children)) {
  184. parseImgs(node.children);
  185. }
  186. });
  187. return nodes;
  188. }
  189. export default {
  190. components: {
  191. previewImage,
  192. CommentSection,
  193. CustomPopup,
  194. },
  195. data() {
  196. return {
  197. swperImages: [],
  198. items: [],
  199. title: "",
  200. arcID: 0,
  201. selImg: 0,
  202. home_image: "",
  203. myinfo: {},
  204. tag_list: [],
  205. image_list: [],
  206. imgs: [],
  207. descs: [],
  208. list_wish: [],
  209. content: "",
  210. tableTotal: 0,
  211. author: {},
  212. // 添加文章信息字段
  213. articleInfo: {
  214. title: "",
  215. content: "",
  216. create_time: "",
  217. images: "",
  218. view_count: 0,
  219. author: "",
  220. like_count: 0,
  221. is_like: false,
  222. },
  223. workInfo: {},
  224. myInfo: {
  225. user_id: getApp().globalData.mobile, // 用户id
  226. user_name: getApp().globalData.nickname, // 用户名
  227. user_avatar: getApp().globalData.avator, // 用户头像地址
  228. },
  229. // 文章作者信息(提示: 一般来自localstorage, 如果是实时获取的话, 那么获取到数据后再v-if显示评论组件)
  230. userInfo: {
  231. user_id: 0, // 用户id
  232. user_name: "", // 用户名
  233. user_avatar: "", // 用户头像地址
  234. },
  235. };
  236. },
  237. onLoad(parms) {
  238. let self = this;
  239. this.arcID = parms.id || 396;
  240. },
  241. onShow() {
  242. uni.$emit("check_update");
  243. this.$nextTick(() => {
  244. if (this.$refs.commentSection) {
  245. this.$refs.commentSection.loadCommentData();
  246. }
  247. });
  248. this.loadData();
  249. },
  250. methods: {
  251. openConfirmationBox() {
  252. this.$refs.confirmationBox.open();
  253. },
  254. closeConfirmationBox() {
  255. this.$refs.confirmationBox.close();
  256. },
  257. // 返回上一页
  258. goBack() {
  259. uni.navigateBack({
  260. delta: 1,
  261. });
  262. },
  263. // 文章点赞
  264. likeArticle() {
  265. uni.request({
  266. url: this.$apiHost + "/Work/zanTA",
  267. data: {
  268. uuid: getApp().globalData.uuid,
  269. id: this.arcID,
  270. },
  271. header: {
  272. "content-type": "application/json",
  273. sign: getApp().globalData.headerSign,
  274. },
  275. success: (res) => {
  276. console.log("点赞结果:", res.data);
  277. if (res.data.success === "yes") {
  278. // 更新点赞状态
  279. if (!this.articleInfo.is_like) {
  280. this.articleInfo.like_count =
  281. (this.articleInfo.like_count || 0) + 1;
  282. this.articleInfo.is_like = true;
  283. uni.showToast({
  284. title: "点赞成功",
  285. icon: "none",
  286. });
  287. } else {
  288. this.articleInfo.like_count =
  289. (this.articleInfo.like_count || 0) - 1;
  290. this.articleInfo.is_like = false;
  291. uni.showToast({
  292. title: res.data.str,
  293. icon: "none",
  294. });
  295. }
  296. } else {
  297. uni.showToast({
  298. title: res.data.str,
  299. icon: "none",
  300. });
  301. }
  302. },
  303. fail: (e) => {
  304. console.log("点赞失败:", e);
  305. uni.showToast({
  306. title: "网络请求失败",
  307. icon: "none",
  308. });
  309. },
  310. });
  311. },
  312. // 关注作者
  313. followTheAuthor(n) {
  314. uni.request({
  315. url: this.$apiHost + "/Member/attention",
  316. data: {
  317. uuid: getApp().globalData.uuid,
  318. id: this.author.id,
  319. },
  320. header: {
  321. "content-type": "application/json",
  322. sign: getApp().globalData.headerSign,
  323. },
  324. success: (res) => {
  325. console.log("点赞结果:", res.data);
  326. uni.showToast({
  327. title: res.data.str,
  328. icon: "none",
  329. });
  330. if (res.data.success === "yes") {
  331. console.log("关注结果:", res.data, n);
  332. this.author.is_attention = n;
  333. }
  334. },
  335. fail: (e) => {
  336. console.log("关注失败:", e);
  337. uni.showToast({
  338. title: "网络请求失败",
  339. icon: "none",
  340. });
  341. },
  342. });
  343. },
  344. totalNumberOfComments(tableTotal) {
  345. this.tableTotal = tableTotal;
  346. },
  347. onLinqu(item) {
  348. uni.navigateTo({
  349. url: "/pages/my/wishHelp?id=" + item.myid,
  350. });
  351. },
  352. selPhoto(item, sel) {
  353. this.selImg = sel;
  354. this.home_image = this.image_list[sel];
  355. },
  356. goToDetails(id) {
  357. console.log("goToDetails", id);
  358. uni.navigateTo({
  359. url: "/pages/index/workDetail?id=" + id,
  360. });
  361. console.log("goToDetails", id);
  362. },
  363. toArr(imgs) {
  364. let arr = imgs.split("|");
  365. return arr;
  366. },
  367. previewOpen(imgs1, index) {
  368. this.imgs = imgs1.split("|");
  369. setTimeout(() => this.$refs.previewImage.open(index), 0);
  370. return; //如需测试和uni原生预览差别可注释这两行
  371. },
  372. loadData() {
  373. uni.request({
  374. url: this.$apiHost + "/Article/getinfo",
  375. data: {
  376. uuid: getApp().globalData.uuid,
  377. id: this.arcID,
  378. },
  379. header: {
  380. "content-type": "application/json",
  381. sign: getApp().globalData.headerSign,
  382. },
  383. success: (res) => {
  384. console.log("文章信息:", res.data);
  385. if (res.data.success === "yes") {
  386. // 更新文章信息
  387. this.articleInfo = res.data.article;
  388. this.swperImages = this.imageString(res.data.article.images);
  389. console.log("swperImages", this.swperImages);
  390. this.userInfo.user_id = res.data.id; // 用户id
  391. this.userInfo.user_name = res.data.nickname; // 用户名
  392. this.userInfo.user_avatar = res.data.avator; // 用户头像地址
  393. this.author = res.data.author;
  394. this.workInfo = res.data.work_info;
  395. const nodes = htmlParser(res.data.article.content);
  396. // #ifdef APP-PLUS-NVUE
  397. parseImgs(nodes);
  398. // #endif
  399. this.content = nodes;
  400. // 更新图片列表
  401. if (res.data.article.images && res.data.article.images !== "") {
  402. this.image_list = res.data.article.images.split(",");
  403. this.home_image = this.image_list[0];
  404. } else {
  405. this.home_image = "../../static/home/avator.png";
  406. }
  407. console.log("img", this.home_image);
  408. // 更新标签列表
  409. // if (res.data.data.tags && res.data.data.tags !== "") {
  410. // this.tag_list = res.data.data.tags.split(",");
  411. // }
  412. } else {
  413. uni.showToast({
  414. title: "获取文章信息失败",
  415. icon: "none",
  416. });
  417. }
  418. },
  419. complete: (com) => {
  420. // uni.hideLoading();
  421. },
  422. fail: (e) => {
  423. console.log("请求失败:", e);
  424. uni.showToast({
  425. title: "网络请求失败",
  426. icon: "none",
  427. });
  428. },
  429. });
  430. },
  431. // 评论相关方法已移至CommentSection组件
  432. // 唤起新评论弹框
  433. openComment() {
  434. if (this.$refs.commentSection) {
  435. this.$refs.commentSection.openComment();
  436. }
  437. },
  438. // 文章点赞
  439. // 分享文章
  440. shareArticle() {
  441. // 如果在微信小程序环境
  442. if (uni.getSystemInfoSync().platform === "mp-weixin") {
  443. uni.showShareMenu({
  444. withShareTicket: true,
  445. menus: ["shareAppMessage", "shareTimeline"],
  446. });
  447. } else {
  448. // 其他环境,如APP
  449. uni.share({
  450. provider: "weixin",
  451. scene: "WXSceneSession",
  452. type: 0,
  453. title: this.articleInfo.title,
  454. summary: this.articleInfo.content.substring(0, 40) + "...",
  455. imageUrl: this.home_image,
  456. success: function (res) {
  457. console.log("分享成功:" + JSON.stringify(res));
  458. },
  459. fail: function (err) {
  460. console.log("分享失败:" + JSON.stringify(err));
  461. },
  462. });
  463. }
  464. },
  465. // 评论回调事件
  466. replyFun({ params }, callback) {
  467. // params = {
  468. // ...params,
  469. // user_id: this.myInfo.user_id, // 用户id
  470. // user_name: this.myInfo.user_name, // 用户名
  471. // user_avatar: this.myInfo.user_avatar, // 用户头像地址
  472. // user_content: this.commentValue, // 用户评论内容
  473. // is_like: false, // 是否点赞
  474. // like_count: 0, // 点赞数统计
  475. // create_time: "刚刚", // 创建时间
  476. // owner: true, // 是否为所有者 所有者可以进行删除 管理员默认true
  477. // };
  478. console.log("replyFun", {
  479. uuid: getApp().globalData.uuid,
  480. article_id: this.arcID, // 文章ID
  481. content: params.user_content, // 评论内容
  482. parent_id: params.parent_id || 0, // 父评论ID
  483. reply_id: params.reply_id || 0, // 回复的评论ID
  484. reply_name: params.reply_name || "", // 被回复人名称
  485. });
  486. uni.request({
  487. url: this.$apiHost + "/Article/newComment",
  488. data: {
  489. uuid: getApp().globalData.uuid,
  490. type: "article",
  491. article_id: this.arcID, // 文章ID
  492. content: params.user_content, // 评论内容
  493. parent_id: params.parent_id || 0, // 父评论ID
  494. reply_id: params.reply_id || 0, // 回复的评论ID
  495. reply_name: params.reply_name || "", // 被回复人名称
  496. },
  497. header: {
  498. "content-type": "application/json",
  499. sign: getApp().globalData.headerSign,
  500. },
  501. success: (res) => {
  502. console.log("评论结果:", res.data);
  503. if (res.data.success === "yes") {
  504. callback(res.data); // 评论成功,传入后端返回的数据
  505. }
  506. },
  507. fail: (e) => {
  508. console.log("评论失败:", e);
  509. uni.showToast({
  510. title: "评论失败,请重试",
  511. icon: "none",
  512. });
  513. },
  514. });
  515. },
  516. /** 删除回调事件
  517. * mode 删除模式
  518. * -- bind: 当被删除的一级评论存在回复评论, 那么该评论内容变更显示为[当前评论内容已被移除]
  519. * -- only: 仅删除当前评论(后端删除相关联的回复评论, 否则总数显示不对)
  520. * -- all : 删除所有评论包括回复评论 前端遍历子评论上报
  521. */
  522. deleteFun({ params, mode }, callback) {
  523. console.log("deleteFun", {
  524. params,
  525. mode,
  526. });
  527. // 将params转换为逗号分隔的字符串
  528. const idsString = Array.isArray(params)
  529. ? params.join(",")
  530. : params.toString();
  531. console.log("删除评论", idsString, mode);
  532. uni.request({
  533. url: this.$apiHost + "/Article/delComment",
  534. data: {
  535. uuid: getApp().globalData.uuid,
  536. ids: idsString, // 将params转换为逗号分隔的字符串传递给ids
  537. mode: mode,
  538. },
  539. header: {
  540. "content-type": "application/json",
  541. sign: getApp().globalData.headerSign,
  542. },
  543. success: (res) => {
  544. console.log("删除结果:", res.data);
  545. if (res.data.success === "yes") {
  546. callback(res);
  547. }
  548. },
  549. fail: (e) => {},
  550. });
  551. // switch (mode) {
  552. // case "bind":
  553. // // 逻辑: 调用接口进行评论内容修改 update
  554. // setTimeout(() => callback(), 500); // 目前为了展示效果, 直接执行callback
  555. // break;
  556. // case "only":
  557. // // 逻辑: 调用接口删除一个评论 delete
  558. // setTimeout(() => callback(), 500); // 目前为了展示效果, 直接执行callback
  559. // break;
  560. // default:
  561. // // all
  562. // // 逻辑: 调用接口删除多个评论 [delete]
  563. // setTimeout(() => callback(), 500); // 目前为了展示效果, 直接执行callback
  564. // break;
  565. // }
  566. },
  567. showActionSheet(n) {
  568. if (n == 0) {
  569. this.items = [
  570. {
  571. text: "分享作品",
  572. icon: "../../static/icon/cz_icon_fenxiangzuopin.png",
  573. },
  574. ];
  575. }
  576. if (n == 1) {
  577. this.items = [
  578. {
  579. text: "分享作品",
  580. icon: "../../static/icon/cz_icon_fenxiangzuopin.png",
  581. },
  582. {
  583. text: "修改帖子",
  584. icon: "../../static/icon/cz_icon_xiugaifengmian.png",
  585. },
  586. {
  587. text: "删除作品",
  588. icon: "../../static/icon/sy_icon_shanchu.png",
  589. danger: true,
  590. },
  591. ];
  592. }
  593. this.$refs.actionSheet.show();
  594. },
  595. handleActionCancel() {
  596. console.log("ActionSheet cancelled");
  597. },
  598. handleActionSelect(index, item) {
  599. console.log("ActionSheet selected index:", item.text);
  600. switch (item.text) {
  601. case "分享作品":
  602. console.log("分享作品");
  603. break;
  604. case "修改帖子":
  605. console.log("修改帖子");
  606. uni.navigateTo({
  607. url: "/pages/make/fabuArticle?id=" + this.fileInformation.id,
  608. });
  609. break;
  610. case "删除作品":
  611. console.log("删除作品");
  612. break;
  613. }
  614. },
  615. imageString(str) {
  616. if (!str) {
  617. return [];
  618. }
  619. return str.split("|");
  620. },
  621. cutTime(time) {
  622. if (!time) {
  623. return "";
  624. }
  625. return time.split(" ")[0];
  626. },
  627. },
  628. };
  629. </script>
  630. <style scoped lang="scss">
  631. @import "articleDetail.scss";
  632. </style>