index.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. <template>
  2. <view class="page">
  3. <!-- 顶部导航 -->
  4. <view class="nav-bar">
  5. <view class="nav-btn" @click="goBack">
  6. <text class="nav-icon">←</text>
  7. </view>
  8. <text class="nav-title">我的播放列表</text>
  9. <view class="nav-btn" @click="showCreateModal = true">
  10. <text class="nav-icon">+</text>
  11. </view>
  12. </view>
  13. <!-- 播放列表 -->
  14. <scroll-view scroll-y class="content">
  15. <view v-if="playlists.length === 0 && !loading" class="empty">
  16. <text class="empty-icon">📋</text>
  17. <text class="empty-text">暂无播放列表</text>
  18. <text class="empty-hint">点击右上角创建第一个播放列表</text>
  19. </view>
  20. <view v-else class="playlist-grid">
  21. <view
  22. v-for="item in playlists"
  23. :key="item.id"
  24. class="playlist-card"
  25. @click="goToDetail(item.id)"
  26. >
  27. <view class="playlist-cover">
  28. <text class="cover-icon">🎵</text>
  29. <view class="count-badge">
  30. <text>{{ item._count?.items || 0 }}</text>
  31. </view>
  32. </view>
  33. <view class="playlist-info">
  34. <text class="playlist-title">{{ item.name }}</text>
  35. <text class="playlist-meta">{{ item.description || '暂无描述' }}</text>
  36. </view>
  37. </view>
  38. </view>
  39. <view v-if="loading" class="loading">
  40. <text>加载中...</text>
  41. </view>
  42. </scroll-view>
  43. <!-- 创建播放列表弹窗 -->
  44. <view v-if="showCreateModal" class="modal">
  45. <view class="modal-mask" @click="showCreateModal = false"></view>
  46. <view class="modal-content">
  47. <view class="modal-header">
  48. <text class="modal-title">新建播放列表</text>
  49. </view>
  50. <view class="modal-body">
  51. <input
  52. v-model="newPlaylistName"
  53. class="input"
  54. placeholder="请输入播放列表名称"
  55. maxlength="50"
  56. />
  57. <textarea
  58. v-model="newPlaylistDesc"
  59. class="textarea"
  60. placeholder="请输入描述(可选)"
  61. maxlength="200"
  62. />
  63. </view>
  64. <view class="modal-footer">
  65. <view class="modal-btn cancel" @click="showCreateModal = false">
  66. <text>取消</text>
  67. </view>
  68. <view class="modal-btn confirm" @click="createPlaylist" :disabled="!newPlaylistName.trim()">
  69. <text>创建</text>
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. </template>
  76. <script setup lang="ts">
  77. import { ref, onMounted } from 'vue';
  78. import { get, post } from '../../utils/request';
  79. const playlists = ref<any[]>([]);
  80. const loading = ref(false);
  81. const showCreateModal = ref(false);
  82. const newPlaylistName = ref('');
  83. const newPlaylistDesc = ref('');
  84. // 返回
  85. function goBack() {
  86. uni.navigateBack();
  87. }
  88. // 跳转到详情
  89. function goToDetail(id: number) {
  90. uni.navigateTo({ url: `/pages/playlists/detail?id=${id}` });
  91. }
  92. // 获取播放列表
  93. async function fetchPlaylists() {
  94. loading.value = true;
  95. try {
  96. const data = await get('/playlists');
  97. playlists.value = data || [];
  98. } catch (error) {
  99. console.error('获取播放列表失败:', error);
  100. } finally {
  101. loading.value = false;
  102. }
  103. }
  104. // 创建播放列表
  105. async function createPlaylist() {
  106. if (!newPlaylistName.value.trim()) return;
  107. try {
  108. await post('/playlists', {
  109. name: newPlaylistName.value.trim(),
  110. description: newPlaylistDesc.value.trim(),
  111. });
  112. uni.showToast({ title: '创建成功', icon: 'success' });
  113. showCreateModal.value = false;
  114. newPlaylistName.value = '';
  115. newPlaylistDesc.value = '';
  116. await fetchPlaylists();
  117. } catch (error) {
  118. uni.showToast({ title: '创建失败', icon: 'none' });
  119. }
  120. }
  121. onMounted(() => {
  122. fetchPlaylists();
  123. });
  124. </script>
  125. <style scoped>
  126. .page {
  127. min-height: 100vh;
  128. background: #f5f5f5;
  129. }
  130. .nav-bar {
  131. display: flex;
  132. align-items: center;
  133. justify-content: space-between;
  134. padding: 44rpx 32rpx 24rpx;
  135. background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  136. position: sticky;
  137. top: 0;
  138. z-index: 100;
  139. }
  140. .nav-btn {
  141. width: 64rpx;
  142. height: 64rpx;
  143. display: flex;
  144. align-items: center;
  145. justify-content: center;
  146. }
  147. .nav-icon {
  148. font-size: 40rpx;
  149. color: #ffffff;
  150. }
  151. .nav-title {
  152. font-size: 32rpx;
  153. font-weight: 600;
  154. color: #ffffff;
  155. }
  156. .content {
  157. padding: 24rpx;
  158. height: calc(100vh - 160rpx);
  159. }
  160. .empty {
  161. display: flex;
  162. flex-direction: column;
  163. align-items: center;
  164. justify-content: center;
  165. padding: 200rpx 0;
  166. }
  167. .empty-icon {
  168. font-size: 120rpx;
  169. margin-bottom: 24rpx;
  170. }
  171. .empty-text {
  172. font-size: 32rpx;
  173. color: #6b7280;
  174. margin-bottom: 12rpx;
  175. }
  176. .empty-hint {
  177. font-size: 26rpx;
  178. color: #9ca3af;
  179. }
  180. .playlist-grid {
  181. display: flex;
  182. flex-wrap: wrap;
  183. gap: 20rpx;
  184. }
  185. .playlist-card {
  186. width: calc(50% - 10rpx);
  187. background: #ffffff;
  188. border-radius: 16rpx;
  189. overflow: hidden;
  190. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.06);
  191. }
  192. .playlist-cover {
  193. position: relative;
  194. width: 100%;
  195. height: 240rpx;
  196. background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  197. display: flex;
  198. align-items: center;
  199. justify-content: center;
  200. }
  201. .cover-icon {
  202. font-size: 80rpx;
  203. opacity: 0.8;
  204. }
  205. .count-badge {
  206. position: absolute;
  207. bottom: 12rpx;
  208. right: 12rpx;
  209. background: rgba(0, 0, 0, 0.6);
  210. color: #ffffff;
  211. font-size: 22rpx;
  212. padding: 4rpx 12rpx;
  213. border-radius: 8rpx;
  214. }
  215. .playlist-info {
  216. padding: 20rpx;
  217. }
  218. .playlist-title {
  219. font-size: 28rpx;
  220. font-weight: 500;
  221. color: #1f2937;
  222. display: block;
  223. overflow: hidden;
  224. text-overflow: ellipsis;
  225. white-space: nowrap;
  226. margin-bottom: 8rpx;
  227. }
  228. .playlist-meta {
  229. font-size: 22rpx;
  230. color: #9ca3af;
  231. display: block;
  232. overflow: hidden;
  233. text-overflow: ellipsis;
  234. white-space: nowrap;
  235. }
  236. .loading {
  237. text-align: center;
  238. padding: 32rpx;
  239. }
  240. .loading text {
  241. font-size: 24rpx;
  242. color: #9ca3af;
  243. }
  244. .modal {
  245. position: fixed;
  246. top: 0;
  247. left: 0;
  248. right: 0;
  249. bottom: 0;
  250. z-index: 1000;
  251. display: flex;
  252. align-items: center;
  253. justify-content: center;
  254. }
  255. .modal-mask {
  256. position: absolute;
  257. top: 0;
  258. left: 0;
  259. right: 0;
  260. bottom: 0;
  261. background: rgba(0, 0, 0, 0.5);
  262. }
  263. .modal-content {
  264. position: relative;
  265. width: 85%;
  266. max-width: 600rpx;
  267. background: #ffffff;
  268. border-radius: 24rpx;
  269. overflow: hidden;
  270. }
  271. .modal-header {
  272. padding: 32rpx;
  273. border-bottom: 1rpx solid #f3f4f6;
  274. }
  275. .modal-title {
  276. font-size: 32rpx;
  277. font-weight: 600;
  278. color: #1f2937;
  279. }
  280. .modal-body {
  281. padding: 32rpx;
  282. }
  283. .input {
  284. width: 100%;
  285. height: 80rpx;
  286. padding: 0 24rpx;
  287. border: 1rpx solid #e5e7eb;
  288. border-radius: 12rpx;
  289. font-size: 28rpx;
  290. margin-bottom: 24rpx;
  291. }
  292. .textarea {
  293. width: 100%;
  294. min-height: 160rpx;
  295. padding: 20rpx 24rpx;
  296. border: 1rpx solid #e5e7eb;
  297. border-radius: 12rpx;
  298. font-size: 28rpx;
  299. }
  300. .modal-footer {
  301. display: flex;
  302. border-top: 1rpx solid #f3f4f6;
  303. }
  304. .modal-btn {
  305. flex: 1;
  306. height: 96rpx;
  307. display: flex;
  308. align-items: center;
  309. justify-content: center;
  310. font-size: 30rpx;
  311. }
  312. .modal-btn.cancel {
  313. color: #6b7280;
  314. border-right: 1rpx solid #f3f4f6;
  315. }
  316. .modal-btn.confirm {
  317. color: #4f46e5;
  318. font-weight: 600;
  319. }
  320. .modal-btn.confirm[disabled] {
  321. opacity: 0.5;
  322. }
  323. </style>