DirectionAndCategory.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <script lang="ts" setup>
  2. import { ref, onMounted, reactive } from "vue";
  3. import { ElMessage } from "element-plus";
  4. import { genFileId } from "element-plus";
  5. import axios from "axios";
  6. const leftDirection = ref("东");
  7. const rightDirection = ref("西");
  8. const directionList = ref<any>([
  9. { value: "东", label: "东" },
  10. { value: "西", label: "西" },
  11. { value: "南", label: "南" },
  12. { value: "北", label: "北" },
  13. ]);
  14. const flag = ref<string>("");
  15. const disableFlag = ref<boolean>(false);
  16. const upload = ref<any>();
  17. const formData = ref<any>();
  18. const fileType = ref<string>("");
  19. const taskType = ref<string>("class_direc");
  20. //车辆类型
  21. const car_type = ref<string>("");
  22. //运动方向
  23. const direction_run = ref<string>("");
  24. //文件的对象
  25. const currentFile = ref<any>();
  26. const uploadFile = (file: any) => {
  27. currentFile.value = file.file;
  28. let name = file.file.name;
  29. let index = name.lastIndexOf(".");
  30. fileType.value = name.substr(index + 1);
  31. // fileType.value = e.target.files[0].name;
  32. //校验文件名字
  33. if (!reType(fileType.value)) {
  34. alert;
  35. ElMessage({
  36. message: "请选择正确的文件格式",
  37. type: "error",
  38. });
  39. //清空选择的列表
  40. upload.value.clearFiles();
  41. currentFile.value = null;
  42. fileType.value = "";
  43. return;
  44. }
  45. };
  46. const startFun = () => {
  47. const formData = new FormData();
  48. formData.append("file", currentFile.value);
  49. formData.append("userName", name.value);
  50. formData.append("fileType", fileType.value);
  51. //第一个方向
  52. formData.append("negativaDir", leftDirection.value);
  53. //第二个方向
  54. formData.append("positiveDir", rightDirection.value);
  55. formData.append("taskType", taskType.value);
  56. disableFlag.value = true;
  57. axios
  58. .post(`/v1/record/create`, formData)
  59. .then((res) => {
  60. console.log(res);
  61. debugger;
  62. //如果结果是返回的是正确的
  63. if (res?.data?.code == 200) {
  64. disableFlag.value = false;
  65. flag.value = res.data.data;
  66. // chartList = arr2;
  67. //开始调用 //查询记录详情
  68. queryDetail();
  69. //发送以后得到返回的id,然后一直启动轮询一直调接口
  70. }
  71. })
  72. .catch((err) => {
  73. disableFlag.value = false;
  74. });
  75. // formData.append("userName", params.name);
  76. // formData.append("fileType", fileForma.value);
  77. };
  78. const queryDetail = () => {
  79. axios.get(`/v1/record/${flag.value}/find`, {}).then((res) => {
  80. if (res.data.code == 200) {
  81. //当结果为空时
  82. // ElMessage({
  83. // message: `结果为${res.data.data.Result}`,
  84. // type: "error",
  85. // });
  86. car_type.value = res.data.data.Result;
  87. direction_run.value = res.data.data.Result;
  88. if (res.data.data.Result == "") {
  89. ElMessage({
  90. message: `解析结果为空`,
  91. type: "success",
  92. });
  93. }else{
  94. //查看是否包含;
  95. //判断字符串中是否包含分号 ;
  96. let a =res.data.data.Result;
  97. if( a.inclides(';')){
  98. let b = res.data.data.Result
  99. car_type.value = b[0];
  100. direction_run.value =b[1];
  101. }else{
  102. car_type.value = res.data.data.Result;
  103. direction_run.value = res.data.data.Result;
  104. }
  105. }
  106. }
  107. // console.log(res.data.data.Result !== "");
  108. });
  109. };
  110. const fileList = ref<any>([]);
  111. const name = ref<string>("");
  112. const reType = (val: string): boolean => {
  113. if (
  114. val == "json" ||
  115. val == "txt" ||
  116. val == "wav" ||
  117. val == "npy" ||
  118. val == "xls" ||
  119. val == "xlsx" ||
  120. val == "sql"
  121. ) {
  122. return true;
  123. } else {
  124. return false;
  125. }
  126. };
  127. const handleExceed: any["onExceed"] = (files) => {
  128. upload.value!.clearFiles();
  129. const file = files[0] as any;
  130. file.uid = genFileId();
  131. upload.value!.handleStart(file);
  132. };
  133. onMounted(() => {
  134. name.value = JSON.parse(sessionStorage.getItem("userInfo") ?? "{}")?.organName;
  135. });
  136. </script>
  137. <template>
  138. <div class="out">
  139. <p>车辆类别与方向检测</p>
  140. <div class="inner_content">
  141. <div class="inner_first">
  142. <div style="margin-bottom: 10px">选择文件</div>
  143. <el-upload
  144. ref="upload"
  145. auto-upload="false"
  146. class="upload-demo"
  147. :on-change="handleChange"
  148. :file-list="fileList"
  149. drag
  150. :limit="1"
  151. :on-exceed="handleExceed"
  152. action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15"
  153. :http-request="uploadFile"
  154. >
  155. <el-icon class="el-icon--upload"><upload-filled /></el-icon>
  156. <div class="el-upload__text"><em>点击上传</em></div>
  157. <template #tip>
  158. <!-- <div class="el-upload__tip">jpg/png files with a size less than 500kb</div> -->
  159. </template>
  160. </el-upload>
  161. <div style="margin-bottom: 10px">选择方向</div>
  162. <div class="class_dre">
  163. <el-select
  164. v-model="leftDirection"
  165. placeholder="Select"
  166. size="large"
  167. style="width: 70px"
  168. >
  169. <el-option
  170. v-for="item in directionList"
  171. :key="item.value"
  172. :label="item.label"
  173. :value="item.value"
  174. :disabled="item.value == rightDirection"
  175. />
  176. </el-select>
  177. <img style="width: 350px" src="../assets/content/kedu.png" alt="" />
  178. <el-select
  179. v-model="rightDirection"
  180. placeholder="Select"
  181. size="large"
  182. style="width: 70px"
  183. >
  184. <el-option
  185. v-for="item in directionList"
  186. :key="item.value"
  187. :label="item.label"
  188. :value="item.value"
  189. :disabled="item.value == leftDirection"
  190. />
  191. </el-select>
  192. </div>
  193. <div class="start_pg">
  194. <el-button @click="startFun" :disabled="disableFlag">开始检测</el-button>
  195. </div>
  196. <div></div>
  197. <div class="run_dir">
  198. <div>检测结果:</div>
  199. <div class="run_input">{{ car_type }}</div>
  200. </div>
  201. <div class="run_dir">
  202. <div>运动方向:</div>
  203. <div class="run_input">{{ direction_run }}</div>
  204. </div>
  205. </div>
  206. </div>
  207. </div>
  208. </template>
  209. <style scoped lang="less">
  210. .out {
  211. height: 80vh;
  212. display: flex;
  213. flex-direction: column;
  214. /* background-color: #F0F3FA; */
  215. }
  216. .inner_content {
  217. display: flex;
  218. justify-content: center;
  219. width: 100%;
  220. flex: 1;
  221. .inner_first {
  222. width: 500px;
  223. .class_dre {
  224. display: flex;
  225. flex-direction: row;
  226. align-items: center;
  227. }
  228. }
  229. /* background-color: #f0f3fa; */
  230. }
  231. .start_pg {
  232. display: flex;
  233. justify-content: end;
  234. margin-top: 20px;
  235. }
  236. .run_dir {
  237. display: flex;
  238. flex-direction: row;
  239. align-items: center;
  240. margin-top: 20px;
  241. .run_input {
  242. word-break: break-all;
  243. margin-left: 20px;
  244. flex: 1;
  245. border: 1px solid #d0d3d9;
  246. height: 40px;
  247. // line-height: 40px;
  248. padding-left: 20px;
  249. }
  250. }
  251. </style>