downloadModal.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <BasicModal
  3. v-bind="$attrs"
  4. @register="register"
  5. :title="t('routes.scenes.downloadScene')"
  6. :showCancelBtn="false"
  7. :okText="t('routes.scenes.cancelDownload')"
  8. @ok="handleSubmit"
  9. @cancel="cancelDownload"
  10. >
  11. <div class="pt-20px">
  12. <BasicForm @register="registerForm">
  13. <template #label="{ model, field }">
  14. {{ model[field] }}
  15. </template>
  16. <template #process> {{ downloadInfo.process }} % </template>
  17. <template #status> {{ downloadInfo.status }} </template>
  18. </BasicForm>
  19. </div>
  20. <template #centerFooter>
  21. <!-- <a-button>xxxx</a-button> -->
  22. </template>
  23. </BasicModal>
  24. </template>
  25. <script lang="ts">
  26. import { defineComponent, reactive, ref, watch } from 'vue';
  27. import { BasicModal, useModalInner } from '/@/components/Modal';
  28. import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
  29. // import { BasicTable, useTable, BasicColumn, FormSchema } from '/@/components/Table';
  30. // import { useMessage } from '/@/hooks/web/useMessage';
  31. // import { checkUserAddAble } from '/@/api/corporation/modal';
  32. import { useI18n } from '/@/hooks/web/useI18n';
  33. import { getDownloadProcessApi } from '/@/api/scene/list';
  34. // import { bindAnchorListParam } from '/@/api/scene/model';
  35. // import { Time } from '/@/components/Time';
  36. // import { useUserStore } from '/@/store/modules/user';
  37. const schemas: FormSchema[] = [
  38. {
  39. field: 'sceneName',
  40. label: '场景名称:',
  41. component: 'Input',
  42. slot: 'label',
  43. },
  44. {
  45. field: 'process',
  46. label: '下载进度:',
  47. component: 'Input',
  48. slot: 'process',
  49. },
  50. {
  51. field: 'status',
  52. label: '状态:',
  53. component: 'Input',
  54. slot: 'status',
  55. },
  56. ];
  57. export default defineComponent({
  58. components: { BasicModal, BasicForm },
  59. props: {
  60. userData: { type: Object },
  61. },
  62. emits: ['register', 'success'],
  63. setup() {
  64. const { t } = useI18n();
  65. // const { createMessage } = useMessage();
  66. const sceneNum = ref('');
  67. const downloadInfo = reactive<Recordable>({});
  68. downloadInfo.timer = null;
  69. downloadInfo.process = 0;
  70. downloadInfo.status = '下载中';
  71. const [registerForm, { setFieldsValue }] = useForm({
  72. schemas: schemas,
  73. labelWidth: 120,
  74. showActionButtonGroup: false,
  75. actionColOptions: {
  76. span: 24,
  77. },
  78. // submitFunc: handleSubmit,
  79. });
  80. const [register, { closeModal }] = useModalInner((data) => {
  81. data && onDataReceive(data);
  82. });
  83. function onDataReceive(data) {
  84. console.log('Data Received', data, data.num);
  85. setFieldsValue({
  86. ...data,
  87. });
  88. sceneNum.value = data.num;
  89. }
  90. const handleSubmit = async () => {
  91. try {
  92. cancelDownload();
  93. closeModal();
  94. } catch (error) {}
  95. };
  96. async function getDownloadInfo(sceneNum: string) {
  97. downloadInfo.timer = setInterval(async () => {
  98. const res = await getDownloadProcessApi({ sceneNum });
  99. console.log('res', res);
  100. const percent = res.percent;
  101. downloadInfo.process = percent;
  102. }, 2000);
  103. }
  104. function cancelDownload() {
  105. clearInterval(downloadInfo.timer);
  106. sceneNum.value = '';
  107. }
  108. watch(
  109. () => sceneNum.value,
  110. () => {
  111. console.log('sceneNum', sceneNum.value);
  112. if (sceneNum.value) {
  113. getDownloadInfo(sceneNum.value);
  114. }
  115. },
  116. );
  117. return {
  118. t,
  119. register,
  120. schemas,
  121. handleSubmit,
  122. closeModal,
  123. registerForm,
  124. downloadInfo,
  125. cancelDownload,
  126. };
  127. },
  128. });
  129. </script>