workDetail.vue 15 KB

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