articleDetail.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  1. <template>
  2. <view class="page">
  3. <!-- 顶部导航栏 -->
  4. <view class="custom-navbar">
  5. <view class="navbar-left" @click="goBack">
  6. <text class="fa fa-angle-left"></text>
  7. </view>
  8. <view class="navbar-center">
  9. <view class="navbar-title" v-if="isMessage" @click="goToUserHomepage(author.id)">
  10. <image class="navbar-avatar" :src="author.avator" mode="aspectFill"></image>
  11. <text class="navbar-text">{{ author.nickname }}</text>
  12. <!-- <text class="navbar-badge" v-if="author.is_vip > 0">VIP</text> -->
  13. </view>
  14. </view>
  15. <view class="navbar-right">
  16. <template v-if="!isItMe">
  17. <text class="followTheAuthor followTheAuthor1" v-if="author.is_attention == 0"
  18. @click="followTheAuthor(1)">+关注</text>
  19. <text class="followTheAuthor followTheAuthor0" v-if="author.is_attention == 1"
  20. @click="followTheAuthor(0)">已关注</text>
  21. </template>
  22. <template v-if="isMessage">
  23. <image v-if="!isItMe" @click="showActionSheet(0)" src="@/static/icon/sy_icon_fenxiang.png"
  24. mode="widthFix"></image>
  25. <view v-else class="navbar-right" @click="showActionSheet(1)">
  26. <image src="@/static/icon/more2.png" style="width: 64rpx;height: 64rpx; margin-top: 15rpx;"
  27. mode="widthFix"></image>
  28. </view>
  29. </template>
  30. <image v-else @click="showActionSheet(2)" src="@/static/icon/sy_icon_fenxiang.png" mode="widthFix">
  31. </image>
  32. </view>
  33. </view>
  34. <view class="topStatusBar inProgress" v-if="articleInfo.status == 2">
  35. 审核中</view>
  36. <view class="topStatusBar fail" v-else-if="articleInfo.status == 3" @click="openConfirmationBox">
  37. 审核未通过,点击查看原因</view>
  38. <template v-if="isMessage">
  39. <!-- 轮播图部分 -->
  40. <uv-swiper class="swiper-box" height="1048rpx" :list="swperImages" indicator indicatorMode="dot"
  41. bgColor="#fff" :autoplay="false" @click="previewImage">
  42. </uv-swiper>
  43. <!-- 文章内容区域 -->
  44. <view class="body">
  45. <!-- 文章标题与元信息 -->
  46. <view class="article-header">
  47. <view class="title">
  48. {{ articleInfo.title || "暂无标题" }}
  49. </view>
  50. <view class="article-content">
  51. <view class="content">
  52. <!-- <rich-text :nodes="content" style="font-size: 14px"></rich-text> -->
  53. <uv-parse :content="articleInfo.content"></uv-parse>
  54. </view>
  55. </view>
  56. <view class="cardLink" v-if="workInfo.id" @click="goToDetails(workInfo.id)">
  57. <image :src="workInfo.images" mode="heightFix"></image>
  58. <view class="content">
  59. <view class="tit">{{ workInfo.title || "暂无标题" }}</view>
  60. <view class="tex">{{
  61. cutTime(workInfo.create_time) || "暂无时间"
  62. }}</view>
  63. </view>
  64. </view>
  65. <view v-if="false" class="meta-info">
  66. <view class="meta-item">
  67. <text class="fa fa-calendar"></text>
  68. <text class="meta-text">{{
  69. articleInfo.create_time || "暂无时间"
  70. }}</text>
  71. </view>
  72. <view class="meta-item">
  73. <text class="fa fa-eye"></text>
  74. <text class="meta-text">{{ articleInfo.num_view || 0 }}次阅读</text>
  75. </view>
  76. <view class="meta-item" v-if="articleInfo.author">
  77. <text class="fa fa-user"></text>
  78. <text class="meta-text">{{ articleInfo.author }}</text>
  79. </view>
  80. </view>
  81. </view>
  82. <!-- 文章底部区域 -->
  83. <view class="article-footer" v-if="false">
  84. <view class="action-bar">
  85. <view class="action-item" @tap="likeArticle">
  86. <text class="fa" :class="articleInfo.is_like ? 'fa-thumbs-up liked' : 'fa-thumbs-o-up'
  87. "></text>
  88. <text class="action-text">{{ articleInfo.like_count || 0 }}</text>
  89. </view>
  90. <view class="action-item" @tap="openComment">
  91. <text class="fa fa-comment-o"></text>
  92. <text class="action-text">{{ tableTotal || 0 }}</text>
  93. </view>
  94. <view class="action-item" @tap="shareArticle">
  95. <text class="fa fa-share-alt"></text>
  96. <text class="action-text">分享</text>
  97. </view>
  98. </view>
  99. </view>
  100. </view>
  101. <!-- <view class="btn_submit" @click="chatTA()">
  102. <image class="icon" src="../../static/icon/icon_chat_white.png" mode="widthFix"></image>
  103. 私聊
  104. </view> -->
  105. <previewImage ref="previewImage" :opacity="0.8" :circular="true" :imgs="imgs" :descs="descs"></previewImage>
  106. </template>
  107. <template v-else>
  108. <!-- <rich-text :nodes="content" style="font-size: 14px"></rich-text> -->
  109. <uv-parse :content="articleInfo.content"></uv-parse>
  110. </template>
  111. <block v-for="(item, idx) in articleInfo.content_images" :key="idx">
  112. <image class="intro-img" :src="item" mode="widthFix" />
  113. </block>
  114. <!-- 评论区域 -->
  115. <template v-if="articleInfo.status == 1">
  116. <CommentSection style="background: #fff; border-top: #F2F6F2 2rpx solid;" v-if="userInfo.id != 0"
  117. ref="commentSection" @totalNumberOfComments="totalNumberOfComments" :articleInfo="articleInfo"
  118. :myInfo="myInfo" :userInfo="userInfo" :author="author" :articleId="arcID" :type="'article'">
  119. </CommentSection>
  120. </template>
  121. <view class="thread2"></view>
  122. <!-- 自定义 ActionSheet -->
  123. <ActionSheet ref="actionSheet" :items="items" @select="handleActionSelect" @cancel="handleActionCancel" />
  124. <CustomPopup ref="confirmationBox">
  125. <view class="failureReason">
  126. <view class="title"> 审核未通关</view>
  127. <view class="reviewContent">
  128. <!-- {{ fileInformation.reason }} -->
  129. <uv-parse :content="articleInfo.reason"></uv-parse>
  130. </view>
  131. <view class="btn-box" @click="closeConfirmationBox">知道了</view>
  132. </view>
  133. </CustomPopup>
  134. <DialogBox ref="DialogBox"></DialogBox>
  135. <SharePopup :visible="showShare" :userId="userId" :share-title="shareTitle" :share-desc="shareDesc"
  136. :share-img="shareImg" view="makeDetail" @close="showShare = false" />
  137. </view>
  138. </template>
  139. <script>
  140. import htmlParser from "../../common/html-parser";
  141. import CommentSection from "@/components/CommentSection/CommentSection.vue";
  142. import previewImage from "@/components/kxj-previewImage/kxj-previewImage.vue"; //引用插件
  143. import CustomPopup from "@/components/CustomPopup/CustomPopup.vue";
  144. import SharePopup from "@/components/SharePopup/SharePopup.vue";
  145. function parseImgs(nodes) {
  146. nodes.forEach((node) => {
  147. if (node.name === "img" && node.attrs && node.attrs["data-img-size-val"]) {
  148. const sizes = node.attrs["data-img-size-val"].split(",");
  149. const width = uni.upx2px(720 * 0.9);
  150. const height = parseInt(width * (sizes[1] / sizes[0]));
  151. node.attrs.style = `width:${width};height:${height};`;
  152. }
  153. if (Array.isArray(node.children)) {
  154. parseImgs(node.children);
  155. }
  156. });
  157. return nodes;
  158. }
  159. export default {
  160. components: {
  161. previewImage,
  162. CommentSection,
  163. CustomPopup,
  164. SharePopup,
  165. },
  166. data() {
  167. return {
  168. swperImages: [],
  169. items: [],
  170. title: "",
  171. arcID: 0,
  172. selImg: 0,
  173. home_image: "",
  174. myinfo: {},
  175. tag_list: [],
  176. image_list: [],
  177. imgs: [],
  178. descs: [],
  179. list_wish: [],
  180. content: "",
  181. tableTotal: 0,
  182. author: {},
  183. // 添加文章信息字段
  184. articleInfo: {
  185. title: "",
  186. content: "",
  187. create_time: "",
  188. images: "",
  189. view_count: 0,
  190. author: "",
  191. like_count: 0,
  192. is_like: false,
  193. },
  194. workInfo: {},
  195. myInfo: {
  196. user_id: getApp().globalData.user_id, // 用户id
  197. user_name: getApp().globalData.nickname, // 用户名
  198. user_avatar: getApp().globalData.avator, // 用户头像地址
  199. },
  200. // 文章作者信息(提示: 一般来自localstorage, 如果是实时获取的话, 那么获取到数据后再v-if显示评论组件)
  201. userInfo: {
  202. user_id: 0, // 用户id
  203. user_name: "", // 用户名
  204. user_avatar: "", // 用户头像地址
  205. },
  206. isItMe: false,
  207. sms_id: 0,
  208. isMessage: true,
  209. showShare: false,
  210. shareTitle: "",
  211. shareDesc: "",
  212. shareImg: "",
  213. userId: 0,
  214. };
  215. },
  216. onLoad(parms) {
  217. let self = this;
  218. this.arcID = parms.id || 529;
  219. if (parms.type == "sms") {
  220. this.isMessage = false;
  221. }
  222. if (parms.sms_id) {
  223. this.sms_id = parms.sms_id;
  224. }
  225. },
  226. onShow() {
  227. uni.$emit("check_update");
  228. this.$nextTick(() => {
  229. if (this.$refs.commentSection) {
  230. this.$refs.commentSection.loadCommentData();
  231. }
  232. });
  233. this.loadData();
  234. },
  235. methods: {
  236. openConfirmationBox() {
  237. this.$refs.confirmationBox.open();
  238. },
  239. closeConfirmationBox() {
  240. this.$refs.confirmationBox.close();
  241. },
  242. // 返回上一页
  243. goBack() {
  244. uni.navigateBack({
  245. delta: 1,
  246. });
  247. },
  248. // 文章点赞
  249. likeArticle() {
  250. uni.request({
  251. url: this.$apiHost + "/Work/zanTA",
  252. data: {
  253. uuid: getApp().globalData.uuid,
  254. id: this.arcID,
  255. },
  256. header: {
  257. "content-type": "application/json",
  258. sign: getApp().globalData.headerSign,
  259. },
  260. success: (res) => {
  261. console.log("点赞结果:", res.data);
  262. if (res.data.success === "yes") {
  263. // 更新点赞状态
  264. if (!this.articleInfo.is_like) {
  265. this.articleInfo.like_count =
  266. (this.articleInfo.like_count || 0) + 1;
  267. this.articleInfo.is_like = true;
  268. uni.showToast({
  269. title: "点赞成功",
  270. icon: "none",
  271. });
  272. } else {
  273. this.articleInfo.like_count =
  274. (this.articleInfo.like_count || 0) - 1;
  275. this.articleInfo.is_like = false;
  276. uni.showToast({
  277. title: res.data.str,
  278. icon: "none",
  279. });
  280. }
  281. } else {
  282. uni.showToast({
  283. title: res.data.str,
  284. icon: "none",
  285. });
  286. }
  287. },
  288. fail: (e) => {
  289. console.log("点赞失败:", e);
  290. uni.showToast({
  291. title: "网络请求失败",
  292. icon: "none",
  293. });
  294. },
  295. });
  296. },
  297. // 关注作者
  298. followTheAuthor(n) {
  299. uni.$emit('check_login', () => {
  300. uni.request({
  301. url: this.$apiHost + "/Member/attention",
  302. data: {
  303. uuid: getApp().globalData.uuid,
  304. id: this.author.id,
  305. },
  306. header: {
  307. "content-type": "application/json",
  308. sign: getApp().globalData.headerSign,
  309. },
  310. success: (res) => {
  311. console.log("点赞结果:", res.data);
  312. uni.showToast({
  313. title: res.data.str,
  314. icon: "none",
  315. });
  316. if (res.data.success === "yes") {
  317. console.log("关注结果:", res.data, n);
  318. this.author.is_attention = n;
  319. }
  320. },
  321. fail: (e) => {
  322. console.log("关注失败:", e);
  323. uni.showToast({
  324. title: "网络请求失败",
  325. icon: "none",
  326. });
  327. },
  328. });
  329. })
  330. },
  331. totalNumberOfComments(tableTotal) {
  332. this.tableTotal = tableTotal;
  333. },
  334. onLinqu(item) {
  335. uni.navigateTo({
  336. url: "/pages/my/wishHelp?id=" + item.myid,
  337. });
  338. },
  339. selPhoto(item, sel) {
  340. this.selImg = sel;
  341. this.home_image = this.image_list[sel];
  342. },
  343. goToDetails(id) {
  344. console.log("goToDetails", id);
  345. uni.navigateTo({
  346. url: "/pages/index/workDetail?id=" + id,
  347. });
  348. console.log("goToDetails", id);
  349. },
  350. toArr(imgs) {
  351. let arr = imgs.split("|");
  352. return arr;
  353. },
  354. previewOpen(imgs1, index) {
  355. this.imgs = imgs1.split("|");
  356. setTimeout(() => this.$refs.previewImage.open(index), 0);
  357. return; //如需测试和uni原生预览差别可注释这两行
  358. },
  359. loadData() {
  360. uni.request({
  361. url: this.$apiHost + "/Article/getinfo",
  362. data: {
  363. uuid: getApp().globalData.uuid,
  364. id: this.arcID,
  365. },
  366. header: {
  367. "content-type": "application/json",
  368. sign: getApp().globalData.headerSign,
  369. },
  370. success: (res) => {
  371. console.log("文章信息:", res.data);
  372. if (res.data.success === "yes") {
  373. // 更新文章信息
  374. if (res.data.article) {
  375. this.articleInfo = res.data.article;
  376. }
  377. this.articleInfo.sms_id = this.sms_id;
  378. this.swperImages = this.imageString(res.data.article.images);
  379. console.log("swperImages", this.swperImages);
  380. this.userInfo.user_id = res.data.id; // 用户id
  381. this.userInfo.user_name = res.data.nickname; // 用户名
  382. this.userInfo.user_avatar = res.data.avator; // 用户头像地址
  383. this.author = res.data.author;
  384. this.workInfo = res.data.work_info;
  385. this.isItMe =
  386. res.data.article.userID == getApp().globalData.user_id ?
  387. true :
  388. false;
  389. // 更新分享相关数据
  390. this.shareTitle = this.articleInfo.title || '萌创星球';
  391. this.shareDesc = this.articleInfo.content;
  392. this.shareImg = this.articleInfo.images;
  393. this.userId = this.articleInfo.userID;
  394. this.articleInfo.content_images = this.articleInfo.content_images.split('|') || [];
  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({
  467. params
  468. }, callback) {
  469. // params = {
  470. // ...params,
  471. // user_id: this.myInfo.user_id, // 用户id
  472. // user_name: this.myInfo.user_name, // 用户名
  473. // user_avatar: this.myInfo.user_avatar, // 用户头像地址
  474. // user_content: this.commentValue, // 用户评论内容
  475. // is_like: false, // 是否点赞
  476. // like_count: 0, // 点赞数统计
  477. // create_time: "刚刚", // 创建时间
  478. // owner: true, // 是否为所有者 所有者可以进行删除 管理员默认true
  479. // };
  480. console.log("replyFun", {
  481. uuid: getApp().globalData.uuid,
  482. article_id: this.arcID, // 文章ID
  483. content: params.user_content, // 评论内容
  484. parent_id: params.parent_id || 0, // 父评论ID
  485. reply_id: params.reply_id || 0, // 回复的评论ID
  486. reply_name: params.reply_name || "", // 被回复人名称
  487. });
  488. uni.request({
  489. url: this.$apiHost + "/Article/newComment",
  490. data: {
  491. uuid: getApp().globalData.uuid,
  492. type: "article",
  493. article_id: this.arcID, // 文章ID
  494. content: params.user_content, // 评论内容
  495. parent_id: params.parent_id || 0, // 父评论ID
  496. reply_id: params.reply_id || 0, // 回复的评论ID
  497. reply_name: params.reply_name || "", // 被回复人名称
  498. },
  499. header: {
  500. "content-type": "application/json",
  501. sign: getApp().globalData.headerSign,
  502. },
  503. success: (res) => {
  504. console.log("评论结果:", res.data);
  505. if (res.data.success === "yes") {
  506. callback(res.data); // 评论成功,传入后端返回的数据
  507. }
  508. },
  509. fail: (e) => {
  510. console.log("评论失败:", e);
  511. uni.showToast({
  512. title: "评论失败,请重试",
  513. icon: "none",
  514. });
  515. },
  516. });
  517. },
  518. /** 删除回调事件
  519. * mode 删除模式
  520. * -- bind: 当被删除的一级评论存在回复评论, 那么该评论内容变更显示为[当前评论内容已被移除]
  521. * -- only: 仅删除当前评论(后端删除相关联的回复评论, 否则总数显示不对)
  522. * -- all : 删除所有评论包括回复评论 前端遍历子评论上报
  523. */
  524. deleteFun({
  525. params,
  526. mode
  527. }, callback) {
  528. console.log("deleteFun", {
  529. params,
  530. mode,
  531. });
  532. // 将params转换为逗号分隔的字符串
  533. const idsString = Array.isArray(params) ?
  534. params.join(",") :
  535. params.toString();
  536. console.log("删除评论", idsString, mode);
  537. uni.request({
  538. url: this.$apiHost + "/Article/delComment",
  539. data: {
  540. uuid: getApp().globalData.uuid,
  541. ids: idsString, // 将params转换为逗号分隔的字符串传递给ids
  542. mode: mode,
  543. },
  544. header: {
  545. "content-type": "application/json",
  546. sign: getApp().globalData.headerSign,
  547. },
  548. success: (res) => {
  549. console.log("删除结果:", res.data);
  550. if (res.data.success === "yes") {
  551. callback(res);
  552. }
  553. },
  554. fail: (e) => {},
  555. });
  556. // switch (mode) {
  557. // case "bind":
  558. // // 逻辑: 调用接口进行评论内容修改 update
  559. // setTimeout(() => callback(), 500); // 目前为了展示效果, 直接执行callback
  560. // break;
  561. // case "only":
  562. // // 逻辑: 调用接口删除一个评论 delete
  563. // setTimeout(() => callback(), 500); // 目前为了展示效果, 直接执行callback
  564. // break;
  565. // default:
  566. // // all
  567. // // 逻辑: 调用接口删除多个评论 [delete]
  568. // setTimeout(() => callback(), 500); // 目前为了展示效果, 直接执行callback
  569. // break;
  570. // }
  571. },
  572. showActionSheet(n) {
  573. uni.$emit('check_login', () => {
  574. if (n == 0) {
  575. // this.items = [
  576. // {
  577. // text: "分享作品",
  578. // icon: "../../static/icon/cz_icon_fenxiangzuopin.png",
  579. // },
  580. // ];
  581. // 如果只有一个分享按钮,直接唤醒分享弹窗
  582. this.showShare = true;
  583. return;
  584. }
  585. if (n == 1) {
  586. this.items = [{
  587. text: "分享作品",
  588. icon: "../../static/icon/cz_icon_fenxiangzuopin.png",
  589. },
  590. {
  591. text: "修改帖子",
  592. icon: "../../static/icon/cz_icon_xiugaifengmian.png",
  593. },
  594. {
  595. text: "举报",
  596. icon: "../../static/icon/jubao.png",
  597. },
  598. {
  599. text: "删除作品",
  600. icon: "../../static/icon/sy_icon_shanchu.png",
  601. danger: true,
  602. },
  603. ];
  604. }
  605. if (n == 2) {
  606. // this.items = [
  607. // {
  608. // text: "分享消息",
  609. // icon: "../../static/icon/cz_icon_fenxiangzuopin.png",
  610. // },
  611. // ];
  612. // 如果只有一个分享按钮,直接唤醒分享弹窗
  613. this.showShare = true;
  614. return;
  615. }
  616. this.$refs.actionSheet.show();
  617. })
  618. },
  619. handleActionCancel() {
  620. console.log("ActionSheet cancelled");
  621. },
  622. handleActionSelect(index, item) {
  623. console.log("ActionSheet selected index:", item.text);
  624. if (item.text === "分享作品") {
  625. this.showShare = true;
  626. } else if (item.text === "修改帖子") {
  627. uni.navigateTo({
  628. url: "/pages/make/fabuArticle?id=" + this.articleInfo.id,
  629. });
  630. } else if (item.text === "删除作品") {
  631. this.deleteArticle();
  632. } else if (item.text === "举报") {
  633. this.handleReport();
  634. }
  635. },
  636. handleReport() {
  637. // 实现举报功能
  638. uni.$emit('check_login', () => {
  639. uni.navigateTo({
  640. url: '/pages/my/feedback'
  641. })
  642. })
  643. },
  644. imageString(str) {
  645. if (!str) {
  646. return [];
  647. }
  648. return str.split("|");
  649. },
  650. cutTime(time) {
  651. if (!time) {
  652. return "";
  653. }
  654. return time.split(" ")[0];
  655. },
  656. deleteArticle() {
  657. this.$refs["DialogBox"]
  658. .confirm({
  659. title: "提示",
  660. content: "确定删除该文章吗",
  661. DialogType: "inquiry",
  662. btn1: "取消",
  663. btn2: "确定",
  664. animation: 0,
  665. })
  666. .then(() => {
  667. uni.showLoading({
  668. title: '删除中...'
  669. });
  670. uni.request({
  671. url: this.$apiHost + "/Article/doAct",
  672. data: {
  673. uuid: getApp().globalData.uuid,
  674. act: "del",
  675. id: this.articleInfo.id,
  676. },
  677. header: {
  678. "content-type": "application/json",
  679. sign: getApp().globalData.headerSign,
  680. },
  681. success: (res) => {
  682. uni.hideLoading();
  683. if (res.data.success === "yes") {
  684. uni.showToast({
  685. title: "删除成功",
  686. icon: "success",
  687. });
  688. // 删除成功后返回上一页
  689. setTimeout(() => {
  690. uni.navigateBack({
  691. delta: 1
  692. });
  693. }, 1500);
  694. } else {
  695. uni.showToast({
  696. title: res.data.str || "删除失败",
  697. icon: "none",
  698. });
  699. }
  700. },
  701. fail: () => {
  702. uni.hideLoading();
  703. uni.showToast({
  704. title: "删除失败",
  705. icon: "none",
  706. });
  707. }
  708. });
  709. })
  710. .catch(() => {
  711. // 用户取消删除
  712. });
  713. },
  714. goToUserHomepage(id) {
  715. uni.$emit('check_login', () => {
  716. if (!id) {
  717. return;
  718. }
  719. uni.navigateTo({
  720. url: "/pages/my/userHomepage?id=" + id,
  721. });
  722. })
  723. },
  724. // 预览图片
  725. previewImage(index) {
  726. if (!this.swperImages || this.swperImages.length === 0) return;
  727. uni.previewImage({
  728. urls: this.swperImages,
  729. current: index,
  730. indicator: 'number',
  731. loop: true,
  732. showmenu: false
  733. });
  734. },
  735. },
  736. };
  737. </script>
  738. <style scoped lang="scss">
  739. @import "articleDetail.scss";
  740. </style>