makeMusicDetail.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  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="isRecharge ? 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" v-if="isRecharge">+</view>
  15. </view>
  16. <view class="coinC" @click="isRecharge ?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" v-if="isRecharge">+</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. 20
  107. </button>
  108. <view v-else class="generate-btn prohibit">生成中 </view>
  109. <view v-if="isRecharge" 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" v-if="isGuiding"></novice-guidance>
  117. </view>
  118. </template>
  119. <script>
  120. import { mapState } from 'vuex'
  121. export default {
  122. name: 'MakeMusicDetail',
  123. data() {
  124. return {
  125. songName: '',
  126. lyrics: '',
  127. selectedTags: {
  128. emotion: [],
  129. genre: [],
  130. era: [],
  131. instrument: []
  132. },
  133. textareaHeight: 120,
  134. minHeight: 120,
  135. selectedTab: 'emotion',
  136. tagOptions: {
  137. emotion: ['欢快', '悲伤', '积极', '浪漫', '忧郁', '华丽', '闪耀', '神秘', '惊怒', '紧张', '恐怖', '平静'],
  138. genre: ['流行', '摇滚', '民谣', '电子', 'R&B', '嘻哈', '古典', '爵士'],
  139. era: ['80年代', '90年代', '00年代', '10年代', '20年代'],
  140. instrument: ['钢琴', '吉他', '贝斯', '鼓', '小提琴', '萨克斯', '电子合成器']
  141. },
  142. inQueue: false,//是否创作中
  143. queuing: false,//是否排队中
  144. queueMessage: '',
  145. myinfo: {},
  146. step: {
  147. name: "makeMusicGuide",
  148. guideList: [
  149. {
  150. el: ".right",
  151. tips: "积分可在这里查看,每日签到可获得积分!",
  152. next: "知道了",
  153. },
  154. {
  155. el: ".input-field",
  156. tips: "在这里输入您想要创作的歌曲名称",
  157. next: "知道了",
  158. },
  159. {
  160. el: ".textarea-field",
  161. tips: "在这里输入歌词内容,AI将根据歌词生成音乐",
  162. next: "知道了",
  163. },
  164. {
  165. el: ".tabs",
  166. tips: "选择音乐风格,包括情感、流派、年代和乐器",
  167. next: "知道了",
  168. },
  169. {
  170. el: ".tags",
  171. tips: "点击选择具体的风格标签,可以多选",
  172. next: "知道了",
  173. },
  174. {
  175. el: ".generate-btn",
  176. tips: "点击这里开始生成您的音乐作品",
  177. next: "完成",
  178. }]
  179. }
  180. }
  181. },
  182. onLoad(e) {
  183. // this.checkQueueStatus();
  184. this.getMyInfo();
  185. if (e.id) {
  186. this.getQueueDetail(e.id)
  187. }
  188. },
  189. computed: {
  190. currentTags() {
  191. return this.selectedTab ? this.tagOptions[this.selectedTab] : [];
  192. },
  193. ...mapState('switchingModule', ['isRecharge', 'isGuiding'])
  194. },
  195. methods: {
  196. doYouWantToEdit() {
  197. return this.inQueue || this.queuing
  198. },
  199. goBack() {
  200. uni.navigateBack({
  201. delta: 1
  202. });
  203. },
  204. getMyInfo() {
  205. uni.request({
  206. url: this.$apiHost + '/My/getnum',
  207. method: 'GET',
  208. header: {
  209. 'content-type': 'application/json',
  210. 'sign': getApp().globalData.headerSign
  211. },
  212. data: {
  213. uuid: getApp().globalData.uuid
  214. },
  215. success: (res) => {
  216. console.log("获取用户信息:", res.data);
  217. this.myinfo = res.data
  218. }
  219. })
  220. },
  221. checkQueueStatus() {
  222. uni.request({
  223. url: this.$apiHost + '/WorkAI/queueStatus',
  224. method: 'GET',
  225. header: {
  226. 'content-type': 'application/json',
  227. 'sign': getApp().globalData.headerSign
  228. },
  229. data: {
  230. uuid: getApp().globalData.uuid,
  231. task_type: 2
  232. },
  233. success: (res) => {
  234. console.log("音乐队列状态:", res.data);
  235. if (res.data.success === "yes") {
  236. this.inQueue = res.data.in_queue
  237. if (this.inQueue) {
  238. this.queueMessage = res.data.str
  239. }
  240. }
  241. },
  242. fail: (err) => {
  243. console.log('获取队列状态失败:', err);
  244. uni.showToast({
  245. title: '获取状态失败',
  246. icon: 'none'
  247. });
  248. }
  249. })
  250. this.getMyInfo();
  251. },
  252. generateMusic() {
  253. if (!this.songName.trim()) {
  254. uni.showToast({
  255. title: '请输入歌曲名称',
  256. icon: 'none'
  257. })
  258. return
  259. }
  260. if (!this.lyrics.trim()) {
  261. uni.showToast({
  262. title: '请输入歌词内容',
  263. icon: 'none'
  264. })
  265. return
  266. }
  267. // 合并所有选中的标签
  268. let allSelectedTags = [
  269. ...this.selectedTags.emotion,
  270. ...this.selectedTags.genre,
  271. ...this.selectedTags.era,
  272. ...this.selectedTags.instrument
  273. ];
  274. console.log(this.lyrics, this.songName,);
  275. let that = this
  276. uni.request({
  277. url: this.$apiHost + '/WorkAI/creatorMusic',
  278. data: {
  279. uuid: getApp().globalData.uuid,
  280. name: this.songName,
  281. lyrics: this.lyrics,
  282. style: allSelectedTags.join(',')
  283. },
  284. method: 'POST',
  285. header: {
  286. 'Content-Type': 'application/x-www-form-urlencoded',
  287. 'sign': getApp().globalData.headerSign
  288. },
  289. dataType: 'json',
  290. success: (res) => {
  291. console.log("生成结果:", res.data);
  292. uni.showToast({
  293. title: res.data.str || '请求成功',
  294. icon: 'none'
  295. });
  296. if (res.data.success == "yes") {
  297. setTimeout(function () {
  298. // that.checkQueueStatus()
  299. //返回上一页
  300. // uni.navigateBack()
  301. // 使用全局变量存储状态
  302. getApp().globalData.needSwitchToGenerating = true;
  303. uni.switchTab({ url: '/pages/my/my' });
  304. }, 1500);
  305. }
  306. },
  307. fail: (err) => {
  308. console.log('生成失败:', err);
  309. uni.showToast({
  310. title: '生成请求失败',
  311. icon: 'none'
  312. });
  313. }
  314. })
  315. },
  316. onTextareaInput(e) {
  317. const lineHeight = 20; // 假设每行高度为20px
  318. const padding = 30; // 上下padding各15px
  319. const value = e.detail.value;
  320. const lines = value.split('\n').length;
  321. // 计算每行的平均字符数
  322. const avgCharsPerLine = 30; // 根据实际输入框宽度调整
  323. const textLines = Math.ceil(value.length / avgCharsPerLine);
  324. // 取行数的最大值,确保有足够空间显示
  325. const totalLines = Math.max(lines, textLines);
  326. const newHeight = Math.max(totalLines * lineHeight + padding, this.minHeight);
  327. this.textareaHeight = newHeight;
  328. },
  329. selectTab(tab) {
  330. if (this.selectedTab !== tab) {
  331. this.selectedTab = tab;
  332. // 不再清空已选择的标签
  333. }
  334. },
  335. state() {
  336. if (this.inQueue) {
  337. uni.showToast({
  338. title: '正在创作中无法修改',
  339. icon: 'none'
  340. })
  341. } else if (this.queuing) {
  342. uni.showToast({
  343. title: '正在排队中无法修改',
  344. icon: 'none'
  345. })
  346. }
  347. },
  348. toggleTag(tag) {
  349. if (this.selectedTags[this.selectedTab].includes(tag)) {
  350. this.selectedTags[this.selectedTab] = this.selectedTags[this.selectedTab].filter(t => t !== tag);
  351. } else {
  352. // 计算所有已选标签的总数
  353. const totalSelectedTags = Object.values(this.selectedTags).reduce((total, tags) => total + tags.length, 0);
  354. if (totalSelectedTags >= 5) {
  355. uni.showToast({
  356. title: '最多只能选择5个标签',
  357. icon: 'none'
  358. });
  359. return;
  360. }
  361. this.selectedTags[this.selectedTab].push(tag);
  362. }
  363. },
  364. getQueueDetail(id) {
  365. if (!id) {
  366. return
  367. }
  368. let that = this
  369. uni.request({
  370. url: this.$apiHost + '/WorkAI/getQueueDetail',
  371. data: {
  372. uuid: getApp().globalData.uuid,
  373. id: id
  374. },
  375. header: {
  376. 'Content-Type': 'application/x-www-form-urlencoded',
  377. 'sign': getApp().globalData.headerSign
  378. },
  379. dataType: 'json',
  380. success: (res) => {
  381. console.log("查询单个结果:", res.data);
  382. if (res.data.success == "yes") {
  383. var { queuePosition, allPosition, song_name, lyrics, style } = res.data.data
  384. that.songName = song_name
  385. that.lyrics = lyrics
  386. const styles = style.split(',');
  387. styles.forEach(tag => {
  388. for (const [key, tags] of Object.entries(that.tagOptions)) {
  389. if (tags.includes(tag)) {
  390. that.selectedTags[key].push(tag);
  391. break;
  392. }
  393. }
  394. });
  395. if (queuePosition == allPosition) {
  396. // 创作中逻辑
  397. that.inQueue = true
  398. } else if (queuePosition < allPosition) {
  399. // 排队中逻辑
  400. that.queuing = true
  401. }
  402. }
  403. },
  404. fail: (err) => {
  405. console.log('查询失败失败:', err);
  406. uni.showToast({
  407. title: '查询失败请求失败',
  408. icon: 'none'
  409. });
  410. }
  411. })
  412. },
  413. goPage(page) {
  414. uni.navigateTo({
  415. url: page,
  416. });
  417. },
  418. }
  419. }
  420. </script>
  421. <style lang="scss">
  422. @import './makeMusicDetail.scss';
  423. </style>