160 lines
4.4 KiB
QML
160 lines
4.4 KiB
QML
import QtQuick 2.14
|
|
import QtQuick.Controls 2.14
|
|
import QtMultimedia 5.11 // 用于加载 GIF
|
|
import "qrc:/QmlFiles/qml/components"
|
|
|
|
Rectangle {
|
|
id: loadingWidget
|
|
width: parent.width
|
|
height: parent.height
|
|
color: Colors.sColor_Blue
|
|
|
|
signal startLoadingSignal()
|
|
signal setErrorStateSignal()
|
|
|
|
Column {
|
|
id: mainLayout
|
|
anchors.centerIn: parent
|
|
spacing: 20
|
|
|
|
// 加载动画
|
|
AnimatedImage {
|
|
id: loadingIcon
|
|
source: "qrc:/icon/icon/loading.gif" // 确保 GIF 文件已正确打包到 qrc 资源中
|
|
width: 150
|
|
height: 150
|
|
visible: false
|
|
playing: false // 控制是否播放
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
}
|
|
|
|
// 错误图片
|
|
Image {
|
|
id: errorIcon
|
|
source: "qrc:/icon/icon/error.png"
|
|
width: 150
|
|
height: 150
|
|
visible: false
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
}
|
|
// 日志文本
|
|
TextArea {
|
|
id: warningLog
|
|
width: 300
|
|
height: 100
|
|
font.pixelSize: 16 // 字体大小
|
|
font.bold: true // 加粗
|
|
readOnly: true
|
|
color: "red" // 字体颜色
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
visible: false
|
|
wrapMode: Text.Wrap // 允许换行
|
|
|
|
// 设置文本居中
|
|
horizontalAlignment: Text.AlignHCenter // 水平居中
|
|
verticalAlignment: Text.AlignVCenter // 垂直居中
|
|
|
|
background: Rectangle {
|
|
color: "transparent"
|
|
border.color: "transparent"
|
|
radius: 5
|
|
}
|
|
}
|
|
|
|
// 日志文本
|
|
TextArea {
|
|
id: initLog
|
|
width: 300
|
|
height: 100
|
|
font.pixelSize: 14
|
|
readOnly: true
|
|
color: "white"
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
background: Rectangle {
|
|
color: "transparent"
|
|
border.color: "black"
|
|
radius: 5
|
|
}
|
|
}
|
|
|
|
Row {
|
|
spacing: 20
|
|
visible: false // 默认隐藏按钮
|
|
id: buttonRow
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
FancyPushButtonText {
|
|
id: retryBtn
|
|
text: "重试"
|
|
width: 100
|
|
height: 50
|
|
onClicked: {
|
|
retryBtn.enabled = false;
|
|
manualBtn.enabled = false;
|
|
loadingWidget.startLoading()
|
|
}
|
|
}
|
|
|
|
FancyPushButtonText {
|
|
id: manualBtn
|
|
text: "离线模式"
|
|
width: 180
|
|
height: 50
|
|
onClicked: {
|
|
console.log("进入离线模式")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// 启动加载
|
|
function startLoading() {
|
|
loadingIcon.visible = true;
|
|
loadingIcon.playing = true;
|
|
errorIcon.visible = false;
|
|
buttonRow.visible = false;
|
|
warningLog.visible = false;
|
|
initLog.text = "正在初始化...";
|
|
}
|
|
|
|
// 设置错误状态
|
|
function setErrorState() {
|
|
loadingIcon.visible = false;
|
|
loadingIcon.playing = false;
|
|
|
|
warningLog.visible = true;
|
|
errorIcon.visible = true;
|
|
buttonRow.visible = true;
|
|
retryBtn.enabled = true;
|
|
manualBtn.enabled = true;
|
|
}
|
|
// 打印日志文本 (颜色, 文本) 并返回行数
|
|
function appendInitLog(text,color) {
|
|
initLog.text += `<font color='${color}'>${text}</font><br>`;
|
|
return initLog.text.split("<br>").length - 1; // 返回行数
|
|
}
|
|
|
|
// 修改日志文本 (颜色, 文本, 行数)
|
|
function modifyInitLog(text, color, lineNumber) {
|
|
let lines = initLog.text.split("<br>");
|
|
if (lineNumber > 0 && lineNumber <= lines.length) {
|
|
lines[lineNumber - 1] = `<font color='${color}'>${text}</font>`;
|
|
initLog.text = lines.join("<br>");
|
|
} else {
|
|
console.log("行号超出范围");
|
|
}
|
|
}
|
|
function clearInitLog() {
|
|
initLog.text = "";
|
|
}
|
|
|
|
function appendWarningLog(text) {
|
|
warningLog.text += text;
|
|
console.log(warningLog.text);
|
|
}
|
|
function clearWarningLog() {
|
|
warningLog.text = "";
|
|
}
|
|
}
|