|
|
@ -48,32 +48,28 @@ |
|
|
|
</BasicModal> |
|
|
|
</BasicModal> |
|
|
|
</template> |
|
|
|
</template> |
|
|
|
<script lang="ts"> |
|
|
|
<script lang="ts"> |
|
|
|
import {defineComponent, reactive, ref, toRefs, unref, computed, PropType, watch} from 'vue'; |
|
|
|
import { defineComponent, reactive, ref, toRefs, unref, computed, PropType } from 'vue'; |
|
|
|
import { Upload, Alert } from 'ant-design-vue'; |
|
|
|
import { Upload, Alert } from 'ant-design-vue'; |
|
|
|
import { BasicModal, useModalInner } from '/@/components/Modal'; |
|
|
|
import { BasicModal, useModalInner } from '/@/components/Modal'; |
|
|
|
// import { BasicTable, useTable } from '/@/components/Table'; |
|
|
|
|
|
|
|
// hooks |
|
|
|
|
|
|
|
import { useUploadType } from './useUpload'; |
|
|
|
import { useUploadType } from './useUpload'; |
|
|
|
import { useMessage } from '/@/hooks/web/useMessage'; |
|
|
|
import { useMessage } from '/@/hooks/web/useMessage'; |
|
|
|
// types |
|
|
|
import { FileItem, UploadResultStatus } from './typing'; |
|
|
|
import {FileItem, PreviewFileItem, UploadResultStatus} from './typing'; |
|
|
|
|
|
|
|
import { basicProps } from './props'; |
|
|
|
import { basicProps } from './props'; |
|
|
|
import { createTableColumns, createActionColumn } from './data'; |
|
|
|
import { createTableColumns, createActionColumn } from './data'; |
|
|
|
// utils |
|
|
|
|
|
|
|
import { checkImgType, getBase64WithFile } from './helper'; |
|
|
|
import { checkImgType, getBase64WithFile } from './helper'; |
|
|
|
import { buildUUID } from '/@/utils/uuid'; |
|
|
|
import { buildUUID } from '/@/utils/uuid'; |
|
|
|
import {isArray, isFunction} from '/@/utils/is'; |
|
|
|
import { isFunction } from '/@/utils/is'; |
|
|
|
import { warn } from '/@/utils/log'; |
|
|
|
import { warn } from '/@/utils/log'; |
|
|
|
import FileList from './FileList.vue'; |
|
|
|
import FileList from './FileList.vue'; |
|
|
|
import { useI18n } from '/@/hooks/web/useI18n'; |
|
|
|
import { useI18n } from '/@/hooks/web/useI18n'; |
|
|
|
import {useTimeoutFn} from '/@/hooks/core/useTimeout'; |
|
|
|
import { useTimeoutFn } from '/@/hooks/core/useTimeout'; |
|
|
|
|
|
|
|
|
|
|
|
export default defineComponent({ |
|
|
|
export default defineComponent({ |
|
|
|
components: { BasicModal, Upload, Alert, FileList }, |
|
|
|
components: { BasicModal, Upload, Alert, FileList }, |
|
|
|
props: { |
|
|
|
props: { |
|
|
|
...basicProps, |
|
|
|
...basicProps, |
|
|
|
previewFileList: { |
|
|
|
previewFileList: { |
|
|
|
type: Array as PropType<string[]>, |
|
|
|
type: Array as PropType<FileItem[]>, |
|
|
|
default: () => [], |
|
|
|
default: () => [], |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
@ -83,18 +79,11 @@ import {useTimeoutFn} from '/@/hooks/core/useTimeout'; |
|
|
|
fileList: [], |
|
|
|
fileList: [], |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// 是否正在上传 |
|
|
|
// 是否正在上传 |
|
|
|
const isUploadingRef = ref(false); |
|
|
|
const isUploadingRef = ref(false); |
|
|
|
const fileListRef = ref<FileItem[]>([]); |
|
|
|
const fileListRef = ref<FileItem[]>([]); |
|
|
|
const { accept, helpText, maxNumber, maxSize } = toRefs(props); |
|
|
|
const { accept, helpText, maxNumber, maxSize } = toRefs(props); |
|
|
|
|
|
|
|
|
|
|
|
watch(() => props.previewFileList, (value) => { |
|
|
|
|
|
|
|
if (!isArray(value)) value = []; |
|
|
|
|
|
|
|
fileListRef.value = value.filter((item) => !!item); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ immediate: true } |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { t } = useI18n(); |
|
|
|
const { t } = useI18n(); |
|
|
|
const [register, { closeModal }] = useModalInner(); |
|
|
|
const [register, { closeModal }] = useModalInner(); |
|
|
|
|
|
|
|
|
|
|
@ -155,7 +144,6 @@ import {useTimeoutFn} from '/@/hooks/core/useTimeout'; |
|
|
|
// 生成图片缩略图 |
|
|
|
// 生成图片缩略图 |
|
|
|
if (checkImgType(file)) { |
|
|
|
if (checkImgType(file)) { |
|
|
|
// beforeUpload,如果异步会调用自带上传方法 |
|
|
|
// beforeUpload,如果异步会调用自带上传方法 |
|
|
|
// file.thumbUrl = await getBase64(file); |
|
|
|
|
|
|
|
getBase64WithFile(file).then(({ result: thumbUrl }) => { |
|
|
|
getBase64WithFile(file).then(({ result: thumbUrl }) => { |
|
|
|
fileListRef.value = [ |
|
|
|
fileListRef.value = [ |
|
|
|
...unref(fileListRef), |
|
|
|
...unref(fileListRef), |
|
|
@ -178,14 +166,6 @@ import {useTimeoutFn} from '/@/hooks/core/useTimeout'; |
|
|
|
emit('delete', record); |
|
|
|
emit('delete', record); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 预览 |
|
|
|
|
|
|
|
// function handlePreview(record: FileItem) { |
|
|
|
|
|
|
|
// const { thumbUrl = '' } = record; |
|
|
|
|
|
|
|
// createImgPreview({ |
|
|
|
|
|
|
|
// imageList: [thumbUrl], |
|
|
|
|
|
|
|
// }); |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function uploadApiByItem(item: FileItem) { |
|
|
|
async function uploadApiByItem(item: FileItem) { |
|
|
|
const { api } = props; |
|
|
|
const { api } = props; |
|
|
|
if (!api || !isFunction(api)) { |
|
|
|
if (!api || !isFunction(api)) { |
|
|
@ -252,7 +232,7 @@ import {useTimeoutFn} from '/@/hooks/core/useTimeout'; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 点击保存 |
|
|
|
// 点击保存 |
|
|
|
function handleOk() { |
|
|
|
function handleOk() { |
|
|
|
const { maxNumber } = props; |
|
|
|
const { maxNumber } = props; |
|
|
|
|
|
|
|
|
|
|
@ -299,7 +279,6 @@ import {useTimeoutFn} from '/@/hooks/core/useTimeout'; |
|
|
|
getStringAccept, |
|
|
|
getStringAccept, |
|
|
|
getOkButtonProps, |
|
|
|
getOkButtonProps, |
|
|
|
beforeUpload, |
|
|
|
beforeUpload, |
|
|
|
// registerTable, |
|
|
|
|
|
|
|
fileListRef, |
|
|
|
fileListRef, |
|
|
|
state, |
|
|
|
state, |
|
|
|
isUploadingRef, |
|
|
|
isUploadingRef, |
|
|
|