wangrong
2026-08-30 4c949c0dc9bcae785c281c9d8125295f09810b15
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<template>
  <el-form size="small" label-position="left" :label-width="14">
    <el-row :gutter="8" v-for="(x, i) in positionKeysGroup" :key="i">
      <el-col :span="12" v-for="({ key, label, min, max, step }, j) in x" :key="j">
        <el-form-item class="form-item" :class="'form-item-' + themes" :label="label">
          <el-input-number
            :effect="themes"
            :disabled="curComponent['isLock']"
            :min="min"
            :max="max"
            :step="step"
            v-model="positionMounted[key]"
            @change="onPositionChange(key)"
            controls-position="right"
          />
        </el-form-item>
      </el-col>
    </el-row>
    <el-form-item
      v-if="curComponent && curComponent.component === 'DeTabs'"
      class="form-item"
      :class="'form-item-' + themes"
    >
      <el-checkbox
        size="small"
        :effect="themes"
        v-model="curComponent['resizeInnerKeep']"
        @change="snapshotChange"
      >
        {{ t('visualization.keep_size') }}
      </el-checkbox>
    </el-form-item>
    <el-form-item class="form-item" :class="'form-item-' + themes">
      <el-checkbox
        v-if="curComponent"
        size="small"
        :effect="themes"
        v-model="curComponent['maintainRadio']"
        @change="maintainRadioChange"
      >
        {{ t('visualization.keep_ratio') }}
      </el-checkbox>
    </el-form-item>
    <el-row v-if="curComponent && curComponent.multiDimensional">
      <el-col :span="12">
        <el-form-item class="form-item" :class="'form-item-' + themes">
          <el-checkbox
            size="small"
            :effect="themes"
            v-model="curComponent.multiDimensional.enable"
            @change="multiDimensionalChange"
          >
            {{ t('visualization.rotation_3d') }}
          </el-checkbox>
        </el-form-item>
        <template v-if="curComponent.multiDimensional.enable">
          <el-form-item class="form-item" :class="'form-item-' + themes" label="X">
            <el-input-number
              :effect="themes"
              :disabled="curComponent['isLock']"
              :min="-360"
              :max="360"
              :step="1"
              v-model="curComponent.multiDimensional.x"
              @change="multiDimensionalChange"
              controls-position="right"
            />
          </el-form-item>
          <el-form-item class="form-item" :class="'form-item-' + themes" label="Y">
            <el-input-number
              :effect="themes"
              :disabled="curComponent['isLock']"
              :min="-360"
              :max="360"
              :step="1"
              v-model="curComponent.multiDimensional.y"
              @change="multiDimensionalChange"
              controls-position="right"
            />
          </el-form-item>
          <el-form-item class="form-item" :class="'form-item-' + themes" label="Z">
            <el-input-number
              :effect="themes"
              :disabled="curComponent['isLock']"
              :min="-360"
              :max="360"
              :step="1"
              v-model="curComponent.multiDimensional.z"
              @change="multiDimensionalChange"
              controls-position="right"
            />
          </el-form-item>
        </template>
      </el-col>
    </el-row>
  </el-form>
</template>
 
<script setup lang="ts">
import { computed, ref, watch } from 'vue'
import { positionData } from '@/utils/attr'
import { storeToRefs } from 'pinia'
import { dvMainStoreWithOut } from '@/store/modules/data-visualization/dvMain'
import _ from 'lodash'
import { snapshotStoreWithOut } from '@/store/modules/data-visualization/snapshot'
import { groupSizeStyleAdaptor, groupStyleRevert } from '@/utils/style'
import { isGroupCanvas, isTabCanvas } from '@/utils/canvasUtils'
import { useI18n } from '@/hooks/web/useI18n'
const parentNode = ref(null)
const canvasId = ref('canvas-main')
const snapshotStore = snapshotStoreWithOut()
const { t } = useI18n()
const dvMainStore = dvMainStoreWithOut()
const { curComponent, canvasStyleData } = storeToRefs(dvMainStore)
const positionMounted = ref({
  width: 0,
  height: 0,
  top: 0,
  left: 0
})
 
withDefaults(
  defineProps<{
    themes: EditorTheme
  }>(),
  { themes: 'dark' }
)
 
const positionKeys = computed(() => {
  if (curComponent.value) {
    const curComponentStyleKeys = Object.keys(curComponent.value.style)
    return positionData.filter(item => curComponentStyleKeys.includes(item.key))
  } else {
    return []
  }
})
 
const positionKeysGroup = computed(() => {
  const _list = []
  _.forEach(positionKeys.value, (x, i) => {
    const index = i % 2
    if (_list[index] === undefined) {
      _list[index] = []
    }
    _list[index].push(x)
  })
  return _list
})
 
const onPositionChange = key => {
  if (!positionMounted.value[key]) {
    positionMounted.value[key] = 0
  }
  if (curComponent.value.maintainRadio) {
    curComponent.value.style[key] = Math.ceil(
      (positionMounted.value[key] * canvasStyleData.value.scale) / 100
    )
    if (key === 'width') {
      curComponent.value.style['height'] =
        curComponent.value.style['width'] / curComponent.value.aspectRatio
      positionMounted.value['height'] = Math.round(
        positionMounted.value['width'] / curComponent.value.aspectRatio
      )
    } else if (key === 'height') {
      curComponent.value.style['width'] =
        curComponent.value.style['height'] * curComponent.value.aspectRatio
      positionMounted.value['width'] = Math.round(
        positionMounted.value['height'] * curComponent.value.aspectRatio
      )
    }
  } else {
    curComponent.value.style[key] = (positionMounted.value[key] * canvasStyleData.value.scale) / 100
  }
 
  //如果当前画布是Group内部画布 则对应组件定位在resize时要还原到groupStyle中
  if (isGroupCanvas(canvasId.value) || isTabCanvas(canvasId.value)) {
    groupStyleRevert(curComponent.value, {
      width: parentNode.value.offsetWidth,
      height: parentNode.value.offsetHeight
    })
  }
 
  if (['Group', 'DeTabs'].includes(curComponent.value.component)) {
    //如果当前组件是Group分组或者Tab 则要进行内部组件深度计算
    groupSizeStyleAdaptor(curComponent.value)
  }
 
  snapshotStore.recordSnapshotCache('onPositionChange')
}
 
const maintainRadioChange = () => {
  curComponent.value.aspectRatio = curComponent.value.style.width / curComponent.value.style.height
  snapshotStore.recordSnapshotCache('maintainRadioChange')
}
const multiDimensionalChange = () => {
  // do change
  snapshotStore.recordSnapshotCache('multiDimensionalChange')
}
 
const snapshotChange = () => {
  snapshotStore.recordSnapshotCache('snapshotChange')
}
 
const positionInit = () => {
  if (curComponent.value) {
    canvasId.value = curComponent.value.canvasId
    parentNode.value = document.querySelector('#editor-' + canvasId.value)
    Object.keys(positionMounted.value).forEach(key => {
      positionMounted.value[key] = Math.round(
        (curComponent.value.style[key] * 100) / canvasStyleData.value.scale
      )
    })
    if (curComponent.value.maintainRadio) {
      positionMounted.value.width = Math.round(
        positionMounted.value.height * curComponent.value.aspectRatio
      )
    }
  }
}
 
watch(
  () => curComponent.value,
  () => {
    positionInit()
  },
  {
    deep: true,
    immediate: true
  }
)
</script>
 
<style lang="less" scoped>
:deep(.ed-form-item) {
  display: flex !important;
  .ed-form-item__label {
    line-height: 24px;
    margin: 3px 0 !important;
  }
}
</style>