|
|
|
@ -50,8 +50,8 @@ |
|
|
|
</BasicModal> |
|
|
|
</template> |
|
|
|
|
|
|
|
<script lang="ts"> |
|
|
|
import { computed, defineComponent, ref, unref, onMounted, onUnmounted, watch } from 'vue'; |
|
|
|
<script lang="ts" setup> |
|
|
|
import { computed, ref, unref, onMounted, onUnmounted, watch } from 'vue'; |
|
|
|
import { useLocalization } from '/@/hooks/abp/useLocalization'; |
|
|
|
import { Tag, Tooltip } from 'ant-design-vue'; |
|
|
|
import { BasicModal, useModalInner } from '/@/components/Modal'; |
|
|
|
@ -60,176 +60,157 @@ |
|
|
|
import { useUserStoreWithOut } from '/@/store/modules/user'; |
|
|
|
import Uploader from 'simple-uploader.js'; |
|
|
|
|
|
|
|
export default defineComponent({ |
|
|
|
name: 'OssUploadModal', |
|
|
|
components: { BasicModal, BasicTable, TableAction, Tag, Tooltip }, |
|
|
|
setup() { |
|
|
|
let uploader: any = null; |
|
|
|
const { L } = useLocalization(['AbpOssManagement', 'AbpUi']); |
|
|
|
const bucket = ref(''); |
|
|
|
const path = ref(''); |
|
|
|
const btnRef = ref<any>(); |
|
|
|
const [registerModal] = useModalInner((data) => { |
|
|
|
path.value = data.path; |
|
|
|
bucket.value = data.bucket; |
|
|
|
}); |
|
|
|
const fileList = ref<Recordable[]>([]); |
|
|
|
const [registerTable] = useTable({ |
|
|
|
rowKey: 'id', |
|
|
|
columns: [ |
|
|
|
{ |
|
|
|
title: 'id', |
|
|
|
dataIndex: 'id', |
|
|
|
width: 1, |
|
|
|
ifShow: false, |
|
|
|
}, |
|
|
|
{ |
|
|
|
title: L('DisplayName:Name'), |
|
|
|
dataIndex: 'name', |
|
|
|
align: 'left', |
|
|
|
width: 300, |
|
|
|
sorter: true, |
|
|
|
}, |
|
|
|
{ |
|
|
|
title: L('DisplayName:Size'), |
|
|
|
dataIndex: 'size', |
|
|
|
align: 'left', |
|
|
|
width: 100, |
|
|
|
sorter: true, |
|
|
|
}, |
|
|
|
{ |
|
|
|
title: L('DisplayName:Status'), |
|
|
|
dataIndex: 'status', |
|
|
|
align: 'left', |
|
|
|
width: 'auto', |
|
|
|
sorter: true, |
|
|
|
}, |
|
|
|
], |
|
|
|
dataSource: fileList, |
|
|
|
pagination: false, |
|
|
|
striped: false, |
|
|
|
useSearchForm: false, |
|
|
|
showTableSetting: false, |
|
|
|
bordered: false, |
|
|
|
showIndexColumn: false, |
|
|
|
canResize: false, |
|
|
|
immediate: false, |
|
|
|
actionColumn: { |
|
|
|
width: 120, |
|
|
|
title: L('Actions'), |
|
|
|
dataIndex: 'action', |
|
|
|
}, |
|
|
|
}); |
|
|
|
|
|
|
|
onMounted(() => { |
|
|
|
const userStore = useUserStoreWithOut(); |
|
|
|
uploader = new Uploader({ |
|
|
|
target: uploadUrl, |
|
|
|
testChunks: false, |
|
|
|
// 加重试机制防止网络波动 |
|
|
|
maxChunkRetries: 3, |
|
|
|
chunkRetryInterval: null, |
|
|
|
successStatuses: [200, 201, 202, 204, 205], |
|
|
|
permanentErrors: [400, 401, 403, 404, 415, 500, 501], |
|
|
|
headers: { |
|
|
|
// TODO: 使用缓存存储令牌类型? |
|
|
|
Authorization: `Bearer ${userStore.getToken}`, |
|
|
|
}, |
|
|
|
processParams: (params: any) => { |
|
|
|
params.bucket = unref(bucket); |
|
|
|
params.path = unref(path); |
|
|
|
return params; |
|
|
|
}, |
|
|
|
}); |
|
|
|
// uploader.on('fileSuccess', _fileSuccess); |
|
|
|
uploader.on('filesSubmitted', _filesSubmitted); |
|
|
|
uploader.on('fileError', _fileError); |
|
|
|
uploader.on('fileProgress', _fileProgress); |
|
|
|
}); |
|
|
|
let uploader: any = null; |
|
|
|
const { L } = useLocalization(['AbpOssManagement', 'AbpUi']); |
|
|
|
const bucket = ref(''); |
|
|
|
const path = ref(''); |
|
|
|
const btnRef = ref<any>(); |
|
|
|
const [registerModal] = useModalInner((data) => { |
|
|
|
path.value = data.path; |
|
|
|
bucket.value = data.bucket; |
|
|
|
}); |
|
|
|
const fileList = ref<Recordable[]>([]); |
|
|
|
const [registerTable] = useTable({ |
|
|
|
rowKey: 'id', |
|
|
|
columns: [ |
|
|
|
{ |
|
|
|
title: 'id', |
|
|
|
dataIndex: 'id', |
|
|
|
width: 1, |
|
|
|
ifShow: false, |
|
|
|
}, |
|
|
|
{ |
|
|
|
title: L('DisplayName:Name'), |
|
|
|
dataIndex: 'name', |
|
|
|
align: 'left', |
|
|
|
width: 300, |
|
|
|
sorter: true, |
|
|
|
}, |
|
|
|
{ |
|
|
|
title: L('DisplayName:Size'), |
|
|
|
dataIndex: 'size', |
|
|
|
align: 'left', |
|
|
|
width: 100, |
|
|
|
sorter: true, |
|
|
|
}, |
|
|
|
{ |
|
|
|
title: L('DisplayName:Status'), |
|
|
|
dataIndex: 'status', |
|
|
|
align: 'left', |
|
|
|
width: 'auto', |
|
|
|
sorter: true, |
|
|
|
}, |
|
|
|
], |
|
|
|
dataSource: fileList, |
|
|
|
pagination: false, |
|
|
|
striped: false, |
|
|
|
useSearchForm: false, |
|
|
|
showTableSetting: false, |
|
|
|
bordered: false, |
|
|
|
showIndexColumn: false, |
|
|
|
canResize: false, |
|
|
|
immediate: false, |
|
|
|
actionColumn: { |
|
|
|
width: 120, |
|
|
|
title: L('Actions'), |
|
|
|
dataIndex: 'action', |
|
|
|
}, |
|
|
|
}); |
|
|
|
|
|
|
|
onUnmounted(() => { |
|
|
|
// uploader.off('fileSuccess', _fileSuccess); |
|
|
|
uploader.off('filesSubmitted', _filesSubmitted); |
|
|
|
uploader.off('fileError', _fileError); |
|
|
|
uploader.off('fileProgress', _fileProgress); |
|
|
|
uploader = null; |
|
|
|
}); |
|
|
|
onMounted(() => { |
|
|
|
const userStore = useUserStoreWithOut(); |
|
|
|
uploader = new Uploader({ |
|
|
|
target: uploadUrl, |
|
|
|
testChunks: false, |
|
|
|
// 加重试机制防止网络波动 |
|
|
|
maxChunkRetries: 3, |
|
|
|
chunkRetryInterval: null, |
|
|
|
successStatuses: [200, 201, 202, 204, 205], |
|
|
|
permanentErrors: [400, 401, 403, 404, 415, 500, 501], |
|
|
|
headers: { |
|
|
|
// TODO: 使用缓存存储令牌类型? |
|
|
|
Authorization: `Bearer ${userStore.getToken}`, |
|
|
|
}, |
|
|
|
processParams: (params: any) => { |
|
|
|
params.bucket = unref(bucket); |
|
|
|
params.path = unref(path); |
|
|
|
return params; |
|
|
|
}, |
|
|
|
}); |
|
|
|
// uploader.on('fileSuccess', _fileSuccess); |
|
|
|
uploader.on('filesSubmitted', _filesSubmitted); |
|
|
|
uploader.on('fileError', _fileError); |
|
|
|
uploader.on('fileProgress', _fileProgress); |
|
|
|
}); |
|
|
|
|
|
|
|
watch( |
|
|
|
() => unref(btnRef), |
|
|
|
(btn) => { |
|
|
|
uploader.assignBrowse(btn); |
|
|
|
}, |
|
|
|
); |
|
|
|
onUnmounted(() => { |
|
|
|
// uploader.off('fileSuccess', _fileSuccess); |
|
|
|
uploader.off('filesSubmitted', _filesSubmitted); |
|
|
|
uploader.off('fileError', _fileError); |
|
|
|
uploader.off('fileProgress', _fileProgress); |
|
|
|
uploader = null; |
|
|
|
}); |
|
|
|
|
|
|
|
function _filesSubmitted(_, files) { |
|
|
|
files.forEach((f) => { |
|
|
|
f.paused = true; |
|
|
|
f.progress = '0 %'; |
|
|
|
}); |
|
|
|
fileList.value.push(...files); |
|
|
|
} |
|
|
|
watch( |
|
|
|
() => unref(btnRef), |
|
|
|
(btn) => { |
|
|
|
uploader.assignBrowse(btn); |
|
|
|
}, |
|
|
|
); |
|
|
|
|
|
|
|
function _fileProgress(_, file) { |
|
|
|
if (file._prevUploadedSize) { |
|
|
|
file.progress = `${Math.floor((file._prevUploadedSize / file.size) * 100)} %`; |
|
|
|
} |
|
|
|
} |
|
|
|
function _filesSubmitted(_, files) { |
|
|
|
files.forEach((f) => { |
|
|
|
f.paused = true; |
|
|
|
f.progress = '0 %'; |
|
|
|
}); |
|
|
|
fileList.value.push(...files); |
|
|
|
} |
|
|
|
|
|
|
|
function _fileError(_, file, message) { |
|
|
|
file.paused = true; |
|
|
|
if (message) { |
|
|
|
const formatedError = JSON.parse(message); |
|
|
|
file.errorMsg = formatedError.error?.message; |
|
|
|
} |
|
|
|
} |
|
|
|
function _fileProgress(_, file) { |
|
|
|
if (file._prevUploadedSize) { |
|
|
|
file.progress = `${Math.floor((file._prevUploadedSize / file.size) * 100)} %`; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
function handleSelect() { |
|
|
|
unref(btnRef)?.click(); |
|
|
|
} |
|
|
|
function _fileError(_, file, message) { |
|
|
|
file.paused = true; |
|
|
|
if (message) { |
|
|
|
const formatedError = JSON.parse(message); |
|
|
|
file.errorMsg = formatedError.error?.message; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
function handleResume(record) { |
|
|
|
if (record.error) { |
|
|
|
record.retry(); |
|
|
|
record.errorMsg = ''; |
|
|
|
} |
|
|
|
record.resume(); |
|
|
|
} |
|
|
|
function handleSelect() { |
|
|
|
unref(btnRef)?.click(); |
|
|
|
} |
|
|
|
|
|
|
|
function handlePause(record) { |
|
|
|
record.pause(); |
|
|
|
} |
|
|
|
function handleResume(record) { |
|
|
|
if (record.error) { |
|
|
|
record.retry(); |
|
|
|
record.errorMsg = ''; |
|
|
|
} |
|
|
|
record.resume(); |
|
|
|
} |
|
|
|
|
|
|
|
function handleCancel(record) { |
|
|
|
record.cancel(); |
|
|
|
uploader.removeFile(record); |
|
|
|
fileList.value = fileList.value.filter((f) => f.id !== record.id); |
|
|
|
} |
|
|
|
function handlePause(record) { |
|
|
|
record.pause(); |
|
|
|
} |
|
|
|
|
|
|
|
const fileSize = computed(() => { |
|
|
|
return (size) => { |
|
|
|
return Uploader.utils.formatSize(size); |
|
|
|
}; |
|
|
|
}); |
|
|
|
function handleCancel(record) { |
|
|
|
record.cancel(); |
|
|
|
uploader.removeFile(record); |
|
|
|
fileList.value = fileList.value.filter((f) => f.id !== record.id); |
|
|
|
} |
|
|
|
|
|
|
|
const averageSpeed = computed(() => { |
|
|
|
return (speed) => { |
|
|
|
return `${Uploader.utils.formatSize(speed)} / s`; |
|
|
|
}; |
|
|
|
}); |
|
|
|
const fileSize = computed(() => { |
|
|
|
return (size) => { |
|
|
|
return Uploader.utils.formatSize(size); |
|
|
|
}; |
|
|
|
}); |
|
|
|
|
|
|
|
return { |
|
|
|
L, |
|
|
|
btnRef, |
|
|
|
fileSize, |
|
|
|
averageSpeed, |
|
|
|
registerModal, |
|
|
|
registerTable, |
|
|
|
handleSelect, |
|
|
|
handleResume, |
|
|
|
handlePause, |
|
|
|
handleCancel, |
|
|
|
}; |
|
|
|
}, |
|
|
|
const averageSpeed = computed(() => { |
|
|
|
return (speed) => { |
|
|
|
return `${Uploader.utils.formatSize(speed)} / s`; |
|
|
|
}; |
|
|
|
}); |
|
|
|
</script> |
|
|
|
|