makeMusicDetail.vue 11 KB

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