yx-web-sdk 0.0.26 → 0.0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -38867,7 +38867,7 @@ const _hoisted_17$2 = {
38867
38867
  const _hoisted_18$2 = { class: "chatCardQuoteMsgName" };
38868
38868
  const _hoisted_19$2 = ["innerHTML"];
38869
38869
  const _hoisted_20$2 = { class: "ant-image-mask-info" };
38870
- const _hoisted_21$2 = { class: "chatCardStatus" };
38870
+ const _hoisted_21$1 = { class: "chatCardStatus" };
38871
38871
  const MAX_IMG_PREVIEW_SIZE = 2 * 1024 * 1024;
38872
38872
  const REVOCATION_INTERVAL = 120 * 1e3;
38873
38873
  const _sfc_main$8 = /* @__PURE__ */ defineComponent({
@@ -38905,19 +38905,90 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
38905
38905
  return props.msg.fromAccount === props.myAccid && nowTime.value - props.msg.time <= REVOCATION_INTERVAL;
38906
38906
  });
38907
38907
  const { copy } = useClipboard();
38908
+ const imageBlobCache = /* @__PURE__ */ new Map();
38909
+ async function fetchImageAsPngBlob(url) {
38910
+ const response = await fetch(url);
38911
+ const blob = await response.blob();
38912
+ if (blob.type === "image/png") {
38913
+ return blob;
38914
+ }
38915
+ return new Promise((resolve, reject) => {
38916
+ const objectUrl = URL.createObjectURL(blob);
38917
+ const img = document.createElement("img");
38918
+ img.crossOrigin = "anonymous";
38919
+ img.onload = () => {
38920
+ const canvas = document.createElement("canvas");
38921
+ canvas.width = img.naturalWidth;
38922
+ canvas.height = img.naturalHeight;
38923
+ const ctx = canvas.getContext("2d");
38924
+ ctx.drawImage(img, 0, 0);
38925
+ canvas.toBlob((b) => {
38926
+ URL.revokeObjectURL(objectUrl);
38927
+ if (b) {
38928
+ resolve(b);
38929
+ } else {
38930
+ reject(new Error("canvas toBlob 失败"));
38931
+ }
38932
+ }, "image/png");
38933
+ };
38934
+ img.onerror = () => {
38935
+ URL.revokeObjectURL(objectUrl);
38936
+ reject(new Error("图片加载失败"));
38937
+ };
38938
+ img.src = objectUrl;
38939
+ });
38940
+ }
38941
+ function clearImageBlobCache() {
38942
+ imageBlobCache.clear();
38943
+ }
38908
38944
  const emit = __emit;
38909
38945
  const textMsgContextMenuVisible = ref(false);
38910
38946
  const textMsgContextMenuX = ref(0);
38911
38947
  const textMsgContextMenuY = ref(0);
38912
38948
  const textMsgContextMenuRef = ref(null);
38913
- function onTextMsgContextMenu(e) {
38949
+ const eventSource = ref("");
38950
+ function onTextMsgContextMenu(e, p) {
38951
+ var _a;
38952
+ eventSource.value = p != null ? p : "normal";
38914
38953
  textMsgContextMenuX.value = e.clientX;
38915
38954
  textMsgContextMenuY.value = e.clientY;
38916
- textMsgContextMenuVisible.value = true;
38955
+ if (p === "img") {
38956
+ const imgUrl = (_a = props.msg.attach) == null ? void 0 : _a.url;
38957
+ if (imgUrl && !imageBlobCache.has(imgUrl)) {
38958
+ fetchImageAsPngBlob(imgUrl).then((blob) => {
38959
+ imageBlobCache.set(imgUrl, blob);
38960
+ }).catch((err) => {
38961
+ console.error("预下载图片失败: ", err);
38962
+ });
38963
+ }
38964
+ }
38965
+ setTimeout(
38966
+ () => {
38967
+ textMsgContextMenuVisible.value = true;
38968
+ },
38969
+ p === "img" ? 150 : 0
38970
+ );
38917
38971
  }
38918
38972
  function onCopyClick() {
38919
- var _a;
38973
+ var _a, _b;
38920
38974
  if (props.msg.type === "text") {
38975
+ if (eventSource.value === "img") {
38976
+ const imgUrl = (_a = props.msg.attach) == null ? void 0 : _a.url;
38977
+ const cachedBlob = imageBlobCache.get(imgUrl);
38978
+ if (cachedBlob) {
38979
+ navigator.clipboard.write([new ClipboardItem({ "image/png": cachedBlob })]).then(() => {
38980
+ }).catch((err) => {
38981
+ console.error("copy image error: ", err);
38982
+ message.error("复制图片失败");
38983
+ }).finally(() => {
38984
+ textMsgContextMenuVisible.value = false;
38985
+ });
38986
+ } else {
38987
+ message.warning("图片正在加载中,请稍后再试");
38988
+ textMsgContextMenuVisible.value = false;
38989
+ }
38990
+ return;
38991
+ }
38921
38992
  copy(props.msg.body).then(() => {
38922
38993
  }).catch((err) => {
38923
38994
  console.error("copy error: ", err);
@@ -38927,13 +38998,20 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
38927
38998
  });
38928
38999
  }
38929
39000
  if (props.msg.type === "image") {
38930
- copy((_a = props.msg.attach) == null ? void 0 : _a.url).then(() => {
38931
- }).catch((err) => {
38932
- console.error("copy error: ", err);
38933
- message.error("复制失败");
38934
- }).finally(() => {
39001
+ const imgUrl = (_b = props.msg.attach) == null ? void 0 : _b.url;
39002
+ const cachedBlob = imageBlobCache.get(imgUrl);
39003
+ if (cachedBlob) {
39004
+ navigator.clipboard.write([new ClipboardItem({ "image/png": cachedBlob })]).then(() => {
39005
+ }).catch((err) => {
39006
+ console.error("copy image error: ", err);
39007
+ message.error("复制图片失败");
39008
+ }).finally(() => {
39009
+ textMsgContextMenuVisible.value = false;
39010
+ });
39011
+ } else {
39012
+ message.warning("图片正在加载中,请稍后再试");
38935
39013
  textMsgContextMenuVisible.value = false;
38936
- });
39014
+ }
38937
39015
  }
38938
39016
  }
38939
39017
  function onQuoteClick() {
@@ -39005,6 +39083,7 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
39005
39083
  onBeforeUnmount(() => {
39006
39084
  document.removeEventListener("click", handleClickOutside, true);
39007
39085
  document.removeEventListener("contextmenu", handleClickOutside, true);
39086
+ clearImageBlobCache();
39008
39087
  });
39009
39088
  const myAvatar = computed(() => {
39010
39089
  var _a, _b, _c, _d;
@@ -39166,7 +39245,7 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
39166
39245
  ], 2)) : __props.msg.type === "image" ? (openBlock(), createElementBlock("div", {
39167
39246
  key: 2,
39168
39247
  class: normalizeClass(["chatCardMainContent flash-target", { myMsg: __props.msg.fromAccount === __props.myAccid, otherMsg: __props.msg.fromAccount !== __props.myAccid }]),
39169
- onContextmenu: withModifiers(onTextMsgContextMenu, ["prevent"])
39248
+ onContextmenu: _cache[0] || (_cache[0] = withModifiers(($event) => onTextMsgContextMenu($event, "img"), ["prevent"]))
39170
39249
  }, [
39171
39250
  createVNode(unref(Image), {
39172
39251
  class: "imgMsg",
@@ -39184,24 +39263,28 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
39184
39263
  ], 34)) : (openBlock(), createElementBlock("div", {
39185
39264
  key: 3,
39186
39265
  class: normalizeClass(["chatCardMainContent", { myMsg: __props.msg.fromAccount === __props.myAccid, otherMsg: __props.msg.fromAccount !== __props.myAccid }])
39187
- }, [..._cache[1] || (_cache[1] = [
39266
+ }, [..._cache[3] || (_cache[3] = [
39188
39267
  createElementVNode("div", { class: "textMsg" }, toDisplayString("暂不支持该消息"), -1)
39189
39268
  ])], 2)),
39190
39269
  __props.msg.type === "text" && IMG_EXT.includes(((_j = (_i = __props.msg) == null ? void 0 : _i.attach) == null ? void 0 : _j.ext) || "") ? (openBlock(), createElementBlock("div", _hoisted_14$3, [
39191
- ((_l = (_k = __props.msg) == null ? void 0 : _k.attach) == null ? void 0 : _l.size) && ((_n = (_m = __props.msg) == null ? void 0 : _m.attach) == null ? void 0 : _n.size) < MAX_IMG_PREVIEW_SIZE ? (openBlock(), createBlock(unref(Image), {
39270
+ ((_l = (_k = __props.msg) == null ? void 0 : _k.attach) == null ? void 0 : _l.size) && ((_n = (_m = __props.msg) == null ? void 0 : _m.attach) == null ? void 0 : _n.size) < MAX_IMG_PREVIEW_SIZE ? (openBlock(), createElementBlock("div", {
39192
39271
  key: 0,
39193
- class: "imgMsg",
39194
- src: (_p = (_o = __props.msg) == null ? void 0 : _o.attach) == null ? void 0 : _p.url,
39195
- width: attachImageSize.value.width,
39196
- height: attachImageSize.value.height
39197
- }, {
39198
- previewMask: withCtx(() => [
39199
- createElementVNode("div", _hoisted_15$3, [
39200
- createVNode(unref(EyeOutlined))
39201
- ])
39202
- ]),
39203
- _: 1
39204
- }, 8, ["src", "width", "height"])) : (openBlock(), createBlock(_sfc_main$9, {
39272
+ onContextmenu: _cache[1] || (_cache[1] = withModifiers(($event) => onTextMsgContextMenu($event, "img"), ["prevent"]))
39273
+ }, [
39274
+ createVNode(unref(Image), {
39275
+ class: "imgMsg",
39276
+ src: (_p = (_o = __props.msg) == null ? void 0 : _o.attach) == null ? void 0 : _p.url,
39277
+ width: attachImageSize.value.width,
39278
+ height: attachImageSize.value.height
39279
+ }, {
39280
+ previewMask: withCtx(() => [
39281
+ createElementVNode("div", _hoisted_15$3, [
39282
+ createVNode(unref(EyeOutlined))
39283
+ ])
39284
+ ]),
39285
+ _: 1
39286
+ }, 8, ["src", "width", "height"])
39287
+ ], 32)) : (openBlock(), createBlock(_sfc_main$9, {
39205
39288
  key: 1,
39206
39289
  attach: (_q = __props.msg) == null ? void 0 : _q.attach
39207
39290
  }, null, 8, ["attach"]))
@@ -39228,7 +39311,7 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
39228
39311
  src: (_s = msgExt.value.quoteMsg.attach) == null ? void 0 : _s.url,
39229
39312
  width: quoteImageMsgSize.value.width,
39230
39313
  height: quoteImageMsgSize.value.height,
39231
- onClick: _cache[0] || (_cache[0] = withModifiers(() => {
39314
+ onClick: _cache[2] || (_cache[2] = withModifiers(() => {
39232
39315
  }, ["stop", "prevent"]))
39233
39316
  }, {
39234
39317
  previewMask: withCtx(() => [
@@ -39241,7 +39324,7 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
39241
39324
  ])
39242
39325
  ])) : createCommentVNode("", true)
39243
39326
  ]),
39244
- createElementVNode("div", _hoisted_21$2, [
39327
+ createElementVNode("div", _hoisted_21$1, [
39245
39328
  __props.msg.deliveryStatus === "failed" ? (openBlock(), createBlock(unref(Button), {
39246
39329
  key: 0,
39247
39330
  type: "text",
@@ -39958,11 +40041,10 @@ const _hoisted_15$2 = {
39958
40041
  class: "chatroomInputAttachmentWrapperImg"
39959
40042
  };
39960
40043
  const _hoisted_16$1 = { class: "chatroomInputAttachmentWrapperImgMask" };
39961
- const _hoisted_17$1 = { class: "chatroomInputWrapper" };
39962
- const _hoisted_18$1 = { class: "chatroomInputLeft" };
39963
- const _hoisted_19$1 = { style: { "width": "400px" } };
39964
- const _hoisted_20$1 = ["onClick"];
39965
- const _hoisted_21$1 = { class: "chatroomController" };
40044
+ const _hoisted_17$1 = { class: "chatroomInputLeft" };
40045
+ const _hoisted_18$1 = { style: { "width": "400px" } };
40046
+ const _hoisted_19$1 = ["onClick"];
40047
+ const _hoisted_20$1 = { class: "chatroomController" };
39966
40048
  const MAX_IMG_SIZE = 10;
39967
40049
  const _sfc_main$5 = /* @__PURE__ */ defineComponent({
39968
40050
  ...{
@@ -40243,41 +40325,101 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
40243
40325
  }
40244
40326
  };
40245
40327
  const handlePaste = async (e) => {
40328
+ var _a;
40246
40329
  if (props.sendDisabled || attachmentUploading.value) return;
40247
40330
  const clipboardData = e.clipboardData;
40248
40331
  if (!clipboardData) return;
40249
- const items = clipboardData.items;
40250
- for (let i = 0; i < items.length; i++) {
40251
- const item = items[i];
40252
- if (item.type.startsWith("image/")) {
40253
- const file = item.getAsFile();
40254
- if (file) {
40255
- e.preventDefault();
40256
- if (!isLt(file.size, MAX_IMG_SIZE)) {
40257
- message.error("图片大小最大支持20M");
40258
- return;
40259
- }
40332
+ let imageFile = null;
40333
+ if (clipboardData.items && clipboardData.items.length) {
40334
+ for (let i = 0; i < clipboardData.items.length; i++) {
40335
+ const item = clipboardData.items[i];
40336
+ if (item.type.startsWith("image/")) {
40337
+ imageFile = item.getAsFile();
40338
+ break;
40339
+ }
40340
+ }
40341
+ }
40342
+ if (!imageFile && clipboardData.files && clipboardData.files.length) {
40343
+ for (let i = 0; i < clipboardData.files.length; i++) {
40344
+ if (clipboardData.files[i].type.startsWith("image/")) {
40345
+ imageFile = clipboardData.files[i];
40346
+ break;
40347
+ }
40348
+ }
40349
+ }
40350
+ if (!imageFile) return;
40351
+ e.preventDefault();
40352
+ const existingFile = (_a = attachment.value) == null ? void 0 : _a.__file;
40353
+ if (existingFile && existingFile.size === imageFile.size && existingFile.type === imageFile.type) {
40354
+ return;
40355
+ }
40356
+ if (!isLt(imageFile.size, MAX_IMG_SIZE)) {
40357
+ message.error("图片大小最大支持20M");
40358
+ return;
40359
+ }
40360
+ attachmentUploading.value = true;
40361
+ try {
40362
+ const uploadResult = await channelStore.uploadImage({
40363
+ file: imageFile,
40364
+ onUploadStart: () => {
40260
40365
  attachmentUploading.value = true;
40261
- try {
40262
- const uploadResult = await channelStore.uploadImage({
40263
- file,
40264
- onUploadStart: () => {
40265
- attachmentUploading.value = true;
40266
- },
40267
- onUploadDone: () => {
40268
- attachmentUploading.value = false;
40269
- }
40270
- });
40271
- attachment.value = uploadResult;
40272
- } catch (error) {
40273
- console.error("上传图片失败:", error);
40274
- message.error("上传图片失败");
40275
- attachmentUploading.value = false;
40276
- }
40366
+ },
40367
+ onUploadDone: () => {
40368
+ attachmentUploading.value = false;
40277
40369
  }
40278
- return;
40370
+ });
40371
+ uploadResult.__file = imageFile;
40372
+ attachment.value = uploadResult;
40373
+ } catch (error) {
40374
+ console.error("上传图片失败:", error);
40375
+ message.error("上传图片失败");
40376
+ attachmentUploading.value = false;
40377
+ }
40378
+ };
40379
+ const handleDrop = async (e) => {
40380
+ var _a;
40381
+ e.preventDefault();
40382
+ if (props.sendDisabled || attachmentUploading.value) return;
40383
+ const dataTransfer = e.dataTransfer;
40384
+ console.log("dataTransfer", dataTransfer);
40385
+ if (!dataTransfer || !dataTransfer.files.length) return;
40386
+ let imageFile = null;
40387
+ for (let i = 0; i < dataTransfer.files.length; i++) {
40388
+ if (dataTransfer.files[i].type.startsWith("image/")) {
40389
+ imageFile = dataTransfer.files[i];
40390
+ break;
40279
40391
  }
40280
40392
  }
40393
+ if (!imageFile) {
40394
+ message.error("仅支持拖入图片文件");
40395
+ return;
40396
+ }
40397
+ const existingFile = (_a = attachment.value) == null ? void 0 : _a.__file;
40398
+ if (existingFile && existingFile.size === imageFile.size && existingFile.type === imageFile.type) {
40399
+ return;
40400
+ }
40401
+ if (!isLt(imageFile.size, MAX_IMG_SIZE)) {
40402
+ message.error(`图片大小最大支持${MAX_IMG_SIZE}MB`);
40403
+ return;
40404
+ }
40405
+ attachmentUploading.value = true;
40406
+ try {
40407
+ const uploadResult = await channelStore.uploadImage({
40408
+ file: imageFile,
40409
+ onUploadStart: () => {
40410
+ attachmentUploading.value = true;
40411
+ },
40412
+ onUploadDone: () => {
40413
+ attachmentUploading.value = false;
40414
+ }
40415
+ });
40416
+ uploadResult.__file = imageFile;
40417
+ attachment.value = uploadResult;
40418
+ } catch (error) {
40419
+ console.error("拖拽上传图片失败:", error);
40420
+ message.error("拖拽上传图片失败");
40421
+ attachmentUploading.value = false;
40422
+ }
40281
40423
  };
40282
40424
  const uploadImgHandler = async (file) => {
40283
40425
  if (!file.type.startsWith("image/")) {
@@ -40485,7 +40627,7 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
40485
40627
  __props.msgs.length ? (openBlock(), createElementBlock("div", _hoisted_2$4, [
40486
40628
  __props.isNoMore ? (openBlock(), createElementBlock("div", _hoisted_3$4, "没有更多消息了~")) : loadingMore.value ? (openBlock(), createElementBlock("div", _hoisted_4$4, [
40487
40629
  createVNode(unref(LoadingOutlined)),
40488
- _cache[1] || (_cache[1] = createElementVNode("span", { style: { "margin-left": "10px" } }, "正在加载,请稍候", -1))
40630
+ _cache[2] || (_cache[2] = createElementVNode("span", { style: { "margin-left": "10px" } }, "正在加载,请稍候", -1))
40489
40631
  ])) : createCommentVNode("", true)
40490
40632
  ])) : createCommentVNode("", true),
40491
40633
  __props.msgs.length ? (openBlock(), createElementBlock("div", _hoisted_5$4, [
@@ -40509,7 +40651,7 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
40509
40651
  class: "emptyChatroomContent",
40510
40652
  style: normalizeStyle({ height: ((_c = curChannel.value) == null ? void 0 : _c.ext) ? "calc(100% - 48px)" : "100%" })
40511
40653
  }, [
40512
- _cache[2] || (_cache[2] = createElementVNode("div", null, "欢迎来到", -1)),
40654
+ _cache[3] || (_cache[3] = createElementVNode("div", null, "欢迎来到", -1)),
40513
40655
  createElementVNode("h1", null, "#" + toDisplayString(__props.channelName), 1)
40514
40656
  ], 4))
40515
40657
  ], 38),
@@ -40561,17 +40703,22 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
40561
40703
  }, null, 8, ["src"])
40562
40704
  ])) : createCommentVNode("", true)
40563
40705
  ])) : createCommentVNode("", true),
40564
- createElementVNode("div", _hoisted_17$1, [
40565
- createElementVNode("div", _hoisted_18$1, [
40706
+ createElementVNode("div", {
40707
+ class: "chatroomInputWrapper",
40708
+ onDragover: _cache[1] || (_cache[1] = withModifiers(() => {
40709
+ }, ["prevent"])),
40710
+ onDrop: withModifiers(handleDrop, ["prevent"])
40711
+ }, [
40712
+ createElementVNode("div", _hoisted_17$1, [
40566
40713
  createVNode(unref(Popover), { placement: "topLeft" }, {
40567
40714
  content: withCtx(() => [
40568
- createElementVNode("div", _hoisted_19$1, [
40715
+ createElementVNode("div", _hoisted_18$1, [
40569
40716
  (openBlock(), createElementBlock(Fragment, null, renderList(emjjData, (value, i) => {
40570
40717
  return createElementVNode("span", {
40571
40718
  key: i,
40572
40719
  style: { "font-size": "16px", "cursor": "pointer" },
40573
40720
  onClick: ($event) => insertEmj(i)
40574
- }, toDisplayString(value), 9, _hoisted_20$1);
40721
+ }, toDisplayString(value), 9, _hoisted_19$1);
40575
40722
  }), 64))
40576
40723
  ])
40577
40724
  ]),
@@ -40581,7 +40728,7 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
40581
40728
  type: "text",
40582
40729
  disabled: __props.sendDisabled
40583
40730
  }, {
40584
- default: withCtx(() => [..._cache[3] || (_cache[3] = [
40731
+ default: withCtx(() => [..._cache[4] || (_cache[4] = [
40585
40732
  createElementVNode("svg", {
40586
40733
  width: "21",
40587
40734
  height: "21",
@@ -40616,7 +40763,7 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
40616
40763
  onBlur: handleInputBlur,
40617
40764
  onPaste: handlePaste
40618
40765
  }, null, 8, ["value", "placeholder", "disabled", "onKeydown", "onClick"]),
40619
- createElementVNode("div", _hoisted_21$1, [
40766
+ createElementVNode("div", _hoisted_20$1, [
40620
40767
  createVNode(unref(Upload), {
40621
40768
  "before-upload": uploadImgHandler,
40622
40769
  "show-upload-list": false,
@@ -40631,7 +40778,7 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
40631
40778
  loading: attachmentUploading.value,
40632
40779
  disabled: __props.sendDisabled || attachmentUploading.value
40633
40780
  }, {
40634
- icon: withCtx(() => [..._cache[4] || (_cache[4] = [
40781
+ icon: withCtx(() => [..._cache[5] || (_cache[5] = [
40635
40782
  createElementVNode("svg", {
40636
40783
  width: "21",
40637
40784
  height: "18",
@@ -40656,14 +40803,14 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
40656
40803
  ]),
40657
40804
  _: 1
40658
40805
  }, 8, ["accept", "disabled"]),
40659
- _cache[6] || (_cache[6] = createElementVNode("span", { class: "lineSeparator" }, null, -1)),
40806
+ _cache[7] || (_cache[7] = createElementVNode("span", { class: "lineSeparator" }, null, -1)),
40660
40807
  createVNode(unref(Button), {
40661
40808
  class: "chatroomButtonArrowUp",
40662
40809
  type: "text",
40663
40810
  disabled: __props.sendDisabled,
40664
40811
  onClick: handleSendText
40665
40812
  }, {
40666
- icon: withCtx(() => [..._cache[5] || (_cache[5] = [
40813
+ icon: withCtx(() => [..._cache[6] || (_cache[6] = [
40667
40814
  createElementVNode("svg", {
40668
40815
  width: "36",
40669
40816
  height: "36",
@@ -40686,7 +40833,7 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
40686
40833
  _: 1
40687
40834
  }, 8, ["disabled"])
40688
40835
  ])
40689
- ])
40836
+ ], 32)
40690
40837
  ])
40691
40838
  ]),
40692
40839
  createVNode(AitPersonPopover, {