wupengfei
16 小时以前 08bcae11d27cf2b5f0f23d413192c5367cb05b3d
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
<!--
 * @Author: 秦少卫
 * @Date: 2022-09-03 19:16:55
 * @LastEditors: 秦少卫
 * @LastEditTime: 2024-10-07 17:20:59
 * @Description: 锁定元素
-->
 
<template>
  <el-tooltip :content="isLock ? '解锁' : '锁定'" v-if="isOne && isMatchType">
    <el-button v-if="isLock" @click="doLock(false)" icon="Lock" text></el-button>
    <el-button v-else @click="doLock(true)" icon="Unlock" text></el-button>
  </el-tooltip>
</template>
 
<script setup name="Lock">
import useSelect from '@/fabric-editor/hooks/select';
import { onBeforeUnmount, onMounted } from 'vue';
import { TemplateParamObjectName } from '@/fabric-editor/customObject';
 
// 可修改的元素
const baseType = [
  'text',
  'i-text',
  'textbox',
  'rect',
  'circle',
  'triangle',
  'polygon',
  // 'image',
  'group',
  'line',
  'arrow',
  'thinTailArrow',
  TemplateParamObjectName,
];
const { isMatchType, canvasEditor, isOne } = useSelect(baseType);
 
const isLock = ref(false);
const doLock = (isLock) => {
  isLock ? canvasEditor.lock() : canvasEditor.unLock();
};
 
const handleSelected = (items) => {
  isLock.value = items[0].lockMovementX;
};
 
onMounted(() => {
  canvasEditor.on('selectOne', handleSelected);
});
 
onBeforeUnmount(() => {
  canvasEditor.off('selectOne', handleSelected);
});
</script>
 
<style scoped lang="scss">
h3 {
  margin: 40px 0 0;
}
 
ul {
  list-style-type: none;
  padding: 0;
}
 
li {
  display: inline-block;
  margin: 0 10px;
}
 
a {
  color: #42b983;
}
</style>