Commit 2c038ef5 authored by 章启成's avatar 章启成 Committed by 言肆

feat(WaterMark): 使用 toRef 保留 props.content 的响应性

parent f4b995c0
import type { CSSProperties, PropType, ExtractPropTypes } from 'vue' import type { CSSProperties, PropType, ExtractPropTypes } from 'vue'
import { defineComponent, computed, ref, watchEffect } from 'vue' import { defineComponent, computed, ref, watchEffect, toRef } from 'vue'
import { useRouteContext } from '../RouteContext' import { useRouteContext } from '../RouteContext'
export type FontStyle = 'none' | 'normal' | 'italic' | 'oblique' export type FontStyle = 'none' | 'normal' | 'italic' | 'oblique'
...@@ -82,7 +82,6 @@ const WaterMark = defineComponent({ ...@@ -82,7 +82,6 @@ const WaterMark = defineComponent({
height = 64, height = 64,
rotate = -22, // 默认旋转 -22 度 rotate = -22, // 默认旋转 -22 度
image, image,
content,
offsetLeft, offsetLeft,
offsetTop, offsetTop,
fontStyle = 'normal', fontStyle = 'normal',
...@@ -93,6 +92,7 @@ const WaterMark = defineComponent({ ...@@ -93,6 +92,7 @@ const WaterMark = defineComponent({
prefixCls: customizePrefixCls, prefixCls: customizePrefixCls,
} = props } = props
const content = toRef(props,'content')
const { getPrefixCls } = useRouteContext() const { getPrefixCls } = useRouteContext()
const prefixCls = getPrefixCls('pro-layout-watermark', customizePrefixCls) const prefixCls = getPrefixCls('pro-layout-watermark', customizePrefixCls)
const wrapperCls = computed(() => `${prefixCls}-wrapper`) const wrapperCls = computed(() => `${prefixCls}-wrapper`)
...@@ -133,11 +133,11 @@ const WaterMark = defineComponent({ ...@@ -133,11 +133,11 @@ const WaterMark = defineComponent({
ctx.drawImage(img, 0, 0, markWidth, markHeight) ctx.drawImage(img, 0, 0, markWidth, markHeight)
base64Url.value = canvas.toDataURL() base64Url.value = canvas.toDataURL()
} }
} else if (content) { } else if (content.value) {
const markSize = Number(fontSize) * ratio const markSize = Number(fontSize) * ratio
ctx.font = `${fontStyle} normal ${fontWeight} ${markSize}px/${markHeight}px ${fontFamily}` ctx.font = `${fontStyle} normal ${fontWeight} ${markSize}px/${markHeight}px ${fontFamily}`
ctx.fillStyle = fontColor ctx.fillStyle = fontColor
ctx.fillText(content, 0, 0) ctx.fillText(content.value, 0, 0)
base64Url.value = canvas.toDataURL() base64Url.value = canvas.toDataURL()
} }
} else { } else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment