uploadE57Modal.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <BasicModal
  3. v-bind="$attrs"
  4. @register="register"
  5. :title="t('routes.archive.patchArchiveE57')"
  6. :showCancelBtn="false"
  7. :centered="true"
  8. :okText="t('common.okText')"
  9. :confirmLoading="loading"
  10. @ok="handleSubmit"
  11. @cancel="handleCancel"
  12. >
  13. <div class="pt-20px">
  14. <BasicForm @register="registerForm">
  15. <template #file>
  16. <Upload
  17. :file-list="fileList"
  18. accept=".e57"
  19. :maxCount="1"
  20. :beforeUpload="handleBeforeUpload"
  21. @remove="handleRemove"
  22. >
  23. <a-button type="primary">{{ t('layout.e57.e57upload') }}</a-button>
  24. </Upload>
  25. </template>
  26. <template #objType>
  27. <Checkbox v-model:checked="isObjCheck">{{ t('layout.e57.e57objText') }}</Checkbox>
  28. </template>
  29. <template #tips>
  30. <div style="word-break: break-all">{{ t('layout.e57.e57tip') }}</div>
  31. </template>
  32. </BasicForm>
  33. </div>
  34. <template #centerFooter>
  35. <!-- <a-button>xxxx</a-button> -->
  36. </template>
  37. </BasicModal>
  38. </template>
  39. <script lang="ts">
  40. import { defineComponent, reactive, ref } from 'vue';
  41. import { BasicModal, useModalInner } from '/@/components/Modal';
  42. import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
  43. import { useI18n } from '/@/hooks/web/useI18n';
  44. import { uploadE57Api } from '/@/api/scene/list';
  45. import { Upload, Checkbox } from 'ant-design-vue';
  46. import { useMessage } from '/@/hooks/web/useMessage';
  47. import type { UploadProps } from 'ant-design-vue';
  48. const loading = ref(false);
  49. const fileList = ref<UploadProps['fileList']>([]);
  50. const { t } = useI18n();
  51. const isObjCheck = ref(false);
  52. const schemas: FormSchema[] = [
  53. {
  54. field: 'file',
  55. label: t('layout.e57.e57name') + ':',
  56. component: 'Input',
  57. slot: 'file',
  58. },
  59. {
  60. field: 'objType',
  61. label: t('layout.e57.e57type') + ':',
  62. component: 'Input',
  63. slot: 'objType',
  64. },
  65. {
  66. field: 'tips',
  67. label: t('routes.archive.warmTips') + ':',
  68. component: 'Input',
  69. slot: 'tips',
  70. colProps: {
  71. span: 24,
  72. offset: 120,
  73. },
  74. },
  75. ];
  76. export default defineComponent({
  77. components: { BasicModal, BasicForm, Upload, Checkbox },
  78. props: {
  79. userData: { type: Object },
  80. },
  81. emits: ['register', 'success'],
  82. setup(_, { emit }) {
  83. const { t } = useI18n();
  84. const { createMessage } = useMessage();
  85. const downloadInfo = reactive<Recordable>({});
  86. const [registerForm] = useForm({
  87. schemas: schemas,
  88. labelWidth: 120,
  89. showActionButtonGroup: false,
  90. actionColOptions: {
  91. span: 24,
  92. },
  93. // submitFunc: handleSubmit,
  94. });
  95. const [register, { closeModal }] = useModalInner((data) => {
  96. data && onDataReceive();
  97. fileList.value = [];
  98. isObjCheck.value = false;
  99. });
  100. function onDataReceive() {}
  101. const handleSubmit = async () => {
  102. if (!fileList.value?.length)
  103. return createMessage.error(t('layout.e57.e57upload') + t('layout.e57.e57name'));
  104. try {
  105. console.log('file', fileList.value);
  106. // const from = new FormData();
  107. loading.value = true;
  108. await uploadE57Api(
  109. {
  110. file: fileList.value[0] as any as File,
  111. data: {
  112. isObj: Number(isObjCheck.value),
  113. },
  114. },
  115. );
  116. loading.value = false;
  117. closeModal();
  118. emit('success');
  119. } catch (error) {
  120. console.log('fileerror', error);
  121. loading.value = false;
  122. }
  123. };
  124. const handleBeforeUpload: UploadProps['beforeUpload'] = (file) => {
  125. const { size, name } = file;
  126. let hz = name.substring(name.lastIndexOf('.'));
  127. console.log('file', file, hz);
  128. if (hz !== '.e57') {
  129. createMessage.error(t('layout.e57.e57nametips'));
  130. return false;
  131. }
  132. if (size / 1024 / 1024 >= 20000) {
  133. fileList.value = [];
  134. return false;
  135. }
  136. fileList.value = [file];
  137. return false;
  138. };
  139. const handleRemove: UploadProps['onRemove'] = (file) => {
  140. const index = fileList.value.indexOf(file);
  141. const newFileList = fileList.value.slice();
  142. newFileList.splice(index, 1);
  143. fileList.value = newFileList;
  144. };
  145. const handleCancel = () => {};
  146. return {
  147. t,
  148. register,
  149. schemas,
  150. handleSubmit,
  151. closeModal,
  152. registerForm,
  153. downloadInfo,
  154. handleBeforeUpload,
  155. isObjCheck,
  156. handleCancel,
  157. fileList,
  158. handleRemove,
  159. loading,
  160. };
  161. },
  162. });
  163. </script>