workDetail.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  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 v-if="showRights" class="permission-tip">
  10. <text class="permission-title">正在获取相机、存储权限</text>
  11. <text class="permission-desc">该权限用于获取设备拍摄或获取本地应用相册,进行头像或图片上传。</text>
  12. </view>
  13. <!-- 顶部导航栏 -->
  14. <view class="custom-navbar">
  15. <view class="navbar-left" @click="goBack">
  16. <text class="fa fa-angle-left"></text>
  17. </view>
  18. <view class="navbar-center">
  19. <view class="navbar-title" @click="goToUserHomepage(author.id)">
  20. <image class="navbar-avatar" :src="author.avator" mode="aspectFill"></image>
  21. <text class="navbar-text">{{ author.nickname }}</text>
  22. <!-- <text class="navbar-badge" v-if="author.is_vip > 0">VIP</text> -->
  23. </view>
  24. </view>
  25. <view class="navbar-right">
  26. <template v-if="!isItMe">
  27. <text class="followTheAuthor followTheAuthor1" v-if="author.is_attention == 0"
  28. @click="() => followTheAuthor(1)">+关注</text>
  29. <text class="followTheAuthor followTheAuthor0" v-if="author.is_attention == 1"
  30. @click="followTheAuthor(0)">已关注</text>
  31. </template>
  32. <image v-if="!isItMe" @click="showActionSheet(0)" src="../../static/icon/sy_icon_fenxiang.png" mode="widthFix">
  33. </image>
  34. <view v-else class="navbar-right" @click="showActionSheet(1)">
  35. <image src="@/static/icon/more2.png" style="width: 64rpx;height: 64rpx; margin-top: 15rpx;" mode="widthFix"></image>
  36. </view>
  37. </view>
  38. </view>
  39. <!-- 灵感 -->
  40. <template v-if="articleInfo.task_type == 1">
  41. <view class="inspiration-content" v-if="home_image">
  42. <image v-if="home_image" :src="home_image" class="inspirationPictures" mode="widthFix" @click="previewImage(home_image)"></image>
  43. </view>
  44. </template>
  45. <!-- 音乐 -->
  46. <template v-else-if="articleInfo.task_type == 2">
  47. <view class="musicContentBox">
  48. <view class="headCard">
  49. <image :src="home_image" class="songCover"></image>
  50. <view class="songInfo">
  51. <view class="songTitle">{{ addBrackets(articleInfo.title) }}</view>
  52. <view class="songTag">
  53. <view class="tag" v-for="(item, index) in commaToArray(articleInfo.style)" :key="index + item">{{ item }}
  54. </view>
  55. </view>
  56. </view>
  57. <template v-if="articleInfo.task_type == 2">
  58. <image @click="toggleAudio" v-if="isPlaying" src="@/static/makedetail/cz_icon_zanting.png"
  59. class="playerButton"></image>
  60. <image @click="toggleAudio" v-else src="@/static/makedetail/cz_icon_bofang.png" class="playerButton">
  61. </image>
  62. </template>
  63. </view>
  64. <view class="contentHeader">
  65. <view class="musicContent">
  66. <text style="display: inline-block; max-width: 350rpx;" > {{ articleInfo.lyrics }}</text>
  67. <image class="roll" src="@/static/icon/roll.png"></image>
  68. </view>
  69. <view class="maskLayer"></view>
  70. </view>
  71. </view>
  72. </template>
  73. <!-- 视频类型 -->
  74. <template v-else-if="articleInfo.task_type == 3">
  75. <view class="video-content">
  76. <video-player
  77. :src="articleInfo.video_url"
  78. :controls="true"
  79. :autoplay="false"
  80. :poster="home_image"
  81. :show-center-play-btn="true"
  82. :enable-progress-gesture="true"
  83. :show-fullscreen-btn="true"
  84. :show-play-btn="true"
  85. :object-fit="'contain'"
  86. @play="handleVideoPlay"
  87. @pause="handleVideoPause"
  88. @ended="handleVideoEnded"
  89. :videoStyle="{ width: '100%', height: '1000rpx' }"
  90. />
  91. <!-- <video-player
  92. src="https://media.w3.org/2010/05/sintel/trailer.mp4"
  93. :controls="true"
  94. :autoplay="false"
  95. :poster="home_image"
  96. :show-center-play-btn="true"
  97. :enable-progress-gesture="true"
  98. :show-fullscreen-btn="true"
  99. :show-play-btn="true"
  100. :object-fit="'contain'"
  101. @play="handleVideoPlay"
  102. @pause="handleVideoPause"
  103. @ended="handleVideoEnded"
  104. :videoStyle="{ width: '100%', height: '400rpx' }"
  105. />-->
  106. </view>
  107. </template>
  108. <!-- 作品描述 -->
  109. <view class="workDescription">
  110. <view class="workDescription-title">
  111. <view>创作说明 </view>
  112. <!-- <image class="pen" src="@/static/icon/wd_icon_bianji.png"></image> -->
  113. </view>
  114. <view class="workDescription-content">
  115. {{ content || "暂无内容" }}
  116. </view>
  117. </view>
  118. <view class="goCreate blick-btn-animation" @click="goCreate()">去创作</view>
  119. <DialogBox ref="customConfirm"></DialogBox>
  120. <!-- 文章头图区域 -->
  121. <view class="topUser" v-if="false">
  122. <image :src="home_image" class="home_image" mode="aspectFill"></image>
  123. <!-- 图片指示器 -->
  124. <view class="image-indicator" v-if="image_list.length > 1">
  125. <text>{{ selImg + 1 }}/{{ image_list.length }}</text>
  126. </view>
  127. <!-- 音乐类型时显示歌词 -->
  128. <view class="lyrics-overlay" v-if="articleInfo.task_type == 2">
  129. <text class="lyrics-text">{{ articleInfo.lyrics }}</text>
  130. </view>
  131. <!-- 音乐类型时显示播放按钮 -->
  132. <view class="play-button" v-if="articleInfo.task_type == 2 && articleInfo.result_audio" @click="toggleAudio">
  133. <text class="fa" :class="isPlaying ? 'fa-pause' : 'fa-play'"></text>
  134. </view>
  135. <!-- 缩略图列表 -->
  136. <view class="list">
  137. <view class="img" :class="selImg == index ? 'active' : ''" v-for="(item, index) in image_list" :key="index"
  138. @click="selPhoto(item, index)">
  139. <image :src="item" mode="aspectFill"></image>
  140. </view>
  141. </view>
  142. </view>
  143. <!-- 音频元素 -->
  144. <audio id="audioPlayer" :src="articleInfo.result_audio" style="display: none" v-if="false"></audio>
  145. <!-- <view class="btn_submit" @click="chatTA()">
  146. <image class="icon" src="../../static/icon/icon_chat_white.png" mode="widthFix"></image>
  147. 私聊
  148. </view> -->
  149. <view class="thread2"></view>
  150. <view class="thread2"></view>
  151. <previewImage ref="previewImage" :opacity="0.8" :circular="true" :imgs="imgs" :descs="descs"></previewImage>
  152. <!-- 评论区域 -->
  153. <CommentSection style="background: #fff; border-top-left-radius: 32rpx; border-top-right-radius: 32rpx;" v-if="userInfo.id != 0 && articleInfo.title" ref="commentSection" :myInfo="myInfo"
  154. :userInfo="userInfo" :articleId="arcID" @totalNumberOfComments="totalNumberOfComments" :articleInfo="articleInfo" :author="author" find="work">
  155. </CommentSection>
  156. <!-- 自定义 ActionSheet -->
  157. <ActionSheet ref="actionSheet" :items="items" @select="handleActionSelect" @cancel="handleActionCancel" />
  158. <view class="thread2"></view>
  159. <SharePopup :visible="showShare" :userId="userId" :share-title="shareTitle" :share-desc="shareDesc"
  160. :share-img="shareImg" view="workDetail" @close="showShare = false" />
  161. </view>
  162. </template>
  163. <script>
  164. import htmlParser from "../../common/html-parser";
  165. import previewImage from "@/components/kxj-previewImage/kxj-previewImage.vue"; //引用插件
  166. import CommentSection from "@/components/CommentSection/CommentSection.vue";
  167. import ActionSheet from "@/components/ActionSheet/ActionSheet.vue";
  168. import SharePopup from "@/components/SharePopup/SharePopup.vue";
  169. import VideoPlayer from "@/components/VideoPlayer/VideoPlayer.vue";
  170. import permission from '@/common/permission.js';
  171. function parseImgs(nodes) {
  172. nodes.forEach((node) => {
  173. if (node.name === "img" && node.attrs && node.attrs["data-img-size-val"]) {
  174. const sizes = node.attrs["data-img-size-val"].split(",");
  175. const width = uni.upx2px(720 * 0.9);
  176. const height = parseInt(width * (sizes[1] / sizes[0]));
  177. node.attrs.style = `width:${width};height:${height};`;
  178. }
  179. if (Array.isArray(node.children)) {
  180. parseImgs(node.children);
  181. }
  182. });
  183. return nodes;
  184. }
  185. export default {
  186. components: {
  187. previewImage,
  188. CommentSection,
  189. ActionSheet,
  190. SharePopup,
  191. VideoPlayer
  192. },
  193. data() {
  194. return {
  195. title: "",
  196. arcID: 0,
  197. selImg: 0,
  198. home_image: "",
  199. tag_list: [],
  200. image_list: [],
  201. imgs: [],
  202. descs: [],
  203. list_wish: [],
  204. content: "",
  205. author: {},
  206. showShare: false,
  207. shareTitle: "",
  208. shareDesc: "",
  209. shareImg: "",
  210. userId: 0,
  211. // 添加文章信息字段
  212. articleInfo: {
  213. title: "",
  214. content: "",
  215. create_time: "",
  216. images: "",
  217. view_count: 0,
  218. author: "",
  219. like_count: 0,
  220. is_like: false,
  221. },
  222. items: [],
  223. myInfo: {
  224. user_id: getApp().globalData.user_id, // 用户id
  225. user_name: getApp().globalData.nickname, // 用户名
  226. user_avatar: getApp().globalData.avator, // 用户头像地址
  227. },
  228. // 文章作者信息(提示: 一般来自localstorage, 如果是实时获取的话, 那么获取到数据后再v-if显示评论组件)
  229. userInfo: {
  230. user_id: 0, // 用户id
  231. user_name: "", // 用户名
  232. user_avatar: "", // 用户头像地址
  233. },
  234. deleteMode: "all", //删除模式
  235. // 评论总数
  236. tableTotal: 4,
  237. // 评论表
  238. tableData: [],
  239. isPlaying: false, // 添加播放状态
  240. audioPlayer: null, // 添加音频播放器实例
  241. sms_id: 0,
  242. isMessage: true,
  243. isItMe: false,
  244. showRights: false,
  245. };
  246. },
  247. onLoad(parms) {
  248. let self = this;
  249. this.arcID = parms.id
  250. if (parms.type == "sms") {
  251. this.isMessage = false;
  252. }
  253. if (parms.sms_id) {
  254. this.sms_id = parms.sms_id;
  255. }
  256. },
  257. onShow() {
  258. uni.$emit("check_update");
  259. this.loadData();
  260. this.$nextTick(() => {
  261. if (this.$refs.commentSection) {
  262. this.$refs.commentSection.loadCommentData();
  263. }
  264. });
  265. },
  266. onReady() {
  267. // 初始化音频播放器
  268. this.audioPlayer = uni.createInnerAudioContext();
  269. this.audioPlayer.onEnded(() => {
  270. this.isPlaying = false;
  271. });
  272. },
  273. onUnload() {
  274. // 页面卸载时停止音频播放
  275. if (this.audioPlayer) {
  276. this.audioPlayer.stop();
  277. this.audioPlayer.destroy();
  278. }
  279. },
  280. methods: {
  281. // 返回上一页
  282. goBack() {
  283. uni.navigateBack({
  284. delta: 1,
  285. });
  286. },
  287. totalNumberOfComments(tableTotal) {
  288. this.tableTotal = tableTotal;
  289. },
  290. onLinqu(item) {
  291. uni.navigateTo({
  292. url: "/pages/my/wishHelp?id=" + item.myid,
  293. });
  294. },
  295. selPhoto(item, sel) {
  296. this.selImg = sel;
  297. this.home_image = this.image_list[sel];
  298. },
  299. toArr(imgs) {
  300. let arr = imgs.split("|");
  301. return arr;
  302. },
  303. previewOpen(imgs1, index) {
  304. this.imgs = imgs1.split("|");
  305. setTimeout(() => this.$refs.previewImage.open(index), 0);
  306. // 传入当前选中的图片地址或序号
  307. return; //如需测试和uni原生预览差别可注释这两行
  308. },
  309. loadData() {
  310. uni.request({
  311. url: this.$apiHost + "/Work/getinfo",
  312. data: {
  313. uuid: getApp().globalData.uuid,
  314. id: this.arcID,
  315. },
  316. header: {
  317. "content-type": "application/json",
  318. sign: getApp().globalData.headerSign,
  319. },
  320. success: (res) => {
  321. console.log("文章信息:", res.data);
  322. if (res.data.success === "yes") {
  323. console.log("文章信息:", res.data.data);
  324. // 更新文章信息
  325. this.articleInfo = res.data.data;
  326. if (res.data.data&&res.data.data.video_url) {
  327. this.articleInfo.task_type = 3
  328. }
  329. if (res.data.article) {
  330. this.articleInfo = res.data.article;
  331. }
  332. this.articleInfo.sms_id = this.sms_id;
  333. this.content = res.data.data.content;
  334. this.home_image = res.data.data.images;
  335. this.author = res.data.author;
  336. // 更新分享相关数据
  337. this.shareTitle = this.articleInfo.title || '萌创星球';
  338. this.shareDesc = this.articleInfo.content;
  339. this.shareImg = this.home_image;
  340. this.userId =res.data.author.id;
  341. this.isItMe = res.data.author.id == getApp().globalData.user_id
  342. ? true
  343. : false;
  344. this.userInfo.user_id = res.data.id; // 用户id
  345. this.userInfo.user_name = res.data.nickname; // 用户名
  346. this.userInfo.user_avatar = res.data.avator; // 用户头像地址
  347. } else {
  348. uni.showToast({
  349. title: "获取信息失败",
  350. icon: "none",
  351. });
  352. }
  353. },
  354. complete: (com) => {
  355. // uni.hideLoading();
  356. },
  357. fail: (e) => {
  358. console.log("请求失败:", e);
  359. uni.showToast({
  360. title: "网络请求失败",
  361. icon: "none",
  362. });
  363. },
  364. });
  365. },
  366. // 唤起新评论弹框
  367. openComment() {
  368. if (this.$refs.commentSection) {
  369. this.$refs.commentSection.openComment();
  370. }
  371. },
  372. // 文章点赞
  373. likeArticle() {
  374. uni.request({
  375. url: this.$apiHost + "/Work/like",
  376. data: {
  377. uuid: getApp().globalData.uuid,
  378. id: this.arcID,
  379. },
  380. header: {
  381. "content-type": "application/json",
  382. sign: getApp().globalData.headerSign,
  383. },
  384. success: (res) => {
  385. console.log("点赞结果:", res.data);
  386. if (res.data.success === "yes") {
  387. // 更新点赞状态
  388. if (!this.articleInfo.is_like) {
  389. this.articleInfo.like_count =
  390. (this.articleInfo.like_count || 0) + 1;
  391. this.articleInfo.is_like = true;
  392. uni.showToast({
  393. title: "点赞成功",
  394. icon: "none",
  395. });
  396. } else {
  397. this.articleInfo.like_count =
  398. (this.articleInfo.like_count || 0) - 1;
  399. this.articleInfo.is_like = false;
  400. uni.showToast({
  401. title: res.data.str,
  402. icon: "none",
  403. });
  404. }
  405. } else {
  406. uni.showToast({
  407. title: res.data.str,
  408. icon: "none",
  409. });
  410. }
  411. },
  412. fail: (e) => {
  413. console.log("点赞失败:", e);
  414. uni.showToast({
  415. title: "网络请求失败",
  416. icon: "none",
  417. });
  418. },
  419. });
  420. },
  421. // 关注作者
  422. followTheAuthor(n) {
  423. uni.$emit('check_login', () => {
  424. uni.request({
  425. url: this.$apiHost + "/Member/attention",
  426. data: {
  427. uuid: getApp().globalData.uuid,
  428. id: this.author.id,
  429. },
  430. header: {
  431. "content-type": "application/json",
  432. sign: getApp().globalData.headerSign,
  433. },
  434. success: (res) => {
  435. console.log("点赞结果:", res.data);
  436. uni.showToast({
  437. title: res.data.str,
  438. icon: "none",
  439. });
  440. if (res.data.success === "yes") {
  441. console.log("关注结果:", res.data, n);
  442. this.author.is_attention = n;
  443. }
  444. },
  445. fail: (e) => {
  446. console.log("关注失败:", e);
  447. uni.showToast({
  448. title: "网络请求失败",
  449. icon: "none",
  450. });
  451. },
  452. });
  453. })
  454. },
  455. // 分享文章
  456. shareArticle() {
  457. // 如果在微信小程序环境
  458. if (uni.getSystemInfoSync().platform === "mp-weixin") {
  459. uni.showShareMenu({
  460. withShareTicket: true,
  461. menus: ["shareAppMessage", "shareTimeline"],
  462. });
  463. } else {
  464. // 其他环境,如APP
  465. uni.share({
  466. provider: "weixin",
  467. scene: "WXSceneSession",
  468. type: 0,
  469. title: this.articleInfo.title,
  470. summary: this.articleInfo.content.substring(0, 40) + "...",
  471. imageUrl: this.home_image,
  472. success: function (res) {
  473. console.log("分享成功:" + JSON.stringify(res));
  474. },
  475. fail: function (err) {
  476. console.log("分享失败:" + JSON.stringify(err));
  477. },
  478. });
  479. }
  480. },
  481. // 切换音频播放状态
  482. toggleAudio() {
  483. if (!this.articleInfo.result_audio) return;
  484. if (this.isPlaying) {
  485. this.audioPlayer.pause();
  486. this.isPlaying = false;
  487. } else {
  488. this.audioPlayer.src = this.articleInfo.result_audio;
  489. this.audioPlayer.play();
  490. this.isPlaying = true;
  491. }
  492. },
  493. // 新增过滤器方法
  494. commaToArray(str) {
  495. if (!str) return "";
  496. return str.split(",");
  497. },
  498. // 新增过滤器方法
  499. addBrackets(str) {
  500. if (!str) return "";
  501. if (!str.startsWith("《")) {
  502. str = "《" + str;
  503. }
  504. if (!str.endsWith("》")) {
  505. str = str + "》";
  506. }
  507. return str;
  508. },
  509. getInfoData() {
  510. uni.request({
  511. url: this.$apiHost + "/Member/getinfoData",
  512. data: {
  513. uuid: getApp().globalData.uuid,
  514. },
  515. header: {
  516. "content-type": "application/json",
  517. },
  518. success: (res) => {
  519. console.log("用户信息", res.data);
  520. },
  521. });
  522. },
  523. showActionSheet(n) {
  524. uni.$emit('check_login', () => {
  525. if (n == 0) {
  526. // 如果只有一个分享按钮,直接唤醒分享弹窗
  527. this.showShare = true;
  528. return;
  529. }
  530. if (n == 1) {
  531. this.items = [
  532. {
  533. text: "分享作品",
  534. icon: "../../static/icon/cz_icon_fenxiangzuopin.png",
  535. },
  536. // {
  537. // text: "修改封面",
  538. // icon: "../../static/icon/cz_icon_xiugaifengmian.png",
  539. // },
  540. {
  541. text: "举报",
  542. icon: "../../static/icon/jubao.png",
  543. },
  544. {
  545. text: "删除作品",
  546. icon: "../../static/icon/sy_icon_shanchu.png",
  547. danger: true,
  548. },
  549. ];
  550. }
  551. this.$refs.actionSheet.show();
  552. })
  553. },
  554. handleActionCancel() {
  555. console.log("ActionSheet cancelled");
  556. },
  557. handleActionSelect(index, item) {
  558. console.log("ActionSheet selected index:", item.text);
  559. if (item.text === "分享作品") {
  560. this.showShare = true;
  561. } else if (item.text === "修改封面") {
  562. // 修改封面
  563. if (this.articleInfo.status == 3) {
  564. uni.showToast({
  565. title: '作品已完成,无法修改封面!',
  566. icon: 'none'
  567. });
  568. return;
  569. }
  570. this.editCover();
  571. } else if (item.text === "删除作品") {
  572. // 删除作品
  573. this.deleteWork();
  574. } else if (item.text === "举报") {
  575. this.handleReport();
  576. }
  577. },
  578. handleReport() {
  579. // 实现举报功能
  580. uni.$emit('check_login', () => {
  581. uni.navigateTo({
  582. url: '/pages/my/feedback'
  583. })
  584. })
  585. },
  586. // 修改封面
  587. editCover() {
  588. uni.showActionSheet({
  589. itemList: ['拍照', '从相册选择'],
  590. success: (res) => {
  591. const sourceType = res.tapIndex === 0 ? 'camera' : 'album';
  592. this.chooseImage(sourceType);
  593. }
  594. });
  595. },
  596. // 删除作品
  597. deleteWork() {
  598. this.$refs["customConfirm"]
  599. .confirm({
  600. title: "确认删除",
  601. content: "确定要删除这个作品吗?",
  602. DialogType: "inquiry",
  603. btn1: "再考虑一下",
  604. btn2: "确认解绑",
  605. animation: 0,
  606. })
  607. .then((res) => {
  608. if (res.confirm) {
  609. // 用户点击确定,执行删除操作
  610. this.confirmDelete();
  611. }
  612. });
  613. },
  614. // 确认删除
  615. confirmDelete() {
  616. uni.showLoading({
  617. title: '删除中...'
  618. });
  619. uni.request({
  620. url: this.$apiHost + '/Work/doAct',
  621. method: 'GET',
  622. data: {
  623. uuid: getApp().globalData.uuid,
  624. act: 'del',
  625. id: this.arcID
  626. },
  627. header: {
  628. 'content-type': 'application/json',
  629. 'sign': getApp().globalData.headerSign
  630. },
  631. success: (res) => {
  632. uni.hideLoading();
  633. if (res.data.success === "yes") {
  634. uni.showToast({
  635. title: '删除成功',
  636. icon: 'success'
  637. });
  638. // 删除成功后返回上一页
  639. setTimeout(() => {
  640. uni.navigateBack({
  641. delta: 1
  642. });
  643. }, 1500);
  644. } else {
  645. uni.showToast({
  646. title: '删除失败',
  647. icon: 'none'
  648. });
  649. }
  650. },
  651. fail: () => {
  652. uni.hideLoading();
  653. uni.showToast({
  654. title: '删除失败',
  655. icon: 'none'
  656. });
  657. }
  658. });
  659. },
  660. goCreate() {
  661. console.log(222222222);
  662. let url=''
  663. if(this.articleInfo.lyrics ){
  664. url = "/pages/makedetail/makeMusicDetail"
  665. }else{
  666. url = "/pages/makedetail/makeImgDetail"
  667. }
  668. uni.navigateTo({
  669. url
  670. })
  671. // // 切换到标签页
  672. // uni.switchTab({
  673. // // 指定要切换到的页面路径
  674. // url: "/pages/make/index",
  675. // });
  676. },
  677. goToUserHomepage(id) {
  678. uni.$emit('check_login', () => {
  679. if (!id) {
  680. return;
  681. }
  682. uni.navigateTo({
  683. url: "/pages/my/userHomepage?id=" + id,
  684. });
  685. })
  686. },
  687. // 预览图片
  688. previewImage(url) {
  689. if (!url) return;
  690. uni.previewImage({
  691. urls: [url],
  692. current: url,
  693. indicator: 'number',
  694. loop: true,
  695. showmenu:false
  696. });
  697. },
  698. async chooseImage(sourceType) {
  699. try {
  700. let hasPermission = false;
  701. if (sourceType === 'camera') {
  702. hasPermission = await this.checkCameraPermission();
  703. } else if (sourceType === 'album') {
  704. hasPermission = await this.checkPhotoLibraryPermission();
  705. }
  706. if (!hasPermission) {
  707. uni.showToast({
  708. title: '未获得权限',
  709. icon: 'none'
  710. });
  711. return;
  712. }
  713. uni.chooseImage({
  714. count: 1,
  715. sizeType: ['compressed'],
  716. sourceType: [sourceType],
  717. success: async (res) => {
  718. console.log('res:', res)
  719. if (res.tempFilePaths.length > 0) {
  720. this.imglocal = res.tempFilePaths[0]
  721. const tempFilePath = res.tempFilePaths[0];
  722. console.log('tempFilePaths:', tempFilePath);
  723. await this.uploadImage(tempFilePath);
  724. }
  725. },
  726. fail: (err) => {
  727. console.error('选择图片失败:', err);
  728. uni.showToast({
  729. title: '选择图片失败',
  730. icon: 'none'
  731. });
  732. }
  733. });
  734. } catch (error) {
  735. console.error('权限检查失败:', error);
  736. uni.showToast({
  737. title: '权限检查失败',
  738. icon: 'none'
  739. });
  740. }
  741. },
  742. async checkCameraPermission() {
  743. const hasPermission = await permission.request(permission.PermissionType.CAMERA, {
  744. title: '“萌创星球”想访问你的相机',
  745. describe: '萌创星球想访问您的摄像头,便于拍摄获取图片来替换原有作品封面图'
  746. });
  747. return hasPermission;
  748. },
  749. async checkPhotoLibraryPermission() {
  750. const hasPermission = await permission.request(permission.PermissionType.PHOTO_LIBRARY, {
  751. title: '“萌创星球”想访问你的照片图库',
  752. describe: '萌创星球想访问您本地照片图库,便于获取图片来替换原有作品封面图'
  753. });
  754. return hasPermission;
  755. },
  756. uploadImage(tempFilePath) {
  757. const _self = this;
  758. const uploadTask = uni.uploadFile({
  759. url: _self.$apiHost + '/Xweb/upload_img?skey=' + _self.skey,
  760. filePath: tempFilePath,
  761. name: 'file',
  762. success: function(uploadFileRes) {
  763. let resdata = JSON.parse(uploadFileRes.data);
  764. console.log('Success:', uploadFileRes);
  765. console.log('Upload data:', resdata);
  766. if (resdata.success == 'yes') {
  767. _self.showRights = false;
  768. _self.home_image = resdata.url;
  769. uni.showToast({
  770. title: '图片上传成功',
  771. icon: 'success',
  772. duration: 1500
  773. });
  774. } else {
  775. uni.showToast({
  776. title: resdata.msg || '上传失败',
  777. icon: 'none',
  778. duration: 1500
  779. });
  780. }
  781. },
  782. fail: function(uploadFileFail) {
  783. console.error('Error:', uploadFileFail);
  784. uni.showToast({
  785. title: '上传失败,请重试',
  786. icon: 'none',
  787. duration: 1500
  788. });
  789. },
  790. complete: () => {
  791. console.log('Upload complete');
  792. }
  793. });
  794. // 显示上传进度
  795. uploadTask.onProgressUpdate((res) => {
  796. console.log('上传进度' + res.progress);
  797. console.log('已经上传的数据长度' + res.totalBytesSent);
  798. console.log('预期需要上传的数据总长度' + res.totalBytesExpectedToSend);
  799. });
  800. },
  801. // 播放视频组件
  802. handleVideoPlay(e) {
  803. console.log('视频开始播放', e);
  804. },
  805. handleVideoPause(e) {
  806. console.log('视频暂停', e);
  807. },
  808. handleVideoEnded(e) {
  809. console.log('视频播放结束', e);
  810. },
  811. },
  812. };
  813. </script>
  814. <style scoped lang="scss">
  815. @import "workDetail.scss";
  816. .permission-tip {
  817. width: 100%;
  818. height: 300rpx;
  819. background-color: rgba(255, 255, 255, 0.9);
  820. position: fixed;
  821. top: 0;
  822. display: flex;
  823. flex-direction: column;
  824. justify-content: center;
  825. align-items: center;
  826. z-index: 999;
  827. .permission-title {
  828. width: 90%;
  829. color: #000000;
  830. font-size: 38rpx;
  831. text-align: left;
  832. padding: 10rpx 20rpx;
  833. padding-top: 10rpx;
  834. }
  835. .permission-desc {
  836. width: 90%;
  837. color: #666666;
  838. font-size: 28rpx;
  839. text-align: left;
  840. padding: 10rpx 20rpx;
  841. }
  842. }
  843. .video-content {
  844. width: 100%;
  845. margin: 20rpx 0;
  846. background-color: #f5f5f5;
  847. }
  848. </style>