ManageEquipment.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. <template>
  2. <div class="main_right_height">
  3. <TopDes :flag="false" topDesFont="设备管理"></TopDes>
  4. <div>
  5. <!-- <el-row>
  6. <el-col :span="1">&nbsp;</el-col>
  7. <el-col :span="20" style="margin-top: 15px">
  8. <div style="display: flex" class="xl_input">
  9. <el-date-picker
  10. v-model="value1"
  11. type="daterange"
  12. range-separator="至"
  13. start-placeholder="开始日期"
  14. end-placeholder="结束日期"
  15. @change="timeChange"
  16. >
  17. </el-date-picker>
  18. &nbsp;&nbsp;&nbsp;&nbsp;
  19. <el-input
  20. placeholder="请输入用户姓名"
  21. v-model="nameSearch"
  22. @input="searchEle"
  23. prefix-icon="el-icon-search"
  24. >
  25. </el-input>
  26. </div>
  27. </el-col>
  28. </el-row> -->
  29. <el-row style="margin-top: 15px">
  30. <el-col :span="1">&nbsp;</el-col>
  31. <el-col :span="22" style="text-align: left">
  32. <!-- <el-button
  33. size="small"
  34. @click="download(1, 1)"
  35. class="xl_down_button"
  36. :disabled="multipleSelection.length === 0 && disableFlag"
  37. >
  38. 批量下载(原始数据)</el-button
  39. >
  40. <el-button
  41. size="small"
  42. :disabled="tableData.length === 0 && disableFlag"
  43. @click="download(1, 2)"
  44. class="xl_down_button"
  45. >
  46. 全部下载(原始数据)</el-button
  47. > -->
  48. <!-- <el-button
  49. size="small"
  50. @click="download(2, 1)"
  51. class="xl_down_button"
  52. :disabled="multipleSelection.length === 0 && disableFlag"
  53. >
  54. 批量下载</el-button
  55. > -->
  56. <el-button
  57. size="small"
  58. class="xl_down_button"
  59. @click="addEquipment()"
  60. >
  61. 新增设备</el-button
  62. >
  63. </el-col>
  64. <el-col :span="1">&nbsp;</el-col>
  65. </el-row>
  66. </div>
  67. <div style="margin-top: 16px">
  68. <el-row>
  69. <el-col :span="1"> &nbsp;</el-col>
  70. <el-col :span="22">
  71. <el-table
  72. :data="tableData"
  73. style="width: 100%"
  74. @selection-change="handleSelectionChange"
  75. :header-cell-style="{
  76. background: '#66B497',
  77. color: '#FFFFFF',
  78. 'letter-spacing': '4px',
  79. }"
  80. :row-class-name="tableRowClassName"
  81. >
  82. <!-- <el-table-column type="selection" align="center" width="55">
  83. </el-table-column> -->
  84. <el-table-column prop="ID" align="center" label="id">
  85. </el-table-column>
  86. <el-table-column
  87. prop="Type"
  88. :formatter="typeFor"
  89. align="center"
  90. label="类型"
  91. >
  92. </el-table-column>
  93. <el-table-column prop="Mac" align="center" label="mac">
  94. </el-table-column>
  95. <!-- <el-table-column
  96. prop="CreatedAt"
  97. align="center"
  98. label="创建时间"
  99. :formatter="dateForMa"
  100. ></el-table-column> -->
  101. <!-- <el-table-column prop="profession" label="职业"></el-table-column> -->
  102. <!-- <el-table-column label="查看测试记录" align="center">
  103. <template slot-scope="scope">
  104. <el-button
  105. class="xl_d_button"
  106. size="mini"
  107. @click="removeFun(scope.$index, scope.row)"
  108. >移除</el-button
  109. >
  110. </template>
  111. </el-table-column> -->
  112. <el-table-column label="操作" align="center">
  113. <template slot-scope="scope">
  114. <!-- <el-button
  115. class="xl_d_button"
  116. size="mini"
  117. @click="singleDownload(scope.$index, scope.row)"
  118. >扫描设备</el-button
  119. > -->
  120. <el-button
  121. class="xl_d_button"
  122. size="mini"
  123. @click="removeFun(scope.$index, scope.row)"
  124. >移除</el-button
  125. >
  126. </template>
  127. </el-table-column>
  128. </el-table>
  129. </el-col>
  130. <el-col :span="1"> &nbsp;</el-col>
  131. </el-row>
  132. </div>
  133. <!-- <p align="center" style="margin-bottom: 40px">
  134. <el-pagination
  135. @size-change="handleSizeChange"
  136. @current-change="handleCurrentChange"
  137. :current-page="pageNum"
  138. :page-size="pageSize"
  139. :page-sizes="[10, , 50, 100, 200, 300, 400]"
  140. layout="total, sizes, prev, pager, next, jumper"
  141. :total="totolSize"
  142. >
  143. </el-pagination>
  144. </p> -->
  145. <el-dialog
  146. title="添加设备"
  147. :visible.sync="centerDialogVisible"
  148. width="30%"
  149. center
  150. >
  151. <span>
  152. <div class="equipment_class">
  153. <div>选择设备:</div>
  154. <el-select
  155. v-model="type"
  156. style="width: 150px"
  157. placeholder="请选择设备"
  158. >
  159. <el-option
  160. v-for="item in options"
  161. :key="item.value"
  162. :label="item.label"
  163. :value="item.value"
  164. >
  165. </el-option>
  166. </el-select>
  167. </div>
  168. <div class="equipment_class">
  169. <div>设备mac:</div>
  170. <el-input
  171. style="width: 150px"
  172. v-model="mac"
  173. placeholder="请输入mac"
  174. ></el-input>
  175. </div>
  176. </span>
  177. <span slot="footer" class="dialog-footer">
  178. <el-button @click="centerDialogVisible = false">取 消</el-button>
  179. <el-button type="primary" @click="addFun()">确 定</el-button>
  180. </span>
  181. </el-dialog>
  182. </div>
  183. </template>
  184. <script>
  185. import axios from "axios";
  186. import jsFileDownload from "js-file-download";
  187. export default {
  188. data() {
  189. return {
  190. centerDialogVisible: false,
  191. options: [
  192. {
  193. value: "1",
  194. label: "脑电",
  195. },
  196. {
  197. value: "2",
  198. label: "心电",
  199. },
  200. ],
  201. mac: "",
  202. type: "1",
  203. head_style: "#f5f7fa",
  204. value1: "",
  205. startDate: "",
  206. endDate: "",
  207. identifier: "",
  208. pageNum: 1,
  209. pageSize: 10,
  210. totolSize: 10,
  211. nameSearch: "",
  212. tableData: [],
  213. multipleSelection: [],
  214. flag: "",
  215. disableFlag: true,
  216. };
  217. },
  218. mounted() {
  219. this.flag = this.$route.query.flag;
  220. this.queryEle();
  221. },
  222. methods: {
  223. removeFun(val, row) {
  224. // debugger;
  225. let path = `v1/device/${row.Mac}/remove`;
  226. this.$http.delete(path, {}, (res) => {
  227. debugger;
  228. if (res.code == 200) {
  229. this.$message(res.message);
  230. this.queryEle();
  231. }
  232. });
  233. },
  234. typeFor(val) {
  235. if (val.Type == "1") {
  236. return "脑电";
  237. } else if (val.Type == "2") {
  238. return "心电";
  239. }
  240. },
  241. addFun() {
  242. let path = "v1/device/add";
  243. let data = {
  244. type: this.type,
  245. mac: this.mac,
  246. };
  247. this.$http.post(path, data, (res) => {
  248. debugger;
  249. if (res.code == 200) {
  250. this.centerDialogVisible = false;
  251. this.queryEle();
  252. }
  253. });
  254. },
  255. addEquipment() {
  256. this.centerDialogVisible = true;
  257. },
  258. dateForMa(row) {
  259. let date = new Date(row.createTime);
  260. let formattedDate = `${date.getFullYear()}-${(
  261. "0" +
  262. (date.getMonth() + 1)
  263. ).slice(-2)}-${("0" + date.getDate()).slice(-2)} ${(
  264. "0" + date.getHours()
  265. ).slice(-2)}:${("0" + date.getMinutes()).slice(-2)}:${(
  266. "0" + date.getSeconds()
  267. ).slice(-2)}`;
  268. return formattedDate;
  269. },
  270. //返回上一页
  271. goBack() {
  272. this.$router.go(-1);
  273. },
  274. //批量下载
  275. download(val, value) {
  276. //获取数组集合
  277. let idArr = [];
  278. for (let i = 0; i < this.multipleSelection.length; i++) {
  279. idArr.push(this.multipleSelection[i].id);
  280. }
  281. this.batchDownloadOriginal(val, value, idArr);
  282. },
  283. //全部下载(原始数据)
  284. batchDownloadOriginalAll() {
  285. let that = this;
  286. let arr = [];
  287. //原始数据批量下载路径
  288. let path = `chat/chatRecord/AllDownload?identifier=${that.nameSearch}&beginDate=${that.startDate}&endDate=${that.endDate}`;
  289. // let path = `record/download`;
  290. let baseUrl = sessionStorage.getItem("baseUrl");
  291. //window.location.href = `${baseUrl}${path}?ids=${arr}`;
  292. let a = arr.join();
  293. axios({
  294. method: "get",
  295. url: `${baseUrl}${path}`,
  296. timeout: 600000, // 请求超时时间,数据量多后台响应慢的情况可以调大点,没生效的话可能是vue.config.js里的配置影响了
  297. responseType: "blob", // 返回类型为数据流
  298. data: {
  299. // ids: arr,
  300. // flag: that.flag,
  301. // startDate: that.startDate,
  302. // endDate: that.endDate,
  303. // userName: that.nameSearch,
  304. }, // 需要传参的话,在这传
  305. }).then((res) => {
  306. if (res && res.data) {
  307. // console.log(decodeURIComponent(res.headers["filename"]))
  308. // 调用js-file-download下载文件,第一个参数是数据流,第二个参数是文件名,我这后端返回时把文件名放到响应的header的filename字段中,所以用这种方式取出
  309. jsFileDownload(res.data, decodeURIComponent(res.headers["filename"]));
  310. }
  311. });
  312. },
  313. //批量下载(原始数据)
  314. batchDownloadOriginal(val, value, idArr) {
  315. let that = this;
  316. let arr = [];
  317. //原始数据批量下载路径
  318. let path = `v1/record/download/source`;
  319. if (val === 2) {
  320. path = `chat/chatRecord/batchDownload`;
  321. }
  322. if ((val === 1 && value === 1) || (val === 2 && value === 1)) {
  323. arr = idArr;
  324. } else {
  325. arr = [];
  326. }
  327. // let path = `record/download`;
  328. let baseUrl = sessionStorage.getItem("baseUrl");
  329. //window.location.href = `${baseUrl}${path}?ids=${arr}`;
  330. let a = arr.join();
  331. axios({
  332. method: "get",
  333. url: `${baseUrl}${path}?ids=${a}`,
  334. timeout: 600000, // 请求超时时间,数据量多后台响应慢的情况可以调大点,没生效的话可能是vue.config.js里的配置影响了
  335. responseType: "blob", // 返回类型为数据流
  336. data: {
  337. ids: arr,
  338. flag: that.flag,
  339. startDate: that.startDate,
  340. endDate: that.endDate,
  341. userName: that.nameSearch,
  342. }, // 需要传参的话,在这传
  343. }).then((res) => {
  344. if (res && res.data) {
  345. // console.log(decodeURIComponent(res.headers["filename"]))
  346. // 调用js-file-download下载文件,第一个参数是数据流,第二个参数是文件名,我这后端返回时把文件名放到响应的header的filename字段中,所以用这种方式取出
  347. jsFileDownload(res.data, decodeURIComponent(res.headers["filename"]));
  348. }
  349. });
  350. },
  351. handleSelectionChange(val) {
  352. this.multipleSelection = val;
  353. },
  354. timeChange(val) {
  355. if (val === null) {
  356. this.startDate = "";
  357. this.endDate = "";
  358. } else {
  359. this.startDate = this.fomatterDate(this.value1[0]);
  360. this.endDate = this.fomatterDate(this.value1[1]);
  361. }
  362. this.pageNum = 1;
  363. this.queryEle();
  364. },
  365. //格式化时间格式
  366. fomatterDate(val) {
  367. var date = new Date(val);
  368. let year = date.getFullYear();
  369. let month = this.fomatterM(date.getMonth() + 1);
  370. let currentDay = this.fomatterM(date.getDate());
  371. return year + "-" + month + "-" + currentDay;
  372. },
  373. fomatterM(val) {
  374. if (val < 10) {
  375. return "0" + val;
  376. } else {
  377. return val + "";
  378. }
  379. },
  380. searchEle() {
  381. this.pageNum = 1;
  382. this.queryEle();
  383. },
  384. queryEle() {
  385. let that = this;
  386. that.$http.get(`/v1/device/list/1`, {}, (res) => {
  387. if (res.code == 200) {
  388. that.tableData = res.data;
  389. // that.totolSize = res.data.totalElements;
  390. } else {
  391. this.$message.error("访问服务器失败!");
  392. }
  393. });
  394. },
  395. handleSizeChange(val) {
  396. this.pageSize = val;
  397. this.queryEle();
  398. },
  399. handleCurrentChange(val) {
  400. this.pageNum = val;
  401. this.queryEle();
  402. // this.pageNum = val;
  403. // this.queryList();
  404. },
  405. singleDownload(index, row) {
  406. let baseUrl = sessionStorage.getItem("baseUrl");
  407. let path = `/chat/chatRecord/download?id=${row.id}`;
  408. // let arr = [row.id];
  409. axios({
  410. method: "get",
  411. url: `${baseUrl}${path}`,
  412. timeout: 600000, // 请求超时时间,数据量多后台响应慢的情况可以调大点,没生效的话可能是vue.config.js里的配置影响了
  413. responseType: "blob", // 返回类型为数据流
  414. data: {
  415. // ids: arr,
  416. }, // 需要传参的话,在这传
  417. }).then((res) => {
  418. if (res && res.data) {
  419. console.log(res.headers["filename"]);
  420. // console.log(decodeURIComponent(res.headers["filename"]))
  421. // 调用js-file-download下载文件,第一个参数是数据流,第二个参数是文件名,我这后端返回时把文件名放到响应的header的filename字段中,所以用这种方式取出
  422. jsFileDownload(res.data, decodeURIComponent(res.headers["filename"]));
  423. }
  424. });
  425. },
  426. getAnswerQuestionPaymentSuccess(id) {
  427. sessionStorage.setItem("back_page", "3");
  428. let _this = this;
  429. _this.$http.post(`v1/record/find/${id}`, {}, (res) => {
  430. if (res.data.code == 200 && res.data.data) {
  431. _this.resultJsonParams = res.data.data;
  432. // let sleep = JSON.parse(
  433. // _this.resultJsonParams.userRecordEntity.testResult
  434. // );
  435. // sleep = sleep[0].newTableContext.result[0].improvementSuggestions;
  436. // if (_this.scale_flag === "20210910163158") {
  437. // _this.askEnd(sleep);
  438. // this.inputFlag = 0;
  439. // }
  440. // if (_this.scale_flag === "20220805135201") {
  441. // _this.askEnd(sleep);
  442. // this.inputFlag = 0;
  443. // }
  444. // let testResult = JSON.parse(res.data.userRecordEntity.testResult)[0]
  445. // .version;
  446. let testResult = JSON.parse(
  447. res.data.data.userRecordEntity.testResult
  448. )[0].version;
  449. if (testResult == 2) {
  450. _this.$router.push({
  451. name: "scaleResultSCl",
  452. params: { tableData: _this.resultJsonParams },
  453. });
  454. } else {
  455. _this.$router.push({
  456. name: "scaleResult",
  457. params: { tableData: _this.resultJsonParams },
  458. });
  459. }
  460. }
  461. });
  462. // _this.$http.get(`/getRecordById?id=${id}`, {}, (res) => {
  463. // if (res.code == 200) {
  464. // _this.resultJsonParams = res.data;
  465. // let testResult = JSON.parse(res.data?.userRecordEntity?.testResult)[0]
  466. // .version;
  467. // if (testResult == 2) {
  468. // _this.$router.push({
  469. // name: "scaleResultSCl",
  470. // query: _this.resultJsonParams,
  471. // });
  472. // } else {
  473. // _this.$router.push({
  474. // name: "ScaleResult",
  475. // query: JSON.stringify(_this.resultJsonParams),
  476. // });
  477. // }
  478. // }
  479. // console.log("请求数据的list", res);
  480. // });
  481. },
  482. handleDelete(index, row) {},
  483. tableRowClassName({ rowIndex }) {
  484. if (rowIndex % 2 === 0) {
  485. return "warning-row";
  486. } else if (rowIndex % 2 === 1) {
  487. return "success-row";
  488. }
  489. return "success-row";
  490. },
  491. },
  492. };
  493. </script>
  494. <style scoped>
  495. .main_right_height {
  496. height: 100vh !important;
  497. display: block !important;
  498. overflow-y: auto !important;
  499. background: #ffffff;
  500. }
  501. .el-input-group {
  502. line-height: normal;
  503. display: inline-table;
  504. width: 200px !important;
  505. border-collapse: separate;
  506. border-spacing: 0;
  507. }
  508. .equipment_class {
  509. margin-top: 20px;
  510. display: flex;
  511. flex-direction: row;
  512. justify-items: center;
  513. align-items: center;
  514. }
  515. </style>