四零语境前端代码仓库
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.

191 lines
3.8 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="selectedVoiceId = 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() {
  64. console.log('选择音色:', this.selectedVoiceId)
  65. uni.$emit('selectVoice', this.selectedVoiceId)
  66. uni.navigateBack()
  67. },
  68. confirmSelection() {
  69. this.selectVoice(this.selectedVoiceId)
  70. // 这里可以保存选择的音色到本地存储或发送到服务器
  71. },
  72. async getVoice(){
  73. const listRes = await this.$api.music.list()
  74. if (listRes.code === 200) {
  75. this.voiceList = listRes.result
  76. }
  77. }
  78. },
  79. onLoad(options) {
  80. this.selectedVoiceId = Number(options.voiceId)
  81. console.log( 'options.voiceId', options.voiceId );
  82. this.getVoice()
  83. }
  84. }
  85. </script>
  86. <style scoped lang="scss">
  87. .music-container {
  88. background: #fff;
  89. min-height: 100vh;
  90. display: flex;
  91. flex-direction: column;
  92. padding-bottom: 120rpx;
  93. }
  94. .voice-list {
  95. flex: 1;
  96. padding: 40rpx 32rpx 120rpx;
  97. display: flex;
  98. flex-direction: column;
  99. gap: 32rpx;
  100. }
  101. .voice-item {
  102. display: flex;
  103. align-items: center;
  104. padding: 32rpx 0;
  105. border-bottom: 4rpx solid #F8F8F8;
  106. position: relative;
  107. background: #F8F8F8;
  108. gap: 12px;
  109. opacity: 1;
  110. border-radius: 8px;
  111. padding: 8px;
  112. transition: all 0.3s ease;
  113. &:last-child {
  114. border-bottom: none;
  115. }
  116. &.selected {
  117. border-bottom: 4rpx solid $primary-color;
  118. }
  119. }
  120. .voice-avatar {
  121. width: 136rpx;
  122. height: 136rpx;
  123. border-radius: 50%;
  124. background: #666;
  125. display: flex;
  126. align-items: center;
  127. justify-content: center;
  128. // margin-right: 32rpx;
  129. position: relative;
  130. }
  131. .play-icon {
  132. display: flex;
  133. width: 60rpx;
  134. height: 60rpx;
  135. border-radius: 100rpx;
  136. background: white;
  137. align-items: center;
  138. justify-content: center;
  139. }
  140. .voice-info {
  141. flex: 1;
  142. }
  143. .voice-name {
  144. font-family: PingFang SC;
  145. font-weight: 600;
  146. font-size: 36rpx;
  147. color: #262626;
  148. margin-bottom: 8rpx;
  149. }
  150. .voice-desc {
  151. font-family: PingFang SC;
  152. font-weight: 400;
  153. font-size: 28rpx;
  154. color: #999;
  155. }
  156. .selected-tag {
  157. background: $primary-color;
  158. color: #fff;
  159. font-size: 24rpx;
  160. padding: 8rpx 16rpx;
  161. border-radius: 20rpx;
  162. font-family: PingFang SC;
  163. font-weight: 500;
  164. }
  165. .bottom-bar {
  166. position: fixed;
  167. bottom: 0;
  168. left: 0;
  169. right: 0;
  170. background: #fff;
  171. padding: 24rpx 50rpx;
  172. z-index: 999;
  173. border-top: 2rpx solid #F1F1F1
  174. }
  175. </style>