makeDetail.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  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 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">
  15. <image class="navbar-avatar" :src="myinfo.avatar" mode="aspectFill"></image>
  16. <text class="navbar-text">{{ myinfo.nickname }}</text>
  17. <text class="navbar-badge" v-if="myinfo.is_vip > 0">VIP</text>
  18. </view>
  19. </view>
  20. <view class="navbar-right" @click="showActionSheet">
  21. <text class="fa fa-ellipsis-h"></text>
  22. </view>
  23. </view>
  24. <!-- 内容头图区域 -->
  25. <view class="topUser">
  26. <image :src="home_image" class="home_image" mode="aspectFill"></image>
  27. <!-- 图片指示器 -->
  28. <!-- <view class="image-indicator" v-if="image_list.length > 1">
  29. <text>{{ selImg + 1 }}/{{ image_list.length }}</text>
  30. </view> -->
  31. <!-- 音乐类型时显示歌词 -->
  32. <view class="lyrics-overlay" v-if="queueDetail.task_type == 2">
  33. <text class="lyrics-text">{{ queueDetail.description }}</text>
  34. </view>
  35. <!-- 音乐类型且状态为9时显示播放按钮 -->
  36. <view class="play-button" v-if="queueDetail.task_type == 2 && queueDetail.status >= 9" @click="toggleAudio">
  37. <text class="fa" :class="isPlaying ? 'fa-pause' : 'fa-play'"></text>
  38. </view>
  39. </view>
  40. <view class="body">
  41. <view class="article-header">
  42. <text class="title">{{ queueDetail.title }}</text>
  43. <view class="meta-info">
  44. <view class="meta-item">
  45. <text class="fa fa-clock-o"></text>
  46. <text class="meta-text">{{ queueDetail.create_time }}</text>
  47. </view>
  48. <view class="meta-item">
  49. <text class="fa fa-tag"></text>
  50. <text class="meta-text">{{ queueDetail.task_type == 1 ? '灵感创作' : '音乐创作' }}</text>
  51. </view>
  52. <view class="meta-item">
  53. <text class="fa fa-circle" :style="getStatusStyle(queueDetail.status)"></text>
  54. <text class="meta-text">{{ getStatusText(queueDetail.status) }}</text>
  55. </view>
  56. </view>
  57. </view>
  58. <view class="divider"></view>
  59. <view class="article-content">
  60. <!-- 灵感创作显示description -->
  61. <view v-if="queueDetail.task_type == 1">
  62. <text class="content">{{ queueDetail.description }}</text>
  63. </view>
  64. <!-- 音乐创作显示lyrics -->
  65. <view v-if="queueDetail.task_type == 2">
  66. <text class="content">{{ queueDetail.lyrics }}</text>
  67. </view>
  68. <!-- 显示创作详情 -->
  69. <view class="creation-details" v-if="queueDetail.task_type == 1">
  70. <view class="detail-item" v-if="queueDetail.action">
  71. <text class="detail-label">行为动作:</text>
  72. <text class="detail-value">{{ queueDetail.action }}</text>
  73. </view>
  74. <view class="detail-item" v-if="queueDetail.environment">
  75. <text class="detail-label">主体环境:</text>
  76. <text class="detail-value">{{ queueDetail.environment }}</text>
  77. </view>
  78. <view class="detail-item" v-if="queueDetail.subject">
  79. <text class="detail-label">主体形象:</text>
  80. <text class="detail-value">{{ queueDetail.subject }}</text>
  81. </view>
  82. <view class="detail-item" v-if="queueDetail.style">
  83. <text class="detail-label">参考风格:</text>
  84. <text class="detail-value">{{ queueDetail.style }}</text>
  85. </view>
  86. </view>
  87. <!-- 音乐创作显示歌曲名称 -->
  88. <view class="creation-details" v-if="queueDetail.task_type == 2">
  89. <view class="detail-item" v-if="queueDetail.song_name">
  90. <text class="detail-label">歌曲名称:</text>
  91. <text class="detail-value">{{ queueDetail.song_name }}</text>
  92. </view>
  93. </view>
  94. <!-- 显示状态信息 -->
  95. <view class="status-info" v-if="queueDetail.status < 4">
  96. <view class="queue-info">
  97. <text class="queue-text">队列位置:
  98. {{ queueDetail.queue_position }}/{{ queueDetail.all_position }}</text>
  99. <view class="progress-bar">
  100. <view class="progress-fill" :style="{ width: getProgressWidth() }"></view>
  101. </view>
  102. </view>
  103. </view>
  104. <!-- 显示错误信息 -->
  105. <view class="error-message" v-if="queueDetail.status == 3">
  106. <text class="error-text">{{ queueDetail.error_msg }}</text>
  107. </view>
  108. </view>
  109. </view>
  110. <view class="thread2"></view>
  111. <!-- 音频元素 -->
  112. <audio id="audioPlayer" :src="queueDetail.result_audio" style="display:none;"></audio>
  113. <!-- 底部漂浮栏 -->
  114. <view class="floating-bar" v-if="queueDetail.status == 9">
  115. <view class="floating-bar-content">
  116. <view class="add-note-btn" @click="showAddNotePopup">
  117. <text>添加说明</text>
  118. </view>
  119. <view class="publish-btn" @click="publishWork">
  120. <text>公布作品</text>
  121. </view>
  122. </view>
  123. </view>
  124. <!-- 添加说明弹窗 -->
  125. <view class="popup-mask" v-if="showNotePopup" @click="closeAddNotePopup"></view>
  126. <view class="note-popup" v-if="showNotePopup">
  127. <view class="popup-header">
  128. <text class="popup-title">添加说明</text>
  129. </view>
  130. <view class="popup-content">
  131. <textarea class="note-textarea" v-model="noteContent" placeholder="请描述你想添加的内容。"
  132. maxlength="500"></textarea>
  133. <view class="word-count">{{noteContent.length}}/500</view>
  134. </view>
  135. <view class="popup-footer">
  136. <view class="cancel-btn" @click="closeAddNotePopup">
  137. <text>取消</text>
  138. </view>
  139. <view class="confirm-btn" @click="confirmAddNote">
  140. <text>确认</text>
  141. </view>
  142. </view>
  143. </view>
  144. </view>
  145. </template>
  146. <script>
  147. import previewImage from '@/components/kxj-previewImage/kxj-previewImage.vue'; //引用插件
  148. export default {
  149. components: {
  150. previewImage
  151. },
  152. data() {
  153. return {
  154. title: '',
  155. arcID: 0,
  156. selImg: 0,
  157. home_image: '',
  158. myinfo: {},
  159. tag_list: [],
  160. image_list: [],
  161. imgs: [],
  162. descs: [],
  163. isPlaying: false,
  164. audioPlayer: null,
  165. showNotePopup: false,
  166. noteContent: '',
  167. // 队列详情数据
  168. queueDetail: {
  169. id: 0,
  170. sso_id: 0,
  171. task_type: 1,
  172. title: '',
  173. description: '',
  174. action: '',
  175. environment: '',
  176. subject: '',
  177. style: '',
  178. song_name: '',
  179. lyrics: '',
  180. generate_uuid: '',
  181. result_images: '',
  182. result_audio: '',
  183. queue_position: 0,
  184. status: 1,
  185. generate_status: 1,
  186. points_cost: 0,
  187. error_msg: '',
  188. create_time: '',
  189. update_time: '',
  190. all_position: 0
  191. },
  192. myinfo: {}
  193. }
  194. },
  195. onLoad(parms) {
  196. let self = this;
  197. this.arcID = parms.id || 3;
  198. this.getMyInfo();
  199. },
  200. onShow() {
  201. this.loadData();
  202. },
  203. onReady() {
  204. // 获取音频元素
  205. this.audioPlayer = uni.createInnerAudioContext();
  206. this.audioPlayer.onEnded(() => {
  207. this.isPlaying = false;
  208. });
  209. },
  210. onUnload() {
  211. // 页面卸载时停止音频播放
  212. if (this.audioPlayer) {
  213. this.audioPlayer.stop();
  214. this.audioPlayer.destroy();
  215. }
  216. },
  217. methods: {
  218. // 返回上一页
  219. goBack() {
  220. uni.navigateBack({
  221. delta: 1
  222. });
  223. },
  224. getMyInfo() {
  225. uni.request({
  226. url: this.$apiHost + '/My/getnum',
  227. method: 'GET',
  228. header: {
  229. 'content-type': 'application/json',
  230. 'sign': getApp().globalData.headerSign
  231. },
  232. data: {
  233. uuid: getApp().globalData.uuid
  234. },
  235. success: (res) => {
  236. console.log("获取用户信息:", res.data);
  237. this.myinfo = res.data
  238. }
  239. })
  240. },
  241. selPhoto(item, sel) {
  242. this.selImg = sel;
  243. this.home_image = this.image_list[sel];
  244. },
  245. toArr(imgs) {
  246. let arr = imgs.split("|");
  247. return arr;
  248. },
  249. previewOpen(imgs1, index) {
  250. this.imgs = imgs1.split("|");
  251. setTimeout(() => this.$refs.previewImage.open(index), 0)
  252. // 传入当前选中的图片地址或序号
  253. return; //如需测试和uni原生预览差别可注释这两行
  254. },
  255. // 切换音频播放状态
  256. toggleAudio() {
  257. if (!this.queueDetail.result_audio) return;
  258. if (this.isPlaying) {
  259. this.audioPlayer.pause();
  260. this.isPlaying = false;
  261. } else {
  262. this.audioPlayer.src = this.queueDetail.result_audio;
  263. this.audioPlayer.play();
  264. this.isPlaying = true;
  265. }
  266. },
  267. // 获取状态文本
  268. getStatusText(status) {
  269. const statusMap = {
  270. 1: '排队中',
  271. 2: '生成中',
  272. 3: '生成失败',
  273. 4: '已完成',
  274. 9: '已完成'
  275. };
  276. return statusMap[status] || '未知状态';
  277. },
  278. // 获取状态样式
  279. getStatusStyle(status) {
  280. const colorMap = {
  281. 1: '#ffa500', // 橙色 - 排队中
  282. 2: '#2979ff', // 蓝色 - 生成中
  283. 3: '#ff5151', // 红色 - 生成失败
  284. 4: '#4caf50', // 绿色 - 已完成
  285. 9: '#4caf50' // 绿色 - 已完成
  286. };
  287. return `color: ${colorMap[status] || '#999'}`;
  288. },
  289. // 获取进度条宽度
  290. getProgressWidth() {
  291. if (this.queueDetail.all_position === 0) return '0%';
  292. const progress = (1 - (this.queueDetail.queue_position / this.queueDetail.all_position)) * 100;
  293. return `${progress}%`;
  294. },
  295. // 加载数据
  296. loadData() {
  297. uni.showLoading({
  298. title: '加载中...'
  299. });
  300. uni.request({
  301. url: this.$apiHost + '/WorkAI/getQueueDetail',
  302. data: {
  303. uuid: getApp().globalData.uuid,
  304. id: this.arcID
  305. },
  306. header: {
  307. "content-type": "application/json",
  308. 'sign': getApp().globalData.headerSign
  309. },
  310. success: (res) => {
  311. console.log("队列详情:", res.data);
  312. if (res.data.success === "yes") {
  313. // 更新队列详情
  314. this.queueDetail = res.data.data;
  315. this.noteContent = res.data.data.content;
  316. // 更新图片列表
  317. if (this.queueDetail.result_images && this.queueDetail.result_images !== "") {
  318. this.image_list = this.queueDetail.result_images.split(",");
  319. this.home_image = this.image_list[0];
  320. } else {
  321. this.home_image = "../../static/home/avator.png";
  322. }
  323. // 如果是音频类型,设置音频源
  324. if (this.queueDetail.task_type == 2 && this.queueDetail.result_audio) {
  325. this.audioPlayer.src = this.queueDetail.result_audio;
  326. }
  327. } else {
  328. uni.showToast({
  329. title: '获取详情失败',
  330. icon: 'none'
  331. });
  332. }
  333. },
  334. complete: () => {
  335. uni.hideLoading();
  336. },
  337. fail: (e) => {
  338. console.log("请求失败:", e);
  339. uni.showToast({
  340. title: '网络请求失败',
  341. icon: 'none'
  342. });
  343. }
  344. });
  345. },
  346. showActionSheet() {
  347. // 显示操作列表
  348. uni.showActionSheet({
  349. itemList: ['修改封面', '删除作品'],
  350. success: (res) => {
  351. switch (res.tapIndex) {
  352. case 0:
  353. // 修改封面
  354. this.editCover();
  355. break;
  356. case 1:
  357. // 删除作品
  358. this.deleteWork();
  359. break;
  360. }
  361. },
  362. fail: (res) => {
  363. console.log(res.errMsg);
  364. }
  365. });
  366. },
  367. // 修改封面
  368. editCover() {
  369. var _self = this;
  370. uni.chooseImage({
  371. count: 1,
  372. sizeType: ['compressed'],
  373. sourceType: ['album', 'camera'],
  374. success: function(res) {
  375. console.log('res:', res)
  376. if (res.tempFilePaths.length > 0) {
  377. _self.imglocal = res.tempFilePaths[0]
  378. const tempFilePaths = res.tempFilePaths[0];
  379. console.log('tempFilePaths:', tempFilePaths);
  380. const uploadTask = uni.uploadFile({
  381. url: _self.$apiHost + '/Xweb/upload_img?skey=' + _self.skey,
  382. filePath: res.tempFilePaths[0],
  383. name: 'file',
  384. success: function(uploadFileRes) {
  385. let resdata = JSON.parse(uploadFileRes.data)
  386. console.log('Success11:', uploadFileRes);
  387. console.log('Success21:', resdata);
  388. if (resdata.success == 'yes') {
  389. _self.home_image = resdata.url;
  390. // 调用修改封面接口
  391. uni.request({
  392. url: _self.$apiHost + '/WorkAI/queueAction',
  393. method: 'GET',
  394. data: {
  395. uuid: getApp().globalData.uuid,
  396. act: 'editImg',
  397. result_images: resdata.url,
  398. id: _self.arcID
  399. },
  400. header: {
  401. 'content-type': 'application/json',
  402. 'sign': getApp().globalData.headerSign
  403. },
  404. success: (res) => {
  405. if (res.data.success === "yes") {
  406. uni.showToast({
  407. title: '修改封面成功',
  408. icon: 'success'
  409. });
  410. } else {
  411. uni.showToast({
  412. title: '修改封面失败',
  413. icon: 'none'
  414. });
  415. }
  416. },
  417. fail: () => {
  418. uni.showToast({
  419. title: '修改封面失败',
  420. icon: 'none'
  421. });
  422. }
  423. });
  424. }
  425. },
  426. fail: function(uploadFileFail) {
  427. console.log('Error:', uploadFileFail.data);
  428. uni.showToast({
  429. title: '图片上传失败',
  430. icon: 'none'
  431. });
  432. }
  433. });
  434. }
  435. },
  436. error: function(e) {
  437. console.log(e);
  438. uni.showToast({
  439. title: '选择图片失败',
  440. icon: 'none'
  441. });
  442. }
  443. });
  444. },
  445. // 删除作品
  446. deleteWork() {
  447. // 显示确认对话框
  448. uni.showModal({
  449. title: '确认删除',
  450. content: '确定要删除这个作品吗?',
  451. confirmColor: '#ff5151',
  452. success: (res) => {
  453. if (res.confirm) {
  454. // 用户点击确定,执行删除操作
  455. this.confirmDelete();
  456. }
  457. }
  458. });
  459. },
  460. // 确认删除
  461. confirmDelete() {
  462. uni.showLoading({
  463. title: '删除中...'
  464. });
  465. uni.request({
  466. url: this.$apiHost + '/WorkAI/queueAction',
  467. method: 'GET',
  468. data: {
  469. uuid: getApp().globalData.uuid,
  470. act: 'del',
  471. id: this.arcID
  472. },
  473. header: {
  474. 'content-type': 'application/json',
  475. 'sign': getApp().globalData.headerSign
  476. },
  477. success: (res) => {
  478. uni.hideLoading();
  479. if (res.data.success === "yes") {
  480. uni.showToast({
  481. title: '删除成功',
  482. icon: 'success'
  483. });
  484. // 删除成功后返回上一页
  485. setTimeout(() => {
  486. uni.navigateBack({
  487. delta: 1
  488. });
  489. }, 1500);
  490. } else {
  491. uni.showToast({
  492. title: '删除失败',
  493. icon: 'none'
  494. });
  495. }
  496. },
  497. fail: () => {
  498. uni.hideLoading();
  499. uni.showToast({
  500. title: '删除失败',
  501. icon: 'none'
  502. });
  503. }
  504. });
  505. },
  506. // 显示添加说明弹窗
  507. showAddNotePopup() {
  508. this.showNotePopup = true;
  509. },
  510. // 关闭添加说明弹窗
  511. closeAddNotePopup() {
  512. this.showNotePopup = false;
  513. },
  514. // 确认添加说明
  515. confirmAddNote() {
  516. if (!this.noteContent.trim()) {
  517. uni.showToast({
  518. title: '请输入说明内容',
  519. icon: 'none'
  520. });
  521. return;
  522. }
  523. uni.showLoading({
  524. title: '保存中...'
  525. });
  526. uni.request({
  527. url: this.$apiHost + '/WorkAI/queueAction',
  528. method: 'GET',
  529. data: {
  530. uuid: getApp().globalData.uuid,
  531. act: 'editContent',
  532. content: this.noteContent,
  533. id: this.arcID
  534. },
  535. header: {
  536. 'content-type': 'application/json',
  537. 'sign': getApp().globalData.headerSign
  538. },
  539. success: (res) => {
  540. uni.hideLoading();
  541. if (res.data.success === "yes") {
  542. uni.showToast({
  543. title: '添加说明成功',
  544. icon: 'success'
  545. });
  546. this.showNotePopup = false;
  547. // this.noteContent = '';
  548. // 重新加载数据
  549. this.loadData();
  550. } else {
  551. uni.showToast({
  552. title: '添加说明失败',
  553. icon: 'none'
  554. });
  555. }
  556. },
  557. fail: () => {
  558. uni.hideLoading();
  559. uni.showToast({
  560. title: '添加说明失败',
  561. icon: 'none'
  562. });
  563. }
  564. });
  565. },
  566. // 发布作品
  567. publishWork() {
  568. uni.showLoading({
  569. title: '发布中...'
  570. });
  571. uni.request({
  572. url: this.$apiHost + '/WorkAI/queueAction',
  573. method: 'GET',
  574. data: {
  575. uuid: getApp().globalData.uuid,
  576. act: 'fabu',
  577. id: this.arcID
  578. },
  579. header: {
  580. 'content-type': 'application/json',
  581. 'sign': getApp().globalData.headerSign
  582. },
  583. success: (res) => {
  584. console.log("resddd", res.data);
  585. uni.hideLoading();
  586. if (res.data.success === "yes") {
  587. uni.showToast({
  588. title: '发布成功',
  589. icon: 'success'
  590. });
  591. // 重新加载数据
  592. // this.loadData();
  593. } else {
  594. uni.showToast({
  595. title: res.data.str || '发布失败',
  596. icon: 'none'
  597. });
  598. }
  599. },
  600. fail: () => {
  601. uni.hideLoading();
  602. uni.showToast({
  603. title: '发布失败',
  604. icon: 'none'
  605. });
  606. }
  607. });
  608. }
  609. }
  610. }
  611. </script>
  612. <style scoped lang="scss">
  613. @import 'makeDetail.scss';
  614. </style>