makeMusicDetail.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <template>
  2. <view class="make-music-detail">
  3. <!-- 顶部导航 -->
  4. <view class="nav-header">
  5. <view class="back-icon">
  6. <text class="iconfont icon-left"></text>
  7. </view>
  8. <view class="right-info">
  9. <view class="coin-box">
  10. <image src="/static/images/coin.png" mode="aspectFit" class="coin-icon" />
  11. <text>999</text>
  12. </view>
  13. <view class="diamond-box">
  14. <image src="/static/images/diamond.png" mode="aspectFit" class="diamond-icon" />
  15. <text>2</text>
  16. </view>
  17. </view>
  18. </view>
  19. <!-- 主要内容区 -->
  20. <view class="content">
  21. <!-- 歌曲名称输入 -->
  22. <view class="input-section">
  23. <text class="label">歌曲名称</text>
  24. <input type="text" placeholder="请输入名称..." class="input-field" maxlength="30" v-model="songName" />
  25. <text class="count">{{songName.length}}/30</text>
  26. </view>
  27. <!-- 创作歌词输入 -->
  28. <view class="input-section">
  29. <text class="label">创作歌词</text>
  30. <textarea
  31. placeholder="请在此处输入您想要进行联想的内容或者歌词"
  32. class="textarea-field"
  33. maxlength="800"
  34. v-model="lyrics"
  35. :style="{height: textareaHeight + 'px'}"
  36. @input="onTextareaInput"
  37. />
  38. <view class="textarea-footer">
  39. <text class="count">{{lyrics.length}}/800</text>
  40. <text class="ai-btn">AI润词</text>
  41. </view>
  42. </view>
  43. <!-- 音乐风格选择 -->
  44. <view class="style-section">
  45. <text class="label">音乐风格</text>
  46. <view class="tabs">
  47. <text :class="{'active': selectedTab === 'emotion'}" @click="selectTab('emotion')">情感</text>
  48. <text :class="{'active': selectedTab === 'genre'}" @click="selectTab('genre')">流派</text>
  49. <text :class="{'active': selectedTab === 'era'}" @click="selectTab('era')">年代</text>
  50. <text :class="{'active': selectedTab === 'instrument'}" @click="selectTab('instrument')">乐器</text>
  51. </view>
  52. <view class="tags">
  53. <text
  54. v-for="(tag, index) in currentTags"
  55. :key="index"
  56. :class="['tag', { active: selectedTags.includes(tag) }]"
  57. @click="toggleTag(tag)"
  58. >
  59. {{tag}}
  60. </text>
  61. </view>
  62. </view>
  63. </view>
  64. <!-- 底部按钮 -->
  65. <view class="bottom-section">
  66. <button class="submit-btn">立即生成<text class="small">(需消耗10枚豆)</text></button>
  67. <view class="promotion-text">
  68. <text class="link-text">>即刻开通订阅,我取各种福利<</text>
  69. </view>
  70. </view>
  71. </view>
  72. </template>
  73. <script>
  74. export default {
  75. name: 'MakeMusicDetail',
  76. data() {
  77. return {
  78. songName: '',
  79. lyrics: '',
  80. selectedTags: [],
  81. textareaHeight: 120,
  82. minHeight: 120,
  83. selectedTab: 'emotion',
  84. tagOptions: {
  85. emotion: ['欢快', '悲伤', '积极', '浪漫', '忧郁', '华丽', '闪耀', '神秘', '惊怒', '紧张', '恐怖', '平静'],
  86. genre: ['流行', '摇滚', '民谣', '电子', 'R&B', '嘻哈', '古典', '爵士'],
  87. era: ['80年代', '90年代', '00年代', '10年代', '20年代'],
  88. instrument: ['钢琴', '吉他', '贝斯', '鼓', '小提琴', '萨克斯', '电子合成器']
  89. }
  90. }
  91. },
  92. computed: {
  93. currentTags() {
  94. return this.selectedTab ? this.tagOptions[this.selectedTab] : [];
  95. }
  96. },
  97. methods: {
  98. onTextareaInput(e) {
  99. const lineHeight = 20; // 假设每行高度为20px
  100. const padding = 30; // 上下padding各15px
  101. const value = e.detail.value;
  102. const lines = value.split('\n').length;
  103. // 计算每行的平均字符数
  104. const avgCharsPerLine = 30; // 根据实际输入框宽度调整
  105. const textLines = Math.ceil(value.length / avgCharsPerLine);
  106. // 取行数的最大值,确保有足够空间显示
  107. const totalLines = Math.max(lines, textLines);
  108. const newHeight = Math.max(totalLines * lineHeight + padding, this.minHeight);
  109. this.textareaHeight = newHeight;
  110. },
  111. selectTab(tab) {
  112. if (this.selectedTab === tab) {
  113. this.selectedTab = '';
  114. } else {
  115. this.selectedTab = tab;
  116. }
  117. // 切换标签时清空已选择的标签
  118. this.selectedTags = [];
  119. },
  120. toggleTag(tag) {
  121. if (this.selectedTags.includes(tag)) {
  122. this.selectedTags = this.selectedTags.filter(t => t !== tag);
  123. } else {
  124. this.selectedTags.push(tag);
  125. }
  126. }
  127. }
  128. }
  129. </script>
  130. <style lang="scss">
  131. @import './makeMusicDetail.scss';
  132. </style>