SameScreenComparison.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. <template>
  2. <!-- 同屏对比弹窗 -->
  3. <el-dialog title="同屏对比" fullscreen :visible.sync="dialogVisible" :before-close="handleClose">
  4. <template slot="title">
  5. <div class="dialogTitle">
  6. <div class="dialogTitleIcon"></div>
  7. 同屏对比
  8. </div>
  9. </template>
  10. <!-- 同屏对比主题 -->
  11. <div class="ssc_main">
  12. <!-- 地图列表 -->
  13. <div class="ssc_main_mapList" id="doPrint" ref="doPrint">
  14. <div
  15. class="ssc_main_mapList_showList"
  16. :id="'map' + index"
  17. v-for="(mapIndex, index) in checkedCities"
  18. :key="index"
  19. :style="mapListBoxStyle()"
  20. @mousedown="changeMouseIndex(index)"
  21. >
  22. <span>{{ mapList[mapIndex].mapName }}</span>
  23. <Map
  24. :mapUrl="mapList[mapIndex].mapUrl"
  25. :index="index"
  26. :mouseIndex="mouseIndex"
  27. :centerZoom="centerZoom"
  28. @changeCenterZoom="changeCenterZoom"
  29. />
  30. </div>
  31. </div>
  32. <!-- 底图列表 -->
  33. <div class="ssc_main_aimapList">
  34. <span>地图底图(最多选择6个) </span>
  35. <div>
  36. 已选择<span class="checkLength">{{ checkedCities.length }}</span
  37. >个
  38. </div>
  39. <el-checkbox-group id="mapCheckBox" v-model="checkedCities" @change="handleCheckedCitiesChange" :min="2" :max="6">
  40. <el-checkbox
  41. class="mapCheckBox"
  42. :disabled="checkedCities.length >= 6 && checkedCities.indexOf(index) == -1"
  43. v-for="(city, index) in mapList"
  44. :checked="city.active"
  45. :label="index"
  46. :key="index"
  47. >{{ city.mapName }}</el-checkbox
  48. >
  49. </el-checkbox-group>
  50. </div>
  51. </div>
  52. <!-- 底部文本域 -->
  53. <div id="textareaBox">
  54. <div class="textareaTitle">描述记录:</div>
  55. <el-input type="textarea" :autosize="{ minRows: 3, maxRows: 4 }" placeholder="请输入内容" v-model="textarea1"> </el-input>
  56. </div>
  57. <!-- 打印区域 -->
  58. <div id="imgBox">
  59. <span>基本农田被侵占</span>
  60. <img src="" id="imgOut" style="width: 1240px; background-repeat: no-repeat; background-size: 100% 100%" />
  61. <span><div>描述记录:</div></span>
  62. <div>{{ textarea1 }}</div>
  63. </div>
  64. <span slot="footer" class="dialog-footer">
  65. <el-button @click="clearDialogVisible()">取 消</el-button>
  66. <el-button type="primary" @click="subMitDialogVisible()">打 印</el-button>
  67. </span>
  68. </el-dialog>
  69. </template>
  70. <script>
  71. /**
  72. * 底部菜单(同屏对比)组件
  73. * @author: LiuMengxiang
  74. * @Date: 2022年11月21-25日
  75. */
  76. import Map from "../../map/Map.vue";
  77. import html2canvas from "html2canvas";
  78. export default {
  79. name: "SameScreenComparison",
  80. components: { Map },
  81. data() {
  82. return {
  83. // 同屏对比弹窗显示状态
  84. dialogVisible: false,
  85. // 默认选中第一个
  86. checkedCities: [],
  87. // 定时器暂存
  88. interval: "",
  89. // 地图暂存显示变量
  90. centerZoom: {},
  91. mouseIndex: -1,
  92. // 底部文本域
  93. textarea1: "",
  94. // 地图底图列表
  95. mapList: [
  96. {
  97. mapName: "2018年航空影像图(春季)",
  98. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  99. active: true
  100. },
  101. {
  102. mapName: "2019年航空影像图(春季)",
  103. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  104. active: false
  105. },
  106. {
  107. mapName: "2020年航空影像图(春季)",
  108. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  109. active: false
  110. },
  111. {
  112. mapName: "2021年航空影像图(春季)",
  113. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  114. active: false
  115. },
  116. {
  117. mapName: "2022年航空影像图(春季)",
  118. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  119. active: false
  120. },
  121. {
  122. mapName: "2018年卫星影像图(春季)",
  123. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  124. active: false
  125. },
  126. {
  127. mapName: "2019年卫星影像图(春季)",
  128. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  129. active: false
  130. },
  131. {
  132. mapName: "2020年卫星影像图(春季)",
  133. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  134. active: false
  135. },
  136. {
  137. mapName: "2021年卫星影像图(春季)",
  138. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  139. active: false
  140. },
  141. {
  142. mapName: "2022年卫星影像图(春季)",
  143. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  144. active: false
  145. },
  146. {
  147. mapName: "2018年航空影像图(秋季)",
  148. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  149. active: false
  150. },
  151. {
  152. mapName: "2019年航空影像图(秋季)",
  153. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  154. active: false
  155. },
  156. {
  157. mapName: "2020年航空影像图(秋季)",
  158. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  159. active: false
  160. },
  161. {
  162. mapName: "2021年航空影像图(秋季)",
  163. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  164. active: false
  165. },
  166. {
  167. mapName: "2022年航空影像图(秋季)",
  168. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  169. active: false
  170. },
  171. {
  172. mapName: "2018年卫星影像图(秋季)",
  173. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  174. active: false
  175. },
  176. {
  177. mapName: "2019年卫星影像图(秋季)",
  178. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  179. active: false
  180. },
  181. {
  182. mapName: "2020年卫星影像图(秋季)",
  183. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  184. active: false
  185. },
  186. {
  187. mapName: "2021年卫星影像图(秋季)",
  188. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  189. active: false
  190. },
  191. {
  192. mapName: "2022年卫星影像图(秋季)",
  193. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  194. active: false
  195. }
  196. ]
  197. };
  198. },
  199. mounted() {
  200. // 同屏对比事件监听
  201. this.$bus.$on("tpdb", () => {
  202. this.changeShowBottomMenusStatus();
  203. });
  204. },
  205. destroy() {
  206. // 当容器销毁时,需要停止监听该事件
  207. this.$bus.$off("tpdb");
  208. },
  209. props: [],
  210. methods: {
  211. // 当用户点击svg底座时,切换底部菜单显示隐藏状态。
  212. changeShowBottomMenusStatus() {
  213. // 打开弹窗
  214. this.dialogVisible = true;
  215. this.$emit("changeShowBottomMenusStatus", false);
  216. },
  217. // 弹窗关闭询问
  218. handleClose() {
  219. if (this.dialogVisible) {
  220. this.$confirm("确认关闭?")
  221. .then(_ => {
  222. this.clearDialogVisible();
  223. })
  224. .catch(_ => {});
  225. }
  226. },
  227. // 同屏对比取消
  228. clearDialogVisible() {
  229. if (this.interval) {
  230. this.$message.info("取消打印!");
  231. this.clearDiyInterval();
  232. } else {
  233. // 关闭弹窗
  234. this.dialogVisible = false;
  235. // 恢复默认选中第一个地图底图
  236. this.checkedCities = [];
  237. this.mapList = [
  238. {
  239. mapName: "2018年航空影像图(春季)",
  240. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  241. active: true
  242. },
  243. {
  244. mapName: "2019年航空影像图(春季)",
  245. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  246. active: false
  247. },
  248. {
  249. mapName: "2020年航空影像图(春季)",
  250. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  251. active: false
  252. },
  253. {
  254. mapName: "2021年航空影像图(春季)",
  255. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  256. active: false
  257. },
  258. {
  259. mapName: "2022年航空影像图(春季)",
  260. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  261. active: false
  262. },
  263. {
  264. mapName: "2018年卫星影像图(春季)",
  265. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  266. active: false
  267. },
  268. {
  269. mapName: "2019年卫星影像图(春季)",
  270. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  271. active: false
  272. },
  273. {
  274. mapName: "2020年卫星影像图(春季)",
  275. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  276. active: false
  277. },
  278. {
  279. mapName: "2021年卫星影像图(春季)",
  280. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  281. active: false
  282. },
  283. {
  284. mapName: "2022年卫星影像图(春季)",
  285. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  286. active: false
  287. },
  288. {
  289. mapName: "2018年航空影像图(秋季)",
  290. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  291. active: false
  292. },
  293. {
  294. mapName: "2019年航空影像图(秋季)",
  295. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  296. active: false
  297. },
  298. {
  299. mapName: "2020年航空影像图(秋季)",
  300. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  301. active: false
  302. },
  303. {
  304. mapName: "2021年航空影像图(秋季)",
  305. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  306. active: false
  307. },
  308. {
  309. mapName: "2022年航空影像图(秋季)",
  310. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  311. active: false
  312. },
  313. {
  314. mapName: "2018年卫星影像图(秋季)",
  315. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  316. active: false
  317. },
  318. {
  319. mapName: "2019年卫星影像图(秋季)",
  320. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  321. active: false
  322. },
  323. {
  324. mapName: "2020年卫星影像图(秋季)",
  325. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  326. active: false
  327. },
  328. {
  329. mapName: "2021年卫星影像图(秋季)",
  330. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  331. active: false
  332. },
  333. {
  334. mapName: "2022年卫星影像图(秋季)",
  335. mapUrl: "http://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=f331ba0b9ab96fb21c56d91de868935d",
  336. active: false
  337. }
  338. ];
  339. // 修改父级菜单变量(弹窗显示状态和显示底部菜单)
  340. this.$emit("changeShowBottomMenusStatus", true);
  341. }
  342. },
  343. // 同屏对比表单提交
  344. subMitDialogVisible() {
  345. if (this.interval) {
  346. this.$message.info("正在打印,请稍后操作!");
  347. } else {
  348. this.cutDiv();
  349. }
  350. },
  351. // div转图片
  352. cutDiv() {
  353. var container = document.getElementById("doPrint").innerHTML;
  354. const _width = container.offsetWidth;
  355. const _height = container.offsetHeight;
  356. const ops = {
  357. _width,
  358. _height,
  359. useCORS: true,
  360. allowTaint: false
  361. };
  362. let that = this;
  363. html2canvas(this.$refs.doPrint, ops).then(canvas => {
  364. document.getElementById("imgOut").setAttribute("src", canvas.toDataURL("image/png"));
  365. });
  366. this.interval = setInterval(() => {
  367. if ($("#imgOut").attr("src")) {
  368. that.clearDiyInterval();
  369. setTimeout(() => {
  370. that.doPrint();
  371. }, 500);
  372. }
  373. }, 500);
  374. },
  375. clearDiyInterval() {
  376. let that = this;
  377. // 先销毁定时器
  378. clearInterval(that.interval);
  379. that.interval = "";
  380. },
  381. // div打印(iframe的方式为最优)
  382. doPrint() {
  383. // 将包含转为图片的div获取。
  384. var new_iframe = document.createElement("IFRAME");
  385. var doc = null;
  386. document.body.appendChild(new_iframe);
  387. doc = new_iframe.contentWindow.document;
  388. var obj = document.getElementById("imgBox");
  389. doc.write('<div style="width:100%;height:auto;margin:0px;">' + obj.innerHTML + "</div>");
  390. doc.close();
  391. new_iframe.contentWindow.focus();
  392. new_iframe.contentWindow.print();
  393. // document.body.removeChild(iframe);
  394. },
  395. // 修改
  396. handleCheckedCitiesChange(e) {
  397. // console.log("已选中的底图:", this.checkedCities, this.checkedCities.length);
  398. },
  399. // 根据地图列表,返回合适的样式
  400. mapListBoxStyle() {
  401. return "width:calc(33% - 2px);height:calc(50% - 2px);";
  402. },
  403. // 当其中一个地图移动或缩放时
  404. changeCenterZoom(data) {
  405. this.centerZoom = data;
  406. },
  407. // 暂存当前光标所在map组件的下标
  408. changeMouseIndex(mouseIndex) {
  409. this.mouseIndex = mouseIndex;
  410. }
  411. },
  412. watch: {}
  413. };
  414. </script>
  415. <style lang="less" scoped>
  416. .ssc_main {
  417. display: flex;
  418. width: 100%;
  419. height: calc(100vh - 310px);
  420. position: relative;
  421. #textareaBox {
  422. width: calc(100% - 20px);
  423. height: 100px;
  424. position: absolute;
  425. bottom: 0;
  426. }
  427. &_mapList {
  428. width: calc(100% - 20rem);
  429. height: 100%;
  430. display: flex;
  431. flex-wrap: wrap;
  432. padding: 10px;
  433. box-sizing: border-box;
  434. overflow-x: hidden;
  435. overflow-y: auto;
  436. scrollbar-width: none; /* Firefox */
  437. -ms-overflow-style: none; /* IE 10+ */
  438. &::-webkit-scrollbar {
  439. display: none; /* Chrome Safari */
  440. }
  441. &_showList {
  442. border: 1px solid #ccc;
  443. text-align: right;
  444. position: relative;
  445. span {
  446. position: absolute;
  447. right: 10px;
  448. top: 10px;
  449. font-size: 22px;
  450. font-weight: bold;
  451. color: #fff;
  452. z-index: 999;
  453. -moz-user-select: none;
  454. -webkit-user-select: none;
  455. -ms-user-select: none;
  456. -khtml-user-select: none;
  457. user-select: none;
  458. }
  459. }
  460. }
  461. &_aimapList {
  462. width: 20rem;
  463. height: 100%;
  464. font-size: 20px;
  465. color: #fff;
  466. padding: 10px;
  467. box-sizing: border-box;
  468. background: #002645 !important;
  469. .checkLength {
  470. font-size: 24px;
  471. color: #74ffff;
  472. }
  473. #mapCheckBox {
  474. height: calc(100% - 58px);
  475. width: 100%;
  476. overflow-x: hidden;
  477. overflow-y: auto;
  478. scrollbar-width: none; /* Firefox */
  479. -ms-overflow-style: none; /* IE 10+ */
  480. border: 1px solid #fff;
  481. &::-webkit-scrollbar {
  482. display: none; /* Chrome Safari */
  483. }
  484. }
  485. .mapCheckBox:hover {
  486. color: #ffffff;
  487. background: #002645 !important;
  488. }
  489. .mapCheckBox[disabled] {
  490. color: #666666;
  491. cursor: not-allowed;
  492. }
  493. .mapCheckBox {
  494. width: 100%;
  495. padding: 10px 5px;
  496. border-bottom: 1px solid;
  497. color: #cccccc;
  498. font-size: 18px;
  499. background: #001e37 !important;
  500. .el-checkbox__label {
  501. font-size: 18px;
  502. }
  503. }
  504. }
  505. }
  506. .textareaTitle {
  507. font-size: 20px;
  508. font-weight: 400;
  509. }
  510. #imgBox {
  511. display: none;
  512. font-size: 16px;
  513. color: #000;
  514. font-weight: 400;
  515. span {
  516. font-size: 20px;
  517. color: #000000;
  518. font-weight: bold;
  519. padding: 20px 10px;
  520. }
  521. }
  522. </style>