index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. (() => {
  2. Vue.component('uploadTitlemap', {
  3. props: [],
  4. name: 'uploadTitlemap',
  5. template: ` <div id="planePic"">
  6. <div class="headerBack">
  7. <div class="topBox">
  8. <i class="backIcon" @click="back"></i>
  9. <p class="headerTitle">平面图</p>
  10. </div>
  11. <el-switch v-model="showMapPic" @change="changeDisplay" active-color="#15BEC8" inactive-color="#999">
  12. </el-switch>
  13. </div>
  14. <div class="defaultPic itemBox" :class="type==0 ?'active':''">
  15. <div class="ctrlBox">
  16. <div class="ctrlTitle">
  17. 默认平面图
  18. <div class="tipBox" title="修改点云或数据集后,请更新平面图"></div>
  19. </div>
  20. <!-- <p>默认平面图</p> -->
  21. <el-popconfirm placement="top" title="确认重新生成平面图?" :hide-icon="true" @confirm="refreshConfirm">
  22. <el-button slot="reference">
  23. <div class="ctrlBtn">
  24. <i class="ctrlIcon refreshIcon"></i>
  25. <p class="ctrlText">重新生成</p>
  26. </div>
  27. </el-button>
  28. </el-popconfirm>
  29. </div>
  30. </div>
  31. <div class="diyPic itemBox " :class=" type==1 ?'active':''">
  32. <div class="ctrlBox">
  33. <p class="ctrlTitle">自定义平面图</p>
  34. <div class="btnBox">
  35. <div class="ctrlBtn" @click="downloadMap">
  36. <i class="ctrlIcon downloadIcon"></i>
  37. <p class="ctrlText">下载</p>
  38. </div>
  39. <label class="ctrlBtn" for="files">
  40. <i class="ctrlIcon uploadIcon"></i>
  41. <p class="ctrlText">上传</p>
  42. </label>
  43. <input type="file" ref="files" id="files" @change="uploadPic">
  44. </div>
  45. </div>
  46. </div>
  47. <div class="tipText">
  48. 操作说明<br /> 1. 下载默认平面图,支持.png文件下载;<br /> 2. 解压下载的压缩包,替换压缩包中的图片文件;<br /> (文件名,图片大小、格式需与原图保持一致)
  49. <br /> 3. 上传平面图<br />
  50. </div>
  51. </div>`,
  52. //删除
  53. // <el-popconfirm placement="top" title="确认删除?" :hide-icon="true" @confirm="delConfirm">
  54. // <el-button slot="reference">
  55. // <div class="ctrlBtn">
  56. // <i class="ctrlIcon disableIcon "></i>
  57. // <p class="ctrlText">删除</p>
  58. // </div>
  59. // </el-button>
  60. // </el-popconfirm>
  61. data() {
  62. return {
  63. showMapPic: false,
  64. info: {},
  65. type: -1,
  66. downloadUrl: 'https://laser.4dkankan.com/'
  67. }
  68. },
  69. methods: {
  70. downloadIamge(imgsrc, name) { //下载图片地址和图片名
  71. let image = new Image();
  72. // 解决跨域 Canvas 污染问题
  73. image.setAttribute("crossOrigin", "anonymous");
  74. image.onload = function () {
  75. let canvas = document.createElement("canvas");
  76. canvas.width = image.width;
  77. canvas.height = image.height;
  78. let context = canvas.getContext("2d");
  79. context.drawImage(image, 0, 0, image.width, image.height);
  80. let url = canvas.toDataURL("image/png"); //得到图片的base64编码数据
  81. let a = document.createElement("a"); // 生成一个a元素
  82. let event = new MouseEvent("click"); // 创建一个单击事件
  83. a.download = name || "photo"; // 设置图片名称
  84. a.href = url; // 将生成的URL设置为a.href属性
  85. a.dispatchEvent(event); // 触发a的单击事件
  86. };
  87. image.src = imgsrc;
  88. },
  89. downloadMap() {
  90. axios.get(`/indoor/${sceneNum}/api/tiled_maps/download`).then(res => {
  91. // console.log(res)
  92. // console.log(this.downloadUrl + res.data.msg)
  93. if (res.data.code == 0) {
  94. var name = res.data.msg.split('/')[res.data.msg.split('/').length - 1]
  95. var file = this.downloadUrl + res.data.msg
  96. // console.log(name)
  97. this.downloadIamge(file, name)
  98. // window.location.href = this.downloadUrl + res.data.msg
  99. } else {
  100. this.$message({
  101. message: res.data.msg,
  102. type: 'error',
  103. duration: 2000,
  104. });
  105. }
  106. }).catch(err => {
  107. this.$message({
  108. message: err.data.msg,
  109. type: 'error',
  110. duration: 2000,
  111. });
  112. })
  113. },
  114. refreshConfirm() {
  115. this.$parent.showLoading('更新中...')
  116. axios.get(`/indoor/${sceneNum}/api/tiled_maps/init`).then(res => {
  117. // this.$parent.hideLoading()
  118. if (res.data.code == 0) {
  119. this.getDetaile()
  120. IV.api.AuthenticationService.sendAuthenticationChanged()
  121. } else {
  122. this.$parent.hideLoading()
  123. this.$message({
  124. message: res.data.msg,
  125. type: 'error',
  126. duration: 2000,
  127. });
  128. }
  129. }).catch(err => {
  130. this.$parent.hideLoading()
  131. this.$message({
  132. message: err.data.msg,
  133. type: 'error',
  134. duration: 2000,
  135. });
  136. })
  137. },
  138. changeDisplay(val) {
  139. console.log(val)
  140. if (val) {
  141. this.info.display = 1
  142. } else {
  143. this.info.display = 0
  144. }
  145. this.$parent.showLoading('切换中...')
  146. axios.get(`/indoor/${sceneNum}/api/tiled_maps/updateDisplay/${this.info.display}`).then(res => {
  147. if (res.data.code == 0) {
  148. IV.api.AuthenticationService.sendAuthenticationChanged()
  149. } else {
  150. this.$parent.hideLoading()
  151. this.$message({
  152. message: res.data.msg,
  153. type: 'error',
  154. duration: 2000,
  155. });
  156. }
  157. }).catch(err => {
  158. this.$parent.hideLoading()
  159. this.$message({
  160. message: err.data.msg,
  161. type: 'error',
  162. duration: 2000,
  163. });
  164. })
  165. },
  166. delConfirm() {
  167. console.log('delConfirm')
  168. },
  169. isZip(file) {
  170. return /\.(zip)$/.test(file.name)
  171. },
  172. uploadPic(e) {
  173. let file = e.target.files[0]
  174. console.log(file)
  175. // if (!this.isZip(file)) {
  176. // this.$message({
  177. // message: '请上传zip格式',
  178. // type: 'error',
  179. // duration: 2000,
  180. // });
  181. // return
  182. // }
  183. let params = new FormData()
  184. params.append('file', file)
  185. this.$parent.showLoading('上传中...')
  186. axios.post(`/indoor/${sceneNum}/api/tiled_maps/upload`, params).then(res => {
  187. let file = this.$refs.files
  188. file.value = ''
  189. if (res.data.code == 0) {
  190. this.$message({
  191. message: '上传成功',
  192. type: 'success',
  193. duration: 2000,
  194. });
  195. this.getDetaile()
  196. IV.api.AuthenticationService.sendAuthenticationChanged()
  197. } else {
  198. this.$parent.hideLoading()
  199. this.$message({
  200. message: res.data.msg,
  201. type: 'error',
  202. duration: 2000,
  203. });
  204. }
  205. }).catch(err => {
  206. let file = this.$refs.file
  207. file.value = ''
  208. this.$parent.hideLoading()
  209. this.$message({
  210. message: err.data.msg,
  211. type: 'error',
  212. duration: 2000,
  213. });
  214. })
  215. },
  216. back() {
  217. this.$parent.showType = 0
  218. },
  219. getDetaile() {
  220. axios.get(`/indoor/${sceneNum}/api/tiled_maps/detail`).then(res => {
  221. if (res.data.code == 0) {
  222. console.log(res.data.data)
  223. this.info = res.data.data
  224. this.type = this.info.status || 0
  225. if (this.info.display) {
  226. this.showMapPic = true
  227. } else {
  228. this.showMapPic = false
  229. }
  230. } else {
  231. this.$message({
  232. message: res.data.msg,
  233. type: 'error',
  234. duration: 1000,
  235. });
  236. }
  237. }).catch(err => {
  238. this.$message({
  239. message: err.data.msg,
  240. type: 'error',
  241. duration: 1000,
  242. });
  243. })
  244. },
  245. openMap() {
  246. this.$parent.hideLoading()
  247. if (IV.getMainView().ViewService.primaryView != 'map') {
  248. IV.swapScenes()
  249. }
  250. }
  251. },
  252. computed: {
  253. },
  254. destroyed() {
  255. if (IV.getMainView().ViewService.primaryView == 'map') {
  256. IV.swapScenes()
  257. }
  258. },
  259. mounted() {
  260. this.openMap()
  261. window.eventBus.off('openMap', this.openMap);
  262. window.eventBus.on('openMap', this.openMap);
  263. // function openMap() {
  264. // this.$parent.hideLoading()
  265. // if (IV.getMainView().ViewService.primaryView != 'map') {
  266. // IV.swapScenes()
  267. // }
  268. // }
  269. this.getDetaile()
  270. },
  271. })
  272. })();