index.js 12 KB

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