MaterialCheckSign.qml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. import QtQuick
  2. import QtQuick.Controls
  3. import QtQuick.Layouts
  4. Item {
  5. id: materialchecksign
  6. x: 290
  7. y: 130
  8. width: 1600
  9. height: 920
  10. property string imagePath : "image/png";
  11. property string imageData : "";
  12. signal signal_postCheckSign(int planId, string path);
  13. PromptInfo
  14. {
  15. id: materialchecksign_prompt_info;
  16. }
  17. onVisibleChanged: {
  18. if (materialchecksign.visible === true)
  19. {
  20. proThread.moveCursorTo(0, 0);
  21. // 如果图片Base64为空字符
  22. if (imageData === "") {
  23. materialchecksign_btn_reset.visible = false;
  24. materialchecksign_btn_confirm.visible = true;
  25. materialchecksign_btn_purge.visible = true;
  26. materialchecksign_mouseArea.enabled = true;
  27. materialchecksign_image_sign.source = imageData;
  28. }
  29. else
  30. {
  31. materialchecksign_btn_reset.visible = true;
  32. materialchecksign_btn_confirm.visible = false;
  33. materialchecksign_btn_purge.visible = false;
  34. materialchecksign_mouseArea.enabled = false;
  35. materialchecksign_image_sign.source = imageData;
  36. }
  37. }
  38. else
  39. {
  40. materialchecksign_canvas.clear();
  41. }
  42. }
  43. // 确认操作弹出框
  44. Dialog {
  45. id: materialchecksign_dialog_confirm
  46. title: "操作确认"
  47. x: parent.width / 2 - width / 2
  48. y: parent.height / 2 - height / 2
  49. width: 600
  50. height: 400
  51. clip: true
  52. modal: true
  53. // 自定义背景(带圆角)
  54. background: Rectangle {
  55. color: "white"
  56. clip: true
  57. }
  58. // 自定义标题栏
  59. header: Rectangle {
  60. x: 0
  61. y: 0
  62. width: parent.width
  63. height: 50 // 设置标题栏高度
  64. color: "#ff3968e9" // 设置标题栏背景色
  65. // 标题文本
  66. Text {
  67. x: 20
  68. y: 0
  69. width: 80
  70. height: 50 // 设置标题栏高度
  71. text: materialchecksign_dialog_confirm.title
  72. font.pixelSize: 20
  73. horizontalAlignment: Text.AlignLeft
  74. verticalAlignment: Text.AlignVCenter
  75. color: "white"
  76. }
  77. }
  78. contentItem: Rectangle {
  79. x: 0
  80. y: 0
  81. width: parent.width
  82. height: 200
  83. color: "white"
  84. Text {
  85. width: parent.width
  86. height: 200
  87. text: "确定要保存签名吗?"
  88. font.pixelSize: 30
  89. horizontalAlignment: Text.AlignHCenter
  90. verticalAlignment: Text.AlignVCenter
  91. }
  92. }
  93. // 自定义 DialogButtonBox
  94. DialogButtonBox {
  95. id: materialcheckplan_buttonBox
  96. x: 0
  97. y: 250
  98. width: parent.width
  99. height: 100
  100. // 自定义按钮
  101. Button {
  102. implicitWidth: 120
  103. implicitHeight: 50
  104. text: "确认"
  105. background: Rectangle {
  106. color: "green"
  107. radius: 5
  108. }
  109. contentItem: Text {
  110. text: parent.text
  111. font.pixelSize: 30
  112. color: "white"
  113. horizontalAlignment: Text.AlignHCenter
  114. verticalAlignment: Text.AlignVCenter
  115. }
  116. onClicked: {
  117. var dataUrl = materialchecksign_canvas.toDataURL(imagePath);
  118. signal_postCheckSign(materialCheckPlan.planId, dataUrl); // 检查签名
  119. materialchecksign_dialog_confirm.close()
  120. }
  121. }
  122. Button {
  123. implicitWidth: 120
  124. implicitHeight: 50
  125. text: "取消"
  126. background: Rectangle {
  127. color: "red"
  128. radius: 5
  129. }
  130. contentItem: Text {
  131. text: parent.text
  132. font.pixelSize: 30
  133. color: "white"
  134. horizontalAlignment: Text.AlignHCenter
  135. verticalAlignment: Text.AlignVCenter
  136. }
  137. onClicked: {
  138. materialchecksign_dialog_confirm.reject()
  139. }
  140. }
  141. }
  142. }
  143. // 保存
  144. Button {
  145. id: materialchecksign_btn_confirm
  146. x: 928
  147. y: 835
  148. width: 192
  149. height: 75
  150. background: Rectangle {
  151. color: "#ff9900"
  152. radius: 10 // 可选,设置圆角
  153. }
  154. text: qsTr("保存")
  155. font.pixelSize: 30
  156. palette.buttonText: "white" // 设置字体颜色为绿色
  157. Connections {
  158. target: materialchecksign_btn_confirm
  159. onClicked: {
  160. if (materialchecksign_canvas.pathPoints.length === 0)
  161. {
  162. }
  163. else
  164. {
  165. materialchecksign_dialog_confirm.open();
  166. }
  167. }
  168. }
  169. }
  170. // 重新签名
  171. Button {
  172. id: materialchecksign_btn_reset
  173. x: 1168
  174. y: 835
  175. width: 192
  176. height: 75
  177. background: Rectangle {
  178. color: "#ff0000"
  179. radius: 10
  180. }
  181. text: qsTr("重新签名")
  182. font.pixelSize: 30
  183. palette.buttonText: "white" // 设置字体颜色为绿色
  184. Connections {
  185. target: materialchecksign_btn_reset
  186. onClicked: {
  187. materialchecksign_btn_reset.visible = false;
  188. materialchecksign_btn_confirm.visible = true;
  189. materialchecksign_btn_purge.visible = true;
  190. materialchecksign_mouseArea.enabled = true;
  191. materialchecksign_image_sign.source = "";
  192. }
  193. }
  194. }
  195. // 清除
  196. Button {
  197. id: materialchecksign_btn_purge
  198. x: 1168
  199. y: 835
  200. width: 192
  201. height: 75
  202. background: Rectangle {
  203. color: "#ff0000"
  204. radius: 10
  205. }
  206. text: qsTr("清除")
  207. font.pixelSize: 30
  208. palette.buttonText: "white" // 设置字体颜色为绿色
  209. Connections {
  210. target: materialchecksign_btn_purge
  211. onClicked: {
  212. materialchecksign_canvas.clear();
  213. }
  214. }
  215. }
  216. // 返回按钮
  217. Button {
  218. id: materialchecksign_btn_return
  219. x: 1408
  220. y: 835
  221. width: 192
  222. height: 75
  223. background: Rectangle {
  224. color: "#055eb3"
  225. radius: 10
  226. }
  227. text: qsTr("返回")
  228. font.pixelSize: 30
  229. palette.buttonText: "white" // 设置字体颜色为绿色
  230. Connections {
  231. target: materialchecksign_btn_return
  232. onClicked: {
  233. materialCheckSign.visible = false;
  234. materialCheckPlan.visible = true;
  235. }
  236. }
  237. }
  238. // 主体区域
  239. Rectangle {
  240. id: materialchecksign_rect_main
  241. width: 1600
  242. height: 800
  243. color: "#1affffff"
  244. radius: 20
  245. clip: true
  246. Canvas {
  247. anchors.fill: parent
  248. onPaint: {
  249. var ctx = getContext("2d")
  250. ctx.strokeStyle = "#ffffff"
  251. ctx.lineWidth = 3
  252. ctx.beginPath()
  253. ctx.moveTo(160, 20)
  254. ctx.lineTo(20, 20)
  255. ctx.lineTo(20, 160)
  256. ctx.stroke()
  257. ctx.beginPath()
  258. ctx.moveTo(160, 780)
  259. ctx.lineTo(20, 780)
  260. ctx.lineTo(20, 640)
  261. ctx.stroke()
  262. ctx.beginPath()
  263. ctx.moveTo(1580, 160)
  264. ctx.lineTo(1580, 20)
  265. ctx.lineTo(1440, 20)
  266. ctx.stroke()
  267. ctx.beginPath()
  268. ctx.moveTo(1580, 640)
  269. ctx.lineTo(1580, 780)
  270. ctx.lineTo(1440, 780)
  271. ctx.stroke()
  272. }
  273. }
  274. Canvas {
  275. id: materialchecksign_canvas
  276. anchors.fill: parent
  277. antialiasing: true
  278. // 存储绘制路径的点
  279. property var pathPoints: [] // QList<QList<QPointF>>
  280. // 开始绘制
  281. onPaint: {
  282. var ctx = getContext("2d")
  283. ctx.clearRect(0, 0, width, height) // 清空画布
  284. ctx.lineWidth = 10
  285. ctx.strokeStyle = "#ffffff"
  286. for (var j = 0; j < pathPoints.length; ++j)
  287. {
  288. if (pathPoints[j].length > 0) {
  289. ctx.beginPath()
  290. ctx.moveTo(pathPoints[j][0].x, pathPoints[j][0].y)
  291. for (var i = 0; i < pathPoints[j].length; i++) {
  292. ctx.lineTo(pathPoints[j][i].x, pathPoints[j][i].y)
  293. }
  294. ctx.stroke()
  295. }
  296. }
  297. }
  298. // 清空签名
  299. function clear() {
  300. pathPoints = []
  301. requestPaint()
  302. }
  303. }
  304. // MouseArea 用于监听鼠标事件
  305. MouseArea {
  306. id: materialchecksign_mouseArea
  307. anchors.fill: parent
  308. onPressed: {
  309. var index = materialchecksign_canvas.pathPoints.length;
  310. materialchecksign_canvas.pathPoints[index] = [];
  311. materialchecksign_canvas.pathPoints[index].push(Qt.point(mouse.x, mouse.y));
  312. materialchecksign_canvas.requestPaint();
  313. }
  314. onPositionChanged: {
  315. if (pressed) {
  316. var index = materialchecksign_canvas.pathPoints.length - 1;
  317. materialchecksign_canvas.pathPoints[index].push(Qt.point(mouse.x, mouse.y));
  318. materialchecksign_canvas.requestPaint();
  319. }
  320. }
  321. }
  322. Image {
  323. id: materialchecksign_image_sign;
  324. anchors.fill: parent
  325. }
  326. }
  327. function slot_postCheckSign(data)
  328. {
  329. var jsonObjRoot = JSON.parse(data);
  330. if (jsonObjRoot.code === 200)
  331. {
  332. // materialchecksign_prompt_info.promptInfoTimeout = 3;
  333. // materialchecksign_prompt_info.promptInfoText = jsonObjRoot.msg;
  334. // materialchecksign_prompt_info.promptInfoIcon = "qrc:/png/error.png"
  335. // materialchecksign_prompt_info.promptInfoColor = "#6600ff00"
  336. materialCheckSign.visible = false;
  337. materialCheckPlan.visible = true;
  338. }
  339. else
  340. {
  341. materialchecksign_prompt_info.promptInfoTimeout = 3;
  342. materialchecksign_prompt_info.promptInfoText = jsonObjRoot.msg;
  343. materialchecksign_prompt_info.promptInfoIcon = "qrc:/png/error.png"
  344. materialchecksign_prompt_info.promptInfoColor = "#66ea3a0e"
  345. }
  346. }
  347. }