workDetail.vue 24 KB

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