File size: 1,347 Bytes
89ce340
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<template>
  <div class="element-opacity">
    <div class="row">
      <div style="width: 40%;">不透明度:</div>
      <Slider
        :min="0"
        :max="1"
        :step="0.1"
        :value="opacity"
        @update:value="value => updateOpacity(value as number)" 
        style="width: 60%;"
      />
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref, watch } from 'vue'
import { storeToRefs } from 'pinia'
import { useMainStore, useSlidesStore } from '@/store'
import useHistorySnapshot from '@/hooks/useHistorySnapshot'
import Slider from '@/components/Slider.vue'

const slidesStore = useSlidesStore()
const { handleElement } = storeToRefs(useMainStore())

const opacity = ref<number>(1)

watch(handleElement, () => {
  if (!handleElement.value) return
  opacity.value = 'opacity' in handleElement.value && handleElement.value.opacity !== undefined ? handleElement.value.opacity : 1
}, { deep: true, immediate: true })

const { addHistorySnapshot } = useHistorySnapshot()

const updateOpacity = (value: number) => {
  if (!handleElement.value) return
  const props = { opacity: value }
  slidesStore.updateElement({ id: handleElement.value.id, props })
  addHistorySnapshot()
}
</script>

<style lang="scss" scoped>
.row {
  width: 100%;
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}
</style>