123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- import * as types from './mutation-type'
- import app from '../../util/appConst'
- import Element from '../../model/Element'
- const mutations = {
- [types.SET_CUR_EDITOR_ELEMENT](state, data) {
- state.editorElement = data
- },
- [types.ADD_PIC_ELEMENT](state, data) {
- state.editorPage.elements.push(new Element(data))
- },
- [types.ADD_PAGE_QUESTION](state, data) {
- state.editorPage.questions = data
- },
- [types.SET_BG_ELEMENT](state, data) {
- let haveBG = false
- state.editorPage.elements.findIndex((value, index, arr) => {
- if (value.type === 'bg') {
- haveBG = true
- value.imgSrc = data.imgSrc
- value.width = data.width
- value.height = data.height
- }
- })
- if (!haveBG) {
- state.editorPage.elements.push(new Element(data))
- }
- },
- // 播放动画
- [types.PLAY_ANIMATE](state) {
- let elements = state.editorPage.elements
- let editingElement = state.editorElement
- if (editingElement && editingElement.animatedName) {
- // 如存在有动画的选择元素
- editingElement.playing = true
- } else if (!editingElement) {
- // 不存在被选择的元素
- elements.forEach(v => {
- v.playing = true
- })
- }
- },
- // 停止播放动画
- [types.STOP_ANIMATE](state, data) {
- if (data instanceof Array) {
- // 该页元素
- data.forEach(v => {
- v['playing'] = false
- })
- } else if (data instanceof Object) {
- // 单个元素
- data['playing'] = false
- } else {
- // 不传参情况
- state['editorPage']['elements'].forEach(v => {
- v['playing'] = false
- })
- }
- },
- [types.ADD_PAGE](state, page) {
- state.editorTheme.pages.push(page);
- },
- [types.ADD_PAGE_POSITION](state, page) {
- state.editorTheme.pages.splice(page.position, 0, page);
- },
- [types.DELETE_PAGE](state, data) {
- state.editorTheme.pages.findIndex((value, index, arr) => {
- if (value === data) {
- state.editorTheme.pages.splice(index, 1)
- }
- })
- },
- [types.SET_CUR_EDITOR_PAGE](state, data) {
- state.editorPage = data
- },
- [types.GET_USER_THEME_LIST](state, data) {
- state.themeList = data
- },
- [types.SET_CUR_EDITOR_THEME](state, data) {
- state.editorTheme = data
- },
- [types.UPDATE_THEME_DES](state, { title, description, canvasHeight }) {
- state.editorTheme.title = title
- state.editorTheme.description = description
- state.editorTheme.canvasHeight = canvasHeight
- },
- [types.DELETE_ELEMENT](state, data) {
- state.editorPage.elements.findIndex((value, index, arr) => {
- if (value === data) {
- state.editorPage.elements.splice(index, 1)
- state.editorElement = null
- }
- })
- },
- [types.DELETE_ELEMENT_QID](state, questionId) {
- var elements = state.editorPage.elements;
- var newElements = [];
- elements.findIndex((value, index, arr) => {
- if (value.questionId !== questionId) {
- newElements.push(value);
- }
- })
- state.editorPage.elements = newElements;
- state.editorElement = null
- },
- [types.CREATE_THEME](state, data) {
- state.themeList.push(data)
- },
- [types.ADD_THEME_SUCCESS](state, data) {
- state.editorTheme._id = data._id
- },
- [types.UPDATE_THEME_SUCCESS](state, data) {
- },
- [types.SAVE_PIC](state, data) {
- state.editorElement.imgSrc = app.APP_MALL_API_URL + data.filePath
- },
- [types.GET_PAGE_THEMEID](state, data) {
- state.editorPage = data
- },
- [types.CLEAN_BG](state) {
- state.editorPage.elements.findIndex((value, index, arr) => {
- if (value && value.type === 'bg') {
- state.editorPage.elements.splice(index, 1)
- }
- })
- },
- [types.CLEAN_ELE](state, ele) {
- state.editorPage.elements.splice(state.editorPage.elements.indexOf(ele), 1)
- },
- [types.FETCH_PIC_LIST](state, picList) {
- state.picList = picList
- },
- [types.PUSH_PIC_LIST](state, ele) {
- state.picList.push(ele)
- },
- [types.CLEAN_PIC_LIST](state) {
- state.picList = []
- },
- [types.SORTELEMENTS](state, data) {
- let element = state.editorPage.elements[data.start]
- let end = parseInt(data.end)
- if (end !== -1) {
- state.editorPage.elements.splice(data.start, 1)
- if (end >= state.editorPage.elements.length) {
- state.editorPage.elements.push(element)
- } else {
- state.editorPage.elements.splice(end, 0, element)
- }
- state.editorPage.elements.map((value, index, arr) => {
- value.zindex = index + 1
- })
- }
- },
- [types.DELETE_THEME](state, data) {
- state.themeList.findIndex((value, index, arr) => {
- if (value === data) {
- state.themeList.splice(index, 1)
- }
- })
- },
- [types.SORTELEMENTS_BY_ZINDEX](state, data) {
- state.editorPage.elements.sort((a, b) => a['zindex'] - b['zindex'])
- state.editorPage.elements.forEach((v, i, arr) => {
- arr[i]['zindex'] = i + 1
- })
- }
- }
- export default mutations
|