Commit 4c3679c42f539622b98e6c4e854c277c656a7114

Authored by ly525
1 parent 6e23b001

fix: move canvas scale ratio to vuex

front-end/h5/src/components/core/editor/canvas/index.js
@@ -6,8 +6,7 @@ import RenderPreviewCanvas from './preview' @@ -6,8 +6,7 @@ import RenderPreviewCanvas from './preview'
6 export default { 6 export default {
7 name: 'EditorCanvas', 7 name: 'EditorCanvas',
8 data: () => ({ 8 data: () => ({
9 - isPreviewMode: false,  
10 - scaleRate: 1 9 + isPreviewMode: false
11 }), 10 }),
12 computed: { 11 computed: {
13 ...mapState('editor', { 12 ...mapState('editor', {
@@ -15,7 +14,8 @@ export default { @@ -15,7 +14,8 @@ export default {
15 editingElement: state => state.editingElement, 14 editingElement: state => state.editingElement,
16 elements: state => state.editingPage.elements, 15 elements: state => state.editingPage.elements,
17 pages: state => state.work.pages, 16 pages: state => state.work.pages,
18 - work: state => state.work 17 + work: state => state.work,
  18 + scaleRate: state => state.scaleRate
19 }), 19 }),
20 ...mapState('loading', [ 20 ...mapState('loading', [
21 'saveWork_loading', 21 'saveWork_loading',
front-end/h5/src/components/core/editor/fixed-tools/index.js
1 -import { mapActions } from 'vuex' 1 +import { mapActions, mapState } from 'vuex'
2 import hotkeys from 'hotkeys-js' 2 import hotkeys from 'hotkeys-js'
3 import fixedTools from './options' 3 import fixedTools from './options'
4 4
5 export default { 5 export default {
  6 + computed: {
  7 + ...mapState('editor', {
  8 + scaleRate: state => state.scaleRate
  9 + })
  10 + },
6 methods: { 11 methods: {
7 - ...mapActions('editor', ['pageManager']) 12 + ...mapActions('editor', ['pageManager', 'elementManager', 'updateScaleRate'])
8 }, 13 },
9 render () { 14 render () {
10 return ( 15 return (
front-end/h5/src/components/core/editor/fixed-tools/options.js
@@ -41,14 +41,14 @@ const fixedTools = [ @@ -41,14 +41,14 @@ const fixedTools = [
41 { 41 {
42 i18nTooltip: 'editor.fixedTool.zoomOut', 42 i18nTooltip: 'editor.fixedTool.zoomOut',
43 icon: 'plus', 43 icon: 'plus',
44 - action: function () { this.scaleRate += 0.25 }, 44 + action: function () { this.updateScaleRate(0.25) },
45 hotkey: 'ctrl&=,⌘&=', 45 hotkey: 'ctrl&=,⌘&=',
46 hotkeyTooltip: '(ctrl +)' 46 hotkeyTooltip: '(ctrl +)'
47 }, 47 },
48 { 48 {
49 i18nTooltip: 'editor.fixedTool.zoomIn', 49 i18nTooltip: 'editor.fixedTool.zoomIn',
50 icon: 'minus', 50 icon: 'minus',
51 - action: function () { this.scaleRate -= 0.25 }, 51 + action: function () { this.updateScaleRate(-0.25) },
52 hotkey: 'ctrl&-,⌘&-', 52 hotkey: 'ctrl&-,⌘&-',
53 hotkeyTooltip: '(ctrl -)' 53 hotkeyTooltip: '(ctrl -)'
54 }, 54 },
front-end/h5/src/components/core/editor/left-panel/shortcuts-panel/index.js
@@ -3,7 +3,7 @@ import UsageTip from './usage-tip' @@ -3,7 +3,7 @@ import UsageTip from './usage-tip'
3 import LoadNpmPlugins from './load-npm-plugins.vue' 3 import LoadNpmPlugins from './load-npm-plugins.vue'
4 import langMixin from 'core/mixins/i18n' 4 import langMixin from 'core/mixins/i18n'
5 import dragMixin from 'core/mixins/drag' 5 import dragMixin from 'core/mixins/drag'
6 -import loadPluginsMixin from 'core/plugins' 6 +import loadPluginsMixin from 'core/plugins/index'
7 import { mapActions } from 'vuex' 7 import { mapActions } from 'vuex'
8 8
9 export default { 9 export default {
front-end/h5/src/components/core/mixins/drag.js
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 * @Author: ly525 2 * @Author: ly525
3 * @Date: 2020-05-17 17:21:04 3 * @Date: 2020-05-17 17:21:04
4 * @LastEditors: ly525 4 * @LastEditors: ly525
5 - * @LastEditTime: 2020-10-10 23:27:21 5 + * @LastEditTime: 2020-10-11 17:20:39
6 * @FilePath: /luban-h5/front-end/h5/src/components/core/mixins/drag.js 6 * @FilePath: /luban-h5/front-end/h5/src/components/core/mixins/drag.js
7 * @Github: https://github.com/ly525/luban-h5 7 * @Github: https://github.com/ly525/luban-h5
8 * @Copyright 2018 - 2020 luban-h5. All Rights Reserved 8 * @Copyright 2018 - 2020 luban-h5. All Rights Reserved
@@ -50,7 +50,6 @@ class Drag { @@ -50,7 +50,6 @@ class Drag {
50 } 50 }
51 51
52 _mouseup (e) { 52 _mouseup (e) {
53 - console.log('mouseup')  
54 this.mouseup(e) 53 this.mouseup(e)
55 this.toggleListener('remove') 54 this.toggleListener('remove')
56 } 55 }
front-end/h5/src/components/core/store/modules/canvas.js 0 → 100644
  1 +// actions
  2 +export const actions = {
  3 + updateScaleRate ({ commit }, payload) {
  4 + commit('updateScaleRate', payload)
  5 + }
  6 +}
  7 +
  8 +// mutations
  9 +export const mutations = {
  10 + /**
  11 + *
  12 + * @param {*} state
  13 + * @param {Number} scaleRateDiff 放大: 0.25, 缩小: -0.25
  14 + */
  15 + updateScaleRate (state, scaleRateDiff) {
  16 + state.scaleRate += scaleRateDiff
  17 + }
  18 +}
front-end/h5/src/components/core/store/modules/editor.js
1 // initial state 1 // initial state
2 import Work from 'core/models/work' 2 import Work from 'core/models/work'
  3 +import { actions as canvasActions, mutations as canvasMutations } from './canvas'
3 import { actions as pageActions, mutations as pageMutations } from './page' 4 import { actions as pageActions, mutations as pageMutations } from './page'
4 import { actions as elementActions, mutations as elementMutations } from './element' 5 import { actions as elementActions, mutations as elementMutations } from './element'
5 import { actions as workActions, mutations as workMutations } from './work' 6 import { actions as workActions, mutations as workMutations } from './work'
@@ -13,7 +14,8 @@ const state = { @@ -13,7 +14,8 @@ const state = {
13 uuidMap2Name: {}, 14 uuidMap2Name: {},
14 formRecords: [] 15 formRecords: []
15 }, 16 },
16 - workTemplates: [] 17 + workTemplates: [],
  18 + scaleRate: 1
17 } 19 }
18 20
19 // getters 21 // getters
@@ -23,14 +25,16 @@ const getters = {} @@ -23,14 +25,16 @@ const getters = {}
23 const actions = { 25 const actions = {
24 ...elementActions, 26 ...elementActions,
25 ...pageActions, 27 ...pageActions,
26 - ...workActions 28 + ...workActions,
  29 + ...canvasActions
27 } 30 }
28 31
29 // mutations 32 // mutations
30 const mutations = { 33 const mutations = {
31 ...elementMutations, 34 ...elementMutations,
32 ...pageMutations, 35 ...pageMutations,
33 - ...workMutations 36 + ...workMutations,
  37 + ...canvasMutations
34 } 38 }
35 39
36 export default { 40 export default {