DPS_Manage/Page/Tab_shop.qml

353 lines
12 KiB
QML

import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15
import QtGraphicalEffects 1.15
import QtQuick.Shapes 1.15
import QtQuick.Layouts 1.15
import HuskarUI.Basic 1.0
import "../MyGlobals" 1.0
import QmlTool 1.0
import "../Component" 1.0
Item {
anchors.fill: parent
anchors.leftMargin: 1
ListModel {
id: pluginModel
}
Component.onCompleted: {
GlobalVars.tab_shop = this;
initServerPluginList();
initAccServerList();
}
//监听全局变量的变化 这里需要监听 因为在本页会产生刷新数据
Connections {
target: GlobalVars
//插件市场的全部插件
function onServerPluginListChanged(){initServerPluginList();}
function onAccServerListChanged(){initAccServerList();}
}
//构造数据
function initServerPluginList(){
//全局数据插件列表存在
if(GlobalVars.serverPluginList){
var Data = GlobalVars.serverPluginList;
// 遍历对象的属性
for (var key in Data) {
var obj = Data[key]
pluginModel.append(obj);
}
gv.model = pluginModel;
}
}
function initAccServerList(){
//全局数据服务器列表存在
if(GlobalVars.accServerList){
server_select.model = [];
var arrbuf = [];
for(var i = 0; i < GlobalVars.accServerList.length;i++){
var obj = GlobalVars.accServerList[i];
var buf = {
label : obj.serverIp,
value : i
}
arrbuf.push(buf);
}
server_select.model = arrbuf;
}
}
//插件详情页面的窗口
property var pluginInfoWidow: null
//搜索插件的模式
property int searchMode: 0
Rectangle{
id:search_rect
anchors.top : parent.top
anchors.left: parent.left
anchors.right: parent.right
anchors.leftMargin: 15
anchors.rightMargin: 26
height: 80
color:"transparent"
radius: 8
border.color: HusTheme.isDark ? "#23272e" : "#f0f4f7"
border.width: 3
HusIconText {
id:server_label
anchors.left: parent.left
anchors.leftMargin: 10
anchors.top: parent.top
anchors.topMargin: 14
text:"选择要安装插件的服务器:"
font {
pixelSize: 14
family: HusTheme.Primary.fontPrimaryFamily
}
}
HusSelect {
id:server_select
anchors.left: server_label.right
anchors.leftMargin: 10
anchors.top: parent.top
anchors.topMargin: 10
width: 250
height: 30
tooltipVisible: true
onCurrentIndexChanged: {
GlobalVars.selectServer = currentIndex
}
}
Row {
anchors.top: server_label.bottom
anchors.topMargin: 15
anchors.left: server_label.left
spacing: 48
ButtonGroup { id: radioGroup }
HusRadio {
text: qsTr("索引插件名")
ButtonGroup.group: radioGroup
checked:true
onCheckedChanged: {searchMode = 0}
HusIconText {
anchors.left: parent.right
anchors.leftMargin: 2
anchors.top: parent.top
iconSize: 24
iconSource: HusIcon.ReadOutlined
}
}
HusRadio {
text: qsTr("索引作者名")
ButtonGroup.group: radioGroup
onCheckedChanged: {searchMode = 1}
HusIconText {
anchors.left: parent.right
anchors.leftMargin: 2
anchors.top: parent.top
anchors.topMargin: -2
iconSize: 24
iconSource: HusIcon.TeamOutlined
}
}
HusRadio {
text: qsTr("索引描述内容")
ButtonGroup.group: radioGroup
onCheckedChanged: {searchMode = 2}
HusIconText {
anchors.left: parent.right
anchors.leftMargin: 2
anchors.top: parent.top
anchors.topMargin: -2
iconSize: 24
iconSource: HusIcon.ProfileOutlined
}
}
}
HusAutoComplete {
anchors.right: search_rect.right
anchors.rightMargin: 10
anchors.verticalCenter: search_rect.verticalCenter
width: 370
height: 40
tooltipVisible: true
placeholderText: qsTr("输入插件名以查找插件")
selectByMouse: true
clearEnabled:true
iconSource: HusIcon.CloseSquareFilled
onSearch: function(input) {
if (!input) {
options = [];
} else {
if(GlobalVars.serverPluginList){
var Data = GlobalVars.serverPluginList;
var SearchBuf = [];
// 遍历对象的属性
for (var key in Data) {
var obj = Data[key];
//搜索插件名
if(searchMode === 0){
if(obj.ProjectName.indexOf(input) !== -1)SearchBuf.push({label: obj.ProjectName + "\t作者: " + obj.ProjectAuthor, index:key});
}
//搜索作者
else if(searchMode === 1){
if(obj.ProjectAuthor.indexOf(input) !== -1)SearchBuf.push({label: obj.ProjectName + "\t作者: " + obj.ProjectAuthor, index:key});
}
//搜索描述
else if(searchMode === 2){
if(obj.ProjectDescribe.indexOf(input) !== -1)SearchBuf.push({label: obj.ProjectName + "\t作者: " + obj.ProjectAuthor, index:key});
}
}
options = SearchBuf;
}
else{
options = [];
}
}
}
onSelect:function(select){
if (!pluginInfoWidow) {
// 创建新窗口
var component = Qt.createComponent("Window_PluginInfo_Goods.qml");
pluginInfoWidow = component.createObject(parent);
pluginInfoWidow.init(select.index)
// 绑定关闭时自动销毁
pluginInfoWidow.closing.connect(function() {
pluginInfoWidow.destroy()
pluginInfoWidow = null // 关键:释放引用
})
}
pluginInfoWidow.y = GlobalVars.main_Window.y + 85
pluginInfoWidow.show()
pluginInfoWidow.raise() // 把窗口提到最前面
clearInput()
}
}
}
GridView {
id: gv
anchors.top: search_rect.bottom
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
anchors.margins: 4
cellWidth: 420
cellHeight: 128
clip: true
delegate:Item { // 每个格子的容器
width: gv.cellWidth
height: gv.cellHeight
Card {
id:card
anchors.centerIn: parent // 在格子容器中居中
width: parent.width - 24 // 改用相对尺寸
height: parent.height - 24
isDarkMode: HusTheme.isDark
onClicked:function(){
if (!pluginInfoWidow) {
// 创建新窗口
var component = Qt.createComponent("Window_PluginInfo_Goods.qml");
pluginInfoWidow = component.createObject(parent);
pluginInfoWidow.init(index)
// 绑定关闭时自动销毁
pluginInfoWidow.closing.connect(function() {
pluginInfoWidow.destroy()
pluginInfoWidow = null // 关键:释放引用
})
}
pluginInfoWidow.y = GlobalVars.main_Window.y + 85
pluginInfoWidow.show()
pluginInfoWidow.raise() // 把窗口提到最前面
}
content: ColumnLayout {
width: parent.width
height: parent.height
spacing: 4
Rectangle{
id:title_row
Layout.fillWidth: true
height: 30
color:"transparent"
Text {
id:title
text: model.ProjectName
font {
pixelSize: 24
family: HusTheme.Primary.fontPrimaryFamily
bold: true
}
color: HusTheme.Primary.colorTextBase
elide: Text.ElideRight
}
Text {
id:author
anchors.top: title_row.top
anchors.topMargin: 4
anchors.right: title_row.right
anchors.rightMargin: 10
text: "作者:" + model.ProjectAuthor
font {
pixelSize: 16
family: HusTheme.Primary.fontPrimaryFamily
bold: true
}
color: HusTheme.Primary.colorTextBase
elide: Text.ElideRight
}
}
Text {
Layout.fillWidth: true
text: model.ProjectDescribe
wrapMode: Text.WordWrap
maximumLineCount: 2
font {
pixelSize: 14
family: HusTheme.Primary.fontPrimaryFamily
}
color: HusTheme.Primary.colorTextSecondary
elide: Text.ElideRight
}
// Item {
// Layout.fillWidth: true
// Layout.fillHeight: true
// height:300
// DelRectangle {
// id: imageContainer
// anchors.fill: parent
// radius: 6
// color: "transparent"
// clip: true
// Image {
// id: card_image
// asynchronous: true // 异步加载不阻塞UI
// cache: true // 启用内存缓存
// anchors.fill: parent
// source: "qrc:/image/moren.png"
// // source: model.ImageMini
// fillMode: Image.PreserveAspectCrop
// }
// layer.enabled: true
// layer.effect: OpacityMask {
// maskSource: Rectangle {
// width: imageContainer.width
// height: imageContainer.height
// radius: imageContainer.radius
// }
// }
// }
// }
}
}
}
}
}