useCanvas.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. "use strict";
  2. const common_vendor = require("../../../../common/vendor.js");
  3. const sheep_components_sShareModal_canvasPoster_poster_index = require("./poster/index.js");
  4. async function useCanvas(options, vm) {
  5. const width = options.width;
  6. const qsc = new common_vendor.QSCanvas(
  7. {
  8. canvasId: options.canvasId,
  9. width: options.width,
  10. height: options.height,
  11. setCanvasWH: (canvas) => {
  12. options.height = canvas.height;
  13. }
  14. },
  15. vm
  16. );
  17. let drawer = sheep_components_sShareModal_canvasPoster_poster_index.getPosterData(options);
  18. const background = await qsc.drawImg({
  19. type: "image",
  20. val: drawer.background,
  21. x: 0,
  22. y: 0,
  23. width,
  24. mode: "widthFix",
  25. zIndex: 0
  26. });
  27. await qsc.updateCanvasWH({
  28. width: background.width,
  29. height: background.bottom
  30. });
  31. let list = drawer.list;
  32. for (let i = 0; i < list.length; i++) {
  33. let item = list[i];
  34. if (item.type === "text") {
  35. await qsc.drawText(item);
  36. }
  37. if (item.type === "image") {
  38. if (item.d) {
  39. qsc.setCircle({
  40. x: item.x,
  41. y: item.y,
  42. d: item.d,
  43. clip: true
  44. });
  45. }
  46. if (item.r) {
  47. qsc.setRect({
  48. x: item.x,
  49. y: item.y,
  50. height: item.height,
  51. width: item.width,
  52. r: item.r,
  53. clip: true
  54. });
  55. }
  56. await qsc.drawImg(item);
  57. qsc.restore();
  58. }
  59. if (item.type === "qrcode") {
  60. await qsc.drawQrCode(item);
  61. }
  62. }
  63. await qsc.draw();
  64. setTimeout(async () => {
  65. options.src = await qsc.toImage();
  66. }, 100);
  67. return options;
  68. }
  69. exports.useCanvas = useCanvas;