MaterialInstructions.qml 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  1. import QtQuick
  2. import QtQuick.Controls
  3. import QtQuick.Layouts
  4. import QtQuick.Pdf
  5. import QtMultimedia
  6. import Qt.labs.platform
  7. import com.InteractiveTask 1.0
  8. Item {
  9. id: materialinstructions
  10. x: 290
  11. y: 130
  12. width: 1600
  13. height: 920
  14. signal signal_get()
  15. signal signal_pdf_click(string text)
  16. property string strMaterialTypeGet: ""
  17. property string strInstructionsGet: ""
  18. property string strJsonData: "";
  19. property string strInstructionsTitle: ""
  20. property bool bResetTimer: false
  21. Connections {
  22. target: materialinstructions
  23. onVisibleChanged: {
  24. if (materialinstructions.visible === true)
  25. {
  26. proThread.moveCursorTo(0, 0);
  27. // materialInstructionsModel.clear();
  28. // materialsellistInstructionsModel.clear();
  29. // signal_get();
  30. var taskType = InteractiveTask.TypeHttpGet_getInstructionsList;
  31. interactiveCore.appendTask(taskType, null, (data)=>{
  32. strJsonData = data;
  33. callback_refresh_view("全部");
  34. });
  35. }
  36. else
  37. {
  38. materialinstructionsPdf.visible = false;
  39. materialinstructionsVideo.visible = false;
  40. }
  41. }
  42. }
  43. // 标题表格
  44. ListModel {
  45. id: materialsellistInstructionsModel
  46. }
  47. // 主体表格
  48. ListModel {
  49. id: materialInstructionsModel
  50. }
  51. // 返回按钮
  52. Button {
  53. id: button_return_instructions
  54. x: 1408
  55. y: 835
  56. width: 192
  57. height: 75
  58. background: Rectangle {
  59. color: "#055eb3" // 设置背景为透明
  60. radius: 10 // 可选,设置圆角
  61. }
  62. text: qsTr("返回")
  63. font.pixelSize: 30
  64. palette.buttonText: "white" // 设置字体颜色为绿色
  65. Connections {
  66. target: button_return_instructions
  67. onClicked: {
  68. materialInstructions.visible = false;
  69. materialSelmodel.visible = true;
  70. mainScreen.resetLogin_timeout();
  71. }
  72. }
  73. }
  74. Rectangle {
  75. id: materialsel11
  76. width: 1600
  77. height: 800
  78. color: "#272b7ae9"
  79. radius: 20
  80. clip: true
  81. Rectangle {
  82. x: 50
  83. y: 100
  84. width: parent.width - 100
  85. height: parent.height - 100
  86. clip: true
  87. color: "#002b7ae9"
  88. GridView {
  89. width: parent.width
  90. height: parent.height
  91. cellWidth: 360 // 每个单元格的宽度,这里是平均分配宽度给5列
  92. cellHeight: 350 // 每个单元格的高度
  93. model: materialInstructionsModel
  94. delegate: Rectangle{
  95. width: 360
  96. height: 350
  97. color: "#00ffffff"
  98. Rectangle {
  99. x: 25
  100. y: 25
  101. width: 350
  102. height: 300
  103. color: model.color
  104. Image {
  105. x: 75
  106. y: 25
  107. width: 200
  108. height: 200
  109. visible: true
  110. source: model.png
  111. fillMode: Image.PreserveAspectFit
  112. }
  113. Text {
  114. x: 0
  115. y: 250
  116. width: parent.width
  117. height: 25
  118. visible: true
  119. text: model.instructionsTitle
  120. font.pixelSize: 28
  121. horizontalAlignment: Text.AlignHCenter
  122. verticalAlignment: Text.AlignVCenter
  123. color: "#ffffff"
  124. }
  125. MouseArea {
  126. anchors.fill: parent // 让MouseArea覆盖整个Image区域
  127. onClicked: {
  128. strInstructionsTitle = model.instructionsTitle;
  129. if (model.fileType === "0")
  130. {
  131. videoPlayer.source = model.fileUrl;
  132. materialinstructionsVideo.visible = true;
  133. }
  134. else if (model.fileType === "1")
  135. {
  136. signal_pdf_click(model.fileUrl);
  137. }
  138. mainScreen.resetLogin_timeout();
  139. }
  140. }
  141. }
  142. }
  143. }
  144. }
  145. Rectangle {
  146. id: materialselviewInstruction
  147. width: 1600
  148. height: 100 // 减去顶部圆角矩形的高度
  149. radius: 20
  150. clip: true
  151. color: "#8f2b7ae9"
  152. Grid {
  153. x: 50
  154. y: 0
  155. width: parent.width - 150
  156. height: parent.height
  157. visible: true
  158. verticalItemAlignment: Grid.AlignVCenter
  159. horizontalItemAlignment: Grid.AlignHCenter
  160. columns: 5
  161. spacing: 20
  162. Repeater {
  163. model: materialsellistInstructionsModel
  164. delegate: Rectangle {
  165. width: 250
  166. height: 100
  167. color: "#00ffffff"
  168. Image {
  169. x: 0
  170. y: 25
  171. width: 50
  172. height: 50
  173. visible: true
  174. source: model.icon
  175. fillMode: Image.PreserveAspectFit
  176. }
  177. Text {
  178. x: 55
  179. y: 25
  180. width: parent.width - 55
  181. height: 50
  182. visible: true
  183. text: model.name + "(" + model.count + ")";
  184. font.pixelSize: 25
  185. horizontalAlignment: Text.AlignHCenter
  186. verticalAlignment: Text.AlignVCenter
  187. color: "#ffffff"
  188. }
  189. Canvas {
  190. anchors.fill: parent
  191. visible: model.view
  192. onPaint: {
  193. var ctx = getContext("2d");
  194. ctx.lineWidth = 10; // 设置线的宽度
  195. ctx.strokeStyle = "skyblue"; // 设置线的颜色为白色
  196. ctx.beginPath();
  197. ctx.moveTo(0, 90); // 直线的起点
  198. ctx.lineTo(parent.width, 90); // 直线的终点
  199. ctx.stroke(); // 绘制直线
  200. }
  201. }
  202. MouseArea {
  203. anchors.fill: parent // 让MouseArea覆盖整个Image区域
  204. onClicked: {
  205. callback_refresh_view(model.name)
  206. }
  207. }
  208. }
  209. }
  210. }
  211. Image {
  212. id: viewImage
  213. x: parent.width - 80
  214. y: 20
  215. width: 60
  216. height: 60
  217. source: "qrc:/png/right.png"
  218. fillMode: Image.PreserveAspectFit
  219. MouseArea {
  220. anchors.fill: parent // 让MouseArea覆盖整个Image区域
  221. onClicked: {
  222. var bIsUnfolding = (materialselviewInstruction.height === 100 ? true : false);
  223. if(bIsUnfolding)
  224. {
  225. viewImage.rotation = 90;
  226. materialselviewInstruction.height = 600;
  227. }
  228. else
  229. {
  230. viewImage.rotation = 0;
  231. materialselviewInstruction.height = 100;
  232. }
  233. mainScreen.resetLogin_timeout();
  234. }
  235. }
  236. }
  237. }
  238. }
  239. Timer {
  240. interval: 1000
  241. running: true
  242. repeat: true
  243. onTriggered: {
  244. if (bResetTimer)
  245. {
  246. mainScreen.resetLogin_timeout();
  247. }
  248. }
  249. }
  250. // pdf显示
  251. Rectangle
  252. {
  253. id: materialinstructionsPdf
  254. x:0
  255. y:0
  256. width: parent.width
  257. height: parent.height - 100
  258. color: "#ffffff"
  259. radius: 10 // 可选,设置圆角
  260. visible: false
  261. Rectangle {
  262. x:0
  263. y:0
  264. width: 1600
  265. height: 800
  266. color: "#ffffff"
  267. radius: 10 // 可选,设置圆角
  268. Connections {
  269. target: materialinstructionsPdf
  270. onVisibleChanged: {
  271. if (materialinstructionsPdf.visible === true)
  272. {
  273. bResetTimer = true;
  274. mainScreen.changeModel_text_Instructions(strInstructionsTitle);
  275. }
  276. else
  277. {
  278. bResetTimer = false;
  279. mainScreen.changeModel_text_Instructions("物资使用说明");
  280. }
  281. }
  282. }
  283. // pdf显示-pdf文档
  284. PdfDocument {
  285. id: pdfDocument
  286. }
  287. PdfPageView {
  288. id: pdfView
  289. document: pdfDocument
  290. anchors.top: parent.top
  291. anchors.bottom: parent.bottom
  292. // 左右居中
  293. anchors.horizontalCenter: parent.horizontalCenter
  294. clip: true
  295. Connections {
  296. target: pdfView
  297. onCurrentPageChanged: {
  298. pdfView.scaleToPage(pdfView.parent.width, pdfView.parent.height);
  299. }
  300. }
  301. Component.onCompleted: {
  302. pdfView.scaleToPage(pdfView.parent.width, pdfView.parent.height);
  303. }
  304. }
  305. Image {
  306. id: materialinstruction_image_pdf_left
  307. x: 20
  308. y: parent.height / 2 - 64
  309. width: 128
  310. height: 128
  311. opacity: 0.25
  312. source: "qrc:/png/pdf_left.png"
  313. fillMode: Image.PreserveAspectFit
  314. visible: true;
  315. }
  316. Image {
  317. id: materialinstruction_image_pdf_right
  318. x: parent.width - 20 - 128
  319. y: parent.height / 2 - 64
  320. width: 128
  321. height: 128
  322. opacity: 0.25
  323. source: "qrc:/png/pdf_right.png"
  324. fillMode: Image.PreserveAspectFit
  325. visible: true;
  326. }
  327. MouseArea {
  328. anchors.fill: parent
  329. hoverEnabled: true
  330. onWheel: {
  331. if (wheel.angleDelta.y > 0) {
  332. // 向上滚动 - 上一页
  333. if (pdfView.currentPage > 0) {
  334. pdfView.goToPage(pdfView.currentPage - 1)
  335. }
  336. } else {
  337. // 向下滚动 - 下一页
  338. if (pdfView.currentPage < pdfView.document.pageCount - 1) {
  339. pdfView.goToPage(pdfView.currentPage + 1)
  340. }
  341. }
  342. }
  343. onClicked:
  344. {
  345. if (mouse.x < parent.width / 2) {
  346. // 向上滚动 - 上一页
  347. if (pdfView.currentPage > 0) {
  348. pdfView.goToPage(pdfView.currentPage - 1)
  349. }
  350. } else {
  351. // 向下滚动 - 下一页
  352. if (pdfView.currentPage < pdfView.document.pageCount - 1) {
  353. pdfView.goToPage(pdfView.currentPage + 1)
  354. }
  355. }
  356. }
  357. }
  358. }
  359. Button {
  360. id: button_return_instructions_pdf
  361. x: 1408
  362. y: 835
  363. width: 192
  364. height: 75
  365. background: Rectangle {
  366. color: "#055eb3" // 设置背景为透明
  367. radius: 10 // 可选,设置圆角
  368. }
  369. text: qsTr("返回")
  370. font.pixelSize: 30
  371. palette.buttonText: "white" // 设置字体颜色为绿色
  372. Connections {
  373. target: button_return_instructions_pdf
  374. onClicked: {
  375. pdfDocument.source = "invalid_path";
  376. pdfView.document = pdfDocument;
  377. materialinstructionsPdf.visible = false;
  378. mainScreen.resetLogin_timeout();
  379. }
  380. }
  381. }
  382. }
  383. // mp4显示
  384. Rectangle
  385. {
  386. id: materialinstructionsVideo
  387. x:0
  388. y:0
  389. width: parent.width
  390. height: parent.height - 100
  391. color: "#000000"
  392. radius: 10 // 可选,设置圆角
  393. visible: false
  394. Connections {
  395. target: materialinstructionsVideo
  396. onVisibleChanged: {
  397. if (materialinstructionsVideo.visible === true)
  398. {
  399. bResetTimer = true;
  400. mainScreen.changeModel_text_Instructions(strInstructionsTitle);
  401. }
  402. else
  403. {
  404. bResetTimer = false;
  405. mainScreen.changeModel_text_Instructions("物资使用说明");
  406. }
  407. }
  408. }
  409. Video {
  410. id: videoPlayer
  411. anchors.fill: parent
  412. visible: true
  413. onPlaybackStateChanged: {
  414. if (videoPlayer.playbackState === MediaPlayer.PlayingState)
  415. {
  416. materialinstruction_image_video.visible = false;
  417. }
  418. else
  419. {
  420. materialinstruction_image_video.visible = true;
  421. }
  422. }
  423. }
  424. MouseArea {
  425. anchors.fill: parent
  426. onClicked: {
  427. if (videoPlayer.playbackState === MediaPlayer.PlayingState) {
  428. videoPlayer.pause()
  429. } else {
  430. videoPlayer.play()
  431. }
  432. }
  433. }
  434. Button {
  435. id: button_return_instructions_video
  436. x: 1408
  437. y: 835
  438. width: 192
  439. height: 75
  440. background: Rectangle {
  441. color: "#055eb3" // 设置背景为透明
  442. radius: 10 // 可选,设置圆角
  443. }
  444. text: qsTr("返回")
  445. font.pixelSize: 30
  446. palette.buttonText: "white" // 设置字体颜色为绿色
  447. Connections {
  448. target: button_return_instructions_video
  449. onClicked: {
  450. videoPlayer.source = "";
  451. materialinstructionsVideo.visible = false;
  452. mainScreen.resetLogin_timeout();
  453. }
  454. }
  455. }
  456. Slider {
  457. id: progressBar
  458. anchors {
  459. left: parent.left
  460. right: parent.right
  461. bottom: parent.bottom
  462. margins: 10
  463. }
  464. from: 0
  465. to: videoPlayer.duration
  466. value: videoPlayer.position
  467. onMoved: {
  468. videoPlayer.seek(progressBar.value)
  469. }
  470. }
  471. Image {
  472. id: materialinstruction_image_video
  473. anchors.centerIn: parent
  474. width: 128
  475. height: 128
  476. source: "qrc:/png/play.png"
  477. fillMode: Image.PreserveAspectFit
  478. visible: true;
  479. }
  480. }
  481. function slot_pdf_relay(name)
  482. {
  483. pdfDocument.source = ""
  484. pdfDocument.source = "file:///" + name
  485. materialinstructionsPdf.visible = true
  486. pdfView.goToPage(pdfView.currentPage + 1);
  487. pdfView.goToPage(0);
  488. }
  489. function callback_refresh_view(title)
  490. {
  491. materialInstructionsModel.clear();
  492. materialsellistInstructionsModel.clear();
  493. var jsonObjRoot = JSON.parse(strJsonData);
  494. if (jsonObjRoot.code === 200)
  495. {
  496. var jsonArrData = jsonObjRoot.data;
  497. for (var i = 0; i < jsonArrData.length; ++i)
  498. {
  499. var jsonObjData = jsonArrData[i];
  500. var materialsTypeId = jsonObjData.materialsTypeId;
  501. var materialsTypeName = jsonObjData.materialsTypeName;
  502. var materialsTypeIcon = jsonObjData.materialsTypeIcon;
  503. var number = jsonObjData.number;
  504. if (materialsTypeName === "全部")
  505. {
  506. materialsTypeIcon = "qrc:/png/allsel.png";
  507. }
  508. materialsellistInstructionsModel.append({
  509. count: number,
  510. icon: materialsTypeIcon,
  511. name: materialsTypeName,
  512. view: materialsTypeName === title ? true : false
  513. });
  514. if (materialsTypeName !== title)
  515. {
  516. continue;
  517. }
  518. var jsonArrInstructions = jsonObjData.instructions;
  519. for (var j = 0; j < jsonArrInstructions.length; ++j)
  520. {
  521. var jsonObjInstructions = jsonArrInstructions[j];
  522. var fileUrl = jsonObjInstructions.fileUrl;
  523. var fileType = jsonObjInstructions.fileType;
  524. var instructionsId = jsonObjInstructions.instructionsId;
  525. var instructionsTitle = jsonObjInstructions.instructionsTitle;
  526. var png = "";
  527. if (fileType === "0")
  528. {
  529. png = "qrc:/png/videoImg.png";
  530. }
  531. else if (fileType === "1")
  532. {
  533. png = "qrc:/png/pdfImg.png";
  534. }
  535. materialInstructionsModel.append({
  536. instructionsTitle:instructionsTitle,
  537. png:png,
  538. fileType: fileType,
  539. fileUrl: fileUrl,
  540. color: "#8fffffff"
  541. });
  542. }
  543. }
  544. }
  545. }
  546. // 获取使用说明列表
  547. function slot_materialTypeGet(data)
  548. {
  549. strMaterialTypeGet = data;
  550. }
  551. // 获取使用说明列表
  552. function slot_instructionsGet(data)
  553. {
  554. strInstructionsGet = data;
  555. build_view("全部");
  556. }
  557. // 构建表头List
  558. function build_view(name)
  559. {
  560. var listStr = [];
  561. var mapData = {};
  562. materialInstructionsModel.clear();
  563. materialsellistInstructionsModel.clear();
  564. var jsonObjInstructionsRoot = JSON.parse(strInstructionsGet);
  565. if (jsonObjInstructionsRoot.code === 200)
  566. {
  567. var jsonObjInstructionsData = jsonObjInstructionsRoot.data;
  568. var jsonArrInstructionsRecords = jsonObjInstructionsData.records;
  569. for (var i = 0; i < jsonArrInstructionsRecords.length; ++i)
  570. {
  571. var jsonObjInstructions = jsonArrInstructionsRecords[i];
  572. var fileType = jsonObjInstructions.fileType;
  573. var fileUrl = jsonObjInstructions.fileUrl;
  574. var strPath = fileUrl.substring(0, fileUrl.lastIndexOf('/') + 1);
  575. var strName = fileUrl.substring(fileUrl.lastIndexOf('/') + 1);
  576. var png = "";
  577. if (fileType === "0")
  578. {
  579. png = "qrc:/png/videoImg.png";
  580. }
  581. else if (fileType === "1")
  582. {
  583. png = "qrc:/png/pdfImg.png";
  584. }
  585. // 获取标题
  586. var instructionsTitle = jsonObjInstructions.instructionsTitle;
  587. var materialsTypeName = jsonObjInstructions.materialsTypeName;
  588. if (materialsTypeName === name || name === "全部")
  589. {
  590. materialInstructionsModel.append({instructionsTitle:instructionsTitle, png:png, fileType: fileType, fileUrl: fileUrl, strPath:strPath, strName: strName, color: "#8fffffff"});
  591. }
  592. if(listStr.indexOf(materialsTypeName) === -1)
  593. {
  594. listStr.push(materialsTypeName);
  595. mapData[materialsTypeName] = 1;
  596. }
  597. else
  598. {
  599. mapData[materialsTypeName]++;
  600. }
  601. }
  602. }
  603. // 读取类型
  604. var jsonObjMaterialTypeRoot = JSON.parse(strMaterialTypeGet);
  605. if (jsonObjMaterialTypeRoot.code === 200)
  606. {
  607. var jsonObjMaterialTypeData = jsonObjMaterialTypeRoot.data;
  608. var jsonArrMaterialTypeRecords = jsonObjMaterialTypeData.records;
  609. var count = 0;
  610. for (var j = 0; j < jsonArrMaterialTypeRecords.length; ++j)
  611. {
  612. var jsonObjMaterialType = jsonArrMaterialTypeRecords[j];
  613. var typeName = jsonObjMaterialType.materialsTypeName;
  614. var typeIcon = jsonObjMaterialType.materialsTypeIcon;
  615. if (listStr.indexOf(typeName) !== -1)
  616. {
  617. var countView = typeName + "(" + mapData[typeName] + ")";
  618. materialsellistInstructionsModel.append({count: countView,icon: typeIcon, name: typeName, view: name === typeName ? true : false});
  619. count += mapData[typeName];
  620. }
  621. }
  622. var countAllView = "全部" + "(" + count + ")";
  623. materialsellistInstructionsModel.insert(0, {count: countAllView, icon: "qrc:/png/allsel.png", name: "全部", view: name === "全部" ? true : false});
  624. }
  625. }
  626. }