workDetail.vue 18 KB

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