init
This commit is contained in:
229
unpackage/dist/dev/mp-weixin/uni_modules/nutui-uni/components/watermark/watermark.js
vendored
Normal file
229
unpackage/dist/dev/mp-weixin/uni_modules/nutui-uni/components/watermark/watermark.js
vendored
Normal file
@@ -0,0 +1,229 @@
|
||||
"use strict";
|
||||
const common_vendor = require("../../../../common/vendor.js");
|
||||
const uni_modules_nutuiUni_components__constants_prefix = require("../_constants/prefix.js");
|
||||
require("../_utils/env.js");
|
||||
const uni_modules_nutuiUni_components__utils_style = require("../_utils/style.js");
|
||||
const uni_modules_nutuiUni_components__constants_event = require("../_constants/event.js");
|
||||
const uni_modules_nutuiUni_components__utils_props = require("../_utils/props.js");
|
||||
const watermarkProps = {
|
||||
...uni_modules_nutuiUni_components__utils_props.commonProps,
|
||||
/**
|
||||
* @description 水印的名称
|
||||
*/
|
||||
name: String,
|
||||
/**
|
||||
* @description 水印之间的垂直间距
|
||||
*/
|
||||
gapY: uni_modules_nutuiUni_components__utils_props.makeNumberProp(48),
|
||||
/**
|
||||
* @description 水印之间的水平间距
|
||||
*/
|
||||
gapX: uni_modules_nutuiUni_components__utils_props.makeNumberProp(24),
|
||||
/**
|
||||
* @description 追加的水印元素的z-index
|
||||
*/
|
||||
zIndex: uni_modules_nutuiUni_components__utils_props.makeNumberProp(2e3),
|
||||
/**
|
||||
* @description 水印的宽度
|
||||
*/
|
||||
width: uni_modules_nutuiUni_components__utils_props.makeNumberProp(120),
|
||||
/**
|
||||
* @description 水印的高度
|
||||
*/
|
||||
height: uni_modules_nutuiUni_components__utils_props.makeNumberProp(64),
|
||||
/**
|
||||
* @description 水印绘制时,旋转的角度
|
||||
*/
|
||||
rotate: uni_modules_nutuiUni_components__utils_props.makeNumberProp(-22),
|
||||
/**
|
||||
* @description 图片源,建议导出 2 倍或 3 倍图,优先使用图片渲染水印
|
||||
*/
|
||||
image: String,
|
||||
/**
|
||||
* @description 图片宽度
|
||||
*/
|
||||
imageWidth: uni_modules_nutuiUni_components__utils_props.makeNumberProp(120),
|
||||
/**
|
||||
* @description 图片高度
|
||||
*/
|
||||
imageHeight: uni_modules_nutuiUni_components__utils_props.makeNumberProp(64),
|
||||
/**
|
||||
* @description 水印文字内容
|
||||
*/
|
||||
content: {
|
||||
type: [String, Array],
|
||||
default: ""
|
||||
},
|
||||
/**
|
||||
* @description 水印文字颜色
|
||||
*/
|
||||
fontColor: uni_modules_nutuiUni_components__utils_props.makeStringProp("rgba(0,0,0,.15)"),
|
||||
/**
|
||||
* @description 水印文字样式
|
||||
*/
|
||||
fontStyle: uni_modules_nutuiUni_components__utils_props.makeStringProp("normal"),
|
||||
/**
|
||||
* @description 水印文字字体
|
||||
*/
|
||||
fontFamily: uni_modules_nutuiUni_components__utils_props.makeStringProp("PingFang SC"),
|
||||
/**
|
||||
* @description 水印文字粗细
|
||||
*/
|
||||
fontWeight: uni_modules_nutuiUni_components__utils_props.makeStringProp("normal"),
|
||||
/**
|
||||
* @description 水印文字大小
|
||||
*/
|
||||
fontSize: uni_modules_nutuiUni_components__utils_props.makeNumericProp(14),
|
||||
/**
|
||||
* @description 是否覆盖整个页面
|
||||
*/
|
||||
fullPage: uni_modules_nutuiUni_components__utils_props.truthProp
|
||||
};
|
||||
const watermarkEmits = {
|
||||
[uni_modules_nutuiUni_components__constants_event.CLICK_EVENT]: (val) => val instanceof Object
|
||||
};
|
||||
const componentName = `${uni_modules_nutuiUni_components__constants_prefix.PREFIX}-watermark`;
|
||||
const __default__ = common_vendor.defineComponent({
|
||||
name: componentName,
|
||||
options: {
|
||||
virtualHost: true,
|
||||
addGlobalClass: true,
|
||||
styleIsolation: "shared"
|
||||
}
|
||||
});
|
||||
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
|
||||
...__default__,
|
||||
props: watermarkProps,
|
||||
emits: watermarkEmits,
|
||||
setup(__props) {
|
||||
const props = __props;
|
||||
const state = common_vendor.reactive({
|
||||
base64Url: ""
|
||||
});
|
||||
const {
|
||||
zIndex,
|
||||
gapX,
|
||||
gapY,
|
||||
width,
|
||||
height,
|
||||
rotate,
|
||||
image,
|
||||
imageWidth,
|
||||
imageHeight,
|
||||
content,
|
||||
fontStyle,
|
||||
fontWeight,
|
||||
fontColor,
|
||||
fontSize,
|
||||
fontFamily
|
||||
} = common_vendor.toRefs(props);
|
||||
async function init() {
|
||||
let ratio = 1;
|
||||
common_vendor.index.getSystemInfo({
|
||||
success(res) {
|
||||
ratio = res.pixelRatio;
|
||||
}
|
||||
});
|
||||
const canvasWidth = `${(gapX.value + width.value) * ratio}`;
|
||||
const canvasHeight = `${(gapY.value + height.value) * ratio}`;
|
||||
const markWidth = width.value * ratio;
|
||||
const markHeight = height.value * ratio;
|
||||
const canvas = common_vendor.index.createOffscreenCanvas({
|
||||
type: "2d",
|
||||
width: Number(canvasWidth),
|
||||
height: Number(canvasHeight)
|
||||
});
|
||||
const ctx = canvas.getContext("2d");
|
||||
if (ctx) {
|
||||
if (image == null ? void 0 : image.value) {
|
||||
const img = canvas.createImage();
|
||||
dealWithImage(ctx, img, ratio, ctx.canvas, markWidth, markHeight);
|
||||
} else if (content == null ? void 0 : content.value) {
|
||||
dealWithText(ctx, ratio, ctx.canvas, markWidth, markHeight);
|
||||
}
|
||||
} else {
|
||||
throw new Error("当前环境不支持Canvas");
|
||||
}
|
||||
}
|
||||
function dealWithImage(ctx, img, ratio, canvas, markWidth, markHeight) {
|
||||
ctx.translate(markWidth / 2, markHeight / 2);
|
||||
ctx.rotate(Math.PI / 180 * Number(rotate.value));
|
||||
img.crossOrigin = "anonymous";
|
||||
img.referrerPolicy = "no-referrer";
|
||||
img.src = image.value;
|
||||
img.onload = () => {
|
||||
ctx.drawImage(
|
||||
img,
|
||||
-imageWidth.value * ratio / 2,
|
||||
-imageHeight.value * ratio / 2,
|
||||
imageWidth.value * ratio,
|
||||
imageHeight.value * ratio
|
||||
);
|
||||
ctx.restore();
|
||||
state.base64Url = canvas.toDataURL();
|
||||
};
|
||||
}
|
||||
function dealWithText(ctx, ratio, canvas, markWidth, markHeight) {
|
||||
var _a;
|
||||
ctx.textBaseline = "middle";
|
||||
ctx.textAlign = "center";
|
||||
ctx.translate(markWidth / 2, markHeight / 2);
|
||||
ctx.rotate(Math.PI / 180 * Number(rotate.value));
|
||||
const markSize = Number(fontSize.value) * ratio;
|
||||
ctx.font = `${fontStyle.value} normal ${fontWeight.value} ${markSize}px/${markHeight}px ${fontFamily.value}`;
|
||||
ctx.fillStyle = fontColor.value;
|
||||
if (Array.isArray(content.value)) {
|
||||
(_a = content.value) == null ? void 0 : _a.forEach((item, index) => {
|
||||
ctx.fillText(item, 0, (index - 1) * markSize);
|
||||
});
|
||||
} else {
|
||||
ctx.fillText(content.value, 0, 0);
|
||||
}
|
||||
ctx.restore();
|
||||
state.base64Url = canvas.toDataURL();
|
||||
}
|
||||
init();
|
||||
common_vendor.watch(
|
||||
() => [
|
||||
zIndex.value,
|
||||
gapX.value,
|
||||
gapY.value,
|
||||
width.value,
|
||||
height.value,
|
||||
rotate.value,
|
||||
image == null ? void 0 : image.value,
|
||||
imageWidth.value,
|
||||
imageHeight.value,
|
||||
content == null ? void 0 : content.value,
|
||||
fontStyle.value,
|
||||
fontWeight.value,
|
||||
fontColor.value,
|
||||
fontSize.value,
|
||||
fontFamily.value
|
||||
],
|
||||
() => {
|
||||
init();
|
||||
}
|
||||
);
|
||||
const classes = common_vendor.computed(() => {
|
||||
return uni_modules_nutuiUni_components__utils_style.getMainClass(props, componentName, {
|
||||
[`${componentName}-full-page`]: props.fullPage
|
||||
});
|
||||
});
|
||||
const styles = common_vendor.computed(() => {
|
||||
return uni_modules_nutuiUni_components__utils_style.getMainStyle(props, {
|
||||
zIndex: props.zIndex,
|
||||
backgroundSize: `${props.gapX + props.width}px`,
|
||||
backgroundImage: `url('${state.base64Url}')`
|
||||
});
|
||||
});
|
||||
return (_ctx, _cache) => {
|
||||
return {
|
||||
a: common_vendor.n(classes.value),
|
||||
b: common_vendor.s(styles.value)
|
||||
};
|
||||
};
|
||||
}
|
||||
});
|
||||
wx.createComponent(_sfc_main);
|
||||
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/uni_modules/nutui-uni/components/watermark/watermark.js.map
|
||||
4
unpackage/dist/dev/mp-weixin/uni_modules/nutui-uni/components/watermark/watermark.json
vendored
Normal file
4
unpackage/dist/dev/mp-weixin/uni_modules/nutui-uni/components/watermark/watermark.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"component": true,
|
||||
"usingComponents": {}
|
||||
}
|
||||
1
unpackage/dist/dev/mp-weixin/uni_modules/nutui-uni/components/watermark/watermark.wxml
vendored
Normal file
1
unpackage/dist/dev/mp-weixin/uni_modules/nutui-uni/components/watermark/watermark.wxml
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<view class="{{a}}" style="{{b}}"/>
|
||||
63
unpackage/dist/dev/mp-weixin/uni_modules/nutui-uni/components/watermark/watermark.wxss
vendored
Normal file
63
unpackage/dist/dev/mp-weixin/uni_modules/nutui-uni/components/watermark/watermark.wxss
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* 这里是uni-app内置的常用样式变量
|
||||
*
|
||||
* uni-app 官方扩展插件及插件市场(https://ext.dcloud.net.cn)上很多三方插件均使用了这些样式变量
|
||||
* 如果你是插件开发者,建议你使用scss预处理,并在插件代码中直接使用这些变量(无需 import 这个文件),方便用户通过搭积木的方式开发整体风格一致的App
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* 如果你是App开发者(插件使用者),你可以通过修改这些变量来定制自己的插件主题,实现自定义主题功能
|
||||
*
|
||||
* 如果你的项目同样使用了scss预处理,你也可以直接在你的 scss 代码中使用如下变量,同时无需 import 这个文件
|
||||
*/
|
||||
/* 颜色变量 */
|
||||
/* 行为相关颜色 */
|
||||
/* 文字基本颜色 */
|
||||
/* 背景颜色 */
|
||||
/* 边框颜色 */
|
||||
/* 尺寸变量 */
|
||||
/* 文字尺寸 */
|
||||
/* 图片尺寸 */
|
||||
/* Border Radius */
|
||||
/* 水平间距 */
|
||||
/* 垂直间距 */
|
||||
/* 透明度 */
|
||||
/* 文章场景相关 */
|
||||
/**
|
||||
* 这里是uni-app内置的常用样式变量
|
||||
*
|
||||
* uni-app 官方扩展插件及插件市场(https://ext.dcloud.net.cn)上很多三方插件均使用了这些样式变量
|
||||
* 如果你是插件开发者,建议你使用scss预处理,并在插件代码中直接使用这些变量(无需 import 这个文件),方便用户通过搭积木的方式开发整体风格一致的App
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* 如果你是App开发者(插件使用者),你可以通过修改这些变量来定制自己的插件主题,实现自定义主题功能
|
||||
*
|
||||
* 如果你的项目同样使用了scss预处理,你也可以直接在你的 scss 代码中使用如下变量,同时无需 import 这个文件
|
||||
*/
|
||||
/* 颜色变量 */
|
||||
/* 行为相关颜色 */
|
||||
/* 文字基本颜色 */
|
||||
/* 背景颜色 */
|
||||
/* 边框颜色 */
|
||||
/* 尺寸变量 */
|
||||
/* 文字尺寸 */
|
||||
/* 图片尺寸 */
|
||||
/* Border Radius */
|
||||
/* 水平间距 */
|
||||
/* 垂直间距 */
|
||||
/* 透明度 */
|
||||
/* 文章场景相关 */
|
||||
.nut-watermark {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
z-index: var(--nut-watermark-z-index, 2000);
|
||||
pointer-events: none;
|
||||
background-repeat: repeat;
|
||||
}
|
||||
.nut-watermark-full-page {
|
||||
position: fixed;
|
||||
}
|
||||
Reference in New Issue
Block a user