(() => {
Vue.component('uploadTitlemap', {
props: [],
name: 'uploadTitlemap',
template: `
操作说明
1. 下载默认平面图,支持.png文件下载;
2.上传时,图片需与默认平面图图片大小、格式保持一致。
`,
//删除
//
//
//
//
//
data() {
return {
showMapPic: false,
info: {},
type: -1,
downloadUrl: 'https://laser-oss.4dkankan.com/'
}
},
methods: {
downloadIamge(imgsrc, name) { //下载图片地址和图片名
let image = new Image();
// 解决跨域 Canvas 污染问题
image.setAttribute("crossOrigin", "anonymous");
image.onload = function () {
let canvas = document.createElement("canvas");
canvas.width = image.width;
canvas.height = image.height;
let context = canvas.getContext("2d");
context.drawImage(image, 0, 0, image.width, image.height);
let url = canvas.toDataURL("image/png"); //得到图片的base64编码数据
let a = document.createElement("a"); // 生成一个a元素
let event = new MouseEvent("click"); // 创建一个单击事件
a.download = name || "photo"; // 设置图片名称
a.href = url; // 将生成的URL设置为a.href属性
a.dispatchEvent(event); // 触发a的单击事件
};
image.src = imgsrc;
},
downloadMap() {
axios.get(`/indoor/${sceneNum}/api/tiled_maps/download`).then(res => {
// console.log(res)
// console.log(this.downloadUrl + res.data.msg)
if (res.data.code == 0) {
var name = res.data.msg.split('/')[res.data.msg.split('/').length - 1]
var file = this.downloadUrl + res.data.msg
// console.log(name)
this.downloadIamge(file, name)
// window.location.href = this.downloadUrl + res.data.msg
} else {
this.$message({
message: res.data.msg,
type: 'error',
duration: 2000,
});
}
}).catch(err => {
this.$message({
message: err.data.msg,
type: 'error',
duration: 2000,
});
})
},
refreshConfirm() {
this.$parent.showLoading('更新中...')
axios.get(`/indoor/${sceneNum}/api/tiled_maps/init`).then(res => {
// this.$parent.hideLoading()
if (res.data.code == 0) {
this.getDetaile()
IV.api.AuthenticationService.sendAuthenticationChanged()
} else {
this.$parent.hideLoading()
this.$message({
message: res.data.msg,
type: 'error',
duration: 2000,
});
}
}).catch(err => {
this.$parent.hideLoading()
this.$message({
message: err.data.msg,
type: 'error',
duration: 2000,
});
})
},
changeDisplay(val) {
console.log(val)
if (val) {
this.info.display = 1
} else {
this.info.display = 0
}
this.$parent.showLoading('切换中...')
axios.get(`/indoor/${sceneNum}/api/tiled_maps/updateDisplay/${this.info.display}`).then(res => {
if (res.data.code == 0) {
IV.api.AuthenticationService.sendAuthenticationChanged()
} else {
this.$parent.hideLoading()
this.$message({
message: res.data.msg,
type: 'error',
duration: 2000,
});
}
}).catch(err => {
this.$parent.hideLoading()
this.$message({
message: err.data.msg,
type: 'error',
duration: 2000,
});
})
},
delConfirm() {
console.log('delConfirm')
},
isZip(file) {
return /\.(zip)$/.test(file.name)
},
uploadPic(e) {
let file = e.target.files[0]
console.log(file)
// if (!this.isZip(file)) {
// this.$message({
// message: '请上传zip格式',
// type: 'error',
// duration: 2000,
// });
// return
// }
let params = new FormData()
params.append('file', file)
this.$parent.showLoading('上传中...')
axios.post(`/indoor/${sceneNum}/api/tiled_maps/upload`, params).then(res => {
let file = this.$refs.files
file.value = ''
if (res.data.code == 0) {
this.$message({
message: '上传成功',
type: 'success',
duration: 2000,
});
this.getDetaile()
IV.api.AuthenticationService.sendAuthenticationChanged()
} else {
this.$parent.hideLoading()
this.$message({
message: res.data.msg,
type: 'error',
duration: 2000,
});
}
}).catch(err => {
let file = this.$refs.file
file.value = ''
this.$parent.hideLoading()
this.$message({
message: err.data.msg,
type: 'error',
duration: 2000,
});
})
},
back() {
this.$parent.showType = 0
},
getDetaile() {
axios.get(`/indoor/${sceneNum}/api/tiled_maps/detail`).then(res => {
if (res.data.code == 0) {
console.log(res.data.data)
this.info = res.data.data
this.type = this.info.status || 0
if (this.info.display) {
this.showMapPic = true
} else {
this.showMapPic = false
}
} else {
this.$message({
message: res.data.msg,
type: 'error',
duration: 1000,
});
}
}).catch(err => {
this.$message({
message: err.data.msg,
type: 'error',
duration: 1000,
});
})
},
openMap() {
this.$parent.hideLoading()
if (IV.getMainView().ViewService.primaryView != 'map') {
IV.swapScenes()
}
}
},
computed: {
},
destroyed() {
if (IV.getMainView().ViewService.primaryView == 'map') {
IV.swapScenes()
}
},
mounted() {
this.openMap()
window.eventBus.off('openMap', this.openMap);
window.eventBus.on('openMap', this.openMap);
// function openMap() {
// this.$parent.hideLoading()
// if (IV.getMainView().ViewService.primaryView != 'map') {
// IV.swapScenes()
// }
// }
this.getDetaile()
},
})
})();