四零语境前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

192 lines
3.9 KiB

  1. <template>
  2. <view class="music-container">
  3. <!-- 音色列表 -->
  4. <view class="voice-list">
  5. <view
  6. v-for="(voice, index) in voiceList"
  7. :key="voice.voiceType"
  8. class="voice-item"
  9. :class="{ 'selected': voice.voiceType === selectedVoiceId }"
  10. @click="selectVoice(voice.voiceType)"
  11. >
  12. <view class="voice-avatar">
  13. <view class="play-icon">
  14. <uv-icon
  15. :name="voice.voiceType === selectedVoiceId ? 'pause' : 'play-right-fill'"
  16. size="24"
  17. color="#666666"
  18. ></uv-icon>
  19. </view>
  20. </view>
  21. <view class="voice-info">
  22. <view class="voice-name">{{ voice.name }}</view>
  23. <view class="voice-desc">{{ voice.info }}</view>
  24. </view>
  25. <view v-if="voice.voiceType === selectedVoiceId" class="selected-tag">
  26. 已选择
  27. </view>
  28. </view>
  29. </view>
  30. <!-- 底部固定确认按钮 -->
  31. <view class="bottom-bar">
  32. <uv-button
  33. type="primary"
  34. text="确定"
  35. :custom-style="{
  36. width: '100%',
  37. height: '82rpx',
  38. borderRadius: '44rpx',
  39. backgroundColor: '#06DADC',
  40. fontSize: '36rpx',
  41. fontWeight: '500',
  42. border: '1px solid #06DADC'
  43. }"
  44. @click="confirmSelection"
  45. ></uv-button>
  46. <uv-safe-bottom></uv-safe-bottom>
  47. </view>
  48. </view>
  49. </template>
  50. <script>
  51. export default {
  52. data() {
  53. return {
  54. selectedVoiceId: '', // 默认选择智小虎
  55. voiceList: [
  56. ]
  57. }
  58. },
  59. methods: {
  60. goBack() {
  61. uni.navigateBack()
  62. },
  63. selectVoice(voiceId) {
  64. this.selectedVoiceId = voiceId
  65. console.log('选择音色:', voiceId)
  66. uni.$emit('selectVoice', voiceId)
  67. },
  68. confirmSelection() {
  69. console.log('确认选择音色:', this.selectedVoiceId)
  70. // 这里可以保存选择的音色到本地存储或发送到服务器
  71. uni.navigateBack()
  72. },
  73. async getVoice(){
  74. const listRes = await this.$api.music.list()
  75. if (listRes.code === 200) {
  76. this.voiceList = listRes.result
  77. }
  78. }
  79. },
  80. onLoad(options) {
  81. this.selectedVoiceId = Number(options.voiceId)
  82. console.log( 'options.voiceId', options.voiceId );
  83. this.getVoice()
  84. }
  85. }
  86. </script>
  87. <style scoped lang="scss">
  88. .music-container {
  89. background: #fff;
  90. min-height: 100vh;
  91. display: flex;
  92. flex-direction: column;
  93. padding-bottom: 120rpx;
  94. }
  95. .voice-list {
  96. flex: 1;
  97. padding: 40rpx 32rpx 120rpx;
  98. display: flex;
  99. flex-direction: column;
  100. gap: 32rpx;
  101. }
  102. .voice-item {
  103. display: flex;
  104. align-items: center;
  105. padding: 32rpx 0;
  106. border-bottom: 4rpx solid #F8F8F8;
  107. position: relative;
  108. background: #F8F8F8;
  109. gap: 12px;
  110. opacity: 1;
  111. border-radius: 8px;
  112. padding: 8px;
  113. transition: all 0.3s ease;
  114. &:last-child {
  115. border-bottom: none;
  116. }
  117. &.selected {
  118. border-bottom: 4rpx solid $primary-color;
  119. }
  120. }
  121. .voice-avatar {
  122. width: 136rpx;
  123. height: 136rpx;
  124. border-radius: 50%;
  125. background: #666;
  126. display: flex;
  127. align-items: center;
  128. justify-content: center;
  129. // margin-right: 32rpx;
  130. position: relative;
  131. }
  132. .play-icon {
  133. display: flex;
  134. width: 60rpx;
  135. height: 60rpx;
  136. border-radius: 100rpx;
  137. background: white;
  138. align-items: center;
  139. justify-content: center;
  140. }
  141. .voice-info {
  142. flex: 1;
  143. }
  144. .voice-name {
  145. font-family: PingFang SC;
  146. font-weight: 600;
  147. font-size: 36rpx;
  148. color: #262626;
  149. margin-bottom: 8rpx;
  150. }
  151. .voice-desc {
  152. font-family: PingFang SC;
  153. font-weight: 400;
  154. font-size: 28rpx;
  155. color: #999;
  156. }
  157. .selected-tag {
  158. background: $primary-color;
  159. color: #fff;
  160. font-size: 24rpx;
  161. padding: 8rpx 16rpx;
  162. border-radius: 20rpx;
  163. font-family: PingFang SC;
  164. font-weight: 500;
  165. }
  166. .bottom-bar {
  167. position: fixed;
  168. bottom: 0;
  169. left: 0;
  170. right: 0;
  171. background: #fff;
  172. padding: 24rpx 50rpx;
  173. z-index: 999;
  174. border-top: 2rpx solid #F1F1F1
  175. }
  176. </style>