Skip to content

Commit 14f7452

Browse files
committed
add: 分享列表界面
1 parent ea0de59 commit 14f7452

File tree

11 files changed

+490
-8
lines changed

11 files changed

+490
-8
lines changed

pc/gui/qml/explore/ShareItem.qml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import QtQuick 2.11
2+
import QtGraphicalEffects 1.0
3+
import QtQuick.Controls 2.1
4+
import "../js/util.js" as Util
5+
6+
Item {
7+
id: root
8+
9+
property var meta
10+
property int idx
11+
property var listComp
12+
width: parent.width
13+
height: content.height + 20
14+
15+
Rectangle {
16+
id: content
17+
width: parent.width
18+
height: 200
19+
color: 'white'
20+
Column {
21+
padding: 10
22+
spacing: 10
23+
Row {
24+
spacing: 10
25+
Rectangle {
26+
width: 50
27+
height: width
28+
radius: width / 2
29+
anchors.verticalCenter: parent.verticalCenter
30+
color: 'orange'
31+
Image {
32+
id: avatar
33+
smooth: true
34+
visible: false
35+
anchors.fill: parent
36+
source: root.meta.user.avatar
37+
antialiasing: true
38+
}
39+
Rectangle {
40+
id: mask
41+
anchors.fill: parent
42+
radius: width / 2
43+
visible: false
44+
antialiasing: true
45+
smooth: true
46+
}
47+
OpacityMask {
48+
anchors.fill: avatar
49+
source: avatar
50+
maskSource: mask
51+
antialiasing: true
52+
visible: avatar.status === Image.Ready
53+
}
54+
}
55+
56+
Column {
57+
Text {
58+
text: root.meta.user.mark_username
59+
font.pointSize: 12
60+
}
61+
Text {
62+
text: Util.unixTime(root.meta.share_at)
63+
font.pointSize: 10
64+
color: '#aaa'
65+
}
66+
}
67+
}
68+
69+
Text {
70+
width: content.width - 30
71+
wrapMode: Text.WrapAnywhere
72+
text: root.meta.title
73+
}
74+
75+
Row {
76+
spacing: 10
77+
Tag {
78+
text.text: Util.humanSize(root.meta.file_size)
79+
}
80+
Tag {
81+
border.color: 'red'
82+
text.text: '热度指数: ' + root.meta.hot_index
83+
}
84+
Tag {
85+
visible: root.meta.official
86+
border.color: '#409EFF'
87+
text.text: '官方认证'
88+
}
89+
}
90+
91+
Row {
92+
spacing: 15
93+
Button {
94+
text: '下载'
95+
}
96+
Button {
97+
text: '转存'
98+
}
99+
Button {
100+
visible: Util.isVideo(root.meta.title)
101+
text: '播放'
102+
}
103+
}
104+
}
105+
}
106+
}

pc/gui/qml/explore/ShareList.qml

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
import QtQuick 2.0
2+
import QtQuick.Controls 2.1
3+
import "../js/util.js" as Util
4+
import "../widget"
5+
6+
Rectangle {
7+
id: root
8+
clip: true
9+
10+
color: '#eee'
11+
12+
property int pageSize: 1
13+
property int offset: 0
14+
property var loadPromise
15+
property string type: 'newest'
16+
property bool noMore: false
17+
signal active
18+
19+
onActive: {
20+
if (offset === 0)
21+
loadMore()
22+
}
23+
24+
TopIndicator {
25+
id: topIndicator
26+
z: 2
27+
}
28+
29+
ListModel {
30+
id: listModel
31+
}
32+
33+
Item {
34+
id: refreshIndicator
35+
width: parent.width
36+
height: 50
37+
visible: !listView.flicking
38+
y: -listView.contentY - refreshIndicator.height + listView.y
39+
Row {
40+
spacing: 5
41+
anchors.centerIn: parent
42+
BusyIndicator {
43+
visible: running
44+
running: refreshText.text === '刷新中'
45+
contentItem.implicitHeight: 25
46+
contentItem.implicitWidth: 25
47+
}
48+
Text {
49+
id: refreshText
50+
text: '下拉刷新'
51+
anchors.verticalCenter: parent.verticalCenter
52+
}
53+
}
54+
Timer {
55+
id: hideSuccessTipTimer
56+
property bool hide: true
57+
interval: 1000
58+
onTriggered: {
59+
hide = true
60+
}
61+
}
62+
states: [
63+
State {
64+
id: refreshDone
65+
name: "refreshDone"
66+
when: !hideSuccessTipTimer.hide
67+
PropertyChanges {
68+
target: refreshText
69+
text: '刷新成功'
70+
}
71+
},
72+
State {
73+
id: refreshing
74+
name: "refreshing"
75+
when: !!root.loadPromise && root.loadPromise.refresh
76+
StateChangeScript {
77+
script: loadPromise.then(function () {
78+
hideSuccessTipTimer.hide = false
79+
hideSuccessTipTimer.restart()
80+
})
81+
}
82+
PropertyChanges {
83+
target: refreshText
84+
text: '刷新中'
85+
}
86+
},
87+
State {
88+
id: refreshHold
89+
name: "refreshHold"
90+
when: -listView.contentY - refreshIndicator.height >= 0
91+
PropertyChanges {
92+
target: refreshText
93+
text: '释放立即刷新'
94+
}
95+
}
96+
97+
]
98+
}
99+
100+
Component {
101+
id: listViewFooter
102+
Item {
103+
width: parent.width
104+
height: 50
105+
Text {
106+
text: {
107+
if (root.type === 'hottest')
108+
return '热度榜每分钟更新一次~'
109+
if (root.loadPromise) {
110+
return '加载中'
111+
}
112+
if (root.noMore)
113+
return '没有更多了'
114+
return '加载更多'
115+
}
116+
anchors.centerIn: parent
117+
MouseArea {
118+
anchors.fill: parent
119+
onClicked: {
120+
if (parent.text === '加载更多')
121+
root.loadMore()
122+
}
123+
}
124+
}
125+
}
126+
}
127+
128+
ListView {
129+
id: listView
130+
footer: listViewFooter
131+
y: ['刷新中', '刷新成功'].indexOf(refreshText.text) >= 0 ? refreshIndicator.height : 0
132+
width: parent.width
133+
height: parent.height
134+
model: listModel
135+
delegate: ShareItem {
136+
id: shareItem
137+
meta: listModel.get(index)
138+
idx: index
139+
listComp: root
140+
}
141+
ScrollBar.vertical: ScrollBar {
142+
}
143+
onDraggingChanged: {
144+
if (!dragging && refreshIndicator.state === 'refreshHold') {
145+
loadMore(true)
146+
}
147+
}
148+
Behavior on y {
149+
PropertyAnimation {
150+
duration: 150
151+
easing.type: Easing.Linear
152+
}
153+
}
154+
}
155+
156+
function loadMore(refresh) {
157+
if (loadPromise)
158+
return
159+
if (!refresh && noMore) return
160+
loadPromise = Util.api('share-list', {
161+
"offset": refresh ? 0 : offset,
162+
"pageSize": pageSize,
163+
"type": type
164+
})
165+
166+
loadPromise = loadPromise.then(function (list) {
167+
if (refresh) {
168+
listModel.clear()
169+
}
170+
handleMore(list)
171+
return Util.sleep(100)
172+
}).catch(function (err) {
173+
topIndicator.fail(err.message)
174+
throw err.message
175+
}).finally(function () {
176+
loadPromise = null
177+
})
178+
loadPromise.refresh = refresh
179+
}
180+
181+
function handleMore(list) {
182+
if (list.length === 0) {
183+
noMore = true
184+
return
185+
}
186+
noMore = false
187+
list.forEach(function (item) {
188+
listModel.append(item)
189+
})
190+
offset = listModel.get(listModel.count - 1).share_at
191+
}
192+
}

pc/gui/qml/explore/Tag.qml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import QtQuick 2.4
2+
3+
Rectangle {
4+
width: text.implicitWidth + 10
5+
height: 25
6+
radius: 6
7+
color: 'transparent'
8+
border.color: 'blue'
9+
property alias text: text
10+
Text {
11+
id: text
12+
anchors.centerIn: parent
13+
color: parent.border.color
14+
font.pointSize: 10
15+
}
16+
}

pc/gui/qml/explore/TagForm.ui.qml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import QtQuick 2.4
2+
3+
Item {
4+
width: 400
5+
height: 400
6+
}

0 commit comments

Comments
 (0)