-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDetailSearchPageView.qml
112 lines (102 loc) · 3.34 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import QtQuick 2.15
import QtQuick.Controls
import QtQuick.Layouts
ColumnLayout{
Layout.fillWidth: true
Layout.fillHeight: true
Rectangle{
Layout.fillWidth: true
width: parent.width
height: 70
color:"#00000000"
Text{
x:10
verticalAlignment: Text.AlignBottom
text:"搜索音乐"
font.family: window.mFontFamily
font.pointSize: 25
color: "#eeffffff"
}
}
RowLayout{
Layout.fillWidth: true
TextField{
id:searchInput
font.family: window.mFontFamily
font.pointSize: 14
selectByMouse: true//可以选中
selectionColor: "#999999"
placeholderText: "请输入搜索关键词"
color: "#eeffffff"
background: Rectangle{
opacity:0.5 //透明度
implicitHeight: 40
implicitWidth: 400
color:"#00000000"
}
focus: true
Keys.onPressed: function(event){if(event.key===Qt.Key_Enter||event.key===Qt.Key_Return){
doSearch()
}
}
}
MusicIconButton{
iconSource: "/icons/images/search"
toolTip: "搜索"
onClicked:{
doSearch()
}
}
}
MusicListView{
id:musicListView
deleteble: false
onLoadMoreData: function(offset){
doSearch(offset)//
}
Layout.topMargin: 10
}
function doSearch(offset=0){
var keywords= searchInput.text
if(keywords.length===0){
return
}
loading.open()
if(offset===0){
musicListView.all=0
musicListView.musicList=[]
musicListView.offset=0
musicListView.current=0
}
function onReply(reply){
http.onReplySignal.disconnect(onReply);//断开连接
loading.close()
try{
if(reply.length<1){
notification.openError("搜索结果为空")
return
}
var result=JSON.parse(reply).result//.songs
musicListView.all=result.songCount
musicListView.musicList=result.songs.map(item=>{
return{
id:item.id,
name:item.name,
artist:item.artists[0].name,
album:item.album.name,
cover:""
}
})
}catch(e){
notification.openError("请求新歌推荐出错")
}
}
http.onReplySignal.connect(onReply)//建立连接
console.log("all="+musicListView.all)
if(offset>musicListView.all){
offset=musicListView.all
}
console.log("offset="+offset)
http.doConnet("search?keywords="+keywords+"&offset="+offset+"&limit=60")//发起网络请求
}
}