reportTableSecurity.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. <template>
  2. <div class="reportTable-security">
  3. <div class="report-query">
  4. <ReportQuery
  5. :show="['time']"
  6. :query-data.sync="queryData"
  7. :search="search"
  8. >
  9. <template #extraItem>
  10. <a-form-model-item label="人员姓名: ">
  11. <a-input
  12. style="width: 200px"
  13. v-model="queryData.name"
  14. placeholder="请输入姓名"
  15. />
  16. </a-form-model-item>
  17. <a-form-model-item label="所属部门名称: ">
  18. <a-select v-model="queryData.dept" style="width: 200px">
  19. <a-select-option
  20. v-for="(item, index) in deptData"
  21. :key="index"
  22. :value="item.value"
  23. >
  24. {{ item.label }}
  25. </a-select-option>
  26. </a-select>
  27. </a-form-model-item>
  28. <a-form-model-item label="人员类型: ">
  29. <a-select v-model="queryData.people" style="width: 200px">
  30. <a-select-option
  31. v-for="(item, index) in peopleOptions"
  32. :key="index"
  33. :value="item.value"
  34. >
  35. {{ item.label }}
  36. </a-select-option>
  37. </a-select>
  38. </a-form-model-item>
  39. </template>
  40. </ReportQuery>
  41. </div>
  42. <div class="report-table-view">
  43. <Card title="报告预览">
  44. <template #title-extra>
  45. <div style="padding-right: 20px">
  46. <span style="color: #b2b2b2; font-size: 12px"
  47. >支持 pdf,word,excel</span
  48. >
  49. <a-button type="link" size="small" @click="exportFunc"
  50. >导出</a-button
  51. >
  52. <a-button type="link" size="small">打印</a-button>
  53. </div>
  54. </template>
  55. <a-table
  56. :columns="tableColumns"
  57. :data-source="tableData"
  58. :pagination="true"
  59. :scroll="{ y: tableContainerHeight }"
  60. bordered
  61. ></a-table>
  62. </Card>
  63. </div>
  64. </div>
  65. </template>
  66. <script>
  67. import ReportQuery from "@/components/report/common/reportQuery.vue";
  68. import Card from "@/components/common/card.vue";
  69. import * as XLSX from "xlsx";
  70. import html2canvas from "html2canvas";
  71. import jsPDF from "jspdf";
  72. export default {
  73. components: {
  74. Card,
  75. ReportQuery,
  76. },
  77. data() {
  78. let timeRange = this.$util.dateUtil.getNearlyMonthRange();
  79. return {
  80. timeRange: "",
  81. queryData: {
  82. timeRange: timeRange,
  83. statis: "0",
  84. name: "",
  85. dept: "0",
  86. people: "0",
  87. },
  88. oriTableData: [],
  89. // 部门数据
  90. deptData: [
  91. {
  92. label: "全部",
  93. value: "0",
  94. },
  95. {
  96. label: "业务一部",
  97. value: "1",
  98. },
  99. {
  100. label: "业务二部",
  101. value: "2",
  102. },
  103. {
  104. label: "业务三部",
  105. value: "3",
  106. },
  107. ],
  108. peopleOptions: [
  109. {
  110. label: "全部",
  111. value: "0",
  112. },
  113. {
  114. label: "自有员工",
  115. value: "1",
  116. },
  117. {
  118. label: "协作员工",
  119. value: "2",
  120. },
  121. {
  122. label: "访客",
  123. value: "3",
  124. },
  125. ],
  126. tableContainerHeight: 500,
  127. tableColumns: [
  128. {
  129. title: "序号",
  130. dataIndex: "index",
  131. key: "index",
  132. align: "center",
  133. width: 80,
  134. customRender: (text, record, index) => `${index + 1}`,
  135. },
  136. {
  137. title: "姓名",
  138. dataIndex: "name",
  139. key: "name",
  140. align: "center",
  141. },
  142. {
  143. title: "身份证号",
  144. dataIndex: "ID",
  145. key: "ID",
  146. align: "center",
  147. },
  148. {
  149. title: "人员类型",
  150. dataIndex: "people_type",
  151. key: "people_type",
  152. align: "center",
  153. },
  154. {
  155. title: "所属部门名称",
  156. dataIndex: "department",
  157. key: "department",
  158. align: "center",
  159. },
  160. {
  161. title: "通行时间",
  162. dataIndex: "time",
  163. key: "time",
  164. },
  165. {
  166. title: "设备名称",
  167. dataIndex: "equipment",
  168. key: "equipment",
  169. align: "center",
  170. },
  171. {
  172. title: "通行方向",
  173. dataIndex: "direction",
  174. key: "direction",
  175. align: "center",
  176. },
  177. {
  178. title: "异常类型",
  179. key: "operation",
  180. fixed: "right",
  181. width: 100,
  182. scopedSlots: { customRender: "action" },
  183. },
  184. ],
  185. originalData: [
  186. {
  187. key: "1",
  188. name: "潘夏彤",
  189. ID:"332987********8765",
  190. people_type: "自有员工",
  191. department: "业务一部",
  192. time: "2023-03-11 12:00:00",
  193. equipment: "ZX010012",
  194. direction: "进入B3",
  195. behavior: "",
  196. directionStatus: "进",
  197. },
  198. {
  199. key: "2",
  200. name: "庞慧",
  201. ID:"332987********8765",
  202. people_type: "协作员工",
  203. department: "业务二部",
  204. time: "2023-03-15 12:00:00",
  205. equipment: "ZX010012",
  206. direction: "进入1F",
  207. behavior: "",
  208. directionStatus: "进",
  209. },
  210. {
  211. key: "3",
  212. name: "李天泽",
  213. ID:"332987********8765",
  214. people_type: "访客",
  215. department: "业务二部",
  216. time: "2023-03-24 12:00:00",
  217. equipment: "ZX010012",
  218. direction: "出去B2",
  219. behavior: "",
  220. directionStatus: "出",
  221. },
  222. {
  223. key: "4",
  224. name: "李天泽",
  225. ID:"332987********8765",
  226. people_type: "访客",
  227. department: "业务二部",
  228. time: "2022-09-11 12:00:00",
  229. equipment: "ZX010012",
  230. direction: "出去B2",
  231. behavior: "",
  232. directionStatus: "出",
  233. },
  234. {
  235. key: "5",
  236. name: "李天泽",
  237. ID:"332987********8765",
  238. people_type: "访客",
  239. department: "业务二部",
  240. time: "2022-09-11 12:00:00",
  241. equipment: "ZX010012",
  242. direction: "出去B2",
  243. behavior: "",
  244. directionStatus: "出",
  245. },
  246. {
  247. key: "6",
  248. name: "李天泽",
  249. ID:"332987********8765",
  250. people_type: "访客",
  251. department: "业务二部",
  252. time: "2022-09-11 12:00:00",
  253. equipment: "ZX010017",
  254. direction: "进入B2",
  255. behavior: "",
  256. directionStatus: "进",
  257. },
  258. {
  259. key: "7",
  260. name: "李天泽",
  261. ID:"332987********8765",
  262. people_type: "访客",
  263. department: "业务三部",
  264. time: "2022-08-26 12:00:00",
  265. equipment: "ZX010017",
  266. direction: "进入B2",
  267. behavior: "",
  268. directionStatus: "进",
  269. },
  270. {
  271. key: "8",
  272. name: "李天泽",
  273. ID:"332987********8765",
  274. people_type: "访客",
  275. department: "业务三部",
  276. time: "2022-08-26 12:00:00",
  277. equipment: "ZX010017",
  278. direction: "进入B2",
  279. behavior: "",
  280. directionStatus: "进",
  281. },
  282. {
  283. key: "9",
  284. name: "李天泽",
  285. ID:"332987********8765",
  286. people_type: "访客",
  287. department: "业务三部",
  288. time: "2022-08-26 12:00:00",
  289. equipment: "ZY010012",
  290. direction: "进入B2",
  291. behavior: "",
  292. directionStatus: "进",
  293. },
  294. {
  295. key: "10",
  296. name: "李天泽",
  297. ID:"332987********8765",
  298. people_type: "访客",
  299. department: "业务三部",
  300. time: "2022-08-26 12:00:00",
  301. equipment: "ZY010012",
  302. direction: "进入B2",
  303. behavior: "",
  304. directionStatus: "进",
  305. },
  306. {
  307. key: "11",
  308. name: "李天泽",
  309. ID:"332987********8765",
  310. people_type: "访客",
  311. department: "业务一部",
  312. time: "2022-08-26 12:00:00",
  313. equipment: "ZY010012",
  314. direction: "进入B2",
  315. behavior: "",
  316. directionStatus: "进",
  317. },
  318. {
  319. key: "12",
  320. name: "李天泽",
  321. ID:"332987********8765",
  322. people_type: "访客",
  323. department: "业务一部",
  324. time: "2022-08-26 12:00:00",
  325. equipment: "ZY010012",
  326. direction: "进入B2",
  327. behavior: "",
  328. directionStatus: "进",
  329. },
  330. {
  331. key: "13",
  332. name: "李天泽",
  333. ID:"332987********8765",
  334. people_type: "访客",
  335. department: "业务一部",
  336. time: "2022-08-26 12:00:00",
  337. equipment: "ZY010012",
  338. direction: "进入B2",
  339. behavior: "",
  340. directionStatus: "进",
  341. },
  342. {
  343. key: "14",
  344. name: "李天泽",
  345. ID:"332987********8765",
  346. people_type: "访客",
  347. department: "业务一部",
  348. time: "2022-08-26 12:00:00",
  349. equipment: "ZY010012",
  350. direction: "进入B2",
  351. behavior: "",
  352. directionStatus: "进",
  353. },
  354. {
  355. key: "15",
  356. name: "李天泽",
  357. ID:"332987********8765",
  358. people_type: "访客",
  359. department: "业务一部",
  360. time: "2022-08-26 12:00:00",
  361. equipment: "ZY010012",
  362. direction: "进入B2",
  363. behavior: "",
  364. directionStatus: "进",
  365. },
  366. {
  367. key: "16",
  368. name: "李天泽",
  369. ID:"332987********8765",
  370. people_type: "访客",
  371. department: "业务一部",
  372. time: "2022-08-26 12:00:00",
  373. equipment: "ZY010012",
  374. direction: "进入B2",
  375. behavior: "",
  376. directionStatus: "进",
  377. },
  378. {
  379. key: "17",
  380. name: "李天泽",
  381. ID:"332987********8765",
  382. people_type: "访客",
  383. department: "业务一部",
  384. time: "2022-08-26 12:00:00",
  385. equipment: "ZY010012",
  386. direction: "进入B2",
  387. behavior: "",
  388. directionStatus: "进",
  389. },
  390. {
  391. key: "18",
  392. name: "李天泽",
  393. ID:"332987********8765",
  394. people_type: "访客",
  395. department: "业务一部",
  396. time: "2022-08-26 12:00:00",
  397. equipment: "ZY010012",
  398. direction: "出去B2",
  399. behavior: "",
  400. directionStatus: "出",
  401. },
  402. {
  403. key: "19",
  404. name: "李天泽",
  405. ID:"332987********8765",
  406. people_type: "访客",
  407. department: "业务三部",
  408. time: "2022-08-26 12:00:00",
  409. equipment: "ZY010012",
  410. direction: "出去B2",
  411. behavior: "",
  412. directionStatus: "出",
  413. },
  414. {
  415. key: "20",
  416. name: "李天泽",
  417. ID:"332987********8765",
  418. people_type: "访客",
  419. department: "业务三部",
  420. time: "2022-08-26 12:00:00",
  421. equipment: "ZY010012",
  422. direction: "出去B2",
  423. behavior: "",
  424. directionStatus: "出",
  425. },
  426. {
  427. key: "21",
  428. name: "李天泽",
  429. ID:"332987********8765",
  430. people_type: "访客",
  431. department: "业务三部",
  432. time: "2022-08-26 12:00:00",
  433. equipment: "ZY010012",
  434. direction: "出去B2",
  435. behavior: "",
  436. directionStatus: "出",
  437. },
  438. ],
  439. tableData: [],
  440. };
  441. },
  442. mounted() {
  443. this.initData();
  444. },
  445. methods: {
  446. initData() {
  447. this.tableData = JSON.parse(JSON.stringify(this.originalData));
  448. },
  449. exportFunc() {
  450. // 获取表格的 DOM 节点
  451. const table = document.querySelector(".ant-table-wrapper");
  452. // 使用 html2canvas 将表格转换成图片
  453. html2canvas(table, {
  454. allowTaint: true,
  455. useCORS: true,
  456. }).then((canvas) => {
  457. // 获取图片的 base64 编码
  458. const base64URL = canvas.toDataURL("image/png");
  459. // 将图片导出成 PDF 或者图片文件
  460. const pdf = new jsPDF("landscape", "px", [canvas.width, canvas.height]);
  461. pdf.addImage(base64URL, "PNG", 0, 0, canvas.width, canvas.height);
  462. pdf.save("智慧安防-安防人员.pdf"); // 保存为 PDF 文件
  463. // window.open(base64URL); // 在新窗口中打开图片
  464. });
  465. },
  466. exportFunc1() {
  467. console.log("打印报表");
  468. const data = [
  469. ["姓名", "年龄", "性别", "毕业院校"],
  470. ["张三", 18, "男", "清华大学"],
  471. ["李四", 22, "女", "北京大学"],
  472. ["王五", 20, "男", "上海交通大学"],
  473. ];
  474. const worksheet = XLSX.utils.aoa_to_sheet(data);
  475. const workbook = XLSX.utils.book_new();
  476. XLSX.utils.book_append_sheet(workbook, worksheet, "表格名字");
  477. XLSX.writeFile(workbook, "智慧安防-安防人员.xlsx");
  478. },
  479. search() {},
  480. },
  481. };
  482. </script>
  483. <style lang="less" scoped>
  484. .reportTable-security {
  485. width: 100%;
  486. height: 100%;
  487. .report-query {
  488. background-color: #ffffff;
  489. padding: 12px;
  490. margin-bottom: 12px;
  491. }
  492. .report-table-view {
  493. width: 100%;
  494. height: 690px;
  495. background-color: #ffffff;
  496. }
  497. }
  498. </style>