SameScreenComparison.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  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" :style="{ height: !subMitStatus ? 'calc(100vh - 190px)' : 'calc(100vh - 310px)' }">
  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">
  40. <el-checkbox
  41. class="mapCheckBox"
  42. :disabled="checkedCities.length >= 6 && checkedCities.indexOf(index) == -1"
  43. v-for="(city, index) in mapList"
  44. :label="index"
  45. :key="index"
  46. >{{ city.mapName }}</el-checkbox
  47. >
  48. </el-checkbox-group>
  49. </div>
  50. </div>
  51. <!-- 底部文本域 -->
  52. <div id="textareaBox" v-if="subMitStatus">
  53. <div class="textareaTitle">描述记录:</div>
  54. <el-input type="textarea" :autosize="{ minRows: 3, maxRows: 4 }" placeholder="请输入内容" v-model="textarea1"> </el-input>
  55. </div>
  56. <!-- 打印区域 -->
  57. <div id="imgBox">
  58. <span>基本农田被侵占</span>
  59. <img src="" id="imgOut" style="width: 1240px; background-repeat: no-repeat; background-size: 100% 100%" />
  60. <span><div>描述记录:</div></span>
  61. <div>{{ textarea1 }}</div>
  62. </div>
  63. <span slot="footer" class="dialog-footer">
  64. <el-button @click="clearDialogVisible()">{{ subMitStatus ? "返回上级" : "取 消" }}</el-button>
  65. <el-button type="primary" @click="subMitDialogVisible()">{{ subMitStatus ? "打 印" : "确 定" }}</el-button>
  66. </span>
  67. </el-dialog>
  68. </template>
  69. <script>
  70. /**
  71. * 底部菜单(同屏对比)组件
  72. * @author: LiuMengxiang
  73. * @Date: 2022年11月21-25日
  74. */
  75. import Map from "../../map/Map.vue";
  76. import html2canvas from "html2canvas";
  77. export default {
  78. name: "SameScreenComparison",
  79. components: { Map },
  80. data() {
  81. return {
  82. // 同屏对比弹窗显示状态
  83. dialogVisible: false,
  84. checkedCities: [],
  85. // 定时器暂存
  86. interval: "",
  87. // 地图暂存显示变量
  88. centerZoom: {},
  89. mouseIndex: -1,
  90. // 确认状态
  91. subMitStatus: false,
  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: false
  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. // 点击底部菜单SVG,且有弹窗打开时触发(弹窗关闭询问)
  205. this.$bus.$on("handleClose", () => {
  206. if (this.dialogVisible) {
  207. this.handleClose();
  208. }
  209. });
  210. },
  211. destroy() {
  212. // 当容器销毁时,需要停止监听该事件
  213. this.$bus.$off("tpdb");
  214. },
  215. props: [],
  216. methods: {
  217. // 当用户点击svg底座时,切换底部菜单显示隐藏状态。
  218. changeShowBottomMenusStatus() {
  219. if (this.dialogVisible) {
  220. this.handleClose();
  221. } else {
  222. // 打开弹窗
  223. this.dialogVisible = !this.dialogVisible;
  224. this.$emit("changeShowBottomMenusStatus", false);
  225. }
  226. },
  227. // 弹窗关闭询问
  228. handleClose() {
  229. if (this.dialogVisible) {
  230. this.$confirm("确认关闭?")
  231. .then(_ => {
  232. this.clearDialogVisible();
  233. })
  234. .catch(_ => {});
  235. }
  236. },
  237. // 同屏对比取消
  238. clearDialogVisible() {
  239. if (this.interval) {
  240. this.$message.info("取消打印!");
  241. this.clearDiyInterval();
  242. } else {
  243. // 返回上级
  244. if (this.subMitStatus) {
  245. this.subMitStatus = !this.subMitStatus;
  246. } else {
  247. // 关闭弹窗
  248. this.dialogVisible = false;
  249. // 修改父级菜单变量(弹窗显示状态和显示底部菜单)
  250. this.$emit("changeShowBottomMenusStatus", true);
  251. }
  252. }
  253. },
  254. // 同屏对比表单提交
  255. subMitDialogVisible() {
  256. if (this.interval) {
  257. this.$message.info("正在打印,请稍后操作!");
  258. } else {
  259. if (!this.subMitStatus) {
  260. if (this.checkedCities.length < 2) {
  261. this.$message.info("请至少选择两个地图底图!");
  262. } else {
  263. this.subMitStatus = !this.subMitStatus;
  264. }
  265. } else {
  266. // 出现新的弹窗并截图当前地图,以及文本域
  267. this.cutDiv();
  268. }
  269. }
  270. },
  271. // div转图片
  272. cutDiv() {
  273. var container = document.getElementById("doPrint").innerHTML;
  274. const _width = container.offsetWidth;
  275. const _height = container.offsetHeight;
  276. const ops = {
  277. _width,
  278. _height,
  279. useCORS: true,
  280. allowTaint: false
  281. };
  282. let that = this;
  283. html2canvas(this.$refs.doPrint, ops).then(canvas => {
  284. document.getElementById("imgOut").setAttribute("src", canvas.toDataURL("image/png"));
  285. });
  286. this.interval = setInterval(() => {
  287. if ($("#imgOut").attr("src")) {
  288. that.clearDiyInterval();
  289. setTimeout(() => {
  290. that.doPrint();
  291. }, 500);
  292. }
  293. }, 500);
  294. },
  295. clearDiyInterval() {
  296. let that = this;
  297. // 先销毁定时器
  298. clearInterval(that.interval);
  299. that.interval = "";
  300. },
  301. // div打印(iframe的方式为最优)
  302. doPrint() {
  303. // 将包含转为图片的div获取。
  304. var new_iframe = document.createElement("IFRAME");
  305. var doc = null;
  306. document.body.appendChild(new_iframe);
  307. doc = new_iframe.contentWindow.document;
  308. var obj = document.getElementById("imgBox");
  309. doc.write('<div style="width:100%;height:auto;margin:0px;">' + obj.innerHTML + "</div>");
  310. doc.close();
  311. new_iframe.contentWindow.focus();
  312. new_iframe.contentWindow.print();
  313. // document.body.removeChild(iframe);
  314. },
  315. // 修改
  316. handleCheckedCitiesChange(e) {
  317. // console.log("已选中的底图:", this.checkedCities, this.checkedCities.length);
  318. },
  319. // 根据地图列表,返回合适的样式
  320. mapListBoxStyle() {
  321. return "width:calc(33% - 2px);height:calc(50% - 2px);";
  322. },
  323. // 当其中一个地图移动或缩放时
  324. changeCenterZoom(data) {
  325. this.centerZoom = data;
  326. },
  327. // 暂存当前光标所在map组件的下标
  328. changeMouseIndex(mouseIndex) {
  329. this.mouseIndex = mouseIndex;
  330. }
  331. },
  332. watch: {}
  333. };
  334. </script>
  335. <style lang="less" scoped>
  336. .ssc_main {
  337. display: flex;
  338. width: 100%;
  339. height: calc(100vh - 190px);
  340. position: relative;
  341. #textareaBox {
  342. width: calc(100% - 20px);
  343. height: 100px;
  344. position: absolute;
  345. bottom: 0;
  346. }
  347. &_mapList {
  348. width: calc(100% - 20rem);
  349. height: 100%;
  350. display: flex;
  351. flex-wrap: wrap;
  352. padding: 10px;
  353. box-sizing: border-box;
  354. overflow-x: hidden;
  355. overflow-y: auto;
  356. scrollbar-width: none; /* Firefox */
  357. -ms-overflow-style: none; /* IE 10+ */
  358. &::-webkit-scrollbar {
  359. display: none; /* Chrome Safari */
  360. }
  361. &_showList {
  362. border: 1px solid #ccc;
  363. text-align: right;
  364. position: relative;
  365. span {
  366. position: absolute;
  367. right: 10px;
  368. top: 10px;
  369. font-size: 22px;
  370. font-weight: bold;
  371. color: #fff;
  372. z-index: 999;
  373. -moz-user-select: none;
  374. -webkit-user-select: none;
  375. -ms-user-select: none;
  376. -khtml-user-select: none;
  377. user-select: none;
  378. }
  379. }
  380. }
  381. &_aimapList {
  382. width: 20rem;
  383. height: 100%;
  384. font-size: 20px;
  385. color: #fff;
  386. padding: 10px;
  387. box-sizing: border-box;
  388. background: #002645 !important;
  389. .checkLength {
  390. font-size: 24px;
  391. color: #74ffff;
  392. }
  393. #mapCheckBox {
  394. height: calc(100% - 58px);
  395. width: 100%;
  396. overflow-x: hidden;
  397. overflow-y: auto;
  398. scrollbar-width: none; /* Firefox */
  399. -ms-overflow-style: none; /* IE 10+ */
  400. border: 1px solid #fff;
  401. &::-webkit-scrollbar {
  402. display: none; /* Chrome Safari */
  403. }
  404. }
  405. .mapCheckBox:hover {
  406. color: #ffffff;
  407. background: #002645 !important;
  408. }
  409. .mapCheckBox[disabled] {
  410. color: #666666;
  411. cursor: not-allowed;
  412. }
  413. .mapCheckBox {
  414. width: 100%;
  415. padding: 10px 5px;
  416. border-bottom: 1px solid;
  417. color: #cccccc;
  418. font-size: 18px;
  419. background: #001e37 !important;
  420. .el-checkbox__label {
  421. font-size: 18px;
  422. }
  423. }
  424. }
  425. }
  426. .textareaTitle {
  427. font-size: 20px;
  428. font-weight: 400;
  429. }
  430. #imgBox {
  431. display: none;
  432. font-size: 16px;
  433. color: #000;
  434. font-weight: 400;
  435. span {
  436. font-size: 20px;
  437. color: #000000;
  438. font-weight: bold;
  439. padding: 20px 10px;
  440. }
  441. }
  442. </style>