import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.12
import Qt5Compat.GraphicalEffects
import QtQuick.Layouts 1.12

import "."
//import io.qt.examples.chattutorial 1.0


Rectangle {
    id:chat
    Accessible.name: "kylin-aiassistant_Chat_Rectangle_1"
    visible: true
    color: "#F5F5F5"
    property string tabViewString: "Command"
    property bool isReplying : false
    property string aiImagePreviewSrc: ""
    property bool isSynthesizing: false
    property int winMode: 2
    property bool isRetry : false
    property string originText: ""      //语音输入时，记录输入框内的源文字，用于实现显示文本修正过程的功能


    // 语音对话4种状态标志
    property int speechMode : 0
    // 全局记录是否是语音对话
    property bool isSpeech: false

    // 暴露voiceInputRectangle.isCapturingVideo
    property bool isCapturingVideo:false

    //同步界面正在回答状态到后端
    onIsReplyingChanged: {
        msgPane.onChangedIsReplyingStatus(isReplying);
    }

    function backtoHome() {
        listView.dialogType = "Text"
        bottomArea.visible = true
        if(listView.isChatEndFlag){
            moveCommonTimer.running = true
        }
        if(speechMode === 2){
            msgPane.onCancelAudio();
            isReplying = false;
        }
        // 返回时，如果有遮罩层，则隐藏遮罩层
        commandShowRet.visible = false
        bottomAreaBackgroundRet.visible = false
        // 恢复文本和滚动条，关闭提示词
        onChangeWinModeToChatTimer.running = true
    }

    // 处理清空ListModel信号的函数
    function handleClearListModel() {
        listModel.clear();
        // 新建对话时，清空输入框文字
        messageField.text = ""
        // 新建对话时，如果有遮罩层，则隐藏遮罩层
        commandShowRet.visible = false
        bottomAreaBackgroundRet.visible = false
        // 恢复文本和滚动条，关闭提示词
        onChangeWinModeToChatTimer.running = true
        // 初始化边框颜色
        inputRectangeGradient.stops[0].color = "#E85CFF" // 改变第一个颜色
        inputRectangeGradient.stops[1].color = "#3790FA" // 改变第二个颜色
    }
    // 处理清空ListModel信号的函数
    function handleClearMessageField() {
        // 切换对话时，清空输入框文字
        messageField.text = ""
        // 窗口模式下，切换对话关闭提示词
        commandShowRet.visible = false
        bottomAreaBackgroundRet.visible = false
        // 恢复文本和滚动条，关闭提示词
        onChangeWinModeToChatTimer.running = true
    }

    // 初始化朗读
    function handleInitReadingIndex() {
        // 切换对话时，初始化朗读
        listView.curIndex = -1;
        listView.preIndex = -1
    }

    // 侧边栏恢复到主页初始化输入框
    function handleIniInputMessagefild() {
        commandShowRet.visible = false
        bottomAreaBackgroundRet.visible = false
        // 恢复文本和滚动条，关闭提示词
        onChangeWinModeToChatTimer.running = true
        // 初始化边框颜色
        inputRectangeGradient.stops[0].color = "#E85CFF" // 改变第一个颜色
        inputRectangeGradient.stops[1].color = "#3790FA" // 改变第二个颜色
    }

    function closeCommand(){
        // 窗口模式下，切换对话关闭提示词
        commandShowRet.visible = false
        bottomAreaBackgroundRet.visible = false
        // 恢复文本和滚动条，关闭提示词
        onChangeWinModeToChatTimer.running = true
    }

    //用于用户发送消息转换
    function convertString(msgMessage){
        // 判断如果是带标签的指令，特殊转换一下
        if(msgMessage !== "" && msgMessage !== null && msgMessage !== undefined){
            // 将换行符转换为 <br> 标签
            var htmlText = msgMessage.replace(/\n/g, "<br>");
            // 可以根据需要添加其他格式化处理，例如
            // 将 **加粗** 的内容用 <b> 包裹
            htmlText = htmlText.replace(/\*\*(.*?)\*\*/g, "<b>$1</b>");
            // 将 _斜体_ 的内容用 <i> 包裹
            htmlText = htmlText.replace(/_(.*?)_/g, "<i>$1</i>");
            msgMessage = htmlText
        }else{
            return "";
        }

        return msgMessage;

    }

    // 替换/n
    function replaceString(content){
        var replaceString = content.replace(/\n/g, "")
        return replaceString
    }

    Connections
    {
        target: chat
        //用于判断全部指令展开或收起时输入框焦点及边框颜色
        onTabViewStringChanged:function(){
            // 判断全部指令展开时
            if(chat.tabViewString === "AllCommand"){
                if(!messageField.focus){
                    //inputRectange.border.color = "#F5F5F5"
                }else{
                    if(messageField.text.length === 0){
                        messageField.focus = false
                    }
                }
                inputRectangeGradient.stops[0].color = "#F5F5F5" // 改变第一个颜色
                inputRectangeGradient.stops[1].color = "#F5F5F5" // 改变第二个颜色
                flowLayout.visible = true
                commandShowRet.visible = true
                bottomAreaBackgroundRet.visible = true
            //判断全部指令收起时
            }else{
                if(messageField.text.length === 0){
                    messageField.focus = false
                }
                flowLayout.visible = false
                bottomAreaBackgroundRet.visible = false
                commandShowRet.visible = false
            }
            // 判断全部指令操作时若指令,图片预览,文档预览有一项存在,则边框颜色激活
            if(inputRectange.activeCommand !== "" || inputRectange.imagePreviewSrc !== "" || inputRectange.documentPreviewName !== ""  || messageField.text.length > 0){
                //inputRectange.border.color = "#3790FA"
                inputRectangeGradient.stops[0].color = "#E85CFF" // 改变第一个颜色
                inputRectangeGradient.stops[1].color = "#3790FA" // 改变第二个颜色
            }
        }
    }

    //底部白色背景，全部指令展开时触发
    Rectangle{
        id: bottomAreaBackground
        Accessible.name: "kylin-aiassistant_Chat_bottomAreaBackground"
        width: parent.width
        height: bottomArea.height
        color: Qt.rgba(0/255, 0/255, 0/255, 0.2)
        visible: tabViewString === "AllCommand"
        anchors.bottom: parent.bottom
        Rectangle {
            anchors.fill: parent
            color: "#FFFFFF"
            radius: 12
            visible: tabViewString === "AllCommand"
        }
    }
    //底部白色背景，全部指令展开时触发,用于实现左上和右上圆角
    Rectangle{
        id: bottomAreaBackgroundRet
        Accessible.name: "kylin-aiassistant_Chat_bottomAreaBackgroundRet"
        width: parent.width
        height: 12
        color: "#FFFFFF"
        visible: tabViewString === "AllCommand" && chat.winMode !== 2
        anchors.bottom: parent.bottom
    }
    ColumnLayout {
        anchors.fill: parent
        anchors.topMargin: (listModel.count === 0) ? 40 : undefined

        //存储
        ListModel {
            id: listModel
            Accessible.name: "kylin-aiassistant_Chat_listModel"
        }

        ListModel {
            id: voiceCommendListModel
            Accessible.name: "kylin-aiassistant_Chat_voiceCommendListModel"
            ListElement{commendTextName:"调高亮度"}
            ListElement{commendTextName:"打开音乐"}
            ListElement{commendTextName:"打开蓝牙"}
            ListElement{commendTextName:"打开wps"}
        }

        ListModel {
            id: askListModel
            Accessible.name: "kylin-aiassistant_Chat_askListModel"
            ListElement{askTextName: qsTr("How do you remove coffee stains from white clothes?")}
            ListElement{askTextName: qsTr("What are great games to play for outdoor gatherings?")}
            ListElement{askTextName: qsTr("Can you help me write a polite email template for a client?")}
            ListElement{askTextName: qsTr("Can you recommend some practical time management methods?")}
        }

        //AI助手首页
        Rectangle {
            id: mainPage
            Accessible.name: "kylin-aiassistant_Chat_mainPage"
            Layout.fillWidth: true
            Layout.fillHeight: true
            height: mainPageColumnLayout.height
            visible: listModel.count === 0
            color: "#F5F5F5"

            ColumnLayout {
                id: mainPageColumnLayout
                Accessible.name: "kylin-aiassistant_Chat_mainPageColumnLayout"
                anchors.fill: parent
                spacing: 0
                width: chat.width
                Layout.fillWidth: true
                Layout.fillHeight: true

                Image {
                    id: welcomeImage
                    Accessible.name: "kylin-aiassistant_Chat_welcomeImage"
                    Layout.preferredWidth: 64
                    Layout.preferredHeight: 64
                    Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter
                    source: "qrc:/icon/icon/xiaoqi.svg"
                }

                Rectangle{
                    id: welcomeOneRet
                    Accessible.name: "kylin-aiassistant_Chat_welcomeOneRet"
                    color: "transparent"
                    width: parent.width
                    height: 20
                }

                Text {
                    id: welcomeText
                    Accessible.name: "kylin-aiassistant_Chat_welcomeText"
                    Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter
                    text: qsTr("Hello, I'm AI assistant Qiling!")
                    font.weight: Font.Bold
                    font.pixelSize: 20
                    color: Qt.rgba(55/255, 144/255, 250/255);
//                    LinearGradient {
//                        anchors.fill: welcomeText
//                        source: welcomeText
//                        gradient: Gradient {
//                            orientation: Gradient.Horizontal
//                            GradientStop { position: 0.0; color: "#3790FA" }
//                            GradientStop { position: 1.0; color: "#E85CFF" }
//                        }
//                    }
                }

                Text {
                    id: welcomeAskOneText
                    Accessible.name: "kylin-aiassistant_Chat_welcomeAskOneText"
                    Layout.preferredWidth: parent.width
                    leftPadding: 20
                    rightPadding: 20
                    Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter
                    horizontalAlignment: Text.AlignHCenter
                    text: qsTr("As your intelligent assistant, I can answer questions, write copy, come up with ideas, etc., how can I help you?")
                    wrapMode: Text.WordWrap

                }

                Rectangle{
                    id: welcomeTwoRet
                    Accessible.name: "kylin-aiassistant_Chat_welcomeTwoRet"
                    color: "transparent"
                    width: parent.width
                    height: 20
                }

                Text {
                    id: welcomeAskTwoText
                    Accessible.name: "kylin-aiassistant_Chat_welcomeAskTwoText"
                    Layout.preferredWidth: parent.width
                    leftPadding: 20
                    rightPadding: 20
                    Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter
                    horizontalAlignment: Text.AlignHCenter
                    text: qsTr("You can ask me:")
                    wrapMode: Text.WordWrap
                    color: Qt.rgba(0/255, 0/255, 0/255, 0.6);
                }

                ListView {
                    id: askListViewSide
                    Accessible.name: "kylin-aiassistant_Chat_askListViewSide"
                    Layout.fillHeight: true
                    width: chat.width
                    model: askListModel
                    boundsMovement: Flickable.StopAtBounds // 防止过度滚动
                    visible: chat.winMode === 2

                    delegate: Column {
                        width: chat.width - 40
                        leftPadding: 20
                        rightPadding: 20
                        topPadding: 4
                        Rectangle{
                            id: askRowRet
                            Accessible.name: "kylin-aiassistant_Chat_askRowRet"
                            width: parent.width
                            height: 44
                            color: "#0d262626"
                            radius: 4
                            MouseArea{
                                anchors.fill: parent
                                hoverEnabled: true
                                onEntered: {
                                    // 当用户名宽度大于组件显示省略号时，悬浮显示提示
                                    if (askTextMetrics.width > askText.width) {
                                        askTextTooltip.visible = true
                                    } else {
                                        askTextTooltip.visible = false
                                    }
                                    askRowRet.color = "#26000000";
                                }
                                onExited: {
                                    askTextTooltip.visible = false
                                    askRowRet.color = "#0d262626";
                                }
                                onPressed: {
                                    askRowRet.color = "#33000000";
                                }
                                onReleased: {
                                    askRowRet.color = "#0d262626";
                                }
                                onClicked: {
                                    if (listModel.count > 0) {
                                        var lastMsg = listModel.get(listModel.count - 1)
                                        lastMsg.isRefreshed = true
                                    }

                                    // 切换到插件时正在说话，取消语音录制
                                    if (isCapturingVideo === true) {
                                        msgPane.onCancelAudio();
                                    }
                                    var msgHeadList = {
                                    };
                                    var jsonMsgHead = JSON.stringify(msgHeadList)
                                    moveCommonTimer.running = true
                                    var retJsonString = msgPane.onSendMsg(jsonMsgHead, askText.text)
                                    var retJsonObject = JSON.parse(retJsonString);
                                    isReplying = retJsonObject['isReplying'] !== undefined ? retJsonObject['isReplying'] : false
                                }
                            }

                            Row{
                                id: askRow
                                Accessible.name: "kylin-aiassistant_Chat_askRow"
                                width: parent.width
                                height: 44
                                Rectangle{
                                    id: askImageRet
                                    Accessible.name: "kylin-aiassistant_Chat_askImageRet"
                                    width: 32
                                    color: "transparent"
                                    height: 44
                                    Image {
                                        id: askImage
                                        Accessible.name: "kylin-aiassistant_Chat_askImage"
                                        source: "qrc:/icon/icon/ask.svg"
                                        anchors.centerIn: parent
                                        width: 12
                                        height: 12
                                    }
                                }
                                Text {
                                    id: askText
                                    Accessible.name: "kylin-aiassistant_Chat_askText"
                                    width:askRow.width - askImage.width - 18
                                    text: askTextName
                                    elide: Text.ElideRight
                                    wrapMode: Text.NoWrap
                                    anchors.verticalCenter: parent.verticalCenter
                                }
                                // 悬浮提示框
                                ToolTip {
                                    id: askTextTooltip
                                    Accessible.name: "kylin-aiassistant_Chat_askTextTooltip"
                                    visible: false   // 默认不显示
                                    text: askTextName  // 显示完整文本
                                    delay: 500       // 延迟显示提升用户体验
                                    contentItem: Text {
                                        text: askTextName
                                        font.pixelSize: 14
                                        wrapMode: Text.WordWrap
                                    }
                                }
                                // 用于测量文本宽度的 TextMetrics 用于显示长度超出时的计算
                                Text {
                                    id: askTextMetrics
                                    Accessible.name: "kylin-aiassistant_Chat_askTextMetrics"
                                    text: askTextName
                                    visible: false
                                }

                            }
                        }
                    }
                }
                Flow {
                    id: askListViewWin
                    Accessible.name: "kylin-aiassistant_Chat_askListViewWin"
                    //width: chat.width - 40
                    Layout.fillWidth: true
                    height: 96
                    clip: true  // 超出内容不会显示
                    visible: chat.winMode === 3
                    spacing: 8
                    Repeater {
                        model: askListModel;
                        delegate: Row {
                            id: askListModelRow
                            Accessible.name: "kylin-aiassistant_Chat_askListModelRow"
                            width: ((chat.width - 40 - 8) / 2)
                            leftPadding: 20
                            rightPadding: 20
                            //spacing: 8
                            Rectangle{
                                id: askRowRetWin
                                Accessible.name: "kylin-aiassistant_Chat_askRowRetWin"
                                width: parent.width
                                height: 44
                                color: "#0d262626"
                                radius: 4
                                MouseArea{
                                    anchors.fill: parent
                                    hoverEnabled: true
                                    onEntered: {
                                        // 当用户名宽度大于组件显示省略号时，悬浮显示提示
                                        if (askTextWinMetrics.width > askTextWin.width) {
                                            askTextWinTooltip.visible = true
                                        } else {
                                            askTextWinTooltip.visible = false
                                        }
                                        askRowRetWin.color = "#26000000";
                                    }
                                    onExited: {
                                        askTextWinTooltip.visible = false
                                        askRowRetWin.color = "#0d262626";
                                    }
                                    onPressed: {
                                        askRowRetWin.color = "#33000000";
                                    }
                                    onReleased: {
                                        askRowRetWin.color = "#0d262626";
                                    }
                                    onClicked: {
                                        if (listModel.count > 0) {
                                            var lastMsg = listModel.get(listModel.count - 1)
                                            lastMsg.isRefreshed = true
                                        }
                                        var msgHeadList = {
                                        };
                                        var jsonMsgHead = JSON.stringify(msgHeadList)
                                        moveCommonTimer.running = true
                                        var retJsonString = msgPane.onSendMsg(jsonMsgHead, askTextWin.text)
                                        var retJsonObject = JSON.parse(retJsonString);
                                        isReplying = retJsonObject['isReplying'] !== undefined ? retJsonObject['isReplying'] : false
                                    }
                                }

                                Row{
                                    id: askRowWin
                                    Accessible.name: "kylin-aiassistant_Chat_askRowWin"
                                    width: parent.width
                                    height: 44
                                    Rectangle{
                                        id: askImageRetWin
                                        Accessible.name: "kylin-aiassistant_Chat_askImageRetWin"
                                        width: 32
                                        color: "transparent"
                                        height: 44
                                        Image {
                                            id: askImageWin
                                            Accessible.name: "kylin-aiassistant_Chat_askImageWin"
                                            source: "qrc:/icon/icon/ask.svg"
                                            anchors.centerIn: parent
                                            width: 12
                                            height: 12
                                        }
                                    }
                                    Text {
                                        id: askTextWin
                                        Accessible.name: "kylin-aiassistant_Chat_askTextWin"
                                        width:askRowWin.width - askImageWin.width - 16
                                        text: askTextName
                                        elide: Text.ElideRight
                                        wrapMode: Text.NoWrap
                                        anchors.verticalCenter: parent.verticalCenter
                                    }
                                    // 悬浮提示框
                                    ToolTip {
                                        id: askTextWinTooltip
                                        Accessible.name: "kylin-aiassistant_Chat_askTextWinTooltip"
                                        visible: false   // 默认不显示
                                        text: askTextName  // 显示完整文本
                                        delay: 500       // 延迟显示提升用户体验
                                        contentItem: Text {
                                            text: askTextName
                                            font.pixelSize: 14
                                            wrapMode: Text.WordWrap
                                        }
                                    }
                                    // 用于测量文本宽度的 TextMetrics 用于显示长度超出时的计算
                                    Text {
                                        id: askTextWinMetrics
                                        Accessible.name: "kylin-aiassistant_Chat_askTextWinMetrics"
                                        text: askTextName
                                        visible: false
                                    }
                                }
                            }
                        }
                    }
                }

                // 弹性模块，用于解决页面的拉伸
                Rectangle{
                    id: elasticityRet
                    Accessible.name: "kylin-aiassistant_Chat_elasticityRet"
                    color: "transparent"
                    Layout.fillWidth: true
                    Layout.fillHeight: true
                    visible: chat.winMode === 3
                }
            }

        }

        //聊天区域
        ScrollView {
            id: chatContentScrollView
            Accessible.name: "kylin-aiassistant_Chat_chatContentScrollView"
            Layout.fillWidth: true
            Layout.fillHeight: true
            visible: listModel.count > 0
            ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
            //ScrollBar.vertical.minimumSize:this.height
            ScrollBar.vertical.policy: ScrollBar.AlwaysOff

            ListView {
                // provide delegate component.
                id: listView
                Accessible.name: "kylin-aiassistant_Chat_listView"
                Layout.fillHeight: true
                width: chat.width
                clip: true
                boundsMovement: Flickable.StopAtBounds // 防止过度滚动
                //property string botAvatar: "qrc:/qml/qml/botAvatar.svg"
                property string botAvatar: "qrc:/html/html/img/avatar/AI-Writing.svg"
                property string userAvatar: "qrc:/qml/qml/myAvatar.png"
                property string userName: "kylin"
                property bool isRelying: true
                //preIndex 记录了上一次朗读的消息index值，  curIndex记录的正在朗读的消息index值
                property int preIndex: -1
                property int curIndex: -1
                property string dialogType: "Text"
                // 当前回答是否在最下面，（1：当前回答在最下面 0：不在最下面）初始默认最下面
                property int isChatEndFlag: 1
                model: listModel
                property bool isContentOverflowing: false

                onContentHeightChanged: {
                    // 判断内容是否超出容器高度，超出显示滚动条
                    // curHeight用来解决第一条消息滚动条闪烁问题
                    var curHeight = 0
                    if(listView.height === 0){
                        curHeight = 765
                    }
                    isContentOverflowing = contentHeight > (height + curHeight)
                    //console.log("curHeight---"+curHeight+"-----isContentOverflowing---"+ contentHeight +"---"+listView.height+"-----" +isContentOverflowing);
                    if(isContentOverflowing){
                        chatContentScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOn
                    }else{
                        chatContentScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOff
                    }
                }
                onHeightChanged: {
                    // 判断内容是否超出容器高度，超出显示滚动条
                    // curHeight用来解决第一条消息滚动条闪烁问题
                    var curHeight = 0
                    if(listView.height === 0){
                        curHeight = 765
                    }
                    isContentOverflowing = contentHeight > (height + curHeight)
                    //console.log("curHeight---"+curHeight+"-----isContentOverflowing---"+ contentHeight +"---"+listView.height+"-----" +isContentOverflowing);
                    if(isContentOverflowing){
                        chatContentScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOn
                    }else{
                        chatContentScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOff
                    }
                }

                onContentYChanged: {
                    // 当前可视区域的最后一个索引
                    let lastVisibleIndex = listView.indexAt(listView.contentX, listView.contentY + listView.height)
                    //console.log("lastVisibleIndex::::"+lastVisibleIndex)
                    if(lastVisibleIndex === -1){
                        listView.isChatEndFlag = 1
                    }else{
                        listView.isChatEndFlag = 0
                    }
                    //console.log("listView.isChatEndFlag::::"+listView.isChatEndFlag)
                }

                delegate: Column {
                    id: columnContainer
                    Accessible.name: "kylin-aiassistant_Chat_columnContainer"
                    width: chat.width - 40
                    spacing: 6
                    leftPadding: 20
                    rightPadding: 20

                    readonly property bool sentByUser: model.author === "User"

                    //回答区域
                    Row {
                        id: messageRow
                        Accessible.name: "kylin-aiassistant_Chat_messageRow"
                        bottomPadding: 16

                        layoutDirection: sentByUser ? Qt.RightToLeft : Qt.LeftToRight
                        width:parent.width
                        onWidthChanged: {
                            if(model.pdfPath !== "" && chat.winMode !== "2"){
                                if((generatePdfLastMetricsText.width + 16) < chat.width - 40){
                                    generatePdfLastText.width = Math.min(chat.width -40 - 16, (generatePdfLastMetricsText.width + 16 + 40 + 16))
                                }else{
                                    generatePdfLastText.width = chat.width - 40 - 16
                                }
                            }
                            if((model.isAddSchedule || model.isGenerateToDo) && chat.winMode !== "2"){
                                if((scheduleCalendarTextMetricsText.width + 16) < chat.width - 40){
                                    scheduleCalendarText.width = Math.min(chat.width -40 - 16, (scheduleCalendarTextMetricsText.width + 16 + 40 + 16))
                                }else{
                                    scheduleCalendarText.width = chat.width - 40 - 16
                                }
                            }
                        }
                        Rectangle{
                            // 用户绘画对话气泡三角标
                            id: cavasRectnagle
                            Accessible.name: "kylin-aiassistant_Chat_cavasRectnagle"
                            width: sentByUser ? Math.min(Math.max(messageText.implicitWidth + 24, (documentShowColumn.visible ?
                                                                                                       Math.max(documentShowColumn.visible ? documentShowColumn.width : 0 , chatLabel.visible ? chatLabel.width : 0) :
                                                                                                       Math.max(imageGeneratedByAIColumn.visible ? imageGeneratedByAIColumn.width : 0 , chatLabel.visible ? chatLabel.width : 0))),
                                                         parent.width - (!sentByUser ? avatar.width + messageRow.spacing : 0)) + (imageSrc !== "" && messageText.text === "" ? (imageGeneratedByAIColumn.padding + imageGeneratedByAIColumn.padding) : 0)
                                              : chat.winMode === 2 ? parent.width : Math.max((imageGeneratedByAIChat.visible || animatedImageLoader.active) ? 338 + 32 : 0 , Math.max(Math.min(chat.width - 40,(scheduleCalendarText.width + 16)) , Math.max(Math.max(Math.max(modelLabel.width, (toolButtonArea.visible ? (refreshButton.visible ? 205 : 170) : 0))) , Math.max(Math.min(chat.width - 40, (model.pdfPath !== "" ? (generatePdfLastMetricsText.width + 16 + 40 + 16) : 0)),Math.max((messageTextMetrics.implicitWidth <= (chat.width - 40 -16) ? Math.min((messageTextMetrics.implicitWidth + 40) , chat.width - 40) : (chat.width - 40)))
                                                                                             , (reasonMessageMetricsText.implicitWidth <= (chat.width - 40 - 16 - 16) ? Math.min((reasonMessageMetricsText.implicitWidth + 40) , chat.width - 40) : (chat.width - 40))))))
                            height: (messageText.visible ? messageText.implicitHeight : 0) + (modelLabel.visible ? modelLabel.height : 0)
                                    + toolButtonArea.implicitHeight - (((imageSrc !== "" && !pictureOperateRow.visible && !(messageText.text !== "")) || !(toolButtonArea.visible)) ? toolButtonArea.implicitHeight : 0)
                                    /*+ (imageLoading.visible ? imageLoading.height : 0)*/
                                    + (imageGeneratedByAIColumn.visible ? imageGeneratedByAIColumn.height : 0)
                                    + (documentShowColumn.visible ? documentShowColumn.height : 0)
                                    + (scheduleCalendarRet.visible ? scheduleCalendarRet.height : 0)
                                    + (generatePdfRet.visible ? generatePdfLastText.height : 0)
                                    + ((imageSrc !== "" || documentName !== "") && chatLabel.visible && model.message === "" ? chatLabel.height + 16 : 0)
                                    + (pictureOperateRow.visible ? pictureOperateRow.height : 0)
                                            //164 为动图大小，10为下padding
                                    + (animatedImageLoader.active ? (338 + 10) : 0) + 5
                                    + (messageLoader.active ? (16 + 10) : 0)
                                    + (reTryTmp.visible ? reTryTmp.height : 0)
                                    + (infoSourcesRet.visible ? infoSourcesRet.height : 0)
                                    + (reasonMessageText.visible ? reasonMessageText.implicitHeight : 0)
                                    + (thinkRow.visible ? thinkRow.height : 0)
                                    + (thinkLineRet.visible ? thinkLineRet.height : 0)
                                    + (setModelRow.visible ? setModelRow.height : 0)
                                    + (feedbackComponent.visible ? feedbackComponent.height : 0)
                            color:"#F5F5F5"
                            Rectangle {
                                id: messageRectangle
                                Accessible.name: "kylin-aiassistant_Chat_messageRectangle"
                                width: cavasRectnagle.width
                                height: cavasRectnagle.height - 5
                                color: sentByUser ? "#3790FA" : "#FFFFFF"
                                radius: 8
                                anchors.bottom: cavasRectnagle.bottom

                                //todo: 模型角标
                                Rectangle{
                                    id:modelLabel
                                    Accessible.name: "kylin-aiassistant_Chat_modelLabel"
                                    //width: model.modelMsg  === "ai" ? 94 : 140
                                    width: modelLabelText.width
                                    height: 18
                                    visible: !sentByUser
                                    anchors.right: messageRectangle.right
                                    color: "transparent"
                                    //设置左上右下不同圆角值
                                    Canvas {
                                        id: customRectCanvas
                                        Accessible.name: "kylin-aiassistant_Chat_customRectCanvas"
                                        //width: model.modelMsg  === "ai" ? 94 : 140
                                        width: modelLabelText.width
                                        height: 18

                                        onPaint: {
                                            var ctx = customRectCanvas.getContext('2d');
                                            ctx.clearRect(0, 0, customRectCanvas.width, customRectCanvas.height);
                                            var topLeftRadius = 0;
                                            var topRightRadius = 8;
                                            var bottomRightRadius =0;
                                            var bottomLeftRadius = 8;

                                            ctx.beginPath();
                                            ctx.moveTo(topLeftRadius, 0);
                                            ctx.lineTo(customRectCanvas.width - topRightRadius, 0);
                                            ctx.arc(customRectCanvas.width - topRightRadius, topRightRadius, topRightRadius, 1.5 * Math.PI, 2 * Math.PI);
                                            ctx.lineTo(customRectCanvas.width, customRectCanvas.height - bottomRightRadius);
                                            ctx.arc(customRectCanvas.width - bottomRightRadius, customRectCanvas.height - bottomRightRadius, bottomRightRadius, 0, 0.5 * Math.PI);
                                            ctx.lineTo(bottomLeftRadius, customRectCanvas.height);
                                            ctx.arc(bottomLeftRadius, customRectCanvas.height - bottomLeftRadius, bottomLeftRadius, 0.5 * Math.PI, Math.PI);
                                            ctx.lineTo(0, topLeftRadius);
                                            ctx.arc(0, topLeftRadius, topLeftRadius, Math.PI, 1.5 * Math.PI);
                                            ctx.closePath();
                                            ctx.fillStyle = "rgba(0, 0, 0, 0.03)";
                                            ctx.fill();
                                            }
                                        }

                                    Text {
                                        id: modelLabelText
                                        Accessible.name: "kylin-aiassistant_Chat_modelLabelText"
                                        text: (model.modelMsg === undefined || model.modelMsg === "ai") ? qsTr("Generated by AI Assistant") : model.modelMsg
                                        font.pixelSize: 10
                                        topPadding: 4
                                        bottomPadding: 4
                                        rightPadding: 8
                                        leftPadding: 8
                                        color: Qt.rgba(0/255, 0/255, 0/255, 0.3)
                                        anchors.verticalCenter: parent.verticalCenter
                                    }
                                }
                                //系统标签
                                Rectangle{
                                    id:chatLabel
                                    Accessible.name: "kylin-aiassistant_Chat_chatLabel"
                                    width: chatLabelImage.width + chatLabelText.width + 10
                                    height: 24
                                    visible: sentByUser && msgHead.length > 0
                                    color: "white"
                                    radius: 4
                                    anchors.left: messageRectangle.left
                                    anchors.leftMargin: 16
                                    anchors.top:messageRectangle.top
                                    anchors.topMargin: 16
                                    Row{
                                        Column {
                                            topPadding: 4
                                            rightPadding: 2
                                            leftPadding: 4
                                            Image {
                                                id: chatLabelImage
                                                Accessible.name: "kylin-aiassistant_Chat_chatLabelImage"
                                                Layout.preferredWidth: 22
                                                Layout.preferredHeight: 22
                                                Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter
                                                source: "qrc:/html/html/img/AI-mockUp.svg"
                                            }
                                        }
                                        Column {
                                            rightPadding: 4
                                            Text {
                                                id: chatLabelText
                                                Accessible.name: "kylin-aiassistant_Chat_chatLabelText"
                                                text: msgHead
                                                color: "#3790FA"
                                                font.pixelSize: 14
                                            }
                                        }
                                    }
                                }
                                Column {
                                    id: messageTextColumn
                                    Accessible.name: "kylin-aiassistant_Chat_messageTextColumn"
                                    topPadding: ((imageSrc !== "" && !pictureOperateRow.visible && !(messageText.text !== "")) ? 0 : 16)
                                    anchors.fill: parent
                                    // 带指令、带图片或文档对话，且文本为空时占位Rectangle
                                    Rectangle{
                                        id:chatLabelCommand
                                        Accessible.name: "kylin-aiassistant_Chat_chatLabelCommand"
                                        width:  1
                                        height: 24 + 16
                                        visible: sentByUser && msgHead.length > 0 && (imageSrc !== "" || documentName !== "") && model.message === ""
                                        color: "transparent"
                                    }

                                    Row{
                                        id: thinkRow
                                        Accessible.name: "kylin-aiassistant_Chat_thinkRow"
                                        width: parent.width
                                        height: 26
                                        leftPadding: 16
                                        rightPadding: 16
                                        topPadding: 6
                                        visible: model.reasonMessage !== undefined && model.reasonMessage !== ""
                                        Row{
                                            width: parent.width
                                            height: 20
                                            Rectangle{
                                                id: thinkImageRet
                                                Accessible.name: "kylin-aiassistant_Chat_thinkImageRet"
                                                width: 20
                                                color: "transparent"
                                                height: 20
                                                Image {
                                                    id: thinkImage
                                                    Accessible.name: "kylin-aiassistant_Chat_thinkImage"
                                                    source: "qrc:/icon/icon/think.svg"
                                                    anchors.centerIn: parent
                                                    width: 12
                                                    height: 12
                                                }
                                                MouseArea{
                                                    anchors.fill: parent
                                                    hoverEnabled: true
                                                    onEntered: {
                                                        thinkImage.source = "qrc:/icon/icon/think_hover.svg"
                                                        thinkText.color = "#3489ED"
                                                        if(reasonMessageRow.visible){
                                                            arrowImage.source = "qrc:/icon/icon/arrow-up-hover.svg"
                                                        }else{
                                                            arrowImage.source = "qrc:/icon/icon/arrow-down-hover.svg"
                                                        }
                                                    }
                                                    onExited: {
                                                        thinkImage.source = "qrc:/icon/icon/think.svg"
                                                        thinkText.color = "#262626"
                                                        if(reasonMessageRow.visible){
                                                            arrowImage.source = "qrc:/icon/icon/arrow-up.svg"
                                                        }else{
                                                            arrowImage.source = "qrc:/icon/icon/arrow-down.svg"
                                                        }
                                                    }
                                                    onPressed: {
                                                        thinkImage.source = "qrc:/icon/icon/think_click.svg"
                                                        thinkText.color = "#2C73C8"
                                                        if(reasonMessageRow.visible){
                                                            arrowImage.source = "qrc:/icon/icon/arrow-up-click.svg"
                                                        }else{
                                                            arrowImage.source = "qrc:/icon/icon/arrow-down-click.svg"
                                                        }
                                                    }
                                                    onReleased: {
                                                        thinkImage.source = "qrc:/icon/icon/think.svg"
                                                        thinkText.color = "#262626"
                                                        if(reasonMessageRow.visible){
                                                            arrowImage.source = "qrc:/icon/icon/arrow-down.svg"
                                                        }else{
                                                            arrowImage.source = "qrc:/icon/icon/arrow-up.svg"
                                                        }
                                                    }
                                                    onClicked: {
    //                                                    if(listView.isChatEndFlag){
    //                                                        messageTextTimer.running = true
    //                                                    }
                                                        reasonMessageRow.visible = !reasonMessageRow.visible
                                                    }
                                                }
                                            }
                                            Text {
                                                id: thinkText
                                                Accessible.name: "kylin-aiassistant_Chat_thinkText"
                                                color: "#262626"
                                                text: model.isEnd ? qsTr("Thought deeply"): qsTr("Deep thinking...")
                                                anchors.verticalCenter: parent.verticalCenter
                                                MouseArea{
                                                    anchors.fill: parent
                                                    hoverEnabled: true
                                                    onEntered: {
                                                        thinkImage.source = "qrc:/icon/icon/think_hover.svg"
                                                        thinkText.color = "#3489ED"
                                                        if(reasonMessageRow.visible){
                                                            arrowImage.source = "qrc:/icon/icon/arrow-up-hover.svg"
                                                        }else{
                                                            arrowImage.source = "qrc:/icon/icon/arrow-down-hover.svg"
                                                        }
                                                    }
                                                    onExited: {
                                                        thinkImage.source = "qrc:/icon/icon/think.svg"
                                                        thinkText.color = "#262626"
                                                        if(reasonMessageRow.visible){
                                                            arrowImage.source = "qrc:/icon/icon/arrow-up.svg"
                                                        }else{
                                                            arrowImage.source = "qrc:/icon/icon/arrow-down.svg"
                                                        }
                                                    }
                                                    onPressed: {
                                                        thinkImage.source = "qrc:/icon/icon/think_click.svg"
                                                        thinkText.color = "#2C73C8"
                                                        if(reasonMessageRow.visible){
                                                            arrowImage.source = "qrc:/icon/icon/arrow-up-click.svg"
                                                        }else{
                                                            arrowImage.source = "qrc:/icon/icon/arrow-down-click.svg"
                                                        }
                                                    }
                                                    onReleased: {
                                                        thinkImage.source = "qrc:/icon/icon/think.svg"
                                                        thinkText.color = "#262626"
                                                        if(reasonMessageRow.visible){
                                                            arrowImage.source = "qrc:/icon/icon/arrow-down.svg"
                                                        }else{
                                                            arrowImage.source = "qrc:/icon/icon/arrow-up.svg"
                                                        }
                                                    }
                                                    onClicked: {
    //                                                    if(listView.isChatEndFlag){
    //                                                        messageTextTimer.running = true
    //                                                    }
                                                        reasonMessageRow.visible = !reasonMessageRow.visible
                                                    }
                                                }
                                            }
                                            Rectangle{
                                                id: arrowImageRet
                                                Accessible.name: "kylin-aiassistant_Chat_arrowImageRet"
                                                width: 20
                                                color: "transparent"
                                                height: 20
                                                Image {
                                                    id: arrowImage
                                                    Accessible.name: "kylin-aiassistant_Chat_arrowImage"
                                                    source: "qrc:/icon/icon/arrow-up.svg"
                                                    anchors.centerIn: parent
                                                    width: 12
                                                    height: 12
                                                }
                                                MouseArea{
                                                    anchors.fill: parent
                                                    hoverEnabled: true
                                                    onEntered: {
                                                        thinkImage.source = "qrc:/icon/icon/think_hover.svg"
                                                        thinkText.color = "#3489ED"
                                                        if(reasonMessageRow.visible){
                                                            arrowImage.source = "qrc:/icon/icon/arrow-up-hover.svg"
                                                        }else{
                                                            arrowImage.source = "qrc:/icon/icon/arrow-down-hover.svg"
                                                        }
                                                    }
                                                    onExited: {
                                                        thinkImage.source = "qrc:/icon/icon/think.svg"
                                                        thinkText.color = "#262626"
                                                        if(reasonMessageRow.visible){
                                                            arrowImage.source = "qrc:/icon/icon/arrow-up.svg"
                                                        }else{
                                                            arrowImage.source = "qrc:/icon/icon/arrow-down.svg"
                                                        }
                                                    }
                                                    onPressed: {
                                                        thinkImage.source = "qrc:/icon/icon/think_click.svg"
                                                        thinkText.color = "#2C73C8"
                                                        if(reasonMessageRow.visible){
                                                            arrowImage.source = "qrc:/icon/icon/arrow-up-click.svg"
                                                        }else{
                                                            arrowImage.source = "qrc:/icon/icon/arrow-down-click.svg"
                                                        }
                                                    }
                                                    onReleased: {
                                                        thinkImage.source = "qrc:/icon/icon/think.svg"
                                                        thinkText.color = "#262626"
                                                        if(reasonMessageRow.visible){
                                                            arrowImage.source = "qrc:/icon/icon/arrow-down.svg"
                                                        }else{
                                                            arrowImage.source = "qrc:/icon/icon/arrow-up.svg"
                                                        }
                                                    }
                                                    onClicked: {
    //                                                    if(listView.isChatEndFlag){
    //                                                        messageTextTimer.running = true
    //                                                    }
                                                        reasonMessageRow.visible = !reasonMessageRow.visible
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    // 思考过程展示文字区域
                                    Row{
                                        id: reasonMessageRow
                                        Accessible.name: "kylin-aiassistant_Chat_reasonMessageRow"
                                        width: parent.width
                                        height: reasonMessageText.height
                                        leftPadding: 16
                                        rightPadding: 16
                                        visible: model.reasonMessage !== undefined && model.reasonMessage !== ""
                                        Rectangle{
                                            id: reasonMessageRet
                                            Accessible.name: "kylin-aiassistant_Chat_reasonMessageRet"
                                            width: reasonMessageRow.width - reasonMessageRow.leftPadding - reasonMessageRow.rightPadding
                                            height: reasonMessageRow.height
                                            color: "transparent"
                                            // 模拟左边框的竖线
                                            Rectangle {
                                                id: leftBorder
                                                Accessible.name: "kylin-aiassistant_Chat_leftBorder"
                                                width: 2  // 竖线的宽度
                                                height: parent.height
                                                color: "#0d262626"  // 竖线的颜色
                                                anchors.left: parent.left
                                            }
                                            TextArea {
                                                id: reasonMessageText
                                                Accessible.name: "kylin-aiassistant_Chat_reasonMessageText"
                                                width: (reasonMessageMetricsText.implicitWidth <= (chat.width - 40 - 16 - 16) ? (reasonMessageMetricsText.implicitWidth + 40) : (chat.width - 40 - 16 - 16))
                                                //topPadding: 6
                                                //leftPadding: 16
                                                bottomPadding: 6
                                                //visible: model.reasonMessage !== undefined && model.reasonMessage !== ""
                                                textFormat:  Text.RichText // 使用富文本格式，上面的方案会导致回答时弹出html代码，此方案会导致未配置模型时，提示信息格式错误
                                                //包含指令时，使用富文本实现
                                                property string reasonMessageTextRich: model.reasonMessage
                                                text: reasonMessageTextRich
                                                wrapMode: Text.WrapAnywhere
                                                color: Qt.rgba(0, 0, 0, 0.6)
                                                onTextChanged: {
                                                    if(listView.isChatEndFlag){
                                                        messageTextTimer.running = true
                                                    }
                                                }
                                                cursorVisible: false   // 隐藏光标
                                                readOnly: true
                                                selectByMouse: true
                                                selectionColor: "#3790FA"  // 自定义选中文本的背景颜色
                                                MouseArea {
                                                    id: reasonMessageTextMouseArea
                                                    Accessible.name: "kylin-aiassistant_Chat_reasonMessageTextMouseArea"
                                                    anchors.fill: parent
                                                    acceptedButtons: Qt.RightButton
                                                    hoverEnabled: true
                                                    onClicked: {
                                                        var popX = 0 // 弹窗x坐标
                                                        popX = mouse.x + 24 + reasonMessageText.x// 设置菜单的显示位置
                                                        if(chat.width - popX <= 200){
                                                            popX = chat.width - 202
                                                        }
                                                        messageReasonTextMenuPopup.x = popX
                                                        messageReasonTextMenuPopup.y = mouse.y + 64
                                                        messageReasonTextMenuPopup.open()
                                                    }
                                                }
                                            }
                                            // 思考过程文字计算宽度区域，不展示
                                            TextArea {
                                                id: reasonMessageMetricsText
                                                Accessible.name: "kylin-aiassistant_Chat_reasonMessageMetricsText"
                                                visible: false
                                                textFormat:  Text.RichText
                                                text: model.reasonMessage
                                            }
                                        }
                                    }

                                    // 正常回答展示文字区域
                                    TextArea {
                                        id: messageText
                                        Accessible.name: "kylin-aiassistant_Chat_messageText"
                                        //width: sentByUser ? Math.min((messageTextMetrics.implicitWidth + 24 + 20 + (chatLabel.visible ? chatLabel.width : 0)), (chat.width - 40 - 16)) : chat.width - 40 - 10
                                        width: sentByUser ? Math.min((messageTextMetrics.implicitWidth + 24 + 20 + (chatLabel.visible ? chatLabel.width : 0)), (chat.width - 40 - 16)) : (messageTextMetrics.implicitWidth <= (chat.width - 40 -16) ? (messageTextMetrics.implicitWidth + 40) : (chat.width - 40 - 10))
                                        topPadding: sentByUser ? 0 : 6
                                        leftPadding: 16
                                        bottomPadding: sentByUser ? 10 : 6
                                        visible: messageText.text !== "" && !model.isAddSchedule && model.message !== ""
                                        background:Item {
                                        }
                                        textFormat:  Text.RichText // 使用富文本格式，上面的方案会导致回答时弹出html代码，此方案会导致未配置模型时，提示信息格式错误

                                        //包含指令时，使用富文本实现
                                        property string messageTextCommand: model.message !== "" ? String("<p style='text-indent: "+ (chatLabel.visible ? chatLabel.width + 10 : 0) + "px;'>" + convertString(model.message) + "</p>") : ""
                                        property string messageTextRich: !sentByUser ? model.message !== "" ? model.message : "" : convertString(model.message)//String("<p>" + model.message + "</p>")
                                        text: sentByUser && msgHead !== undefined && msgHead.length > 0
                                                    ? messageTextCommand
                                                    : messageTextRich
                                        wrapMode: Text.WrapAnywhere
                                        color: sentByUser ? "#FFFFFF" : ( colorMsg === "red" ? "red" : "#262626")
                                        onTextChanged: {
                                            if(listView.isChatEndFlag){
                                                messageTextTimer.running = true
                                            }
                                        }
                                        cursorVisible: false   // 隐藏光标
                                        readOnly: true
                                        selectByMouse: true
                                        selectionColor: sentByUser ? Qt.rgba(00/255, 00/255, 00/255, 0.2) : "#3790FA"  // 自定义选中文本的背景颜色
                                        MouseArea {
                                            id: messageTextMouseArea
                                            Accessible.name: "kylin-aiassistant_Chat_messageTextMouseArea"
                                            anchors.fill: parent
                                            hoverEnabled: true
                                            acceptedButtons: Qt.RightButton
                                            onClicked: {
                                                var popX = 0 // 弹窗x坐标
                                                if(sentByUser){
                                                    var offsetX = 0 // 偏移后x坐标
                                                    offsetX = mouse.x + 16 + (chat.width - 40 - cavasRectnagle.width)
                                                    popX = mouse.x + 16 + messageText.x// 设置菜单的显示位置
                                                    if(chat.width - offsetX <= 200){
                                                        popX = chat.width - 202 - (chat.width - 40 - cavasRectnagle.width)
                                                    }
                                                }else{
                                                    popX = mouse.x + 16 + messageText.x// 设置菜单的显示位置
                                                    if(chat.width - popX <= 200){
                                                        popX = chat.width - 202
                                                    }
                                                }

                                                messageTextMenuPopup.x = popX
                                                messageTextMenuPopup.y = mouse.y + 24 + messageText.y
                                                messageTextMenuPopup.open()
                                            }
                                        }
                                    }

                                    // 动态加载消息回答GIF图loader
                                    Loader {
                                        id: messageLoader
                                        Accessible.name: "kylin-aiassistant_Chat_animatedImageLoader"
                                        anchors.horizontalCenter: parent.horizontalCenter
                                        sourceComponent: messageImageComponent  // 引用要加载的组件
                                        active: !drawMsg && !model.isEnd && !sentByUser
                                        // 当 loader.active 为 false 时,设置loader.visible=false，确保彻底隐藏
                                        onActiveChanged: {
                                            if (!active) {
                                                messageLoader.visible = false
                                            }else{
                                                messageLoader.visible = true
                                            }
                                            if(listView.isChatEndFlag){
                                                moveGIFTimer.running = true
                                            }
                                        }
                                    }

                                    // 定义一个 messageImageComponent 组件作为源组件(GIF图)
                                    Component {
                                        id: messageImageComponent
                                        Row{
                                            rightPadding: cavasRectnagle.width - messageImageLoading.width - 16 - messageText.leftPadding
                                            bottomPadding: 10
                                            AnimatedImage {
                                                id: messageImageLoading
                                                height: 16
                                                width: 16
                                                source: "qrc:/icon/icon/text_loading.gif"
                                            }
                                        }
                                    }

                                    Text{
                                        id: closePopupText
                                        text: model.closePopup
                                        visible: false
                                        onTextChanged: {
                                            messageTextMenuPopup.close()
                                            messageReasonTextMenuPopup.close()
                                            imageGeneratedByAIChatPopup.close()
                                        }
                                    }

                                    Popup{
                                        id: messageTextMenuPopup
                                        Accessible.name: "kylin-aiassistant_Chat_messageTextMenuPopup"
                                        width: messageTextMenuColumn.width
                                        height: messageTextMenuColumn.height
                                        property bool moveFlag: true
                                        modal: true
                                        closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
                                        MouseArea{
                                            anchors.fill: parent
                                            hoverEnabled: true
//                                            onEntered: {
//                                                messageTextMenuPopupTimer.running = false
//                                                messageTextMenuPopup.moveFlag = true
//                                            }
//                                            onExited: {
//                                                if(messageTextMenuPopup.moveFlag){
//                                                    messageTextMenuPopupTimer.running = true
//                                                    messageTextMenuPopup.moveFlag = false
//                                                }
//                                            }

                                            Column {
                                                id: messageTextMenuColumn
                                                Accessible.name: "kylin-aiassistant_Chat_messageTextMenuColumn"
                                                anchors.centerIn: parent
                                                width: 180
                                                height: 52
                                                padding: 0

                                                // 复制按钮
                                                Rectangle {
                                                    id: messageTextCopy
                                                    Accessible.name: "kylin-aiassistant_Chat_messageTextCopy"
                                                    width: messageTextMenuColumn.width
                                                    height: 52
                                                    radius: 8
                                                    color: "transparent"

                                                    Row {
                                                        id: messageTextCopyRow
                                                        Accessible.name: "kylin-aiassistant_Chat_messageTextCopyRow"
                                                        anchors.fill: parent
                                                        leftPadding: 8
                                                        rightPadding: 8
                                                        topPadding: 8
                                                        bottomPadding: 8

                                                        Rectangle {
                                                            id: messageTextCtrlCRet
                                                            Accessible.name: "kylin-aiassistant_Chat_messageTextCtrlCRet"
                                                            width: messageTextMenuColumn.width - messageTextCopyRow.leftPadding - messageTextCopyRow.rightPadding
                                                            height: messageTextMenuColumn.height - messageTextCopyRow.topPadding - messageTextCopyRow.bottomPadding
                                                            radius: 6
                                                            Row {
                                                                id:messageTextCtrlCRow
                                                                Accessible.name: "kylin-aiassistant_Chat_messageTextCtrlCRow"
                                                                anchors.fill: parent
                                                                leftPadding: 8
                                                                rightPadding: 8

                                                                Text {
                                                                    id: messageTextCtrlCText
                                                                    Accessible.name: "kylin-aiassistant_Chat_messageTextCtrlCText"
                                                                    text: qsTr("Copy")
                                                                    color: "black"
                                                                    font.pixelSize: 14
                                                                    anchors.verticalCenter: parent.verticalCenter
                                                                }
                                                            }

                                                            MouseArea {
                                                                id: messageTexCtrlCRetMouseArea
                                                                Accessible.name: "kylin-aiassistant_Chat_messageTexCtrlCRetMouseArea"
                                                                anchors.fill: parent
                                                                propagateComposedEvents: true
                                                                hoverEnabled: true  // 允许悬浮事件
        //                                                        enabled: messageText.selectedText.length > 0
                                                                onEntered: {
                                                                    messageTextCtrlCText.color = "#FFFFFF"
                                                                    messageTextCtrlCRet.color = "#3489ED";
                                                                }
                                                                onExited: {
                                                                    messageTextCtrlCText.color = "#000000"
                                                                    messageTextCtrlCRet.color = "#FFFFFF"
                                                                }
                                                                onPressed: {
                                                                    messageTextCtrlCText.color = "#FFFFFF"
                                                                    messageTextCtrlCRet.color = "#2C73C8"
                                                                }
                                                                onReleased: {
                                                                    messageTextCtrlCText.color = "#000000"
                                                                    messageTextCtrlCRet.color = "#FFFFFF"
                                                                }
                                                                onClicked: {
                                                                    if (messageText.selectedText.length > 0) {
                                                                        messageText.copy();
                                                                        msgPane.onCopySuccess();

                                                                    } else {
                                                                        console.log("没有选中的文本，复制整条文本消息");
                                                                        var str = model.message.replace(/<\/?.+?\/?>/g,'');
                                                                        str = str.replace(/&quot;/g,"\"") // 替换文本中的&quot;为"
                                                                        msgPane.onCopyText(str);
                                                                    }
                                                                    // 取消选中的文本
                                                                    messageText.cursorPosition = messageText.selectionEnd
                                                                    messageTextMenuPopup.close()
                                                                }
                                                            }
                                                        }

                                                    }

                                                }

                                            }
                                        }
                                        background: Rectangle {
                                            color: "#FFFFFF"  // 背景颜色
                                            radius: 8  // 圆角
                                            border.color: Qt.rgba(0/255, 0/255, 0/255, 0.1)  // 边框颜色
                                            border.width: 1  // 边框宽度
                                        }
                                    }
                                    Popup{
                                        id: messageReasonTextMenuPopup
                                        Accessible.name: "kylin-aiassistant_Chat_messageReasonTextMenuPopup"
                                        width: messageReasonTextMenuColumn.width
                                        height: messageReasonTextMenuColumn.height
                                        property bool moveFlag: true
                                        modal: true
                                        closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
                                        MouseArea{
                                            anchors.fill: parent
                                            hoverEnabled: true
//                                            onEntered: {
//                                                messageReasonTextMenuPopupTimer.running = false
//                                                messageReasonTextMenuPopup.moveFlag = true
//                                            }
//                                            onExited: {
//                                                if(messageReasonTextMenuPopup.moveFlag){
//                                                    messageReasonTextMenuPopupTimer.running = true
//                                                    messageReasonTextMenuPopup.moveFlag = false
//                                                }
//                                            }

                                            Column {
                                                id: messageReasonTextMenuColumn
                                                Accessible.name: "kylin-aiassistant_Chat_messageReasonTextMenuColumn"
                                                anchors.centerIn: parent
                                                width: 180
                                                height: 52
                                                padding: 0

                                                // 复制按钮
                                                Rectangle {
                                                    id: messageReasonTextCopy
                                                    Accessible.name: "kylin-aiassistant_Chat_messageReasonTextCopy"
                                                    width: messageReasonTextMenuColumn.width
                                                    height: 52
                                                    radius: 8
                                                    color: "transparent"

                                                    Row {
                                                        id: messageReasonTextCopyRow
                                                        Accessible.name: "kylin-aiassistant_Chat_messageReasonTextCopyRow"
                                                        anchors.fill: parent
                                                        leftPadding: 8
                                                        rightPadding: 8
                                                        topPadding: 8
                                                        bottomPadding: 8

                                                        Rectangle {
                                                            id: messageReasonTextCtrlCRet
                                                            Accessible.name: "kylin-aiassistant_Chat_messageReasonTextCtrlCRet"
                                                            width: messageReasonTextMenuColumn.width - messageReasonTextCopyRow.leftPadding - messageReasonTextCopyRow.rightPadding
                                                            height: messageReasonTextMenuColumn.height - messageReasonTextCopyRow.topPadding - messageReasonTextCopyRow.bottomPadding
                                                            radius: 6
                                                            Row {
                                                                id:messageReasonTextCtrlCRow
                                                                Accessible.name: "kylin-aiassistant_Chat_messageReasonTextCtrlCRow"
                                                                anchors.fill: parent
                                                                leftPadding: 8
                                                                rightPadding: 8

                                                                Text {
                                                                    id: messageReasonTextCtrlCText
                                                                    Accessible.name: "kylin-aiassistant_Chat_messageReasonTextCtrlCText"
                                                                    text: qsTr("Copy")
                                                                    color: "black"
                                                                    font.pixelSize: 14
                                                                    anchors.verticalCenter: parent.verticalCenter
                                                                }
                                                            }

                                                            MouseArea {
                                                                id: messageReasonTexCtrlCRetMouseArea
                                                                Accessible.name: "kylin-aiassistant_Chat_messageReasonTexCtrlCRetMouseArea"
                                                                anchors.fill: parent
                                                                propagateComposedEvents: true
                                                                hoverEnabled: true  // 允许悬浮事件
        //                                                        enabled: messageText.selectedText.length > 0
                                                                onEntered: {
                                                                    messageReasonTextCtrlCText.color = "#FFFFFF"
                                                                    messageReasonTextCtrlCRet.color = "#3489ED";
                                                                }
                                                                onExited: {
                                                                    messageReasonTextCtrlCText.color = "#000000"
                                                                    messageReasonTextCtrlCRet.color = "#FFFFFF"
                                                                }
                                                                onPressed: {
                                                                    messageReasonTextCtrlCText.color = "#FFFFFF"
                                                                    messageReasonTextCtrlCRet.color = "#2C73C8"
                                                                }
                                                                onReleased: {
                                                                    messageReasonTextCtrlCText.color = "#000000"
                                                                    messageReasonTextCtrlCRet.color = "#FFFFFF"
                                                                }
                                                                onClicked: {
                                                                    if (reasonMessageText.selectedText.length > 0) {
                                                                        reasonMessageText.copy();
                                                                        msgPane.onCopySuccess();

                                                                    } else {
                                                                        console.log("没有选中的文本，复制整条文本消息");
                                                                        var str = model.reasonMessage.replace(/<\/?.+?\/?>/g,'');
                                                                        str = str.replace(/&quot;/g,"\"") // 替换文本中的&quot;为"
                                                                        msgPane.onCopyText(str);
                                                                    }
                                                                    // 取消选中的文本
                                                                    reasonMessageText.cursorPosition = reasonMessageText.selectionEnd
                                                                    messageReasonTextMenuPopup.close()
                                                                }
                                                            }
                                                        }

                                                    }

                                                }

                                            }
                                        }
                                        background: Rectangle {
                                            color: "#FFFFFF"  // 背景颜色
                                            radius: 8  // 圆角
                                            border.color: Qt.rgba(0/255, 0/255, 0/255, 0.1)  // 边框颜色
                                            border.width: 1  // 边框宽度
                                        }
                                    }

//                                    Timer {
//                                        id: messageTextMenuPopupTimer
//                                        Accessible.name: "kylin-aiassistant_Chat_messageTextMenuPopupTimer"
//                                        interval: 1000
//                                        repeat: false   // 设置定时器只执行一次
//                                        running: false   // 设置定时器启动
//                                        onTriggered: {
//                                            // 定时器触发后执行的代码
//                                            messageTextMenuPopup.close()
//                                            messageTextMenuPopup.moveFlag = true
//                                        }
//                                    }
//                                    Timer {
//                                        id: messageReasonTextMenuPopupTimer
//                                        Accessible.name: "kylin-aiassistant_Chat_messageTextMenuPopupTimer"
//                                        interval: 1000
//                                        repeat: false   // 设置定时器只执行一次
//                                        running: false   // 设置定时器启动
//                                        onTriggered: {
//                                            // 定时器触发后执行的代码
//                                            messageReasonTextMenuPopup.close()
//                                            messageReasonTextMenuPopup.moveFlag = true
//                                        }
//                                    }

                                    //新建日程/生成代办-打开日历超链接
                                    Rectangle{
                                        id: scheduleCalendarRet
                                        Accessible.name: "kylin-aiassistant_Chat_scheduleCalendarRet"
                                        visible: !sentByUser && (model.isAddSchedule || model.isGenerateToDo) && model.isEnd
                                        width: scheduleCalendarText.width
                                        height: scheduleCalendarText.height
                                        TextEdit {
                                            id: scheduleCalendarText
                                            Accessible.name: "kylin-aiassistant_Chat_scheduleCalendarText"
                                            width: 344
                                            topPadding: 6
                                            leftPadding: 16
                                            bottomPadding: 6
                                            property string date: model.isAddSchedule ? String("<span>您的日程已新建成功！您可以在</span><a href='https://www.kylinos.cn' style='text-decoration:none; color:#3790FA;'>" + "日历" + "</a>" + "<span>插件中查看、修改或删除此日程。</span>")
                                                                                      : model.isGenerateToDo ? String("<span>已为您将待办添加到日程中，您可以在</span><a href='https://www.kylinos.cn' style='text-decoration:none; color:#3790FA;'>" + "日历" + "</a>" + "<span>插件中查看、修改或删除此日程。</span>") : ""
                                            text: date
                                            textFormat:Text.RichText
                                            font.pixelSize: 14
                                            wrapMode: Text.WrapAnywhere
                                            cursorVisible: false   // 隐藏光标
                                            readOnly: true
                                            selectByMouse: true
                                            selectionColor: sentByUser ? Qt.rgba(00/255, 00/255, 00/255, 0.2) : "#3790FA"  // 自定义选中文本的背景颜色
                                            onLinkHovered: {
                                                if(scheduleCalendarText.selectedText.length > 0){
                                                    return;
                                                }
                                                //focus = false;  // 防止焦点被意外获取
                                                if(link === ""){
                                                    if(model.isAddSchedule){
                                                        scheduleCalendarText.text = String("<span>您的日程已新建成功！您可以在</span><a href='https://www.kylinos.cn' style='text-decoration:none; color:#3790FA;'>" + "日历" + "</a>" + "<span>插件中查看、修改或删除此日程。</span>")
                                                    }else if(model.isGenerateToDo){
                                                        scheduleCalendarText.text = String("<span>已为您将待办添加到日程中，您可以在</span><a href='https://www.kylinos.cn' style='text-decoration:none; color:#3790FA;'>" + "日历" + "</a>" + "<span>插件中查看、修改或删除此日程。</span>")
                                                    }else{

                                                    }

                                                }else{
                                                    if(model.isAddSchedule){
                                                        scheduleCalendarText.text = String("<span>您的日程已新建成功！您可以在</span><a href='https://www.kylinos.cn' style='text-decoration:none; color:#3489ED;'>" + "日历" + "</a>" + "<span>插件中查看、修改或删除此日程。</span>")
                                                    }else if(model.isGenerateToDo){
                                                        scheduleCalendarText.text = String("<span>已为您将待办添加到日程中，您可以在</span><a href='https://www.kylinos.cn' style='text-decoration:none; color:#3489ED;'>" + "日历" + "</a>" + "<span>插件中查看、修改或删除此日程。</span>")
                                                    }else{

                                                    }
                                                }
                                            }
                                            onLinkActivated: {
                                                scheduleCalendarRetLinkHoverTimer.running = true
                                                msgPane.openSchedule(model.scheduleDate);
                                            }
                                            onTextChanged: {
                                                if(chat.winMode !== "2"){
                                                    if((scheduleCalendarTextMetricsText.width + 16) < chat.width - 40){
                                                        scheduleCalendarText.width = Math.min(chat.width -40 - 16, (scheduleCalendarTextMetricsText.width + 16 + 40 + 16))
                                                    }else{
                                                        scheduleCalendarText.width = chat.width - 40 - 16
                                                    }
                                                }
                                            }
                                        }
                                        TextEdit {
                                            id: scheduleCalendarTextMetricsText
                                            Accessible.name: "kylin-aiassistant_Chat_scheduleCalendarTextMetricsText"
                                            property string date: model.isAddSchedule ? String("<span>您的日程已新建成功！您可以在</span><a href='https://www.kylinos.cn' style='text-decoration:none; color:#3790FA;'>" + "日历" + "</a>" + "<span>插件中查看、修改或删除此日程。</span>")
                                                                                      : model.isGenerateToDo ? String("<span>已为您将待办添加到日程中，您可以在</span><a href='https://www.kylinos.cn' style='text-decoration:none; color:#3790FA;'>" + "日历" + "</a>" + "<span>插件中查看、修改或删除此日程。</span>") : 0
                                            text: date
                                            textFormat:Text.RichText
                                            visible: false
                                        }
                                        Timer {
                                            // 用于解决onLinkActivated再页面失去焦点时替换文字实现三态不生效问题
                                            id: scheduleCalendarRetLinkHoverTimer
                                            interval: 10
                                            repeat: false   // 设置定时器只执行一次
                                            running: false   // 设置定时器启动
                                            onTriggered: {
                                                // 定时器触发后执行的代码
                                                if(model.isAddSchedule){
                                                    scheduleCalendarText.text = String("<span>您的日程已新建成功！您可以在</span><a href='https://www.kylinos.cn' style='text-decoration:none; color:#2C73C8;'>" + "日历" + "</a>" + "<span>插件中查看、修改或删除此日程。</span>")
                                                }else if(model.isGenerateToDo){
                                                    scheduleCalendarText.text = String("<span>已为您将待办添加到日程中，您可以在</span><a href='https://www.kylinos.cn' style='text-decoration:none; color:#2C73C8;'>" + "日历" + "</a>" + "<span>插件中查看、修改或删除此日程。</span>")
                                                }else{

                                                }
                                            }
                                        }
                                    }

                                    //生成周报-打开Pdf
                                    Rectangle{
                                        id: generatePdfRet
                                        Accessible.name: "kylin-aiassistant_Chat_generatePdfRet"
                                        visible: !sentByUser && model.pdfPath !== ""
                                        width: generatePdfLastText.width
                                        height: generatePdfLastText.height
                                        TextEdit {
                                            id: generatePdfLastText
                                            Accessible.name: "kylin-aiassistant_Chat_generatePdfLastText"
                                            width: 344
                                            topPadding: 6
                                            leftPadding: 16
                                            bottomPadding: 6
                                            property string date: String("<span>周报已整理完成！位置为</span><a href='https://www.kylinos.cn' style='text-decoration:none; color:#3790FA;'>" + model.pdfPath + "</a>")
                                            text: date
                                            textFormat:Text.RichText
                                            font.pixelSize: 14
                                            wrapMode: Text.WrapAnywhere
                                            cursorVisible: false   // 隐藏光标
                                            readOnly: true
                                            selectByMouse: true
                                            selectionColor: sentByUser ? Qt.rgba(00/255, 00/255, 00/255, 0.2) : "#3790FA"  // 自定义选中文本的背景颜色
                                            onLinkHovered: {
                                                if(generatePdfLastText.selectedText.length > 0){
                                                    return;
                                                }
                                                //focus = false;  // 防止焦点被意外获取
                                                if(link === ""){
                                                    //console.log("Link onLinkHovered1: " + link);
                                                    generatePdfLastText.text = String("<span>周报已整理完成！位置为</span><a href='https://www.kylinos.cn' style='text-decoration:none; color:#3790FA;'>" + model.pdfPath + "</a>")

                                                }else{
                                                    //console.log("Link onLinkHovered2: " + link);
                                                    generatePdfLastText.text = String("<span>周报已整理完成！位置为</span><a href='https://www.kylinos.cn' style='text-decoration:none; color:#3489ED;'>" + model.pdfPath + "</a>")
                                                }
                                            }
                                            onLinkActivated: {
                                                //console.log("Link clicked: " + link);
                                                //generatePdfLastText.text = String("<span>周报已整理完成！位置为</span><a href='https://www.kylinos.cn' style='text-decoration:none; color:#2C73C8;'>" + model.pdfPath + "</a>")
                                                linkHoverTimer.running = true
                                                msgPane.openDocument(model.pdfPath)
                                            }
                                            onTextChanged: {
                                                if(model.pdfPath !== "" && chat.winMode !== "2"){
                                                    if((generatePdfLastMetricsText.width + 16) < chat.width - 40){
                                                        generatePdfLastText.width = Math.min(chat.width -40 - 16, (generatePdfLastMetricsText.width + 16 + 40 + 16))
                                                    }else{
                                                        generatePdfLastText.width = chat.width - 40 - 16
                                                    }
                                                }
                                            }
                                        }
                                        TextEdit {
                                            id: generatePdfLastMetricsText
                                            Accessible.name: "kylin-aiassistant_Chat_generatePdfLastMetricsText"
                                            property string date: String("<span>周报已整理完成！位置为</span><a href='https://www.kylinos.cn' style='text-decoration:none; color:#3790FA;'>" + model.pdfPath + "</a>")
                                            text: date
                                            textFormat:Text.RichText
                                            visible: false
                                        }
                                        Timer {
                                            // 用于解决onLinkActivated再页面失去焦点时替换文字实现三态不生效问题
                                            id: linkHoverTimer
                                            interval: 10
                                            repeat: false   // 设置定时器只执行一次
                                            running: false   // 设置定时器启动
                                            onTriggered: {
                                                // 定时器触发后执行的代码
                                                generatePdfLastText.text = String("<span>周报已整理完成！位置为</span><a href='https://www.kylinos.cn' style='text-decoration:none; color:#2C73C8;'>" + model.pdfPath + "</a>")
                                            }
                                        }
                                    }

                                    // 用于计算文本实际宽度，不显示，仅做计算
                                    Text{
                                        id: messageTextMetrics
                                        Accessible.name: "kylin-aiassistant_Chat_messageTextMetrics"
                                        textFormat:  Text.RichText // 使用富文本格式
                                        visible: false
                                        text: sentByUser && msgHead.length > 0
                                              ? model.message
                                              : model.message
                                    }

                                    Timer {
                                        // 临时用于解决滚动条不自动刷新问题
                                        id: messageTextTimer
                                        interval: 10
                                        repeat: false   // 设置定时器只执行一次
                                        running: false   // 设置定时器启动
                                        onTriggered: {
                                            // 定时器触发后执行的代码
                                            listView.positionViewAtEnd()
                                        }
                                    }

                                    //信息来源
                                    Rectangle{
                                        id: infoSourcesRet
                                        Accessible.name: "kylin-aiassistant_Chat_infoSourcesRet"
                                        width: parent.width
                                        height: infoSourcesColumn.height
                                        visible: !sentByUser && model.isShowInfoSources !== undefined && model.isShowInfoSources && model.isEnd
                                        Column{
                                            id: infoSourcesColumn
                                            Accessible.name: "kylin-aiassistant_Chat_infoSourcesColumn"
                                            width: parent.width
                                            height: infoSourcesTitleText.height + infoSourcesListView.height
                                            spacing: 0
                                            leftPadding: 16
                                            rightPadding: 16
                                            TextEdit {
                                                id: infoSourcesTitleText
                                                Accessible.name: "kylin-aiassistant_Chat_infoSourcesTitleText"
                                                width: parent.width
                                                text: qsTr("Sources of information:")
                                                topPadding: 6
                                                wrapMode: Text.WrapAnywhere
                                                color: "#9d262626"
                                                cursorVisible: false   // 隐藏光标
                                                readOnly: true
                                                selectByMouse: true
                                                selectionColor: sentByUser ? Qt.rgba(00/255, 00/255, 00/255, 0.2) : "#3790FA"  // 自定义选中文本的背景颜色
                                            }

                                            ListView{
                                                id: infoSourcesListView
                                                Accessible.name: "kylin-aiassistant_Chat_infoSourcesListView"
                                                height: contentHeight
                                                width: infoSourcesRet.width
                                                clip: true
                                                interactive: false
                                                boundsMovement: Flickable.StopAtBounds // 防止过度滚动
                                                model: ListModel{
                                                    id: infoSourcesListModel
                                                    Accessible.name: "kylin-aiassistant_Chat_infoSourcesListModel"
                                                }
                                                Text{
                                                    visible: false
                                                    text:model.infoSources
                                                    onTextChanged: {
                                                        if(model.infoSources === "" || model.infoSources === undefined){
                                                            return
                                                        }
                                                        var infoSources = JSON.parse(model.infoSources)
                                                        for (var i = 0; i < infoSources.infoSources.length; i++) {
                                                            infoSourcesListModel.insert(i, infoSources.infoSources[i])
                                                        }
                                                    }
                                                }

                                                delegate: Column {
                                                    TextEdit {
                                                        id: infoSourcesText
                                                        Accessible.name: "kylin-aiassistant_Chat_infoSourcesText"
                                                        width: Math.min(infoSourcesText.implicitWidth,infoSourcesRet.width)
                                                        text: (index + 1) + "." + infoSourcesListModel.get(index).text
                                                        //leftPadding: 16
                                                        rightPadding: 32
                                                        //bottomPadding: 6
                                                        wrapMode: Text.WrapAnywhere
                                                        color: "#3790FA"
                                                        cursorVisible: false   // 隐藏光标
                                                        readOnly: true
                                                        selectByMouse: true
                                                        selectionColor: sentByUser ? Qt.rgba(00/255, 00/255, 00/255, 0.2) : "#3790FA"  // 自定义选中文本的背景颜色
                                                        MouseArea{
                                                            id: infoSourcesTextMouseArea
                                                            Accessible.name: "kylin-aiassistant_Chat_infoSourcesTextMouseArea"
                                                            hoverEnabled: true
                                                            anchors.fill:parent
                                                            onEntered: {
                                                                infoSourcesText.color = "#3489ED"
                                                            }
                                                            onExited: {
                                                                infoSourcesText.color = "#3790FA"
                                                            }
                                                            onPressed: {
                                                                infoSourcesText.color = "#2C73C8"
                                                            }
                                                            onReleased: {
                                                                infoSourcesText.color = "#3790FA"
                                                            }
                                                            onClicked: {
                                                                msgPane.onSelectInfoSource(infoSourcesListModel.get(index).tool_id)
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    // 动态加载GIF图loader
                                    Loader {
                                        id: animatedImageLoader
                                        Accessible.name: "kylin-aiassistant_Chat_animatedImageLoader"
                                        anchors.horizontalCenter: parent.horizontalCenter
                                        sourceComponent: animatedImageComponent  // 引用要加载的组件
                                        active: drawMsg
                                        // 当 loader.active 为 false 时,设置loader.visible=false，确保彻底隐藏
                                        onActiveChanged: {
                                            if (!active) {
                                                animatedImageLoader.visible = false
                                            }else{
                                                animatedImageLoader.visible = true
                                            }
                                            if(listView.isChatEndFlag){
                                                moveGIFTimer.running = true
                                            }

                                        }
                                    }

                                    // 定义一个 AnimatedImage 组件作为源组件(GIF图)
                                    Component {
                                        id: animatedImageComponent
                                        Row{
                                            rightPadding: cavasRectnagle.width - 338 - messageText.leftPadding
                                            bottomPadding: 10
                                            AnimatedImage {
                                                id: imageLoading
                                                height: 338
                                                width: 338
                                                source: "qrc:/html/html/img/loading.gif"
                                            }
                                        }
                                    }

                                    // 文件展示区域
                                    Column{
                                        id: documentShowColumn
                                        Accessible.name: "kylin-aiassistant_Chat_documentShowColumn"
                                        //padding: 16
                                        visible: sentByUser && documentName !== ""
                                        // 文件展示窗口
                                        Row{
                                            id:documentShowRow
                                            Accessible.name: "kylin-aiassistant_Chat_documentShowRow"
                                            leftPadding: 16
                                            rightPadding: 16
                                            topPadding: 0 + (chatLabel.visible && messageText.text === "" ? 40 : 0)
                                            bottomPadding: 10
                                            visible: model.documentName !== ""
                                            Rectangle{
                                                id: documentRet
                                                Accessible.name: "kylin-aiassistant_Chat_documentRet"
                                                visible: model.documentName !== ""
                                                radius: 6
                                                color: "#FFFFFF"
                                                width: documentRow.width + documentRow.leftPadding +  documentRow.rightPadding
                                                height: documentRow.height + documentRow.topPadding + documentRow.bottomPadding
                                                MouseArea{
                                                    anchors.fill: parent
                                                    hoverEnabled: true
                                                    onClicked: {
                                                        msgPane.openDocument(model.documentPath)
                                                    }
                                                }
                                                Row{
                                                    id: documentRow
                                                    Accessible.name: "kylin-aiassistant_Chat_documentRow"
                                                    leftPadding: 6
                                                    rightPadding: 6
                                                    topPadding: 6
                                                    bottomPadding: 6
                                                    visible: model.documentName !== ""
                                                    width: documentIconRet.width + documentDetailsShowRow.width +
                                                           (documentNameShowText.implicitWidth < documentDetailsShowRow.documentNameRowMaxWidth ? 20 : 0)
                                                    height: documentDetailsShowRow.height > documentIconRet.height ? documentDetailsShowRow.height : documentIconRet.height
                                                    Rectangle{
                                                        id: documentIconRet
                                                        Accessible.name: "kylin-aiassistant_Chat_documentIconRet"
                                                        width: 50
                                                        color: "transparent"
                                                        height: documentDetailsShowRow.height
                                                        Image {
                                                            id: documentIconShowImage
                                                            Accessible.name: "kylin-aiassistant_Chat_documentIconShowImage"
                                                            source: model.documentIcon
                                                            visible: model.documentName !== ""
                                                            anchors.centerIn: parent
                                                            // 固定值
                                                            property int fixedSize: 32
                                                            // 计算宽高比
                                                            property real aspectRatio: implicitWidth / implicitHeight
                                                            // 根据图片宽高比调整大小，取宽度或高度中的较大者为fixedSize
                                                            width: aspectRatio >= 1 ? fixedSize : fixedSize * aspectRatio  // 如果宽比高大，则宽度取固定值
                                                            height: aspectRatio < 1 ? fixedSize : fixedSize / aspectRatio
                                                        }
                                                    }
                                                    Column{
                                                        id: documentDetailsShowRow
                                                        Accessible.name: "kylin-aiassistant_Chat_documentDetailsShowRow"
                                                        width: documentNameShowRow.width > documentSizeShowRow.width ? documentNameShowRow.width : documentSizeShowRow.width
                                                        // 文档名称可展示最大宽度
                                                        property int documentNameRowMaxWidth: messageRow.width - documentShowRow.leftPadding - documentShowRow.rightPadding
                                                                                              - documentRow.leftPadding - documentRow.rightPadding - documentIconRet.width
                                                        Row{
                                                            id:documentNameShowRow
                                                            Accessible.name: "kylin-aiassistant_Chat_documentNameShowRow"
                                                            width: Math.min(documentNameShowText.implicitWidth, documentDetailsShowRow.documentNameRowMaxWidth)
                                                            Text{
                                                                id: documentNameShowText
                                                                Accessible.name: "kylin-aiassistant_Chat_documentNameShowText"
                                                                width: parent.width
                                                                text: model.documentName
                                                                font.pixelSize: 14
                                                                wrapMode: Text.WordWrap
                                                            }
                                                        }
                                                        Row{
                                                            id:documentSizeShowRow
                                                            Accessible.name: "kylin-aiassistant_Chat_documentSizeShowRow"
                                                            width: documentSizeShowText.width
                                                            Text{
                                                                id:documentSizeShowText
                                                                Accessible.name: "kylin-aiassistant_Chat_documentSizeShowText"
                                                                text: "大小 " + model.documentSize
                                                                font.pixelSize: 12
                                                                color: Qt.rgba(38/255, 38/255, 38/255, 0.3)
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    Column{
                                        id: imageGeneratedByAIColumn
                                        Accessible.name: "kylin-aiassistant_Chat_imageGeneratedByAIColumn"
                                        topPadding: 6
                                        bottomPadding: 16
                                        leftPadding: (chat.winMode === 2 ? 12 : 16)
                                        rightPadding: 16
                                        visible: imageSrc !== ""
                                        Image {
                                            id: imageGeneratedByAI
                                            Accessible.name: "kylin-aiassistant_Chat_imageGeneratedByAI"
                                            // 固定值
                                            property int fixedSize: 56
                                            // 计算宽高比
                                            property real aspectRatio: imageGeneratedByAI.implicitWidth / imageGeneratedByAI.implicitHeight
                                            // 根据图片宽高比调整大小，取宽度或高度中的较大者为fixedSize
                                            width: aspectRatio >= 1 ? fixedSize : fixedSize * aspectRatio  // 如果宽比高大，则宽度取固定值
                                            height: aspectRatio < 1 ? fixedSize : fixedSize / aspectRatio

                                            visible: sentByUser && imageSrc !== ""
                                            source: imageSrc
                                            MouseArea {
                                                id: imageGeneratedByAIMouseArea
                                                Accessible.name: "kylin-aiassistant_Chat_imageGeneratedByAIMouseArea"
                                                anchors.fill: parent
                                                acceptedButtons: Qt.RightButton | Qt.LeftButton
                                                onClicked: {
                                                    if(mouse.button === Qt.LeftButton){
                                                        msgPane.xdgOpen(model.imagePath);
                                                    }
                                                }
                                            }
                                        }
                                        Image {
                                            id: imageGeneratedByAIChat
                                            Accessible.name: "kylin-aiassistant_Chat_imageGeneratedByAIChat"
                                            // 固定值
                                            property int fixedChatSize: 338
                                            // 计算宽高比
                                            property real aspectRatio: imageGeneratedByAIChat.implicitWidth / imageGeneratedByAIChat.implicitHeight
                                            // 根据图片宽高比调整大小，取宽度或高度中的较大者为fixedSize
                                            width: aspectRatio >= 1 ? fixedChatSize : fixedChatSize * aspectRatio  // 如果宽比高大，则宽度取固定值
                                            height: aspectRatio < 1 ? fixedChatSize : fixedChatSize / aspectRatio

                                            visible: !sentByUser && imageSrc !== ""
                                            source: imageSrc
                                            onSourceChanged: {
                                                if(listView.isChatEndFlag){
                                                    imageGeneratedByAIChatTimer.running = true
                                                }
                                            }
                                            MouseArea {
                                                id: imageGeneratedByAIChatMouseArea
                                                Accessible.name: "kylin-aiassistant_Chat_imageGeneratedByAIChatMouseArea"
                                                anchors.fill: parent
                                                acceptedButtons: Qt.RightButton | Qt.LeftButton
                                                onClicked: {
                                                    if(mouse.button === Qt.RightButton)
                                                    {
                                                        imageGeneratedByAIChatPopup.x = mouse.x -5 // 设置菜单的显示位置
                                                        imageGeneratedByAIChatPopup.y = mouse.y -5
                                                        imageGeneratedByAIChatPopup.open()
                                                    }
                                                    if(mouse.button === Qt.LeftButton)
                                                    {
//                                                        imageGeneratedByAIChatPopup.close()
//                                                        chat.aiImagePreviewSrc = imageSrc
//                                                        commandShowRet.visible = true
                                                        msgPane.xdgOpenForImageOperate(model.imageSrc, model.operatorId, model.imagePath)
                                                    }

                                                }
                                            }
                                        }

                                        Popup {
                                            id: imageGeneratedByAIChatPopup
                                            Accessible.name: "kylin-aiassistant_Chat_imageGeneratedByAIChatPopup"
                                            width: 180
                                            height: 128
                                            // 禁用默认的窗口裁剪，会截断圆角阴影效果
                                            clip: false

                                            property bool moveFlag: true
                                            //visible: true  // 确保 Popup 可见
                                            //focus: true
                                            modal: true
                                            closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
                                            background: Rectangle {
                                                color: "#FFFFFF"  // 背景颜色
                                                radius: 8  // 圆角
                                                border.color: Qt.rgba(0/255, 0/255, 0/255, 0.1);  // 边框颜色
                                                border.width: 1  // 边框宽度

                                                // 阴影效果 box-shadow: var(--kshadow-menu); /* 0px 4px 20px 0px rgba(0, 0, 0, 0.2) */
                                                layer.enabled: true
                                                layer.effect: DropShadow {
                                                    color: Qt.rgba(0/255, 0/255, 0/255, 0.2)
                                                    horizontalOffset: 0          // 水平偏移0
                                                    verticalOffset: 4            // 垂直偏移4px
                                                    radius: 10                   // 模糊半径（近似20px效果）
                                                    samples: 21                  // 采样数（radius*2+1）
                                                    spread: 0                    // 扩展量0
                                                }
                                            }

                                            MouseArea{
                                                anchors.fill: parent
                                                hoverEnabled: true
//                                                onEntered: {
//                                                    imageGeneratedByAIChatPopupTimer.running = false
//                                                    imageGeneratedByAIChatPopup.moveFlag = true
//                                                }
//                                                onExited: {
//                                                    if(imageGeneratedByAIChatPopup.moveFlag){
//                                                        imageGeneratedByAIChatPopupTimer.running = true
//                                                        imageGeneratedByAIChatPopup.moveFlag = false
//                                                    }
//                                                }
                                                Column {
                                                    id: picturePopupColumn
                                                    Accessible.name: "kylin-aiassistant_Chat_picturePopupColumn"
                                                    anchors.centerIn: parent
                                                    spacing: 2
                                                    leftPadding: 8
                                                    rightPadding: 8
                                                    topPadding: 8
                                                    bottomPadding: 8

                                                    Rectangle {
                                                        id: downloadPictureRet
                                                        Accessible.name: "kylin-aiassistant_Chat_downloadPictureRet"
                                                        width: 164
                                                        height: 36
                                                        radius: 6
                                                        Row {
                                                            anchors.fill: parent
                                                            leftPadding: 8
                                                            rightPadding: 8
                                                            Text {
                                                                id: downloadPictureText
                                                                Accessible.name: "kylin-aiassistant_Chat_downloadPictureText"
                                                                text: qsTr("Download")
                                                                 color: "black"
                                                                font.pixelSize: 14
                                                                anchors.verticalCenter: parent.verticalCenter
                                                                horizontalAlignment: Text.AlignLeft  // 左对齐
                                                            }
                                                        }
                                                        MouseArea {
                                                            id: downloadPictureMouseArea
                                                            Accessible.name: "kylin-aiassistant_Chat_downloadPictureMouseArea"
                                                            anchors.fill: parent
                                                            hoverEnabled: true  // 允许悬浮事件
                                                            onEntered: {
                                                                downloadPictureText.color = "#FFFFFF"
                                                                downloadPictureRet.color = "#3790FA"
                                                            }
                                                            onExited: {
                                                                downloadPictureText.color = "#000000"
                                                                downloadPictureRet.color = "#FFFFFF"
                                                            }
                                                            onPressed: {
                                                                downloadPictureText.color = "#FFFFFF"
                                                                downloadPictureRet.color = "#3790FA"
                                                            }
                                                            onReleased: {
                                                                downloadPictureText.color = "#000000"
                                                                downloadPictureRet.color = "#FFFFFF"
                                                            }
                                                            onClicked: {
                                                                imageGeneratedByAIChatPopup.close()
                                                                msgPane.onDownloadImage(imageSrc)
                                                            }
                                                        }
                                                    }
                                                    Rectangle {
                                                        id: copyPictureRet
                                                        Accessible.name: "kylin-aiassistant_Chat_copyPictureRet"
                                                        width: 164
                                                        height: 36
                                                        radius: 6
                                                        Row {
                                                            anchors.fill: parent
                                                            leftPadding: 8
                                                            rightPadding: 8
                                                            Text {
                                                                id: copyPictureText
                                                                Accessible.name: "kylin-aiassistant_Chat_copyPictureText"
                                                                text: qsTr("Copy")
                                                                color: "black"
                                                                font.pixelSize: 14
                                                                anchors.verticalCenter: parent.verticalCenter
                                                                horizontalAlignment: Text.AlignLeft  // 左对齐
                                                            }
                                                        }
                                                        MouseArea {
                                                            id: copyPictureMouseArea
                                                            Accessible.name: "kylin-aiassistant_Chat_copyPictureMouseArea"
                                                            anchors.fill: parent
                                                            hoverEnabled: true  // 允许悬浮事件
                                                            onEntered: {
                                                                copyPictureText.color = "#FFFFFF"
                                                                copyPictureRet.color = "#3790FA"
                                                            }
                                                            onExited: {
                                                                copyPictureText.color = "#000000"
                                                                copyPictureRet.color = "#FFFFFF"
                                                            }
                                                            onPressed: {
                                                                copyPictureText.color = "#FFFFFF"
                                                                copyPictureRet.color = "#3790FA"
                                                            }

                                                            onReleased: {
                                                                copyPictureText.color = "#000000"
                                                                copyPictureRet.color = "#FFFFFF"
                                                            }
                                                            onClicked: {
                                                                imageGeneratedByAIChatPopup.close()
                                                                msgPane.onCopyImage(imageSrc)
                                                            }
                                                        }
                                                    }
                                                    Rectangle {
                                                        id: previewPictureRet
                                                        Accessible.name: "kylin-aiassistant_Chat_previewPictureRet"
                                                        width: 164
                                                        height: 36
                                                        radius: 6
                                                        Row {
                                                            anchors.fill: parent
                                                            leftPadding: 8
                                                            rightPadding: 8
                                                            Text {
                                                                id: previewPictureText
                                                                Accessible.name: "kylin-aiassistant_Chat_previewPictureText"
                                                                text: qsTr("Preview")
                                                                color: "black"
                                                                font.pixelSize: 14
                                                                anchors.verticalCenter: parent.verticalCenter
                                                                horizontalAlignment: Text.AlignLeft  // 左对齐
                                                            }
                                                        }
                                                        MouseArea {
                                                            id: previewPictureMouseArea
                                                            Accessible.name: "kylin-aiassistant_Chat_previewPictureMouseArea"
                                                            anchors.fill: parent
                                                            hoverEnabled: true  // 允许悬浮事件
                                                            onEntered: {
                                                                previewPictureText.color = "#FFFFFF"
                                                                previewPictureRet.color = "#3790FA"
                                                            }
                                                            onExited: {
                                                                previewPictureText.color = "#000000"
                                                                previewPictureRet.color = "#FFFFFF"
                                                            }
                                                            onPressed: {
                                                                previewPictureText.color = "#FFFFFF"
                                                                previewPictureRet.color = "#3790FA"
                                                            }
                                                            onReleased: {
                                                                previewPictureText.color = "#000000"
                                                                previewPictureRet.color = "#FFFFFF"
                                                            }
                                                            onClicked: {
                                                                imageGeneratedByAIChatPopup.close()
                                                                msgPane.xdgOpenForImageOperate(model.imageSrc, model.operatorId, model.imagePath)                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        Timer {
                                            // 用于解决生成图片时内容不会自动向下滚动问题
                                            id: imageGeneratedByAIChatTimer
                                            Accessible.name: "kylin-aiassistant_Chat_imageGeneratedByAIChatTimer"
                                            interval: 10
                                            repeat: false   // 设置定时器只执行一次
                                            running: false   // 设置定时器启动
                                            onTriggered: {
                                                // 定时器触发后执行的代码
                                                listView.positionViewAtEnd()
                                            }
                                        }
//                                        Timer {
//                                            id: imageGeneratedByAIChatPopupTimer
//                                            Accessible.name: "kylin-aiassistant_Chat_imageGeneratedByAIChatPopupTimer"
//                                            interval: 1000
//                                            repeat: false   // 设置定时器只执行一次
//                                            running: false   // 设置定时器启动
//                                            onTriggered: {
//                                                // 定时器触发后执行的代码
//                                                imageGeneratedByAIChatPopup.close()
//                                                imageGeneratedByAIChatPopup.moveFlag = true
//                                            }
//                                        }
                                    }
                                    Column {
                                        id: pictureOperateRow
                                        Accessible.name: "kylin-aiassistant_Chat_pictureOperateRow"
                                        width: parent.width - pictureOperateRow.leftPadding
                                        height: pictureOperatesListView.height + pictureOperateRow.bottomPadding
                                        leftPadding: 20
                                        bottomPadding: 10
                                        visible: (!sentByUser && model.showImageOptions)
                                        ListView{
                                            id: pictureOperatesListView
                                            Accessible.name: "kylin-aiassistant_Chat_pictureOperatesListView"
                                            height: contentHeight
                                            width: pictureOperateRow.width
                                            clip: true
                                            interactive: false
                                            boundsMovement: Flickable.StopAtBounds // 防止过度滚动
                                            model: ListModel{
                                                id: pictureOperatesListModel
                                                Accessible.name: "kylin-aiassistant_Chat_pictureOperatesListModel"
                                            }
                                            Text{
                                                visible: false
                                                text:model.pictureOperates
                                                onTextChanged: {
                                                    if(model.pictureOperates === "" || model.pictureOperates === undefined){
                                                        return
                                                    }
                                                    var imagePath = model.imagePath
                                                    var pictureOperates = JSON.parse(model.pictureOperates)
                                                    for (var i = 0; i < pictureOperates.pictureOperates.length; i++) {
                                                        pictureOperates.pictureOperates[i].imagePath = imagePath
                                                        pictureOperatesListModel.insert(i, pictureOperates.pictureOperates[i])
                                                    }
                                                }
                                            }

                                            delegate: Column {
                                                TextEdit {
                                                    id: pictureOperateText
                                                    Accessible.name: "kylin-aiassistant_Chat_pictureOperateText"
                                                    width: Math.min(pictureOperateText.implicitWidth,pictureOperateRow.width)
                                                    text: "·" + pictureOperatesListModel.get(index).tool_name
                                                    //leftPadding: 16
                                                    rightPadding: 32
                                                    //bottomPadding: 6
                                                    wrapMode: Text.WrapAnywhere
                                                    color: "#3790FA"
                                                    cursorVisible: false   // 隐藏光标
                                                    readOnly: true
                                                    selectByMouse: true
                                                    selectionColor: sentByUser ? Qt.rgba(00/255, 00/255, 00/255, 0.2) : "#3790FA"  // 自定义选中文本的背景颜色
                                                    MouseArea{
                                                        id: pictureOperateTextMouseArea
                                                        Accessible.name: "kylin-aiassistant_Chat_pictureOperateTextMouseArea"
                                                        hoverEnabled: true
                                                        anchors.fill:parent
                                                        onEntered: {
                                                            pictureOperateText.color = "#3489ED"
                                                        }
                                                        onExited: {
                                                            pictureOperateText.color = "#3790FA"
                                                        }
                                                        onPressed: {
                                                            pictureOperateText.color = "#2C73C8"
                                                        }
                                                        onReleased: {
                                                            pictureOperateText.color = "#3790FA"
                                                        }
                                                        onClicked: {
                                                            if(isReplying){
                                                                msgPane.onContinueDialog();
                                                                return
                                                            }
                                                            var lastMsg
                                                            if (listModel.count > 0) {
                                                                lastMsg = listModel.get(listModel.count - 1)
                                                                lastMsg.isRefreshed = true
                                                            }
                                                            var retJsonString = msgPane.onPictureOperateClick(pictureOperatesListModel.get(index).tool_id , pictureOperatesListModel.get(index).imagePath)
                                                            var retJsonObject = JSON.parse(retJsonString);
                                                            isReplying = retJsonObject['isReplying'] !== undefined ? retJsonObject['isReplying'] : false
                                                            // 用于解决点击后不自动下滑功能
                                                            moveGIFTimer.running = true
                                                            listView.positionViewAtEnd()
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    Rectangle{
                                        id: thinkLineRet
                                        Accessible.name: "kylin-aiassistant_Chat_thinkLineRet"
                                        width: parent.width -32
                                        height: 8
                                        color: "transparent"
                                        visible: model.reasonMessage !== undefined && model.reasonMessage !== "" && !messageText.visible
                                        anchors.horizontalCenter: parent.horizontalCenter
                                    }

                                    //在此处插入一条横线
                                    Rectangle{
                                        width: parent.width -32
                                        height: 1
                                        color: '#0d262626'
                                        visible: !sentByUser && (toolButtonArea.visible || setModelRow.visible) && !isReplying
                                        anchors.horizontalCenter: parent.horizontalCenter
                                    }

                                    // reTry之后对话气泡没有toolButtonArea的高度，需要一个空矩形来撑开气泡高度
                                    Rectangle{
                                        id: reTryTmp
                                        Accessible.name: "kylin-aiassistant_Chat_reTryTmp"
                                        width: parent.width
                                        height: 16
                                        visible: !sentByUser && !(toolButtonArea.visible || setModelRow.visible)
                                        color: "transparent"
                                        radius: 4
                                    }

                                    // 立即配置按钮区域
                                    Row{
                                        id: setModelRow
                                        Accessible.name: "kylin-aiassistant_Chat_setModelRow"
                                        width: messageRectangle.width - 22
                                        layoutDirection: Qt.RightToLeft
                                        topPadding: 6
                                        bottomPadding: 16
                                        visible: model.noModelError !== ""
                                        Rectangle {
                                            id: setModelButton
                                            Accessible.name: "kylin-aiassistant_Chat_setModelButton"
                                            width: setModelText.implicitWidth
                                            height: 16
                                            visible: !sentByUser
                                            Row {
                                                spacing:4
                                                Text {
                                                    id: setModelText
                                                    Accessible.name: "kylin-aiassistant_Chat_setModelText"
                                                    color: "#3790FA"
                                                    anchors.verticalCenter: parent.verticalCenter
                                                    text: qsTr("Configure")
                                                }
                                            }
                                            MouseArea {
                                                anchors.fill: parent
                                                hoverEnabled: true
                                                cursorShape: Qt.PointingHandCursor
                                                onEntered: {
                                                    setModelText.color = "#3489ED"
                                                }
                                                onExited: {
                                                    setModelText.color = "#3790FA"
                                                }
                                                onPressed: {
                                                    setModelText.color = "#2C73C8"
                                                }
                                                onReleased: {
                                                    setModelText.color = "#3790FA"
                                                }
                                                onClicked: {
                                                    //msgPane.showSettingPage()
                                                    msgPane.openUkuiControlCenter()
                                                }
                                            }
                                        }
                                    }

                                    Row {
                                        id: toolButtonArea
                                        Accessible.name: "kylin-aiassistant_Chat_toolButtonArea"
                                        width: messageRectangle.width - 22
                                        layoutDirection: Qt.LeftToRight
                                        topPadding: 10
                                        bottomPadding: 10
                                        leftPadding: 22
                                        visible: model.noModelError === "" && model.colorMsg === ""
                                        property bool isLikePressed: false
                                        spacing:16
//                                        Rectangle {
//                                            id: stopButton
//                                            Accessible.name: "kylin-aiassistant_Chat_stopButton"
//                                            width: stopButtonImage.implicitWidth + stopButtonText.implicitWidth
//                                            height: 16
//                                            visible: !sentByUser && !isEnd
//                                            Row {
//                                                spacing:4
//                                                Image {
//                                                    id: stopButtonImage
//                                                    Accessible.name: "kylin-aiassistant_Chat_stopButtonImage"
//                                                    source: "qrc:/html/html/img/chathome/stop.svg"
//                                                    width:16
//                                                    height:16
//                                                    anchors.verticalCenter: parent.verticalCenter

//                                                }
//                                                Text {
//                                                    id: stopButtonText
//                                                    Accessible.name: "kylin-aiassistant_Chat_stopButtonText"
//                                                    color: "#E41A2B"
//                                                    anchors.verticalCenter: parent.verticalCenter
//                                                    text: qsTr("Stop answering")
//                                                }
//                                            }
//                                            MouseArea {
//                                                anchors.fill: parent
//                                                hoverEnabled: true
//                                                cursorShape: Qt.PointingHandCursor
//                                                onEntered: {
//                                                    stopButtonText.color = "#E41A2B"
//                                                    stopButtonImage.source = "qrc:/html/html/img/chathome/stop_hover.svg"
//                                                }
//                                                onExited: {
//                                                    stopButtonText.color = "#F3222D"
//                                                    stopButtonImage.source = "qrc:/html/html/img/chathome/stop.svg"
//                                                }
//                                                onPressed: {
//                                                    stopButtonText.color = "#CC1222"
//                                                    stopButtonImage.source = "qrc:/html/html/img/chathome/stop_active.svg"
//                                                }
//                                                onClicked: {
//                                                    console.log("MouseArea")
//                                                    msgPane.onStopReply()
//                                                }
//                                                onReleased: {
//                                                    stopButtonText.color = "#E41A2B"
//                                                    stopButtonImage.source = "qrc:/html/html/img/chathome/stop_hover.svg"
//                                                }
//                                            }
//                                        }
                                        //重新回答按钮
                                        Rectangle {
                                            id: refreshButton
                                            Accessible.name: "kylin-aiassistant_Chat_refreshButton"
                                            width: refreshButtonImage.implicitWidth
                                            height: 16
                                            ToolTip.text: qsTr("Re-answer")
                                            ToolTip.visible: refreshButtonMouseArea.containsMouse
                                            visible: !sentByUser && isEnd !== undefined && isEnd && !isRefreshed && !model.isCleared && (index === listView.model.count - 1) && isShowPictureOperateRefresh
                                            Row {
                                                spacing:4
                                                Image {
                                                    id: refreshButtonImage
                                                    Accessible.name: "kylin-aiassistant_Chat_refreshButtonImage"
                                                    source: "qrc:/html/html/img/chathome/refresh.svg"
                                                    width:16
                                                    height:16
                                                    anchors.verticalCenter: parent.verticalCenter

                                                }
                                            }

                                            MouseArea {
                                                id: refreshButtonMouseArea
                                                anchors.fill: parent
                                                cursorShape: Qt.PointingHandCursor
                                                hoverEnabled: true
                                                onEntered: {
                                                    refreshButtonImage.source = "qrc:/html/html/img/chathome/refresh_hover.svg"
                                                }
                                                onExited: {
                                                    refreshButtonImage.source = "qrc:/html/html/img/chathome/refresh.svg"
                                                }
                                                onPressed: {
                                                    refreshButtonImage.source = "qrc:/html/html/img/chathome/refresh_active.svg"
                                                }
                                                onClicked: {
                                                    if (listModel.count > 0) {
                                                        var lastMsg = listModel.get(listModel.count - 1)
                                                        lastMsg.isRefreshed = true
                                                    }

                                                    var foundElement = null;
                                                    for (var i = listModel.count - 1; i >= 0; i--) {
                                                        var element = listModel.get(i);
                                                        if (element.author === "User") {
                                                            foundElement = element;
                                                            break;
                                                        }
                                                    }

                                                    if (foundElement.imageSrc !== "" && foundElement.imagePath !== "") {
                                                        msgPane.onSendImage(foundElement.imagePath);
                                                        return;
                                                    }

                                                    if (foundElement.imagePath !== "" && foundElement.message === "扫描黑白件") {
                                                        msgPane.onEnhanceBlackAndWhite(foundElement.imagePath);
                                                        return;
                                                    }

                                                    if (foundElement.imagePath !== "" && foundElement.message === "智能抠图") {
                                                        msgPane.onCutOutImage(foundElement.imagePath);
                                                        return;
                                                    }

                                                    var msgHead = foundElement.msgHead;
                                                    var promptId = foundElement.promptId;
                                                    var msg = foundElement.message;
                                                    var speechFlag = foundElement.speechFlag;
                                                    var msgHeadList = {
                                                        msgHead: msgHead,
                                                        promptId: promptId,
                                                        reAnswer: true,
                                                        speechFlag: speechFlag,
                                                    };
                                                    var jsonMsgHead = JSON.stringify(msgHeadList);
                                                    moveCommonTimer.running = true
                                                    if (listView.curIndex >= 0 && listView.curIndex < listModel.count && speechFlag) {
                                                        // 重新发送语音对话消息前需要停止朗读
                                                        msgPane.onPauseRead();
                                                        listModel.get(listView.curIndex).showRead = true;
                                                        listView.preIndex = listView.curIndex;
                                                        listView.curIndex = -1;

                                                    }
                                                    var retJsonString = msgPane.onSendMsg(jsonMsgHead, msg);
                                                    var retJsonObject = JSON.parse(retJsonString);
                                                    isReplying = retJsonObject['isReplying'] !== undefined ? retJsonObject['isReplying'] : false

                                                }
                                                onReleased: {
                                                    refreshButtonImage.source = "qrc:/html/html/img/chathome/refresh_hover.svg"
                                                }
                                            }

                                        }
                                        //复制按钮
                                        Rectangle {
                                            id: copyButton
                                            Accessible.name: "kylin-aiassistant_Chat_copyButton"
                                            width: copyButtonImage.implicitWidth
                                            height: 16
                                            ToolTip.text: qsTr("Copy")
                                            ToolTip.visible: copyButtonMouseArea.containsMouse
                                            visible: !sentByUser && isEnd
                                            Row {
                                                spacing: 4
                                                Image {
                                                    id: copyButtonImage
                                                    Accessible.name: "kylin-aiassistant_Chat_copyButtonImage"
                                                    source: "qrc:/html/html/img/chathome/copy.svg"
                                                    width:16
                                                    height:16
                                                    anchors.verticalCenter: parent.verticalCenter

                                                }
                                            }
                                            MouseArea{
                                                id: copyButtonMouseArea
                                                anchors.fill: parent
                                                cursorShape: Qt.PointingHandCursor
                                                hoverEnabled: true
                                                onEntered: {
                                                    copyButtonImage.source = "qrc:/html/html/img/chathome/copy_hover.svg"
                                                }
                                                onExited: {
                                                    copyButtonImage.source = "qrc:/html/html/img/chathome/copy.svg"
                                                }
                                                onPressed: {
                                                    copyButtonImage.source ="qrc:/html/html/img/chathome/copy_active.svg"
                                                }
                                                onClicked: {
                                                    var str = model.message.replace(/<\/?.+?\/?>/g,'');
                                                    str = str.replace(/&quot;/g,"\"") // 替换文本中的&quot;为"
                                                    msgPane.onCopyText(str);
                                                }
                                                onReleased: {
                                                    copyButtonImage.source = "qrc:/html/html/img/chathome/copy_hover.svg"
                                                }
                                            }


                                        }
                                        //朗读按钮
                                        Rectangle {
                                            id: readButton
                                            Accessible.name: "kylin-aiassistant_Chat_readButton"
                                            width: 16
                                            height: 16
                                            ToolTip.text: qsTr("Read")
                                            ToolTip.visible: readButtonMouseArea.containsMouse
                                            visible: !sentByUser && isEnd && showRead
                                            Row {
                                                spacing:4
                                                Image {
                                                    id: readButtonImage
                                                    Accessible.name: "kylin-aiassistant_Chat_readButtonImage"
                                                    source: "qrc:/html/html/img/chathome/read.svg"
                                                    width:16
                                                    height:16
                                                    anchors.verticalCenter: parent.verticalCenter
                                                }
                                            }

                                            MouseArea {
                                                id: readButtonMouseArea
                                                anchors.fill: parent
                                                hoverEnabled: true
                                                cursorShape: Qt.PointingHandCursor
                                                onEntered: {
                                                    readButtonImage.source = "qrc:/html/html/img/chathome/read_hover.svg"
                                                }
                                                onExited: {
                                                    readButtonImage.source = "qrc:/html/html/img/chathome/read.svg"
                                                }
                                                onPressed: {
                                                    readButtonImage.source = "qrc:/html/html/img/chathome/read_active.svg"
                                                }

                                                onClicked: {
                                                    console.log("readButton ", index);
                                                    console.log("preIndex ", listView.preIndex);
                                                    console.log("curIndex ", listView.curIndex);
                                                    if (listView.curIndex !== -1) {
                                                        //如果有正在朗读的消息，则打断
                                                        listModel.get(listView.curIndex).showRead = true;
                                                        listView.preIndex = listView.curIndex;

                                                    }

                                                    // 朗读开始后,更新为暂停按钮状态
                                                    listModel.get(index).showRead = false;

                                                    if (listView.preIndex === index) {
                                                        // 说明本次朗读打断后,再次开始朗读
                                                        listView.curIndex = index;
                                                        msgPane.onContinueRead(index);
                                                        return;
                                                    }

                                                    listView.curIndex = index;
                                                    //去除html标签
                                                    var str = message.replace(/<\/?.+?\/?>/g,'');
                                                    msgPane.onStartRead(str, index);

                                                }
                                                onReleased: {
                                                    readButtonImage.source = "qrc:/html/html/img/chathome/read.svg"
                                                }

                                            }
                                        }

                                        //暂停朗读按钮
                                        Rectangle {
                                            id: pauseButton
                                            Accessible.name: "kylin-aiassistant_Chat_pauseButton"
                                            width: 16
                                            height: 16
                                            ToolTip.text: qsTr("Pause")
                                            ToolTip.visible: pauseButtonMouseArea.containsMouse
                                            visible: !sentByUser && isEnd && !showRead

                                            Row {
                                                Rectangle{
                                                    width: 16
                                                    height: 16
                                                    color: "transparent"
                                                    // 播放动画
                                                    VoicePlayAnimation {
                                                        id:playAnimation2
                                                        Accessible.name: "kylin-aiassistant_Chat_playAnimation2"
                                                        anchors.verticalCenter: parent.verticalCenter
                                                        anchors.horizontalCenter: parent.horizontalCenter
                                                    }
                                                }
                                            }

                                            MouseArea {
                                                id: pauseButtonMouseArea
                                                anchors.fill: parent
                                                hoverEnabled: true
                                                cursorShape: Qt.PointingHandCursor
                                                onEntered: {
                                                    pauseButton.color = Qt.rgba(55/255, 144/255, 255/255, 0.1);
                                                }
                                                onExited: {
                                                    pauseButton.color = "#FFFFFF"
                                                }
                                                onPressed: {
                                                    pauseButton.color = Qt.rgba(55/255, 144/255, 255/255, 0.2);
                                                }
                                                onReleased: {
                                                    pauseButton.color = "#FFFFFF"
                                                }
                                                onClicked: {
                                                    console.log("pre reading index", listView.preIndex)
                                                    console.log("pauseButton ", index)

                                                    listModel.get(index).showRead = true;
                                                    listView.preIndex = index;
                                                    listView.curIndex = -1;

                                                    msgPane.onPauseRead();
                                                }

                                            }

                                        }

                                        //在此处插入一条横线
                                        Rectangle{
                                            width: 1
                                            height: 16
                                            color: '#0d262626'
                                            visible: !sentByUser && isEnd
                                            anchors.verticalCenter: parent.verticalCenter
                                        }
                                        //点赞按钮
                                        Rectangle {
                                            id: likeButton
                                            Accessible.name: "kylin-aiassistant_Chat_likeButton"
                                            width: likeButtonImage.implicitWidth
                                            height: 16
                                            ToolTip.text: qsTr("Like")
                                            ToolTip.visible: likeButtonMouseArea.containsMouse
                                            visible: !sentByUser && isEnd && !isLike
                                            Row {
                                                spacing: 4
                                                Image {
                                                    id: likeButtonImage
                                                    Accessible.name: "kylin-aiassistant_Chat_likeButtonImage"
                                                    source: "qrc:/html/html/img/chathome/like.svg"
                                                    width:16
                                                    height:16
                                                    anchors.verticalCenter: parent.verticalCenter

                                                }
                                            }
                                            MouseArea{
                                                id: likeButtonMouseArea
                                                anchors.fill: parent
                                                cursorShape: Qt.PointingHandCursor
                                                hoverEnabled: true
                                                onEntered: {
                                                    likeButtonImage.source = "qrc:/html/html/img/chathome/like_hover.svg"
                                                }
                                                onExited: {
                                                    likeButtonImage.source = "qrc:/html/html/img/chathome/like.svg"
                                                }
                                                onPressed: {
                                                    likeButtonImage.source ="qrc:/html/html/img/chathome/like_clicked.svg"
                                                }
                                                onClicked: {
                                                    feedbackComponent.visible = false
                                                    var element = listModel.get(index)
                                                    element.isDislike = false
                                                    element.isLike = true
                                                    toolButtonArea.isLikePressed = true
                                                    if(listModel.count === 0 || element.author === "User")
                                                        return;
                                                    element.isEnd = isEnd;
                                                    if(element.colorMsg === "red"){
                                                        //如果是异常消息，去除html标签和末尾的换行，解决历史记录第一条异常的问题
                                                        // 解析 JSON 字符串为 JavaScript 对象
                                                        var jsonObject = JSON.parse(JSON.stringify(element));
                                                        //去除html标签
                                                        jsonObject.message = jsonObject.message.replace(/<\/?.+?\/?>/g,'');
                                                        //去除最末尾的换行
                                                        jsonObject.message = jsonObject.message.replace(/\n$/, '')
                                                        msgPane.updateFeedbackDatabase(index, JSON.stringify(jsonObject));
                                                    }else{
                                                        msgPane.updateFeedbackDatabase(index, JSON.stringify(element));
                                                    }
                                                    msgPane.onLikeAction();
                                                }
                                                onReleased: {
                                                    likeButtonImage.source = "qrc:/html/html/img/chathome/liked_hover.svg"
                                                }
                                            }


                                        }
                                        Rectangle {
                                            id: likedButton
                                            Accessible.name: "kylin-aiassistant_Chat_likedButton"
                                            width: likedButtonImage.implicitWidth
                                            height: 16
                                            ToolTip.text: qsTr("Like")
                                            ToolTip.visible: likedButtonMouseArea.containsMouse
                                            visible: !sentByUser && isEnd && isLike

                                            Row {
                                                Image {
                                                    id: likedButtonImage
                                                    Accessible.name: "kylin-aiassistant_Chat_likedButtonImage"
                                                    source: "qrc:/html/html/img/chathome/like_clicked.svg"
                                                    width:16
                                                    height:16
                                                    anchors.verticalCenter: parent.verticalCenter
                                                }
                                            }

                                            MouseArea {
                                                id: likedButtonMouseArea
                                                anchors.fill: parent
                                                hoverEnabled: true
                                                cursorShape: Qt.PointingHandCursor
                                                onEntered: {
                                                    likedButtonImage.source = "qrc:/html/html/img/chathome/liked_hover.svg"
                                                }
                                                onExited: {
                                                    likedButtonImage.source = "qrc:/html/html/img/chathome/like_clicked.svg"
                                                }
                                                onPressed: {
                                                    likedButtonImage.source= "qrc:/html/html/img/chathome/liked_click.svg"
                                                }
                                                onClicked: {
                                                    feedbackComponent.visible = false
                                                    var element = listModel.get(index)
                                                    element.isDislike = false
                                                    element.isLike = false
                                                    toolButtonArea.isLikePressed = false
                                                    if(listModel.count === 0 || element.author === "User")
                                                        return;
                                                    element.isEnd = isEnd;
                                                    if(element.colorMsg === "red"){
                                                        //如果是异常消息，去除html标签和末尾的换行，解决历史记录第一条异常的问题
                                                        // 解析 JSON 字符串为 JavaScript 对象
                                                        var jsonObject = JSON.parse(JSON.stringify(element));
                                                        //去除html标签
                                                        jsonObject.message = jsonObject.message.replace(/<\/?.+?\/?>/g,'');
                                                        //去除最末尾的换行
                                                        jsonObject.message = jsonObject.message.replace(/\n$/, '')
                                                        msgPane.updateFeedbackDatabase(index, JSON.stringify(jsonObject));
                                                    }else{
                                                        msgPane.updateFeedbackDatabase(index, JSON.stringify(element));
                                                    }
                                                 }
                                                onReleased: {
                                                    likedButtonImage.source = "qrc:/html/html/img/chathome/like_hover.svg"
                                                }

                                            }

                                        }
                                        //点踩按钮
                                        Rectangle {
                                            id: dislikeButton
                                            Accessible.name: "kylin-aiassistant_Chat_dislikeButton"
                                            width: dislikeButtonImage.implicitWidth
                                            height: 16
                                            ToolTip.text: qsTr("Dislike")
                                            ToolTip.visible: dislikeButtonMouseArea.containsMouse
                                            visible: !sentByUser && isEnd && !isDislike
                                            Row {
                                                spacing: 4
                                                Image {
                                                    id: dislikeButtonImage
                                                    Accessible.name: "kylin-aiassistant_Chat_dislikeButtonImage"
                                                    source: "qrc:/html/html/img/chathome/dislike.svg"
                                                    width:16
                                                    height:16
                                                    anchors.verticalCenter: parent.verticalCenter

                                                }
                                            }
                                            MouseArea{
                                                id: dislikeButtonMouseArea
                                                anchors.fill: parent
                                                cursorShape: Qt.PointingHandCursor
                                                hoverEnabled: true
                                                onEntered: {
                                                    dislikeButtonImage.source = "qrc:/html/html/img/chathome/dislike_hover.svg"
                                                }
                                                onExited: {
                                                    dislikeButtonImage.source = "qrc:/html/html/img/chathome/dislike.svg"
                                                }
                                                onPressed: {
                                                    dislikeButtonImage.source ="qrc:/html/html/img/chathome/dislike_clicked.svg"
                                                }
                                                onClicked: {
                                                    //加载声明界面
                                                    feedbackComponent.visible = true
                                                    //最末尾index滚动加载，中间index由于无法获取正确的y不能实现自适应滚动加载
                                                    if(index === listView.count -1) {
                                                        showFeedbackpage.running = true
                                                    }
                                                    //逻辑,要在投诉建议点击后才能更新点赞点踩状态
                                                    //暂时的状态保存
                                                    var element = listModel.get(index)
                                                    element.isDislike = false
                                                    element.isLike = false
                                                }
                                                onReleased: {
                                                    dislikeButtonImage.source = "qrc:/html/html/img/chathome/disliked_hover.svg"
                                                }
                                            }


                                        }
                                        Rectangle {
                                            id: dislikedButton
                                            Accessible.name: "kylin-aiassistant_Chat_dislikedButton"
                                            width: dislikedButtonImage.implicitWidth
                                            height: 16
                                            ToolTip.text: qsTr("Dislike")
                                            ToolTip.visible: dislikedButtonMouseArea.containsMouse
                                            visible: !sentByUser && isEnd && isDislike

                                            Row {
                                                Image {
                                                    id: dislikedButtonImage
                                                    Accessible.name: "kylin-aiassistant_Chat_dislikedButtonImage"
                                                    source: "qrc:/html/html/img/chathome/dislike_clicked.svg"
                                                    width:16
                                                    height:16
                                                    anchors.verticalCenter: parent.verticalCenter
                                                }
                                            }

                                            MouseArea {
                                                id: dislikedButtonMouseArea
                                                Accessible.name: "kylin-aiassistant_Chat_dislikedButtonMouseArea"
                                                anchors.fill: parent
                                                hoverEnabled: true
                                                cursorShape: Qt.PointingHandCursor
                                                onEntered: {
                                                    dislikedButtonImage.source = "qrc:/html/html/img/chathome/disliked_hover.svg"
                                                }
                                                onExited: {
                                                    dislikedButtonImage.source = "qrc:/html/html/img/chathome/dislike_clicked.svg"
                                                }
                                                onPressed: {
                                                    dislikedButtonImage.source= "qrc:/html/html/img/chathome/disliked_active.svg"
                                                }
                                                onClicked: {
                                                    feedbackComponent.visible = false
                                                    var element = listModel.get(index)
                                                    element.isDislike = false
                                                    element.isLike = false
                                                    toolButtonArea.isLikePressed = false
                                                    if(listModel.count === 0 || element.author === "User")
                                                        return;
                                                    element.isEnd = isEnd;
                                                    if(element.colorMsg === "red"){
                                                        //如果是异常消息，去除html标签和末尾的换行，解决历史记录第一条异常的问题
                                                        // 解析 JSON 字符串为 JavaScript 对象
                                                        var jsonObject = JSON.parse(JSON.stringify(element));
                                                        //去除html标签
                                                        jsonObject.message = jsonObject.message.replace(/<\/?.+?\/?>/g,'');
                                                        //去除最末尾的换行
                                                        jsonObject.message = jsonObject.message.replace(/\n$/, '')
                                                        msgPane.updateFeedbackDatabase(index, JSON.stringify(jsonObject));
                                                    }else{
                                                        msgPane.updateFeedbackDatabase(index, JSON.stringify(element));
                                                    }
                                                }
                                                onReleased: {
                                                    dislikedButtonImage.source = "qrc:/html/html/img/chathome/dislike_hover.svg"
                                                }

                                            }

                                        }

                                    }
                                    // 声明界面
                                    Column {
                                        id: feedbackComponent
                                        Accessible.name: "kylin-aiassistant_Chat_feedbackComponent"
                                        visible: false
                                        width: messageRectangle.width -32
                                        leftPadding: 16
                                        rightPadding: 16
                                        topPadding: 10
                                        bottomPadding: 16
                                        spacing: 12
                                        Row{
                                            id: feedbackTitlebarRow
                                            Accessible.name: "kylin-aiassistant_Chat_feedbackTitlebarRow"
                                            width: messageRectangle.width - 32
                                            height: 32
                                            //标题栏
                                            Rectangle {
                                                id: feedbackTitleRect
                                                Accessible.name: "kylin-aiassistant_Chat_feedbackTitleRect"
                                                width: messageRectangle.width -64 - 42 - feedbackCloseButtonImage.width//需要跟随回答区域大小变动
                                                height: parent.height
                                                Text {
                                                    id: feedbackTitleText
                                                    text: qsTr("Thanks for your feedback")
                                                    font.bold: true
                                                    font.pixelSize: 14
                                                    anchors.verticalCenter: parent.verticalCenter // 只垂直居中
                                                }
                                            }
                                            //中间弹簧
                                            Rectangle {
                                                width: feedbackTitlebarRow.width - 10 - feedbackTitleRect.width - feedbackTitlebarButton.width
                                                height: parent.height
                                            }
                                            Rectangle {
                                                id: feedbackTitlebarButton
                                                Accessible.name: "kylin-aiassistant_Chat_feedbackTitlebarButton"
                                                width: 32
                                                height: 32
                                                color: "transparent"
                                                radius: 4
                                                ToolTip.visible: feedbackCloseButtonMouseArea.containsMouse
                                                ToolTip.text: qsTr("Close")
                                                ToolTip.delay: 500
                                                Image {
                                                    id: feedbackCloseButtonImage
                                                    Accessible.name: "kylin-aiassistant_Chat_feedbackCloseButtonImage"
                                                    anchors.centerIn: parent
                                                    source: "qrc:/icon/icon/close-black.svg"
                                                    width:16
                                                    height:16
                                                    anchors.verticalCenter: parent.verticalCenter
                                                }
                                                MouseArea {
                                                    id: feedbackCloseButtonMouseArea
                                                    Accessible.name: "kylin-aiassistant_Chat_feedbackCloseButtonMouseArea"
                                                    anchors.fill: parent
                                                    hoverEnabled: true
                                                    onEntered: {
                                                        feedbackTitlebarButton.color = "#26000000";
                                                    }
                                                    onExited: {
                                                        feedbackTitlebarButton.color = "transparent";
                                                    }
                                                    onPressed: {
                                                        feedbackTitlebarButton.color = "#33000000";
                                                    }
                                                    onClicked: {
                                                        //取消点踩并隐藏声明界面
                                                        feedbackComponent.visible = false
                                                        var element = listModel.get(index)
                                                        element.isDislike = false
                                                        element.isLike = toolButtonArea.isLikePressed
                                                    }
                                                    onReleased: {
                                                        feedbackTitlebarButton.color = "transparent";
                                                    }
                                                }
                                            }
                                        }
                                        Row {
                                            // 用于读取 HTML 文件内容
                                            function loadHtmlFile(fileUrl) {
                                                var htmlFile = new XMLHttpRequest();
                                                htmlFile.open("GET", fileUrl);
                                                htmlFile.onreadystatechange = function() {
                                                    if (htmlFile.readyState === XMLHttpRequest.DONE) {
                                                        if (htmlFile.status === 200) {
                                                            // 将读取的 HTML 内容设置到 Text 组件中
                                                            feedbackTextArea.text = htmlFile.responseText;
                                                        } else {
                                                            console.error("Failed to load HTML file:", htmlFile.statusText);
                                                        }
                                                    }
                                                };
                                                htmlFile.send();

                                                }
                                            Component.onCompleted: {
                                                // 加载 HTML 文件
                                                loadHtmlFile("qrc:/html/html/openKylin操作系统AI功能使用协议250228-0318.html");
                                            }
                                            //声明滚动区域
                                            Flickable {
                                                id: feedbackTextAreaScrollView
                                                Accessible.name: "kylin-aiassistant_Chat_feedbackComponent"
                                                width: messageRectangle.width -32
                                                height: 134  // 限定高度
                                                clip: true  // 保证超出内容不显示
                                                contentWidth: feedbackTextArea.width  // 内容宽度
                                                contentHeight: feedbackTextArea.height  // 内容高度
                                                boundsBehavior: Flickable.StopAtBounds
                                                // 自定义垂直滚动条
                                                ScrollBar.vertical: ScrollBar {
                                                    policy: ScrollBar.AlwaysOn
                                                }
                                                TextArea {
                                                    id: feedbackTextArea
                                                    Accessible.name: "kylin-aiassistant_Chat_feedbackComponent"
                                                    width: messageRectangle.width -64
                                                    wrapMode: TextArea.Wrap
                                                    readOnly: true
                                                    textFormat:  Text.RichText
                                                }
                                                function adjustScrollPosition() {
                                                    var cursorPosition = feedbackTextArea.cursorPosition
                                                    var contentHeight = feedbackTextArea.contentHeight
                                                    var visibleHeight = feedbackTextAreaScrollView.height

                                                    // 如果内容超出可视区域，确保滚动条跟随光标
                                                    if (contentHeight > visibleHeight) {
                                                        if (cursorPosition >= contentHeight - visibleHeight) {
                                                            // 如果光标接近底部，则滚动到光标
                                                            feedbackTextAreaScrollView.contentY = contentHeight - visibleHeight + 12
                                                        } else {
                                                            // 否则滚动一点，确保光标可见
                                                            feedbackTextAreaScrollView. contentY = Math.max(0, cursorPosition - visibleHeight)
                                                        }
                                                    }
                                                }
                                            }

                                        }
                                        //投诉建议按钮
                                        Row {
                                            id: feedbakButtonRow
                                            Accessible.name: "kylin-aiassistant_Chat_feedbakButtonRow"
                                            width: messageRectangle.width - 32
                                            layoutDirection: Qt.RightToLeft
                                            //需要获取模型类型显示
                                            Rectangle {
                                                id: feedbakButton
                                                Accessible.name: "kylin-aiassistant_Chat_feedbakButton"
                                                width: feedbackButtonText.width + 32
                                                height: 36
                                                radius: 6
                                                color: "#3790FA"
                                                visible: model.feedbackURL !== undefined && model.feedbackURL !== ""
                                                Row {
                                                    anchors.centerIn: parent
                                                    Text {
                                                        id: feedbackButtonText
                                                        Accessible.name: "kylin-aiassistant_Chat_feedbackButtonText"
                                                        text: qsTr("Feedback")
                                                        color: "#FFFFFF"
                                                        anchors.verticalCenter: parent.verticalCenter
                                                    }
                                                }
                                                MouseArea{
                                                    id: feedbackButtonMouseArea
                                                    anchors.fill: parent
//                                                    cursorShape: Qt.PointingHandCursor
                                                    hoverEnabled: true
                                                    onEntered: {
                                                        parent.color = "#3489EE";
                                                    }
                                                    onExited: {
                                                        parent.color = "#3790FA";
                                                    }
                                                    onPressed: {
                                                        parent.color = "#2C73C8";
                                                    }
                                                    onClicked: {
                                                        //跳链接
                                                        feedbackComponent.visible = false
                                                        var element = listModel.get(index)
                                                        element.isDislike = true
                                                        element.isLike = false
                                                        toolButtonArea.isLikePressed = false
                                                        Qt.openUrlExternally(element.feedbackURL);
                                                        if(listModel.count === 0 || element.author === "User")
                                                            return;
                                                        element.isEnd = isEnd;
                                                        if(element.colorMsg === "red"){
                                                            //如果是异常消息，去除html标签和末尾的换行，解决历史记录第一条异常的问题
                                                            // 解析 JSON 字符串为 JavaScript 对象
                                                            var jsonObject = JSON.parse(JSON.stringify(element));
                                                            //去除html标签
                                                            jsonObject.message = jsonObject.message.replace(/<\/?.+?\/?>/g,'');
                                                            //去除最末尾的换行
                                                            jsonObject.message = jsonObject.message.replace(/\n$/, '')
                                                            msgPane.updateFeedbackDatabase(index, JSON.stringify(jsonObject));
                                                        }else{
                                                            msgPane.updateFeedbackDatabase(index, JSON.stringify(element));
                                                        }
                                                        msgPane.onLikeAction();
                                                    }
                                                    onReleased: {
                                                        parent.color = "#3489EE";
                                                    }
                                                }
                                            }
                                        }
                                        Timer {
                                            id: showFeedbackpage
                                            interval: 100
                                            repeat: false   // 设置定时器只执行一次
                                            running: false   // 设置定时器启动
                                            onTriggered: {
                                                // 定时器触发后执行的代码
                                                listView.positionViewAtEnd()
                                            }
                                        }
                                    }
                                }

                            }
                        }
                    }
                    // 开启新回答区域
                    Row{
                        id: clearContextRow
                        Accessible.name: "kylin-aiassistant_Chat_clearContextRow"
                        spacing:4
                        //临时用于清除上下文关联水平居中
                        leftPadding: 25
                        anchors.horizontalCenter: parent.horizontalCenter  // 水平方向居中
                        Image {
                            id: separatorLeftImage
                            Accessible.name: "kylin-aiassistant_Chat_separatorLeftImage"
                            source: "qrc:/icon/icon/separator-left.svg"
                            visible: isEnd === undefined ? false : isEnd && model.isCleared ? isEnd && model.isCleared : (isEnd && (index === listModel.count - 1))
                            anchors.verticalCenter: parent.verticalCenter
                            // 固定值
                            property int fixedSize: 120
                            // 计算宽高比
                            property real aspectRatio: implicitWidth / implicitHeight
                            // 根据图片宽高比调整大小，取宽度或高度中的较大者为fixedSize
                            width: aspectRatio >= 1 ? fixedSize : fixedSize * aspectRatio  // 如果宽比高大，则宽度取固定值
                            height: aspectRatio < 1 ? fixedSize : fixedSize / aspectRatio
                        }
                        Text {
                            id: contextText
                            Accessible.name: "kylin-aiassistant_Chat_contextText"
                            color: Qt.rgba(0, 0 , 0, 0.85)
                            text: qsTr("To conclude the above topic,")
                            visible: isEnd === undefined ? false : isEnd && !model.isCleared && (index === listModel.count - 1)
                            anchors.verticalCenter: parent.verticalCenter
                            font.pixelSize: 12
                            MouseArea{
                                id: contextTextMouseArea
                                anchors.fill: parent
                                hoverEnabled: true
                                onEntered: {
                                    clearContextText.color= "#3489EE"
                                }
                                onExited: {
                                    clearContextText.color= "#3790FA"
                                }
                                onPressed: {
                                    clearContextText.color= "#2C73C8"
                                }
                                onReleased: {
                                    clearContextText.color= "#3790FA"
                                }
                                onClicked: {
                                    var lastElement = listModel.get(listModel.count - 1)
                                    lastElement.isCleared = true
                                    msgPane.onClearContext();
                                }
                            }
                        }
                        Text {
                            id: clearContextText
                            Accessible.name: "kylin-aiassistant_Chat_clearContextText"
                            color: "#3790FA"
                            text: qsTr("Start a new topic")
                            visible: isEnd === undefined ? false : isEnd && !model.isCleared && (index === listModel.count - 1)
                            font.pixelSize: 12
                            anchors.verticalCenter: parent.verticalCenter
                            onVisibleChanged: {
                                // 当清除按钮显示时，判断滚动条是否最下面，解决滚动条不自动上划
                                if(clearContextText.visible){
                                    if(listView.isChatEndFlag){
                                        clearContextTimer.running = true
                                    }
                                }
                            }
                            MouseArea{
                                id: clearContextTextMouseArea
                                anchors.fill: parent
                                hoverEnabled: true
                                onEntered: {
                                    clearContextText.color= "#3489EE"
                                }
                                onExited: {
                                    clearContextText.color= "#3790FA"
                                }
                                onPressed: {
                                    clearContextText.color= "#2C73C8"
                                }
                                onReleased: {
                                    clearContextText.color= "#3790FA"
                                }
                                onClicked: {
                                    var lastElement = listModel.get(listModel.count - 1)
                                    lastElement.isCleared = true
                                    msgPane.onClearContext();
                                }
                            }
                        }
                        Text {
                            id: alreadyClearContextText
                            Accessible.name: "kylin-aiassistant_Chat_alreadyClearContextText"
                            color: Qt.rgba(0, 0, 0, 0.3)
                            text: qsTr("A new topic has been opened")
                            visible: isEnd === undefined ? false : isEnd && model.isCleared
                            font.pixelSize: 12
                            anchors.verticalCenter: parent.verticalCenter
                        }
                        Image {
                            id: separatorRightImage
                            Accessible.name: "kylin-aiassistant_Chat_separatorRightImage"
                            source: "qrc:/icon/icon/separator-right.svg"
                            visible: isEnd === undefined ? false : isEnd && model.isCleared ? isEnd && model.isCleared : isEnd && ((index === listModel.count - 1))
                            anchors.verticalCenter: parent.verticalCenter
                            // 固定值
                            property int fixedSize: 120
                            // 计算宽高比
                            property real aspectRatio: implicitWidth / implicitHeight
                            // 根据图片宽高比调整大小，取宽度或高度中的较大者为fixedSize
                            width: aspectRatio >= 1 ? fixedSize : fixedSize * aspectRatio  // 如果宽比高大，则宽度取固定值
                            height: aspectRatio < 1 ? fixedSize : fixedSize / aspectRatio
                        }
                        Timer {
                            // 用于解决生成图片时内容不会自动向下滚动问题
                            id: clearContextTimer
                            interval: 10
                            repeat: false   // 设置定时器只执行一次
                            running: false   // 设置定时器启动
                            onTriggered: {
                                // 定时器触发后执行的代码
                                listView.positionViewAtEnd()
                            }
                        }
                    }
                }
                Component.onCompleted: {
                }

                Connections
                {
                    target: msgPane

                    //插入一条新消息
                    function pushMsg(author, msgHeadList, msg){

                        var jsonObject = null
                        var colorMsg = null                 //回答字体颜色
                        var drawMsg = null                  //是否显示文生图等待动画
                        var imageSrc = null                 //图片base64数据
                        var imagePath = null                //图片路径
                        var showImageOptions = null         //是否显示提供可选择的图片处理方式
                        var showRead = null                 //是否显示朗读按钮
                        var msgHead = null                  //系统标签
                        var promptId = null                 //指令ID
                        var modelMsg = null                 //模型角标
                        var isCleared = null                //是否清除上下文关联
                        var documentName = null             //上传的文档名称
                        var documentSize = null             //上传的文档大小
                        var documentIcon = null             //上传的文档icon
                        var documentPath = null             //上传的文档路径
                        var isAddSchedule = null            //是否新建日程
                        var isGenerateToDo = null           //是否生成待办
                        var scheduleDate;                   //打开日历所需的年月日
                        var pdfPath;                        //周报生成日历的链接
                        var noModelError;                   //未配置模型的错误信息
                        var isFirst;                        //是否初次修改
                        var speechFlag;                     //是否是语音对话识别的消息
                        var isShowInfoSources;              //是否展示信息来源
                        var infoSources;                    //消息来源
                        var pictureOperates;                //图像处理操作
                        var isShowPictureOperateRefresh;    //是否是图像操作生成的图片
                        var reasonMessage;                  //思考过程
                        var operatorId;                     //图像处理操作
                        var isLike;                         //是否点赞
                        var isDislike;                      //是否点踩
                        var feedbackURL;                    //投诉链接
                        var closePopup;                     //关闭弹窗
                        if(msgHeadList !== ''){
                            jsonObject = JSON.parse(msgHeadList);
                            colorMsg = jsonObject.colorMsg !== undefined? jsonObject.colorMsg : ""
                            drawMsg = jsonObject.drawMsg !== undefined? jsonObject.drawMsg : false
                            imageSrc = jsonObject.imageSrc !== undefined? jsonObject.imageSrc : ""
                            imagePath = jsonObject.imagePath !== undefined? jsonObject.imagePath : ""
                            showImageOptions = jsonObject.showImageOptions !== undefined? jsonObject.showImageOptions : false
                            showRead = jsonObject.showRead !== undefined? jsonObject.showRead : true
                            msgHead = jsonObject.msgHead !== undefined? jsonObject.msgHead : ""
                            promptId = jsonObject.promptId !== undefined? jsonObject.promptId : -1
                            modelMsg = jsonObject.modelMsg !== undefined? jsonObject.modelMsg : ""
                            isCleared = jsonObject.isCleared !== undefined? jsonObject.isCleared : false
                            documentName = jsonObject.documentName !== undefined? jsonObject.documentName : ""
                            documentSize = jsonObject.documentSize !== undefined? jsonObject.documentSize : ""
                            documentIcon = jsonObject.documentIcon !== undefined? jsonObject.documentIcon : ""
                            documentPath = jsonObject.documentPath !== undefined? jsonObject.documentPath : ""
                            isAddSchedule = jsonObject.isAddSchedule !== undefined? jsonObject.isAddSchedule : false
                            isGenerateToDo = jsonObject.isGenerateToDo !== undefined? jsonObject.isGenerateToDo : false
                            scheduleDate = jsonObject.scheduleDate !== undefined? jsonObject.scheduleDate: "";
                            pdfPath = jsonObject.pdfPath !== undefined? jsonObject.pdfPath: "";
                            noModelError = jsonObject.noModelError !== undefined? jsonObject.noModelError: "";
                            isFirst = jsonObject.isFirst !== undefined ? jsonObject.isFirst: true;
                            speechFlag = jsonObject.speechFlag !== undefined ? jsonObject.speechFlag: false;
                            isShowInfoSources = jsonObject.isShowInfoSources !== undefined ? jsonObject.isShowInfoSources: false;
                            infoSources = jsonObject.infoSources !== undefined ? jsonObject.infoSources: "";
                            pictureOperates = jsonObject.pictureOperates !== undefined ? jsonObject.pictureOperates: "";
                            isShowPictureOperateRefresh = jsonObject.isShowPictureOperateRefresh !== undefined ? jsonObject.isShowPictureOperateRefresh: true;
                            operatorId = jsonObject.operatorId !== undefined ? jsonObject.operatorId: 0;
                            isLike = jsonObject.isLike !== undefined? jsonObject.isLike : false
                            isDislike = jsonObject.isDislike !== undefined? jsonObject.isDislike : false
                            feedbackURL = jsonObject.feedbackURL !== undefined? jsonObject.feedbackURL : ""
                            closePopup = jsonObject.closePopup !== undefined? jsonObject.closePopup : false
                        };
                        var item = {"author":author, "isEnd":false, "isRefreshed":false,
                                     "colorMsg":colorMsg, "drawMsg":drawMsg, "imageSrc":imageSrc,
                                     "imagePath":imagePath, "showImageOptions":false, "showRead":showRead,
                                     "msgHead":msgHead, "promptId":promptId, "message":msg, "modelMsg":modelMsg,
                                     "isCleared":isCleared,"documentName":documentName,"documentSize":documentSize,
                                     "documentIcon":documentIcon,"documentPath":documentPath,"isAddSchedule":isAddSchedule,
                                     "isGenerateToDo":isGenerateToDo,"scheduleDate":scheduleDate, "pdfPath":pdfPath,"noModelError":noModelError,
                                     "isFirst":isFirst,"speechFlag":speechFlag,"isShowInfoSources":isShowInfoSources,"infoSources":infoSources,
                                     "pictureOperates":pictureOperates,"isShowPictureOperateRefresh":isShowPictureOperateRefresh,
                                     "reasonMessage":"","operatorId":operatorId,"isLike":isLike,
                                     "isDislike":isDislike,"feedbackURL":feedbackURL,"closePopup":closePopup};
                        listModel.append(item)
                        //用户发送消息直接保存到数据库中
                        //TODO: 文档和图片类消息的msg也为空，if的判断条件需要修改
                        if(author !== "Bot" && (msg !== "" || documentName !== "" || imageSrc !== ""))
                        {
                            msgPane.saveToDatabase(listModel.count - 1, JSON.stringify(item));
                        }
                        //对话移动到最新的一次回答
                        if(listView.isChatEndFlag){
                            listView.positionViewAtEnd()
                        }
                        // 对话出现立即配置需要移动到对话最下方
                        if(noModelError !== "" && noModelError !==undefined){
                            moveCommonTimer.running = true
                            //移动到最新的一次回答，魔法方案
                            for(var i = 0; i < 10; ++i){
                                listView.positionViewAtEnd()
                            }
                        }
                    }

                    //修改最后一条消息的属性
                    onUpdateMsg: function(msgHeadList, msg) {
                        var jsonObject;
                        var colorMsg;                       //回答字体颜色
                        var drawMsg;                        //是否显示文生图等待动画
                        var imageSrc;                       //图片base64数据
                        var imagePath;                      //图片路径
                        var showImageOptions;               //是否显示提供可选择的图片处理方式
                        var showRead;                       //是否显示朗读按钮
                        var msgHead;                        //系统标签
                        var promptId;                       //指令ID
                        var modelMsg;                       //模型角标
                        var isCleared;                      //是否清除上下文关联
                        var documentName;                   //上传的文档名称
                        var documentSize;                   //上传的文档大小
                        var documentIcon;                   //上传的文档icon
                        var documentPath;                   //上传的文档路径
                        var isAddSchedule;                  //是否新建日程
                        var isGenerateToDo;                 //是否生成待办
                        var scheduleDate;                   //打开日历所需的年月日
                        var pdfPath;                        //周报生成日历的链接
                        var noModelError;                   //未配置模型的错误信息
                        var speechFlag;                     //是否是语音对话识别的消息
                        var isShowInfoSources;              //是否展示信息来源
                        var infoSources;                    //消息来源
                        var pictureOperates;                //图像处理操作
                        var isShowPictureOperateRefresh;    //是否是图像操作生成的图片
                        var operatorId;                     //图像处理操作
                        var isLike;                         //是否点赞
                        var isDislike;                      //是否点踩
                        var feedbackURL;                    //投诉链接
                        var closePopup;                     //关闭弹窗
                        var lastMsg = listModel.get(listModel.count - 1);
                        //如果isFirst为true，解析所有字段
                        if(lastMsg.isFirst === true)
                        {

                            if(msgHeadList !== ''){
                                jsonObject = JSON.parse(msgHeadList);
                                colorMsg = jsonObject.colorMsg !== undefined? jsonObject.colorMsg : ""
                                drawMsg = jsonObject.drawMsg !== undefined? jsonObject.drawMsg : false
                                imageSrc = jsonObject.imageSrc !== undefined? jsonObject.imageSrc : ""
                                imagePath = jsonObject.imagePath !== undefined? jsonObject.imagePath : ""
                                showImageOptions = jsonObject.showImageOptions !== undefined? jsonObject.showImageOptions : false
                                showRead = jsonObject.showRead !== undefined? jsonObject.showRead : true
                                msgHead = jsonObject.msgHead !== undefined? jsonObject.msgHead : ""
                                promptId = jsonObject.promptId !== undefined? jsonObject.promptId : -1
                                modelMsg = jsonObject.modelMsg !== undefined? jsonObject.modelMsg : ""
                                isCleared = jsonObject.isCleared !== undefined? jsonObject.isCleared : false
                                documentName = jsonObject.documentName !== undefined? jsonObject.documentName : ""
                                documentSize = jsonObject.documentSize !== undefined? jsonObject.documentSize : ""
                                documentIcon = jsonObject.documentIcon !== undefined? jsonObject.documentIcon : ""
                                documentPath = jsonObject.documentPath !== undefined? jsonObject.documentPath : ""
                                isAddSchedule = jsonObject.isAddSchedule !== undefined? jsonObject.isAddSchedule : false
                                isGenerateToDo = jsonObject.isGenerateToDo !== undefined? jsonObject.isGenerateToDo : false
                                scheduleDate = jsonObject.scheduleDate !== undefined? jsonObject.scheduleDate: "";
                                pdfPath = jsonObject.pdfPath !== undefined? jsonObject.pdfPath: "";
                                noModelError = jsonObject.noModelError !== undefined? jsonObject.noModelError: "";
                                speechFlag = jsonObject.speechFlag !== undefined ? jsonObject.speechFlag: false;
                                isShowInfoSources = jsonObject.isShowInfoSources !== undefined ? jsonObject.isShowInfoSources: false;
                                infoSources = jsonObject.infoSources !== undefined ? jsonObject.infoSources: "";
                                pictureOperates = jsonObject.pictureOperates !== undefined ? jsonObject.pictureOperates: "";
                                isShowPictureOperateRefresh = jsonObject.isShowPictureOperateRefresh !== undefined ? jsonObject.isShowPictureOperateRefresh: true;
                                operatorId = jsonObject.operatorId !== undefined ? jsonObject.operatorId: 0;
                                isLike = jsonObject.isLike !== undefined? jsonObject.isLike : false;
                                isDislike = jsonObject.isDislike !== undefined? jsonObject.isDislike : false;
                                feedbackURL = jsonObject.feedbackURL !== undefined? jsonObject.feedbackURL : "";
                                closePopup = jsonObject.closePopup !== undefined? jsonObject.closePopup : false
                            };
                            var item = {"author":"Bot", "isEnd":false, "isRefreshed":false,
                                         "colorMsg":colorMsg, "drawMsg":drawMsg, "imageSrc":imageSrc,
                                         "imagePath":imagePath, "showImageOptions":false, "showRead":showRead,
                                         "msgHead":msgHead, "promptId":promptId, "message":msg, "modelMsg":modelMsg,
                                         "isCleared":isCleared,"documentName":documentName,"documentSize":documentSize,
                                         "documentIcon":documentIcon,"documentPath":documentPath,"isAddSchedule":isAddSchedule,
                                         "isGenerateToDo":isGenerateToDo,"scheduleDate":scheduleDate,"pdfPath":pdfPath,"noModelError":noModelError,
                                         "isFirst":false,"speechFlag":speechFlag,"isShowInfoSources":isShowInfoSources,"infoSources":infoSources,
                                         "pictureOperates":pictureOperates,"isShowPictureOperateRefresh":isShowPictureOperateRefresh,
                                         "reasonMessage":lastMsg.reasonMessage,"operatorId":operatorId,
                                         "isLike":isLike,"isDislike":isDislike,"feedbackURL":feedbackURL,"closePopup":closePopup};
//                            lastMsg = item;
                            listModel.set(listModel.count - 1,item);
                        }else{
                            if(msgHeadList !== ''){
                                jsonObject = JSON.parse(msgHeadList);
                                colorMsg = jsonObject.colorMsg;
                                drawMsg = jsonObject.drawMsg;
                                msgHead = jsonObject.msgHead;
                                promptId = jsonObject.promptId;
                                scheduleDate = (jsonObject.scheduleDate !== undefined? jsonObject.scheduleDate: "")
                                isAddSchedule = (jsonObject.isAddSchedule !== undefined? jsonObject.isAddSchedule : false)
                                isGenerateToDo = (jsonObject.isGenerateToDo !== undefined? jsonObject.isGenerateToDo : false)
                            };

                            lastMsg = listModel.get(listModel.count - 1);

                            lastMsg.colorMsg = colorMsg;
                            lastMsg.drawMsg = drawMsg;
                            lastMsg.msgHead = msgHead;
                            lastMsg.promptId = promptId;
                            lastMsg.scheduleDate = scheduleDate;
                            lastMsg.isAddSchedule = isAddSchedule;
                            lastMsg.isGenerateToDo = isGenerateToDo;
                            lastMsg.message = msg;


                        }
                        //对话移动到最新的一次回答
                        if(listView.isChatEndFlag){
                            listView.positionViewAtEnd()
                        }
                        // 对话出现立即配置需要移动到对话最下方
                        if(noModelError !== "" && noModelError !==undefined){
                            moveCommonTimer.running = true
                            //移动到最新的一次回答，魔法方案
                            for(var i = 0; i < 10; ++i){
                                listView.positionViewAtEnd()
                            }
                        }
                        isSpeech = listModel.get(listModel.count -1).speechFlag;
                    }

                    //修改思考过程消息的属性
                    onUpdateReasoningMsg: function(msgHeadList, msg) {
                        var jsonObject;
                        var colorMsg;                       //回答字体颜色
                        var drawMsg;                        //是否显示文生图等待动画
                        var imageSrc;                       //图片base64数据
                        var imagePath;                      //图片路径
                        var showImageOptions;               //是否显示提供可选择的图片处理方式
                        var showRead;                       //是否显示朗读按钮
                        var msgHead;                        //系统标签
                        var promptId;                       //指令ID
                        var modelMsg;                       //模型角标
                        var isCleared;                      //是否清除上下文关联
                        var documentName;                   //上传的文档名称
                        var documentSize;                   //上传的文档大小
                        var documentIcon;                   //上传的文档icon
                        var documentPath;                   //上传的文档路径
                        var isAddSchedule;                  //是否新建日程
                        var isGenerateToDo;                 //是否生成待办
                        var scheduleDate;                   //打开日历所需的年月日
                        var pdfPath;                        //周报生成日历的链接
                        var noModelError;                   //未配置模型的错误信息
                        var speechFlag;                     //是否是语音对话识别的消息
                        var isShowInfoSources;              //是否展示信息来源
                        var infoSources;                    //消息来源
                        var pictureOperates;                //图像处理操作
                        var isShowPictureOperateRefresh;    //是否是图像操作生成的图片
                        var operatorId;                     //图像处理操作
                        var isLike;                         //是否点赞
                        var isDislike;                      //是否点踩
                        var feedbackURL;                    //投诉链接
                        var closePopup;                     //关闭弹窗
                        var lastMsg = listModel.get(listModel.count - 1);
                        //如果isFirst为true，解析所有字段
                        if(lastMsg.isFirst === true)
                        {

                            if(msgHeadList !== ''){
                                jsonObject = JSON.parse(msgHeadList);
                                colorMsg = jsonObject.colorMsg !== undefined? jsonObject.colorMsg : ""
                                drawMsg = jsonObject.drawMsg !== undefined? jsonObject.drawMsg : false
                                imageSrc = jsonObject.imageSrc !== undefined? jsonObject.imageSrc : ""
                                imagePath = jsonObject.imagePath !== undefined? jsonObject.imagePath : ""
                                showImageOptions = jsonObject.showImageOptions !== undefined? jsonObject.showImageOptions : false
                                showRead = jsonObject.showRead !== undefined? jsonObject.showRead : true
                                msgHead = jsonObject.msgHead !== undefined? jsonObject.msgHead : ""
                                promptId = jsonObject.promptId !== undefined? jsonObject.promptId : -1
                                modelMsg = jsonObject.modelMsg !== undefined? jsonObject.modelMsg : ""
                                isCleared = jsonObject.isCleared !== undefined? jsonObject.isCleared : false
                                documentName = jsonObject.documentName !== undefined? jsonObject.documentName : ""
                                documentSize = jsonObject.documentSize !== undefined? jsonObject.documentSize : ""
                                documentIcon = jsonObject.documentIcon !== undefined? jsonObject.documentIcon : ""
                                documentPath = jsonObject.documentPath !== undefined? jsonObject.documentPath : ""
                                isAddSchedule = jsonObject.isAddSchedule !== undefined? jsonObject.isAddSchedule : false
                                isGenerateToDo = jsonObject.isGenerateToDo !== undefined? jsonObject.isGenerateToDo : false
                                scheduleDate = jsonObject.scheduleDate !== undefined? jsonObject.scheduleDate: "";
                                noModelError = jsonObject.noModelError !== undefined? jsonObject.noModelError: "";
                                speechFlag = jsonObject.speechFlag !== undefined ? jsonObject.speechFlag: false;
                                isShowInfoSources = jsonObject.isShowInfoSources !== undefined ? jsonObject.isShowInfoSources: false;
                                infoSources = jsonObject.infoSources !== undefined ? jsonObject.infoSources: "";
                                pictureOperates = jsonObject.pictureOperates !== undefined ? jsonObject.pictureOperates: "";
                                isShowPictureOperateRefresh = jsonObject.isShowPictureOperateRefresh !== undefined ? jsonObject.isShowPictureOperateRefresh: true;
                                operatorId = jsonObject.operatorId !== undefined ? jsonObject.operatorId: 0;
                                isLike = jsonObject.isLike !== undefined? jsonObject.isLike : false;
                                isDislike = jsonObject.isDislike !== undefined? jsonObject.isDislike : false;
                                feedbackURL = jsonObject.feedbackURL !== undefined? jsonObject.feedbackURL : "";
                                closePopup = jsonObject.closePopup !== undefined? jsonObject.closePopup : false
                            };
                            var item = {"author":"Bot", "isEnd":false, "isRefreshed":false,
                                         "colorMsg":colorMsg, "drawMsg":drawMsg, "imageSrc":imageSrc,
                                         "imagePath":imagePath, "showImageOptions":false, "showRead":showRead,
                                         "msgHead":msgHead, "promptId":promptId, "message":"", "modelMsg":modelMsg,
                                         "isCleared":isCleared,"documentName":documentName,"documentSize":documentSize,
                                         "documentIcon":documentIcon,"documentPath":documentPath,"isAddSchedule":isAddSchedule,
                                         "isGenerateToDo":isGenerateToDo,"scheduleDate":scheduleDate,"pdfPath":pdfPath,"noModelError":noModelError,
                                         "isFirst":false,"speechFlag":speechFlag,"isShowInfoSources":isShowInfoSources,"infoSources":infoSources,
                                         "pictureOperates":pictureOperates,"isShowPictureOperateRefresh":isShowPictureOperateRefresh,
                                         "reasonMessage":lastMsg.reasonMessage,"operatorId":operatorId,
                                         "isLike":isLike,"isDislike":isDislike,"feedbackURL":feedbackURL,"closePopup":closePopup};
//                            lastMsg = item;
                            listModel.set(listModel.count - 1,item);
                        }else{
                            if(msgHeadList !== ''){
                                jsonObject = JSON.parse(msgHeadList);
                                colorMsg = jsonObject.colorMsg;
                                drawMsg = jsonObject.drawMsg;
                                msgHead = jsonObject.msgHead;
                                promptId = jsonObject.promptId;
                            };
                            listModel.set(listModel.count - 1, {"author":"Bot", "isEnd":false,
                                "isRefreshed":false, "colorMsg":colorMsg, "drawMsg":drawMsg,
                                "imageSrc":"", "imagePath":"", "showImageOptions":false,
                                "showRead":true, "msgHead":msgHead, "promptId":promptId, "message":"","reasonMessage":msg})
                        }
                        //listModel.set(listModel.count - 1, {"reasonMessage":msg})
                        //对话移动到最新的一次回答
                        if(listView.isChatEndFlag){
                            listView.positionViewAtEnd()
                        }
                    }

                    onAddMsg: function(msgHeadList, msg){
                        pushMsg("User",msgHeadList, msg);
                    }

                    onAddRecvMsg: function(msgHeadList, msg) {
                        pushMsg("Bot",msgHeadList, msg);
                    }

                    onReplyEnd: function(isEnd) {
                        console.log("onReplyEnd", isEnd);
                        var element = listModel.get(listModel.count - 1);
                        if(listModel.count === 0 || element.author === "User")
                            return;
                        element.isEnd = isEnd;
                        //element.colorMsg === "red" || element.noModelError === "true"
                        if(element.colorMsg === "red"){
                            //如果是异常消息，去除html标签和末尾的换行，解决历史记录第一条异常的问题
                            // 解析 JSON 字符串为 JavaScript 对象
                            var jsonObject = JSON.parse(JSON.stringify(element));
                            //去除html标签
                            jsonObject.message = jsonObject.message.replace(/<\/?.+?\/?>/g,'');
                            //去除最末尾的换行
                            jsonObject.message = jsonObject.message.replace(/\n$/, '')
                            msgPane.saveToDatabase(listModel.count - 1, JSON.stringify(jsonObject));
                        }else{
                            msgPane.saveToDatabase(listModel.count - 1, JSON.stringify(element));
                        }
                        isReplying = false;
                    }

                    onReplyingChanged: function(replying) {
                        isReplying = replying;
                    }

                    onInsertImage: function(base64EncodedImage, operatorId, imagePath) {
                        console.log("zzzzzzzzzzzzzzzz onInsetImage")
                        var lastElement = listModel.get(listModel.count - 1)
                        if(operatorId === 1){
                            lastElement.message = "好的，这是根据您的要求扫描完成的黑白件："
                        }else if(operatorId === 2){
                            lastElement.message = "好的，这是根据您的要求完成的智能抠图："
                        }else if(operatorId === 0){
                            lastElement.message = "好的，这是根据您的描述生成的图片。"
                        }

                        if(operatorId === 4){
                            lastElement.imageSrc = "qrc:/icon/icon/loading-fail.png"
                        }else{
                            lastElement.imageSrc = base64EncodedImage

                        }
                        lastElement.drawMsg = false
                        lastElement.operatorId = operatorId
                        lastElement.imagePath = imagePath
                        lastElement.isFirst = false
                        //对话移动到最新的一次回答
                        if(listView.isChatEndFlag){
                            listView.positionViewAtEnd()
                        }
                    }

                    //暫停文生圖
                    onSigCancelGenerateImage: function(){
                        var lastElement = listModel.get(listModel.count - 1)
                        lastElement.message = "文生图已暂停"
                        lastElement.drawMsg = false
                        lastElement.operatorId = 0
                        //对话移动到最新的一次回答
                        if(listView.isChatEndFlag){
                            listView.positionViewAtEnd()
                        }
                    }

                    // 图像处理生成的图片
                    onInsertOperateImage: function(base64EncodedImage, operatorId, imagePath) {
                        var lastElement = listModel.get(listModel.count - 1)
                        if(operatorId === 1){
                            lastElement.message = "好的，这是根据您的要求扫描完成的黑白件："
                        }else if(operatorId === 2){
                            lastElement.message = "好的，这是根据您的要求完成的智能抠图："
                        }else{
                            lastElement.message = "好的，这是为您生成的图片。"
                        }
                        lastElement.imageSrc = base64EncodedImage
                        lastElement.drawMsg = false
                        lastElement.operatorId = operatorId
                        lastElement.imagePath = imagePath
                        //对话移动到最新的一次回答
                        if(listView.isChatEndFlag){
                            listView.positionViewAtEnd()
                        }
                        msgPane.sigPictureAutoSpeak();
                    }
                    // 图像处理生成的图片重新回答不可用
                    onUpdateOperateRefresh: function(base64EncodedImage) {
                        var lastElement = listModel.get(listModel.count - 1)
                        lastElement.isShowPictureOperateRefresh = false
                    }

                    onLoadConversation: function(list)
                    {
                        //console.log("onLoadHistory");
                        listModel.clear();
                        for(var i = 0; i < list.length; ++i){
                            var item = JSON.parse(list[i]);
                            listModel.append(item);
                        }
                        //初始化历史记录将对话移动到最新的一次回答
                        for(i = 0; i < list.length + 10; ++i){
                            listView.positionViewAtEnd()
                        }
                    }

                    onSetReadEnd: function(readEndIndex) {
                        var element = listModel.get(readEndIndex)
                        listView.preIndex = readEndIndex;
                        listView.curIndex = -1;
                        if (!element.showRead) {
                            element.showRead = true;
                        }
                    }

                    onSendImage: function(imagePath, base64EncodedImage) {
                        if (listModel.count > 0) {
                            var lastMsg = listModel.get(listModel.count - 1)
                            lastMsg.isRefreshed = true;
                        }

                        var item = {"author":"User", "isEnd":false, "isRefreshed":false,
                            "colorMsg":"", "drawMsg":false, "imageSrc":base64EncodedImage,
                            "imagePath":imagePath, "showImageOptions":false, "showRead":true,
                            "msgHead":"", "promptId":-1, "message":""}
                        listModel.append(item);
                        msgPane.saveToDatabase(listModel.count - 1, JSON.stringify(item));
                        msgPane.onSendImage(imagePath);
                    }

                    onAddImagePreview: function(imagePath, base64EncodedImage){
                        //图像处理注释掉，取消缩略图，不确定后续

                        if (listModel.count > 0) {
                            var lastMsg = listModel.get(listModel.count - 1)
                            lastMsg.isRefreshed = true
                        }
                        var msgHeadList = {
                            imagePath: imagePath,
                            imageSrc: base64EncodedImage,
                        };
                        var jsonMsgHead = JSON.stringify(msgHeadList)
                        moveCommonTimer.running = true
                        var retJsonString = msgPane.onSendMsg(jsonMsgHead, "")
                        var retJsonObject = JSON.parse(retJsonString);
                        isReplying = retJsonObject['isReplying'] !== undefined ? retJsonObject['isReplying'] : false
                    }

                    onAddDocumentPreview: function(filePath, icon, fileName, fileSize){
                        inputRectange.documentPreviewPath = filePath
                        inputRectange.documentPreviewIcon = icon
                        inputRectange.documentPreviewName = fileName
                        inputRectange.documentPreviewSize = fileSize
                        root.focus = true
                        root.forceActiveFocus()
                        chat.focus = true
                        chat.forceActiveFocus()
                        messageField.focus = true
                        messageField.forceActiveFocus()
                    }

                    onSetReplyOptions:function(imagePath) {
                        console.log("onSetReplyOptions", imagePath)
                        if (listModel.count > 0) {
                            var lastMsg = listModel.get(listModel.count - 1)
                            lastMsg.imagePath = imagePath;
                            lastMsg.showImageOptions = true;
                        }
                    }

                    onContextCleared:function()
                    {
                        console.log("onContextCleared");

                        if (listModel.count === 0) {
                            return;
                        }

                        var lastMsg = listModel.get(listModel.count - 1);
                        lastMsg.message = msg;
                    }

                    // 实时更新系统用户名
                    onChangeCurrentUserName:function (currentUserName){
                        listView.userName = currentUserName;
                    }

                    // 实时更新系统用户头像
                    onChangeCurrentUserIcon:function (currentUserIcon){
                        listView.userAvatar = currentUserIcon;
                    }

                    //周报另存为PDF
                    onSaveToPDF:function (){
                        if (!isSupportHtml2Docx) {
                            msgPane.onReplyEnd(true);
                            return;
                        }

                        var lastMsg = listModel.get(listModel.count - 1);
                        msgPane.onSaveHTML2PDF(lastMsg.message);
                    }

                    //后端向前端返回生成PDF文件的路径
                    onAddReportPath:function (path){
                        var lastMsg = listModel.get(listModel.count - 1);
                        lastMsg.pdfPath = path;
                        msgPane.onReplyEnd(true);

                    }

                    onSaveLastMsgToDatabase:function (){
                        var item =listModel.get(listModel.count - 1);
                        msgPane.saveToDatabase(listModel.count - 1 , JSON.stringify(item));
                    }

                    //停止语音输入
                    onCancelSendAudio:function() {
                        if (isCapturingVideo){
                            countDownTimer.stop(); // 停止计时器
                            isCapturingVideo = false;
                            speechMode = 0;
                            msgPane.onSpeechModeChanged(speechMode);
                        }
                    }

                    onUpdateCurrentStartTimer:function() {
                            startTimer(); // 启动倒计时
                    }

                    //语音提问的问题，触发自动朗读
                    onTriggerAutoRead:function(msg) {
                        var index = listModel.count - 1;
                        var lastMsg = listModel.get(index);

                        lastMsg.showRead = false;
                        listView.curIndex = index;
                        var str = lastMsg.message.replace(/<\/?.+?\/?>/g,'');
                        msgPane.onStartRead(str, index);
                    }

                    onChangeWinModeToChat:function(winMode){
                        // 切换页面，关闭提示词显示
                        commandShowRet.visible = false
                        bottomAreaBackgroundRet.visible = false
                        chat.winMode = winMode
                        //console.log("winMode" + chat.winMode)
                        onChangeWinModeToChatTimer.running = true
                        inputRectangeGradient.stops[0].color = "#E85CFF" // 改变第一个颜色
                        inputRectangeGradient.stops[1].color = "#3790FA" // 改变第二个颜色
                    }

                    onClearListModel:function(){
                        console.log("chat qml clear list model");
                        isReplying = false;
                        listModel.clear();
                    }
                    // 发送新消息，将滚动条移动到最下面
                    onMoveScrollBar:function(){
                        listView.positionViewAtEnd()
                    }
                    // 接收系统助手返回信息
                    onAddRecvSources:function(jsonData){
                        if(jsonData !== ""){
                            var element = listModel.get(listModel.count - 1);
                            if(listModel.count === 0 || element.author === "User")
                                return;
                            element.isShowInfoSources = true
                            element.infoSources = jsonData
                            console.log("onAddRecvSources" +element.infoSources)
                            listModel.set(listModel.count - 1,element);
                        }
                    }
                    // 接收图像处理返回信息
                    onAppendRecvTool:function(jsonData){
                        if(jsonData !== ""){
                            var element = listModel.get(listModel.count - 1);
                            if(listModel.count === 0 || element.author === "User")
                                return;
                            element.showImageOptions = true
                            element.pictureOperates = jsonData
                            listModel.set(listModel.count - 1,element);
                        }
                    }
                    // 接受enter信号，用于解决文档图片上传之后获取不到焦点，无法使用enter键的问题
                    onKeyReturnPressed:function(){
                        //判断是否在文本对话页面
                        if(chat.visible === false){
                            return
                        }

                        //判断输入框内消息是否为空
                        if ((messageField.text.trim() === "" && inputRectange.imagePreviewSrc ==="" && inputRectange.documentPreviewName === "" ) || isReplying === true)
                        {
                            return;
                        }

                        //判断是否正在语音输入
                        if (isCapturingVideo){
                            voiceStopButtonMouseArea.stopVoiceInput();
                        }

                        if (listModel.count > 0) {
                            var lastMsg = listModel.get(listModel.count - 1)
                            lastMsg.isRefreshed = true
                        }
                        var msgHeadList = {
                            msgHead: inputRectange.activeCommand,
                            promptId: inputRectange.activeCommandID,
                            imagePath: inputRectange.imagePreviewPath,
                            imageSrc: inputRectange.imagePreviewSrc,
                            documentPath: inputRectange.documentPreviewPath,
                            documentIcon: inputRectange.documentPreviewIcon,
                            documentName: inputRectange.documentPreviewName,
                            documentSize: inputRectange.documentPreviewSize,
                        };
                        var jsonMsgHead = JSON.stringify(msgHeadList)
                        moveCommonTimer.running = true
                        var retJsonString = msgPane.onSendMsg(jsonMsgHead, messageField.text)
                        var retJsonObject = JSON.parse(retJsonString);
                        isReplying = retJsonObject['isReplying'] !== undefined ? retJsonObject['isReplying'] : false
                        messageField.text = "";
                        inputRectange.imagePreviewSrc = "";
                        inputRectange.imagePreviewPath = "";
                        inputRectange.documentPreviewPath = "";
                        inputRectange.documentPreviewIcon = "";
                        inputRectange.documentPreviewName = "";
                        inputRectange.documentPreviewSize = "";
                        inputRectange.activeCommandID = -1
                        inputRectange.activeCommand = ""
                        chat.tabViewString ="Command"
                        messageField.focus = false
                    }

                    //切换页面停止语音录入并停止朗读
                    onCancelVoiceStopReplying:function(){
                        msgPane.onCancelAudio();
                        if (chat.speechMode !== 0) {
                            isReplying = false;
                        }

                        if(listView.curIndex !== -1){
                            listModel.get(listView.curIndex).showRead = true;
                            listView.preIndex = listView.curIndex;
                            listView.curIndex = -1;
                        }

                        msgPane.onPauseRead();
                    }

                    //添加识别中间结果到文本输入框
                    onSigSendTmpMsgToQML:function(str){
                        messageField.text = originText + str;
                        messageField.cursorPosition = messageField.length;
                        // messageField.adjustScrollPosition(); // 语音输入文字改变后改变滚动条位置
                    }

                    //添加识别修正结果到文本输入框
                    onSigSendMsgToQML:function(str){
                        originText += str;
                        messageField.text = originText;
                        messageField.cursorPosition = messageField.length;
                        // messageField.adjustScrollPosition(); // 语音输入文字改变后改变滚动条位置
                    }

                    //重置preIndex值
                    onSigResetPreIndex:function(){
                        chat.handleInitReadingIndex();
                    }

                    // 更新回答状态
                    onStartReplyingToChat:function(isReplying){
                        chat.isReplying = isReplying
                    }

                    // 页面失去焦点，关闭弹窗
                    onSendFocusChanged:function(){
                        // 关闭输入框弹窗
                        rightClickMenuPopup.close()
                        // 关闭复制按钮，文生图操作等popup弹窗
                        for(var i = 0; i < listModel.count;i++){
                            listView.model.get(i).closePopup = !listView.model.get(i).closePopup
                        }
                    }
                }
            }
        }

        //底部区域 -- 文字
        Column {
            id: bottomArea
            Accessible.name: "kylin-aiassistant_Chat_bottomArea"
            //topPadding: 6
            bottomPadding: 16
            leftPadding:16
            rightPadding: 16
            Layout.fillWidth: true
            //height: tabViewString === "AllCommand" ? 280: 222
            height: tabViewString === "AllCommand" ? (bottomRetColumn.spacing + cueWordHeaderRet.height + commandFlickable.height + inputRectange.height + bottomArea.topPadding + bottomArea.bottomPadding + 11 + bottomAreaTopRet.height)
                                                   : (firstLineCommandFlow.height + inputRectange.height + bottomArea.topPadding + bottomArea.bottomPadding + 11 + bottomAreaTopRet.height)
            width: chat.width
            visible: true
            z: 3 // 确保在其他组件之上
            //用于做toppadding，并上色
            Rectangle{
                id: bottomAreaTopRet
                Accessible.name: "kylin-aiassistant_Chat_bottomAreaTopRet"
                width: bottomArea.width - bottomArea.leftPadding - bottomArea.rightPadding
                height: 6
                color: tabViewString === "AllCommand"? "#FFFFFF" : "#F5F5F5"
                MouseArea{
                    anchors.fill: parent
                    hoverEnabled: true
                }
            }

            Rectangle {
                id: bottomRet
                Accessible.name: "kylin-aiassistant_Chat_bottomRet"
                width: bottomArea.width - bottomAreaTopRet.height - bottomArea.rightPadding
                height: bottomArea.height - bottomAreaTopRet.height - bottomArea.bottomPadding
                color: tabViewString === "AllCommand"? "#FFFFFF" : "#F5F5F5"
                Column {
                    id: bottomRetColumn
                    spacing: 5
                    //指令标签--非滚动区域，只显示一行
                    Rectangle {
                        id: firstLineCommand;
                        Accessible.name: "kylin-aiassistant_Chat_firstLineCommand"
                        width: chat.width - 40;
                        height: firstLineCommandFlow.height
                        visible: tabViewString === "Command"
                        color: "transparent"
                        Row{
                            width: parent.width
                            height: firstLineCommandFlow.height
                            Flow {
                                id: firstLineCommandFlow
                                width: Math.min(firstLineCommandFlow.calculateVisibleWidth(chat.width - 40 - (moreRowRet.visible ? moreRowRet.width : 0)) , Math.min((firstLineCommandFlow.calculateTotalWidth() + (moreRowRet.visible ? moreRowRet.width : 0)), (chat.width - 40)));
                                height: 30  // 固定高度为一行的高度，30像素
                                clip: true  // 超出内容不会显示

                                spacing: 8
                                Repeater {
                                    id: firstLineCommandRepeater
                                    model: commandTemplateListModel;
                                    delegate: Rectangle {
                                        id: firstLineCommandRet
                                        Accessible.name: "kylin-aiassistant_Chat_firstLineCommandRet"
                                        width: commandRetRow.width;
                                        height: 30;
                                        //color: Qt.rgba(55/255, 144/255, 250/255, 0.1)
                                        radius: 4
                                        border.color: Qt.rgba(0/255, 0/255, 0/255, 0.1)
                                        border.width: 1
                                        ToolTip.visible: firstLineCommandMouseArea.containsMouse
                                        ToolTip.text: name
                                        ToolTip.delay: 500
                                        Row{
                                            id: commandRetRow
                                            Accessible.name: "kylin-aiassistant_Chat_commandRetRow"
                                            width: commandImageRet.width + firstLineCommandTextRow.width
                                            height: 30
                                            Rectangle{
                                                id: commandImageRet
                                                Accessible.name: "kylin-aiassistant_Chat_commandImageRet"
                                                width: 30
                                                color: "transparent"
                                                height: 30
                                                Image {
                                                    id: commandRowImage
                                                    Accessible.name: "kylin-aiassistant_Chat_commandRowImage"
                                                    source: iconPath
                                                    anchors.centerIn: parent
                                                    width: 12
                                                    height: 12
                                                }
                                            }
                                            Row {
                                                id: firstLineCommandTextRow
                                                Accessible.name: "kylin-aiassistant_Chat_firstLineCommandTextRow"
                                                width: firstLineCommandText.width + rightPadding
                                                height: 30
                                                rightPadding: 8
                                                Text {
                                                    id: firstLineCommandText;
                                                    Accessible.name: "kylin-aiassistant_Chat_firstLineCommandText"
                                                    text: name;
                                                    anchors.verticalCenter: parent.verticalCenter
                                                    //color: Qt.rgba(55/255, 144/255, 250/255);
                                                }
                                            }
                                        }
                                        MouseArea {
                                            id: firstLineCommandMouseArea
                                            anchors.fill: parent
                                            hoverEnabled: true
        //                                    visible: chat.tabViewString === "Command" ? true : false
                                            onEntered: {
                                                parent.color = "#F2F2F2"
                                            }
                                            onExited: {
                                                parent.color = "#FFFFFF"
                                            }
                                            onPressed: {
                                                parent.color = "#EEEEEE"
                                            }
                                            onReleased: {
                                                parent.color = "#FFFFFF"
                                            }
                                            onClicked: {
                                                inputRectange.activeCommandID = actorId
                                                inputRectange.activeCommand = name
                                                inputRectange.activeCommandContent = content.replace(/\n/g, "");
                                                //todo
                                                inputRectange.activeCommandIcon = iconPath

                                                // 监控选择指令的变化，点击标签发送消息 注释掉，点击标签不在打断回答
//                                                if(inputRectange.activeCommand !== "" && messageField.text.trim().length > 0){
//                                                    msgPane.onStopReply();
//                                                    //启动定时器，确保上一条消息停止回答后，发送下一条消息
//                                                    stopReplyTimer.running = true;
//                                                }
                                            }
                                        }
                                    }
                                }
                                // 计算 Repeater 中所有元素的宽度之和
                                function calculateTotalWidth() {
                                    var totalWidth = 0;
                                    for (var i = 0; i < firstLineCommandRepeater.count; i++) {
                                        var item = firstLineCommandRepeater.itemAt(i);
                                        totalWidth += item.width + 8   // 获取每个子项的宽度及其x偏移量
                                    }
                                    return totalWidth;
                                }
                                // 计算在固定宽度下已显示的元素宽度
                                function calculateVisibleWidth(fixedWidth) {
                                    var currentWidth = 0;

                                    // 遍历每个元素，直到超出固定宽度
                                    for (var i = 0; i < firstLineCommandRepeater.count; i++) {
                                        var item = firstLineCommandRepeater.itemAt(i);
                                        if (item) {
                                            // 累加当前元素的宽度
                                            if (currentWidth + item.width + 8 <= fixedWidth) {
                                                currentWidth += item.width + 8;
                                            } else {
                                                break;
                                            }
                                        }
                                    }
                                    return currentWidth;  // 返回已显示元素的总宽度
                                }
                            }
                            Rectangle{
                                id: moreRowRet
                                Accessible.name: "kylin-aiassistant_Chat_moreRowRet"
                                width: moreRow.width
                                height: 30
                                radius: 4
                                border.color: Qt.rgba(0/255, 0/255, 0/255, 0.1)
                                border.width: 1
                                ToolTip.visible: moreRowMouseArea.containsMouse
                                ToolTip.text: moreText.text
                                ToolTip.delay: 500
                                visible: commandTemplateListModel !== null && commandTemplateListModel.count() > 0 && (firstLineCommandFlow.calculateTotalWidth() >= chat.width - 40)
                                MouseArea {
                                    id: moreRowMouseArea
                                    anchors.fill: parent
                                    hoverEnabled: true
                                    onEntered: {
                                        moreRowRet.color = "#F2F2F2"
                                    }
                                    onExited: {
                                        moreRowRet.color = "#FFFFFF"
                                    }
                                    onPressed: {
                                        moreRowRet.color = "#EEEEEE"
                                    }
                                    onReleased: {
                                        moreRowRet.color = "#FFFFFF"
                                    }
                                    onClicked: {
                                        chat.tabViewString = (chat.tabViewString === "AllCommand")? "Command" : "AllCommand"
                                    }
                                }
                                Row{
                                    id: moreRow
                                    Accessible.name: "kylin-aiassistant_Chat_moreRow"
                                    width: moreTextRow.width + moreImageRet.width
                                    height: 30
                                    Rectangle{
                                        id: moreImageRet
                                        Accessible.name: "kylin-aiassistant_Chat_moreImageRet"
                                        width: 30
                                        color: "transparent"
                                        height: 30
                                        Image {
                                            id: moreRowImage
                                            Accessible.name: "kylin-aiassistant_Chat_moreRowImage"
                                            source: "qrc:/icon/icon/more_icon.svg"
                                            anchors.centerIn: parent
                                            width: 12
                                            height: 12
                                        }
                                    }
                                    Row{
                                        id: moreTextRow
                                        Accessible.name: "kylin-aiassistant_Chat_moreTextRow"
                                        width: moreText.width + rightPadding
                                        rightPadding: 8
                                        height: 30
                                        Text {
                                            id: moreText
                                            Accessible.name: "kylin-aiassistant_Chat_moreText"
                                            //width:moreRow.width - moreRowImage.width
                                            text: qsTr("More")
                                            anchors.verticalCenter: parent.verticalCenter
                                        }
                                    }
                                }
                            }
                        }
                    }

                    Rectangle {
                        id: cueWordHeaderRet
                        Accessible.name: "kylin-aiassistant_Chat_cueWordHeaderRet"
                        width: chat.width - 40;
                        height: 32
                        visible: tabViewString === "AllCommand"
                        color: "transparent"
                        MouseArea {
                            anchors.fill: parent
                            hoverEnabled: true
                        }
                        Row{
                            id: cueWordHeaderRow
                            Accessible.name: "kylin-aiassistant_Chat_cueWordHeaderRow"
                            anchors.centerIn: parent
                            leftPadding: 18
                            width: parent.width
                            height: parent.height
                            Rectangle{
                                width: cueWordHeaderText.width
                                height: parent.height
                                color: "transparent"
                                Text {
                                    id: cueWordHeaderText;
                                    Accessible.name: "kylin-aiassistant_Chat_cueWordHeaderText"
                                    width: cueWordHeaderRet.width - cueWordHeaderCloseButtonRet.width - cueWordHeaderRow.leftPadding
                                    text: qsTr("Recommended prompt words")
                                    color: Qt.rgba(0/255, 0/255, 0/255, 0.6)
                                    anchors.verticalCenter: parent.verticalCenter // 只垂直居中
                                    anchors.left: parent.left // 水平左对齐
                                }
                            }
                            Rectangle{
                                id: cueWordHeaderCloseButtonRet
                                Accessible.name: "kylin-aiassistant_Chat_cueWordHeaderCloseButtonRet"
                                width: 32
                                height: 32
                                color: "transparent"
                                radius: 4
                                ToolTip.visible: cueWordHeaderCloseButtonRetMouseArea.containsMouse
                                ToolTip.text: qsTr("Close")
                                ToolTip.delay: 500
                                Image {
                                    id: cueWordHeaderCloseButtonImage
                                    anchors.centerIn: parent
                                    source: "qrc:/icon/icon/close-black.svg"
                                }
                                MouseArea {
                                    id: cueWordHeaderCloseButtonRetMouseArea
                                    anchors.fill: parent
                                    hoverEnabled: true
                                    onEntered: {
                                        cueWordHeaderCloseButtonRet.color = "#26000000";
                                    }
                                    onExited: {
                                        cueWordHeaderCloseButtonRet.color = "transparent";
                                    }
                                    onPressed: {
                                        cueWordHeaderCloseButtonRet.color = "#33000000";
                                    }
                                    onReleased: {
                                        cueWordHeaderCloseButtonRet.color = "transparent";
                                    }
                                    onClicked: {
                                        tabViewString = "Command"
                                    }
                                }
                            }
                        }
                    }

                    //指令标签--滚动区域
                    Flickable {
                        id: commandFlickable
                        width: chat.width - 40;
                        height: Math.min(flowLayout.implicitHeight, (chat.winMode === 2 ? 8 : 5) * 44 + (chat.winMode === 2 ? 7 : 4) * 4)  // 最多显示 8 或 5 行
                        clip: true  // 保证超出内容不显示
                        // 限制 Flow 的高度为最多五行
                        contentHeight: flowLayout.implicitHeight
                        boundsBehavior: Flickable.StopAtBounds  // 防止过度滚动
                        visible: tabViewString === "AllCommand"
                        // 自定义垂直滚动条
                        ScrollBar.vertical: ScrollBar {
                            policy: ScrollBar.AlwaysOff  // 仅在需要时显示
                        }
                        property bool isCommandContentOverflowing: false

                        onContentHeightChanged: {
                            // 判断内容是否超出容器高度，超出显示滚动条
                            isCommandContentOverflowing = contentHeight > height
                            if(isCommandContentOverflowing){
                                commandFlickable.ScrollBar.vertical.policy = ScrollBar.AlwaysOn
                            }else{
                                commandFlickable.ScrollBar.vertical.policy = ScrollBar.AlwaysOff
                            }
                        }
                        //指令标签--所有
                        Flow {
                            id: flowLayout
                            width: chat.width - 40
                            height: 100
                            visible: tabViewString === "AllCommand"
                            spacing: 4
                            Repeater {
                                model: commandTemplateListModel
                                delegate: Rectangle {
                                    id: commandTemplateListModelRet
                                    Accessible.name: "kylin-aiassistant_Chat_commandTemplateListModelRet"
                                    width: chat.width - 40 - 12
                                    height: 44
                                    color: "transparent"//Qt.rgba(55/255, 144/255, 250/255, 0.1)
                                    radius: 4
                                    MouseArea {
                                        id: commandTemplateListModelMouseArea
                                        anchors.fill: parent
                                        hoverEnabled: true
                                        visible: chat.tabViewString === "AllCommand" ? true : false
                                        onEntered: {
                                            commandTemplateListModelRet.color = Qt.rgba(0/255, 0/255, 0/255, 0.08);
                                        }
                                        onExited: {
                                            commandTemplateListModelRet.color = "transparent";
                                        }
                                        onPressed: {
                                            commandTemplateListModelRet.color = Qt.rgba(0/255, 0/255, 0/255, 0.15);
                                        }
                                        onReleased: {
                                            commandTemplateListModelRet.color = "transparent";
                                        }
                                        onClicked: {
                                            if (isCapturingVideo){
                                                voiceStopButtonMouseArea.stopVoiceInput();
                                            }
                                            inputRectange.activeCommandID = actorId
                                            inputRectange.activeCommand = name
                                            inputRectange.activeCommandContent = content.replace(/\n/g, "")
                                            //todo
                                            inputRectange.activeCommandIcon = iconPath
                                            // 监控选择指令的变化，点击标签发送消息 注释掉，点击标签不在打断回答
//                                            if(inputRectange.activeCommand !== "" && messageField.text.trim().length > 0){
//                                                msgPane.onStopReply();
//                                                //启动定时器，确保上一条消息停止回答后，发送下一条消息
//                                                stopReplyTimer.running = true;
//                                            }
                                        }
                                    }
                                    Row {
                                        id: commandTemplateListModelRow
                                        Accessible.name: "kylin-aiassistant_Chat_commandTemplateListModelRow"
                                        width: commandTemplateListModelRet.width
                                        height: commandTemplateListModelRet.height
                                        //anchors.centerIn: parent
                                        Rectangle {
                                            id: commandTemplateImageRet
                                            Accessible.name: "kylin-aiassistant_Chat_commandTemplateImageRet"
                                            width: commandTemplateImageRowLayout.width
                                            height: commandTemplateListModelRet.height
                                            radius: 4
                                            color: "transparent"
                                            RowLayout {
                                                id: commandTemplateImageRowLayout
                                                Accessible.name: "kylin-aiassistant_Chat_commandTemplateImageRowLayout"
                                                width: commandTemplateListModelRet.height
                                                anchors.centerIn: parent
                                                Image {
                                                    id: commandTemplateImage
                                                    Accessible.name: "kylin-aiassistant_Chat_commandTemplateImage"
                                                    Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
                                                    // todo
                                                    source: iconPath
                                                }
                                            }
                                        }
                                        //指令标签区域
                                        Rectangle {
                                            id: commandTemplateNameRet
                                            Accessible.name: "kylin-aiassistant_Chat_commandTemplateNameRet"
                                            width: commandTemplateNameRow.width
                                            height: 44
                                            color: "transparent"
                                            //visible: inputRectange.activeCommand !== ""
                                            Row {
                                                id: commandTemplateNameRow
                                                Accessible.name: "kylin-aiassistant_Chat_commandTemplateNameRow"
                                                rightPadding: 8
                                                anchors.centerIn: parent
                                                Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
                                                Text {
                                                    id: commandTemplateNameText
                                                    Accessible.name: "kylin-aiassistant_Chat_commandTemplateNameText"
                                                    text: name
                                                    //color: Qt.rgba(55/255, 144/255, 250/255)
                                                }
                                            }
                                        }
                                        //指令标签描述区域
                                        Rectangle {
                                            id: commandTemplateContentRet
                                            Accessible.name: "kylin-aiassistant_Chat_commandTemplateContentRet"
                                            width: commandTemplateRow.width
                                            height: 44
                                            color: "transparent"
                                            //visible: inputRectange.activeCommand !== ""
                                            Row {
                                                id: commandTemplateRow
                                                Accessible.name: "kylin-aiassistant_Chat_commandTemplateRow"
                                                width: commandTemplateListModelRow.width - commandTemplateImageRet.width - commandTemplateNameRet.width
                                                rightPadding: 8
                                                anchors.centerIn: parent
                                                Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
                                                Text {
                                                    id: commandTemplateContent
                                                    width: parent.width
                                                    text: (model.commandType === 3) ? qsTr("The prompt word is not visible") : replaceString(content)
                                                    elide: Text.ElideRight
                                                    color: Qt.rgba(0/255, 0/255, 0/255, 0.6)
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    Rectangle {
                        id: inputRectangeMainRect
                        Accessible.name: "kylin-aiassistant_Chat_inputRectangeMainRect"
                        width: bottomArea.width - bottomArea.leftPadding - bottomArea.rightPadding
                        height: inputRectangeColumnLayout.height + inputRectange.border.width * 2 + 6 - 4
                        Layout.alignment: Qt.AlignBottom
                        radius: 6
                        // 外层用于显示边框
                        Rectangle {
                            id: inputBorderRectange
                            Accessible.name: "kylin-aiassistant_Chat_inputBorderRectange"
                            anchors.fill: parent
                            border.width: 2
                            border.color: "transparent"
                            radius: 6
                            gradient: Gradient {
                                id: inputRectangeGradient
                                orientation: Gradient.Horizontal
                                GradientStop { position: 0.0; color: "#E85CFF"}
                                GradientStop { position: 1.0; color:  "#3790FA"}
                            }

                            // 内层白色矩形，用于覆盖内部，只显示边框
                            Rectangle {
                                id: inputRectange
                                Accessible.name: "kylin-aiassistant_Chat_inputRectange"
                                anchors.fill: parent
                                width: bottomArea.width - bottomArea.leftPadding - bottomArea.rightPadding - 4
                                height: inputRectangeColumnLayout.height + inputRectange.border.width * 2 + 6 - 4
                                color: "#FFFFFF"
                                visible: listView.dialogType === "Text"
                                radius: 6
                                anchors.margins: 2


                                property int activeCommandID: -1
                                property string activeCommand: ""
                                property string activeCommandContent: ""
                                property string activeCommandIcon: ""
                                property string imagePreviewPath: ""
                                property string imagePreviewSrc: ""
                                property string documentPreviewPath:""
                                property string documentPreviewIcon: ""
                                property string documentPreviewName: ""
                                property string documentPreviewSize: ""

                                Column {
                                    id: inputRectangeColumnLayout
                                    width:parent.width - inputRectange.border.width * 2 + 2
                                    spacing: 0
                                    anchors.horizontalCenter: parent.horizontalCenter
                                    anchors.verticalCenter: parent.verticalCenter
                                    bottomPadding: 2
                                    // 这里设置ColumnLayout的具体内容
                                    //Layout.fillWidth: true // 让ColumnLayout的宽度填满可用空间
                                    Rectangle{
                                        id: messageFieldRet
                                        Accessible.name: "kylin-aiassistant_Chat_messageFieldRet"
                                        width: parent.width
                                        radius: 6
                                        height: 72
//                                        height:{
//                                            if(chat.winMode === 2 ){
//                                                return 110 //- commandInputRectangle.visible ? 0 : 28
//                                            }else{
//                                                return 72 //- commandInputRectangle.visible ? 0 : 28
//                                            }
//                                        }
                                        Column{
                                            id: messageFieldColumn
                                            Accessible.name: "kylin-aiassistant_Chat_messageFieldColumn"
                                            //topPadding: 8
                                            //leftPadding: 8
                                            rightPadding: 8

                                            //输入框内的指令标签区域
                                            Rectangle {
                                                id: commandInputRectangle
                                                Accessible.name: "kylin-aiassistant_Chat_commandInputRectangle"
                                                height: 34
                                                width: messageFieldRet.width
                                                //color: Qt.rgba(55/255, 144/255, 250/255, 0.05)
                                                radius: 6
                                                color: "transparent"
                                                visible: inputRectange.activeCommand !== ""
                                                property bool isContentOverflowing: false
                                                onVisibleChanged: {
                                                    if(messageField.text.length === 0){
                                                        if(commandInputRectangle.visible){
                                                            messageFieldRet.height = 72
                                                        }else{
                                                            messageFieldRet.height = 72 - 34
                                                        }
                                                    }else{
                                                        isContentOverflowing = messageField.contentHeight > textAreaScrollView.height
                                                        if(isContentOverflowing){
//                                                                if(chat.winMode === 2 ){
//                                                                    messageField.height = messageField.implicitHeight
//                                                                    textAreaScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOn
//                                                                }else{
                                                                if(messageField.contentHeight >= 110){
                                                                    messageFieldRet.height = 150 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                                    textAreaScrollView.height = 116
                                                                    messageField.height = messageField.implicitHeight
                                                                    textAreaScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOn
                                                                }else if(messageField.contentHeight > 90 && messageField.contentHeight < 110){
                                                                    messageFieldRet.height = 150 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                                    textAreaScrollView.height = 116
                                                                    messageField.height = 116
                                                                }else if(messageField.contentHeight > 67 && messageField.contentHeight < 90 ){
                                                                    messageFieldRet.height = 130 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                                    textAreaScrollView.height = 96
                                                                    messageField.height = 96
                                                                }else if(messageField.contentHeight > 50 && messageField.contentHeight < 67){
                                                                    messageFieldRet.height = 110 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                                    textAreaScrollView.height = 76
                                                                    messageField.height = 76
                                                                }else if(messageField.contentHeight > 30){
                                                                    messageFieldRet.height = 92 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                                    textAreaScrollView.height = 56
                                                                    messageField.height = 56
                                                                }
                                                            //}
                                                        }else{
//                                                                var winHeight = 0
//                                                                if(chat.winMode === 2 ){
//                                                                    winHeight = 76
//                                                                    messageField.height = winHeight
//                                                                    textAreaScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOff
//                                                                }else{
                                                            if(messageField.contentHeight >= 110){
                                                                messageFieldRet.height = 150 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                                textAreaScrollView.height = 116
                                                                messageField.height = messageField.implicitHeight
                                                                textAreaScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOn
                                                            }else if(messageField.contentHeight > 90 && messageField.contentHeight < 110){
                                                                messageFieldRet.height = 150 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                                textAreaScrollView.height = 116
                                                                messageField.height = 116
                                                                textAreaScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOff
                                                            }else if(messageField.contentHeight > 67 && messageField.contentHeight < 90 ){
                                                                messageFieldRet.height = 130 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                                textAreaScrollView.height = 96
                                                                messageField.height = 96
                                                                textAreaScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOff
                                                            }else if(messageField.contentHeight > 50 && messageField.contentHeight < 67){
                                                                messageFieldRet.height = 110 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                                textAreaScrollView.height = 76
                                                                messageField.height = 76
                                                                textAreaScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOff
                                                            }else if(messageField.contentHeight > 30){
                                                                messageFieldRet.height = 92 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                                textAreaScrollView.height = 56
                                                                messageField.height = 56
                                                                textAreaScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOff
                                                            }else{
                                                                messageFieldRet.height = (72 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height))
                                                                textAreaScrollView.height = 50
                                                                messageField.height = 50
                                                                textAreaScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOff
                                                            }
                                                            //}
                                                            //textAreaScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOff
                                                        }

                                                    }
                                                }
                                                Row {
                                                    id: commandInputRow
                                                    Accessible.name: "kylin-aiassistant_Chat_commandInputRow"
                                                    anchors.fill: parent
                                                    //leftPadding: 1
                                                    //rightPadding: 1
                                                    Rectangle{
                                                        id: allCommandOpenButton
                                                        Accessible.name: "kylin-aiassistant_Chat_allCommandOpenButton"
                                                        width: allCommandButtonRow.width
                                                        height: 34
                                                        radius: 6
                                                        visible: inputRectange.activeCommand !== ""
                                                        color: "#0d262626"
                                                        Row{
                                                            id:allCommandButtonRow
                                                            Accessible.name: "kylin-aiassistant_Chat_allCommandButtonRow"
                                                            Rectangle {
                                                                id: allCommandButtonImageShowRet
                                                                Accessible.name: "kylin-aiassistant_Chat_allCommandButtonImageShowRet"
                                                                width: allCommandButtonImageShowRowLayout.width
                                                                height: 34
                                                                radius: 4
                                                                color: "transparent"
                                                                RowLayout {
                                                                    id: allCommandButtonImageShowRowLayout
                                                                    width: 34
                                                                    anchors.centerIn: parent
                                                                    Image {
                                                                        id: allCommandButtonImageShow
                                                                        Accessible.name: "kylin-aiassistant_Chat_allCommandButtonImageShow"
                                                                        Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
                                                                        source: inputRectange.activeCommandIcon
                                                                    }
                                                                }
                                                                MouseArea{
                                                                    id: allCommandButtonImageShowRetMouseArea
                                                                    anchors.fill: parent
                                                                    hoverEnabled: true
                                                                    onEntered: {
                                                                        allCommandOpenButton.color = "#26000000";
                                                                    }
                                                                    onExited: {
                                                                        allCommandOpenButton.color = "#0d262626";
                                                                    }
                                                                    onPressed: {
                                                                        allCommandOpenButton.color = "#33000000";
                                                                    }
                                                                    onReleased: {
                                                                        allCommandOpenButton.color = "#0d262626";
                                                                    }
                                                                    onClicked: {
                                                                    }
                                                                }
                                                            }
                                                            //指令标签区域
                                                            Rectangle {
                                                                id: textExpansionCommandRet
                                                                Accessible.name: "kylin-aiassistant_Chat_textExpansionCommandRet"
                                                                width: textExpansionCommandRow.width
                                                                height: 34
                                                                color: "transparent"
                                                                //visible: inputRectange.activeCommand !== ""
                                                                Row {
                                                                    id:textExpansionCommandRow
                                                                    Accessible.name: "kylin-aiassistant_Chat_textExpansionCommandRow"
                                                                    rightPadding: 8
                                                                    anchors.centerIn: parent
                                                                    Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
                                                                    Text {
                                                                        id: textExpansionCommand
                                                                        Accessible.name: "kylin-aiassistant_Chat_textExpansionCommand"
                                                                        text: inputRectange.activeCommand
                                                                        //color: Qt.rgba(55/255, 144/255, 250/255)
                                                                    }
                                                                }
                                                                MouseArea{
                                                                    id: textExpansionCommandRetMouseArea
                                                                    Accessible.name: "kylin-aiassistant_Chat_textExpansionCommandRetMouseArea"
                                                                    anchors.fill: parent
                                                                    hoverEnabled: true
                                                                    onEntered: {
                                                                        allCommandOpenButton.color = "#26000000";
                                                                    }
                                                                    onExited: {
                                                                        allCommandOpenButton.color = "#0d262626";
                                                                    }
                                                                    onPressed: {
                                                                        allCommandOpenButton.color = "#33000000";
                                                                    }
                                                                    onReleased: {
                                                                        allCommandOpenButton.color = "#0d262626";
                                                                    }
                                                                    onClicked: {
                                                                    }
                                                                }
                                                            }
                                                            //指令标签描述区域
                                                            Rectangle {
                                                                id: textCommandContentRet
                                                                Accessible.name: "kylin-aiassistant_Chat_textCommandContentRet"
                                                                width: textCommandContentRetRow.width
                                                                height: 34
                                                                color: "transparent"
                                                                //visible: inputRectange.activeCommand !== ""
                                                                // 文档名称可展示最大宽度
                                                                property int textCommandContentRetMaxWidth: commandInputRectangle.width - commandInputRow.leftPadding - commandInputRow.rightPadding
                                                                    - allCommandButtonImageShowRet.width - textExpansionCommandRet.width
                                                                    - closeCommandButton.width
                                                                Row {
                                                                    id:textCommandContentRetRow
                                                                    Accessible.name: "kylin-aiassistant_Chat_textCommandContentRetRow"
                                                                    width: Math.min(textCommandContent.implicitWidth, textCommandContentRet.textCommandContentRetMaxWidth)
                                                                    rightPadding: 8
                                                                    anchors.centerIn: parent
                                                                    Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
                                                                    Text {
                                                                        id: textCommandContent
                                                                        Accessible.name: "kylin-aiassistant_Chat_textCommandContent"
                                                                        width: parent.width
                                                                        text: ""
                                                                        textFormat:Text.PlainText
                                                                        elide: Text.ElideRight
                                                                        color: Qt.rgba(0/255, 0/255, 0/255, 0.6)
                                                                    }
                                                                }
                                                                MouseArea{
                                                                    id: textCommandContentRetMouseArea
                                                                    anchors.fill: parent
                                                                    hoverEnabled: true
                                                                    onEntered: {
                                                                        allCommandOpenButton.color = "#26000000";
                                                                    }
                                                                    onExited: {
                                                                        allCommandOpenButton.color = "#0d262626";
                                                                    }
                                                                    onPressed: {
                                                                        allCommandOpenButton.color = "#33000000";
                                                                    }
                                                                    onReleased: {
                                                                        allCommandOpenButton.color = "#0d262626";
                                                                    }
                                                                    onClicked: {
                                                                    }
                                                                }
                                                            }
                                                            Rectangle{
                                                                id: commandPositionRet
                                                                Accessible.name: "kylin-aiassistant_Chat_commandPositionRet"
                                                                property int commandPositionRetMaxWidth: commandInputRectangle.width - commandInputRow.leftPadding - commandInputRow.rightPadding
                                                                    - allCommandButtonImageShowRet.width - textExpansionCommandRet.width - textCommandContentRet.width
                                                                    - closeCommandButton.width
                                                                width: commandPositionRetMaxWidth === 0 ? 0 : commandPositionRetMaxWidth
                                                                height: 34
                                                                color: "transparent"
                                                                visible: commandPositionRetMaxWidth === 0 ? false : true
                                                                radius: 6
                                                                MouseArea {
                                                                    id: commandPositionRetMouseArea
                                                                    Accessible.name: "kylin-aiassistant_Chat_commandPositionRetMouseArea"
                                                                    anchors.fill: parent
                                                                    hoverEnabled: true
                                                                    onEntered: {
                                                                        allCommandOpenButton.color = "#26000000";
                                                                    }
                                                                    onExited: {
                                                                        allCommandOpenButton.color = "#0d262626";
                                                                    }
                                                                    onPressed: {
                                                                        allCommandOpenButton.color = "#33000000";
                                                                    }
                                                                    onReleased: {
                                                                        allCommandOpenButton.color = "#0d262626";
                                                                    }
                                                                }
                                                            }

                                                            //指令标签关闭按钮区域
                                                            Rectangle {
                                                                id: closeCommandButton
                                                                Accessible.name: "kylin-aiassistant_Chat_closeCommandButton"
                                                                width: 28
                                                                height: 34
                                                                color: "transparent"
                                                                radius: 4
                                                                //visible: inputRectange.activeCommand !== ""
                                                                RowLayout {
                                                                    anchors.centerIn: parent
                                                                    Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
                                                                    Image {
                                                                        id: closeCommandButtonImage
                                                                        Accessible.name: "kylin-aiassistant_Chat_closeCommandButtonImage"
                                                                        Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
                                                                        source: "qrc:/icon/icon/close-black.svg"
                                                                    }
                                                                }
                                                                MouseArea {
                                                                    id: closeCommandButtonMouseArea
                                                                    Accessible.name: "kylin-aiassistant_Chat_closeCommandButtonMouseArea"
                                                                    anchors.fill: parent
                                                                    hoverEnabled: true
                                                                    onEntered: {
                                                                        allCommandOpenButton.color = "#26000000";
                                                                    }
                                                                    onExited: {
                                                                        allCommandOpenButton.color = "#0d262626";
                                                                    }
                                                                    onPressed: {
                                                                        allCommandOpenButton.color = "#33000000";
                                                                    }
                                                                    onReleased: {
                                                                        allCommandOpenButton.color = "#0d262626";
                                                                    }
                                                                    onClicked: {
                                                                        inputRectange.activeCommandID = -1
                                                                        inputRectange.activeCommand = ""
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }

                                            //文字编辑区
                                            Rectangle{
                                                id: textAreaScrollViewRet
                                                Accessible.name: "kylin-aiassistant_Chat_textAreaScrollViewRet"
                                                width: textAreaScrollView.width -10
                                                height: textAreaScrollView.height
                                                z: 1  // 确保该控件在前面
                                                radius: 6
                                                // 用于显示鼠标右键菜单
                                                MouseArea{
                                                    anchors.fill: parent
                                                    acceptedButtons: Qt.RightButton
                                                    hoverEnabled: true
                                                    enabled: true
                                                    z: 2 // 确保该控件在前面
                                                    cursorShape:Qt.IBeamCursor
                                                    propagateComposedEvents: true  // 确保事件传递
                                                    onPressed: {
                                                        if (mouse.button === Qt.RightButton) {
                                                            //messageField.forceActiveFocus();
                                                            var popX = 0 // 弹窗x坐标
                                                            popX = mouse.x - 5// 设置菜单的显示位置
                                                            if(chat.width - popX <= (142)){
                                                                popX = chat.width - 143
                                                            }
                                                            rightClickMenuPopup.x = popX
                                                            rightClickMenuPopup.y = mouseY - 130
                                                            rightClickMenuPopup.open();
                                                        }
                                                    }
                                                    Popup{
                                                        id: rightClickMenuPopup
                                                        Accessible.name: "kylin-aiassistant_Chat_rightClickMenuPopup"
                                                        width: rightClickMenuColumn.width
                                                        height: rightClickMenuColumn.height
                                                        property bool moveFlag: true
                                                        modal: true
                                                        closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
                                                        MouseArea{
                                                            anchors.fill: parent
                                                            hoverEnabled: true
//                                                            onEntered: {
//                                                                rightClickMenuPopupTimer.running = false
//                                                                rightClickMenuPopup.moveFlag = true
//                                                            }
//                                                            onExited: {
//                                                                if(rightClickMenuPopup.moveFlag){
//                                                                    rightClickMenuPopupTimer.running = true
//                                                                    rightClickMenuPopup.moveFlag = false
//                                                                }
//                                                            }
                                                            Column {
                                                                id: rightClickMenuColumn
                                                                Accessible.name: "kylin-aiassistant_Chat_rightClickMenuColumn"
                                                                anchors.centerIn: parent
                                                                padding: 4
                                                                Rectangle {
                                                                    id: ctrlXRet
                                                                    Accessible.name: "kylin-aiassistant_Chat_ctrlXRet"
                                                                    width: 116
                                                                    height: 36
                                                                    radius: 4
                                                                    RowLayout {
                                                                        anchors.centerIn: parent
                                                                        Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
                                                                        Text {
                                                                            id: ctrlXText
                                                                            Accessible.name: "kylin-aiassistant_Chat_ctrlXText"
                                                                            text: qsTr("Cut")
                                                                            color: "black"
                                                                            font.pixelSize: 14
                                                                        }
                                                                    }
                                                                    MouseArea {
                                                                        id: ctrlXRetMouseArea
                                                                        Accessible.name: "kylin-aiassistant_Chat_ctrlXRetMouseArea"
                                                                        anchors.fill: parent
                                                                        propagateComposedEvents: true
                                                                        hoverEnabled: true  // 允许悬浮事件
                                                                        enabled: messageField.selectedText.length > 0
                                                                        onEntered: {
                                                                            ctrlXText.color = "#FFFFFF"
                                                                            ctrlXRet.color = "#3790FA"
                                                                        }
                                                                        onExited: {
                                                                            ctrlXText.color = "#000000"
                                                                            ctrlXRet.color = "#FFFFFF"
                                                                        }
                                                                        onPressed: {
                                                                            ctrlXText.color = "#FFFFFF"
                                                                            ctrlXRet.color = "#3790FA"
                                                                        }
                                                                        onReleased: {
                                                                            ctrlXText.color = "#000000"
                                                                            ctrlXRet.color = "#FFFFFF"
                                                                        }
                                                                        onClicked: {
                                                                            if (messageField.selectedText.length > 0) {
                                                                                messageField.cut(); // 如果有选中的文本，执行剪切
                                                                            } else {
                                                                                console.log("没有选中的文本，无法剪切");
                                                                            }
                                                                            rightClickMenuPopup.close()
                                                                        }
                                                                    }
                                                                }
                                                                Rectangle {
                                                                    id: ctrlCRet
                                                                    Accessible.name: "kylin-aiassistant_Chat_ctrlCRet"
                                                                    width: 116
                                                                    height: 36
                                                                    radius: 4
                                                                    RowLayout {
                                                                        anchors.centerIn: parent
                                                                        Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
                                                                        Text {
                                                                            id: ctrlCText
                                                                            Accessible.name: "kylin-aiassistant_Chat_ctrlCText"
                                                                            text: qsTr("Copy")
                                                                            color: "black"
                                                                            font.pixelSize: 14
                                                                        }
                                                                    }
                                                                    MouseArea {
                                                                        id: ctrlCRetMouseArea
                                                                        Accessible.name: "kylin-aiassistant_Chat_ctrlCRetMouseArea"
                                                                        anchors.fill: parent
                                                                        propagateComposedEvents: true
                                                                        hoverEnabled: true  // 允许悬浮事件
                                                                        enabled: messageField.selectedText.length > 0
                                                                        onEntered: {
                                                                            ctrlCText.color = "#FFFFFF"
                                                                            ctrlCRet.color = "#3790FA"
                                                                        }
                                                                        onExited: {
                                                                            ctrlCText.color = "#000000"
                                                                            ctrlCRet.color = "#FFFFFF"
                                                                        }
                                                                        onPressed: {
                                                                            ctrlCText.color = "#FFFFFF"
                                                                            ctrlCRet.color = "#3790FA"
                                                                        }
                                                                        onReleased: {
                                                                            ctrlCText.color = "#000000"
                                                                            ctrlCRet.color = "#FFFFFF"
                                                                        }
                                                                        onClicked: {
                                                                            if (messageField.selectedText.length > 0) {
                                                                                messageField.copy();
                                                                            } else {
                                                                                console.log("没有选中的文本，无法复制");
                                                                            }
                                                                            rightClickMenuPopup.close()
                                                                        }
                                                                    }
                                                                }
                                                                Rectangle {
                                                                    id: ctrlVRet
                                                                    Accessible.name: "kylin-aiassistant_Chat_ctrlVRet"
                                                                    width: 116
                                                                    height: 36
                                                                    radius: 4
                                                                    RowLayout {
                                                                        anchors.centerIn: parent
                                                                        Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
                                                                        Text {
                                                                            id: ctrlVText
                                                                            Accessible.name: "kylin-aiassistant_Chat_ctrlVText"
                                                                            text: qsTr("Paste")
                                                                            color: "black"
                                                                            font.pixelSize: 14
                                                                        }
                                                                    }
                                                                    MouseArea {
                                                                        id: ctrlVRetMouseArea
                                                                        Accessible.name: "kylin-aiassistant_Chat_ctrlVRetMouseArea"
                                                                        anchors.fill: parent
                                                                        propagateComposedEvents: true
                                                                        hoverEnabled: true  // 允许悬浮事件
                                                                        onEntered: {
                                                                            ctrlVText.color = "#FFFFFF"
                                                                            ctrlVRet.color = "#3790FA"
                                                                        }
                                                                        onExited: {
                                                                            ctrlVText.color = "#000000"
                                                                            ctrlVRet.color = "#FFFFFF"
                                                                        }
                                                                        onPressed: {
                                                                            ctrlVText.color = "#FFFFFF"
                                                                            ctrlVRet.color = "#3790FA"
                                                                        }
                                                                        onReleased: {
                                                                            ctrlVText.color = "#000000"
                                                                            ctrlVRet.color = "#FFFFFF"
                                                                        }
                                                                        onClicked: {
                                                                            messageField.paste()
                                                                            rightClickMenuPopup.close()
                                                                        }
                                                                    }
                                                                }
                                                                Rectangle {
                                                                    id: deleteRet
                                                                    Accessible.name: "kylin-aiassistant_Chat_deleteRet"
                                                                    width: 116
                                                                    height: 36
                                                                    radius: 4
                                                                    RowLayout {
                                                                        anchors.centerIn: parent
                                                                        Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
                                                                        Text {
                                                                            id: deleteText
                                                                            Accessible.name: "kylin-aiassistant_Chat_deleteText"
                                                                            text: qsTr("Delete")
                                                                            color: "black"
                                                                            font.pixelSize: 14
                                                                        }
                                                                    }
                                                                    MouseArea {
                                                                        id: deleteRetMouseArea
                                                                        Accessible.name: "kylin-aiassistant_Chat_deleteRetMouseArea"
                                                                        anchors.fill: parent
                                                                        propagateComposedEvents: true
                                                                        hoverEnabled: true  // 允许悬浮事件
                                                                        enabled: messageField.selectionStart !== messageField.selectionEnd
                                                                        onEntered: {
                                                                            if(messageField.selectionStart !== messageField.selectionEnd){
                                                                                deleteText.color = "#FFFFFF"
                                                                                deleteRet.color = "#3790FA"
                                                                            }
                                                                        }
                                                                        onExited: {
                                                                            deleteText.color = "#000000"
                                                                            deleteRet.color = "#FFFFFF"
                                                                        }
                                                                        onPressed: {
                                                                            deleteText.color = "#FFFFFF"
                                                                            deleteRet.color = "#3790FA"
                                                                        }
                                                                        onReleased: {
                                                                            deleteText.color = "#000000"
                                                                            deleteRet.color = "#FFFFFF"
                                                                        }
                                                                        onClicked: {
                                                                            var start = messageField.selectionStart
                                                                            var end = messageField.selectionEnd
                                                                            messageField.text = messageField.text.slice(0, start) + messageField.text.slice(end)
                                                                            messageField.cursorPosition = start
                                                                            rightClickMenuPopup.close()
                                                                        }
                                                                    }
                                                                }
                                                                Rectangle {
                                                                    id: ctrlARet
                                                                    Accessible.name: "kylin-aiassistant_Chat_ctrlARet"
                                                                    width: 116
                                                                    height: 36
                                                                    radius: 4
                                                                    RowLayout {
                                                                        anchors.centerIn: parent
                                                                        Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
                                                                        Text {
                                                                            id: ctrlAText
                                                                            text: qsTr("Select all")
                                                                            color: "black"
                                                                            font.pixelSize: 14
                                                                        }
                                                                    }
                                                                    MouseArea {
                                                                        id: ctrlATextMouseArea
                                                                        Accessible.name: "kylin-aiassistant_Chat_ctrlATextMouseArea"
                                                                        anchors.fill: parent
                                                                        propagateComposedEvents: true
                                                                        hoverEnabled: true  // 允许悬浮事件
                                                                        onEntered: {
                                                                            ctrlAText.color = "#FFFFFF"
                                                                            ctrlARet.color = "#3790FA"
                                                                        }
                                                                        onExited: {
                                                                            ctrlAText.color = "#000000"
                                                                            ctrlARet.color = "#FFFFFF"
                                                                        }
                                                                        onPressed: {
                                                                            ctrlAText.color = "#FFFFFF"
                                                                            ctrlARet.color = "#3790FA"
                                                                        }
                                                                        onReleased: {
                                                                            ctrlAText.color = "#000000"
                                                                            ctrlARet.color = "#FFFFFF"
                                                                        }
                                                                        onClicked: {
                                                                            messageField.selectAll()
                                                                            rightClickMenuPopup.close()
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                        background: Rectangle {
                                                            color: "#FFFFFF"  // 背景颜色
                                                            radius: 4  // 圆角
                                                            border.color: "#26000000"  // 边框颜色
                                                            border.width: 1  // 边框宽度
                                                        }
                                                    }
//                                                    Timer {
//                                                        id: rightClickMenuPopupTimer
//                                                        interval: 1000 // 10毫秒
//                                                        repeat: false // 重复触发
//                                                        running: false // 初始不运行
//                                                        onTriggered: {
//                                                            rightClickMenuPopup.close()
//                                                            rightClickMenuPopup.moveFlag = true
//                                                        }
//                                                    }
                                                }
                                                ScrollView {
                                                    id: textAreaScrollView
                                                    // 最后(+5)将滚动条显示到外面去
                                                    width: inputRectange.width - messageFieldColumn.leftPadding - messageFieldColumn.rightPadding + 4
//                                                    height: {
//                                                        if(chat.winMode === 2 ){
//                                                            return 76
//                                                        }else{
//                                                            return 36
//                                                        }
//                                                    }
                                                    height: 50
        //                                            ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
        //                                            ScrollBar.vertical.policy: ScrollBar.AlwaysOff
                                                    clip: true  // 保证超出内容不显示
                                                    // 限制 Flow 的高度为最多五行
                                                    contentHeight: messageField.height
                                                    //boundsBehavior: Flickable.StopAtBounds  // 防止过度滚动属性ScrollView用不了，代码先保存
                                                    // 自定义垂直滚动条
                                                    ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
                                                    //ScrollBar.vertical.minimumSize:this.height
                                                    ScrollBar.vertical.policy: ScrollBar.AlwaysOff
                                                    TextArea {
                                                        id: messageField
                                                        Accessible.name: "kylin-aiassistant_Chat_messageField"
                                                        width: inputRectange.width - messageFieldColumn.leftPadding - messageFieldColumn.rightPadding
                                                        // 内容高度是否超出容器高度标识
                                                        property bool isContentOverflowing: false
                                                        wrapMode: TextArea.WrapAnywhere
                                                        selectByMouse: true
                                                        topPadding:2
                                                        color: "black"
                                                        background: Rectangle{
                                                            anchors.fill: parent
                                                            border.width: 0
                                                            border.color: "transparent"
                                                        }
//                                                        font.pixelSize: 12
                                                        //用于解决点击区域问题和换行问题
                                                        height: 50
//                                                        height: {
//                                                            if(chat.winMode === 2 ){
//                                                                return 76
//                                                            }else{
//                                                                return 36
//                                                            }
//                                                        }
                                                        placeholderText: qsTr("Ask me a question or type a '/'")
                                                        placeholderTextColor: Qt.rgba(0,0,0,0.6)
                                                        onFocusChanged: {
                                                            inputRectangeGradient.stops[0].color = (messageField.focus || inputRectange.activeCommand !== ""|| inputRectange.imagePreviewSrc !== "" || inputRectange.documentPreviewName !== "") ? "#E85CFF" : "white" // 改变第一个颜色
                                                            inputRectangeGradient.stops[1].color = (messageField.focus || inputRectange.activeCommand !== ""|| inputRectange.imagePreviewSrc !== "" || inputRectange.documentPreviewName !== "") ? "#3790FA" : "white" // 改变第二个颜色
                                                            //inputRectange.border.color = (messageField.focus || inputRectange.activeCommand !== ""|| inputRectange.imagePreviewSrc !== "" || inputRectange.documentPreviewName !== "") ? "#3790FA" : "#F5F5F5"
                                                            //inputRectange.border.color = messageField.focus ? "#3790FA" : "#F5F5F5";
                                                        }
                                                        onActiveFocusChanged: {
                                                            inputRectangeGradient.stops[0].color = (messageField.focus || inputRectange.activeCommand !== ""|| inputRectange.imagePreviewSrc !== "" || inputRectange.documentPreviewName !== "") ? "#E85CFF" : "white" // 改变第一个颜色
                                                            inputRectangeGradient.stops[1].color = (messageField.focus || inputRectange.activeCommand !== ""|| inputRectange.imagePreviewSrc !== "" || inputRectange.documentPreviewName !== "") ? "#3790FA" : "white" // 改变第二个颜色
                                                            //inputRectange.border.color = (messageField.focus || inputRectange.activeCommand !== ""|| inputRectange.imagePreviewSrc !== "" || inputRectange.documentPreviewName !== "") ? "#3790FA" : "#F5F5F5"
                                                        }
                                                        // 监听文本变化和光标位置变化
                                                        onTextChanged: {
                                                            // 判断内容是否超出容器高度，超出显示滚动条
                                                            isContentOverflowing = contentHeight > textAreaScrollView.height
                                                            if(isContentOverflowing){
//                                                                if(chat.winMode === 2 ){
//                                                                    messageField.height = messageField.implicitHeight
//                                                                    textAreaScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOn
//                                                                }else{
                                                                    if(contentHeight >= 110){
                                                                        messageFieldRet.height = 150 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                                        textAreaScrollView.height = 116
                                                                        messageField.height = messageField.implicitHeight
                                                                        textAreaScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOn
                                                                    }else if(contentHeight > 90 && contentHeight < 110){
                                                                        messageFieldRet.height = 150 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                                        textAreaScrollView.height = 116
                                                                        messageField.height = 116
                                                                    }else if(contentHeight > 67 && contentHeight < 90 ){
                                                                        messageFieldRet.height = 130 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                                        textAreaScrollView.height = 96
                                                                        messageField.height = 96
                                                                    }else if(contentHeight > 50 && contentHeight < 67){
                                                                        messageFieldRet.height = 110 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                                        textAreaScrollView.height = 76
                                                                        messageField.height = 76
                                                                    }else if(contentHeight > 30){
                                                                        messageFieldRet.height = 92 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                                        textAreaScrollView.height = 56
                                                                        messageField.height = 56
                                                                    }
                                                                //}
                                                            }else{
//                                                                var winHeight = 0
//                                                                if(chat.winMode === 2 ){
//                                                                    winHeight = 76
//                                                                    messageField.height = winHeight
//                                                                    textAreaScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOff
//                                                                }else{
                                                                    if(contentHeight >= 110){
                                                                        messageFieldRet.height = 150 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                                        textAreaScrollView.height = 116
                                                                        messageField.height = messageField.implicitHeight
                                                                        textAreaScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOn
                                                                    }else if(contentHeight > 90 && contentHeight < 110){
                                                                        messageFieldRet.height = 150 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                                        textAreaScrollView.height = 116
                                                                        messageField.height = 116
                                                                        textAreaScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOff
                                                                    }else if(contentHeight > 67 && contentHeight < 90 ){
                                                                        messageFieldRet.height = 130 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                                        textAreaScrollView.height = 96
                                                                        messageField.height = 96
                                                                        textAreaScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOff
                                                                    }else if(contentHeight > 50 && contentHeight < 67){
                                                                        messageFieldRet.height = 110 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                                        textAreaScrollView.height = 76
                                                                        messageField.height = 76
                                                                        textAreaScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOff
                                                                    }else if(contentHeight > 30){
                                                                        messageFieldRet.height = 92 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                                        textAreaScrollView.height = 56
                                                                        messageField.height = 56
                                                                        textAreaScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOff
                                                                    }else{
                                                                        messageFieldRet.height = (72 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height))
                                                                        textAreaScrollView.height = 50
                                                                        messageField.height = 50
                                                                        textAreaScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOff
                                                                    }
                                                                //}
                                                                //textAreaScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOff
                                                            }
                                                            //光标位置变化
                                                            // adjustScrollPosition()
                                                        }
        //                                                onCursorPositionChanged: {
        //                                                    adjustScrollPosition()
        //                                                }
                                                        onContentHeightChanged: {
                                                            // 判断内容是否超出容器高度，超出显示滚动条
                                                            isContentOverflowing = contentHeight > textAreaScrollView.height
                                                            if(isContentOverflowing){
//                                                                if(chat.winMode === 2 ){
//                                                                    messageField.height = messageField.implicitHeight
//                                                                    textAreaScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOn
//                                                                }else{
                                                                if(contentHeight >= 110){
                                                                    messageFieldRet.height = 150 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                                    textAreaScrollView.height = 116
                                                                    messageField.height = messageField.implicitHeight
                                                                    textAreaScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOn
                                                                }else if(contentHeight > 90 && contentHeight < 110){
                                                                    messageFieldRet.height = 150 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                                    textAreaScrollView.height = 116
                                                                    messageField.height = 116
                                                                }else if(contentHeight > 67 && contentHeight < 90 ){
                                                                    messageFieldRet.height = 130 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                                    textAreaScrollView.height = 96
                                                                    messageField.height = 96
                                                                }else if(contentHeight > 50 && contentHeight < 67){
                                                                    messageFieldRet.height = 110 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                                    textAreaScrollView.height = 76
                                                                    messageField.height = 76
                                                                }else if(contentHeight > 30){
                                                                    messageFieldRet.height = 92 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                                    textAreaScrollView.height = 56
                                                                    messageField.height = 56
                                                                }
                                                                //}
                                                            }else{
//                                                                var winHeight = 0
//                                                                if(chat.winMode === 2 ){
//                                                                    winHeight = 76
//                                                                    messageField.height = winHeight
//                                                                    textAreaScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOff
//                                                                }else{
                                                                if(contentHeight >= 110){
                                                                    messageFieldRet.height = 150 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                                    textAreaScrollView.height = 116
                                                                    messageField.height = messageField.implicitHeight
                                                                    textAreaScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOn
                                                                }else if(contentHeight > 90 && contentHeight < 110){
                                                                    messageFieldRet.height = 150 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                                    textAreaScrollView.height = 116
                                                                    messageField.height = 116
                                                                    textAreaScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOff
                                                                }else if(contentHeight > 67 && contentHeight < 90 ){
                                                                    messageFieldRet.height = 130 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                                    textAreaScrollView.height = 96
                                                                    messageField.height = 96
                                                                    textAreaScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOff
                                                                }else if(contentHeight > 50 && contentHeight < 67){
                                                                    messageFieldRet.height = 110 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                                    textAreaScrollView.height = 76
                                                                    messageField.height = 76
                                                                    textAreaScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOff
                                                                }else if(contentHeight > 30){
                                                                    messageFieldRet.height = 92 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                                    textAreaScrollView.height = 56
                                                                    messageField.height = 56
                                                                    textAreaScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOff
                                                                }else{
                                                                    messageFieldRet.height = (72 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height))
                                                                    textAreaScrollView.height = 50
                                                                    messageField.height = 50
                                                                    textAreaScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOff
                                                                }
                                                                //}
                                                            }
                                                        }
                                                        Keys.onPressed: {
                                                            //任意键盘按键都会打断语音输入
                                                            if (isCapturingVideo){
                                                                voiceStopButtonMouseArea.stopVoiceInput();
                                                            }
                                                            // 判断输入是否是 "/",处理是否弹出提示词
                                                            if (event.key === Qt.Key_Slash) {  // 判断是否是 "/"
                                                                if(messageField.text.length === 0){
                                                                    tabViewString = "AllCommand"
                                                                    messageField.focus = true
                                                                }else{
                                                                    tabViewString = "Command"
                                                                    messageField.focus = true
                                                                }
                                                            }else{
                                                                // 解决输入/按下enter，关闭提示词显示异常问题
                                                                commandShowRet.visible = false
                                                                bottomAreaBackgroundRet.visible = false
                                                                // 恢复文本和滚动条，关闭提示词
                                                                onChangeWinModeToChatTimer.running = true
                                                                messageField.focus = true
                                                            }
                                                            // 判断输入是否是 退格键,处理是否收起提示词
                                                            if (event.key === Qt.Key_Backspace) {  // 判断是否是退格键
                                                                if(messageField.text.length === 1){
                                                                    tabViewString = "Command"
                                                                    messageField.focus = true
                                                                }
                                                            }
                                                            if (event.key === Qt.Key_Tab) {
                                                                // 插入一个制表符（Tab）
                                                                var cursor = messageField.cursorPosition
                                                                messageField.text = messageField.text.substring(0, cursor) + " " + messageField.text.substring(cursor)
                                                                messageField.cursorPosition = cursor + 1  // 移动光标到插入的 Tab 后
                                                                // adjustScrollPosition()
                                                                event.accepted = true  // 阻止默认的 Tab 键行为
                                                            }

                                                            if ((event.key === Qt.Key_Return || event.key === Qt.Key_Enter)) {
                                                                // Ctrl+Enter/Alt+Enter/Shift+Enter - 换行
                                                                if (event.modifiers & (Qt.ControlModifier | Qt.AltModifier | Qt.ShiftModifier)) {
                                                                    console.log("按下ctrl + enter/alt +enter/shift + enter")
                                                                    var cursorPos = messageField.cursorPosition;
                                                                    messageField.text = messageField.text.substring(0, cursorPos) + "\n" + messageField.text.substring(cursorPos);
                                                                    messageField.cursorPosition = cursorPos + 1;
                                                                    // adjustScrollPosition();
                                                                    event.accepted = true;
                                                                    return;
                                                                }

                                                                console.log("只按下enter")

                                                                if ((messageField.text.trim() === "" && inputRectange.imagePreviewSrc ==="" && inputRectange.documentPreviewName === "" ) || isReplying === true)
                                                                {
                                                                    event.accepted = true;
                                                                    return;
                                                                }
                                                                if (listModel.count > 0) {
                                                                    var lastMsg = listModel.get(listModel.count - 1)
                                                                    lastMsg.isRefreshed = true
                                                                }

                                                                var msgHeadList = {
                                                                    msgHead: inputRectange.activeCommand,
                                                                    promptId: inputRectange.activeCommandID,
                                                                    imagePath: inputRectange.imagePreviewPath,
                                                                    imageSrc: inputRectange.imagePreviewSrc,
                                                                    documentPath: inputRectange.documentPreviewPath,
                                                                    documentIcon: inputRectange.documentPreviewIcon,
                                                                    documentName: inputRectange.documentPreviewName,
                                                                    documentSize: inputRectange.documentPreviewSize,
                                                                };
                                                                var jsonMsgHead = JSON.stringify(msgHeadList)
                                                                moveCommonTimer.running = true
        //                                                        if (listView.preIndex >= 0 && listView.preIndex < listModel.count) {
        //                                                            // 发送消息前需要停止朗读
        //                                                            msgPane.onPauseRead();
        //                                                            listModel.get(listView.preIndex).showRead = true;
        //                                                        }
                                                                var retJsonString = msgPane.onSendMsg(jsonMsgHead, messageField.text)
                                                                var retJsonObject = JSON.parse(retJsonString);
                                                                isReplying = retJsonObject['isReplying'] !== undefined ? retJsonObject['isReplying'] : false
                                                                messageField.text = "";
                                                                inputRectange.imagePreviewSrc = "";
                                                                inputRectange.imagePreviewPath = "";
                                                                inputRectange.documentPreviewPath = "";
                                                                inputRectange.documentPreviewIcon = "";
                                                                inputRectange.documentPreviewName = "";
                                                                inputRectange.documentPreviewSize = "";
                                                                inputRectange.activeCommandID = -1
                                                                inputRectange.activeCommand = ""
                                                                chat.tabViewString ="Command"
                                                                messageField.focus = false
                                                                event.accepted = true;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    // 用于解决切换窗口或侧边栏模式后输入框文字高度变化问题，提示词模板高度变化问题
                                     Timer {
                                        id: onChangeWinModeToChatTimer
                                        interval: 10 // 10毫秒
                                        repeat: false // 重复触发
                                        running: false // 初始不运行
                                        onTriggered: {
                                            // 切换窗口，关闭提示词
                                            chat.tabViewString = "Command"

                                            // 切换窗口判断提示词模板内容是否超出容器高度，超出显示滚动条
                                            var isCommandContentOverflowing = commandFlickable.contentHeight > commandFlickable.height
                                            if(isCommandContentOverflowing){
                                                commandFlickable.ScrollBar.vertical.policy = ScrollBar.AlwaysOn
                                            }else{
                                                commandFlickable.ScrollBar.vertical.policy = ScrollBar.AlwaysOff
                                            }

                                            // 判断输入框内容是否超出容器高度，超出显示滚动条
                                            var isContentOverflowing = messageField.contentHeight > textAreaScrollView.height
                                            if(isContentOverflowing){
//                                                if(chat.winMode === 2 ){
//                                                    var messageFieldRetHeight = 0
//                                                    var textAreaScrollViewHeight = 0
//                                                    messageFieldRetHeight = 110
//                                                    textAreaScrollViewHeight = 76
//                                                    messageField.height = messageField.implicitHeight
//                                                    messageFieldRet.height = messageFieldRetHeight
//                                                    textAreaScrollView.height = textAreaScrollViewHeight
//                                                    textAreaScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOn
//                                                }else{
                                                if(messageField.contentHeight >= 110){
                                                    messageFieldRet.height = 150 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                    textAreaScrollView.height = 116
                                                    messageField.height = messageField.implicitHeight
                                                    textAreaScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOn
                                                }else if(messageField.contentHeight > 90 && messageField.contentHeight < 110){
                                                    messageFieldRet.height = 150 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                    textAreaScrollView.height = 116
                                                    messageField.height = 116
                                                }else if(messageField.contentHeight > 67 && messageField.contentHeight < 90 ){
                                                    messageFieldRet.height = 130 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                    textAreaScrollView.height = 96
                                                    messageField.height = 96
                                                }else if(messageField.contentHeight > 50 && messageField.contentHeight < 67){
                                                    messageFieldRet.height = 110 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                    textAreaScrollView.height = 76
                                                    messageField.height = 76
                                                }else if(messageField.contentHeight > 30){
                                                    messageFieldRet.height = 92 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                    textAreaScrollView.height = 56
                                                    messageField.height = 56
                                                }
                                                //}
                                            }else{
//                                                var winHeight = 0
//                                                var messageFieldRetHeight = 0
//                                                var textAreaScrollViewHeight = 0
//                                                if(chat.winMode === 2 ){
//                                                    winHeight = 76
//                                                    messageFieldRetHeight = 110
//                                                    textAreaScrollViewHeight = 76
//                                                    messageField.height = winHeight
//                                                    messageFieldRet.height = messageFieldRetHeight
//                                                    textAreaScrollView.height = textAreaScrollViewHeight
//                                                }else{
                                                if(messageField.contentHeight >= 110){
                                                    messageFieldRet.height = 150 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                    textAreaScrollView.height = 116
                                                    messageField.height = messageField.implicitHeight
                                                    textAreaScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOn
                                                }else if(messageField.contentHeight > 90 && messageField.contentHeight < 110){
                                                    messageFieldRet.height = 150 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                    textAreaScrollView.height = 116
                                                    messageField.height = 116
                                                    textAreaScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOff
                                                }else if(messageField.contentHeight > 67 && messageField.contentHeight < 90 ){
                                                    messageFieldRet.height = 130 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                    textAreaScrollView.height = 96
                                                    messageField.height = 96
                                                    textAreaScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOff
                                                }else if(messageField.contentHeight > 50 && messageField.contentHeight < 67){
                                                    messageFieldRet.height = 110 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                    textAreaScrollView.height = 76
                                                    messageField.height = 76
                                                    textAreaScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOff
                                                }else if(messageField.contentHeight > 30){
                                                    messageFieldRet.height = 92 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height)
                                                    textAreaScrollView.height = 56
                                                    messageField.height = 56
                                                    textAreaScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOff
                                                }else{
                                                    messageFieldRet.height = (72 - (commandInputRectangle.visible ? 0 : commandInputRectangle.height))
                                                    textAreaScrollView.height = 50
                                                    messageField.height = 50
                                                    textAreaScrollView.ScrollBar.vertical.policy = ScrollBar.AlwaysOff
                                                }
                                                //}
                                            }
                                        }
                                    }
                                    // 图片上传小预览窗口
                                    Row{
                                        id:imagePreviewShowRow
                                        Accessible.name: "kylin-aiassistant_Chat_imagePreviewShowRow"
                                        leftPadding: 10
                                        topPadding: 5
                                        bottomPadding: 5
                                        visible: inputRectange.imagePreviewSrc !== ""
                                        onVisibleChanged: {
                                            // 上传图片时清空文档
                                            if(imagePreviewShowRow.visible){
                                                inputRectange.documentPreviewPath = ""
                                                inputRectange.documentPreviewName = ""
                                                inputRectange.documentPreviewSize = ""
                                                inputRectange.documentPreviewIcon = ""
                                            }
                                        }
                                        Rectangle{
                                            id: imagePreviewRet
                                            Accessible.name: "kylin-aiassistant_Chat_imagePreviewRet"
                                            visible: inputRectange.imagePreviewSrc !== ""
                                            //radius: 6
                                            width: imagePreviewRow.width + imagePreviewRow.leftPadding
                                            height: imagePreviewImage.height
                                            Row{
                                                id: imagePreviewRow
                                                Accessible.name: "kylin-aiassistant_Chat_imagePreviewRow"
                                                leftPadding: 6
                                                visible: inputRectange.imagePreviewSrc !== ""
                                                width: imagePreviewImage.width
                                                height: imagePreviewImage.height
                                                Image {
                                                    id: imagePreviewImage
                                                    Accessible.name: "kylin-aiassistant_Chat_imagePreviewImage"
                                                    source: inputRectange.imagePreviewSrc
                                                    visible: inputRectange.imagePreviewSrc !== ""
                                                    //anchors.verticalCenter: parent.verticalCenter
                                                    // 固定值
                                                    property int fixedSize: 74
                                                    // 计算宽高比
                                                    property real aspectRatio: implicitWidth / implicitHeight
                                                    // 根据图片宽高比调整大小，取宽度或高度中的较大者为fixedSize
                                                    width: aspectRatio >= 1 ? fixedSize : fixedSize * aspectRatio  // 如果宽比高大，则宽度取固定值
                                                    height: aspectRatio < 1 ? fixedSize : fixedSize / aspectRatio
                                                    // 使图片显示为圆形
                                                    layer.enabled: true // 启用图层特性
                                                    layer.effect: OpacityMask {
                                                        maskSource: Item {
                                                            width: imagePreviewImage.width
                                                            height: imagePreviewImage.height
                                                            Rectangle {
                                                                anchors.centerIn: parent
                                                                width: parent.width
                                                                height: width
                                                                radius: 6
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            Image {
                                                id: imagePreviewButtonImage
                                                Accessible.name: "kylin-aiassistant_Chat_imagePreviewButtonImage"
                                                source: "qrc:/icon/icon/closeDoc.svg"
                                                visible: inputRectange.imagePreviewSrc !== ""
                                                anchors.top: imagePreviewRet.top  // 按钮贴紧顶部
                                                anchors.right: imagePreviewRet.right  // 按钮贴紧右侧
                                                MouseArea {
                                                    id: imagePreviewButtonImageMouseArea
                                                    Accessible.name: "kylin-aiassistant_Chat_imagePreviewButtonImageMouseArea"
                                                    anchors.fill: parent
                                                    hoverEnabled: true
                                                    onEntered: {
                                                        imagePreviewButtonImage.source = "qrc:/icon/icon/closeDoc_hover.svg"
                                                    }
                                                    onExited: {
                                                        imagePreviewButtonImage.source = "qrc:/icon/icon/closeDoc.svg"
                                                    }
                                                    onPressed: {
                                                        imagePreviewButtonImage.source = "qrc:/icon/icon/closeDoc_active.svg"
                                                    }
                                                    onReleased: {
                                                        imagePreviewButtonImage.source = "qrc:/icon/icon/closeDoc.svg"
                                                    }
                                                    onClicked: {
                                                        inputRectange.imagePreviewSrc = ""
                                                        inputRectange.imagePreviewPath = ""
                                                    }

                                                }
                                            }
                                            onVisibleChanged: {
                                                moveCommonTimer.running = true
                                            }
                                        }
                                    }

                                    // 文件上传小预览窗口
                                    Row{
                                        id:documentPreviewShowRow
                                        Accessible.name: "kylin-aiassistant_Chat_documentPreviewShowRow"
                                        leftPadding: 10
                                        rightPadding: 10
                                        topPadding: 5
                                        bottomPadding: 5
                                        visible: inputRectange.documentPreviewName !== ""
                                        onVisibleChanged: {
                                            // 上传文档时清空图片
                                            if(documentPreviewShowRow.visible){
                                                inputRectange.imagePreviewSrc = ""
                                                inputRectange.imagePreviewPath = ""
                                            }
                                        }

                                        Rectangle{
                                            id: documentPreviewRet
                                            Accessible.name: "kylin-aiassistant_Chat_documentPreviewRet"
                                            visible: inputRectange.documentPreviewName !== ""
                                            radius: 6
                                            color: "#0d262626"
                                            width: documentPreviewRow.width + documentPreviewRow.leftPadding +  documentPreviewRow.rightPadding
                                            height: documentPreviewRow.height + documentPreviewRow.topPadding + documentPreviewRow.bottomPadding
                                            Row{
                                                id: documentPreviewRow
                                                Accessible.name: "kylin-aiassistant_Chat_documentPreviewRow"
                                                leftPadding: 6
                                                rightPadding: 6
                                                topPadding: 6
                                                bottomPadding: 6
                                                visible: inputRectange.documentPreviewName !== ""
                                                width: documentIconPreviewRet.width + documentDetailsRow.width +
                                                       (documentNameText.implicitWidth < documentDetailsRow.documentNameRowMaxWidth ? 20 : 0)
                                                height: documentDetailsRow.height > documentIconPreviewRet.height ? documentDetailsRow.height : documentIconPreviewRet.height
                                                Rectangle{
                                                    id: documentIconPreviewRet
                                                    Accessible.name: "kylin-aiassistant_Chat_documentIconPreviewRet"
                                                    width: 50
                                                    color: "transparent"
                                                    height: documentDetailsRow.height
                                                    Image {
                                                        id: documentIconPreviewImage
                                                        Accessible.name: "kylin-aiassistant_Chat_documentIconPreviewImage"
                                                        source: inputRectange.documentPreviewIcon
                                                        visible: inputRectange.documentPreviewName !== ""
                                                        anchors.centerIn: parent
                                                        // 固定值
                                                        property int fixedSize: 32
                                                        // 计算宽高比
                                                        property real aspectRatio: implicitWidth / implicitHeight
                                                        // 根据图片宽高比调整大小，取宽度或高度中的较大者为fixedSize
                                                        width: aspectRatio >= 1 ? fixedSize : fixedSize * aspectRatio  // 如果宽比高大，则宽度取固定值
                                                        height: aspectRatio < 1 ? fixedSize : fixedSize / aspectRatio
                                                    }
                                                }

                                                Column{
                                                    id: documentDetailsRow
                                                    Accessible.name: "kylin-aiassistant_Chat_documentDetailsRow"
                                                    width: documentNameRow.width > documentSizeRow.width ? documentNameRow.width : documentSizeRow.width
                                                    // 文档名称可展示最大宽度
                                                    property int documentNameRowMaxWidth: inputRectange.width - documentPreviewShowRow.leftPadding - documentPreviewShowRow.rightPadding
                                                                                          - documentPreviewRow.leftPadding - documentPreviewRow.rightPadding - documentIconPreviewRet.width
                                                    Row{
                                                        id:documentNameRow
                                                        Accessible.name: "kylin-aiassistant_Chat_documentNameRow"
                                                        width: Math.min(documentNameText.implicitWidth, documentDetailsRow.documentNameRowMaxWidth)
                                                        Text{
                                                            id: documentNameText
                                                            Accessible.name: "kylin-aiassistant_Chat_documentNameText"
                                                            width: parent.width
                                                            text: inputRectange.documentPreviewName
                                                            font.pixelSize: 14
                                                            wrapMode: Text.WordWrap
                                                        }
                                                    }
                                                    Row{
                                                        id:documentSizeRow
                                                        Accessible.name: "kylin-aiassistant_Chat_documentSizeRow"
                                                        width: documentSizeText.width
                                                        Text{
                                                            id:documentSizeText
                                                            Accessible.name: "kylin-aiassistant_Chat_documentSizeText"
                                                            text: "大小 " + inputRectange.documentPreviewSize
                                                            font.pixelSize: 12
                                                            color: Qt.rgba(38/255, 38/255, 38/255, 0.3)
                                                        }
                                                    }

                                                }
                                            }
                                            Image {
                                                id: documentPreviewButtonImage
                                                source: "qrc:/icon/icon/closeDoc.svg"
                                                visible: inputRectange.documentPreviewName !== ""
                                                anchors.top: documentPreviewRet.top  // 按钮贴紧顶部
                                                anchors.right: documentPreviewRet.right  // 按钮贴紧右侧
                                                MouseArea {
                                                    id: documentPreviewButtonImageMouseArea
                                                    anchors.fill: parent
                                                    hoverEnabled: true
                                                    onEntered: {
                                                        documentPreviewButtonImage.source = "qrc:/icon/icon/closeDoc_hover.svg"
                                                    }
                                                    onExited: {
                                                        documentPreviewButtonImage.source = "qrc:/icon/icon/closeDoc.svg"
                                                    }
                                                    onPressed: {
                                                        documentPreviewButtonImage.source = "qrc:/icon/icon/closeDoc_active.svg"
                                                    }
                                                    onReleased: {
                                                        documentPreviewButtonImage.source = "qrc:/icon/icon/closeDoc.svg"
                                                    }
                                                    onClicked: {
                                                        inputRectange.documentPreviewPath = ""
                                                        inputRectange.documentPreviewName = ""
                                                        inputRectange.documentPreviewIcon = ""
                                                        inputRectange.documentPreviewSize = ""
                                                    }
                                                }
                                            }
                                            onVisibleChanged: {
                                                moveCommonTimer.running = true
                                            }
                                        }
                                    }

                                    //底部按钮区
                                    Row {
                                        id: bottomButtonRowLayout
                                        Accessible.name: "kylin-aiassistant_Chat_bottomButtonRowLayout"
                                        width: inputRectange.width - 10 - inputRectange.border.width * 2
                                        //spacing: 0
                                        Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
                                        leftPadding: 4
                                        rightPadding: 4
                                        bottomPadding: 2
                                        //添加图片按钮
                                        Rectangle {
                                            id: addImageButton
                                            Accessible.name: "kylin-aiassistant_Chat_addImageButton"
                                            width: 36
                                            height: 36
                                            radius: 4
                                            ToolTip.text: qsTr("Number of images: no more than 1\nSize of images:no more than 50MB\nSupported formats:bmp、jpe、jpeg、jpg、pbm、pgm、png、ppm、tiff、webp")
                                            ToolTip.visible: addImageButtonMouseArea.containsMouse
                                            visible: isSupportImageProcessing //1203注释，测试要求不提测图片处理时隐藏该入口
                                            RowLayout {
                                                anchors.fill: parent
                                                Image {
                                                    Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
                                                    source: "qrc:/icon/icon/addImage.svg"
                                                }
                                            }

                                            MouseArea {
                                                id: addImageButtonMouseArea
                                                Accessible.name: "kylin-aiassistant_Chat_addImageButtonMouseArea"
                                                anchors.fill: parent
                                                hoverEnabled: true
                                                onEntered: {
                                                    addImageButton.color = "#26000000"
                                                }
                                                onExited: {
                                                    addImageButton.color = "#FFFFFF"
                                                }
                                                onPressed: {
                                                    addImageButton.color = "#33000000"
                                                    onCloseCommand()
                                                }
                                                onReleased: {
                                                    addImageButton.color = "#FFFFFF"
                                                }
                                                onClicked: {
                                                    //1015注释
                                                    msgPane.onSelectFile(1);
                                                }

                                            }
                                        }
                                        //添加文件按钮
                                        Rectangle {
                                            id: addFileButton
                                            Accessible.name: "kylin-aiassistant_Chat_addFileButton"
                                            width: 36
                                            height: 36
                                            radius: 4
                                            visible: isSupportDocumentQA
                                            ToolTip.text: qsTr("Number of Documents: no more than 1\nSize of Documents:no more than 50MB\nSupported formats:txt、pdf、docx、pptx")
                                            ToolTip.visible: addFileButtonMouseArea.containsMouse

                                            RowLayout {
                                                anchors.fill: parent
                                                Image {
                                                    Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
                                                    source: "qrc:/icon/icon/addFile.svg"
                                                }
                                            }

                                            MouseArea {
                                                id: addFileButtonMouseArea
                                                Accessible.name: "kylin-aiassistant_Chat_addFileButtonMouseArea"
                                                anchors.fill: parent
                                                hoverEnabled: true
                                                onEntered: {
                                                    addFileButton.color = "#26000000"
                                                }
                                                onExited: {
                                                    addFileButton.color = "#FFFFFF"
                                                }
                                                onPressed: {
                                                    addFileButton.color = "#33000000"
                                                    onCloseCommand()
                                                }
                                                onReleased: {
                                                    addFileButton.color = "#FFFFFF"
                                                }
                                                onClicked: {
                                                    msgPane.onSelectFile(2);
                                                }

                                            }
                                        }

                                        //底部中间弹簧
                                        Rectangle {
        //                                   Layout.fillHeight: true;
        //                                   Layout.fillWidth: true;
                                            width: inputRectange.width - 10 - inputRectange.border.width * 2 - (addImageButton.visible ? addImageButton.width : 0) - (voiceSwapButton.visible ? voiceSwapButton.width : 0) - (voiceStopButton.visible ? voiceStopButton.width : 0) - sendTextButton.width - (addFileButton.visible?addFileButton.width:0)
                                            height: 36
                                        }

                                        //按钮-语音输入
                                        Rectangle {
                                            id: voiceSwapButton
                                            Accessible.name: "kylin-aiassistant_Chat_voiceSwapButton"
                                            width: 36
                                            height: 36
                                            radius: 4
                                            ToolTip.text: qsTr("Voice input")
                                            ToolTip.visible: voiceSwapButtonMouseArea.containsMouse
                                            visible: speechMode === 0
                                            RowLayout {
                                                anchors.fill: parent
                                                Image {
                                                    id: audioInputIcon
                                                    Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
                                                    source: "qrc:/icon/icon/new_voice.svg"

                                                }
                                            }

                                            MouseArea {
                                                id: voiceSwapButtonMouseArea
                                                Accessible.name: "kylin-aiassistant_Chat_voiceSwapButtonMouseArea"
                                                anchors.fill: parent
                                                hoverEnabled: true
                                                property bool isEnable: !isReplying  //使用qml自带的enabled属性，会导致悬浮时无Tooltips，采用自定义属性实现
                                                onEntered: {
                                                    if (!isEnable){
                                                        return;
                                                    }

                                                    voiceSwapButton.color = "#26000000"
                                                }
                                                onExited: {
                                                    if (!isEnable){
                                                        return;
                                                    }

                                                    voiceSwapButton.color = "#FFFFFF"
                                                }
                                                onPressed: {
                                                    // 解决按下语音，关闭提示词显示异常问题
                                                    commandShowRet.visible = false
                                                    bottomAreaBackgroundRet.visible = false
                                                    // 恢复文本和滚动条，关闭提示词
                                                    onChangeWinModeToChatTimer.running = true
                                                    if (!isEnable){
                                                        return;
                                                    }

                                                    voiceSwapButton.color = "#33000000"
                                                }
                                                onReleased: {
                                                    if (!isEnable){
                                                        return;
                                                    }

                                                    voiceSwapButton.color = "#FFFFFF"
                                                }
                                                onClicked: {
                                                    if (!isEnable){
                                                        return;
                                                    }


                                                    if(listView.isChatEndFlag){
                                                        moveCommonTimer.running = true
                                                    }
                                                    if(isReplying && !isSpeech){
                                                        speechMode = 0;
                                                        msgPane.onSpeechModeChanged(speechMode);
                                                    }
                                                    chat.tabViewString = "Command"; //全部指令收起

                                                    //暂停正在朗读的消息
                                                    if (listView.curIndex >= 0 && listView.curIndex < listModel.count) {
                                                        msgPane.onPauseRead();
                                                        listModel.get(listView.curIndex).showRead = true;
                                                        listView.preIndex = listView.curIndex;
                                                        listView.curIndex = -1;
                                                    }


                                                    isCapturingVideo = true;
                                                    speechMode = 2;

                                                    //语音输入30s自动暂停，当后端初始化成功时，通过信号updateCurrentStartTimer启动计时器
                                                    originText = messageField.text;
                                                    msgPane.onSendAudio();
                                                    msgPane.onSpeechModeChanged(speechMode);
                                                }
                                                onIsEnableChanged: {
                                                    if(isEnable){
                                                        audioInputIcon.source = "qrc:/icon/icon/new_voice.svg";
                                                    }else{
                                                        audioInputIcon.source = "qrc:/icon/icon/micphone_disable.svg"
                                                    }
                                                }

                                            }
                                        }

                                        //按钮-停止语音输入
                                        Rectangle {
                                            id: voiceStopButton
                                            Accessible.name: "kylin-aiassistant_Chat_voiceStopButton"
                                            width: voiceText.visible ? 20 + voiceStopRow.leftPadding * 2 + voiceStopRow.spacing + voiceText.width : 36
                                            height: 36
                                            radius: 4
                                            visible: speechMode === 2
                                            ToolTip.text: qsTr("Complete voice input")
                                            ToolTip.visible: voiceStopButtonMouseArea.containsMouse

                                            Row {
                                                id: voiceStopRow
                                                Accessible.name: "kylin-aiassistant_Chat_voiceStopRow"
                                                anchors.fill: parent
                                                spacing: 4
                                                leftPadding: 8
                                                rightPadding: 8

                                                Rectangle{
                                                    width: 20
                                                    height: 36
                                                    color: "transparent"
                                                    // 播放动画
                                                    VoicePlayAnimation {
                                                        id:playAnimation
                                                        Accessible.name: "kylin-aiassistant_Chat_playAnimation"
                                                        anchors.verticalCenter: parent.verticalCenter
                                                        anchors.horizontalCenter: parent.horizontalCenter
                                                    }
                                                }


                                                Text {
                                                    id: voiceText
                                                    Accessible.name: "kylin-aiassistant_Chat_voiceText"
                                                    visible: voiceText.text !== ""
                                                    text: qsTr("")
                                                    color: Qt.rgba(55/255, 143/255, 255/255, 1)
                                                    anchors.verticalCenter: parent.verticalCenter
                                                }

                                                Timer {
                                                    id: countDownTimer
                                                    interval: 1000 // 1秒
                                                    repeat: true // 重复触发
                                                    running: false // 初始不运行
                                                    onTriggered: {
                                                        startCountDown();
                                                    }
                                                }
                                            }

                                            MouseArea {
                                                id: voiceStopButtonMouseArea
                                                Accessible.name: "kylin-aiassistant_Chat_voiceStopButtonMouseArea"
                                                anchors.fill: parent
                                                hoverEnabled: true
                                                onEntered: {
                                                    voiceStopButton.color = Qt.rgba(55/255, 144/255, 255/255, 0.1);
                                                }
                                                onExited: {
                                                    voiceStopButton.color = "#FFFFFF"
                                                }
                                                onPressed: {
                                                    voiceStopButton.color = Qt.rgba(55/255, 144/255, 255/255, 0.2);
                                                }
                                                onReleased: {
                                                    voiceStopButton.color = "#FFFFFF"
                                                }
                                                onClicked: {
                                                    stopVoiceInput();
                                                }

                                                //停止语音输入，恢复前端UI状态，多处会调用此函数
                                                function stopVoiceInput() {
                                                    speechMode = 0
                                                    isCapturingVideo = false
                                                    msgPane.onStopAudio();
                                                    countDownTimer.stop();
                                                    msgPane.onSpeechModeChanged(speechMode);
                                                    originText = "";
                                                    voiceText.text = "";
                                                }
                                            }
                                        }



                                        //发送按钮
                                        Rectangle {
                                            id: sendTextButton
                                            Accessible.name: "kylin-aiassistant_Chat_sendTextButton"
                                            width: 36
                                            height: 36
        //                                    color: messageField.text.length > 0 ? "#3790FA" : "#FFFFFF"
                                            radius: 4
                                            visible: !isReplying
                                            ToolTip.text: qsTr("Send")
                                            ToolTip.visible: sendTextButtonMouseArea.containsMouse
                                            RowLayout {
                                                anchors.fill: parent
                                                Image {
                                                    id: sendButtonImage
                                                    Accessible.name: "kylin-aiassistant_Chat_sendButtonImage"
                                                    Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
                                                    source: messageField.text.trim().length > 0 && !isReplying  ? "qrc:/html/html/img/send_text_white.svg" : "qrc:/html/html/img/send_text.svg"

                                                }
                                            }

                                            MouseArea {
                                                id: sendTextButtonMouseArea
                                                Accessible.name: "kylin-aiassistant_Chat_sendTextButtonMouseArea"
                                                anchors.fill: parent
                                                hoverEnabled: true
                                                enabled: false
                                                //enabled: messageField.text.length > 0
                                                visible: !isReplying
                                                onEntered: {
                                                    if (enabled) {
                                                        sendTextButton.color = "#3489EE"; // 鼠标悬停时的颜色
                                                    }
                                                }
                                                onExited: {
                                                    if (enabled) {
                                                        sendTextButton.color = "#3790FA"; // 鼠标离开时恢复到默认颜色
                                                    } else {
                                                        sendTextButton.color = "#FFFFFF"; // 没有内容时，恢复到默认的灰色
                                                    }
                                                }
                                                onPressed: {
                                                    if (enabled) {
                                                        sendTextButton.color = "#2C73C8"; // 按下时的颜色
                                                    }
                                                }
                                                onClicked: {
                                                    //判断是否正在语音输入
                                                    if (isCapturingVideo){
                                                        voiceStopButtonMouseArea.stopVoiceInput();
                                                    }

                                                    var inputText = messageField.text
                                                    //console.log(inputText)
                                                    //modify:
                                                    if (listModel.count > 0) {
                                                        var lastMsg = listModel.get(listModel.count - 1)
                                                        lastMsg.isRefreshed = true
                                                    }
                                                    var msgHeadList = {
                                                        msgHead: inputRectange.activeCommand,
                                                        promptId: inputRectange.activeCommandID,
                                                        imagePath: inputRectange.imagePreviewPath,
                                                        imageSrc: inputRectange.imagePreviewSrc,
                                                        documentPath: inputRectange.documentPreviewPath,
                                                        documentIcon: inputRectange.documentPreviewIcon,
                                                        documentName: inputRectange.documentPreviewName,
                                                        documentSize: inputRectange.documentPreviewSize,
                                                    };
                                                    var jsonMsgHead = JSON.stringify(msgHeadList)
                                                    moveCommonTimer.running = true
        //                                            if (listView.preIndex >= 0 && listView.preIndex < listModel.count) {
        //                                                // 发送消息前需要停止朗读
        //                                                msgPane.onPauseRead();
        //                                                listModel.get(listView.preIndex).showRead = true;
        //                                            }
                                                    var retJsonString = msgPane.onSendMsg(jsonMsgHead, messageField.text)
                                                    var retJsonObject = JSON.parse(retJsonString);
                                                    messageField.text = "";
                                                    isReplying = retJsonObject['isReplying'] !== undefined ? retJsonObject['isReplying'] : false

                                                    inputRectange.imagePreviewSrc = "";
                                                    inputRectange.imagePreviewPath = "";
                                                    inputRectange.documentPreviewPath = "";
                                                    inputRectange.documentPreviewIcon = "";
                                                    inputRectange.documentPreviewName = "";
                                                    inputRectange.documentPreviewSize = "";

                                                    //发送按钮的三态
                                                    if (messageField.text.trim().length > 0) {
                                                        sendTextButton.color = "#3790FA"; // 恢复默认的激活状态颜色
                                                        sendButtonImage.source = "qrc:/html/html/img/send_text_white.svg";
                                                        sendTextButtonMouseArea.enabled = true;
                                                    } else {
                                                        sendTextButton.color = "#FFFFFF"; // 如果输入框为空，恢复到禁用状态
                                                        sendButtonImage.source = "qrc:/html/html/img/send_text.svg";
                                                        sendTextButtonMouseArea.enabled = false;
                                                    }
                                                    // 点击发送按钮时，关闭全部指令
                                                    chat.tabViewString = "Command"
                                                    messageField.focus = false
                                                    inputRectange.activeCommand = ""
                                                    inputRectange.activeCommandID = -1
                                                }
                                                onReleased: {
                                                    if(enabled){
                                                        sendTextButton.color = "#3489EE"
                                                        // 手动触发重新计算样式
                                                        sendTextButton.color = "#FFFFFF";
                                                        sendButtonImage.source = "qrc:/html/html/img/send_text.svg";
                                                        sendTextButtonMouseArea.enabled = false;

                                                    }
                                                }
                                                onVisibleChanged: {
                                                    if(visible === true){
                                                        if(messageField.text.trim().length > 0 || inputRectange.imagePreviewSrc !== "" || inputRectange.documentPreviewName !== ""){
                                                            sendTextButton.color = "#3790FA";
                                                            sendButtonImage.source = "qrc:/html/html/img/send_text_white.svg";
                                                            sendTextButtonMouseArea.enabled = true;
                                                        }
                                                    }else{
                                                        sendTextButton.color = "#FFFFFF"; // 如果输入框为空，恢复到禁用状态
                                                        sendButtonImage.source = "qrc:/html/html/img/send_text.svg";
                                                        sendTextButtonMouseArea.enabled = false;
                                                    }
                                                }
                                                // 监听输入框内容变化，动态更新按钮样式
                                                Connections {
                                                    target: messageField
                                                    onTextChanged: function(){
                                                        if(!sendTextButtonMouseArea.visible){
                                                            return;
                                                        }

                                                        if (messageField.text.trim().length > 0 || inputRectange.imagePreviewSrc !== "" || inputRectange.documentPreviewName !== "") {
                                                            sendTextButton.color = "#3790FA";
                                                            sendButtonImage.source = "qrc:/html/html/img/send_text_white.svg";
                                                            sendTextButtonMouseArea.enabled = true;
                                                        } else {
                                                            sendTextButton.color = "#FFFFFF";
                                                            sendButtonImage.source = "qrc:/html/html/img/send_text.svg";
                                                            sendTextButtonMouseArea.enabled = false;
                                                        }
                                                    }
                                                }
                                                // 监听输入框内容变化，动态更新按钮样式，监听是否有图片上传
                                                Connections {
                                                    target: imagePreviewShowRow
                                                    onVisibleChanged: function(){
                                                        if(!sendTextButtonMouseArea.visible){
                                                            return;
                                                        }
                                                        if (messageField.text.trim().length > 0 || inputRectange.imagePreviewSrc !== "" || inputRectange.documentPreviewName !== "") {
                                                            sendTextButton.color = "#3790FA";
                                                            sendButtonImage.source = "qrc:/html/html/img/send_text_white.svg";
                                                            sendTextButtonMouseArea.enabled = true;
                                                        } else {
                                                            sendTextButton.color = "#FFFFFF";
                                                            sendButtonImage.source = "qrc:/html/html/img/send_text.svg";
                                                            sendTextButtonMouseArea.enabled = false;
                                                        }
                                                    }
                                                }
                                                // 监听输入框内容变化，动态更新按钮样式，监听是否有文档上传
                                                Connections {
                                                    target: documentPreviewShowRow
                                                    onVisibleChanged: function(){
                                                        if(!sendTextButtonMouseArea.visible){
                                                            return;
                                                        }
                                                        if (messageField.text.trim().length > 0 || inputRectange.imagePreviewSrc !== "" || inputRectange.documentPreviewName !== "") {
                                                            sendTextButton.color = "#3790FA";
                                                            sendButtonImage.source = "qrc:/html/html/img/send_text_white.svg";
                                                            sendTextButtonMouseArea.enabled = true;
                                                        } else {
                                                            sendTextButton.color = "#FFFFFF";
                                                            sendButtonImage.source = "qrc:/html/html/img/send_text.svg";
                                                            sendTextButtonMouseArea.enabled = false;
                                                        }
                                                    }
                                                }

                                            }
                                        }

                                        // 停止回答按钮
                                        Rectangle {
                                            id: stopButton
                                            Accessible.name: "kylin-aiassistant_Chat_stopButton"
                                            width: 36
                                            height: 36
                                            color:"#3790FA"
                                            radius: 4
                                            visible: isReplying
                                            ToolTip.text: qsTr("Stop answering")
                                            ToolTip.visible: stopButtonMouseArea.containsMouse
                                            RowLayout {
                                                anchors.fill: parent
                                                Image {
                                                    id: stopButtonImage
                                                    Accessible.name: "kylin-aiassistant_Chat_stopButtonImage"
                                                    Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
                                                    source: "qrc:/icon/icon/stop-reply-middle.svg"
                                                }
                                            }
                                            MouseArea {
                                                id: stopButtonMouseArea
                                                Accessible.name: "kylin-aiassistant_Chat_stopButtonMouseArea"
                                                anchors.fill: parent
                                                hoverEnabled: true
                                                enabled: true
                                                onEntered: {
                                                    stopButton.color = "#3489EE"; // 鼠标悬停时的颜色
                                                }
                                                onExited: {
                                                    stopButton.color = "#3790FA"; // 鼠标离开时恢复到默认颜色
                                                }
                                                onPressed: {
                                                    stopButton.color = "#2C73C8"; // 按下时的颜色
                                                }
                                                onReleased: {
                                                    stopButton.color = "#3790FA"
                                                }
                                                onClicked: {
                                                    // 停止回答
                                                    msgPane.onStopReply()
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    //文本对话-输入区域

                    Connections {
                        target: commandTemplateListModel
                        onSigUpdateActiveCommand: function(actorId, name){
                            if (inputRectange.activeCommandID === actorId) {

                                inputRectange.activeCommandID = actorId
                                inputRectange.activeCommand = name
                            }

                        }
                        onSigDeleteActiveCommand: function(actorId, name){
                            if (inputRectange.activeCommandID === actorId) {

                                inputRectange.activeCommandID = -1
                                inputRectange.activeCommand = ""
                            }
                        }
                    }

                    Connections {
                        target: inputRectange
                        onActiveCommandChanged: function(){
                            // 点击选择标签时收起全部指令
                            if(inputRectange.activeCommand !== ""){
                                chat.tabViewString = "Command"
                            }

                            // 判断选择了操作指令,图片预览,文档预览有一项存在,则边框颜色激活
                            if(inputRectange.activeCommand !== "" || inputRectange.imagePreviewSrc !== "" || inputRectange.documentPreviewName !== ""  || messageField.text.trim().length > 0){
                                //inputRectange.border.color = "#3790FA"
                                inputRectangeGradient.stops[0].color = "#E85CFF" // 改变第一个颜色
                                inputRectangeGradient.stops[1].color = "#3790FA" // 改变第二个颜色

                            }else{
                                //inputRectange.border.color = "#F5F5F5"
                                inputRectangeGradient.stops[0].color = "#F5F5F5" // 改变第一个颜色
                                inputRectangeGradient.stops[1].color = "#F5F5F5" // 改变第二个颜色

                            }

                            if(messageField.text.trim().length === 0){
                                messageField.focus = false
                            }
                            //修改输入框的边框颜色及焦点状态
                            if(chat.tabViewString === "AllCommand"){
                                if(messageField.text.trim().length === 0 && !imagePreviewShowRow.visible){
                                    //inputRectange.border.color = "#F5F5F5"
                                    inputRectangeGradient.stops[0].color = "#F5F5F5" // 改变第一个颜色
                                    inputRectangeGradient.stops[1].color = "#F5F5F5" // 改变第二个颜色
                                    messageField.focus = false
                                }
                            }
                        }
                        // 监控上传图片预览变化
                        onImagePreviewSrcChanged: function() {
                            // 判断选择了操作指令,图片预览,文档预览有一项存在,则边框颜色激活
                            if(inputRectange.activeCommand !== "" || inputRectange.imagePreviewSrc !== "" || inputRectange.documentPreviewName !== "" || messageField.text.trim().length > 0){
                                //inputRectange.border.color = "#3790FA"
                                inputRectangeGradient.stops[0].color = "#E85CFF" // 改变第一个颜色
                                inputRectangeGradient.stops[1].color = "#3790FA" // 改变第二个颜色
                            }else{
                                //inputRectange.border.color = "#F5F5F5"
                                inputRectangeGradient.stops[0].color = "#F5F5F5" // 改变第一个颜色
                                inputRectangeGradient.stops[1].color = "#F5F5F5" // 改变第二个颜色
                            }
                        }
                        // 监控上传文档预览变化
                        onDocumentPreviewNameChanged: function() {
                            // 判断选择了操作指令,图片预览,文档预览有一项存在,则边框颜色激活
                            if(inputRectange.activeCommand !== "" || inputRectange.imagePreviewSrc !== "" || inputRectange.documentPreviewName !== "" || messageField.text.trim().length > 0){
                                //inputRectange.border.color = "#3790FA"
                                inputRectangeGradient.stops[0].color = "#E85CFF" // 改变第一个颜色
                                inputRectangeGradient.stops[1].color = "#3790FA" // 改变第二个颜色
                            }else{
                                //inputRectange.border.color = "#F5F5F5"
                                inputRectangeGradient.stops[0].color = "#F5F5F5" // 改变第一个颜色
                                inputRectangeGradient.stops[1].color = "#F5F5F5" // 改变第二个颜色
                            }
                        }
                    }
                }
            }
        }
    }

    // 遮罩层
    Rectangle {
        id: commandShowRet
        width: parent.width
        height: parent.height - bottomArea.height
        color: Qt.rgba(0/255, 0/255, 0/255, 0.2)
        visible: chat.tabViewString === "AllCommand" // 初始时遮罩层不可见
        z: 1 // 确保遮罩层在其他组件之上

        // 阻止底层点击的 MouseArea
        MouseArea {
            anchors.fill: parent
            hoverEnabled: true
            acceptedButtons: Qt.RightButton | Qt.LeftButton
            // 使用 WheelHandler 来忽略滚轮事件
            onWheel: {
                // 阻止事件传播
                wheel.accepted = true
            }
            onClicked: {
                closeCommand()
            }
        }
    }
    Timer {
        // 用于解决GIT图慢问题
        id: moveGIFTimer
        interval: 100
        repeat: false   // 设置定时器只执行一次
        running: false   // 设置定时器启动
        onTriggered: {
            // 定时器触发后执行的代码
            listView.positionViewAtEnd()
        }
    }

    Timer {
        // 用于解决内容高度变化时，滚动条在最下方是不会自动滚动问题
        id: moveCommonTimer
        interval: 10
        repeat: false   // 设置定时器只执行一次
        running: false   // 设置定时器启动
        onTriggered: {
            // 定时器触发后执行的代码
            listView.positionViewAtEnd()
        }
    }
    Timer {
        // 用于解决内容高度变化时，滚动条在最下方是不会自动滚动问题
        id: stopReplyTimer
        interval: 100
        repeat: true
        running: false   // 设置定时器启动
        onTriggered: {
            // 定时检查isReplying状态
            //console.log("stopReplyTimer onTriggered----isReplying: " + isReplying)
            if (!isReplying) {
                // 如果isReplying为false，则发送消息
                stopReplyTimer.running = false;  // 停止定时器

                var inputText = messageField.text
                //modify:
                if (listModel.count > 0) {
                    var lastMsg = listModel.get(listModel.count - 1)
                    lastMsg.isRefreshed = true
                }
                var msgHeadList = {
                msgHead: inputRectange.activeCommand,
                promptId: inputRectange.activeCommandID,
                };
                var jsonMsgHead = JSON.stringify(msgHeadList)
                moveCommonTimer.running = true
    //            if (listView.preIndex >= 0 && listView.preIndex < listModel.count) {
    //                // 发送消息前需要停止朗读
    //                msgPane.onPauseRead();
    //                listModel.get(listView.preIndex).showRead = true;
    //            }
                if(!(messageField.text.length === 1 && messageField.text === "/")){
                    var retJsonString = msgPane.onSendMsg(jsonMsgHead, messageField.text)
                    var retJsonObject = JSON.parse(retJsonString);
                    isReplying = retJsonObject['isReplying'] !== undefined ? retJsonObject['isReplying'] : false
                    messageField.text = ""
                    inputRectange.activeCommand = ""
                    inputRectange.activeCommandID = -1
                }
                if(messageField.text.length === 1 && messageField.text === "/"){
                    messageField.text = ""
                }
                chat.tabViewString = "Command"
            }
        }
    }

    Component.onCompleted: {
        //console.log("主页面已加载完成")
        // 初始化头像和用户名
        msgPane.initCurrentUser()
    }



    property int remainingTime: 30 // 倒计时时间
    function startCountDown() {
//         console.log("111111111倒计时" + remainingTime)
        if (remainingTime > 0) {
            remainingTime--; // 倒计时减少

            if (remainingTime <= 5 && remainingTime > 0) {
                voiceText.text = qsTr("%1 seconds remaining").arg(remainingTime);
            } else if (remainingTime === 0) {
                voiceStopButtonMouseArea.stopVoiceInput();
            }
        }
    }

    // 启动计时器的函数（比如按钮点击或其他事件）
    function startTimer() {
        remainingTime = 30; // 重置倒计时
        countDownTimer.start(); // 启动计时器
        msgPane.onSpeechModeChanged(speechMode);
    }

}
