-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDetailSearchPageView.qml
73 lines (63 loc) · 2.51 KB
/
DetailSearchPageView.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.12
ColumnLayout{
RowLayout{
Layout.fillWidth: true
Layout.leftMargin: 5
Layout.topMargin: 5
TextField{
id: searchInput
font.pointSize: 12
selectByMouse: true
selectionColor: "#999999"
placeholderText: qsTr("请输入搜索关键字")
color: "#000000"
background: Rectangle{
color: "#00000000"
border.color: "black"
border.width: 1
opacity: 0.5
implicitHeight: 35
implicitWidth: 600
}
focus: true
Keys.onPressed: if(event.key===Qt.Key_Enter||event.key===Qt.Key_Return) doSearch()
}
MusicIconButton{
iconSource: "qrc:/images/search"
toolTip: "搜索"
onClicked: {
doSearch()
}
}
}
MusicListView{
id: musicListView
onLoadMore: doSearch(offset, current)
}
function doSearch(offset = 0, current = 0){
var keywords = searchInput.text
if(keywords.length <= 0) return
function onReply(reply){
http.onReplySignal.disconnect(onReply)
musicListView.current = current
var result = JSON.parse(reply).result
var songsList = result.songs
musicListView.all = result.songCount
/// map方法和箭头函数=>都是JS里的方法,一般搭配使用
/// map生成新数组,这里类型为[{"id":v1,"name":v2,"artist":v3,"album":v4}{...}]JSON数组,直接调用id即可获得v1
/// item是遍历songList获取的每一个元素,并当做参数传入=>函数,=>函数返回{id:item.id,...}这样JSON类型
musicListView.musicList = songsList.map(item=>{
return {
id: item.id,
name: item.name,
artist: item.artists[0].name,
album: item.album.name
}
})
}
http.onReplySignal.connect(onReply)
http.connet("search?keywords="+keywords+"&offset="+offset+"&limit=60")
}
}