ImportPlatform.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <template>
  2. <n-button type="primary" @click="showImportModal"
  3. >导入数据(冷链平台)</n-button
  4. >
  5. <n-modal
  6. style="width: 30%"
  7. v-model:show="showModal"
  8. :show-icon="false"
  9. preset="dialog"
  10. title="导入"
  11. >
  12. <n-space vertical>
  13. <n-card>
  14. <n-form
  15. :model="formValue"
  16. label-placement="left"
  17. label-width="auto"
  18. show-require-mark
  19. >
  20. <n-form-item label="起止时间">
  21. <n-date-picker
  22. value-format="yyyy.MM.dd HH:mm:ss"
  23. type="datetimerange"
  24. @update:formatted-value="
  25. (value) => {
  26. formValue.Time_start = value[0];
  27. formValue.Time_end = value[1];
  28. }
  29. "
  30. />
  31. </n-form-item>
  32. <n-form-item label="SN" path="T_sn">
  33. <n-input v-model:value="formValue.T_sn" />
  34. </n-form-item>
  35. <n-form-item label="探头编号" path="T_id">
  36. <n-input v-model:value="formValue.T_id" />
  37. </n-form-item>
  38. </n-form>
  39. <template #action>
  40. <div class="flex justify-end">
  41. <n-button type="primary" @click="getDataList">查询</n-button>
  42. </div>
  43. </template>
  44. </n-card>
  45. <n-card title="数据总量">
  46. <template #header-extra>
  47. <n-spin :show="spinShow">
  48. <n-progress
  49. type="dashboard"
  50. gap-position="bottom"
  51. :percentage="100"
  52. >
  53. <span class="text-center font-bold"
  54. >{{ percentage }}/{{ total }}</span
  55. >
  56. </n-progress>
  57. </n-spin>
  58. </template>
  59. <n-descriptions bordered class="mt-auto">
  60. <n-descriptions-item label="SN">
  61. {{ formValue.T_sn }}
  62. </n-descriptions-item>
  63. <n-descriptions-item label="探头编号">
  64. {{ formValue.T_id }}
  65. </n-descriptions-item>
  66. </n-descriptions>
  67. <template #action>
  68. <div class="flex justify-end">
  69. <n-popconfirm @positive-click="handleImport">
  70. <template #trigger>
  71. <n-button type="primary" :disabled="disableds">导入</n-button>
  72. </template>
  73. 是否确认导入?
  74. </n-popconfirm>
  75. </div>
  76. </template>
  77. </n-card>
  78. </n-space>
  79. </n-modal>
  80. </template>
  81. <script setup>
  82. import { getV3DataList, addTaskDatas } from '@/api';
  83. import { useMessage } from 'naive-ui';
  84. const message = useMessage();
  85. const notification = useNotification();
  86. const props = defineProps({
  87. task: {
  88. required: true,
  89. default: {},
  90. },
  91. });
  92. const disableds = ref(false)
  93. // 是否展示 Modal
  94. const showModal = ref(false);
  95. // 是否展示 Spinner
  96. const spinShow = ref(false);
  97. //
  98. const dataList = ref([]);
  99. // 总数
  100. const total = ref(0);
  101. // 表单数据
  102. const formValue = reactive({
  103. Time_start: null,
  104. Time_end: null,
  105. T_sn: null,
  106. T_id: null,
  107. page: 1,
  108. page_z: 9999,
  109. });
  110. // 当前完成数
  111. const percentage = ref(0);
  112. // 显示导入
  113. const showImportModal = () => {
  114. showModal.value = true;
  115. formValue.Time_start = null;
  116. formValue.Time_end = null;
  117. formValue.T_sn = null;
  118. formValue.T_id = null;
  119. disableds.value = false
  120. // formValue.Time_start = '2023.04.25 00:00:00';
  121. // formValue.Time_end = '2023.04.25 00:30:00';
  122. // formValue.T_sn = 2023141974576341;
  123. // formValue.T_id = 1;
  124. total.value = 0;
  125. percentage.value = 0;
  126. };
  127. let flag = ref(false)
  128. // 批量导入
  129. const handleImport = async () => {
  130. if(flag.value) return
  131. flag.value = true
  132. if (dataList.value.length === 0) return message.info('无数据');
  133. disableds.value = true
  134. let arr = dataList.value
  135. let chunk = 100;
  136. for (let i = 0; i < arr.length; i += chunk) {
  137. let dataIt = await dataFun(arr.slice(i, i + chunk))
  138. const resIt = await addTask(dataIt)
  139. percentage.value += Number(resIt.data.Data)
  140. if(percentage.value==total.value){
  141. message.success('数据导入完成')
  142. flag.value = false
  143. }
  144. }
  145. };
  146. const dataFun = (arr)=>{
  147. return new Promise(resolve=>{
  148. const arr1 = arr.map(item => item.T_sn + '-'+ item.T_id + '|' + item.T_id + '|' + item.T_t + '|' + item.T_rh + '|' + item.T_time)
  149. resolve(arr1.join('?'))
  150. })
  151. }
  152. // 导入任务
  153. const addTask = async (item) => {
  154. return new Promise(resolve=>{
  155. setTimeout(() => {
  156. const res = addTaskDatas({
  157. T_task_id: props.task.T_task_id,
  158. T_Data:item
  159. });
  160. resolve(res)
  161. },100)
  162. })
  163. };
  164. // 查询数据
  165. const getDataList = async () => {
  166. console.log('查询1',formValue)
  167. const sto = await inspect(formValue)
  168. console.log('查询2',formValue)
  169. if(sto){
  170. // spinShow.value = true;
  171. const { data: res } = await getV3DataList({
  172. Time_start: formValue.Time_start + '',
  173. Time_end: formValue.Time_end + '',
  174. T_snid: `${formValue.T_sn},${formValue.T_id}|`,
  175. page: 1,
  176. page_z: 9999,
  177. });
  178. dataList.value = res.Data.Data || [];
  179. total.value = res.Data.Num || 0;
  180. }else{
  181. message.error('搜索条件全部必填哦')
  182. }
  183. };
  184. const inspect = (value)=>{
  185. return new Promise(resolve=>{
  186. if(value.Time_start!= null && value.Time_end!=null && value.T_sn!=null && value.T_id!=null){
  187. resolve(true)
  188. }else{
  189. resolve(false)
  190. }
  191. })
  192. }
  193. </script>
  194. <style lang="scss" scoped></style>