@jzt-packages/components 1.0.0
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/package.json +68 -0
- package/src/JztBackTop/index.vue +255 -0
- package/src/JztButtonList/index.vue +88 -0
- package/src/JztChart/index.vue +95 -0
- package/src/JztCharts/index.vue +317 -0
- package/src/JztClassTabs/index.vue +156 -0
- package/src/JztDateSelect/dateSelect.vue +186 -0
- package/src/JztDateSelect/dateType.vue +54 -0
- package/src/JztDateSelect/index.ts +135 -0
- package/src/JztDateSelect/interface/index.ts +13 -0
- package/src/JztDialog/index.vue +249 -0
- package/src/JztEllipsisTooltip/index.vue +61 -0
- package/src/JztEmpty/index.vue +45 -0
- package/src/JztErrorPage/403.vue +30 -0
- package/src/JztErrorPage/404.vue +19 -0
- package/src/JztErrorPage/500.vue +18 -0
- package/src/JztErrorPage/assets/401.png +0 -0
- package/src/JztErrorPage/assets/403.png +0 -0
- package/src/JztErrorPage/assets/404.png +0 -0
- package/src/JztErrorPage/assets/500.png +0 -0
- package/src/JztErrorPage/index.scss +35 -0
- package/src/JztErrorPage/index.vue +35 -0
- package/src/JztFilePreview/components/pdfViewer.vue +221 -0
- package/src/JztFilePreview/hooks/useImageMethod.ts +256 -0
- package/src/JztFilePreview/index.scss +171 -0
- package/src/JztFilePreview/index.vue +68 -0
- package/src/JztFilePreview/interface/index.ts +18 -0
- package/src/JztFilePreview/previewFile.vue +371 -0
- package/src/JztFormGrid/README.md +520 -0
- package/src/JztFormGrid/components/formItem.vue +209 -0
- package/src/JztFormGrid/components/formItemValue.vue +384 -0
- package/src/JztFormGrid/components/showDetailForm.vue +172 -0
- package/src/JztFormGrid/index.scss +60 -0
- package/src/JztFormGrid/index.vue +513 -0
- package/src/JztFormGrid/interface/index.ts +106 -0
- package/src/JztGrid/components/GridItem.vue +68 -0
- package/src/JztGrid/index.vue +179 -0
- package/src/JztGrid/interface/index.ts +6 -0
- package/src/JztImportExcel/assets/delete.png +0 -0
- package/src/JztImportExcel/index.scss +46 -0
- package/src/JztImportExcel/index.vue +430 -0
- package/src/JztImportExcel/interface/index.ts +25 -0
- package/src/JztLabelTitle/index.vue +65 -0
- package/src/JztLeftRightMode/components/CollapseButton.vue +80 -0
- package/src/JztLeftRightMode/components/LeftCard.vue +203 -0
- package/src/JztLeftRightMode/components/LeftLayout.vue +173 -0
- package/src/JztLeftRightMode/components/RightHeader.vue +186 -0
- package/src/JztLeftRightMode/components/RightLayout.vue +235 -0
- package/src/JztLeftRightMode/components/RightTableHeader.vue +43 -0
- package/src/JztLeftRightMode/hooks/useCollapse.ts +17 -0
- package/src/JztLeftRightMode/hooks/useDefaultProps.ts +19 -0
- package/src/JztLeftRightMode/hooks/useLeftLayout.ts +201 -0
- package/src/JztLeftRightMode/hooks/useMode.ts +20 -0
- package/src/JztLeftRightMode/hooks/usePrevNext.ts +60 -0
- package/src/JztLeftRightMode/hooks/useRightLayout.ts +215 -0
- package/src/JztLeftRightMode/hooks/useSlots.ts +15 -0
- package/src/JztLeftRightMode/index.ts +3 -0
- package/src/JztLeftRightMode/index.vue +494 -0
- package/src/JztLeftRightMode/types/index.ts +457 -0
- package/src/JztLoading/fullScreen.ts +45 -0
- package/src/JztLoading/index.scss +67 -0
- package/src/JztLoading/index.vue +18 -0
- package/src/JztLogin/components/LoginFooter.vue +17 -0
- package/src/JztLogin/components/LoginForm.vue +99 -0
- package/src/JztLogin/hooks/useLogin.ts +186 -0
- package/src/JztLogin/index.scss +142 -0
- package/src/JztLogin/index.vue +31 -0
- package/src/JztLogin/interface/index.ts +47 -0
- package/src/JztNumericalRange/index.vue +81 -0
- package/src/JztPageCard/comm/datePicker.vue +151 -0
- package/src/JztPageCard/comm/details.vue +60 -0
- package/src/JztPageCard/comm/export.vue +24 -0
- package/src/JztPageCard/comm/tabs.vue +94 -0
- package/src/JztPageCard/comm/tooltip.vue +31 -0
- package/src/JztPageCard/index.vue +287 -0
- package/src/JztPagination/index.vue +70 -0
- package/src/JztProductInfo/components/imagePreview.vue +275 -0
- package/src/JztProductInfo/components/qxUnique.vue +101 -0
- package/src/JztProductInfo/components/records.vue +265 -0
- package/src/JztProductInfo/hooks/useParams.ts +143 -0
- package/src/JztProductInfo/hooks/useQxUnique.tsx +466 -0
- package/src/JztProductInfo/images/defaultProduct.png +0 -0
- package/src/JztProductInfo/index.ts +116 -0
- package/src/JztProductInfo/index.vue +108 -0
- package/src/JztProductInfo/interface/index.ts +15 -0
- package/src/JztQueryDetailTable/index.scss +100 -0
- package/src/JztQueryDetailTable/index.vue +400 -0
- package/src/JztQueryDetailTable/interface/index.ts +10 -0
- package/src/JztQueryTable/QueryTable /345/212/237/350/203/275.md" +1580 -0
- package/src/JztQueryTable/README.md +567 -0
- package/src/JztQueryTable/components/ColSetting.vue +67 -0
- package/src/JztQueryTable/components/ColumnsSetting.vue +404 -0
- package/src/JztQueryTable/components/ColumnsSetting1.vue +220 -0
- package/src/JztQueryTable/components/DeployToAccountLevelSetting.vue +351 -0
- package/src/JztQueryTable/components/Pagination.vue +54 -0
- package/src/JztQueryTable/components/TableColumn.vue +109 -0
- package/src/JztQueryTable/const.ts +1 -0
- package/src/JztQueryTable/hooks/useQueryTable.ts +194 -0
- package/src/JztQueryTable/hooks/useSelection.ts +47 -0
- package/src/JztQueryTable/hooks/useTableSetting.ts +197 -0
- package/src/JztQueryTable/hooks/useTemplate.ts +127 -0
- package/src/JztQueryTable/index.scss +91 -0
- package/src/JztQueryTable/index.vue +1445 -0
- package/src/JztQueryTable/interface/index.ts +185 -0
- package/src/JztRegionSelect/index.vue +134 -0
- package/src/JztSearchForm/components/SearchFormItem.vue +473 -0
- package/src/JztSearchForm/index.vue +530 -0
- package/src/JztSearchForm/interface/index.ts +100 -0
- package/src/JztSelectFilter/index.scss +63 -0
- package/src/JztSelectFilter/index.vue +110 -0
- package/src/JztSelectTable/index.vue +257 -0
- package/src/JztTable/index.scss +72 -0
- package/src/JztTable/index.vue +353 -0
- package/src/JztTable/interface/index.ts +1 -0
- package/src/JztTime/comm/agencySelect.vue +112 -0
- package/src/JztTime/comm/collapseRow.vue +132 -0
- package/src/JztTime/comm/dateSelect.vue +292 -0
- package/src/JztTime/comm/deptSelect.vue +193 -0
- package/src/JztTime/comm/typeSelect.vue +97 -0
- package/src/JztTime/index.ts +216 -0
- package/src/JztTime/index.vue +303 -0
- package/src/JztTime/interface/index.ts +23 -0
- package/src/JztTreeFilter/index.scss +44 -0
- package/src/JztTreeFilter/index.vue +177 -0
- package/src/JztUploadFile/interface/index.ts +21 -0
- package/src/JztUploadFile/multiple.scss +215 -0
- package/src/JztUploadFile/multiple.vue +318 -0
- package/src/JztUploadFile/single.scss +226 -0
- package/src/JztUploadFile/single.vue +274 -0
- package/src/JztUploadImg/Img.vue +294 -0
- package/src/JztUploadImg/Imgs.vue +411 -0
- package/src/JztUploadImg/index.scss +138 -0
- package/src/JztUploadImg/interface/index.ts +22 -0
- package/src/SelectIcon/index.scss +39 -0
- package/src/SelectIcon/index.vue +106 -0
- package/src/SvgIcon/index.vue +22 -0
- package/src/hooks/useAuthButtons.ts +58 -0
- package/src/hooks/useFormByUserType.ts +90 -0
- package/src/hooks/useTableEvents.ts +30 -0
- package/src/hooks/useUploadFileHook.ts +262 -0
- package/src/index.ts +91 -0
- package/src/typings/global.d.ts +101 -0
- package/src/utils/index.ts +107 -0
- package/src/utils/tree.ts +57 -0
- package/tsconfig.json +45 -0
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div :class="[listType === 'text' ? 'file_upload_box' : 'img_upload_box']">
|
|
3
|
+
<!-- {{ imageUrl }} -->
|
|
4
|
+
<!-- {{ fileList }} -->
|
|
5
|
+
<el-upload
|
|
6
|
+
:id="uuid"
|
|
7
|
+
v-model:file-list="fileList"
|
|
8
|
+
action="#"
|
|
9
|
+
:class="[
|
|
10
|
+
'upload flx-left-top',
|
|
11
|
+
self_disabled ? 'disabled' : '',
|
|
12
|
+
drag ? 'no-border' : '',
|
|
13
|
+
listType !== 'text' && imageUrl ? 'no-upload' : '',
|
|
14
|
+
]"
|
|
15
|
+
:multiple="false"
|
|
16
|
+
:disabled="self_disabled"
|
|
17
|
+
:show-file-list="listType === 'text' && showFileList"
|
|
18
|
+
:http-request="handleHttpUpload"
|
|
19
|
+
:before-upload="beforeUpload"
|
|
20
|
+
:on-success="uploadSuccess"
|
|
21
|
+
:on-remove="deleteImg"
|
|
22
|
+
:on-error="uploadError"
|
|
23
|
+
|
|
24
|
+
:drag="listType === 'text' ? false : drag"
|
|
25
|
+
:accept="fileType.join(',')"
|
|
26
|
+
>
|
|
27
|
+
<div class="el-upload__tip">
|
|
28
|
+
<slot name="tip"></slot>
|
|
29
|
+
</div>
|
|
30
|
+
<template v-if="imageUrl" #trigger>
|
|
31
|
+
<div v-if="listType === 'text'">
|
|
32
|
+
<div>
|
|
33
|
+
<el-button :disabled="true" type="primary" class="mb5">{{
|
|
34
|
+
emptyText
|
|
35
|
+
}}</el-button>
|
|
36
|
+
</div>
|
|
37
|
+
<!-- <div class="el-upload-list__item flx-between-center" @click.stop>
|
|
38
|
+
<div class="el-upload-list__item-name sle flx-left-center">
|
|
39
|
+
<el-icon><Document /></el-icon>
|
|
40
|
+
<div class="sle fileName">文件XXX文件XXX文件XXX文件XXX文件</div>
|
|
41
|
+
</div>
|
|
42
|
+
<div class="result">
|
|
43
|
+
<span class="success">
|
|
44
|
+
<el-icon color="#67c23a"><CircleCheck /></el-icon>
|
|
45
|
+
</span>
|
|
46
|
+
<span class="delete" @click="deleteImg">
|
|
47
|
+
<el-icon color="#A1A1A3"><Close /></el-icon>
|
|
48
|
+
</span>
|
|
49
|
+
</div>
|
|
50
|
+
</div> -->
|
|
51
|
+
</div>
|
|
52
|
+
<div v-else class="upload-image-box" style="width: 100%; height: 100%">
|
|
53
|
+
<img :src="getFullUrl(imageUrl)" class="upload-image" />
|
|
54
|
+
<div class="upload-handle" @click.stop>
|
|
55
|
+
<div class="handle-icon" @click="imgViewVisible = true">
|
|
56
|
+
<el-icon><ZoomIn /></el-icon>
|
|
57
|
+
<span>查看</span>
|
|
58
|
+
</div>
|
|
59
|
+
<div v-if="!self_disabled" class="handle-icon" @click="deleteImg">
|
|
60
|
+
<el-icon><Delete /></el-icon>
|
|
61
|
+
<span>删除</span>
|
|
62
|
+
</div>
|
|
63
|
+
</div>
|
|
64
|
+
</div>
|
|
65
|
+
</template>
|
|
66
|
+
<template v-else #trigger>
|
|
67
|
+
<template v-if="listType === 'text'">
|
|
68
|
+
<el-icon v-if="drag" class="el-icon--upload">
|
|
69
|
+
<upload-filled />
|
|
70
|
+
</el-icon>
|
|
71
|
+
<el-button v-else type="primary">
|
|
72
|
+
{{ emptyText }}
|
|
73
|
+
</el-button>
|
|
74
|
+
</template>
|
|
75
|
+
<template v-else>
|
|
76
|
+
<div class="upload-empty">
|
|
77
|
+
<slot name="empty">
|
|
78
|
+
<el-icon><Plus /></el-icon>
|
|
79
|
+
<span>{{ emptyText }}</span>
|
|
80
|
+
</slot>
|
|
81
|
+
</div>
|
|
82
|
+
</template>
|
|
83
|
+
</template>
|
|
84
|
+
</el-upload>
|
|
85
|
+
<el-image-viewer
|
|
86
|
+
v-if="imgViewVisible"
|
|
87
|
+
:url-list="[getFullUrl(imageUrl)]"
|
|
88
|
+
@close="imgViewVisible = false"
|
|
89
|
+
/>
|
|
90
|
+
</div>
|
|
91
|
+
</template>
|
|
92
|
+
|
|
93
|
+
<script setup lang="ts" name="UploadImg">
|
|
94
|
+
import { ref, computed, inject, watch } from "vue";
|
|
95
|
+
import { generateUUID } from "../utils/index";
|
|
96
|
+
import {
|
|
97
|
+
ElNotification,
|
|
98
|
+
formContextKey,
|
|
99
|
+
formItemContextKey,
|
|
100
|
+
} from "element-plus";
|
|
101
|
+
import type {
|
|
102
|
+
UploadProps,
|
|
103
|
+
UploadRequestOptions,
|
|
104
|
+
UploadUserFile,
|
|
105
|
+
} from "element-plus";
|
|
106
|
+
import { useUploadFileHook } from "../hooks/useUploadFileHook";
|
|
107
|
+
const { useBeforeUpload, useHttpUploadHook, getFullUrl } = useUploadFileHook();
|
|
108
|
+
|
|
109
|
+
interface UploadFileProps {
|
|
110
|
+
imageUrl: string; // 图片地址 ==> 必传
|
|
111
|
+
api?: (params: any) => Promise<any>; // 上传图片的 api 方法,一般项目上传都是同一个 api 方法,在组件里直接引入即可 ==> 非必传
|
|
112
|
+
drag?: boolean; // 是否支持拖拽上传 ==> 非必传(默认为 true)
|
|
113
|
+
disabled?: boolean; // 是否禁用上传组件 ==> 非必传(默认为 false)
|
|
114
|
+
fileSize?: number; // 图片大小限制 ==> 非必传(默认为 5M)
|
|
115
|
+
fileType?: File.FilePostfixType[]; // 图片类型限制 ==> 非必传(默认为 [".jpeg", ".png", ".jpeg", ".jpg", ".pdf"])
|
|
116
|
+
height?: string; // 组件高度 ==> 非必传(默认为 120px)
|
|
117
|
+
width?: string; // 组件宽度 ==> 非必传(默认为 120px)
|
|
118
|
+
borderRadius?: string; // 组件边框圆角 ==> 非必传(默认为 8px)
|
|
119
|
+
listType?: "text" | "picture" | "picture-card";
|
|
120
|
+
fileName?: string;
|
|
121
|
+
emptyText?: string;
|
|
122
|
+
showFileList?: boolean; // 是否显示文件列表 ==> 非必传(默认为 true)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const props = withDefaults(defineProps<UploadFileProps>(), {
|
|
126
|
+
imageUrl: "",
|
|
127
|
+
drag: false,
|
|
128
|
+
disabled: false,
|
|
129
|
+
fileSize: 5,
|
|
130
|
+
fileType: () => [".jpeg", ".png", ".jpeg", ".jpg", ".pdf"],
|
|
131
|
+
height: "120px",
|
|
132
|
+
width: "120px",
|
|
133
|
+
borderRadius: "8px",
|
|
134
|
+
emptyText: "上传文件",
|
|
135
|
+
listType: "text",
|
|
136
|
+
fileName: "file",
|
|
137
|
+
showFileList: true, // 默认显示文件列表
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
const fileList = ref<any[]>([]);
|
|
141
|
+
|
|
142
|
+
// 监听 props.fileList 列表默认值改变
|
|
143
|
+
watch(
|
|
144
|
+
() => props.imageUrl,
|
|
145
|
+
(imageUrl: string) => {
|
|
146
|
+
if (imageUrl) {
|
|
147
|
+
fileList.value = [
|
|
148
|
+
{
|
|
149
|
+
url: getFullUrl(props.imageUrl),
|
|
150
|
+
name: props.imageUrl,
|
|
151
|
+
uid: Math.floor(Math.random() * 100),
|
|
152
|
+
},
|
|
153
|
+
];
|
|
154
|
+
} else {
|
|
155
|
+
fileList.value = [];
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
immediate: true,
|
|
160
|
+
}
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
// 生成组件唯一id
|
|
164
|
+
const uuid = ref("id-" + generateUUID());
|
|
165
|
+
|
|
166
|
+
// 查看图片
|
|
167
|
+
const imgViewVisible = ref(false);
|
|
168
|
+
// 获取 el-form 组件上下文
|
|
169
|
+
const formContext = inject(formContextKey, void 0);
|
|
170
|
+
// 获取 el-form-item 组件上下文
|
|
171
|
+
const formItemContext = inject(formItemContextKey, void 0);
|
|
172
|
+
// 判断是否禁用上传和删除
|
|
173
|
+
const self_disabled = computed(() => {
|
|
174
|
+
return props.disabled || formContext?.disabled;
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
// 获取文件名
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* @description 图片上传
|
|
181
|
+
* @param options upload 所有配置项
|
|
182
|
+
* */
|
|
183
|
+
const emit = defineEmits<{
|
|
184
|
+
"update:imageUrl": [value: any];
|
|
185
|
+
}>();
|
|
186
|
+
const handleHttpUpload = async (options: UploadRequestOptions) => {
|
|
187
|
+
useHttpUploadHook({
|
|
188
|
+
fileName: props.fileName,
|
|
189
|
+
options,
|
|
190
|
+
api: props.api,
|
|
191
|
+
});
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* @description 删除图片
|
|
196
|
+
* */
|
|
197
|
+
const deleteImg = () => {
|
|
198
|
+
emit("update:imageUrl", "");
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* @description 编辑图片
|
|
203
|
+
* */
|
|
204
|
+
const editImg = () => {
|
|
205
|
+
const dom = document.querySelector(`#${uuid.value} .el-upload__input`);
|
|
206
|
+
dom && dom.dispatchEvent(new MouseEvent("click"));
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* @description 文件上传之前判断
|
|
211
|
+
* @param rawFile 选择的文件
|
|
212
|
+
* */
|
|
213
|
+
const beforeUpload: UploadProps["beforeUpload"] = (rawFile) => {
|
|
214
|
+
return useBeforeUpload({
|
|
215
|
+
rawFile,
|
|
216
|
+
fileSize: props.fileSize,
|
|
217
|
+
fileType: props.fileType,
|
|
218
|
+
});
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* @description 图片上传成功
|
|
223
|
+
* 导入成功的函数,response是 http-request="handleHttpUpload" return的值
|
|
224
|
+
* */
|
|
225
|
+
const uploadSuccess = (val) => {
|
|
226
|
+
if (val && val.fileUrl) {
|
|
227
|
+
ElNotification({
|
|
228
|
+
title: "温馨提示",
|
|
229
|
+
message: "图片上传成功!",
|
|
230
|
+
type: "success",
|
|
231
|
+
});
|
|
232
|
+
emit("update:imageUrl", val.fileUrl);
|
|
233
|
+
} else {
|
|
234
|
+
emit("update:imageUrl", "");
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* @description 图片上传错误
|
|
240
|
+
* */
|
|
241
|
+
const uploadError = () => {
|
|
242
|
+
ElNotification({
|
|
243
|
+
title: "温馨提示",
|
|
244
|
+
message: "图片上传失败,请您重新上传!",
|
|
245
|
+
type: "error",
|
|
246
|
+
});
|
|
247
|
+
};
|
|
248
|
+
</script>
|
|
249
|
+
|
|
250
|
+
<style scoped lang="scss">
|
|
251
|
+
@use "./single.scss";
|
|
252
|
+
:deep(.upload) {
|
|
253
|
+
.el-upload-dragger {
|
|
254
|
+
width: v-bind(width) !important;
|
|
255
|
+
height: 100%;
|
|
256
|
+
border-radius: v-bind(borderRadius);
|
|
257
|
+
padding: 30px 10px;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
.img_upload_box {
|
|
261
|
+
.no-border {
|
|
262
|
+
:deep(.el-upload) {
|
|
263
|
+
border: none !important;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
:deep(.upload) {
|
|
267
|
+
.el-upload {
|
|
268
|
+
width: v-bind(width);
|
|
269
|
+
height: v-bind(height);
|
|
270
|
+
border-radius: v-bind(borderRadius);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
</style>
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="upload-box">
|
|
3
|
+
<el-upload
|
|
4
|
+
:id="uuid"
|
|
5
|
+
action="#"
|
|
6
|
+
:class="['upload', self_disabled ? 'disabled' : '', drag ? 'no-border' : '']"
|
|
7
|
+
:multiple="false"
|
|
8
|
+
:disabled="self_disabled"
|
|
9
|
+
:show-file-list="false"
|
|
10
|
+
:http-request="handleHttpUpload"
|
|
11
|
+
:before-upload="beforeUpload"
|
|
12
|
+
:on-success="uploadSuccess"
|
|
13
|
+
:on-error="uploadError"
|
|
14
|
+
:drag="drag"
|
|
15
|
+
:accept="fileType.join(',')"
|
|
16
|
+
>
|
|
17
|
+
<template v-if="imageUrl">
|
|
18
|
+
<img :src="getFullUrl(imageUrl)" class="upload-image" />
|
|
19
|
+
<div class="upload-handle" @click.stop>
|
|
20
|
+
<!-- <div v-if="!self_disabled" class="handle-icon" @click="editImg">
|
|
21
|
+
<el-icon><Edit /></el-icon>
|
|
22
|
+
<span>编辑</span>
|
|
23
|
+
</div> -->
|
|
24
|
+
<div class="handle-icon" @click="imgViewVisible = true">
|
|
25
|
+
<el-icon><ZoomIn /></el-icon>
|
|
26
|
+
<span>查看</span>
|
|
27
|
+
</div>
|
|
28
|
+
<div v-if="!self_disabled" class="handle-icon" @click="deleteImg">
|
|
29
|
+
<el-icon><Delete /></el-icon>
|
|
30
|
+
<span>删除</span>
|
|
31
|
+
</div>
|
|
32
|
+
</div>
|
|
33
|
+
</template>
|
|
34
|
+
<template v-else>
|
|
35
|
+
<div class="upload-empty">
|
|
36
|
+
<slot name="empty">
|
|
37
|
+
<el-icon><Plus /></el-icon>
|
|
38
|
+
<span>{{ emptyText }}</span>
|
|
39
|
+
</slot>
|
|
40
|
+
</div>
|
|
41
|
+
</template>
|
|
42
|
+
</el-upload>
|
|
43
|
+
<div class="el-upload__tip">
|
|
44
|
+
<slot name="tip"></slot>
|
|
45
|
+
</div>
|
|
46
|
+
<el-image-viewer v-if="imgViewVisible" :url-list="[getFullUrl(imageUrl)]" @close="imgViewVisible = false" />
|
|
47
|
+
</div>
|
|
48
|
+
</template>
|
|
49
|
+
|
|
50
|
+
<script setup lang="ts" name="UploadImg">
|
|
51
|
+
import { ref, computed, inject } from 'vue'
|
|
52
|
+
import { generateUUID } from '../utils/index'
|
|
53
|
+
import { ElNotification, formContextKey, formItemContextKey } from 'element-plus'
|
|
54
|
+
import type { UploadProps, UploadRequestOptions } from 'element-plus'
|
|
55
|
+
import { useUploadFileHook } from '../hooks/useUploadFileHook'
|
|
56
|
+
const { useBeforeUpload, useRemoveFilterList, useUploadSuccess, useHttpUploadHook, getFullUrl } = useUploadFileHook()
|
|
57
|
+
|
|
58
|
+
interface UploadFileProps {
|
|
59
|
+
imageUrl: string // 图片地址 ==> 必传
|
|
60
|
+
api?: (params: any) => Promise<any> // 上传图片的 api 方法,一般项目上传都是同一个 api 方法,在组件里直接引入即可 ==> 非必传
|
|
61
|
+
drag?: boolean // 是否支持拖拽上传 ==> 非必传(默认为 true)
|
|
62
|
+
disabled?: boolean // 是否禁用上传组件 ==> 非必传(默认为 false)
|
|
63
|
+
fileSize?: number // 图片大小限制 ==> 非必传(默认为 5M)
|
|
64
|
+
fileType?: File.ImagePostfixType[] // 图片类型限制 ==> 非必传(默认为 [".jpeg", ".png", ".jpg"])
|
|
65
|
+
height?: string // 组件高度 ==> 非必传(默认为 120px)
|
|
66
|
+
width?: string // 组件宽度 ==> 非必传(默认为 120px)
|
|
67
|
+
borderRadius?: string // 组件边框圆角 ==> 非必传(默认为 8px)
|
|
68
|
+
emptyText?: string
|
|
69
|
+
fileName?: string
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// 接受父组件参数
|
|
73
|
+
const props = withDefaults(defineProps<UploadFileProps>(), {
|
|
74
|
+
imageUrl: '',
|
|
75
|
+
drag: true,
|
|
76
|
+
disabled: false,
|
|
77
|
+
fileSize: 5,
|
|
78
|
+
fileType: () => ['.jpeg', '.png', '.jpg'],
|
|
79
|
+
height: '120px',
|
|
80
|
+
width: '120px',
|
|
81
|
+
borderRadius: '8px',
|
|
82
|
+
emptyText: '请上传图片',
|
|
83
|
+
fileName: 'file'
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
// 生成组件唯一id
|
|
87
|
+
const uuid = ref('id-' + generateUUID())
|
|
88
|
+
|
|
89
|
+
// 查看图片
|
|
90
|
+
const imgViewVisible = ref(false)
|
|
91
|
+
// 获取 el-form 组件上下文
|
|
92
|
+
const formContext = inject(formContextKey, void 0)
|
|
93
|
+
// 获取 el-form-item 组件上下文
|
|
94
|
+
const formItemContext = inject(formItemContextKey, void 0)
|
|
95
|
+
// 判断是否禁用上传和删除
|
|
96
|
+
const self_disabled = computed(() => {
|
|
97
|
+
return props.disabled || formContext?.disabled
|
|
98
|
+
})
|
|
99
|
+
/**
|
|
100
|
+
* @description 图片上传
|
|
101
|
+
* @param options upload 所有配置项
|
|
102
|
+
* */
|
|
103
|
+
const emit = defineEmits<{
|
|
104
|
+
'update:imageUrl': [value: string]
|
|
105
|
+
}>()
|
|
106
|
+
const handleHttpUpload = async (options: UploadRequestOptions) => {
|
|
107
|
+
useHttpUploadHook({
|
|
108
|
+
fileName: props.fileName,
|
|
109
|
+
options,
|
|
110
|
+
api: props.api
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* @description 删除图片
|
|
116
|
+
* */
|
|
117
|
+
const deleteImg = () => {
|
|
118
|
+
emit('update:imageUrl', '')
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* @description 编辑图片
|
|
123
|
+
* */
|
|
124
|
+
const editImg = () => {
|
|
125
|
+
const dom = document.querySelector(`#${uuid.value} .el-upload__input`)
|
|
126
|
+
dom && dom.dispatchEvent(new MouseEvent('click'))
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* @description 文件上传之前判断
|
|
131
|
+
* @param rawFile 选择的文件
|
|
132
|
+
* */
|
|
133
|
+
const beforeUpload: UploadProps['beforeUpload'] = rawFile => {
|
|
134
|
+
return useBeforeUpload({
|
|
135
|
+
rawFile,
|
|
136
|
+
fileSize: props.fileSize,
|
|
137
|
+
fileType: props.fileType
|
|
138
|
+
})
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @description 图片上传成功
|
|
143
|
+
* */
|
|
144
|
+
const uploadSuccess = val => {
|
|
145
|
+
if (val && val.fileUrl) {
|
|
146
|
+
ElNotification({
|
|
147
|
+
title: '温馨提示',
|
|
148
|
+
message: '图片上传成功!',
|
|
149
|
+
type: 'success'
|
|
150
|
+
})
|
|
151
|
+
emit('update:imageUrl', val.fileUrl)
|
|
152
|
+
} else {
|
|
153
|
+
emit('update:imageUrl', '')
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* @description 图片上传错误
|
|
159
|
+
* */
|
|
160
|
+
const uploadError = () => {
|
|
161
|
+
ElNotification({
|
|
162
|
+
title: '温馨提示',
|
|
163
|
+
message: '图片上传失败,请您重新上传!',
|
|
164
|
+
type: 'error'
|
|
165
|
+
})
|
|
166
|
+
}
|
|
167
|
+
</script>
|
|
168
|
+
|
|
169
|
+
<style scoped lang="scss">
|
|
170
|
+
.is-error {
|
|
171
|
+
.upload {
|
|
172
|
+
:deep(.el-upload),
|
|
173
|
+
:deep(.el-upload-dragger) {
|
|
174
|
+
border: 1px dashed var(--el-color-danger) !important;
|
|
175
|
+
&:hover {
|
|
176
|
+
border-color: var(--el-color-primary) !important;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
:deep(.disabled) {
|
|
182
|
+
.el-upload,
|
|
183
|
+
.el-upload-dragger {
|
|
184
|
+
cursor: not-allowed !important;
|
|
185
|
+
background: var(--el-disabled-bg-color);
|
|
186
|
+
border: 1px dashed var(--el-border-color-darker) !important;
|
|
187
|
+
&:hover {
|
|
188
|
+
border: 1px dashed var(--el-border-color-darker) !important;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
.upload-box {
|
|
193
|
+
.no-border {
|
|
194
|
+
:deep(.el-upload) {
|
|
195
|
+
border: none !important;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
:deep(.upload) {
|
|
199
|
+
.el-upload {
|
|
200
|
+
position: relative;
|
|
201
|
+
display: flex;
|
|
202
|
+
align-items: center;
|
|
203
|
+
justify-content: center;
|
|
204
|
+
width: v-bind(width);
|
|
205
|
+
height: v-bind(height);
|
|
206
|
+
overflow: hidden;
|
|
207
|
+
border: 1px dashed var(--el-border-color-darker);
|
|
208
|
+
border-radius: v-bind(borderRadius);
|
|
209
|
+
transition: var(--el-transition-duration-fast);
|
|
210
|
+
background-color: #fff !important;
|
|
211
|
+
&:hover {
|
|
212
|
+
border-color: var(--el-color-primary);
|
|
213
|
+
.upload-handle {
|
|
214
|
+
opacity: 1;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
.el-upload-dragger {
|
|
218
|
+
display: flex;
|
|
219
|
+
align-items: center;
|
|
220
|
+
justify-content: center;
|
|
221
|
+
width: 100%;
|
|
222
|
+
height: 100%;
|
|
223
|
+
padding: 0;
|
|
224
|
+
overflow: hidden;
|
|
225
|
+
// background-color: transparent;
|
|
226
|
+
border: 1px dashed var(--el-border-color-darker);
|
|
227
|
+
border-radius: v-bind(borderRadius);
|
|
228
|
+
&:hover {
|
|
229
|
+
border: 1px dashed var(--el-color-primary);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
.el-upload-dragger.is-dragover {
|
|
233
|
+
background-color: var(--el-color-primary-light-9);
|
|
234
|
+
border: 2px dashed var(--el-color-primary) !important;
|
|
235
|
+
}
|
|
236
|
+
.upload-image {
|
|
237
|
+
width: 100%;
|
|
238
|
+
height: 100%;
|
|
239
|
+
object-fit: contain;
|
|
240
|
+
}
|
|
241
|
+
.upload-empty {
|
|
242
|
+
position: relative;
|
|
243
|
+
display: flex;
|
|
244
|
+
flex-direction: column;
|
|
245
|
+
align-items: center;
|
|
246
|
+
justify-content: center;
|
|
247
|
+
font-size: 12px;
|
|
248
|
+
line-height: 30px;
|
|
249
|
+
color: var(--el-color-info);
|
|
250
|
+
.el-icon {
|
|
251
|
+
font-size: 28px;
|
|
252
|
+
color: var(--el-text-color-secondary);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
.upload-handle {
|
|
256
|
+
position: absolute;
|
|
257
|
+
top: 0;
|
|
258
|
+
right: 0;
|
|
259
|
+
box-sizing: border-box;
|
|
260
|
+
display: flex;
|
|
261
|
+
align-items: center;
|
|
262
|
+
justify-content: center;
|
|
263
|
+
width: 100%;
|
|
264
|
+
height: 100%;
|
|
265
|
+
cursor: pointer;
|
|
266
|
+
background: rgb(0 0 0 / 60%);
|
|
267
|
+
opacity: 0;
|
|
268
|
+
transition: var(--el-transition-duration-fast);
|
|
269
|
+
.handle-icon {
|
|
270
|
+
display: flex;
|
|
271
|
+
flex-direction: column;
|
|
272
|
+
align-items: center;
|
|
273
|
+
justify-content: center;
|
|
274
|
+
padding: 0 6%;
|
|
275
|
+
color: aliceblue;
|
|
276
|
+
.el-icon {
|
|
277
|
+
margin-bottom: 40%;
|
|
278
|
+
font-size: 130%;
|
|
279
|
+
line-height: 130%;
|
|
280
|
+
}
|
|
281
|
+
span {
|
|
282
|
+
font-size: 85%;
|
|
283
|
+
line-height: 85%;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
.el-upload__tip {
|
|
290
|
+
line-height: 18px;
|
|
291
|
+
text-align: center;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
</style>
|