|
|
@@ -3,7 +3,7 @@ import Teleport from '@/components/Teleport'
|
|
|
|
|
|
import * as TextboxConfig from './module/TextboxConfig'
|
|
|
import fabric from "../../js/fabric-adapter";
|
|
|
-import {markRaw} from "vue";
|
|
|
+import {markRaw,reactive} from "vue";
|
|
|
// 将默认的 clipSettings 提取为常量
|
|
|
const DEFAULT_CLIP_SETTINGS = {
|
|
|
shape: '',
|
|
|
@@ -30,6 +30,14 @@ export default {
|
|
|
TextboxConfig:TextboxConfig,
|
|
|
options:TextboxConfig.fontFamily,
|
|
|
fontFamilyStyle:"",
|
|
|
+ opacityValue: 1,
|
|
|
+ layerState: {
|
|
|
+ fontSize: 16,
|
|
|
+ lineHeight: 1.2,
|
|
|
+ charSpacing: 0,
|
|
|
+ fill: '#000000',
|
|
|
+ textAlign: 'left',
|
|
|
+ },
|
|
|
shadowText:{
|
|
|
x:0,
|
|
|
y:0,
|
|
|
@@ -51,6 +59,7 @@ export default {
|
|
|
if(this.selected && this.selected.length === 1){
|
|
|
object = this.selected[0]
|
|
|
}
|
|
|
+ // return reactive(object)
|
|
|
return object
|
|
|
},
|
|
|
fontFamily(){
|
|
|
@@ -68,6 +77,17 @@ export default {
|
|
|
watch: {
|
|
|
editLayer(){
|
|
|
this.fontFamilyStyle = this.editLayer.fontFamily
|
|
|
+ this.opacityValue = (this.editLayer && typeof this.editLayer.opacity === 'number')
|
|
|
+ ? this.editLayer.opacity
|
|
|
+ : 1
|
|
|
+ this.layerState = {
|
|
|
+ ...this.layerState,
|
|
|
+ fontSize: this.editLayer?.fontSize ?? 16,
|
|
|
+ lineHeight: this.editLayer?.lineHeight ?? 1,
|
|
|
+ charSpacing: this.editLayer?.charSpacing ?? 0,
|
|
|
+ fill: this.editLayer?.fill ?? '#000000',
|
|
|
+ textAlign: this.editLayer?.textAlign ?? 'left',
|
|
|
+ }
|
|
|
switch (this.editLayer.type){
|
|
|
case "textbox":
|
|
|
if(this.editLayer.shadow){
|
|
|
@@ -118,6 +138,19 @@ export default {
|
|
|
break;
|
|
|
}
|
|
|
},
|
|
|
+ selected(){
|
|
|
+ this.opacityValue = (this.editLayer && typeof this.editLayer.opacity === 'number')
|
|
|
+ ? this.editLayer.opacity
|
|
|
+ : 1
|
|
|
+ this.layerState = {
|
|
|
+ ...this.layerState,
|
|
|
+ fontSize: this.editLayer?.fontSize ?? 16,
|
|
|
+ lineHeight: this.editLayer?.lineHeight ?? 1,
|
|
|
+ charSpacing: this.editLayer?.charSpacing ?? 0,
|
|
|
+ fill: this.editLayer?.fill ?? '#000000',
|
|
|
+ textAlign: this.editLayer?.textAlign ?? 'left',
|
|
|
+ }
|
|
|
+ }
|
|
|
},
|
|
|
created() {
|
|
|
},
|
|
|
@@ -177,25 +210,59 @@ export default {
|
|
|
if(!this.judge()) return;
|
|
|
let {label,value,action } = data
|
|
|
action = action || 'set'
|
|
|
+ // 构造待设置的参数;仅当 label 为 fill 且当前无填充时兜底 #000
|
|
|
let params = value
|
|
|
- if(label){
|
|
|
- params = {}
|
|
|
- params[label] = value
|
|
|
- }
|
|
|
- if(!this.editLayer.fill || label !== 'fill'){
|
|
|
- params = {
|
|
|
- fill:'#000'
|
|
|
+ if (label) {
|
|
|
+ params = { [label]: value }
|
|
|
+ if (label === 'fill' && !this.editLayer.fill) {
|
|
|
+ params.fill = value || '#000'
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
this.editLayer[action](params)
|
|
|
- if(Array.isArray(this.editLayer._objects)){
|
|
|
- this.editLayer._objects?.map(item=>{
|
|
|
+ if (Array.isArray(this.editLayer._objects)){
|
|
|
+ this.editLayer._objects?.forEach(item=>{
|
|
|
item[action](params)
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
+ // 同步常用文本状态到 layerState,避免 UI 视图不同步
|
|
|
+ if (['fontSize','lineHeight','charSpacing','fill','textAlign'].includes(label)) {
|
|
|
+ this.layerState = {
|
|
|
+ ...this.layerState,
|
|
|
+ [label]: value,
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
this.updateCanvasState()
|
|
|
this.fcanvas.requestRenderAll()
|
|
|
},
|
|
|
+ // 通用设置图层属性,解决 markRaw 不响应问题
|
|
|
+ setLayerAttr(name, val){
|
|
|
+ if(!this.editLayer) return
|
|
|
+ this.layerState = {
|
|
|
+ ...this.layerState,
|
|
|
+ [name]: val,
|
|
|
+ }
|
|
|
+ this.editLayer.set(name, val)
|
|
|
+ if(Array.isArray(this.editLayer._objects)){
|
|
|
+ this.editLayer._objects.forEach(o => o.set(name, val))
|
|
|
+ }
|
|
|
+ this.updateCanvasState()
|
|
|
+ this.fcanvas && this.fcanvas.requestRenderAll()
|
|
|
+ },
|
|
|
+ // 设置透明度(解决 Vue3 markRaw 不响应)
|
|
|
+ setOpacity(val){
|
|
|
+ if(!this.editLayer) return
|
|
|
+ const num = Number(val)
|
|
|
+ this.opacityValue = num
|
|
|
+ this.editLayer.set('opacity', num)
|
|
|
+ if(Array.isArray(this.editLayer._objects)){
|
|
|
+ this.editLayer._objects.forEach(o => o.set('opacity', num))
|
|
|
+ }
|
|
|
+ this.updateCanvasState()
|
|
|
+ this.fcanvas && this.fcanvas.requestRenderAll()
|
|
|
+ },
|
|
|
async setFontFamily(val,item=null){
|
|
|
console.log(val)
|
|
|
console.log(item)
|