index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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. </div>
  50. </div>`,
  51. //删除
  52. // <el-popconfirm placement="top" title="确认删除?" :hide-icon="true" @confirm="delConfirm">
  53. // <el-button slot="reference">
  54. // <div class="ctrlBtn">
  55. // <i class="ctrlIcon disableIcon "></i>
  56. // <p class="ctrlText">删除</p>
  57. // </div>
  58. // </el-button>
  59. // </el-popconfirm>
  60. data() {
  61. return {
  62. showMapPic: false,
  63. info: {},
  64. type: -1,
  65. downloadUrl: 'https://laser-oss.4dkankan.com/'
  66. }
  67. },
  68. methods: {
  69. dataURLtoBlob(dataurl) {
  70. var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
  71. bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
  72. while (n--) {
  73. u8arr[n] = bstr.charCodeAt(n);
  74. }
  75. return new Blob([u8arr], { type: mime });
  76. },
  77. downloadIamge(imgsrc, name) { //下载图片地址和图片名
  78. let image = new Image();
  79. // 解决跨域 Canvas 污染问题
  80. image.setAttribute("crossOrigin", "anonymous");
  81. image.onload = ()=> {
  82. let canvas = document.createElement("canvas");
  83. canvas.width = image.width;
  84. canvas.height = image.height;
  85. let context = canvas.getContext("2d");
  86. context.drawImage(image, 0, 0, image.width, image.height);
  87. let url = canvas.toDataURL("image/png"); //得到图片的base64编码数据
  88. let a = document.createElement("a"); // 生成一个a元素
  89. a.download = name || "photo"; // 设置图片名称
  90. console.log(URL.createObjectURL(this.dataURLtoBlob(url)) )
  91. a.href = URL.createObjectURL(this.dataURLtoBlob(url)) // 将生成的URL设置为a.href属性
  92. let event = new MouseEvent("click"); // 创建一个单击事件
  93. a.dispatchEvent(event); // 触发a的单击事件
  94. };
  95. image.src = imgsrc;
  96. },
  97. downloadMap() {
  98. axios.get(`/indoor/${sceneNum}/api/tiled_maps/download`).then(res => {
  99. // console.log(res)
  100. // console.log(this.downloadUrl + res.data.msg)
  101. if (res.data.code == 0) {
  102. var name = res.data.msg.split('/')[res.data.msg.split('/').length - 1]
  103. var file = this.downloadUrl + res.data.msg+'?t='+new Date().getTime()
  104. // console.log(name)
  105. this.downloadIamge(file, name)
  106. // window.location.href = this.downloadUrl + res.data.msg
  107. } else {
  108. this.$message({
  109. message: res.data.msg,
  110. type: 'error',
  111. duration: 2000,
  112. });
  113. }
  114. }).catch(err => {
  115. this.$message({
  116. message: err.data.msg,
  117. type: 'error',
  118. duration: 2000,
  119. });
  120. })
  121. },
  122. refreshConfirm() {
  123. this.$parent.showLoading('更新中...')
  124. axios.get(`/indoor/${sceneNum}/api/tiled_maps/init`).then(res => {
  125. // this.$parent.hideLoading()
  126. if (res.data.code == 0) {
  127. this.getDetaile()
  128. IV.api.AuthenticationService.sendAuthenticationChanged()
  129. } else {
  130. this.$parent.hideLoading()
  131. this.$message({
  132. message: res.data.msg,
  133. type: 'error',
  134. duration: 2000,
  135. });
  136. }
  137. }).catch(err => {
  138. this.$parent.hideLoading()
  139. this.$message({
  140. message: err.data.msg,
  141. type: 'error',
  142. duration: 2000,
  143. });
  144. })
  145. },
  146. changeDisplay(val) {
  147. console.log(val)
  148. if (val) {
  149. this.info.display = 1
  150. } else {
  151. this.info.display = 0
  152. }
  153. this.$parent.showLoading('切换中...')
  154. axios.get(`/indoor/${sceneNum}/api/tiled_maps/updateDisplay/${this.info.display}`).then(res => {
  155. if (res.data.code == 0) {
  156. IV.api.AuthenticationService.sendAuthenticationChanged()
  157. } else {
  158. this.$parent.hideLoading()
  159. this.$message({
  160. message: res.data.msg,
  161. type: 'error',
  162. duration: 2000,
  163. });
  164. }
  165. }).catch(err => {
  166. this.$parent.hideLoading()
  167. this.$message({
  168. message: err.data.msg,
  169. type: 'error',
  170. duration: 2000,
  171. });
  172. })
  173. },
  174. delConfirm() {
  175. console.log('delConfirm')
  176. },
  177. isZip(file) {
  178. return /\.(zip)$/.test(file.name)
  179. },
  180. uploadPic(e) {
  181. let file = e.target.files[0]
  182. console.log(file)
  183. // if (!this.isZip(file)) {
  184. // this.$message({
  185. // message: '请上传zip格式',
  186. // type: 'error',
  187. // duration: 2000,
  188. // });
  189. // return
  190. // }
  191. let params = new FormData()
  192. params.append('file', file)
  193. this.$parent.showLoading('上传中...')
  194. axios.post(`/indoor/${sceneNum}/api/tiled_maps/upload`, params).then(res => {
  195. let file = this.$refs.files
  196. file.value = ''
  197. if (res.data.code == 0) {
  198. this.$message({
  199. message: '上传成功',
  200. type: 'success',
  201. duration: 2000,
  202. });
  203. this.getDetaile()
  204. IV.api.AuthenticationService.sendAuthenticationChanged()
  205. } else {
  206. this.$parent.hideLoading()
  207. this.$message({
  208. message: res.data.msg,
  209. type: 'error',
  210. duration: 2000,
  211. });
  212. }
  213. }).catch(err => {
  214. let file = this.$refs.file
  215. file.value = ''
  216. this.$parent.hideLoading()
  217. this.$message({
  218. message: err.data.msg,
  219. type: 'error',
  220. duration: 2000,
  221. });
  222. })
  223. },
  224. back() {
  225. this.$parent.showType = 0
  226. },
  227. getDetaile() {
  228. axios.get(`/indoor/${sceneNum}/api/tiled_maps/detail`).then(res => {
  229. if (res.data.code == 0) {
  230. console.log(res.data.data)
  231. this.info = res.data.data
  232. this.type = this.info.status || 0
  233. if (this.info.display) {
  234. this.showMapPic = true
  235. } else {
  236. this.showMapPic = false
  237. }
  238. } else {
  239. this.$message({
  240. message: res.data.msg,
  241. type: 'error',
  242. duration: 1000,
  243. });
  244. }
  245. }).catch(err => {
  246. this.$message({
  247. message: err.data.msg,
  248. type: 'error',
  249. duration: 1000,
  250. });
  251. })
  252. },
  253. openMap() {
  254. this.$parent.hideLoading()
  255. if (IV.getMainView().ViewService.primaryView != 'map') {
  256. IV.swapScenes()
  257. }
  258. }
  259. },
  260. computed: {
  261. },
  262. destroyed() {
  263. if (IV.getMainView().ViewService.primaryView == 'map') {
  264. IV.swapScenes()
  265. }
  266. },
  267. mounted() {
  268. this.openMap()
  269. window.eventBus.off('openMap', this.openMap);
  270. window.eventBus.on('openMap', this.openMap);
  271. // function openMap() {
  272. // this.$parent.hideLoading()
  273. // if (IV.getMainView().ViewService.primaryView != 'map') {
  274. // IV.swapScenes()
  275. // }
  276. // }
  277. this.getDetaile()
  278. },
  279. })
  280. })();