workDetail.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875
  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. <text class="fa fa-ellipsis-h"></text>
  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 v-if="userInfo.id != 0 && articleInfo.title" ref="commentSection" :myInfo="myInfo"
  154. :userInfo="userInfo" :articleId="arcID" @totalNumberOfComments="totalNumberOfComments" :articleInfo="articleInfo" 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/sy_icon_shanchu.png",
  543. danger: true,
  544. },
  545. ];
  546. }
  547. this.$refs.actionSheet.show();
  548. })
  549. },
  550. handleActionCancel() {
  551. console.log("ActionSheet cancelled");
  552. },
  553. handleActionSelect(index, item) {
  554. console.log("ActionSheet selected index:", item.text);
  555. if (item.text === "分享作品") {
  556. this.showShare = true;
  557. } else if (item.text === "修改封面") {
  558. // 修改封面
  559. if (this.articleInfo.status == 3) {
  560. uni.showToast({
  561. title: '作品已完成,无法修改封面!',
  562. icon: 'none'
  563. });
  564. return;
  565. }
  566. this.editCover();
  567. } else if (item.text === "删除作品") {
  568. // 删除作品
  569. this.deleteWork();
  570. }
  571. },
  572. // 修改封面
  573. editCover() {
  574. uni.showActionSheet({
  575. itemList: ['拍照', '从相册选择'],
  576. success: (res) => {
  577. const sourceType = res.tapIndex === 0 ? 'camera' : 'album';
  578. this.chooseImage(sourceType);
  579. }
  580. });
  581. },
  582. // 删除作品
  583. deleteWork() {
  584. this.$refs["customConfirm"]
  585. .confirm({
  586. title: "确认删除",
  587. content: "确定要删除这个作品吗?",
  588. DialogType: "inquiry",
  589. btn1: "再考虑一下",
  590. btn2: "确认解绑",
  591. animation: 0,
  592. })
  593. .then((res) => {
  594. if (res.confirm) {
  595. // 用户点击确定,执行删除操作
  596. this.confirmDelete();
  597. }
  598. });
  599. },
  600. // 确认删除
  601. confirmDelete() {
  602. uni.showLoading({
  603. title: '删除中...'
  604. });
  605. uni.request({
  606. url: this.$apiHost + '/Work/doAct',
  607. method: 'GET',
  608. data: {
  609. uuid: getApp().globalData.uuid,
  610. act: 'del',
  611. id: this.arcID
  612. },
  613. header: {
  614. 'content-type': 'application/json',
  615. 'sign': getApp().globalData.headerSign
  616. },
  617. success: (res) => {
  618. uni.hideLoading();
  619. if (res.data.success === "yes") {
  620. uni.showToast({
  621. title: '删除成功',
  622. icon: 'success'
  623. });
  624. // 删除成功后返回上一页
  625. setTimeout(() => {
  626. uni.navigateBack({
  627. delta: 1
  628. });
  629. }, 1500);
  630. } else {
  631. uni.showToast({
  632. title: '删除失败',
  633. icon: 'none'
  634. });
  635. }
  636. },
  637. fail: () => {
  638. uni.hideLoading();
  639. uni.showToast({
  640. title: '删除失败',
  641. icon: 'none'
  642. });
  643. }
  644. });
  645. },
  646. goCreate() {
  647. console.log(222222222);
  648. let url=''
  649. if(this.articleInfo.lyrics ){
  650. url = "/pages/makedetail/makeMusicDetail"
  651. }else{
  652. url = "/pages/makedetail/makeImgDetail"
  653. }
  654. uni.navigateTo({
  655. url
  656. })
  657. // // 切换到标签页
  658. // uni.switchTab({
  659. // // 指定要切换到的页面路径
  660. // url: "/pages/make/index",
  661. // });
  662. },
  663. goToUserHomepage(id) {
  664. uni.$emit('check_login', () => {
  665. if (!id) {
  666. return;
  667. }
  668. uni.navigateTo({
  669. url: "/pages/my/userHomepage?id=" + id,
  670. });
  671. })
  672. },
  673. // 预览图片
  674. previewImage(url) {
  675. if (!url) return;
  676. uni.previewImage({
  677. urls: [url],
  678. current: url,
  679. indicator: 'number',
  680. loop: true,
  681. showmenu:false
  682. });
  683. },
  684. async chooseImage(sourceType) {
  685. try {
  686. let hasPermission = false;
  687. if (sourceType === 'camera') {
  688. hasPermission = await this.checkCameraPermission();
  689. } else if (sourceType === 'album') {
  690. hasPermission = await this.checkPhotoLibraryPermission();
  691. }
  692. if (!hasPermission) {
  693. uni.showToast({
  694. title: '未获得权限',
  695. icon: 'none'
  696. });
  697. return;
  698. }
  699. uni.chooseImage({
  700. count: 1,
  701. sizeType: ['compressed'],
  702. sourceType: [sourceType],
  703. success: async (res) => {
  704. console.log('res:', res)
  705. if (res.tempFilePaths.length > 0) {
  706. this.imglocal = res.tempFilePaths[0]
  707. const tempFilePath = res.tempFilePaths[0];
  708. console.log('tempFilePaths:', tempFilePath);
  709. await this.uploadImage(tempFilePath);
  710. }
  711. },
  712. fail: (err) => {
  713. console.error('选择图片失败:', err);
  714. uni.showToast({
  715. title: '选择图片失败',
  716. icon: 'none'
  717. });
  718. }
  719. });
  720. } catch (error) {
  721. console.error('权限检查失败:', error);
  722. uni.showToast({
  723. title: '权限检查失败',
  724. icon: 'none'
  725. });
  726. }
  727. },
  728. async checkCameraPermission() {
  729. const hasPermission = await permission.request(permission.PermissionType.CAMERA, {
  730. title: '“萌创星球”想访问你的相机',
  731. describe: '萌创星球想访问您的摄像头,便于拍摄获取图片来替换原有作品封面图'
  732. });
  733. return hasPermission;
  734. },
  735. async checkPhotoLibraryPermission() {
  736. const hasPermission = await permission.request(permission.PermissionType.PHOTO_LIBRARY, {
  737. title: '“萌创星球”想访问你的照片图库',
  738. describe: '萌创星球想访问您本地照片图库,便于获取图片来替换原有作品封面图'
  739. });
  740. return hasPermission;
  741. },
  742. uploadImage(tempFilePath) {
  743. const _self = this;
  744. const uploadTask = uni.uploadFile({
  745. url: _self.$apiHost + '/Xweb/upload_img?skey=' + _self.skey,
  746. filePath: tempFilePath,
  747. name: 'file',
  748. success: function(uploadFileRes) {
  749. let resdata = JSON.parse(uploadFileRes.data);
  750. console.log('Success:', uploadFileRes);
  751. console.log('Upload data:', resdata);
  752. if (resdata.success == 'yes') {
  753. _self.showRights = false;
  754. _self.home_image = resdata.url;
  755. uni.showToast({
  756. title: '图片上传成功',
  757. icon: 'success',
  758. duration: 1500
  759. });
  760. } else {
  761. uni.showToast({
  762. title: resdata.msg || '上传失败',
  763. icon: 'none',
  764. duration: 1500
  765. });
  766. }
  767. },
  768. fail: function(uploadFileFail) {
  769. console.error('Error:', uploadFileFail);
  770. uni.showToast({
  771. title: '上传失败,请重试',
  772. icon: 'none',
  773. duration: 1500
  774. });
  775. },
  776. complete: () => {
  777. console.log('Upload complete');
  778. }
  779. });
  780. // 显示上传进度
  781. uploadTask.onProgressUpdate((res) => {
  782. console.log('上传进度' + res.progress);
  783. console.log('已经上传的数据长度' + res.totalBytesSent);
  784. console.log('预期需要上传的数据总长度' + res.totalBytesExpectedToSend);
  785. });
  786. },
  787. // 播放视频组件
  788. handleVideoPlay(e) {
  789. console.log('视频开始播放', e);
  790. },
  791. handleVideoPause(e) {
  792. console.log('视频暂停', e);
  793. },
  794. handleVideoEnded(e) {
  795. console.log('视频播放结束', e);
  796. },
  797. },
  798. };
  799. </script>
  800. <style scoped lang="scss">
  801. @import "workDetail.scss";
  802. .permission-tip {
  803. width: 100%;
  804. height: 300rpx;
  805. background-color: rgba(255, 255, 255, 0.9);
  806. position: fixed;
  807. top: 0;
  808. display: flex;
  809. flex-direction: column;
  810. justify-content: center;
  811. align-items: center;
  812. z-index: 999;
  813. .permission-title {
  814. width: 90%;
  815. color: #000000;
  816. font-size: 38rpx;
  817. text-align: left;
  818. padding: 10rpx 20rpx;
  819. padding-top: 10rpx;
  820. }
  821. .permission-desc {
  822. width: 90%;
  823. color: #666666;
  824. font-size: 28rpx;
  825. text-align: left;
  826. padding: 10rpx 20rpx;
  827. }
  828. }
  829. .video-content {
  830. width: 100%;
  831. margin: 20rpx 0;
  832. background-color: #f5f5f5;
  833. }
  834. </style>