Skip to content

Commit

Permalink
fix: 优化渐变的执行频率
Browse files Browse the repository at this point in the history
  • Loading branch information
Qiu-Jun committed Oct 4, 2023
1 parent 9099c83 commit 85ff587
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"dependencies": {
"@vueuse/core": "^10.1.0",
"axios": "^1.3.4",
"color-gradient-picker-vue3": "^2.0.1",
"color-gradient-picker-vue3": "^2.0.3",
"events": "^3.3.0",
"fabric": "^5.2.1",
"fontfaceobserver": "^2.1.0",
Expand Down
24 changes: 13 additions & 11 deletions src/components/colorSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@
<div v-if="isGradient">
<div class="gradient-bar" :style="bgStr"></div>
<!-- 颜色插件 -->
<div class="ivu-poptip-popper ivu-poptip-inner">
<gradientColorPicker
:is-gradient="true"
:gradient="currentGradient"
@change="changeGradientColor"
:cancel-text="$t('cancel')"
:confirm-text="$t('ok')"
/>
</div>

<gradientColorPicker
:is-gradient="true"
:gradient="currentGradient"
@change="changeGradientColor"
:cancel-text="$t('cancel')"
:confirm-text="$t('ok')"
/>
</div>

<!-- 纯色选择器 -->
Expand All @@ -41,6 +40,7 @@ import 'color-gradient-picker-vue3/dist/style.css';
import gradientColorPicker from 'color-gradient-picker-vue3';
import { fabric } from 'fabric';
import useSelect from '@/hooks/select';
import { debounce } from 'lodash-es';
const { canvasEditor } = useSelect();
const generateFabricGradientFromColorStops = (handlers, width, height, orientation, angle) => {
// 角度转换坐标
Expand Down Expand Up @@ -109,6 +109,8 @@ const emitChange = defineEmits(['change']);
// const poptipCreated = ref(false);
// 是否渐变
const isGradient = ref(false);
// 是否显示渐变
const showGradient = ref(false);
// 纯色
const fill = ref('');
// 渐变
Expand Down Expand Up @@ -153,7 +155,7 @@ const checkColor = (val) => {
}
}
};
const changeGradientColor = (val) => {
const changeGradientColor = debounce(function (val) {
const activeObject = canvasEditor.canvas.getActiveObjects()[0];
const { gradient } = val;
if (activeObject) {
Expand All @@ -165,7 +167,7 @@ const changeGradientColor = (val) => {
activeObject.set(props.angleKey, gradient.degree);
setGradientBar(val);
}
};
}, 500);
// 设置渐变颜色条
const setGradientBar = (val) => {
if (val.gradient.type === 'linear') {
Expand Down

0 comments on commit 85ff587

Please sign in to comment.