workDetail.vue 26 KB

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