| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391 |
- import QtQuick
- import QtQuick.Controls
- import QtQuick.Layouts
- Item {
- id: materialchecksign
- x: 290
- y: 130
- width: 1600
- height: 920
- property string imagePath : "image/png";
- property string imageData : "";
- signal signal_postCheckSign(int planId, string path);
- PromptInfo
- {
- id: materialchecksign_prompt_info;
- }
- onVisibleChanged: {
- if (materialchecksign.visible === true)
- {
- proThread.moveCursorTo(0, 0);
- // 如果图片Base64为空字符
- if (imageData === "") {
- materialchecksign_btn_reset.visible = false;
- materialchecksign_btn_confirm.visible = true;
- materialchecksign_btn_purge.visible = true;
- materialchecksign_mouseArea.enabled = true;
- materialchecksign_image_sign.source = imageData;
- }
- else
- {
- materialchecksign_btn_reset.visible = true;
- materialchecksign_btn_confirm.visible = false;
- materialchecksign_btn_purge.visible = false;
- materialchecksign_mouseArea.enabled = false;
- materialchecksign_image_sign.source = imageData;
- }
- }
- else
- {
- materialchecksign_canvas.clear();
- }
- }
- // 确认操作弹出框
- Dialog {
- id: materialchecksign_dialog_confirm
- title: "操作确认"
- x: parent.width / 2 - width / 2
- y: parent.height / 2 - height / 2
- width: 600
- height: 400
- clip: true
- modal: true
- // 自定义背景(带圆角)
- background: Rectangle {
- color: "white"
- clip: true
- }
- // 自定义标题栏
- header: Rectangle {
- x: 0
- y: 0
- width: parent.width
- height: 50 // 设置标题栏高度
- color: "#ff3968e9" // 设置标题栏背景色
- // 标题文本
- Text {
- x: 20
- y: 0
- width: 80
- height: 50 // 设置标题栏高度
- text: materialchecksign_dialog_confirm.title
- font.pixelSize: 20
- horizontalAlignment: Text.AlignLeft
- verticalAlignment: Text.AlignVCenter
- color: "white"
- }
- }
- contentItem: Rectangle {
- x: 0
- y: 0
- width: parent.width
- height: 200
- color: "white"
- Text {
- width: parent.width
- height: 200
- text: "确定要保存签名吗?"
- font.pixelSize: 30
- horizontalAlignment: Text.AlignHCenter
- verticalAlignment: Text.AlignVCenter
- }
- }
- // 自定义 DialogButtonBox
- DialogButtonBox {
- id: materialcheckplan_buttonBox
- x: 0
- y: 250
- width: parent.width
- height: 100
- // 自定义按钮
- Button {
- implicitWidth: 120
- implicitHeight: 50
- text: "确认"
- background: Rectangle {
- color: "green"
- radius: 5
- }
- contentItem: Text {
- text: parent.text
- font.pixelSize: 30
- color: "white"
- horizontalAlignment: Text.AlignHCenter
- verticalAlignment: Text.AlignVCenter
- }
- onClicked: {
- var dataUrl = materialchecksign_canvas.toDataURL(imagePath);
- signal_postCheckSign(materialCheckPlan.planId, dataUrl); // 检查签名
- materialchecksign_dialog_confirm.close()
- }
- }
- Button {
- implicitWidth: 120
- implicitHeight: 50
- text: "取消"
- background: Rectangle {
- color: "red"
- radius: 5
- }
- contentItem: Text {
- text: parent.text
- font.pixelSize: 30
- color: "white"
- horizontalAlignment: Text.AlignHCenter
- verticalAlignment: Text.AlignVCenter
- }
- onClicked: {
- materialchecksign_dialog_confirm.reject()
- }
- }
- }
- }
- // 保存
- Button {
- id: materialchecksign_btn_confirm
- x: 928
- y: 835
- width: 192
- height: 75
- background: Rectangle {
- color: "#ff9900"
- radius: 10 // 可选,设置圆角
- }
- text: qsTr("保存")
- font.pixelSize: 30
- palette.buttonText: "white" // 设置字体颜色为绿色
- Connections {
- target: materialchecksign_btn_confirm
- onClicked: {
- if (materialchecksign_canvas.pathPoints.length === 0)
- {
- }
- else
- {
- materialchecksign_dialog_confirm.open();
- }
- }
- }
- }
- // 重新签名
- Button {
- id: materialchecksign_btn_reset
- x: 1168
- y: 835
- width: 192
- height: 75
- background: Rectangle {
- color: "#ff0000"
- radius: 10
- }
- text: qsTr("重新签名")
- font.pixelSize: 30
- palette.buttonText: "white" // 设置字体颜色为绿色
- Connections {
- target: materialchecksign_btn_reset
- onClicked: {
- materialchecksign_btn_reset.visible = false;
- materialchecksign_btn_confirm.visible = true;
- materialchecksign_btn_purge.visible = true;
- materialchecksign_mouseArea.enabled = true;
- materialchecksign_image_sign.source = "";
- }
- }
- }
- // 清除
- Button {
- id: materialchecksign_btn_purge
- x: 1168
- y: 835
- width: 192
- height: 75
- background: Rectangle {
- color: "#ff0000"
- radius: 10
- }
- text: qsTr("清除")
- font.pixelSize: 30
- palette.buttonText: "white" // 设置字体颜色为绿色
- Connections {
- target: materialchecksign_btn_purge
- onClicked: {
- materialchecksign_canvas.clear();
- }
- }
- }
- // 返回按钮
- Button {
- id: materialchecksign_btn_return
- x: 1408
- y: 835
- width: 192
- height: 75
- background: Rectangle {
- color: "#055eb3"
- radius: 10
- }
- text: qsTr("返回")
- font.pixelSize: 30
- palette.buttonText: "white" // 设置字体颜色为绿色
- Connections {
- target: materialchecksign_btn_return
- onClicked: {
- materialCheckSign.visible = false;
- materialCheckPlan.visible = true;
- }
- }
- }
- // 主体区域
- Rectangle {
- id: materialchecksign_rect_main
- width: 1600
- height: 800
- color: "#1affffff"
- radius: 20
- clip: true
- Canvas {
- anchors.fill: parent
- onPaint: {
- var ctx = getContext("2d")
- ctx.strokeStyle = "#ffffff"
- ctx.lineWidth = 3
- ctx.beginPath()
- ctx.moveTo(160, 20)
- ctx.lineTo(20, 20)
- ctx.lineTo(20, 160)
- ctx.stroke()
- ctx.beginPath()
- ctx.moveTo(160, 780)
- ctx.lineTo(20, 780)
- ctx.lineTo(20, 640)
- ctx.stroke()
- ctx.beginPath()
- ctx.moveTo(1580, 160)
- ctx.lineTo(1580, 20)
- ctx.lineTo(1440, 20)
- ctx.stroke()
- ctx.beginPath()
- ctx.moveTo(1580, 640)
- ctx.lineTo(1580, 780)
- ctx.lineTo(1440, 780)
- ctx.stroke()
- }
- }
- Canvas {
- id: materialchecksign_canvas
- anchors.fill: parent
- antialiasing: true
- // 存储绘制路径的点
- property var pathPoints: [] // QList<QList<QPointF>>
- // 开始绘制
- onPaint: {
- var ctx = getContext("2d")
- ctx.clearRect(0, 0, width, height) // 清空画布
- ctx.lineWidth = 10
- ctx.strokeStyle = "#ffffff"
- for (var j = 0; j < pathPoints.length; ++j)
- {
- if (pathPoints[j].length > 0) {
- ctx.beginPath()
- ctx.moveTo(pathPoints[j][0].x, pathPoints[j][0].y)
- for (var i = 0; i < pathPoints[j].length; i++) {
- ctx.lineTo(pathPoints[j][i].x, pathPoints[j][i].y)
- }
- ctx.stroke()
- }
- }
- }
- // 清空签名
- function clear() {
- pathPoints = []
- requestPaint()
- }
- }
- // MouseArea 用于监听鼠标事件
- MouseArea {
- id: materialchecksign_mouseArea
- anchors.fill: parent
- onPressed: {
- var index = materialchecksign_canvas.pathPoints.length;
- materialchecksign_canvas.pathPoints[index] = [];
- materialchecksign_canvas.pathPoints[index].push(Qt.point(mouse.x, mouse.y));
- materialchecksign_canvas.requestPaint();
- }
- onPositionChanged: {
- if (pressed) {
- var index = materialchecksign_canvas.pathPoints.length - 1;
- materialchecksign_canvas.pathPoints[index].push(Qt.point(mouse.x, mouse.y));
- materialchecksign_canvas.requestPaint();
- }
- }
- }
- Image {
- id: materialchecksign_image_sign;
- anchors.fill: parent
- }
- }
- function slot_postCheckSign(data)
- {
- var jsonObjRoot = JSON.parse(data);
- if (jsonObjRoot.code === 200)
- {
- // materialchecksign_prompt_info.promptInfoTimeout = 3;
- // materialchecksign_prompt_info.promptInfoText = jsonObjRoot.msg;
- // materialchecksign_prompt_info.promptInfoIcon = "qrc:/png/error.png"
- // materialchecksign_prompt_info.promptInfoColor = "#6600ff00"
- materialCheckSign.visible = false;
- materialCheckPlan.visible = true;
- }
- else
- {
- materialchecksign_prompt_info.promptInfoTimeout = 3;
- materialchecksign_prompt_info.promptInfoText = jsonObjRoot.msg;
- materialchecksign_prompt_info.promptInfoIcon = "qrc:/png/error.png"
- materialchecksign_prompt_info.promptInfoColor = "#66ea3a0e"
- }
- }
- }
|