import factoryCreate from '../views/diy-form/page/components/class/factoryCreate' export default { initDiyList(state, diyList) { state.diyList = diyList state.mousedown.zIndex = 100 + diyList.length - 1 state.mousedown.activeId = 'basicSet' }, resetDiy(state) { state.diyList = [{ id: 'basicSet', type: 'basicSet', titleImg: '', bgImg: [], titleColor: '', title: '基础设置', activityName: null // 专区名称(活动) }] state.mousedown = { startTime: 0, moveDom: null, activeId: 'basicSet', zIndex: 100 } }, addDiyList(state, obj) { state.diyList.push(obj) }, updateDiylistById(state, obj) { if (!obj.id) return const arr = state.diyList.filter(v => { return v.id === obj.id }) arr[0] = Object.assign(arr[0], obj.update) }, updateCurrent(state, update) { const arr = state.diyList.filter(v => { return v.id === state.mousedown.activeId }) arr[0] = Object.assign(arr[0], update) }, // 设置按钮样式 setBtnStyle(state, val) { const obj = val || { type: 'text', size: '' } state.btnStyleVal = obj }, delPopDiyList(state) { state.diyList.pop() }, changeTypeDiyList(state, type) { let beforeObj let index for (let i = 0; i < state.diyList.length; i++) { if (state.diyList[i].id === state.mousedown.activeId) { beforeObj = state.diyList[i] index = i break } } const obj = factoryCreate({ x: beforeObj.x, y: beforeObj.y, w: beforeObj.w, h: beforeObj.h, z: beforeObj.z, type: type, title: beforeObj.title }) state.mousedown.activeId = obj.id state.diyList.splice(index, 1, obj) }, updateMousedown(state, mousedown) { state.mousedown = Object.assign(state.mousedown, mousedown) } }