1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063 |
- <template>
- <view class="page">
-
- <!-- 权限申请提示 -->
- <view v-if="showRights" class="permission-tip">
- <text class="permission-title">正在获取相机、存储权限</text>
- <text class="permission-desc">该权限用于获取设备拍摄或获取本地应用相册,进行头像或图片上传。</text>
- </view>
- <!-- 顶部导航栏 -->
- <view class="custom-navbar">
- <view class="navbar-left" @click="goBack">
- <text class="fa fa-angle-left"></text>
- </view>
- <view class="navbar-center">
- <view class="navbar-title" v-if="false">
- <image class="navbar-avatar" :src="myinfo.avator" mode="aspectFill"></image>
- <text class="navbar-text">{{ myinfo.nickname }}</text>
- <text class="navbar-badge" v-if="myinfo.is_vip > 0">VIP</text>
- </view>
- </view>
- <view class="navbar-right" @click="showActionSheet">
- <image src="@/static/icon/more2.png" style="width: 64rpx;height: 64rpx; margin-top: 15rpx;" mode="widthFix"></image>
- </view>
- </view>
- <view class="topStatusBar inProgress" v-if="fileInformation.status == 2"
- :class="queueDetail.task_type == 1 ? 'mb20' : ''"> 审核中</view>
- <view class="topStatusBar fail" v-if="fileInformation.status == 4"
- :class="queueDetail.task_type == 2 ? 'mb20' : ''" @click="openConfirmationBox"> 审核未通过,点击查看原因</view>
- <!-- 灵感 -->
- <template v-if="queueDetail.task_type == 1">
- <view class="inspiration-content" v-if="home_image">
- <image v-if="home_image" src="../../static/makedetail/cz_img_zhanshi.png" mode="widthFix"></image>
- <image :src="home_image" class="inspirationPictures" mode="widthFix"></image>
- </view>
- </template>
- <!-- 音乐 -->
- <template v-else-if="queueDetail.task_type == 2">
- <view class="musicContentBox">
- <view class="headCard">
- <image :src="home_image" class="songCover"></image>
- <view class="songInfo">
- <view class="songTitle">{{ addBrackets(queueDetail.song_name) }}</view>
- <view class="songTag">
- <view class="tag" v-for="(item, index) in commaToArray(queueDetail.style)"
- :key="index + item">{{ item }}</view>
- </view>
- </view>
- <template v-if="queueDetail.task_type == 2 && queueDetail.status >= 9">
- <image @click="toggleAudio" v-if="isPlaying" src="@/static/makedetail/cz_icon_zanting.png"
- class="playerButton"></image>
- <image @click="toggleAudio" v-else src="@/static/makedetail/cz_icon_bofang.png"
- class="playerButton"></image>
- </template>
- </view>
- <view class="contentHeader">
- <view class="musicContent">
- <text style="max-width: 350rpx; display: inline-block;"> {{ queueDetail.description }}</text>
- <image class="roll" src="@/static/icon/roll.png"></image>
- </view>
- <view class="maskLayer"></view>
- </view>
- </view>
- </template>
- <!-- 作品描述 -->
- <view class="workDescription">
- <view class="workDescription-title">
- <view>创作描述 </view>
- <!-- <image class="pen" src="@/static/icon/wd_icon_bianji.png"></image> -->
- </view>
- <view class="workDescription-content">
- <uv-text :text="queueDetail.lyrics || queueDetail.description" class=" ">
-
- </uv-text>
- <!--{{ queueDetail.lyrics || queueDetail.description }}-->
- </view>
- </view>
- <!-- 作品描述 -->
- <view class="workDescription" v-if="queueDetail.content">
- <view class="workDescription-title">
- <view>创作说明 </view>
- <!-- <image class="pen" src="@/static/icon/wd_icon_bianji.png"></image> -->
- </view>
- <view class="workDescription-content">
- {{ noteContent }}
- </view>
- </view>
- <view class="thread2"></view>
- <!-- 音频元素 -->
- <audio id="audioPlayer" :src="queueDetail.result_audio" style="display:none;"></audio>
- <!-- 用于处理图片像素的隐藏canvas -->
- <canvas canvas-id="pixelCanvas"
- style="width: 10px; height: 10px; position: absolute; left: -100px; top: -100px;"></canvas>
- <!-- 底部漂浮栏 -->
- <view class="floating-bar"
- v-if="queueDetail.status == 9 && (fileInformation.status == 3 || fileInformation.status == 0)">
- <view class="floating-bar-content">
- <view class="add-note-btn" @click="openContentPopUpWindow">
- <text>添加说明</text>
- </view>
- <view class="publish-btn" @click="publishWork">
- <text>公布作品</text>
- </view>
- </view>
- </view>
- <!-- 自定义 ActionSheet -->
- <ActionSheet ref="actionSheet" :items="[
- { text: '分享作品', icon: '../../static/icon/cz_icon_fenxiangzuopin.png' },
- { text: '修改封面', icon: '../../static/icon/cz_icon_xiugaifengmian.png' },
- { text: '举报', icon: '../../static/icon/jubao.png' },
- { text: '删除作品', icon: '../../static/icon/sy_icon_shanchu.png', danger: true },
- ]" @select="handleActionSelect" @cancel="handleActionCancel" />
- <NicknamePopup title="添加说明" subtitle="" class="openContentPopUpWindow" ref="openContentPopUpWindow">
- <template v-slot:content>
- <uv-textarea v-model="noteContent" maxlength="500" count placeholder="请描述你添加的内容"></uv-textarea>
- <view class="btn-box" @click="confirmAddNote">确认</view>
- </template>
- </NicknamePopup>
- <CustomPopup ref="confirmationBox">
- <view class="failureReason">
- <view class="title"> 审核未通关</view>
- <view class="reviewContent">
- <uv-parse :content="fileInformation.reason"></uv-parse>
- </view>
- <view class="btn-box" @click="closeConfirmationBox">知道了</view>
- </view>
- </CustomPopup>
- <DialogBox ref="customConfirm"></DialogBox>
- <SharePopup :visible="showShare" :userId="userId" :share-title="shareTitle" :share-desc="shareDesc"
- :share-img="shareImg" view="makeDetail" @close="showShare = false" />
- </view>
- </template>
- <script>
- import previewImage from '@/components/kxj-previewImage/kxj-previewImage.vue'; //引用插件
- import NicknamePopup from '@/components//NicknamePopup/NicknamePopup.vue';
- import CustomPopup from '@/components/CustomPopup/CustomPopup.vue';
- import ActionSheet from '@/components/ActionSheet/ActionSheet.vue';
- import SharePopup from "@/components/SharePopup/SharePopup.vue";
- import permission from '@/common/permission.js';
- export default {
- components: {
- previewImage,
- NicknamePopup,
- CustomPopup,
- ActionSheet,
- SharePopup,
- },
- data() {
- return {
- title: '',
- arcID: 0,
- selImg: 0,
- home_image: '',
- myinfo: {},
- tag_list: [],
- image_list: [],
- imgs: [],
- descs: [],
- isPlaying: false,
- audioPlayer: null,
- showNotePopup: false,
- noteContent: '',
- pixelColor: null, // 存储像素颜色值
- queueId: 0,
- showShare: false,
- shareTitle: "",
- shareDesc: "",
- shareImg: "",
- userId: 0,
- showRights: false,
- // 队列详情数据
- queueDetail: {
- id: 0,
- sso_id: 0,
- task_type: 1,
- title: '',
- description: '',
- action: '',
- environment: '',
- subject: '',
- style: '',
- song_name: '',
- lyrics: '',
- generate_uuid: '',
- result_images: '',
- result_audio: '',
- queue_position: 0,
- status: 1,
- generate_status: 1,
- points_cost: 0,
- error_msg: '',
- create_time: '',
- update_time: '',
- all_position: 0
- },
- fileInformation: {
- age: 0,
- author: "",
- avator: "",
- city: "",
- content: "",
- create_time: "",
- dtime: "",
- id: 0,
- images: "",
- is_like: 0,
- is_vip: 0,
- like_count: 0,
- lyrics: "",
- nickname: "",
- num_comment: 0,
- num_like: 0,
- num_view: 0,
- queue_id: 0,
- reason: "",
- result_audio: "",
- sex: 0,
- sso_id: 0,
- status: 0, //1是成功 2是审核中 4是失败 3是未公布也就是私人状态
- task_type: 0,
- tdate: "",
- title: "",
- userID: 0,
- xinzuo: "",
- },
- myinfo: {},
- offsetY: 0,
- isDragging: false,
- startY: 0,
- initialOffsetY: 0,
- }
- },
- onLoad(parms) {
- let self = this;
- this.arcID = parms.id;
- this.queueId = parms.queueId;
- this.getMyInfo();
- },
- onShow() {
- this.loadData();
- this.getInfoData();
- },
- onReady() {
- // 获取音频元素
- this.audioPlayer = uni.createInnerAudioContext();
- this.audioPlayer.onEnded(() => {
- this.isPlaying = false;
- });
- },
- onUnload() {
- // 页面卸载时停止音频播放
- if (this.audioPlayer) {
- this.audioPlayer.stop();
- this.audioPlayer.destroy();
- }
- },
- mounted() {
- },
- methods: {
- openConfirmationBox() {
- this.$refs.confirmationBox.open();
- },
- closeConfirmationBox() {
- this.$refs.confirmationBox.close();
- },
- openContentPopUpWindow() {
- this.$refs.openContentPopUpWindow.open();
- },
- closeContentPopUpWindow() {
- this.$refs.openContentPopUpWindow.close();
- },
- // 获取图片第一个像素的RGB值
- getImagePixelColor() {
- console.log("图片加载完成,准备获取像素颜色");
- // 清空之前的颜色值,进入加载状态
- this.pixelColor = null;
- // 如果是默认图片或空图片,则直接返回
- if (!this.home_image || this.home_image === '../../static/home/avator.png') {
- console.log("无有效图片,不获取像素颜色");
- return;
- }
- // 使用uni.getImageInfo获取图片信息
- uni.getImageInfo({
- src: this.home_image,
- success: (res) => {
- console.log("图片信息:", res);
- // 创建临时canvas绘制上下文
- const ctx = uni.createCanvasContext('pixelCanvas', this);
- // 修改绘制参数,确保只绘制图片左上角的一小块区域
- // drawImage(图片路径, 源图片裁剪x, 源图片裁剪y, 源图片裁剪宽度, 源图片裁剪高度, canvas目标x, canvas目标y, canvas目标宽度, canvas目标高度)
- // 这里我们只从源图片左上角裁剪10x10的区域,绘制到canvas的左上角
- ctx.drawImage(res.path, 0, 0, 10, 10, 0, 0, 10, 10);
- ctx.draw(false, () => {
- // 绘制完成后,获取像素数据
- setTimeout(() => { // 添加短暂延迟确保绘制完成
- uni.canvasGetImageData({
- canvasId: 'pixelCanvas',
- x: 0, // 获取(0,0)位置的像素
- y: 0,
- width: 1,
- height: 1,
- success: (res) => {
- // 获取像素RGB值
- this.pixelColor = {
- r: res.data[0],
- g: res.data[1],
- b: res.data[2],
- a: res.data[3]
- };
- console.log("第一个像素的RGB值:", this
- .pixelColor);
- },
- fail: (err) => {
- console.error("获取像素数据失败:", err);
- // 显示错误提示
- uni.showToast({
- title: '获取颜色失败',
- icon: 'none',
- duration: 2000
- });
- }
- });
- }, 100);
- });
- },
- fail: (err) => {
- console.error("获取图片信息失败:", err);
- // 显示错误提示
- uni.showToast({
- title: '图片加载失败',
- icon: 'none',
- duration: 2000
- });
- }
- });
- },
- // 返回上一页
- goBack() {
- uni.navigateBack({
- delta: 1
- });
- },
- getMyInfo() {
- uni.request({
- url: this.$apiHost + '/My/getnum',
- method: 'GET',
- header: {
- 'content-type': 'application/json',
- 'sign': getApp().globalData.headerSign
- },
- data: {
- uuid: getApp().globalData.uuid
- },
- success: (res) => {
- console.log("获取用户信息:", res.data);
- this.myinfo = res.data
- }
- })
- },
- selPhoto(item, sel) {
- this.selImg = sel;
- this.home_image = this.image_list[sel];
- },
- toArr(imgs) {
- let arr = imgs.split("|");
- return arr;
- },
- previewOpen(imgs1, index) {
- this.imgs = imgs1.split("|");
- setTimeout(() => this.$refs.previewImage.open(index), 0)
- // 传入当前选中的图片地址或序号
- return; //如需测试和uni原生预览差别可注释这两行
- },
- // 切换音频播放状态
- toggleAudio() {
- if (!this.queueDetail.result_audio) return;
- if (this.isPlaying) {
- this.audioPlayer.pause();
- this.isPlaying = false;
- } else {
- this.audioPlayer.src = this.queueDetail.result_audio;
- this.audioPlayer.play();
- this.isPlaying = true;
- }
- },
- // 获取进度条宽度
- getProgressWidth() {
- if (this.queueDetail.all_position === 0) return '0%';
- const progress = (1 - (this.queueDetail.queue_position / this.queueDetail.all_position)) * 100;
- return `${progress}%`;
- },
- // 加载数据
- loadData() {
- uni.showLoading({
- title: '加载中...'
- });
- let that = this;
- if (this.queueId) {
- that.workInformation()
- }
- uni.request({
- url: this.$apiHost + '/WorkAI/getQueueDetail',
- data: {
- uuid: getApp().globalData.uuid,
- id: this.arcID
- },
- header: {
- "content-type": "application/json",
- 'sign': getApp().globalData.headerSign
- },
- success: (res) => {
- console.log("队列详情:", res.data);
- if (res.data.success === "yes") {
- // 更新队列详情
- this.queueDetail = res.data.data;
- this.noteContent = res.data.data.content;
- // 更新图片列表
- if (this.queueDetail.result_images && this.queueDetail.result_images !== "") {
- this.image_list = this.queueDetail.result_images.split(",");
- this.home_image = this.image_list[0];
- // 当图片更新后,手动触发获取像素颜色(因为图片可能从缓存加载,不会触发@load事件)
- // setTimeout(() => {
- // that.getImagePixelColor();
- // }, 500);
- } else {
- this.home_image = "../../static/home/avator.png";
- }
- // 如果是音频类型,设置音频源
- if (this.queueDetail.task_type == 2 && this.queueDetail.result_audio) {
- this.audioPlayer.src = this.queueDetail.result_audio;
- }
- // 更新分享相关数据
- this.shareTitle = res.data.data.song_name || '萌创星球';
- this.shareDesc = res.data.data.description;
- this.shareImg = this.home_image;
- this.userId = res.data.data.sso_id;
- console.log(this.shareTitle, 9, this.shareDesc, 2, this.shareImg, 3, this.userId, 4, '分享数据');
- } else {
- uni.showToast({
- title: '获取详情失败',
- icon: 'none'
- });
- }
- },
- complete: () => {
- uni.hideLoading();
- },
- fail: (e) => {
- console.log("请求失败:", e);
- uni.showToast({
- title: '网络请求失败',
- icon: 'none'
- });
- }
- });
- },
- // 加载作品信息
- workInformation() {
- uni.request({
- url: this.$apiHost + '/Work/getinfo',
- data: {
- uuid: getApp().globalData.uuid,
- id: this.queueId
- },
- header: {
- "content-type": "application/json",
- 'sign': getApp().globalData.headerSign
- },
- success: (res) => {
- console.log("文章信息:", res.data);
- if (res.data.success === "yes") {
- // 更新文章信息
- this.fileInformation = res.data.data;
- } else {
- }
- },
- complete: (com) => {
- // uni.hideLoading();
- },
- fail: (e) => {
- console.log("请求失败:", e);
- uni.showToast({
- title: '网络请求失败',
- icon: 'none'
- });
- }
- });
- },
- showActionSheet() {
- this.$refs.actionSheet.show();
- },
- handleActionSelect(index, item) {
- console.log('ActionSheet selected index:', item.text,);
- switch (item.text) {
- case '分享作品':
- this.showShare = true;
- break;
- case '修改封面':
- // 修改封面
- if (this.queueDetail.status == 9 && (this.fileInformation.status == 3 || this.fileInformation.status == 0)) {
- this.editCover();
- } else {
- if (this.queueDetail.status == 9) {
- uni.showToast({
- title: '作品已完成,无法修改封面!',
- icon: 'none'
- });
- } else {
- uni.showToast({
- title: '作品未完成,无法修改封面!',
- icon: 'none'
- });
- }
- break;
- }
- break;
- case '删除作品':
- // 删除作品
- this.deleteWork();
- break;
- case '举报':
- this.handleReport();
- break;
- }
- },
- handleReport() {
- // 实现举报功能
- uni.$emit('check_login', () => {
- uni.navigateTo({
- url: '/pages/my/feedback'
- })
- })
- },
- handleActionCancel() {
- console.log('ActionSheet cancelled');
- },
- // 修改封面
- async editCover() {
- var _self = this;
- const hasPermission = await this.checkCameraPermission();
- if (!hasPermission) return;
- console.log(1111111);
- uni.chooseImage({
- count: 1,
- sizeType: ['compressed'],
- sourceType: ['album', 'camera'],
- success: async function (res) {
- console.log('res:', res)
- if (res.tempFilePaths.length > 0) {
- _self.imglocal = res.tempFilePaths[0]
- const tempFilePaths = res.tempFilePaths[0];
- console.log('tempFilePaths:', tempFilePaths);
- const uploadTask = uni.uploadFile({
- url: _self.$apiHost + '/Xweb/upload_img?skey=' + _self.skey,
- filePath: res.tempFilePaths[0],
- name: 'file',
- success: async function (uploadFileRes) {
- let resdata = JSON.parse(uploadFileRes.data)
- console.log('Success11:', uploadFileRes);
- console.log('Success21:', resdata);
- if (resdata.success == 'yes') {
- // 调用修改封面接口
- uni.request({
- url: _self.$apiHost + '/WorkAI/queueAction',
- method: 'GET',
- data: {
- uuid: getApp().globalData.uuid,
- act: 'editImg',
- result_images: resdata.url,
- id: _self.arcID
- },
- header: {
- 'content-type': 'application/json',
- 'sign': getApp().globalData.headerSign
- },
- success: async (res) => {
- if (res.data.success === "yes") {
- _self.home_image = resdata.url;
- uni.showToast({
- title: '修改封面成功',
- icon: 'success'
- });
- } else {
- uni.showToast({
- title: '修改封面失败',
- icon: 'none'
- });
- }
- },
- fail: () => {
- uni.showToast({
- title: '修改封面失败',
- icon: 'none'
- });
- }
- });
- }
- },
- fail: function (uploadFileFail) {
- console.log('Error:', uploadFileFail.data);
- uni.showToast({
- title: '图片上传失败',
- icon: 'none'
- });
- }
- });
- }
- },
- error: function (e) {
- console.log(e);
- uni.showToast({
- title: '选择图片失败',
- icon: 'none'
- });
- }
- });
- },
- // 删除作品
- deleteWork() {
- this.$refs["customConfirm"]
- .confirm({
- title: "确认删除",
- content: "确定要删除这个作品吗?",
- DialogType: "inquiry",
- btn1: "再考虑一下",
- btn2: "确认删除",
- animation: 0,
- })
- .then((res) => {
- console.log(res);
- if (res.confirm) {
- // 用户点击确定,执行删除操作
- this.confirmDelete();
- }
- }, () => { });
- },
- // 确认删除
- confirmDelete() {
- uni.showLoading({
- title: '删除中...'
- });
- let url = this.$apiHost + '/WorkAI/queueAction';
- let id = this.arcID;
- if (this.queueDetail.status == 9) {
- url = this.$apiHost + '/Work/doAct';
- id = this.queueId;
- }
- uni.request({
- url,
- method: 'GET',
- data: {
- uuid: getApp().globalData.uuid,
- act: 'del',
- id,
- },
- header: {
- 'content-type': 'application/json',
- 'sign': getApp().globalData.headerSign
- },
- success: (res) => {
- uni.hideLoading();
- if (res.data.success === "yes") {
- uni.showToast({
- title: '删除成功',
- icon: 'success'
- });
- // 删除成功后返回上一页
- setTimeout(() => {
- uni.navigateBack({
- delta: 1
- });
- }, 1500);
- } else {
- uni.showToast({
- title: '删除失败',
- icon: 'none'
- });
- }
- },
- fail: () => {
- uni.hideLoading();
- uni.showToast({
- title: '删除失败',
- icon: 'none'
- });
- }
- });
- },
- // 显示添加说明弹窗
- showAddNotePopup() {
- this.showNotePopup = true;
- },
- // 关闭添加说明弹窗
- closeAddNotePopup() {
- this.showNotePopup = false;
- },
- // 确认添加说明
- confirmAddNote() {
- if (!this.noteContent.trim()) {
- uni.showToast({
- title: '请输入说明内容',
- icon: 'none'
- });
- return;
- }
- uni.showLoading({
- title: '保存中...'
- });
- uni.request({
- url: this.$apiHost + '/WorkAI/queueAction',
- method: 'GET',
- data: {
- uuid: getApp().globalData.uuid,
- act: 'editContent',
- content: this.noteContent,
- id: this.arcID
- },
- header: {
- 'content-type': 'application/json',
- 'sign': getApp().globalData.headerSign
- },
- success: (res) => {
- uni.hideLoading();
- if (res.data.success === "yes") {
- uni.showToast({
- title: res.data.str,
- icon: 'success'
- });
- this.noteContent = '';
- this.closeContentPopUpWindow();
- // 重新加载数据
- this.loadData();
- } else {
- uni.showToast({
- title: res.data.str,
- icon: 'none'
- });
- }
- },
- fail: () => {
- uni.hideLoading();
- uni.showToast({
- title: '添加说明失败',
- icon: 'none'
- });
- }
- });
- },
- // 发布作品
- publishWork() {
- uni.showLoading({
- title: '发布中...'
- });
- uni.request({
- url: this.$apiHost + '/WorkAI/queueAction',
- method: 'GET',
- data: {
- uuid: getApp().globalData.uuid,
- act: 'fabu',
- id: this.arcID
- },
- header: {
- 'content-type': 'application/json',
- 'sign': getApp().globalData.headerSign
- },
- success: (res) => {
- console.log("resddd", res.data);
- uni.hideLoading();
- if (res.data.success === "yes") {
- uni.showToast({
- title: '发布成功',
- icon: 'success'
- });
- // 重新加载数据
- // this.loadData();
- } else {
- uni.showToast({
- title: res.data.str || '发布失败',
- icon: 'none'
- });
- }
- },
- fail: () => {
- uni.hideLoading();
- uni.showToast({
- title: '发布失败',
- icon: 'none'
- });
- },
- complete: () => {
- setTimeout(() => {
- uni.navigateBack({
- delta: 1
- });
- }, 800);
- }
- });
- },
- // 新增过滤器方法
- commaToArray(str) {
- if (!str) return '';
- return str.split(',');
- },
- // 新增过滤器方法
- addBrackets(str) {
- if (!str) return '';
- if (!str.startsWith('《')) {
- str = '《' + str;
- }
- if (!str.endsWith('》')) {
- str = str + '》';
- }
- return str;
- },
- getInfoData() {
- uni.request({
- url: this.$apiHost + '/Member/getinfoData',
- data: {
- uuid: getApp().globalData.uuid
- },
- header: {
- 'content-type': 'application/json'
- },
- success: (res) => {
- console.log('用户信息', res.data);
- }
- });
- },
- async chooseImage(sourceType) {
- try {
- let hasPermission = false;
- if (sourceType === 'camera') {
- hasPermission = await this.checkCameraPermission();
- } else if (sourceType === 'album') {
- hasPermission = await this.checkPhotoLibraryPermission();
- }
- if (!hasPermission) {
- uni.showToast({
- title: '未获得权限',
- icon: 'none'
- });
- return;
- }
- uni.chooseImage({
- count: 1,
- sizeType: ['compressed'],
- sourceType: [sourceType],
- success: async (res) => {
- console.log('res:', res)
- if (res.tempFilePaths.length > 0) {
- this.imglocal = res.tempFilePaths[0]
- const tempFilePath = res.tempFilePaths[0];
- console.log('tempFilePaths:', tempFilePath);
- await this.uploadImage(tempFilePath);
- }
- },
- fail: (err) => {
- console.error('选择图片失败:', err);
- uni.showToast({
- title: '选择图片失败',
- icon: 'none'
- });
- }
- });
- } catch (error) {
- console.error('权限检查失败:', error);
- uni.showToast({
- title: '权限检查失败',
- icon: 'none'
- });
- }
- },
- async checkCameraPermission() {
- const hasPermission = await permission.request(permission.PermissionType.CAMERA, {
- title: '“萌创星球”想访问你的相机',
- describe: '萌创星球想访问您的摄像头,便于拍摄获取图片来替换原有作品封面图'
- });
- return hasPermission;
- },
- async checkPhotoLibraryPermission() {
- const hasPermission = await permission.request(permission.PermissionType.PHOTO_LIBRARY, {
- title: '“萌创星球”想访问你的照片图库',
- describe: '萌创星球想访问您本地照片图库,便于获取图片来替换原有作品封面图'
- });
- return hasPermission;
- },
- uploadImage(tempFilePath) {
- const _self = this;
- const uploadTask = uni.uploadFile({
- url: _self.$apiHost + '/Xweb/upload_img?skey=' + _self.skey,
- filePath: tempFilePath,
- name: 'file',
- success: function (uploadFileRes) {
- let resdata = JSON.parse(uploadFileRes.data)
- console.log('Success11:', uploadFileRes);
- console.log('Success21:', resdata);
- if (resdata.success == 'yes') {
- // 调用修改封面接口
- uni.request({
- url: _self.$apiHost + '/WorkAI/queueAction',
- method: 'GET',
- data: {
- uuid: getApp().globalData.uuid,
- act: 'editImg',
- result_images: resdata.url,
- id: _self.arcID
- },
- header: {
- 'content-type': 'application/json',
- 'sign': getApp().globalData.headerSign
- },
- success: async (res) => {
- if (res.data.success === "yes") {
- _self.showRights = false;
- _self.home_image = resdata.url;
- uni.showToast({
- title: '修改封面成功',
- icon: 'success'
- });
- } else {
- uni.showToast({
- title: '修改封面失败',
- icon: 'none'
- });
- }
- },
- fail: () => {
- uni.showToast({
- title: '修改封面失败',
- icon: 'none'
- });
- }
- });
- }
- },
- fail: function (uploadFileFail) {
- console.error('Error:', uploadFileFail);
- uni.showToast({
- title: '上传失败,请重试',
- icon: 'none',
- duration: 1500
- });
- },
- complete: () => {
- console.log('Upload complete');
- }
- });
- // 显示上传进度
- uploadTask.onProgressUpdate((res) => {
- console.log('上传进度' + res.progress);
- console.log('已经上传的数据长度' + res.totalBytesSent);
- console.log('预期需要上传的数据总长度' + res.totalBytesExpectedToSend);
- });
- },
- editCover() {
- uni.showActionSheet({
- itemList: ['拍照', '从相册选择'],
- success: (res) => {
- const sourceType = res.tapIndex === 0 ? 'camera' : 'album';
- this.chooseImage(sourceType);
- }
- });
- },
- }
- }
- </script>
- <style scoped lang="scss">
- @import 'makeDetail.scss';
- .openContentPopUpWindow {
- ::v-deep.uv-textarea {
- width: 694rpx !important;
- border-radius: 20rpx !important;
- border: 1rpx solid #000000 !important;
- margin: 0 auto;
- margin-bottom: 44rpx;
- min-height: 300rpx;
- }
- }
- .permission-tip {
- width: 100%;
- height: 300rpx;
- background-color: rgba(255, 255, 255, 0.9);
- position: fixed;
- top: 0;
- display: flex;
- flex-direction: column;
- justify-content: center;
- align-items: center;
- z-index: 999;
- .permission-title {
- width: 90%;
- color: #000000;
- font-size: 38rpx;
- text-align: left;
- padding: 10rpx 20rpx;
- padding-top: 10rpx;
- }
- .permission-desc {
- width: 90%;
- color: #666666;
- font-size: 28rpx;
- text-align: left;
- padding: 10rpx 20rpx;
- }
- }
- </style>
|