makeMusicDetail.vue 12 KB

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