articleDetail.vue 18 KB

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