Commit 349d12efb666143faa463867083ce0a9eab0119b
1 parent
bb1a5b5e
fix: #233 add confirm before delete element; #!zh: 删除元素前需要确认
Showing
7 changed files
with
85 additions
and
7 deletions
front-end/h5/src/components/core/editor/left-panel/index.js
| 1 | 1 | import RenderShortcutsPanel from './shortcuts-panel/index' |
| 2 | 2 | import RenderPageManager from './page-manager/index' |
| 3 | 3 | import RenderPageTree from './page-tree/index' |
| 4 | +import RenderPagePreferences from './preferences/index' | |
| 4 | 5 | |
| 5 | 6 | export default { |
| 6 | 7 | name: 'EditorLeftPanel', |
| ... | ... | @@ -20,6 +21,9 @@ export default { |
| 20 | 21 | <a-tab-pane key='page-tree' tab={this.$t('editor.sidebar.tree')}> |
| 21 | 22 | <RenderPageTree /> |
| 22 | 23 | </a-tab-pane> |
| 24 | + <a-tab-pane key='preferences' tab={this.$t('editor.sidebar.preferences')}> | |
| 25 | + <RenderPagePreferences /> | |
| 26 | + </a-tab-pane> | |
| 23 | 27 | </a-tabs> |
| 24 | 28 | </a-layout-sider> |
| 25 | 29 | ) | ... | ... |
front-end/h5/src/components/core/editor/left-panel/preferences/index.js
0 → 100644
| 1 | +import langMixin from 'core/mixins/i18n' | |
| 2 | +import LocalPreferences, { IS_CONFIRM_BEFORE_DELETE_ELEMENT } from './local-preferences' | |
| 3 | + | |
| 4 | +export default { | |
| 5 | + mixins: [langMixin], | |
| 6 | + data: () => ({ | |
| 7 | + form: { | |
| 8 | + [IS_CONFIRM_BEFORE_DELETE_ELEMENT]: false // 删除元素前需要确认 | |
| 9 | + } | |
| 10 | + }), | |
| 11 | + methods: { | |
| 12 | + handleChange (key, value) { | |
| 13 | + switch (key) { | |
| 14 | + case IS_CONFIRM_BEFORE_DELETE_ELEMENT: | |
| 15 | + this[IS_CONFIRM_BEFORE_DELETE_ELEMENT] = value | |
| 16 | + LocalPreferences.set(key, value) | |
| 17 | + break | |
| 18 | + default: | |
| 19 | + break | |
| 20 | + } | |
| 21 | + } | |
| 22 | + }, | |
| 23 | + render (h) { | |
| 24 | + return ( | |
| 25 | + <a-form layout="horizontal"> | |
| 26 | + <a-form-model-item label="删除元素前需要确认"> | |
| 27 | + <a-switch value={this.form[IS_CONFIRM_BEFORE_DELETE_ELEMENT]} onChange={val => this.handleChange(IS_CONFIRM_BEFORE_DELETE_ELEMENT, val)} /> | |
| 28 | + </a-form-model-item> | |
| 29 | + </a-form> | |
| 30 | + ) | |
| 31 | + } | |
| 32 | +} | ... | ... |
front-end/h5/src/components/core/editor/left-panel/preferences/local-preferences.js
0 → 100644
| 1 | +export default class LocalPreferences { | |
| 2 | + static get (key) { | |
| 3 | + this.preferences = this.preferences || this.getAll() | |
| 4 | + return this.preferences[key] | |
| 5 | + } | |
| 6 | + | |
| 7 | + static getAll () { | |
| 8 | + let preferences = {} | |
| 9 | + try { | |
| 10 | + preferences = JSON.parse(localStorage.preferences) | |
| 11 | + } catch (error) {} | |
| 12 | + return preferences | |
| 13 | + } | |
| 14 | + | |
| 15 | + static set (key, value) { | |
| 16 | + this.preferences = this.preferences || this.getAll() | |
| 17 | + this.preferences[key] = value | |
| 18 | + localStorage.preferences = JSON.stringify({ | |
| 19 | + ...this.getAll(), | |
| 20 | + [key]: value | |
| 21 | + }) | |
| 22 | + } | |
| 23 | +} | |
| 24 | + | |
| 25 | +export const IS_CONFIRM_BEFORE_DELETE_ELEMENT = 'isConfirmBeforeDeleteElement' | ... | ... |
front-end/h5/src/components/core/store/modules/element.js
| 1 | 1 | import Element from 'core/models/element' |
| 2 | 2 | import { swapZindex, getVM } from '@/utils/element' |
| 3 | +import LocalPreferences, { IS_CONFIRM_BEFORE_DELETE_ELEMENT } from 'core/editor/left-panel/preferences/local-preferences.js' | |
| 4 | +import { Modal } from 'ant-design-vue' | |
| 5 | +import i18n from '@/locales' | |
| 3 | 6 | |
| 4 | 7 | // actions |
| 5 | 8 | export const actions = { |
| ... | ... | @@ -21,6 +24,20 @@ export const actions = { |
| 21 | 24 | } |
| 22 | 25 | } |
| 23 | 26 | |
| 27 | +const confirmDelete = () => new Promise((resolve, reject) => { | |
| 28 | + if (LocalPreferences.get(IS_CONFIRM_BEFORE_DELETE_ELEMENT)) { | |
| 29 | + Modal.confirm({ | |
| 30 | + title: i18n.t('workCard.confirmDeleteTip', { tip: `` }), | |
| 31 | + onOk: (close) => { | |
| 32 | + resolve() | |
| 33 | + close() | |
| 34 | + } | |
| 35 | + }) | |
| 36 | + return | |
| 37 | + } | |
| 38 | + resolve() | |
| 39 | +}) | |
| 40 | + | |
| 24 | 41 | // mutations |
| 25 | 42 | export const mutations = { |
| 26 | 43 | setEditingElement (state, payload) { |
| ... | ... | @@ -66,10 +83,9 @@ export const mutations = { |
| 66 | 83 | { |
| 67 | 84 | const index = elements.findIndex(e => e.uuid === editingElement.uuid) |
| 68 | 85 | if (index !== -1) { |
| 69 | - // let newElements = elements.slice() | |
| 70 | - // newElements.splice(index, 1) | |
| 71 | - // state.editingPage.elements = newElements | |
| 72 | - state.editingPage.elements.splice(index, 1) | |
| 86 | + confirmDelete().then(() => { | |
| 87 | + state.editingPage.elements.splice(index, 1) | |
| 88 | + }) | |
| 73 | 89 | } |
| 74 | 90 | state.editingElement = null |
| 75 | 91 | } | ... | ... |
front-end/h5/src/components/core/support/shape.js
front-end/h5/src/locales/lang/en-US.js