|
|
@@ -89,7 +89,7 @@ export default {
|
|
|
},
|
|
|
mounted() {
|
|
|
console.log(this.$route?.params?.id);
|
|
|
- if(this.$route?.params?.id){
|
|
|
+ if(this.$route?.name === 'editTpl'){
|
|
|
this.loadTemplate()
|
|
|
}
|
|
|
this.init()
|
|
|
@@ -101,7 +101,6 @@ export default {
|
|
|
methods: {
|
|
|
loadTemplate(){
|
|
|
if(this.hasLoadedTpl) return
|
|
|
- if(!this.$route?.params?.id) return
|
|
|
const tpl = [
|
|
|
{
|
|
|
index: 0,
|
|
|
@@ -325,6 +324,44 @@ export default {
|
|
|
this.saveCanvasSnapshot()
|
|
|
this.$emit('update:index', index)
|
|
|
},
|
|
|
+ handleDeleteCanvas(targetIndex){
|
|
|
+ if(this.data.length <= 1){
|
|
|
+ this.$message.warning('至少需要保留一个画布')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 如果删除的是当前激活的画布,需要先保存快照并销毁实例
|
|
|
+ if(targetIndex === this.index){
|
|
|
+ this.saveCanvasSnapshot()
|
|
|
+ this.destroyCanvasInstance()
|
|
|
+ }
|
|
|
+ // 从数组中移除画布
|
|
|
+ this.data.splice(targetIndex, 1)
|
|
|
+ // 计算新的激活索引
|
|
|
+ let newIndex = this.index
|
|
|
+ if(targetIndex < this.index){
|
|
|
+ // 删除的画布在当前画布之前,索引减1
|
|
|
+ newIndex = this.index - 1
|
|
|
+ } else if(targetIndex === this.index){
|
|
|
+ // 删除的是当前画布,切换到前一个(如果存在),否则切换到第一个
|
|
|
+ newIndex = targetIndex > 0 ? targetIndex - 1 : 0
|
|
|
+ }
|
|
|
+ // 确保索引不超出范围
|
|
|
+ if(newIndex >= this.data.length){
|
|
|
+ newIndex = this.data.length - 1
|
|
|
+ }
|
|
|
+ if(newIndex < 0){
|
|
|
+ newIndex = 0
|
|
|
+ }
|
|
|
+ // 更新激活索引
|
|
|
+ this.$emit('update:index', newIndex)
|
|
|
+ // 如果删除的是当前画布,需要重新初始化
|
|
|
+ if(targetIndex === this.index){
|
|
|
+ this.$nextTick(() => {
|
|
|
+ this.init()
|
|
|
+ })
|
|
|
+ }
|
|
|
+ this.$message.success('画布已删除')
|
|
|
+ },
|
|
|
canvasBodyStyle(item){
|
|
|
const height = Number(item?.height)
|
|
|
const width = Number(item?.width) || FIXED_CANVAS_WIDTH
|