workDetail.vue 15 KB

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