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