From 1dd349364a4af3972cb4baffdf4457fe0b726c4a Mon Sep 17 00:00:00 2001 From: student-ice Date: Wed, 13 Dec 2023 11:20:19 +0800 Subject: [PATCH] chore: Adjust directory structure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将所有页面都放到qml/pages文件夹下,减少文件夹数量 --- src/main.qml | 2 +- src/music.qrc | 27 ++- src/qml/{artist => pages}/Artist.qml | 0 src/qml/{daily => pages}/Daily.qml | 0 src/qml/{discover => pages}/Discover.qml | 0 src/qml/{favorite => pages}/Favorite.qml | 0 src/qml/{index => pages}/Index.qml | 0 src/qml/{library => pages}/Library.qml | 0 .../PlaylistDetail.qml | 0 src/qml/playlistdetail/PlaylistDetailHead.qml | 130 ------------- src/qml/search/Search.qml | 183 ------------------ src/router/Router.qml | 16 +- 12 files changed, 20 insertions(+), 338 deletions(-) rename src/qml/{artist => pages}/Artist.qml (100%) rename src/qml/{daily => pages}/Daily.qml (100%) rename src/qml/{discover => pages}/Discover.qml (100%) rename src/qml/{favorite => pages}/Favorite.qml (100%) rename src/qml/{index => pages}/Index.qml (100%) rename src/qml/{library => pages}/Library.qml (100%) rename src/qml/{playlistdetail => pages}/PlaylistDetail.qml (100%) delete mode 100644 src/qml/playlistdetail/PlaylistDetailHead.qml delete mode 100644 src/qml/search/Search.qml diff --git a/src/main.qml b/src/main.qml index 5e8e3f5..ceacc7b 100644 --- a/src/main.qml +++ b/src/main.qml @@ -179,7 +179,7 @@ ApplicationWindow { model: ListModel { ListElement { - source: "qml/index/Index.qml" + source: "qml/pages/Index.qml" } } diff --git a/src/music.qrc b/src/music.qrc index 2650b5c..d58672f 100644 --- a/src/music.qrc +++ b/src/music.qrc @@ -1,17 +1,17 @@ main.qml - - qml/index/Index.qml - - qml/discover/Discover.qml - - qml/daily/Daily.qml - - qml/library/Library.qml - qml/playlistdetail/PlaylistDetail.qml - qml/playlistdetail/PlaylistDetailHead.qml + qml/pages/Index.qml + qml/pages/Discover.qml + qml/pages/Daily.qml + qml/pages/Library.qml + qml/pages/PlaylistDetail.qml + qml/pages/Search.qml + qml/pages/Artist.qml + qml/pages/Favorite.qml + qml/pages/Index.qml + qml/pages/Index.qml qml/lyric/Lyric.qml qml/lyric/LyricRect.qml @@ -40,6 +40,7 @@ qml/widgets/PlayTime.qml qml/widgets/Duration.qml qml/widgets/BuyAlbums.qml + qml/widgets/PlaylistDetailHead.qml qml/toolbar/Toolbar.qml qml/toolbar/VolumeSlider.qml @@ -47,12 +48,6 @@ qml/playlist/Playlist.qml qml/playlist/PlaylistDelegate.qml - qml/search/Search.qml - - qml/artist/Artist.qml - - qml/favorite/Favorite.qml - qml/dialogs/CloseDialog.qml util/Util.qml diff --git a/src/qml/artist/Artist.qml b/src/qml/pages/Artist.qml similarity index 100% rename from src/qml/artist/Artist.qml rename to src/qml/pages/Artist.qml diff --git a/src/qml/daily/Daily.qml b/src/qml/pages/Daily.qml similarity index 100% rename from src/qml/daily/Daily.qml rename to src/qml/pages/Daily.qml diff --git a/src/qml/discover/Discover.qml b/src/qml/pages/Discover.qml similarity index 100% rename from src/qml/discover/Discover.qml rename to src/qml/pages/Discover.qml diff --git a/src/qml/favorite/Favorite.qml b/src/qml/pages/Favorite.qml similarity index 100% rename from src/qml/favorite/Favorite.qml rename to src/qml/pages/Favorite.qml diff --git a/src/qml/index/Index.qml b/src/qml/pages/Index.qml similarity index 100% rename from src/qml/index/Index.qml rename to src/qml/pages/Index.qml diff --git a/src/qml/library/Library.qml b/src/qml/pages/Library.qml similarity index 100% rename from src/qml/library/Library.qml rename to src/qml/pages/Library.qml diff --git a/src/qml/playlistdetail/PlaylistDetail.qml b/src/qml/pages/PlaylistDetail.qml similarity index 100% rename from src/qml/playlistdetail/PlaylistDetail.qml rename to src/qml/pages/PlaylistDetail.qml diff --git a/src/qml/playlistdetail/PlaylistDetailHead.qml b/src/qml/playlistdetail/PlaylistDetailHead.qml deleted file mode 100644 index 22a4939..0000000 --- a/src/qml/playlistdetail/PlaylistDetailHead.qml +++ /dev/null @@ -1,130 +0,0 @@ -import "../../router" -import "../../util" -import "../widgets" -import Melodix.Player 1.0 -import QtQuick 2.11 -import QtQuick.Controls 2.4 -import QtQuick.Layouts 1.15 -import org.deepin.dtk 1.0 - -Row { - property string cover: "" - property string name: "" - property string creatorNickname: "" - property string updateTime: "" - property string description: "" - - spacing: 30 - - Item { - width: 1 - height: 1 - } - - RoundedImage { - id: coverImg - - width: scrollWidth / 3.9 - height: width - imgSrc: cover - } - - Item { - width: scrollWidth - coverImg.width - 10 - 30 - 10 - 30 - height: coverImg.height - - Column { - anchors.fill: parent - spacing: 10 - - Item { - width: 10 - height: 5 - } - - Text { - id: playlistName - - width: parent.width - height: (parent.height - 40) / 4 - 10 - font.pixelSize: DTK.fontManager.t3.pixelSize - font.bold: true - color: Util.textColor - text: name - } - - Item { - width: parent.width - height: (parent.height - 40) / 4 - - Text { - id: playlistAuthor - - width: parent.width - height: parent.height / 2 - font.pixelSize: DTK.fontManager.t4.pixelSize - font.bold: true - color: Util.textColor - text: creatorNickname - } - - Text { - id: playlistUpdateTime - - anchors.top: playlistAuthor.bottom - anchors.topMargin: 2 - width: parent.width - height: parent.height / 2 - font.pixelSize: DTK.fontManager.t5.pixelSize - color: Util.textColor - text: updateTime - } - - } - - Label { - id: playlistDescription - - width: parent.width - height: (parent.height - 40) / 4 + 10 - wrapMode: Text.Wrap - elide: Text.ElideRight - maximumLineCount: 3 - font.pixelSize: DTK.fontManager.t6.pixelSize - color: Util.textColor - text: description - } - - Item { - width: parent.width - height: (parent.height - 40) / 4 - - RecommandButton { - width: 80 - height: 40 - text: "播放" - font.bold: true - font.pixelSize: DTK.fontManager.t6.pixelSize - onClicked: { - console.log("播放按钮点击"); - if (!isAddToPlaylist) - playPlaylistAllMusic(); - else - Player.play(0); - } - - icon { - name: "details_play" - width: 25 - height: 25 - } - - } - - } - - } - - } - -} diff --git a/src/qml/search/Search.qml b/src/qml/search/Search.qml deleted file mode 100644 index b5662dc..0000000 --- a/src/qml/search/Search.qml +++ /dev/null @@ -1,183 +0,0 @@ -import "../../router" -import "../../util" -import "../widgets" -import Melodix.API 1.0 -import Melodix.Player 1.0 -import QtQuick 2.11 -import QtQuick.Layouts 1.15 -import org.deepin.dtk 1.0 - -Item { - id: root - - property string currentPlaylistId: "" - property int currentSelectIndex: -1 - property bool initing: true - property var songs: [] - // 已经添加到播放列表的歌曲数量 - property int playlistSongCount: 0 - // 是否已经将歌单全部歌曲添加到了播放列表 - property bool isAddToPlaylist: false - // 搜索到的歌曲总量 - property int songListCount: 0 - // 歌曲偏移量 - property int offset: 0 - // 一次加载的歌曲数量 - property int limit: 0 - // 是否正在“加载更多” - property bool loadMore: false - // 是否加载完全部歌曲 - property bool hasMore: true - property int imgCellRectWidth: 45 - property int timeRectWidth: 54 - property int spacingWidth: 10 - property int serialNumberWidth: 20 - - function getSearchSongsInfo() { - function onReply(result) { - API.onSearchCompleted.disconnect(onReply); - var newSongs = result.songs; - for (const song of newSongs) { - songs.push(song); - listView.model.append({ - "song": song - }); - } - initing = false; - offset += newSongs.length; - loadMore = false; - console.log("加载的歌曲数量: limit: " + limit + " offset: " + offset + " songs数组长度: " + songs.length); - } - - if (songListCount - offset > 50) { - limit = 50; - } else { - limit = songListCount - offset; - hasMore = false; - } - API.onSearchCompleted.connect(onReply); - API.search(Router.routeCurrent.key, limit, offset); - } - - function getSearchResult(offset = 0) { - function onReply(result) { - API.onSearchCompleted.disconnect(onReply); - songListCount = result.songCount; - console.log("搜索到的歌曲共有:" + songListCount + "首"); - getSearchSongsInfo(); - } - - API.onSearchCompleted.connect(onReply); - API.search(Router.routeCurrent.key); - } - - function playPlaylistAllMusic(index = -1) { - // 切换播放列表 - Player.switchToPlaylistMode(); - if (Player.getCurrentPlaylistId() != "" && Player.getCurrentPlaylistId() != currentPlaylistId) - Player.clearPlaylist(); - - // 判断点击的歌曲是否已经添加到播放列表 - // 如果添加了直接播放 - if (index != -1 && index < playlistSongCount) { - Player.play(index); - return ; - } - for (var i = playlistSongCount; i < songs.length; i++) { - Player.addPlaylistToPlaylist(songs[i].id, songs[i].name, Util.spliceSinger(songs[i].ar), songs[i].pic, Util.formatDuration(songs[i].duration), songs[i].al); - } - playlistSongCount = songs.length; - // 如果没有传入index参数 - // 则说明点击的是播放按钮 - if (index != -1) - Player.play(index); - else - Player.play(0); - // 给Player类设置当前的播放列表id - Player.setCurrentPlaylistId(currentPlaylistId); - // 如果歌曲url总数等于歌单歌曲总数 - // 说明全部歌曲都已经添加到了播放列表 - if (playlistSongCount == songListCount) - isAddToPlaylist = true; - - } - - function onPlaylistCurrentIndexChanged() { - currentSelectIndex = Player.getCurrentIndex(); - } - - Component.onCompleted: { - getSearchResult(); - currentPlaylistId = Router.routeCurrent.key; - Player.playlistCurrentIndexChanged.connect(onPlaylistCurrentIndexChanged); - } - Component.onDestruction: { - Player.playlistCurrentIndexChanged.disconnect(onPlaylistCurrentIndexChanged); - } - - ListModel { - id: songListModel - } - - ScrollView { - anchors.fill: parent - clip: true - contentHeight: 5 + listView.height - ScrollBar.vertical.onPositionChanged: () => { - const position = ScrollBar.vertical.position + ScrollBar.vertical.size; - if (position > 0.99 && !loadMore && hasMore) { - console.log("position: " + position + " 滚动到底部,加载更多"); - loadMore = true; - getSearchSongsInfo(); - } - } - - Column { - id: body - - spacing: 20 - x: Util.pageLeftPadding - y: 5 - - ListView { - id: listView - - width: scrollWidth - height: offset * 55 - model: songListModel - - delegate: ListViewDelegate { - } - - } - - } - - } - - Rectangle { - id: loadAnimation - - visible: initing - anchors.fill: root - color: Util.pageBackgroundColor - - Loading { - anchors.centerIn: parent - } - - } - - BusyIndicator { - id: indicator - - visible: loadMore - anchors.horizontalCenter: parent.horizontalCenter - anchors.bottom: parent.bottom - anchors.bottomMargin: 5 - running: true - width: 20 - height: 20 - } - -} diff --git a/src/router/Router.qml b/src/router/Router.qml index c10f0fe..fd0130e 100644 --- a/src/router/Router.qml +++ b/src/router/Router.qml @@ -11,41 +11,41 @@ Item { // 首页 property var routeIndex: { "path": "index", - "component": "qml/index/Index.qml" + "component": "qml/pages/Index.qml" } // 发现 property var routeDiscover: { "path": "discover", - "component": "qml/discover/Discover.qml", + "component": "qml/pages/Discover.qml", "showRecommend": false } // 音乐库 property var routeLibrary: { "path": "library", - "component": "qml/library/Library.qml" + "component": "qml/pages/Library.qml" } // 歌单详情页 property var routePlaylistDetail: { "path": "playlist", - "component": "qml/playlistdetail/PlaylistDetail.qml", + "component": "qml/pages/PlaylistDetail.qml", "id": 0 } // 搜索结果页 property var routeSearch: { "path": "search", - "component": "qml/search/Search.qml", + "component": "qml/pages/Search.qml", "key": "" } // 艺人详情页 property var routeArtist: { "path": "artist", - "component": "qml/artist/Artist.qml", + "component": "qml/pages/Artist.qml", "id": "" } // 喜欢的歌曲页 property var routeFavorite: { "path": "favourite", - "component": "qml/favorite/Favorite.qml", + "component": "qml/pages/Favorite.qml", "id": "", "count": "" } @@ -62,7 +62,7 @@ Item { // 每日推荐歌曲页 property var routeDaily: { "path": "daily", - "component": "qml/daily/Daily.qml" + "component": "qml/pages/Daily.qml" } // 路由后退信号