2021-05-13 10:56:04 +08:00
|
|
|
<template>
|
2021-06-17 11:40:27 +08:00
|
|
|
<div class="renovation">
|
|
|
|
<!-- 左侧模块列表 -->
|
|
|
|
<div class="model-list">
|
|
|
|
<div class="classification-title">基础模块</div>
|
|
|
|
<draggable tag="ul" :list="modelData" v-bind="{group:{ name:'model', pull:'clone',put:false},sort:false, ghostClass: 'ghost'}" @end="handleMoveEnd" @start="handleMoveStart" :move="handleMove">
|
|
|
|
<li v-for="(model, index) in modelData" :key="index" class="model-item">
|
|
|
|
<Icon :type="model.icon" />
|
|
|
|
<span>{{model.name}}</span>
|
|
|
|
</li>
|
|
|
|
</draggable>
|
2021-05-13 10:56:04 +08:00
|
|
|
</div>
|
2021-06-17 11:40:27 +08:00
|
|
|
<!-- 中间展示模块 -->
|
|
|
|
<div class="show-content">
|
|
|
|
<model-form ref="modelForm" :data="modelForm"></model-form>
|
|
|
|
</div>
|
2021-08-04 17:07:39 +08:00
|
|
|
<!-- 操作按钮 -->
|
|
|
|
<div class="btn-bar">
|
2021-08-11 14:56:02 +08:00
|
|
|
<Button type="primary" :loading="submitLoading" @click="saveTemplate">保存模板</Button>
|
2021-08-04 17:07:39 +08:00
|
|
|
<Button class="ml_10" @click="resetTemplate">还原模板</Button>
|
|
|
|
</div>
|
2021-06-17 11:40:27 +08:00
|
|
|
</div>
|
2021-05-13 10:56:04 +08:00
|
|
|
</template>
|
|
|
|
<script>
|
2021-06-17 11:40:27 +08:00
|
|
|
import { modelData } from "./modelConfig";
|
2021-05-13 10:56:04 +08:00
|
|
|
import Draggable from "vuedraggable";
|
2021-06-17 11:40:27 +08:00
|
|
|
import ModelForm from "./modelForm.vue";
|
|
|
|
import * as API_floor from "@/api/other.js";
|
2021-05-13 10:56:04 +08:00
|
|
|
export default {
|
2021-06-17 11:40:27 +08:00
|
|
|
components: {
|
|
|
|
Draggable,
|
|
|
|
ModelForm,
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.getTemplateItem(this.$route.query.id);
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
modelData, // 可选模块数据
|
|
|
|
modelForm: { list: [] }, // 模板数据
|
2021-08-11 14:56:02 +08:00
|
|
|
submitLoading: false, // 提交加载状态
|
2021-06-17 11:40:27 +08:00
|
|
|
};
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
saveTemplate() {
|
|
|
|
// 保存模板
|
2021-06-17 14:11:13 +08:00
|
|
|
this.submitTemplate(this.$route.query.pageShow ? 'OPEN' : 'CLOSE')
|
2021-05-13 10:56:04 +08:00
|
|
|
},
|
2021-06-17 11:40:27 +08:00
|
|
|
// 提交模板
|
|
|
|
submitTemplate(pageShow) {
|
2021-08-11 14:56:02 +08:00
|
|
|
this.submitLoading = true
|
|
|
|
const modelForm = JSON.parse(JSON.stringify(this.modelForm))
|
|
|
|
modelForm.list.unshift(this.$refs.modelForm.navList);
|
|
|
|
modelForm.list.unshift(this.$refs.modelForm.topAdvert);
|
2021-06-17 11:40:27 +08:00
|
|
|
const data = {
|
|
|
|
id: this.$route.query.id,
|
2021-08-11 14:56:02 +08:00
|
|
|
pageData: JSON.stringify(modelForm),
|
2021-07-28 09:24:37 +08:00
|
|
|
pageShow
|
2021-06-17 11:40:27 +08:00
|
|
|
};
|
|
|
|
API_floor.updateHome(this.$route.query.id, data).then((res) => {
|
2021-08-11 14:56:02 +08:00
|
|
|
this.submitLoading = false
|
2021-06-17 11:40:27 +08:00
|
|
|
if (res.success) {
|
|
|
|
this.$Message.success("保存模板成功");
|
2021-05-13 10:56:04 +08:00
|
|
|
}
|
2021-06-17 11:40:27 +08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
resetTemplate() {
|
|
|
|
// 还原模板
|
|
|
|
this.getTemplateItem(this.$route.query.id);
|
2021-05-13 10:56:04 +08:00
|
|
|
},
|
2021-06-17 11:40:27 +08:00
|
|
|
getTemplateItem(id) {
|
|
|
|
// 获取模板数据
|
|
|
|
API_floor.getHomeData(id).then((res) => {
|
|
|
|
if (res.success) {
|
|
|
|
let pageData = res.result.pageData;
|
|
|
|
if (pageData) {
|
|
|
|
pageData = JSON.parse(pageData);
|
|
|
|
if (pageData.list[0].type === "topAdvert") {
|
|
|
|
// topAdvert 为顶部广告 navList为导航栏
|
|
|
|
this.$refs.modelForm.topAdvert = pageData.list[0];
|
|
|
|
this.$refs.modelForm.navList = pageData.list[1];
|
|
|
|
pageData.list.splice(0, 2);
|
|
|
|
this.modelForm = pageData;
|
|
|
|
} else {
|
|
|
|
this.modelForm = { list: [] };
|
2021-05-13 10:56:04 +08:00
|
|
|
}
|
2021-06-17 11:40:27 +08:00
|
|
|
} else {
|
|
|
|
this.modelForm = { list: [] };
|
|
|
|
}
|
2021-05-13 10:56:04 +08:00
|
|
|
}
|
2021-06-17 11:40:27 +08:00
|
|
|
});
|
2021-05-13 10:56:04 +08:00
|
|
|
},
|
2021-06-17 11:40:27 +08:00
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
modelForm: {
|
|
|
|
deep: true,
|
|
|
|
handler: function (val) {
|
|
|
|
console.log(val);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2021-05-13 10:56:04 +08:00
|
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
2021-06-17 11:40:27 +08:00
|
|
|
.renovation {
|
|
|
|
position: relative;
|
|
|
|
display: flex;
|
2021-05-13 10:56:04 +08:00
|
|
|
}
|
2021-06-17 11:40:27 +08:00
|
|
|
.model-list {
|
|
|
|
width: 120px;
|
|
|
|
height: auto;
|
|
|
|
padding: 10px;
|
|
|
|
background: #fff;
|
|
|
|
margin-top: 60px;
|
|
|
|
position: fixed;
|
|
|
|
z-index: 100;
|
|
|
|
box-shadow: 1px 1px 10px #999;
|
|
|
|
.classification-title {
|
|
|
|
width: 100%;
|
|
|
|
height: 30px;
|
|
|
|
line-height: 30px;
|
|
|
|
}
|
|
|
|
.model-item {
|
|
|
|
width: 100px;
|
|
|
|
height: 30px;
|
|
|
|
background: #eee;
|
|
|
|
margin-top: 10px;
|
|
|
|
line-height: 30px;
|
|
|
|
text-align: center;
|
|
|
|
color: #999;
|
|
|
|
&:hover {
|
|
|
|
border: 1px dashed #409eff;
|
|
|
|
color: #409eff;
|
|
|
|
cursor: move;
|
2021-05-13 10:56:04 +08:00
|
|
|
}
|
2021-06-17 11:40:27 +08:00
|
|
|
}
|
|
|
|
.ghost::after {
|
|
|
|
border: none;
|
|
|
|
height: 0;
|
|
|
|
content: "";
|
|
|
|
}
|
2021-05-13 10:56:04 +08:00
|
|
|
}
|
2021-06-17 11:40:27 +08:00
|
|
|
.show-content {
|
|
|
|
margin-left: 150px;
|
|
|
|
margin-top: 60px;
|
2021-05-13 10:56:04 +08:00
|
|
|
}
|
2021-06-17 11:40:27 +08:00
|
|
|
.ghost {
|
|
|
|
background: #fff;
|
|
|
|
height: 30px;
|
|
|
|
position: relative;
|
|
|
|
&::after {
|
|
|
|
content: "松开鼠标添加模块";
|
|
|
|
position: absolute;
|
2021-05-13 10:56:04 +08:00
|
|
|
background: #fff;
|
2021-06-17 11:40:27 +08:00
|
|
|
border: 1px dashed #409eff;
|
|
|
|
color: #409eff;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
2021-05-13 10:56:04 +08:00
|
|
|
width: 100%;
|
|
|
|
height: 50px;
|
2021-06-17 11:40:27 +08:00
|
|
|
text-align: center;
|
|
|
|
line-height: 50px;
|
|
|
|
}
|
2021-05-13 10:56:04 +08:00
|
|
|
}
|
2021-06-17 11:40:27 +08:00
|
|
|
.btn-bar {
|
|
|
|
position: fixed;
|
|
|
|
width: 100%;
|
|
|
|
background: #fff;
|
|
|
|
height: 50px;
|
|
|
|
padding: 10px;
|
|
|
|
box-shadow: 1px 1px 10px #999;
|
|
|
|
z-index: 99;
|
|
|
|
top: 100px;
|
|
|
|
}
|
|
|
|
</style>
|