makeMusicDetail.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. <template>
  2. <view class="make-music-detail">
  3. <!-- 顶部导航 -->
  4. <view class="nav-bar">
  5. <view class="left">
  6. <view class="uni-btn-icon" @click="goBack">&#xe601;</view>
  7. <view class="create">音乐制作</view>
  8. <image src="@/static/makedetail/cz_icon_lingganchuangzuo.png" class="edit"></image>
  9. </view>
  10. <view class="right">
  11. <view class="coinM" @click="goPage('/pages/vip/M_purchase')">
  12. <image src="/static/icon/coin_m.png" mode="aspectFit"></image>
  13. <text>{{ myinfo.num_gmm | formatNumberToK }}</text>
  14. <view class="money-add">+</view>
  15. </view>
  16. <view class="coinC" @click="goPage('/pages/my/job?type=recharge')">
  17. <image src="/static/icon/coin_cd.png" mode="aspectFit"></image>
  18. <text>{{ myinfo.num_gmd | formatNumberToK }}</text>
  19. <view class="money-add">+</view>
  20. </view>
  21. </view>
  22. </view>
  23. <!-- 排队预览区域 -->
  24. <view class="preview-section lineUp-section" v-if="queuing">
  25. <view class="section-title">
  26. <text>创作预览</text>
  27. <view class="member-box">
  28. <image src="@/static/makedetail/wd_icon_vip(1).png" mode="aspectFit"></image>
  29. 升级会员插队加速
  30. </view>
  31. </view>
  32. <view class="preview-card">
  33. <image src="@/static/makedetail/cz_icon_jiazai.png" mode="aspectFit"></image>
  34. <view class="text1">{{ queueMessage }}</view>
  35. <view class="text2">退出不影响继续生成</view>
  36. </view>
  37. </view>
  38. <!-- 创作预览区域 -->
  39. <view class="preview-section" v-if="inQueue">
  40. <view class="section-title">创作预览</view>
  41. <view class="preview-card">
  42. <image src="@/static/makedetail/cz_icon_shengcheng.png" mode="aspectFit"></image>
  43. <view class="text1">生成中0%</view>
  44. <view class="text2">退出不影响继续生成</view>
  45. </view>
  46. </view>
  47. <!-- 主要内容区 -->
  48. <view class="content">
  49. <!-- 歌曲名称输入 -->
  50. <view class="input-section">
  51. <text class="label">歌曲名称</text>
  52. <input type="text" placeholder="请输入名称..." class="input-field" maxlength="30" v-model="songName"
  53. :disabled="doYouWantToEdit()" />
  54. <text class="count lyricCount">{{ songName.length }}/30</text>
  55. </view>
  56. <!-- 创作歌词输入 -->
  57. <view class="input-section">
  58. <text class="label">创作歌词</text>
  59. <textarea placeholder="请在此处输入您想要进行联想的内容或者歌词" class="textarea-field" maxlength="800" v-model="lyrics"
  60. :disabled="doYouWantToEdit()" :style="{ height: textareaHeight + 'px' }" @input="onTextareaInput" />
  61. <view class="textarea-footer">
  62. <text class="count">{{ lyrics.length }}/800</text>
  63. <text class="ai-btn" v-if="false">
  64. <image src="@/static/makedetail/cz_btn_airunse.png"></image>
  65. </text>
  66. </view>
  67. </view>
  68. <!-- 音乐风格选择 -->
  69. <view class="style-section">
  70. <text class="label">音乐风格</text>
  71. <view class="tabs">
  72. <text :class="{ 'active': selectedTab === 'emotion' }" @click="selectTab('emotion')">
  73. 情感
  74. <view class="indicator-triangle">
  75. </view>
  76. </text>
  77. <text :class="{ 'active': selectedTab === 'genre' }" @click="selectTab('genre')">
  78. 流派
  79. <view class="indicator-triangle">
  80. </view>
  81. </text>
  82. <text :class="{ 'active': selectedTab === 'era' }" @click="selectTab('era')">
  83. 年代
  84. <view class="indicator-triangle">
  85. </view>
  86. </text>
  87. <text :class="{ 'active': selectedTab === 'instrument' }" @click="selectTab('instrument')">
  88. 乐器
  89. <view class="indicator-triangle">
  90. </view>
  91. </text>
  92. </view>
  93. <view class="tags">
  94. <text v-for="(tag, index) in currentTags" :key="index"
  95. :class="['tag', { active: selectedTags[selectedTab].includes(tag) }]"
  96. @click="doYouWantToEdit() ? state() : toggleTag(tag)">
  97. {{ tag }}
  98. </text>
  99. </view>
  100. </view>
  101. </view>
  102. <!-- 底部按钮 -->
  103. <view class="bottom-button">
  104. <button v-if="doYouWantToEdit" class="generate-btn" @click="generateMusic">立即生成
  105. <image src="/static/icon/coin_cd.png" mode="aspectFit"></image>
  106. 10
  107. </button>
  108. <view v-else class="generate-btn prohibit">生成中 </view>
  109. <view class="promotion-link" @click="goPage('/pages/vip/index')">
  110. <image class="vip" src="/static/makedetail/wd_icon_vip(1).png" mode="aspectFit"></image>
  111. <text> 即刻开通订阅,获取各种福利! </text>
  112. <image class="jiantou" src="/static/makedetail/cz_icon_jiantou.png" mode="aspectFit"></image>
  113. </view>
  114. </view>
  115. <!-- 新手引导组件 -->
  116. <novice-guidance :step="step"></novice-guidance>
  117. </view>
  118. </template>
  119. <script>
  120. export default {
  121. name: 'MakeMusicDetail',
  122. data() {
  123. return {
  124. songName: '',
  125. lyrics: '',
  126. selectedTags: {
  127. emotion: [],
  128. genre: [],
  129. era: [],
  130. instrument: []
  131. },
  132. textareaHeight: 120,
  133. minHeight: 120,
  134. selectedTab: 'emotion',
  135. tagOptions: {
  136. emotion: ['欢快', '悲伤', '积极', '浪漫', '忧郁', '华丽', '闪耀', '神秘', '惊怒', '紧张', '恐怖', '平静'],
  137. genre: ['流行', '摇滚', '民谣', '电子', 'R&B', '嘻哈', '古典', '爵士'],
  138. era: ['80年代', '90年代', '00年代', '10年代', '20年代'],
  139. instrument: ['钢琴', '吉他', '贝斯', '鼓', '小提琴', '萨克斯', '电子合成器']
  140. },
  141. inQueue: false,//是否创作中
  142. queuing: false,//是否排队中
  143. queueMessage: '',
  144. myinfo: {},
  145. step: {
  146. name: "makeMusicGuide",
  147. guideList: [
  148. {
  149. el: ".right",
  150. tips: "积分可在这里查看,每日签到可获得积分!",
  151. next: "知道了",
  152. },
  153. {
  154. el: ".input-field",
  155. tips: "在这里输入您想要创作的歌曲名称",
  156. next: "知道了",
  157. },
  158. {
  159. el: ".textarea-field",
  160. tips: "在这里输入歌词内容,AI将根据歌词生成音乐",
  161. next: "知道了",
  162. },
  163. {
  164. el: ".tabs",
  165. tips: "选择音乐风格,包括情感、流派、年代和乐器",
  166. next: "知道了",
  167. },
  168. {
  169. el: ".tags",
  170. tips: "点击选择具体的风格标签,可以多选",
  171. next: "知道了",
  172. },
  173. {
  174. el: ".generate-btn",
  175. tips: "点击这里开始生成您的音乐作品",
  176. next: "完成",
  177. }]
  178. }
  179. }
  180. },
  181. onLoad(e) {
  182. // this.checkQueueStatus();
  183. this.getMyInfo();
  184. if (e.id) {
  185. this.getQueueDetail(e.id)
  186. }
  187. },
  188. computed: {
  189. currentTags() {
  190. return this.selectedTab ? this.tagOptions[this.selectedTab] : [];
  191. }
  192. },
  193. methods: {
  194. doYouWantToEdit() {
  195. return this.inQueue || this.queuing
  196. },
  197. goBack() {
  198. uni.navigateBack({
  199. delta: 1
  200. });
  201. },
  202. getMyInfo() {
  203. uni.request({
  204. url: this.$apiHost + '/My/getnum',
  205. method: 'GET',
  206. header: {
  207. 'content-type': 'application/json',
  208. 'sign': getApp().globalData.headerSign
  209. },
  210. data: {
  211. uuid: getApp().globalData.uuid
  212. },
  213. success: (res) => {
  214. console.log("获取用户信息:", res.data);
  215. this.myinfo = res.data
  216. }
  217. })
  218. },
  219. checkQueueStatus() {
  220. uni.request({
  221. url: this.$apiHost + '/WorkAI/queueStatus',
  222. method: 'GET',
  223. header: {
  224. 'content-type': 'application/json',
  225. 'sign': getApp().globalData.headerSign
  226. },
  227. data: {
  228. uuid: getApp().globalData.uuid,
  229. task_type: 2
  230. },
  231. success: (res) => {
  232. console.log("音乐队列状态:", res.data);
  233. if (res.data.success === "yes") {
  234. this.inQueue = res.data.in_queue
  235. if (this.inQueue) {
  236. this.queueMessage = res.data.str
  237. }
  238. }
  239. },
  240. fail: (err) => {
  241. console.log('获取队列状态失败:', err);
  242. uni.showToast({
  243. title: '获取状态失败',
  244. icon: 'none'
  245. });
  246. }
  247. })
  248. this.getMyInfo();
  249. },
  250. generateMusic() {
  251. if (!this.songName.trim()) {
  252. uni.showToast({
  253. title: '请输入歌曲名称',
  254. icon: 'none'
  255. })
  256. return
  257. }
  258. if (!this.lyrics.trim()) {
  259. uni.showToast({
  260. title: '请输入歌词内容',
  261. icon: 'none'
  262. })
  263. return
  264. }
  265. // 合并所有选中的标签
  266. let allSelectedTags = [
  267. ...this.selectedTags.emotion,
  268. ...this.selectedTags.genre,
  269. ...this.selectedTags.era,
  270. ...this.selectedTags.instrument
  271. ];
  272. console.log(this.lyrics, this.songName,);
  273. let that = this
  274. uni.request({
  275. url: this.$apiHost + '/WorkAI/creatorMusic',
  276. data: {
  277. uuid: getApp().globalData.uuid,
  278. name: this.songName,
  279. lyrics: this.lyrics,
  280. style: allSelectedTags.join(',')
  281. },
  282. method: 'POST',
  283. header: {
  284. 'Content-Type': 'application/x-www-form-urlencoded',
  285. 'sign': getApp().globalData.headerSign
  286. },
  287. dataType: 'json',
  288. success: (res) => {
  289. console.log("生成结果:", res.data);
  290. uni.showToast({
  291. title: res.data.str || '请求成功',
  292. icon: 'none'
  293. });
  294. if (res.data.success == "yes") {
  295. setTimeout(function () {
  296. // that.checkQueueStatus()
  297. //返回上一页
  298. // uni.navigateBack()
  299. // 使用全局变量存储状态
  300. getApp().globalData.needSwitchToGenerating = true;
  301. uni.switchTab({ url: '/pages/my/my' });
  302. }, 1500);
  303. }
  304. },
  305. fail: (err) => {
  306. console.log('生成失败:', err);
  307. uni.showToast({
  308. title: '生成请求失败',
  309. icon: 'none'
  310. });
  311. }
  312. })
  313. },
  314. onTextareaInput(e) {
  315. const lineHeight = 20; // 假设每行高度为20px
  316. const padding = 30; // 上下padding各15px
  317. const value = e.detail.value;
  318. const lines = value.split('\n').length;
  319. // 计算每行的平均字符数
  320. const avgCharsPerLine = 30; // 根据实际输入框宽度调整
  321. const textLines = Math.ceil(value.length / avgCharsPerLine);
  322. // 取行数的最大值,确保有足够空间显示
  323. const totalLines = Math.max(lines, textLines);
  324. const newHeight = Math.max(totalLines * lineHeight + padding, this.minHeight);
  325. this.textareaHeight = newHeight;
  326. },
  327. selectTab(tab) {
  328. if (this.selectedTab !== tab) {
  329. this.selectedTab = tab;
  330. // 不再清空已选择的标签
  331. }
  332. },
  333. state() {
  334. if (this.inQueue) {
  335. uni.showToast({
  336. title: '正在创作中无法修改',
  337. icon: 'none'
  338. })
  339. } else if (this.queuing) {
  340. uni.showToast({
  341. title: '正在排队中无法修改',
  342. icon: 'none'
  343. })
  344. }
  345. },
  346. toggleTag(tag) {
  347. if (this.selectedTags[this.selectedTab].includes(tag)) {
  348. this.selectedTags[this.selectedTab] = this.selectedTags[this.selectedTab].filter(t => t !== tag);
  349. } else {
  350. this.selectedTags[this.selectedTab].push(tag);
  351. }
  352. },
  353. getQueueDetail(id) {
  354. if (!id) {
  355. return
  356. }
  357. let that = this
  358. uni.request({
  359. url: this.$apiHost + '/WorkAI/getQueueDetail',
  360. data: {
  361. uuid: getApp().globalData.uuid,
  362. id: id
  363. },
  364. header: {
  365. 'Content-Type': 'application/x-www-form-urlencoded',
  366. 'sign': getApp().globalData.headerSign
  367. },
  368. dataType: 'json',
  369. success: (res) => {
  370. console.log("查询单个结果:", res.data);
  371. if (res.data.success == "yes") {
  372. var { queuePosition, allPosition, song_name, lyrics, style } = res.data.data
  373. that.songName = song_name
  374. that.lyrics = lyrics
  375. const styles = style.split(',');
  376. styles.forEach(tag => {
  377. for (const [key, tags] of Object.entries(that.tagOptions)) {
  378. if (tags.includes(tag)) {
  379. that.selectedTags[key].push(tag);
  380. break;
  381. }
  382. }
  383. });
  384. if (queuePosition == allPosition) {
  385. // 创作中逻辑
  386. that.inQueue = true
  387. } else if (queuePosition < allPosition) {
  388. // 排队中逻辑
  389. that.queuing = true
  390. }
  391. }
  392. },
  393. fail: (err) => {
  394. console.log('查询失败失败:', err);
  395. uni.showToast({
  396. title: '查询失败请求失败',
  397. icon: 'none'
  398. });
  399. }
  400. })
  401. },
  402. goPage(page) {
  403. uni.navigateTo({
  404. url: page,
  405. });
  406. },
  407. }
  408. }
  409. </script>
  410. <style lang="scss">
  411. @import './makeMusicDetail.scss';
  412. </style>