workDetail.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  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" @click="goToUserHomepage(author.id)">
  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="true"
  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. <!-- 灵感 -->
  51. <template v-if="articleInfo.task_type == 1">
  52. <view class="inspiration-content" v-if="home_image">
  53. <image
  54. v-if="home_image"
  55. src="../../static/makedetail/cz_img_zhanshi.png"
  56. mode="widthFix"
  57. ></image>
  58. <image
  59. :src="home_image"
  60. class="inspirationPictures"
  61. mode="widthFix"
  62. ></image>
  63. </view>
  64. </template>
  65. <!-- 音乐 -->
  66. <template v-else-if="articleInfo.task_type == 2">
  67. <view class="musicContentBox">
  68. <view class="headCard">
  69. <image :src="home_image" class="songCover"></image>
  70. <view class="songInfo">
  71. <view class="songTitle">{{ addBrackets(articleInfo.title) }}</view>
  72. <view class="songTag">
  73. <view
  74. class="tag"
  75. v-for="(item, index) in commaToArray(articleInfo.style)"
  76. :key="index + item"
  77. >{{ item }}</view
  78. >
  79. </view>
  80. </view>
  81. <template v-if="articleInfo.task_type == 2">
  82. <image
  83. @click="toggleAudio"
  84. v-if="isPlaying"
  85. src="@/static/makedetail/cz_icon_zanting.png"
  86. class="playerButton"
  87. ></image>
  88. <image
  89. @click="toggleAudio"
  90. v-else
  91. src="@/static/makedetail/cz_icon_bofang.png"
  92. class="playerButton"
  93. ></image>
  94. </template>
  95. </view>
  96. <view class="contentHeader">
  97. <view class="musicContent">
  98. <text> {{ articleInfo.lyrics }}</text>
  99. <image class="roll" src="@/static/icon/roll.png"></image>
  100. </view>
  101. <view class="maskLayer"></view>
  102. </view>
  103. </view>
  104. </template>
  105. <!-- 作品描述 -->
  106. <view class="workDescription">
  107. <view class="workDescription-title">
  108. <view>创作说明 </view>
  109. <!-- <image class="pen" src="@/static/icon/wd_icon_bianji.png"></image> -->
  110. </view>
  111. <view class="workDescription-content">
  112. {{ content || "暂无内容" }}
  113. </view>
  114. </view>
  115. <view class="goCreate" @click="goCreate()">去创作</view>
  116. <DialogBox ref="customConfirm"></DialogBox>
  117. <!-- 文章头图区域 -->
  118. <view class="topUser" v-if="false">
  119. <image :src="home_image" class="home_image" mode="aspectFill"></image>
  120. <!-- 图片指示器 -->
  121. <view class="image-indicator" v-if="image_list.length > 1">
  122. <text>{{ selImg + 1 }}/{{ image_list.length }}</text>
  123. </view>
  124. <!-- 音乐类型时显示歌词 -->
  125. <view class="lyrics-overlay" v-if="articleInfo.task_type == 2">
  126. <text class="lyrics-text">{{ articleInfo.lyrics }}</text>
  127. </view>
  128. <!-- 音乐类型时显示播放按钮 -->
  129. <view
  130. class="play-button"
  131. v-if="articleInfo.task_type == 2 && articleInfo.result_audio"
  132. @click="toggleAudio"
  133. >
  134. <text class="fa" :class="isPlaying ? 'fa-pause' : 'fa-play'"></text>
  135. </view>
  136. <!-- 缩略图列表 -->
  137. <view class="list">
  138. <view
  139. class="img"
  140. :class="selImg == index ? 'active' : ''"
  141. v-for="(item, index) in image_list"
  142. :key="index"
  143. @click="selPhoto(item, index)"
  144. >
  145. <image :src="item" mode="aspectFill"></image>
  146. </view>
  147. </view>
  148. </view>
  149. <!-- 音频元素 -->
  150. <audio
  151. id="audioPlayer"
  152. :src="articleInfo.result_audio"
  153. style="display: none"
  154. v-if="false"
  155. ></audio>
  156. <!-- 文章内容区域 -->
  157. <view class="body" v-if="false">
  158. <!-- 文章标题与元信息 -->
  159. <view class="article-header">
  160. <view class="title">
  161. {{ articleInfo.title || "暂无标题" }}
  162. </view>
  163. <view class="meta-info">
  164. <view class="meta-item">
  165. <text class="fa fa-calendar"></text>
  166. <text class="meta-text">{{
  167. articleInfo.create_time || "暂无时间"
  168. }}</text>
  169. </view>
  170. <view class="meta-item">
  171. <text class="fa fa-eye"></text>
  172. <text class="meta-text">{{ articleInfo.num_view || 0 }}次阅读</text>
  173. </view>
  174. <view class="meta-item" v-if="articleInfo.author">
  175. <text class="fa fa-user"></text>
  176. <text class="meta-text">{{ articleInfo.author }}</text>
  177. </view>
  178. </view>
  179. </view>
  180. <!-- 内容分隔线 -->
  181. <view class="divider"></view>
  182. <!-- 文章内容 -->
  183. <!-- <view class="article-content" v-if="articleInfo.type == 'user'">
  184. <view class="content">{{ articleInfo.content || '暂无内容' }}</view>
  185. </view> -->
  186. <view class="article-content">
  187. <view class="content">
  188. <!-- <rich-text :nodes="content" style="font-size: 14px"></rich-text> -->
  189. <uv-parse :content="articleInfo.content"></uv-parse>
  190. </view>
  191. </view>
  192. <!-- 文章底部区域 -->
  193. <view class="article-footer">
  194. <view class="action-bar">
  195. <view class="action-item" @tap="likeArticle">
  196. <text
  197. class="fa"
  198. :class="
  199. articleInfo.is_like ? 'fa-thumbs-up liked' : 'fa-thumbs-o-up'
  200. "
  201. ></text>
  202. <text class="action-text">{{ articleInfo.like_count || 0 }}</text>
  203. </view>
  204. <view class="action-item" @tap="openComment">
  205. <text class="fa fa-comment-o"></text>
  206. <text class="action-text">{{ tableTotal || 0 }}</text>
  207. </view>
  208. <view class="action-item" @tap="shareArticle">
  209. <text class="fa fa-share-alt"></text>
  210. <text class="action-text">分享</text>
  211. </view>
  212. </view>
  213. </view>
  214. <!-- 空白占位 -->
  215. <view class="list_info">
  216. <view class="blankHeight"></view>
  217. </view>
  218. </view>
  219. <!-- <view class="btn_submit" @click="chatTA()">
  220. <image class="icon" src="../../static/icon/icon_chat_white.png" mode="widthFix"></image>
  221. 私聊
  222. </view> -->
  223. <view class="thread2"></view>
  224. <view class="thread2"></view>
  225. <previewImage
  226. ref="previewImage"
  227. :opacity="0.8"
  228. :circular="true"
  229. :imgs="imgs"
  230. :descs="descs"
  231. ></previewImage>
  232. <!-- 评论区域 -->
  233. <CommentSection
  234. v-if="userInfo.id != 0&& articleInfo.title"
  235. ref="commentSection"
  236. :myInfo="myInfo"
  237. :userInfo="userInfo"
  238. :articleId="arcID"
  239. @totalNumberOfComments="totalNumberOfComments"
  240. articleInfo="articleInfo"
  241. ></CommentSection>
  242. <!-- 自定义 ActionSheet -->
  243. <ActionSheet
  244. ref="actionSheet"
  245. :items="items"
  246. @select="handleActionSelect"
  247. @cancel="handleActionCancel"
  248. />
  249. <view class="thread2"></view>
  250. </view>
  251. </template>
  252. <script>
  253. import htmlParser from "../../common/html-parser";
  254. import previewImage from "@/components/kxj-previewImage/kxj-previewImage.vue"; //引用插件
  255. import CommentSection from "@/components/CommentSection/CommentSection.vue";
  256. import ActionSheet from "@/components/ActionSheet/ActionSheet.vue";
  257. function parseImgs(nodes) {
  258. nodes.forEach((node) => {
  259. if (node.name === "img" && node.attrs && node.attrs["data-img-size-val"]) {
  260. const sizes = node.attrs["data-img-size-val"].split(",");
  261. const width = uni.upx2px(720 * 0.9);
  262. const height = parseInt(width * (sizes[1] / sizes[0]));
  263. node.attrs.style = `width:${width};height:${height};`;
  264. }
  265. if (Array.isArray(node.children)) {
  266. parseImgs(node.children);
  267. }
  268. });
  269. return nodes;
  270. }
  271. export default {
  272. components: {
  273. previewImage,
  274. CommentSection,
  275. ActionSheet,
  276. },
  277. data() {
  278. return {
  279. title: "",
  280. arcID: 0,
  281. selImg: 0,
  282. home_image: "",
  283. articleInfo: {},
  284. tag_list: [],
  285. image_list: [],
  286. imgs: [],
  287. descs: [],
  288. list_wish: [],
  289. content: "",
  290. author: {},
  291. // 添加文章信息字段
  292. articleInfo: {
  293. title: "",
  294. content: "",
  295. create_time: "",
  296. images: "",
  297. view_count: 0,
  298. author: "",
  299. like_count: 0,
  300. is_like: false,
  301. },
  302. items: [],
  303. myInfo: {
  304. user_id: getApp().globalData.user_id, // 用户id
  305. user_name: getApp().globalData.nickname, // 用户名
  306. user_avatar: getApp().globalData.avator, // 用户头像地址
  307. },
  308. // 文章作者信息(提示: 一般来自localstorage, 如果是实时获取的话, 那么获取到数据后再v-if显示评论组件)
  309. userInfo: {
  310. user_id: 0, // 用户id
  311. user_name: "", // 用户名
  312. user_avatar: "", // 用户头像地址
  313. },
  314. deleteMode: "all", //删除模式
  315. // 评论总数
  316. tableTotal: 4,
  317. // 评论表
  318. tableData: [],
  319. isPlaying: false, // 添加播放状态
  320. audioPlayer: null, // 添加音频播放器实例
  321. sms_id: 0,
  322. isMessage: true,
  323. };
  324. },
  325. onLoad(parms) {
  326. let self = this;
  327. this.arcID = parms.id
  328. if (parms.type == "sms") {
  329. this.isMessage = false;
  330. }
  331. if (parms.sms_id) {
  332. this.sms_id = parms.sms_id;
  333. }
  334. },
  335. onShow() {
  336. uni.$emit("check_update");
  337. this.loadData();
  338. this.$nextTick(() => {
  339. if (this.$refs.commentSection) {
  340. this.$refs.commentSection.loadCommentData();
  341. }
  342. });
  343. },
  344. onReady() {
  345. // 初始化音频播放器
  346. this.audioPlayer = uni.createInnerAudioContext();
  347. this.audioPlayer.onEnded(() => {
  348. this.isPlaying = false;
  349. });
  350. },
  351. onUnload() {
  352. // 页面卸载时停止音频播放
  353. if (this.audioPlayer) {
  354. this.audioPlayer.stop();
  355. this.audioPlayer.destroy();
  356. }
  357. },
  358. methods: {
  359. // 返回上一页
  360. goBack() {
  361. uni.navigateBack({
  362. delta: 1,
  363. });
  364. },
  365. totalNumberOfComments(tableTotal) {
  366. this.tableTotal = tableTotal;
  367. },
  368. onLinqu(item) {
  369. uni.navigateTo({
  370. url: "/pages/my/wishHelp?id=" + item.myid,
  371. });
  372. },
  373. selPhoto(item, sel) {
  374. this.selImg = sel;
  375. this.home_image = this.image_list[sel];
  376. },
  377. toArr(imgs) {
  378. let arr = imgs.split("|");
  379. return arr;
  380. },
  381. previewOpen(imgs1, index) {
  382. this.imgs = imgs1.split("|");
  383. setTimeout(() => this.$refs.previewImage.open(index), 0);
  384. // 传入当前选中的图片地址或序号
  385. return; //如需测试和uni原生预览差别可注释这两行
  386. },
  387. loadData() {
  388. uni.request({
  389. url: this.$apiHost + "/Work/getinfo",
  390. data: {
  391. uuid: getApp().globalData.uuid,
  392. id: this.arcID,
  393. },
  394. header: {
  395. "content-type": "application/json",
  396. sign: getApp().globalData.headerSign,
  397. },
  398. success: (res) => {
  399. console.log("文章信息:", res.data);
  400. if (res.data.success === "yes") {
  401. console.log("文章信息:", res.data.data);
  402. // 更新文章信息
  403. if (res.data.article) {
  404. this.articleInfo = res.data.article;
  405. }
  406. this.articleInfo = res.data.data;
  407. this.articleInfo.sms_id = this.sms_id;
  408. this.content = res.data.data.content;
  409. this.home_image = res.data.data.images;
  410. this.author = res.data.author;
  411. this.userInfo.user_id = res.data.id; // 用户id
  412. this.userInfo.user_name = res.data.nickname; // 用户名
  413. this.userInfo.user_avatar = res.data.avator; // 用户头像地址
  414. } else {
  415. uni.showToast({
  416. title: "获取信息失败",
  417. icon: "none",
  418. });
  419. }
  420. },
  421. complete: (com) => {
  422. // uni.hideLoading();
  423. },
  424. fail: (e) => {
  425. console.log("请求失败:", e);
  426. uni.showToast({
  427. title: "网络请求失败",
  428. icon: "none",
  429. });
  430. },
  431. });
  432. },
  433. // 唤起新评论弹框
  434. openComment() {
  435. if (this.$refs.commentSection) {
  436. this.$refs.commentSection.openComment();
  437. }
  438. },
  439. // 文章点赞
  440. likeArticle() {
  441. uni.request({
  442. url: this.$apiHost + "/Work/zanTA",
  443. data: {
  444. uuid: getApp().globalData.uuid,
  445. id: this.arcID,
  446. },
  447. header: {
  448. "content-type": "application/json",
  449. sign: getApp().globalData.headerSign,
  450. },
  451. success: (res) => {
  452. console.log("点赞结果:", res.data);
  453. if (res.data.success === "yes") {
  454. // 更新点赞状态
  455. if (!this.articleInfo.is_like) {
  456. this.articleInfo.like_count =
  457. (this.articleInfo.like_count || 0) + 1;
  458. this.articleInfo.is_like = true;
  459. uni.showToast({
  460. title: "点赞成功",
  461. icon: "none",
  462. });
  463. } else {
  464. this.articleInfo.like_count =
  465. (this.articleInfo.like_count || 0) - 1;
  466. this.articleInfo.is_like = false;
  467. uni.showToast({
  468. title: res.data.str,
  469. icon: "none",
  470. });
  471. }
  472. } else {
  473. uni.showToast({
  474. title: res.data.str,
  475. icon: "none",
  476. });
  477. }
  478. },
  479. fail: (e) => {
  480. console.log("点赞失败:", e);
  481. uni.showToast({
  482. title: "网络请求失败",
  483. icon: "none",
  484. });
  485. },
  486. });
  487. },
  488. // 关注作者
  489. followTheAuthor(n) {
  490. uni.request({
  491. url: this.$apiHost + "/Member/attention",
  492. data: {
  493. uuid: getApp().globalData.uuid,
  494. id: this.author.id,
  495. },
  496. header: {
  497. "content-type": "application/json",
  498. sign: getApp().globalData.headerSign,
  499. },
  500. success: (res) => {
  501. console.log("点赞结果:", res.data);
  502. uni.showToast({
  503. title: res.data.str,
  504. icon: "none",
  505. });
  506. if (res.data.success === "yes") {
  507. console.log("关注结果:", res.data, n);
  508. this.author.is_attention = n;
  509. }
  510. },
  511. fail: (e) => {
  512. console.log("关注失败:", e);
  513. uni.showToast({
  514. title: "网络请求失败",
  515. icon: "none",
  516. });
  517. },
  518. });
  519. },
  520. // 分享文章
  521. shareArticle() {
  522. // 如果在微信小程序环境
  523. if (uni.getSystemInfoSync().platform === "mp-weixin") {
  524. uni.showShareMenu({
  525. withShareTicket: true,
  526. menus: ["shareAppMessage", "shareTimeline"],
  527. });
  528. } else {
  529. // 其他环境,如APP
  530. uni.share({
  531. provider: "weixin",
  532. scene: "WXSceneSession",
  533. type: 0,
  534. title: this.articleInfo.title,
  535. summary: this.articleInfo.content.substring(0, 40) + "...",
  536. imageUrl: this.home_image,
  537. success: function (res) {
  538. console.log("分享成功:" + JSON.stringify(res));
  539. },
  540. fail: function (err) {
  541. console.log("分享失败:" + JSON.stringify(err));
  542. },
  543. });
  544. }
  545. },
  546. // 切换音频播放状态
  547. toggleAudio() {
  548. if (!this.articleInfo.result_audio) return;
  549. if (this.isPlaying) {
  550. this.audioPlayer.pause();
  551. this.isPlaying = false;
  552. } else {
  553. this.audioPlayer.src = this.articleInfo.result_audio;
  554. this.audioPlayer.play();
  555. this.isPlaying = true;
  556. }
  557. },
  558. // 新增过滤器方法
  559. commaToArray(str) {
  560. if (!str) return "";
  561. return str.split(",");
  562. },
  563. // 新增过滤器方法
  564. addBrackets(str) {
  565. if (!str) return "";
  566. if (!str.startsWith("《")) {
  567. str = "《" + str;
  568. }
  569. if (!str.endsWith("》")) {
  570. str = str + "》";
  571. }
  572. return str;
  573. },
  574. getInfoData() {
  575. uni.request({
  576. url: this.$apiHost + "/Member/getinfoData",
  577. data: {
  578. uuid: getApp().globalData.uuid,
  579. },
  580. header: {
  581. "content-type": "application/json",
  582. },
  583. success: (res) => {
  584. console.log("用户信息", res.data);
  585. },
  586. });
  587. },
  588. showActionSheet(n) {
  589. if (n == 0) {
  590. this.items = [
  591. {
  592. text: "分享作品",
  593. icon: "../../static/icon/cz_icon_fenxiangzuopin.png",
  594. },
  595. ];
  596. }
  597. if (n == 1) {
  598. this.items = [
  599. {
  600. text: "分享作品",
  601. icon: "../../static/icon/cz_icon_fenxiangzuopin.png",
  602. },
  603. {
  604. text: "修改封面",
  605. icon: "../../static/icon/cz_icon_xiugaifengmian.png",
  606. },
  607. {
  608. text: "删除作品",
  609. icon: "../../static/icon/sy_icon_shanchu.png",
  610. danger: true,
  611. },
  612. ];
  613. }
  614. this.$refs.actionSheet.show();
  615. },
  616. handleActionCancel() {
  617. console.log("ActionSheet cancelled");
  618. },
  619. handleActionSelect(index, item) {
  620. console.log("ActionSheet selected index:", item.text);
  621. },
  622. goCreate() {
  623. // 切换到标签页
  624. uni.switchTab({
  625. // 指定要切换到的页面路径
  626. url: "/pages/make/index",
  627. });
  628. },
  629. goToUserHomepage(id) {
  630. if (!id) {
  631. return;
  632. }
  633. uni.navigateTo({
  634. url: "/pages/my/userHomepage?id=" + id,
  635. });
  636. },
  637. },
  638. };
  639. </script>
  640. <style scoped lang="scss">
  641. @import "workDetail.scss";
  642. </style>