scanListInfo.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <script setup lang="ts">
  2. import {MusicInfo, MusicScanSetting} from "@/types/musicType.ts";
  3. import {onBeforeMount, PropType, ref, watch} from "vue";
  4. import LickIcon from "@/components/music/common/lickIcon.vue";
  5. import IconSvg from "@/components/public/icon/iconSvg.vue";
  6. import message from "@/components/public/kui/message";
  7. import {api_likeMusic, fetchScanMusic} from "@/apis/musicControl.ts";
  8. import {ErrorCode} from "@/types/apiTypes.ts";
  9. import {secondToTimeStr} from "@/util/time.ts";
  10. import {music_action_emits, Music_Action_events} from "@/components/music/music_emits.ts";
  11. const props = defineProps({
  12. scanSetting: {
  13. type: Object as PropType<MusicScanSetting>,
  14. default: () => ({})
  15. }
  16. })
  17. let scanSetting_id = ref(0)
  18. const scanCount = ref(0)
  19. const musicList = ref<MusicInfo[]>([])
  20. const search_key = ref("");
  21. const search_page = ref(1);
  22. const page_limit = 10;
  23. const lock_loading = ref(false);
  24. async function loadMusic(scanSetting: MusicScanSetting, page: number, key: string = '')
  25. {
  26. console.log("loadMusic");
  27. if (lock_loading.value)
  28. {
  29. message.info("正在加载中,请稍后");
  30. return;
  31. }
  32. lock_loading.value = true;
  33. let res = await fetchScanMusic(scanSetting.id, page, page_limit, key)
  34. lock_loading.value = false;
  35. if (res.code === ErrorCode.success)
  36. {
  37. if (page === 1)
  38. {
  39. scanCount.value = res.data.total?? 0;
  40. }
  41. let pageData = res.data.data ;
  42. for ( let i = 0; i < pageData.length; i++)
  43. {
  44. pageData[i].isLike = !!pageData[i].isLike;
  45. pageData[i].isLocal = !!pageData[i].isLocal;
  46. musicList.value.push(pageData[i]);
  47. }
  48. }
  49. else {
  50. message.error(res.msg);
  51. }
  52. }
  53. watch(()=>props.scanSetting, ()=>{
  54. if (scanSetting_id.value !== props.scanSetting.id)
  55. {
  56. musicList.value = [];
  57. loadMusic(props.scanSetting, 1, search_key.value);
  58. }
  59. })
  60. async function loadMore()
  61. {
  62. search_page.value++;
  63. await loadMusic(props.scanSetting, search_page.value, search_key.value);
  64. }
  65. onBeforeMount(()=>{
  66. loadMusic(props.scanSetting, search_page.value, search_key.value);
  67. })
  68. function playMusic(item: MusicInfo) {
  69. console.log(item);
  70. message.info(`play ${item.name}`);
  71. music_action_emits(Music_Action_events.play_music, item);
  72. }
  73. function likeMusic(item: MusicInfo) {
  74. console.log(item);
  75. message.info(`like ${item.name}`);
  76. api_likeMusic(item.id);
  77. }
  78. function showMore(item: MusicInfo) {
  79. console.log(item);
  80. message.info(`show ${item.name}`);
  81. }
  82. </script>
  83. <template>
  84. <div class="scan-list-info">
  85. <div class="info">
  86. <div class="name">{{scanSetting.name}}</div>
  87. <div class="path">{{scanSetting.path}}</div>
  88. <div class="line-row">
  89. <span class="label">扫描数量</span>
  90. <span class="value">{{scanCount}}</span>
  91. </div>
  92. </div>
  93. <div class="music-lists">
  94. <div class="music-list-head">
  95. <div class="music-list-item">
  96. <div class="cover">
  97. </div>
  98. <div class="name">名称</div>
  99. <div class="artists">艺术家</div>
  100. <div class="origin">来源</div>
  101. <div class="duration">时长</div>
  102. <div class="isLike">喜欢</div>
  103. </div>
  104. </div>
  105. <!-- 让下面框在滑动到底部时自动加载下一级数据 -->
  106. <div class="music-list-con scroll">
  107. <div v-for="item in musicList"
  108. class="music-list-item"
  109. @click="playMusic(item)"
  110. >
  111. <div class="cover">
  112. <img :src="item.cover" alt=""/>
  113. </div>
  114. <div class="name">{{item.name}}</div>
  115. <div class="artists">{{item.artists}}</div>
  116. <div class="origin">{{item.origin}}</div>
  117. <div class="duration">{{ secondToTimeStr(item.duration, "m分s秒" )}}</div>
  118. <lick-icon class="isLike" :like="item.isLike"
  119. @click.stop.capture="likeMusic(item)"/>
  120. <div class="more">
  121. <icon-svg icon-name="add" @click.stop.capture="showMore(item)"></icon-svg>
  122. </div>
  123. </div>
  124. </div>
  125. </div>
  126. </div>
  127. </template>
  128. <style scoped>
  129. @import "../../../assets/public.css";
  130. .scan-list-info {
  131. display: flex;
  132. flex-direction: column;
  133. width: 100%;
  134. height: 100%;
  135. }
  136. .info {
  137. width: calc(100% - 10px);
  138. height: 120px;
  139. padding: 10px;
  140. box-sizing: border-box;
  141. border-radius: 5px;
  142. margin: 5px auto;
  143. font-size: 1em;
  144. background-color: var(--color-background-mute);
  145. }
  146. .info .name {
  147. width: 100%;
  148. height: 40px;
  149. font-size: 1.5rem;
  150. }
  151. .path {
  152. width: 100%;
  153. height: 30px;
  154. font-size: 1rem;
  155. display: flex;
  156. }
  157. .count {
  158. width: 100%;
  159. height: 30px;
  160. font-size: 1rem;
  161. display: flex;
  162. }
  163. .line-row .label {
  164. width: auto;
  165. }
  166. .music-lists{
  167. height: calc(100% - 120px);
  168. }
  169. </style>