uploadModal.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <BasicModal
  3. v-bind="$attrs"
  4. @register="register"
  5. title="原始数据上传"
  6. :showCancelBtn="false"
  7. @visible-change="handleVisibleChange"
  8. @cancel="resetFields"
  9. @ok="handleSubmit"
  10. :loading="loading"
  11. :min-height="0"
  12. >
  13. <div class="pt-2px pr-3px">
  14. <BasicForm @register="registerForm" :model="model">
  15. <template #text="{ model, field }">
  16. {{ model[field] }}
  17. </template>
  18. </BasicForm>
  19. <!-- <span>注意:迁移后该场景的权限配置将被清空,如需保留,请复制后再做迁移</span> -->
  20. </div>
  21. </BasicModal>
  22. </template>
  23. <script lang="ts">
  24. import { defineComponent, ref, nextTick, onMounted, reactive, h } from 'vue';
  25. import { BasicModal, useModalInner } from '/@/components/Modal';
  26. import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
  27. import { useMessage } from '/@/hooks/web/useMessage';
  28. import { uploadSceneOrig, uploadSceneCheck } from '/@/api/operate';
  29. import { useI18n } from '/@/hooks/web/useI18n';
  30. import { uploadApi } from '/@/api/product/index';
  31. const { t } = useI18n();
  32. export default defineComponent({
  33. components: { BasicModal, BasicForm },
  34. props: {
  35. userData: { type: Object },
  36. },
  37. emits: ['update', 'register'],
  38. setup(props, { emit }) {
  39. const modelRef = ref({});
  40. const fileFlow = reactive({
  41. filePath: null,
  42. });
  43. const loading = ref(false);
  44. const { createMessage, createConfirm } = useMessage();
  45. const schemas: FormSchema[] = [
  46. {
  47. field: 'filePath',
  48. component: 'Upload',
  49. label: t('routes.product.file'),
  50. required: true,
  51. rules: [{ required: true, message: t('common.uploadMessge') }],
  52. // helpMessage: t('routes.corporation.uploadHelp'),
  53. itemProps: {
  54. validateTrigger: 'onBlur',
  55. },
  56. componentProps: {
  57. api: uploadApi,
  58. maxNumber: 1,
  59. sizeUnit: 'GB',
  60. maxSize: 5,
  61. // accept: ['xls', 'xlsx'],
  62. afterFetch: function (data) {
  63. fileFlow.filePath = data.file;
  64. return data;
  65. },
  66. },
  67. colProps: {
  68. span: 22,
  69. },
  70. },
  71. ];
  72. const [registerForm, { validate, resetFields, setFieldsValue }] = useForm({
  73. labelWidth: 120,
  74. schemas,
  75. showActionButtonGroup: false,
  76. actionColOptions: {
  77. span: 24,
  78. },
  79. });
  80. onMounted(() => {});
  81. let addListFunc = () => {};
  82. const [register, { closeModal }] = useModalInner((data) => {
  83. console.log(data);
  84. data && onDataReceive(data);
  85. });
  86. function onDataReceive(data) {
  87. modelRef.value = data;
  88. resetFields();
  89. setFieldsValue({
  90. type: data.sceneName,
  91. });
  92. }
  93. const handleSubmit = async () => {
  94. try {
  95. const params = await validate();
  96. let filePath = params.filePath[0];
  97. const resCheck = await uploadSceneCheck(filePath);
  98. if (resCheck.code == 60042) {
  99. return createConfirm({
  100. iconType: 'warning',
  101. title: '提示',
  102. content: () =>
  103. h('div', {}, [
  104. h('div', null, `此场景原属于${resCheck.data},继续上传将重新计算并覆盖原场景:`),
  105. h('div', null, `归属权转移至当前账号;`),
  106. h('div', null, `清除原所有者的权限设置;`),
  107. h('div', null, `清空场景内由用户手动添加的空间模型。`),
  108. h('div', null, `确定继续吗?`),
  109. ]),
  110. onOk: async () => {
  111. Submit(filePath)
  112. },
  113. });
  114. }
  115. if(resCheck.code == 60043) {
  116. return createConfirm({
  117. iconType: 'warning',
  118. title: '提示',
  119. content: `此场景此前已上传过‌,继续上传将重新计算并覆盖原场景,场景内由用户手动添加的空间模型也会清空,确定继续吗?`,
  120. onOk: async () => {
  121. Submit(filePath)
  122. },
  123. });
  124. }
  125. Submit(filePath)
  126. } catch (error) {
  127. console.log('not passing', error);
  128. }
  129. };
  130. function handleVisibleChange(v) {
  131. // console.log(v);
  132. // v && props.userData && nextTick(() => onDataReceive(props.userData));
  133. }
  134. async function Submit(filePath) {
  135. loading.value = true;
  136. const res = await uploadSceneOrig(filePath);
  137. loading.value = false;
  138. console.log('res', res, filePath);
  139. closeModal();
  140. resetFields();
  141. createMessage.success('上传成功。');
  142. emit('update');
  143. }
  144. return {
  145. register,
  146. schemas,
  147. registerForm,
  148. model: modelRef,
  149. fileFlow,
  150. handleVisibleChange,
  151. handleSubmit,
  152. addListFunc,
  153. loading,
  154. resetFields,
  155. t,
  156. };
  157. },
  158. });
  159. </script>