<template>
|
<div>
|
<hot-area-box @handle-preview="handlePreview">
|
<template slot="hotContent">
|
<set-up :diyDes="diyDes"></set-up>
|
</template>
|
</hot-area-box>
|
<preview ref="preview"></preview>
|
</div>
|
</template>
|
<script>
|
import setUp from './set-up/index.vue'
|
import { mapState, mapMutations } from 'vuex'
|
import { getDiyInfoById, editDiy, addDiy } from '@/api/diy.js'
|
import preview from './components/preview.vue'
|
import { useSceneMap } from './commonData'
|
import { submitValidate } from '@/utils/submitValidate'
|
import hotAreaBox from '../../components/hotAreaBox/index.vue'
|
export default {
|
name: 'diy-index',
|
components: {
|
setUp,
|
preview,
|
hotAreaBox
|
},
|
data() {
|
return {
|
useSceneMap,
|
diyDes: null,
|
resCode: null
|
}
|
},
|
computed: {
|
...mapState(['diyList'])
|
},
|
methods: {
|
...mapMutations(['initDiyList', 'resetDiy']),
|
// 设置diy主题
|
setDiyDes() {
|
this.$prompt('请输入主题名称', '提示', {
|
confirmButtonText: '确定',
|
cancelButtonText: '取消',
|
inputPattern: /^.{1,20}$/,
|
inputErrorMessage: '主题名称不能为空,且不超过20字符'
|
}).then(({ value }) => {
|
if (this.resCode === '500') {
|
this.addDiy(value)
|
} else {
|
this.diyDes = value
|
}
|
}).catch(() => {
|
this.$router.push(`${this.$baseRouter}/diy/list`)
|
})
|
},
|
async _getDiyInfoById(params) {
|
const res = await getDiyInfoById(params)
|
if (res.code === '0' && res.data) {
|
this.initDiyList(JSON.parse(res.data.styleInfo))
|
}
|
},
|
async handlePreview() {
|
if (submitValidate(this.diyList, this.useSceneMap)) return // 表单验证
|
const id = this.$route.query.id
|
let res
|
if (id) {
|
res = await editDiy({
|
id,
|
styleInfo: JSON.stringify(this.diyList),
|
diyType: '1'
|
})
|
if (res.code === '0') {
|
const str = `${process.env.VUE_APP_H5_URL}/index2?id=${res.data.id}`
|
this.$refs.preview.show(str)
|
}
|
} else {
|
this.addDiy(this.diyDes)
|
}
|
},
|
/**
|
* 新增diy
|
*/
|
async addDiy(diyDes) {
|
const res = await addDiy({
|
diyDes,
|
styleInfo: JSON.stringify(this.diyList),
|
diyType: '1'
|
})
|
if (res.code === '0') {
|
this.$router.replace(`${this.$baseRouter}/diy/update?id=${res.data.id}`)
|
const str = `${process.env.VUE_APP_H5_URL}/index2?id=${res.data.id}`
|
this.$refs.preview.show(str)
|
} else if (!this.$route.query.id && res.code !== '0') {
|
this.resCode = '500'
|
setTimeout(() => {
|
this.setDiyDes()
|
}, 1000)
|
}
|
}
|
},
|
created() {
|
if (this.$route.query.id) {
|
this._getDiyInfoById({ id: this.$route.query.id })
|
} else {
|
this.setDiyDes()// 设置diy主题
|
}
|
},
|
destroyed() {
|
this.resetDiy()
|
}
|
}
|
</script>
|
<style scoped lang="scss">
|
/* 设置滚动条的样式 */
|
.diy-aside::-webkit-scrollbar {
|
display: none;
|
width: 0;
|
}
|
|
.diy-aside {
|
overflow: hidden;
|
border: 1px solid #333;
|
height: 667px;
|
overflow-y: auto;
|
-ms-overflow-style:none;
|
overflow:-moz-scrollbars-none;
|
scrollbar-width: none;
|
}
|
.el_aside {
|
text-align: center;
|
}
|
.preview_btn {
|
margin-top: 10px;
|
}
|
</style>
|