FileList mock测试
parent
14125369fe
commit
24bcce875a
|
@ -1,6 +1,7 @@
|
||||||
import QtQuick 2.15
|
import QtQuick 2.15
|
||||||
import QtQuick.Layouts
|
import QtQuick.Layouts
|
||||||
import FluentUI
|
import FluentUI
|
||||||
|
import "qrc:///AicsKnowledgeBase/qml/global"
|
||||||
|
|
||||||
Window {
|
Window {
|
||||||
id: fileListTestWindow
|
id: fileListTestWindow
|
||||||
|
@ -19,6 +20,9 @@ Window {
|
||||||
header: fileListItemHeader
|
header: fileListItemHeader
|
||||||
model: fileListModel
|
model: fileListModel
|
||||||
delegate: fileListItemDelegate
|
delegate: fileListItemDelegate
|
||||||
|
Component.onCompleted: {
|
||||||
|
update()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Component {
|
Component {
|
||||||
id: fileListItemHeader
|
id: fileListItemHeader
|
||||||
|
@ -32,13 +36,7 @@ Window {
|
||||||
width: parent.width
|
width: parent.width
|
||||||
height: parent.height
|
height: parent.height
|
||||||
separator: ">"
|
separator: ">"
|
||||||
items: [{
|
items: []
|
||||||
"title": "Home"
|
|
||||||
}, {
|
|
||||||
"title": "Documents"
|
|
||||||
}, {
|
|
||||||
"title": "File List"
|
|
||||||
}]
|
|
||||||
onClickItem: function (model) {
|
onClickItem: function (model) {
|
||||||
if (model.index + 1 !== count()) {
|
if (model.index + 1 !== count()) {
|
||||||
items = items.slice(0, model.index + 1)
|
items = items.slice(0, model.index + 1)
|
||||||
|
@ -56,7 +54,7 @@ Window {
|
||||||
height: 24
|
height: 24
|
||||||
iconSource: FluentIcons.ChromeBack
|
iconSource: FluentIcons.ChromeBack
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if (header.count() > 1) {
|
if (header.count() > 0) {
|
||||||
header.items = header.items.slice(
|
header.items = header.items.slice(
|
||||||
0, header.count() - 1)
|
0, header.count() - 1)
|
||||||
}
|
}
|
||||||
|
@ -65,46 +63,53 @@ Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function add(folderName) {
|
function add(folderName, uuid) {
|
||||||
listView.headerItem.children[0].items
|
console.log(header.items)
|
||||||
= listView.headerItem.children[0].items.concat([{
|
header.items = header.items.concat([{
|
||||||
"title": folderName
|
"title": folderName,
|
||||||
}])
|
"uuid": uuid
|
||||||
|
}])
|
||||||
}
|
}
|
||||||
function update() {
|
function update() {
|
||||||
// combine all header items to a path
|
var uuid = header.items.length
|
||||||
var path = ""
|
=== 0 ? "null" : header.items[header.items.length - 1].uuid
|
||||||
// for (var i = 0; i < listView.headerItem.children[0].items.length; i++) {
|
Request.get(uuid, function (response) {
|
||||||
// path += listView.headerItem.children[0].items[i].title + "/"
|
var data = JSON.parse(response)
|
||||||
// }
|
console.log(data.knowledgeFileAttribute)
|
||||||
console.log(path)
|
fileListModel.clear()
|
||||||
var newListModel = [{
|
var files = data.children
|
||||||
"title": "File 2",
|
for (var i = 0; i < files.length; i++) {
|
||||||
"isDir": false,
|
var file = files[i]
|
||||||
"brief": "This is a test file",
|
console.log(file.name)
|
||||||
"size": 500,
|
var modelItem = {
|
||||||
"type": "WORD",
|
"title": file.name,
|
||||||
"date": "2020-09-09",
|
"uuid": file.id,
|
||||||
"pageView": 100,
|
"date": file.createTime
|
||||||
"stars": 10,
|
}
|
||||||
"tags": "tag1,tag2,tag3"
|
if (file.knowledgeFileAttribute === null) {
|
||||||
}, {
|
modelItem.type = "folder"
|
||||||
"title": "File 3",
|
modelItem.isDir = true
|
||||||
"isDir": false,
|
modelItem.size = 0
|
||||||
"brief": "This is a test file",
|
} else {
|
||||||
"size": 500,
|
modelItem.isDir = false
|
||||||
"type": "WORD",
|
modelItem.type = file.knowledgeFileAttribute.suffix
|
||||||
"date": "2020-09-09",
|
modelItem.size = file.knowledgeFileAttribute.size
|
||||||
"pageView": 100,
|
modelItem.brief = file.knowledgeFileAttribute.brief
|
||||||
"stars": 10,
|
modelItem.pageView = file.knowledgeFileAttribute.pageView
|
||||||
"tags"// 15 tags
|
modelItem.stars = 0
|
||||||
: "tag1,tag2,tag3,tag4,tag5,tag6,tag7,tag8,tag9,tag10,tag11,tag12,tag13,tag14,tag15"
|
// merge file.knowledgeFileAttribute.tags array to a string
|
||||||
}]
|
var tagString = ""
|
||||||
// http request for new list data
|
for (var j = 0; j < file.knowledgeFileAttribute.tags.length; j++) {
|
||||||
fileListModel.clear()
|
if (j != 0)
|
||||||
fileListModel.append(newListModel)
|
tagString = tagString + ","
|
||||||
// set ListView currentItem to null
|
tagString = tagString + file.knowledgeFileAttribute.tags[j].name
|
||||||
listView.currentIndex = -1
|
}
|
||||||
|
modelItem.tags = tagString
|
||||||
|
}
|
||||||
|
fileListModel.append(modelItem)
|
||||||
|
}
|
||||||
|
listView.currentIndex = -1
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,18 +122,19 @@ Window {
|
||||||
color: !ListView.isCurrentItem ? "lightgray" : "red"
|
color: !ListView.isCurrentItem ? "lightgray" : "red"
|
||||||
FileListItem {
|
FileListItem {
|
||||||
id: fileListItem
|
id: fileListItem
|
||||||
|
uuid: model.uuid
|
||||||
width: parent.width
|
width: parent.width
|
||||||
height: parent.height
|
height: parent.height
|
||||||
title: model.title
|
title: model.title
|
||||||
isDir: model.isDir
|
isDir: model.isDir
|
||||||
brief: model.brief
|
|
||||||
size: model.size
|
|
||||||
type: model.type
|
|
||||||
date: model.date
|
date: model.date
|
||||||
pageView: model.pageView
|
brief: isDir ? "" : model.brief
|
||||||
stars: model.stars
|
type: isDir ? "FOLDER" : model.type
|
||||||
|
pageView: isDir ? 0 : model.pageView
|
||||||
|
size: isDir ? 0 : model.size
|
||||||
|
stars: isDir ? 0 : model.stars
|
||||||
// split string to array
|
// split string to array
|
||||||
tags: model.tags.split(",")
|
tags: isDir ? [] : model.tags.split(",")
|
||||||
onTagClicked: {
|
onTagClicked: {
|
||||||
emit: search(tag)
|
emit: search(tag)
|
||||||
console.log(tag)
|
console.log(tag)
|
||||||
|
@ -137,43 +143,43 @@ Window {
|
||||||
function doubleClicked() {
|
function doubleClicked() {
|
||||||
listView.currentIndex = index
|
listView.currentIndex = index
|
||||||
if (model.isDir) {
|
if (model.isDir) {
|
||||||
listView.headerItem.add(model.title)
|
listView.headerItem.add(model.title, model.uuid)
|
||||||
} else {
|
} else {
|
||||||
emit: open(model.uid)
|
emit: open(model.uuid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ListModel {
|
ListModel {
|
||||||
id: fileListModel
|
id: fileListModel
|
||||||
ListElement {
|
// ListElement {
|
||||||
title: "File 1"
|
// title: "File 1"
|
||||||
isDir: true
|
// isDir: true
|
||||||
brief: "This is a test file"
|
// brief: "This is a test file"
|
||||||
type: "FOLDER"
|
// type: "FOLDER"
|
||||||
}
|
// }
|
||||||
ListElement {
|
// ListElement {
|
||||||
uid: "2"
|
// uid: "2"
|
||||||
title: "File 2"
|
// title: "File 2"
|
||||||
isDir: false
|
// isDir: false
|
||||||
brief: "This is a test file"
|
// brief: "This is a test file"
|
||||||
size: 500
|
// size: 500
|
||||||
type: "WORD"
|
// type: "WORD"
|
||||||
date: "2020-09-09"
|
// date: "2020-09-09"
|
||||||
pageView: 100
|
// pageView: 100
|
||||||
stars: 10
|
// stars: 10
|
||||||
}
|
// }
|
||||||
ListElement {
|
// ListElement {
|
||||||
uid: "3"
|
// uid: "3"
|
||||||
title: "File 3"
|
// title: "File 3"
|
||||||
isDir: false
|
// isDir: false
|
||||||
brief: "This is a test file"
|
// brief: "This is a test file"
|
||||||
type: "PPT"
|
// type: "PPT"
|
||||||
date: "2020-09-09"
|
// date: "2020-09-09"
|
||||||
pageView: 100
|
// pageView: 100
|
||||||
size: 10200000022
|
// size: 10200000022
|
||||||
stars: 10
|
// stars: 10
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import QtQuick.Layouts
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
id: fileItem
|
id: fileItem
|
||||||
property string id
|
property string uuid
|
||||||
property string title
|
property string title
|
||||||
property string brief
|
property string brief
|
||||||
property string date
|
property string date
|
||||||
|
@ -37,7 +37,8 @@ Item {
|
||||||
id: titleRow
|
id: titleRow
|
||||||
Image {
|
Image {
|
||||||
id: icon
|
id: icon
|
||||||
source: type ? "qrc:/AicsKnowledgeBase/res/" + type + ".png" : ""
|
source: type ? "qrc:/AicsKnowledgeBase/res/" + type.toUpperCase(
|
||||||
|
) + ".png" : ""
|
||||||
Layout.preferredHeight: 18
|
Layout.preferredHeight: 18
|
||||||
Layout.preferredWidth: 18
|
Layout.preferredWidth: 18
|
||||||
}
|
}
|
||||||
|
@ -69,7 +70,7 @@ Item {
|
||||||
}
|
}
|
||||||
FluText {
|
FluText {
|
||||||
id: pageView
|
id: pageView
|
||||||
text: fileItem.pageView + "浏览" + tags.length
|
text: fileItem.pageView + "浏览"
|
||||||
}
|
}
|
||||||
FluText {
|
FluText {
|
||||||
id: stars
|
id: stars
|
||||||
|
|
|
@ -5,7 +5,7 @@ import QtQuick
|
||||||
QtObject {
|
QtObject {
|
||||||
id: request
|
id: request
|
||||||
|
|
||||||
property string baseUrl: "http://127.0.0.1:4523/m1/2914957-0-default/"
|
property string baseUrl: "http://127.0.0.1:4523/m1/2914957-0-5604d062/"
|
||||||
|
|
||||||
// GET
|
// GET
|
||||||
function get(url, success, failure) {
|
function get(url, success, failure) {
|
||||||
|
|
|
@ -36,7 +36,7 @@ int main(int argc, char* argv[])
|
||||||
qmlRegisterSingletonInstance<HttpClient>("AicsKB.HttpClient", 1, 0, "HttpClient", httpClient);
|
qmlRegisterSingletonInstance<HttpClient>("AicsKB.HttpClient", 1, 0, "HttpClient", httpClient);
|
||||||
|
|
||||||
|
|
||||||
const QUrl url(u"qrc:/AicsKnowledgeBase/qml/App.qml"_qs);
|
const QUrl url(u"qrc:/AicsKnowledgeBase/qml/component/FileList.qml"_qs);
|
||||||
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
|
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
|
||||||
&app, [url](QObject* obj, const QUrl& objUrl) {
|
&app, [url](QObject* obj, const QUrl& objUrl) {
|
||||||
if (!obj && url == objUrl)
|
if (!obj && url == objUrl)
|
||||||
|
|
Loading…
Reference in New Issue