zhengyiming
20 小时以前 55119aeab85c9dc310ab8bc3de3091a20fa9a684
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
<template>
  <div v-if="isOne && type === 'image'" class="attr-item-box">
    <div class="bg-item ivu-mb-8">
      <Dropdown style="width: 270px" @on-click="addClipPath">
        <Button type="text" long>{{ $t('createClip') }}</Button>
        <template #list>
          <DropdownMenu>
            <DropdownItem v-for="item in options" :key="item.value" :name="item.value">
              {{ item.label }}
            </DropdownItem>
          </DropdownMenu>
        </template>
      </Dropdown>
    </div>
    <div class="bg-item">
      <Button @click="removeClip" type="text" long>{{ $t('removeClip') }}</Button>
    </div>
  </div>
</template>
 
<script setup name="ReplaceImg">
import useSelect from '@/hooks/select';
import { useI18n } from 'vue-i18n';
 
const update = getCurrentInstance();
// const canvasEditor = inject('canvasEditor');
const { canvasEditor, isOne } = useSelect();
const { t } = useI18n();
const type = ref('');
const options = [
  {
    label: t('polygonClip'),
    value: 'polygon',
  },
  {
    label: t('rectClip'),
    value: 'rect',
  },
  {
    label: t('circleClip'),
    value: 'circle',
  },
  {
    label: t('triangleClip'),
    value: 'triangle',
  },
  {
    label: t('polygonClipInverted'),
    value: 'polygon-inverted',
  },
  {
    label: t('rectClipInverted'),
    value: 'rect-inverted',
  },
  {
    label: t('circleClipInverted'),
    value: 'circle-inverted',
  },
  {
    label: t('triangleClipInverted'),
    value: 'triangle-inverted',
  },
];
const addClipPath = async (name) => {
  canvasEditor.addClipPathToImage(name);
};
const removeClip = () => {
  canvasEditor.removeClip();
};
const init = () => {
  const activeObject = canvasEditor.canvas.getActiveObjects()[0];
  if (activeObject) {
    type.value = activeObject.type;
    update?.proxy?.$forceUpdate();
  }
};
 
onMounted(() => {
  canvasEditor.on('selectOne', init);
});
 
onBeforeUnmount(() => {
  canvasEditor.off('selectOne', init);
});
</script>
<style lang="less" scoped>
.attr-item-box {
  margin-top: 8px;
}
</style>