articleDetail.vue 21 KB

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