Skip to content

Commit

Permalink
fix: 修复渐变组件问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Qiu-Jun committed Oct 3, 2023
1 parent b974c01 commit 9099c83
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
4 changes: 2 additions & 2 deletions 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": "^1.0.3",
"color-gradient-picker-vue3": "^2.0.1",
"events": "^3.3.0",
"fabric": "^5.2.1",
"fontfaceobserver": "^2.1.0",
Expand Down Expand Up @@ -69,4 +69,4 @@
"prettier --write"
]
}
}
}
26 changes: 14 additions & 12 deletions src/components/colorSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,17 @@
<div v-if="isGradient">
<div class="gradient-bar" :style="bgStr"></div>
<!-- 颜色插件 -->
<div class="ivu-poptip-inner">
<div class="ivu-poptip-popper ivu-poptip-inner">
<gradientColorPicker
:is-gradient="true"
:gradient="currentGradient"
:on-end-change="changeGradientColor"
@change="changeGradientColor"
:cancel-text="$t('cancel')"
:confirm-text="$t('ok')"
/>
</div>
</div>

<!-- <div class="ivu-poptip-popper ivu-poptip-inner">
<gradientColorPicker
:is-gradient="true"
:gradient="currentGradient"
:on-end-change="changeGradientColor"
/>
</div> -->
<!-- 纯色选择器 -->
<ColorPicker v-show="!isGradient" v-model="fill" @on-change="changePureColor" alpha />
</div>
Expand Down Expand Up @@ -160,22 +155,29 @@ const checkColor = (val) => {
};
const changeGradientColor = (val) => {
const activeObject = canvasEditor.canvas.getActiveObjects()[0];
const { gradient } = val;
if (activeObject) {
const currentGradient = cssToFabricGradient(val, activeObject);
const currentGradient = cssToFabricGradient(gradient, activeObject);
// TODO:
emitChange('change', currentGradient);
// 保存角度,用于下一次选中展示
activeObject.set(props.angleKey, val.degree);
activeObject.set(props.angleKey, gradient.degree);
setGradientBar(val);
}
};
// 设置渐变颜色条
const setGradientBar = (val) => {
bgStr.value = `background:${val.style.replace('radial', 'linear')};`;
if (val.gradient.type === 'linear') {
bgStr.value = `background: ${val.style};`;
} else {
bgStr.value = `background: ${val.style.replace('radial', 'linear')};`;
}
};
// Fabric渐变bar背景设置
const fabricGradientToBar = (val) => {
// 百分比排序
val.colorStops.sort((a, b) => a.offset - b.offset);
const str = val.colorStops.map((item) => `${item.color} ${item.offset * 100}%`);
bgStr.value = `background: linear-gradient(124deg, ${str});`;
};
Expand Down

0 comments on commit 9099c83

Please sign in to comment.