|
|
@@ -11,13 +11,29 @@
|
|
|
:confirmLoading="loading"
|
|
|
:min-height="0"
|
|
|
>
|
|
|
- <div class="pt-2px pr-3px">
|
|
|
+ <div class="pt-2px pr-3px myzdyfrom">
|
|
|
<BasicForm @register="registerForm" :model="model">
|
|
|
<template #text="{ model, field }">
|
|
|
{{ model[field] }}
|
|
|
</template>
|
|
|
+ <template #elupload="{ model, field }">
|
|
|
+ <Upload
|
|
|
+ style="width: 300px"
|
|
|
+ :file-list="fileFlow.list"
|
|
|
+ :before-upload="beforeUpload"
|
|
|
+ name="file"
|
|
|
+ ref="uploadRef"
|
|
|
+ accept=".zip"
|
|
|
+ :customRequest="handleCustomRequest"
|
|
|
+ @progress="handleProgress"
|
|
|
+ @remove="handleRemove"
|
|
|
+ @change="handleChange"
|
|
|
+ >
|
|
|
+ <a-button type="primary"> 上传</a-button>
|
|
|
+ </Upload>
|
|
|
+ </template>
|
|
|
</BasicForm>
|
|
|
- <!-- <span>注意:迁移后该场景的权限配置将被清空,如需保留,请复制后再做迁移</span> -->
|
|
|
+ <!-- :headers="headers" <span>注意:迁移后该场景的权限配置将被清空,如需保留,请复制后再做迁移</span> -->
|
|
|
</div>
|
|
|
</BasicModal>
|
|
|
</template>
|
|
|
@@ -27,12 +43,13 @@
|
|
|
import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
|
|
|
import { useMessage } from '/@/hooks/web/useMessage';
|
|
|
import { uploadSceneOrig, uploadSceneCheck } from '/@/api/operate';
|
|
|
+ import { Upload } from 'ant-design-vue';
|
|
|
import { useI18n } from '/@/hooks/web/useI18n';
|
|
|
import { uploadApi } from '/@/api/product/index';
|
|
|
|
|
|
const { t } = useI18n();
|
|
|
export default defineComponent({
|
|
|
- components: { BasicModal, BasicForm },
|
|
|
+ components: { BasicModal, BasicForm, Upload },
|
|
|
props: {
|
|
|
userData: { type: Object },
|
|
|
},
|
|
|
@@ -40,33 +57,46 @@
|
|
|
setup(props, { emit }) {
|
|
|
const modelRef = ref({});
|
|
|
const fileFlow = reactive({
|
|
|
+ list: [],
|
|
|
+ percent: 0,
|
|
|
filePath: null,
|
|
|
});
|
|
|
const loading = ref(false);
|
|
|
+ const uploadRef = ref(null);
|
|
|
const { createMessage, createConfirm } = useMessage();
|
|
|
+ const valiFile = async (_rule: Rule, value: string) => {
|
|
|
+ console.log(fileFlow, 'fileFlow');
|
|
|
+ if (fileFlow.list && fileFlow.list.length == 0) {
|
|
|
+ return Promise.reject(t('common.uploadMessge'));
|
|
|
+ } else {
|
|
|
+ return Promise.resolve();
|
|
|
+ }
|
|
|
+ };
|
|
|
const schemas: FormSchema[] = [
|
|
|
{
|
|
|
+ field: 'sourceType',
|
|
|
+ component: 'RadioGroup',
|
|
|
+ label: '类型',
|
|
|
+ defaultValue: 'orig',
|
|
|
+ required: true,
|
|
|
+ colProps: {
|
|
|
+ span: 24,
|
|
|
+ },
|
|
|
+ componentProps: {
|
|
|
+ options: [
|
|
|
+ { label: '原始数据', value: 'orig' },
|
|
|
+ { label: '离线包', value: 'offline' },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
field: 'filePath',
|
|
|
component: 'Upload',
|
|
|
+ slot: 'elupload',
|
|
|
label: t('routes.product.file'),
|
|
|
required: true,
|
|
|
- rules: [{ required: true, message: t('common.uploadMessge') }],
|
|
|
+ rules: [{ required: true, validator: valiFile, trigger: 'change' }],
|
|
|
// helpMessage: t('routes.corporation.uploadHelp'),
|
|
|
- itemProps: {
|
|
|
- validateTrigger: 'onBlur',
|
|
|
- },
|
|
|
- componentProps: {
|
|
|
- api: uploadApi,
|
|
|
- maxNumber: 1,
|
|
|
- sizeUnit: 'GB',
|
|
|
- maxSize: 5,
|
|
|
- // accept: ['xls', 'xlsx'],
|
|
|
- afterFetch: function (data) {
|
|
|
- fileFlow.filePath = data.file;
|
|
|
- return data;
|
|
|
- },
|
|
|
- },
|
|
|
-
|
|
|
colProps: {
|
|
|
span: 22,
|
|
|
},
|
|
|
@@ -90,15 +120,45 @@
|
|
|
function onDataReceive(data) {
|
|
|
modelRef.value = data;
|
|
|
resetFields();
|
|
|
- setFieldsValue({
|
|
|
- type: data.sceneName,
|
|
|
+ // setFieldsValue({
|
|
|
+ // type: data.sceneName,
|
|
|
+ // });
|
|
|
+ }
|
|
|
+ function beforeUpload(file: File) {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ const { size, name } = file;
|
|
|
+ let maxSize = 5; // 单位MB
|
|
|
+ let accept = ['zip']; // 单位MB
|
|
|
+ let sizeUnit = 'GB'; // 单位MB
|
|
|
+ const type = name.split('.').pop() || '';
|
|
|
+ console.log('beforeUpload', type, name);
|
|
|
+ if (accept && accept.length > 0 && !accept.includes(type.toLowerCase())) {
|
|
|
+ createMessage.error(t('component.upload.accept', [accept.join(',')]));
|
|
|
+ (file.status = 'error'), (fileFlow.list = []);
|
|
|
+ uploadRef.value.clearFiles();
|
|
|
+ return reject(false);
|
|
|
+ }
|
|
|
+ let newMaxSize =
|
|
|
+ sizeUnit == 'GB' ? maxSize * 1024 : sizeUnit == 'KB' ? maxSize / 1024 : maxSize;
|
|
|
+ // 设置最大值,则判断
|
|
|
+ if (maxSize && file.size / 1024 / 1024 >= newMaxSize) {
|
|
|
+ createMessage.error(
|
|
|
+ t('component.upload.maxSizeMultiple', { number: maxSize, unit: sizeUnit || 'MB' }),
|
|
|
+ );
|
|
|
+ (file.status = 'error'), (fileFlow.list = []);
|
|
|
+ uploadRef.value.clearFiles();
|
|
|
+ return reject(false);
|
|
|
+ }
|
|
|
+ fileFlow.list = [file];
|
|
|
+ return resolve(true);
|
|
|
});
|
|
|
}
|
|
|
const handleSubmit = async () => {
|
|
|
try {
|
|
|
const params = await validate();
|
|
|
- let filePath = params.filePath[0];
|
|
|
- const resCheck = await uploadSceneCheck(filePath);
|
|
|
+ const filePath = fileFlow.filePath
|
|
|
+ console.log('params', params, filePath, fileFlow.list);
|
|
|
+ const resCheck = await uploadSceneCheck({filePath, sourceType: params.sourceType});
|
|
|
if (resCheck.code == 60042) {
|
|
|
return createConfirm({
|
|
|
iconType: 'warning',
|
|
|
@@ -112,25 +172,33 @@
|
|
|
h('div', null, `确定继续吗?`),
|
|
|
]),
|
|
|
onOk: async () => {
|
|
|
- Submit(filePath)
|
|
|
+ Submit(filePath);
|
|
|
},
|
|
|
});
|
|
|
}
|
|
|
- if(resCheck.code == 60043) {
|
|
|
+ if (resCheck.code == 60043) {
|
|
|
return createConfirm({
|
|
|
iconType: 'warning',
|
|
|
title: '提示',
|
|
|
content: `此场景此前已上传过,继续上传将重新计算并覆盖原场景,场景内由用户手动添加的空间模型也会清空,确定继续吗?`,
|
|
|
onOk: async () => {
|
|
|
- Submit(filePath)
|
|
|
+ Submit(filePath);
|
|
|
},
|
|
|
});
|
|
|
}
|
|
|
- Submit(filePath)
|
|
|
+ Submit(filePath);
|
|
|
} catch (error) {
|
|
|
console.log('not passing', error);
|
|
|
}
|
|
|
};
|
|
|
+ function handleChange(value){
|
|
|
+ console.log('handleChange', value);
|
|
|
+ }
|
|
|
+ function handleRemove(file){
|
|
|
+ fileFlow.list = fileFlow.list.filter(item => item.uid !== file.uid);
|
|
|
+ console.log('handleRemove', file);
|
|
|
+ }
|
|
|
+
|
|
|
function handleVisibleChange(v) {
|
|
|
// console.log(v);
|
|
|
// v && props.userData && nextTick(() => onDataReceive(props.userData));
|
|
|
@@ -138,7 +206,8 @@
|
|
|
async function Submit(filePath) {
|
|
|
loading.value = true;
|
|
|
try {
|
|
|
- const res = await uploadSceneOrig(filePath);
|
|
|
+ const params = await validate();
|
|
|
+ const res = await uploadSceneOrig({filePath, sourceType: params.sourceType});
|
|
|
loading.value = false;
|
|
|
console.log('res', res, filePath);
|
|
|
closeModal();
|
|
|
@@ -148,7 +217,37 @@
|
|
|
} catch (error) {
|
|
|
loading.value = false;
|
|
|
}
|
|
|
-
|
|
|
+ }
|
|
|
+ function handleProgress(file) {
|
|
|
+ // file 对象包含了上传进度信息
|
|
|
+ console.log('上传进度:', file.percent);
|
|
|
+ // antd-vue Upload 组件会自动处理进度条显示
|
|
|
+ }
|
|
|
+ async function handleCustomRequest(option) {
|
|
|
+ if(!option){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const params = await validate();
|
|
|
+ let file = fileFlow.list && fileFlow.list[0];
|
|
|
+ const apiData = {
|
|
|
+ file: file,
|
|
|
+ data: {
|
|
|
+ dictId: params.dictId,
|
|
|
+ },
|
|
|
+ };
|
|
|
+ loading.value = true;
|
|
|
+ fileFlow.complete = 0;
|
|
|
+ function onUploadProgress(progressEvent: ProgressEvent) {
|
|
|
+ const complete = ((progressEvent.loaded / progressEvent.total) * 100) | 0;
|
|
|
+ fileFlow.complete = complete;
|
|
|
+ }
|
|
|
+ let url = await uploadApi(apiData, onUploadProgress);
|
|
|
+ option.onSuccess && option.onSuccess();
|
|
|
+ console.log('uploadApi', url);
|
|
|
+ fileFlow.filePath = url;
|
|
|
+ loading.value = false;
|
|
|
+ createMessage.success('上传成功。');
|
|
|
+ return url;
|
|
|
}
|
|
|
return {
|
|
|
register,
|
|
|
@@ -156,13 +255,26 @@
|
|
|
registerForm,
|
|
|
model: modelRef,
|
|
|
fileFlow,
|
|
|
+ handleProgress,
|
|
|
+ handleCustomRequest,
|
|
|
handleVisibleChange,
|
|
|
handleSubmit,
|
|
|
addListFunc,
|
|
|
loading,
|
|
|
resetFields,
|
|
|
+ beforeUpload,
|
|
|
+ handleChange,
|
|
|
+ handleRemove,
|
|
|
+ uploadRef,
|
|
|
t,
|
|
|
};
|
|
|
},
|
|
|
});
|
|
|
</script>
|
|
|
+<style lang="less">
|
|
|
+ .myzdyfrom {
|
|
|
+ .ant-upload-list {
|
|
|
+ width: 300px;
|
|
|
+ }
|
|
|
+ }
|
|
|
+</style>
|