knt-shared 1.2.0 → 1.2.2
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.
- package/dist/components/Form/componentMap.d.ts +35 -0
- package/dist/components/Form/componentMap.d.ts.map +1 -1
- package/dist/components/Upload/BasicUpload.vue.d.ts +7 -4
- package/dist/components/Upload/BasicUpload.vue.d.ts.map +1 -1
- package/dist/components/Upload/types.d.ts +15 -0
- package/dist/components/Upload/types.d.ts.map +1 -1
- package/dist/index.cjs.js +113 -48
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +113 -48
- package/dist/index.esm.js.map +1 -1
- package/dist/style.css +40 -40
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -656,14 +656,10 @@ const IconFullscreen = Object.assign(_IconFullscreen, {
|
|
|
656
656
|
});
|
|
657
657
|
const _hoisted_1$3 = { class: "basic-upload" };
|
|
658
658
|
const _hoisted_2$3 = {
|
|
659
|
-
key: 0,
|
|
660
|
-
class: "upload-card-button"
|
|
661
|
-
};
|
|
662
|
-
const _hoisted_3$2 = {
|
|
663
659
|
key: 0,
|
|
664
660
|
class: "upload-text"
|
|
665
661
|
};
|
|
666
|
-
const
|
|
662
|
+
const _hoisted_3$2 = { class: "upload-tip" };
|
|
667
663
|
const _sfc_main$4 = /* @__PURE__ */ defineComponent({
|
|
668
664
|
...{
|
|
669
665
|
name: "BasicUpload",
|
|
@@ -672,8 +668,8 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
|
|
|
672
668
|
__name: "BasicUpload",
|
|
673
669
|
props: {
|
|
674
670
|
modelValue: {},
|
|
675
|
-
accept: { default: "" },
|
|
676
|
-
maxSize: { default:
|
|
671
|
+
accept: { default: "image/*" },
|
|
672
|
+
maxSize: { default: 30 },
|
|
677
673
|
maxCount: { default: 1 },
|
|
678
674
|
multiple: { type: Boolean, default: false },
|
|
679
675
|
disabled: { type: Boolean, default: false },
|
|
@@ -697,6 +693,7 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
|
|
|
697
693
|
showPreviewButton: { type: Boolean, default: true },
|
|
698
694
|
showUploadButton: { type: Boolean, default: true },
|
|
699
695
|
tip: {},
|
|
696
|
+
cardSize: {},
|
|
700
697
|
imagePreview: { type: Boolean, default: true },
|
|
701
698
|
imageCrop: { type: Boolean, default: false },
|
|
702
699
|
imageCompress: { type: Boolean, default: false },
|
|
@@ -704,17 +701,20 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
|
|
|
704
701
|
draggable: { type: Boolean, default: false },
|
|
705
702
|
directory: { type: Boolean, default: false },
|
|
706
703
|
autoUpload: { type: Boolean, default: true },
|
|
707
|
-
resultType: { default: "
|
|
704
|
+
resultType: { default: "fileList" },
|
|
708
705
|
uploadButtonText: {},
|
|
709
|
-
uploadButtonType: { default: "primary" }
|
|
706
|
+
uploadButtonType: { default: "primary" },
|
|
707
|
+
responseUrlKey: { type: [String, Function], default: void 0 }
|
|
710
708
|
},
|
|
711
|
-
emits: ["register", "update:modelValue", "change", "success", "error", "progress", "remove", "preview", "exceed"],
|
|
709
|
+
emits: ["register", "update:modelValue", "change", "success", "handleSuccess", "error", "handlError", "progress", "remove", "preview", "exceed"],
|
|
712
710
|
setup(__props, { expose: __expose, emit: __emit }) {
|
|
713
711
|
const props = __props;
|
|
714
712
|
const emit = __emit;
|
|
715
713
|
const uploadRef = ref();
|
|
716
714
|
const fileListRef = ref([]);
|
|
717
715
|
const propsRef = ref({});
|
|
716
|
+
const hasShownActionError = ref(false);
|
|
717
|
+
const processedFiles = ref(/* @__PURE__ */ new Map());
|
|
718
718
|
const getProps = computed(() => {
|
|
719
719
|
return { ...props, ...unref(propsRef) };
|
|
720
720
|
});
|
|
@@ -735,7 +735,15 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
|
|
|
735
735
|
showRemoveButton: propsData.showRemoveButton && !propsData.readonly,
|
|
736
736
|
showUploadButton: !hideUploadButton.value,
|
|
737
737
|
// 只有在没有自定义预览时才启用 imagePreview
|
|
738
|
-
imagePreview: propsData.imagePreview && !propsData.onPreview
|
|
738
|
+
imagePreview: propsData.imagePreview && !propsData.onPreview,
|
|
739
|
+
onRemove: async (fileItem) => {
|
|
740
|
+
if (propsData.onRemove) {
|
|
741
|
+
const canRemove = await propsData.onRemove(fileItem);
|
|
742
|
+
if (!canRemove) return false;
|
|
743
|
+
}
|
|
744
|
+
emit("remove", fileItem);
|
|
745
|
+
return true;
|
|
746
|
+
}
|
|
739
747
|
};
|
|
740
748
|
});
|
|
741
749
|
const validateFileSize = (file) => {
|
|
@@ -816,18 +824,46 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
|
|
|
816
824
|
action: propsData.action,
|
|
817
825
|
withCredentials: propsData.withCredentials
|
|
818
826
|
};
|
|
819
|
-
propsData.customRequest(customOptions);
|
|
820
|
-
}
|
|
821
|
-
|
|
827
|
+
return propsData.customRequest(customOptions);
|
|
828
|
+
}
|
|
829
|
+
return defaultUpload(options);
|
|
830
|
+
};
|
|
831
|
+
const extractUrlFromResponse = (response) => {
|
|
832
|
+
const urlPaths = ["url", "data.pathUrl", "data.url", "data.path", "pathUrl", "path"];
|
|
833
|
+
for (const path of urlPaths) {
|
|
834
|
+
const value = path.split(".").reduce((obj, key) => obj == null ? void 0 : obj[key], response);
|
|
835
|
+
if (value && typeof value === "string") {
|
|
836
|
+
return value;
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
if (response.data && typeof response.data === "string") {
|
|
840
|
+
return response.data;
|
|
822
841
|
}
|
|
842
|
+
return null;
|
|
843
|
+
};
|
|
844
|
+
const isDev = false;
|
|
845
|
+
const logger = {
|
|
846
|
+
debug: (...args) => isDev,
|
|
847
|
+
warn: (...args) => console.warn("[BasicUpload]", ...args),
|
|
848
|
+
error: (...args) => console.error("[BasicUpload]", ...args)
|
|
823
849
|
};
|
|
824
850
|
const defaultUpload = (options) => {
|
|
825
851
|
const propsData = unref(getProps);
|
|
826
852
|
const { fileItem, onProgress, onSuccess, onError } = options;
|
|
827
853
|
if (!propsData.action) {
|
|
828
|
-
|
|
854
|
+
if (!hasShownActionError.value) {
|
|
855
|
+
Message.error("请配置上传地址 action");
|
|
856
|
+
hasShownActionError.value = true;
|
|
857
|
+
setTimeout(() => {
|
|
858
|
+
hasShownActionError.value = false;
|
|
859
|
+
}, 3e3);
|
|
860
|
+
}
|
|
829
861
|
onError(new Error("上传地址未配置"));
|
|
830
|
-
return
|
|
862
|
+
return {
|
|
863
|
+
abort() {
|
|
864
|
+
xhr.abort();
|
|
865
|
+
}
|
|
866
|
+
};
|
|
831
867
|
}
|
|
832
868
|
const formData = new FormData();
|
|
833
869
|
formData.append(propsData.name || "file", fileItem.file);
|
|
@@ -847,15 +883,31 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
|
|
|
847
883
|
if (xhr.status >= 200 && xhr.status < 300) {
|
|
848
884
|
try {
|
|
849
885
|
const response = JSON.parse(xhr.responseText);
|
|
850
|
-
|
|
886
|
+
const { code, message, data } = response;
|
|
887
|
+
if (code !== 200) {
|
|
888
|
+
const errorMsg = message ? `上传失败: ${message}` : "上传失败";
|
|
889
|
+
onError(new Error(errorMsg));
|
|
890
|
+
Message.error(errorMsg);
|
|
891
|
+
return;
|
|
892
|
+
}
|
|
893
|
+
const extractedUrl = extractUrlFromResponse(response);
|
|
894
|
+
const normalizedResponse = extractedUrl ? { url: extractedUrl, name: fileItem.name, ...data } : response;
|
|
895
|
+
if (!extractedUrl) {
|
|
896
|
+
logger.warn("响应中未找到 URL 字段,可能导致上传状态异常");
|
|
897
|
+
}
|
|
898
|
+
Message.success(`${fileItem.name} 上传成功`);
|
|
899
|
+
onSuccess(normalizedResponse);
|
|
851
900
|
} catch (error) {
|
|
852
|
-
onSuccess(xhr.responseText);
|
|
901
|
+
onSuccess({ data: xhr.responseText });
|
|
853
902
|
}
|
|
854
903
|
} else {
|
|
855
|
-
|
|
904
|
+
const errorMsg = `上传失败: HTTP ${xhr.status}`;
|
|
905
|
+
Message.error(errorMsg);
|
|
906
|
+
onError(new Error(errorMsg));
|
|
856
907
|
}
|
|
857
908
|
});
|
|
858
909
|
xhr.addEventListener("error", () => {
|
|
910
|
+
logger.error("上传网络错误");
|
|
859
911
|
onError(new Error("网络错误"));
|
|
860
912
|
});
|
|
861
913
|
xhr.addEventListener("abort", () => {
|
|
@@ -871,32 +923,41 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
|
|
|
871
923
|
xhr.withCredentials = true;
|
|
872
924
|
}
|
|
873
925
|
xhr.send(formData);
|
|
926
|
+
return {
|
|
927
|
+
abort() {
|
|
928
|
+
xhr.abort();
|
|
929
|
+
}
|
|
930
|
+
};
|
|
874
931
|
};
|
|
875
932
|
const handleChange = (fileList, currentFile) => {
|
|
933
|
+
const oldLength = fileListRef.value.length;
|
|
934
|
+
const newLength = fileList.length;
|
|
876
935
|
fileListRef.value = fileList;
|
|
877
936
|
emit("change", fileList);
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
} else if (currentFile.status === "error") {
|
|
885
|
-
|
|
937
|
+
const isRemove = newLength < oldLength;
|
|
938
|
+
const fileKey = currentFile.uid;
|
|
939
|
+
const lastStatus = processedFiles.value.get(fileKey);
|
|
940
|
+
if (currentFile.status === "done" && lastStatus !== "done" && !isRemove) {
|
|
941
|
+
processedFiles.value.set(fileKey, "done");
|
|
942
|
+
emit("handleSuccess", currentFile.response, currentFile);
|
|
943
|
+
} else if (currentFile.status === "error" && lastStatus !== "error") {
|
|
944
|
+
processedFiles.value.set(fileKey, "error");
|
|
886
945
|
const error = new Error("上传失败");
|
|
887
|
-
emit("
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
946
|
+
emit("handlError", error, currentFile);
|
|
947
|
+
}
|
|
948
|
+
if (isRemove) {
|
|
949
|
+
const fileUids = new Set(fileList.map((f) => f.uid));
|
|
950
|
+
processedFiles.value.forEach((_, uid) => {
|
|
951
|
+
if (!fileUids.has(uid)) {
|
|
952
|
+
processedFiles.value.delete(uid);
|
|
953
|
+
}
|
|
954
|
+
});
|
|
891
955
|
}
|
|
892
956
|
updateModelValue(fileList);
|
|
893
957
|
};
|
|
894
958
|
const handleProgress = (currentFile, event) => {
|
|
895
959
|
const percent = currentFile.percent || 0;
|
|
896
960
|
emit("progress", percent, currentFile);
|
|
897
|
-
if (getProps.value.onProgress) {
|
|
898
|
-
getProps.value.onProgress(percent, currentFile);
|
|
899
|
-
}
|
|
900
961
|
};
|
|
901
962
|
const handlePreview = (fileItem) => {
|
|
902
963
|
const propsData = unref(getProps);
|
|
@@ -963,6 +1024,7 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
|
|
|
963
1024
|
};
|
|
964
1025
|
const clearFiles = () => {
|
|
965
1026
|
fileListRef.value = [];
|
|
1027
|
+
processedFiles.value.clear();
|
|
966
1028
|
emit("update:modelValue", []);
|
|
967
1029
|
emit("change", []);
|
|
968
1030
|
};
|
|
@@ -985,18 +1047,14 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
|
|
|
985
1047
|
updateModelValue(fileListRef.value);
|
|
986
1048
|
};
|
|
987
1049
|
const removeFile = (fileItem) => {
|
|
988
|
-
const index = fileListRef.value.findIndex(
|
|
989
|
-
(item) => item.uid === fileItem.uid
|
|
990
|
-
);
|
|
1050
|
+
const index = fileListRef.value.findIndex((item) => item.uid === fileItem.uid);
|
|
991
1051
|
if (index !== -1) {
|
|
992
1052
|
fileListRef.value.splice(index, 1);
|
|
993
1053
|
updateModelValue(fileListRef.value);
|
|
994
1054
|
}
|
|
995
1055
|
};
|
|
996
1056
|
const updateFile = (fileItem) => {
|
|
997
|
-
const index = fileListRef.value.findIndex(
|
|
998
|
-
(item) => item.uid === fileItem.uid
|
|
999
|
-
);
|
|
1057
|
+
const index = fileListRef.value.findIndex((item) => item.uid === fileItem.uid);
|
|
1000
1058
|
if (index !== -1) {
|
|
1001
1059
|
fileListRef.value[index] = { ...fileListRef.value[index], ...fileItem };
|
|
1002
1060
|
updateModelValue(fileListRef.value);
|
|
@@ -1047,8 +1105,8 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
|
|
|
1047
1105
|
}, getBindValue.value, {
|
|
1048
1106
|
"file-list": fileListRef.value,
|
|
1049
1107
|
"custom-request": handleCustomRequest,
|
|
1050
|
-
"before-upload": handleBeforeUpload,
|
|
1051
1108
|
onChange: handleChange,
|
|
1109
|
+
onBeforeUpload: handleBeforeUpload,
|
|
1052
1110
|
onProgress: handleProgress,
|
|
1053
1111
|
onPreview: handlePreview
|
|
1054
1112
|
}), createSlots({ _: 2 }, [
|
|
@@ -1056,10 +1114,17 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
|
|
|
1056
1114
|
name: "upload-button",
|
|
1057
1115
|
fn: withCtx(() => [
|
|
1058
1116
|
renderSlot(_ctx.$slots, "upload-button", {}, () => [
|
|
1059
|
-
getProps.value.listType === "picture-card" ? (openBlock(), createElementBlock("div",
|
|
1117
|
+
getProps.value.listType === "picture-card" ? (openBlock(), createElementBlock("div", {
|
|
1118
|
+
key: 0,
|
|
1119
|
+
class: "upload-card-button",
|
|
1120
|
+
style: normalizeStyle({
|
|
1121
|
+
width: `${getProps.value.cardSize || 80}px`,
|
|
1122
|
+
height: `${getProps.value.cardSize || 80}px`
|
|
1123
|
+
})
|
|
1124
|
+
}, [
|
|
1060
1125
|
createVNode(unref(IconPlus), { size: 16 }),
|
|
1061
|
-
getProps.value.uploadButtonText ? (openBlock(), createElementBlock("div",
|
|
1062
|
-
])) : (openBlock(), createBlock(_component_a_button, {
|
|
1126
|
+
getProps.value.uploadButtonText ? (openBlock(), createElementBlock("div", _hoisted_2$3, toDisplayString(getProps.value.uploadButtonText), 1)) : createCommentVNode("", true)
|
|
1127
|
+
], 4)) : (openBlock(), createBlock(_component_a_button, {
|
|
1063
1128
|
key: 1,
|
|
1064
1129
|
type: getProps.value.uploadButtonType || "primary"
|
|
1065
1130
|
}, {
|
|
@@ -1086,7 +1151,7 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
|
|
|
1086
1151
|
name: "tip",
|
|
1087
1152
|
fn: withCtx(() => [
|
|
1088
1153
|
renderSlot(_ctx.$slots, "tip", {}, () => [
|
|
1089
|
-
createElementVNode("div",
|
|
1154
|
+
createElementVNode("div", _hoisted_3$2, toDisplayString(getProps.value.tip), 1)
|
|
1090
1155
|
], true)
|
|
1091
1156
|
]),
|
|
1092
1157
|
key: "2"
|
|
@@ -1110,7 +1175,7 @@ const _export_sfc = (sfc, props) => {
|
|
|
1110
1175
|
}
|
|
1111
1176
|
return target;
|
|
1112
1177
|
};
|
|
1113
|
-
const BasicUpload = /* @__PURE__ */ _export_sfc(_sfc_main$4, [["__scopeId", "data-v-
|
|
1178
|
+
const BasicUpload = /* @__PURE__ */ _export_sfc(_sfc_main$4, [["__scopeId", "data-v-1a5a7ff7"]]);
|
|
1114
1179
|
const componentMap = {
|
|
1115
1180
|
Input,
|
|
1116
1181
|
InputNumber,
|
|
@@ -2114,7 +2179,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
|
|
|
2114
2179
|
const indexColumn = {
|
|
2115
2180
|
title: "序号",
|
|
2116
2181
|
dataIndex: "__index__",
|
|
2117
|
-
width:
|
|
2182
|
+
width: 60,
|
|
2118
2183
|
align: "center",
|
|
2119
2184
|
fixed: "left",
|
|
2120
2185
|
slotName: "__index__",
|
|
@@ -2995,7 +3060,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
|
|
|
2995
3060
|
};
|
|
2996
3061
|
}
|
|
2997
3062
|
});
|
|
2998
|
-
const BasicTable = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-
|
|
3063
|
+
const BasicTable = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-04667d35"]]);
|
|
2999
3064
|
function useTable(options = {}) {
|
|
3000
3065
|
const tableRef = ref(null);
|
|
3001
3066
|
const formRef = ref(null);
|