SEditorImageAdjust.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. import { ref as c, reactive as _, computed as b, watch as f, resolveComponent as h, openBlock as O, createBlock as S, withCtx as o, createVNode as i, createTextVNode as $, toDisplayString as y } from "vue";
  2. import { a6 as A } from "./index2.js";
  3. import { _ as B } from "./index10.js";
  4. const j = {
  5. __name: "SEditorImageAdjust",
  6. emits: ["confirm"],
  7. setup(D, { expose: k, emit: C }) {
  8. const R = C, r = c(!1), m = c(null), p = c(null), n = _({ width: 0, height: 0 }), e = _({ scale: "1", width: 0, height: 0 }), x = [
  9. { label: window.$l("原图比例"), value: "1" },
  10. { label: window.$l("自由比例"), value: "2" },
  11. { label: "1:1", value: "3" },
  12. { label: "4:3", value: "4" },
  13. { label: "3:2", value: "5" },
  14. { label: "16:9", value: "6" },
  15. { label: window.$l("身份证"), value: "7" },
  16. { label: window.$l("护照"), value: "8" }
  17. ], H = {
  18. 3: 1 / 1,
  19. 4: 4 / 3,
  20. 5: 3 / 2,
  21. 6: 16 / 9,
  22. 7: 340 / 420,
  23. 8: 288 / 420
  24. }, M = b(() => !n.width || !n.height ? 1 : n.width / n.height), d = b(() => {
  25. var t;
  26. return e.scale === "1" ? M.value : e.scale === "2" ? null : (t = H[e.scale]) != null ? t : null;
  27. });
  28. f(
  29. () => e.scale,
  30. () => {
  31. const t = d.value;
  32. t && (e.width ? e.height = Math.ceil(e.width / t) : e.height && (e.width = Math.ceil(e.height * t)));
  33. }
  34. ), f(
  35. () => e.width,
  36. (t) => {
  37. const l = d.value;
  38. !l || !t || (e.height = Math.ceil(t / l));
  39. }
  40. ), f(
  41. () => e.height,
  42. (t) => {
  43. const l = d.value;
  44. !l || !t || (e.width = Math.ceil(t * l));
  45. }
  46. );
  47. function N(t) {
  48. const { editor: l, image: a } = t || {};
  49. !l || !a || (m.value = l, p.value = a, n.width = a.naturalWidth || a.offsetWidth || 0, n.height = a.naturalHeight || a.offsetHeight || 0, e.scale = "1", e.width = a.offsetWidth || n.width, e.height = a.offsetHeight || n.height, r.value = !0);
  50. }
  51. function w() {
  52. r.value = !1;
  53. }
  54. function U() {
  55. const t = Number(e.width), l = Number(e.height);
  56. if (!t || !l) {
  57. window.$message.warning(window.$l("高度或宽度不能为0"));
  58. return;
  59. }
  60. const a = p.value, u = m.value;
  61. !a || !u || (a.style.width = `${t}px`, a.style.height = `${l}px`, u.events.fire("change", u.value), r.value = !1, R("confirm", { width: t, height: l }));
  62. }
  63. return k({ open: N }), (t, l) => {
  64. const a = A, u = h("s-form-item"), v = B, W = h("s-form"), g = h("s-button"), I = h("s-modal");
  65. return O(), S(I, {
  66. value: r.value,
  67. "onUpdate:value": l[3] || (l[3] = (s) => r.value = s),
  68. title: t.$l("调整宽高"),
  69. width: 380,
  70. "show-full-screen": !1,
  71. "mask-closable": !1,
  72. onHandCancel: w
  73. }, {
  74. footer: o(() => [
  75. i(g, { onClick: w }, {
  76. default: o(() => [
  77. $(y(t.$l("取消")), 1)
  78. ]),
  79. _: 1
  80. }),
  81. i(g, {
  82. type: "primary",
  83. onClick: U
  84. }, {
  85. default: o(() => [
  86. $(y(t.$l("确定")), 1)
  87. ]),
  88. _: 1
  89. })
  90. ]),
  91. default: o(() => [
  92. i(W, {
  93. model: e,
  94. column: 1,
  95. labelWidth: "70px"
  96. }, {
  97. default: o(() => [
  98. i(u, {
  99. label: t.$l("比例"),
  100. prop: "scale"
  101. }, {
  102. default: o(() => [
  103. i(a, {
  104. value: e.scale,
  105. "onUpdate:value": l[0] || (l[0] = (s) => e.scale = s),
  106. options: x
  107. }, null, 8, ["value"])
  108. ]),
  109. _: 1
  110. }, 8, ["label"]),
  111. i(u, {
  112. label: t.$l("高度"),
  113. prop: "height"
  114. }, {
  115. default: o(() => [
  116. i(v, {
  117. value: e.height,
  118. "onUpdate:value": l[1] || (l[1] = (s) => e.height = s),
  119. min: 1,
  120. max: 4e3,
  121. style: { width: "100%" }
  122. }, null, 8, ["value"])
  123. ]),
  124. _: 1
  125. }, 8, ["label"]),
  126. i(u, {
  127. label: t.$l("宽度"),
  128. prop: "width"
  129. }, {
  130. default: o(() => [
  131. i(v, {
  132. value: e.width,
  133. "onUpdate:value": l[2] || (l[2] = (s) => e.width = s),
  134. min: 1,
  135. max: 4e3,
  136. style: { width: "100%" }
  137. }, null, 8, ["value"])
  138. ]),
  139. _: 1
  140. }, 8, ["label"])
  141. ]),
  142. _: 1
  143. }, 8, ["model"])
  144. ]),
  145. _: 1
  146. }, 8, ["value", "title"]);
  147. };
  148. }
  149. };
  150. export {
  151. j as default
  152. };