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 | import RenderShortcutsPanel from './shortcuts-panel/index' | 1 | import RenderShortcutsPanel from './shortcuts-panel/index' |
| 2 | import RenderPageManager from './page-manager/index' | 2 | import RenderPageManager from './page-manager/index' |
| 3 | import RenderPageTree from './page-tree/index' | 3 | import RenderPageTree from './page-tree/index' |
| 4 | +import RenderPagePreferences from './preferences/index' | ||
| 4 | 5 | ||
| 5 | export default { | 6 | export default { |
| 6 | name: 'EditorLeftPanel', | 7 | name: 'EditorLeftPanel', |
| @@ -20,6 +21,9 @@ export default { | @@ -20,6 +21,9 @@ export default { | ||
| 20 | <a-tab-pane key='page-tree' tab={this.$t('editor.sidebar.tree')}> | 21 | <a-tab-pane key='page-tree' tab={this.$t('editor.sidebar.tree')}> |
| 21 | <RenderPageTree /> | 22 | <RenderPageTree /> |
| 22 | </a-tab-pane> | 23 | </a-tab-pane> |
| 24 | + <a-tab-pane key='preferences' tab={this.$t('editor.sidebar.preferences')}> | ||
| 25 | + <RenderPagePreferences /> | ||
| 26 | + </a-tab-pane> | ||
| 23 | </a-tabs> | 27 | </a-tabs> |
| 24 | </a-layout-sider> | 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 | import Element from 'core/models/element' | 1 | import Element from 'core/models/element' |
| 2 | import { swapZindex, getVM } from '@/utils/element' | 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 | // actions | 7 | // actions |
| 5 | export const actions = { | 8 | export const actions = { |
| @@ -21,6 +24,20 @@ 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 | // mutations | 41 | // mutations |
| 25 | export const mutations = { | 42 | export const mutations = { |
| 26 | setEditingElement (state, payload) { | 43 | setEditingElement (state, payload) { |
| @@ -66,10 +83,9 @@ export const mutations = { | @@ -66,10 +83,9 @@ export const mutations = { | ||
| 66 | { | 83 | { |
| 67 | const index = elements.findIndex(e => e.uuid === editingElement.uuid) | 84 | const index = elements.findIndex(e => e.uuid === editingElement.uuid) |
| 68 | if (index !== -1) { | 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 | state.editingElement = null | 90 | state.editingElement = null |
| 75 | } | 91 | } |
front-end/h5/src/components/core/support/shape.js
| @@ -146,7 +146,6 @@ export default { | @@ -146,7 +146,6 @@ export default { | ||
| 146 | * !#en: delete element with keyboard | 146 | * !#en: delete element with keyboard |
| 147 | * !#zh: 键盘快捷键删除元素 | 147 | * !#zh: 键盘快捷键删除元素 |
| 148 | * | 148 | * |
| 149 | - * TODO: 增加 确认删除 拦截操作 | ||
| 150 | */ | 149 | */ |
| 151 | handleDeleteByKeyboard (event) { | 150 | handleDeleteByKeyboard (event) { |
| 152 | const key = event.keyCode || event.charCode | 151 | const key = event.keyCode || event.charCode |
front-end/h5/src/locales/lang/en-US.js
| @@ -35,7 +35,8 @@ export default { | @@ -35,7 +35,8 @@ export default { | ||
| 35 | components: 'Components', | 35 | components: 'Components', |
| 36 | pages: 'Pages', | 36 | pages: 'Pages', |
| 37 | templates: 'Templates', | 37 | templates: 'Templates', |
| 38 | - tree: 'Tree' | 38 | + tree: 'Tree', |
| 39 | + preferences: 'Preferences' | ||
| 39 | }, | 40 | }, |
| 40 | pageManager: { | 41 | pageManager: { |
| 41 | title: 'Page {index}', | 42 | title: 'Page {index}', |
front-end/h5/src/locales/lang/zh-CN.js
| @@ -45,7 +45,8 @@ export default { | @@ -45,7 +45,8 @@ export default { | ||
| 45 | components: '组件列表', | 45 | components: '组件列表', |
| 46 | pages: '页面管理', | 46 | pages: '页面管理', |
| 47 | templates: '模板', | 47 | templates: '模板', |
| 48 | - tree: '组件树' | 48 | + tree: '组件树', |
| 49 | + preferences: '偏好设置' | ||
| 49 | }, | 50 | }, |
| 50 | pageManager: { | 51 | pageManager: { |
| 51 | title: '第{index}页面', | 52 | title: '第{index}页面', |