@tplc/wot 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/common/AbortablePromise.ts +36 -0
- package/components/common/abstracts/_config.scss +7 -0
- package/components/common/abstracts/_function.scss +76 -0
- package/components/common/abstracts/_mixin.scss +339 -0
- package/components/common/abstracts/variable.scss +1346 -0
- package/components/common/base64.ts +30 -0
- package/components/common/canvasHelper.ts +49 -0
- package/components/common/clickoutside.ts +34 -0
- package/components/common/dayjs.ts +157 -0
- package/components/common/event.ts +8 -0
- package/components/common/props.ts +51 -0
- package/components/common/util.ts +751 -0
- package/components/composables/useCell.ts +13 -0
- package/components/composables/useChildren.ts +122 -0
- package/components/composables/useCountDown.ts +138 -0
- package/components/composables/useLockScroll.ts +39 -0
- package/components/composables/useParent.ts +41 -0
- package/components/composables/usePopover.ts +193 -0
- package/components/composables/useQueue.ts +52 -0
- package/components/composables/useRaf.ts +37 -0
- package/components/composables/useTouch.ts +44 -0
- package/components/composables/useTranslate.ts +22 -0
- package/components/wd-action-sheet/index.scss +204 -0
- package/components/wd-action-sheet/types.ts +128 -0
- package/components/wd-action-sheet/wd-action-sheet.vue +174 -0
- package/components/wd-backtop/index.scss +25 -0
- package/components/wd-backtop/types.ts +37 -0
- package/components/wd-backtop/wd-backtop.vue +48 -0
- package/components/wd-badge/index.scss +59 -0
- package/components/wd-badge/types.ts +53 -0
- package/components/wd-badge/wd-badge.vue +69 -0
- package/components/wd-button/index.scss +340 -0
- package/components/wd-button/types.ts +112 -0
- package/components/wd-button/wd-button.vue +176 -0
- package/components/wd-calendar/index.scss +244 -0
- package/components/wd-calendar/types.ts +235 -0
- package/components/wd-calendar/wd-calendar.vue +456 -0
- package/components/wd-calendar-view/index.scss +9 -0
- package/components/wd-calendar-view/month/index.scss +151 -0
- package/components/wd-calendar-view/month/month.vue +391 -0
- package/components/wd-calendar-view/month/types.ts +19 -0
- package/components/wd-calendar-view/monthPanel/index.scss +89 -0
- package/components/wd-calendar-view/monthPanel/month-panel.vue +388 -0
- package/components/wd-calendar-view/monthPanel/types.ts +48 -0
- package/components/wd-calendar-view/types.ts +134 -0
- package/components/wd-calendar-view/utils.ts +451 -0
- package/components/wd-calendar-view/wd-calendar-view.vue +111 -0
- package/components/wd-calendar-view/year/index.scss +148 -0
- package/components/wd-calendar-view/year/types.ts +19 -0
- package/components/wd-calendar-view/year/year.vue +220 -0
- package/components/wd-calendar-view/yearPanel/index.scss +24 -0
- package/components/wd-calendar-view/yearPanel/types.ts +38 -0
- package/components/wd-calendar-view/yearPanel/year-panel.vue +140 -0
- package/components/wd-card/index.scss +70 -0
- package/components/wd-card/types.ts +30 -0
- package/components/wd-card/wd-card.vue +40 -0
- package/components/wd-cell/index.scss +189 -0
- package/components/wd-cell/types.ts +96 -0
- package/components/wd-cell/wd-cell.vue +135 -0
- package/components/wd-cell-group/index.scss +55 -0
- package/components/wd-cell-group/types.ts +41 -0
- package/components/wd-cell-group/wd-cell-group.vue +45 -0
- package/components/wd-checkbox/index.scss +285 -0
- package/components/wd-checkbox/types.ts +68 -0
- package/components/wd-checkbox/wd-checkbox.vue +185 -0
- package/components/wd-checkbox-group/index.scss +20 -0
- package/components/wd-checkbox-group/types.ts +59 -0
- package/components/wd-checkbox-group/wd-checkbox-group.vue +103 -0
- package/components/wd-circle/index.scss +18 -0
- package/components/wd-circle/types.ts +54 -0
- package/components/wd-circle/wd-circle.vue +318 -0
- package/components/wd-col/index.scss +19 -0
- package/components/wd-col/types.ts +15 -0
- package/components/wd-col/wd-col.vue +91 -0
- package/components/wd-col-picker/index.scss +241 -0
- package/components/wd-col-picker/types.ts +170 -0
- package/components/wd-col-picker/wd-col-picker.vue +550 -0
- package/components/wd-collapse/index.scss +55 -0
- package/components/wd-collapse/types.ts +63 -0
- package/components/wd-collapse/wd-collapse.vue +160 -0
- package/components/wd-collapse-item/index.scss +79 -0
- package/components/wd-collapse-item/types.ts +36 -0
- package/components/wd-collapse-item/wd-collapse-item.vue +182 -0
- package/components/wd-config-provider/types.ts +1023 -0
- package/components/wd-config-provider/wd-config-provider.vue +82 -0
- package/components/wd-count-down/index.scss +14 -0
- package/components/wd-count-down/types.ts +41 -0
- package/components/wd-count-down/utils.ts +52 -0
- package/components/wd-count-down/wd-count-down.vue +60 -0
- package/components/wd-count-to/index.scss +6 -0
- package/components/wd-count-to/types.ts +110 -0
- package/components/wd-count-to/wd-count-to.vue +134 -0
- package/components/wd-curtain/index.scss +80 -0
- package/components/wd-curtain/types.ts +45 -0
- package/components/wd-curtain/wd-curtain.vue +174 -0
- package/components/wd-datetime-picker/index.scss +243 -0
- package/components/wd-datetime-picker/types.ts +225 -0
- package/components/wd-datetime-picker/wd-datetime-picker.vue +827 -0
- package/components/wd-datetime-picker-view/index.scss +0 -0
- package/components/wd-datetime-picker-view/types.ts +137 -0
- package/components/wd-datetime-picker-view/wd-datetime-picker-view.vue +514 -0
- package/components/wd-divider/index.scss +32 -0
- package/components/wd-divider/types.ts +12 -0
- package/components/wd-divider/wd-divider.vue +29 -0
- package/components/wd-drop-menu/index.scss +89 -0
- package/components/wd-drop-menu/types.ts +38 -0
- package/components/wd-drop-menu/wd-drop-menu.vue +128 -0
- package/components/wd-drop-menu-item/index.scss +66 -0
- package/components/wd-drop-menu-item/types.ts +78 -0
- package/components/wd-drop-menu-item/wd-drop-menu-item.vue +230 -0
- package/components/wd-fab/index.scss +115 -0
- package/components/wd-fab/types.ts +61 -0
- package/components/wd-fab/wd-fab.vue +257 -0
- package/components/wd-form/index.scss +10 -0
- package/components/wd-form/types.ts +93 -0
- package/components/wd-form/wd-form.vue +185 -0
- package/components/wd-form-item/index.scss +17 -0
- package/components/wd-form-item/types.ts +22 -0
- package/components/wd-form-item/wd-form-item.vue +65 -0
- package/components/wd-gap/index.scss +9 -0
- package/components/wd-gap/types.ts +23 -0
- package/components/wd-gap/wd-gap.vue +39 -0
- package/components/wd-grid/index.scss +9 -0
- package/components/wd-grid/types.ts +54 -0
- package/components/wd-grid/wd-grid.vue +107 -0
- package/components/wd-grid-item/index.scss +137 -0
- package/components/wd-grid-item/types.ts +74 -0
- package/components/wd-grid-item/wd-grid-item.vue +181 -0
- package/components/wd-icon/index.scss +1222 -0
- package/components/wd-icon/types.ts +21 -0
- package/components/wd-icon/wd-icon.vue +53 -0
- package/components/wd-icon/wd-icons.ttf +0 -0
- package/components/wd-img/index.scss +19 -0
- package/components/wd-img/types.ts +53 -0
- package/components/wd-img/wd-img.vue +76 -0
- package/components/wd-img-cropper/index.scss +227 -0
- package/components/wd-img-cropper/types.ts +87 -0
- package/components/wd-img-cropper/wd-img-cropper.vue +659 -0
- package/components/wd-index-anchor/index.scss +34 -0
- package/components/wd-index-anchor/type.ts +9 -0
- package/components/wd-index-anchor/wd-index-anchor.vue +57 -0
- package/components/wd-index-bar/index.scss +39 -0
- package/components/wd-index-bar/type.ts +28 -0
- package/components/wd-index-bar/wd-index-bar.vue +158 -0
- package/components/wd-input/index.scss +326 -0
- package/components/wd-input/types.ts +182 -0
- package/components/wd-input/wd-input.vue +327 -0
- package/components/wd-input-number/index.scss +132 -0
- package/components/wd-input-number/types.ts +78 -0
- package/components/wd-input-number/wd-input-number.vue +221 -0
- package/components/wd-loading/index.scss +34 -0
- package/components/wd-loading/types.ts +31 -0
- package/components/wd-loading/wd-loading.vue +90 -0
- package/components/wd-loadmore/index.scss +39 -0
- package/components/wd-loadmore/types.ts +24 -0
- package/components/wd-loadmore/wd-loadmore.vue +53 -0
- package/components/wd-message-box/index.scss +121 -0
- package/components/wd-message-box/index.ts +95 -0
- package/components/wd-message-box/types.ts +116 -0
- package/components/wd-message-box/wd-message-box.vue +326 -0
- package/components/wd-navbar/index.scss +103 -0
- package/components/wd-navbar/types.ts +52 -0
- package/components/wd-navbar/wd-navbar.vue +142 -0
- package/components/wd-navbar-capsule/index.scss +65 -0
- package/components/wd-navbar-capsule/types.ts +0 -0
- package/components/wd-navbar-capsule/wd-navbar-capsule.vue +31 -0
- package/components/wd-notice-bar/index.scss +86 -0
- package/components/wd-notice-bar/types.ts +56 -0
- package/components/wd-notice-bar/wd-notice-bar.vue +223 -0
- package/components/wd-notify/index.scss +34 -0
- package/components/wd-notify/index.ts +59 -0
- package/components/wd-notify/types.ts +62 -0
- package/components/wd-notify/wd-notify.vue +83 -0
- package/components/wd-number-keyboard/index.scss +78 -0
- package/components/wd-number-keyboard/key/index.scss +79 -0
- package/components/wd-number-keyboard/key/index.vue +76 -0
- package/components/wd-number-keyboard/key/types.ts +11 -0
- package/components/wd-number-keyboard/types.ts +79 -0
- package/components/wd-number-keyboard/wd-number-keyboard.vue +173 -0
- package/components/wd-overlay/index.scss +17 -0
- package/components/wd-overlay/types.ts +25 -0
- package/components/wd-overlay/wd-overlay.vue +46 -0
- package/components/wd-pagination/index.scss +57 -0
- package/components/wd-pagination/types.ts +41 -0
- package/components/wd-pagination/wd-pagination.vue +121 -0
- package/components/wd-password-input/index.scss +123 -0
- package/components/wd-password-input/types.ts +48 -0
- package/components/wd-password-input/wd-password-input.vue +58 -0
- package/components/wd-picker/index.scss +216 -0
- package/components/wd-picker/types.ts +186 -0
- package/components/wd-picker/wd-picker.vue +409 -0
- package/components/wd-picker-view/index.scss +91 -0
- package/components/wd-picker-view/types.ts +162 -0
- package/components/wd-picker-view/wd-picker-view.vue +361 -0
- package/components/wd-popover/index.scss +123 -0
- package/components/wd-popover/types.ts +69 -0
- package/components/wd-popover/wd-popover.vue +216 -0
- package/components/wd-popup/index.scss +112 -0
- package/components/wd-popup/types.ts +68 -0
- package/components/wd-popup/wd-popup.vue +227 -0
- package/components/wd-progress/index.scss +62 -0
- package/components/wd-progress/types.ts +40 -0
- package/components/wd-progress/wd-progress.vue +201 -0
- package/components/wd-radio/index.scss +300 -0
- package/components/wd-radio/types.ts +42 -0
- package/components/wd-radio/wd-radio.vue +136 -0
- package/components/wd-radio-group/index.scss +23 -0
- package/components/wd-radio-group/types.ts +36 -0
- package/components/wd-radio-group/wd-radio-group.vue +54 -0
- package/components/wd-rate/index.scss +24 -0
- package/components/wd-rate/types.ts +91 -0
- package/components/wd-rate/wd-rate.vue +131 -0
- package/components/wd-resize/index.scss +26 -0
- package/components/wd-resize/types.ts +6 -0
- package/components/wd-resize/wd-resize.vue +155 -0
- package/components/wd-row/index.scss +10 -0
- package/components/wd-row/types.ts +16 -0
- package/components/wd-row/wd-row.vue +63 -0
- package/components/wd-search/index.scss +148 -0
- package/components/wd-search/types.ts +83 -0
- package/components/wd-search/wd-search.vue +237 -0
- package/components/wd-segmented/index.scss +97 -0
- package/components/wd-segmented/types.ts +68 -0
- package/components/wd-segmented/wd-segmented.vue +143 -0
- package/components/wd-select-picker/index.scss +177 -0
- package/components/wd-select-picker/types.ts +116 -0
- package/components/wd-select-picker/wd-select-picker.vue +486 -0
- package/components/wd-sidebar/index.scss +25 -0
- package/components/wd-sidebar/types.ts +28 -0
- package/components/wd-sidebar/wd-sidebar.vue +41 -0
- package/components/wd-sidebar-item/index.scss +93 -0
- package/components/wd-sidebar-item/types.ts +31 -0
- package/components/wd-sidebar-item/wd-sidebar-item.vue +114 -0
- package/components/wd-skeleton/index.scss +101 -0
- package/components/wd-skeleton/index.ts +1 -0
- package/components/wd-skeleton/types.ts +69 -0
- package/components/wd-skeleton/wd-skeleton.vue +135 -0
- package/components/wd-slider/index.scss +91 -0
- package/components/wd-slider/types.ts +104 -0
- package/components/wd-slider/wd-slider.vue +377 -0
- package/components/wd-sort-button/index.scss +86 -0
- package/components/wd-sort-button/types.ts +43 -0
- package/components/wd-sort-button/wd-sort-button.vue +76 -0
- package/components/wd-status-tip/index.scss +37 -0
- package/components/wd-status-tip/types.ts +59 -0
- package/components/wd-status-tip/wd-status-tip.vue +94 -0
- package/components/wd-step/index.scss +236 -0
- package/components/wd-step/types.ts +33 -0
- package/components/wd-step/wd-step.vue +151 -0
- package/components/wd-steps/index.scss +10 -0
- package/components/wd-steps/types.ts +59 -0
- package/components/wd-steps/wd-steps.vue +37 -0
- package/components/wd-sticky/index.scss +9 -0
- package/components/wd-sticky/types.ts +13 -0
- package/components/wd-sticky/wd-sticky.vue +190 -0
- package/components/wd-sticky-box/index.scss +6 -0
- package/components/wd-sticky-box/types.ts +20 -0
- package/components/wd-sticky-box/wd-sticky-box.vue +154 -0
- package/components/wd-swipe-action/index.scss +22 -0
- package/components/wd-swipe-action/types.ts +43 -0
- package/components/wd-swipe-action/wd-swipe-action.vue +307 -0
- package/components/wd-swiper/index.scss +23 -0
- package/components/wd-swiper/types.ts +189 -0
- package/components/wd-swiper/wd-swiper.vue +202 -0
- package/components/wd-swiper-nav/index.scss +153 -0
- package/components/wd-swiper-nav/types.ts +42 -0
- package/components/wd-swiper-nav/wd-swiper-nav.vue +37 -0
- package/components/wd-switch/index.scss +58 -0
- package/components/wd-switch/types.ts +56 -0
- package/components/wd-switch/wd-switch.vue +83 -0
- package/components/wd-tab/index.scss +8 -0
- package/components/wd-tab/types.ts +20 -0
- package/components/wd-tab/wd-tab.vue +100 -0
- package/components/wd-tabbar/index.scss +57 -0
- package/components/wd-tabbar/types.ts +88 -0
- package/components/wd-tabbar/wd-tabbar.vue +104 -0
- package/components/wd-tabbar-item/index.scss +52 -0
- package/components/wd-tabbar-item/types.ts +51 -0
- package/components/wd-tabbar-item/wd-tabbar-item.vue +101 -0
- package/components/wd-table/index.scss +132 -0
- package/components/wd-table/types.ts +69 -0
- package/components/wd-table/wd-table.vue +255 -0
- package/components/wd-table-col/index.scss +44 -0
- package/components/wd-table-col/types.ts +54 -0
- package/components/wd-table-col/wd-table-col.vue +149 -0
- package/components/wd-tabs/index.scss +280 -0
- package/components/wd-tabs/types.ts +71 -0
- package/components/wd-tabs/wd-tabs.vue +528 -0
- package/components/wd-tag/index.scss +115 -0
- package/components/wd-tag/types.ts +81 -0
- package/components/wd-tag/wd-tag.vue +154 -0
- package/components/wd-text/index.scss +34 -0
- package/components/wd-text/types.ts +98 -0
- package/components/wd-text/wd-text.vue +138 -0
- package/components/wd-textarea/index.scss +343 -0
- package/components/wd-textarea/types.ts +298 -0
- package/components/wd-textarea/wd-textarea.vue +303 -0
- package/components/wd-toast/index.scss +66 -0
- package/components/wd-toast/index.ts +109 -0
- package/components/wd-toast/types.ts +76 -0
- package/components/wd-toast/wd-toast.vue +212 -0
- package/components/wd-tooltip/index.scss +61 -0
- package/components/wd-tooltip/types.ts +102 -0
- package/components/wd-tooltip/wd-tooltip.vue +167 -0
- package/components/wd-transition/index.scss +91 -0
- package/components/wd-transition/types.ts +89 -0
- package/components/wd-transition/wd-transition.vue +221 -0
- package/components/wd-upload/index.scss +173 -0
- package/components/wd-upload/types.ts +378 -0
- package/components/wd-upload/utils.ts +152 -0
- package/components/wd-upload/wd-upload.vue +737 -0
- package/components/wd-video-preview/index.scss +34 -0
- package/components/wd-video-preview/types.ts +32 -0
- package/components/wd-video-preview/wd-video-preview.vue +76 -0
- package/components/wd-watermark/index.scss +18 -0
- package/components/wd-watermark/types.ts +82 -0
- package/components/wd-watermark/wd-watermark.vue +592 -0
- package/components/wot-design-uni/wot-design-uni.vue +14 -0
- package/global.d.ts +108 -0
- package/index.ts +30 -0
- package/locale/index.ts +41 -0
- package/locale/lang/en-US.ts +128 -0
- package/locale/lang/th-TH.ts +127 -0
- package/locale/lang/vi-VN.ts +89 -0
- package/locale/lang/zh-CN.ts +127 -0
- package/locale/lang/zh-HK.ts +84 -0
- package/locale/lang/zh-TW.ts +84 -0
- package/package.json +20 -0
|
@@ -0,0 +1,592 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
* @Author: weisheng
|
|
3
|
+
* @Date: 2023-04-05 21:32:56
|
|
4
|
+
* @LastEditTime: 2024-04-01 20:40:34
|
|
5
|
+
* @LastEditors: weisheng
|
|
6
|
+
* @Description: 水印组件
|
|
7
|
+
* @FilePath: /wot-design-uni/src/uni_modules/wot-design-uni/components/wd-watermark/wd-watermark.vue
|
|
8
|
+
* 记得注释
|
|
9
|
+
-->
|
|
10
|
+
<template>
|
|
11
|
+
<view :class="rootClass" :style="rootStyle">
|
|
12
|
+
<canvas
|
|
13
|
+
v-if="!canvasOffScreenable && showCanvas"
|
|
14
|
+
type="2d"
|
|
15
|
+
:style="{ height: canvasHeight + 'px', width: canvasWidth + 'px', visibility: 'hidden' }"
|
|
16
|
+
:canvas-id="canvasId"
|
|
17
|
+
:id="canvasId"
|
|
18
|
+
/>
|
|
19
|
+
</view>
|
|
20
|
+
</template>
|
|
21
|
+
|
|
22
|
+
<script lang="ts">
|
|
23
|
+
export default {
|
|
24
|
+
name: 'wd-watermark',
|
|
25
|
+
options: {
|
|
26
|
+
addGlobalClass: true,
|
|
27
|
+
virtualHost: true,
|
|
28
|
+
styleIsolation: 'shared',
|
|
29
|
+
},
|
|
30
|
+
}
|
|
31
|
+
</script>
|
|
32
|
+
|
|
33
|
+
<script lang="ts" setup>
|
|
34
|
+
import { computed, onMounted, ref, watch, nextTick } from 'vue'
|
|
35
|
+
import { addUnit, buildUrlWithParams, isBase64Image, objToStyle, uuid } from '../common/util'
|
|
36
|
+
import { watermarkProps } from './types'
|
|
37
|
+
|
|
38
|
+
const props = defineProps(watermarkProps)
|
|
39
|
+
|
|
40
|
+
watch(
|
|
41
|
+
() => props,
|
|
42
|
+
() => {
|
|
43
|
+
doReset()
|
|
44
|
+
},
|
|
45
|
+
{ deep: true },
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
const canvasId = ref<string>(`water${uuid()}`) // canvas 组件的唯一标识符
|
|
49
|
+
const waterMarkUrl = ref<string>('') // canvas生成base64水印
|
|
50
|
+
const canvasOffScreenable = ref<boolean>(
|
|
51
|
+
uni.canIUse('createOffscreenCanvas') && Boolean(uni.createOffscreenCanvas),
|
|
52
|
+
) // 是否可以使用离屏canvas
|
|
53
|
+
const pixelRatio = ref<number>(uni.getSystemInfoSync().pixelRatio) // 像素比
|
|
54
|
+
const canvasHeight = ref<number>((props.height + props.gutterY) * pixelRatio.value) // canvas画布高度
|
|
55
|
+
const canvasWidth = ref<number>((props.width + props.gutterX) * pixelRatio.value) // canvas画布宽度
|
|
56
|
+
const showCanvas = ref<boolean>(true) // 是否展示canvas
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 水印css类
|
|
60
|
+
*/
|
|
61
|
+
const rootClass = computed(() => {
|
|
62
|
+
let classess: string = 'wd-watermark'
|
|
63
|
+
if (props.fullScreen) {
|
|
64
|
+
classess = `${classess} is-fullscreen`
|
|
65
|
+
}
|
|
66
|
+
return `${classess} ${props.customClass}`
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* 水印样式
|
|
71
|
+
*/
|
|
72
|
+
const rootStyle = computed(() => {
|
|
73
|
+
const style: Record<string, string | number> = {
|
|
74
|
+
opacity: props.opacity,
|
|
75
|
+
backgroundSize: addUnit(props.width + props.gutterX),
|
|
76
|
+
}
|
|
77
|
+
if (waterMarkUrl.value) {
|
|
78
|
+
style.backgroundImage = `url('${waterMarkUrl.value}')`
|
|
79
|
+
}
|
|
80
|
+
return `${objToStyle(style)};${props.customStyle}`
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
onMounted(() => {
|
|
84
|
+
doInit()
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
function doReset() {
|
|
88
|
+
showCanvas.value = true
|
|
89
|
+
canvasHeight.value = (props.height + props.gutterY) * pixelRatio.value
|
|
90
|
+
canvasWidth.value = (props.width + props.gutterX) * pixelRatio.value
|
|
91
|
+
nextTick(() => {
|
|
92
|
+
doInit()
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function doInit() {
|
|
97
|
+
// #ifdef H5
|
|
98
|
+
// h5使用document.createElement创建canvas,不用展示canvas标签
|
|
99
|
+
showCanvas.value = false
|
|
100
|
+
// #endif
|
|
101
|
+
const {
|
|
102
|
+
width,
|
|
103
|
+
height,
|
|
104
|
+
color,
|
|
105
|
+
size,
|
|
106
|
+
fontStyle,
|
|
107
|
+
fontWeight,
|
|
108
|
+
fontFamily,
|
|
109
|
+
content,
|
|
110
|
+
rotate,
|
|
111
|
+
gutterX,
|
|
112
|
+
gutterY,
|
|
113
|
+
image,
|
|
114
|
+
imageHeight,
|
|
115
|
+
imageWidth,
|
|
116
|
+
} = props
|
|
117
|
+
|
|
118
|
+
// 创建水印
|
|
119
|
+
createWaterMark(
|
|
120
|
+
width,
|
|
121
|
+
height,
|
|
122
|
+
color,
|
|
123
|
+
size,
|
|
124
|
+
fontStyle,
|
|
125
|
+
fontWeight,
|
|
126
|
+
fontFamily,
|
|
127
|
+
content,
|
|
128
|
+
rotate,
|
|
129
|
+
gutterX,
|
|
130
|
+
gutterY,
|
|
131
|
+
image,
|
|
132
|
+
imageHeight,
|
|
133
|
+
imageWidth,
|
|
134
|
+
)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* 创建水印图片
|
|
139
|
+
* @param width canvas宽度
|
|
140
|
+
* @param height canvas高度
|
|
141
|
+
* @param color canvas字体颜色
|
|
142
|
+
* @param size canvas字体大小
|
|
143
|
+
* @param fontStyle canvas字体样式
|
|
144
|
+
* @param fontWeight canvas字体字重
|
|
145
|
+
* @param fontFamily canvas字体系列
|
|
146
|
+
* @param content canvas内容
|
|
147
|
+
* @param rotate 倾斜角度
|
|
148
|
+
* @param gutterX X轴间距
|
|
149
|
+
* @param gutterY Y轴间距
|
|
150
|
+
* @param image canvas图片
|
|
151
|
+
* @param imageHeight canvas图片高度
|
|
152
|
+
* @param imageWidth canvas图片宽度
|
|
153
|
+
*/
|
|
154
|
+
function createWaterMark(
|
|
155
|
+
width: number,
|
|
156
|
+
height: number,
|
|
157
|
+
color: string,
|
|
158
|
+
size: number,
|
|
159
|
+
fontStyle: string,
|
|
160
|
+
fontWeight: number | string,
|
|
161
|
+
fontFamily: string,
|
|
162
|
+
content: string,
|
|
163
|
+
rotate: number,
|
|
164
|
+
gutterX: number,
|
|
165
|
+
gutterY: number,
|
|
166
|
+
image: string,
|
|
167
|
+
imageHeight: number,
|
|
168
|
+
imageWidth: number,
|
|
169
|
+
) {
|
|
170
|
+
const canvasHeight = (height + gutterY) * pixelRatio.value
|
|
171
|
+
const canvasWidth = (width + gutterX) * pixelRatio.value
|
|
172
|
+
const contentWidth = width * pixelRatio.value
|
|
173
|
+
const contentHeight = height * pixelRatio.value
|
|
174
|
+
const fontSize = size * pixelRatio.value
|
|
175
|
+
// #ifndef H5
|
|
176
|
+
if (canvasOffScreenable.value) {
|
|
177
|
+
createOffscreenCanvas(
|
|
178
|
+
canvasHeight,
|
|
179
|
+
canvasWidth,
|
|
180
|
+
contentWidth,
|
|
181
|
+
contentHeight,
|
|
182
|
+
rotate,
|
|
183
|
+
fontSize,
|
|
184
|
+
fontFamily,
|
|
185
|
+
fontStyle,
|
|
186
|
+
fontWeight,
|
|
187
|
+
color,
|
|
188
|
+
content,
|
|
189
|
+
image,
|
|
190
|
+
imageHeight,
|
|
191
|
+
imageWidth,
|
|
192
|
+
)
|
|
193
|
+
} else {
|
|
194
|
+
createCanvas(
|
|
195
|
+
canvasHeight,
|
|
196
|
+
contentWidth,
|
|
197
|
+
rotate,
|
|
198
|
+
fontSize,
|
|
199
|
+
color,
|
|
200
|
+
content,
|
|
201
|
+
image,
|
|
202
|
+
imageHeight,
|
|
203
|
+
imageWidth,
|
|
204
|
+
)
|
|
205
|
+
}
|
|
206
|
+
// #endif
|
|
207
|
+
// #ifdef H5
|
|
208
|
+
createH5Canvas(
|
|
209
|
+
canvasHeight,
|
|
210
|
+
canvasWidth,
|
|
211
|
+
contentWidth,
|
|
212
|
+
contentHeight,
|
|
213
|
+
rotate,
|
|
214
|
+
fontSize,
|
|
215
|
+
fontFamily,
|
|
216
|
+
fontStyle,
|
|
217
|
+
fontWeight,
|
|
218
|
+
color,
|
|
219
|
+
content,
|
|
220
|
+
image,
|
|
221
|
+
imageHeight,
|
|
222
|
+
imageWidth,
|
|
223
|
+
)
|
|
224
|
+
// #endif
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* 创建离屏canvas
|
|
229
|
+
* @param canvasHeight canvas高度
|
|
230
|
+
* @param canvasWidth canvas宽度
|
|
231
|
+
* @param contentWidth 内容宽度
|
|
232
|
+
* @param contentHeight 内容高度
|
|
233
|
+
* @param rotate 内容倾斜角度
|
|
234
|
+
* @param fontSize 字体大小
|
|
235
|
+
* @param fontFamily 字体系列
|
|
236
|
+
* @param fontStyle 字体样式
|
|
237
|
+
* @param fontWeight 字体字重
|
|
238
|
+
* @param color 字体颜色
|
|
239
|
+
* @param content 内容
|
|
240
|
+
* @param image canvas图片
|
|
241
|
+
* @param imageHeight canvas图片高度
|
|
242
|
+
* @param imageWidth canvas图片宽度
|
|
243
|
+
*/
|
|
244
|
+
function createOffscreenCanvas(
|
|
245
|
+
canvasHeight: number,
|
|
246
|
+
canvasWidth: number,
|
|
247
|
+
contentWidth: number,
|
|
248
|
+
contentHeight: number,
|
|
249
|
+
rotate: number,
|
|
250
|
+
fontSize: number,
|
|
251
|
+
fontFamily: string,
|
|
252
|
+
fontStyle: string,
|
|
253
|
+
fontWeight: string | number,
|
|
254
|
+
color: string,
|
|
255
|
+
content: string,
|
|
256
|
+
image: string,
|
|
257
|
+
imageHeight: number,
|
|
258
|
+
imageWidth: number,
|
|
259
|
+
) {
|
|
260
|
+
// 创建离屏canvas
|
|
261
|
+
const canvas: any = uni.createOffscreenCanvas({
|
|
262
|
+
height: canvasHeight,
|
|
263
|
+
width: canvasWidth,
|
|
264
|
+
type: '2d',
|
|
265
|
+
})
|
|
266
|
+
const ctx: any = canvas.getContext('2d')
|
|
267
|
+
if (ctx) {
|
|
268
|
+
if (image) {
|
|
269
|
+
const img = canvas.createImage() as HTMLImageElement
|
|
270
|
+
drawImageOffScreen(
|
|
271
|
+
ctx,
|
|
272
|
+
img,
|
|
273
|
+
image,
|
|
274
|
+
imageHeight,
|
|
275
|
+
imageWidth,
|
|
276
|
+
rotate,
|
|
277
|
+
contentWidth,
|
|
278
|
+
contentHeight,
|
|
279
|
+
canvas,
|
|
280
|
+
)
|
|
281
|
+
} else {
|
|
282
|
+
drawTextOffScreen(
|
|
283
|
+
ctx,
|
|
284
|
+
content,
|
|
285
|
+
contentWidth,
|
|
286
|
+
contentHeight,
|
|
287
|
+
rotate,
|
|
288
|
+
fontSize,
|
|
289
|
+
fontFamily,
|
|
290
|
+
fontStyle,
|
|
291
|
+
fontWeight,
|
|
292
|
+
color,
|
|
293
|
+
canvas,
|
|
294
|
+
)
|
|
295
|
+
}
|
|
296
|
+
} else {
|
|
297
|
+
console.error('无法获取canvas上下文,请确认当前环境是否支持canvas')
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* 非H5创建canvas
|
|
303
|
+
* 不支持创建离屏canvas时调用
|
|
304
|
+
* @param contentHeight 内容高度
|
|
305
|
+
* @param contentWidth 内容宽度
|
|
306
|
+
* @param rotate 内容倾斜角度
|
|
307
|
+
* @param fontSize 字体大小
|
|
308
|
+
* @param color 字体颜色
|
|
309
|
+
* @param content 内容
|
|
310
|
+
* @param image canvas图片
|
|
311
|
+
* @param imageHeight canvas图片高度
|
|
312
|
+
* @param imageWidth canvas图片宽度
|
|
313
|
+
*/
|
|
314
|
+
function createCanvas(
|
|
315
|
+
contentHeight: number,
|
|
316
|
+
contentWidth: number,
|
|
317
|
+
rotate: number,
|
|
318
|
+
fontSize: number,
|
|
319
|
+
color: string,
|
|
320
|
+
content: string,
|
|
321
|
+
image: string,
|
|
322
|
+
imageHeight: number,
|
|
323
|
+
imageWidth: number,
|
|
324
|
+
) {
|
|
325
|
+
const ctx = uni.createCanvasContext(canvasId.value)
|
|
326
|
+
if (ctx) {
|
|
327
|
+
if (image) {
|
|
328
|
+
drawImageOnScreen(ctx, image, imageHeight, imageWidth, rotate, contentWidth, contentHeight)
|
|
329
|
+
} else {
|
|
330
|
+
drawTextOnScreen(ctx, content, contentWidth, rotate, fontSize, color)
|
|
331
|
+
}
|
|
332
|
+
} else {
|
|
333
|
+
console.error('无法获取canvas上下文,请确认当前环境是否支持canvas')
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* h5创建canvas
|
|
339
|
+
* @param canvasHeight canvas高度
|
|
340
|
+
* @param canvasWidth canvas宽度
|
|
341
|
+
* @param contentWidth 水印内容宽度
|
|
342
|
+
* @param contentHeight 水印内容高度
|
|
343
|
+
* @param rotate 水印内容倾斜角度
|
|
344
|
+
* @param fontSize 水印字体大小
|
|
345
|
+
* @param fontFamily 水印字体系列
|
|
346
|
+
* @param fontStyle 水印字体样式
|
|
347
|
+
* @param fontWeight 水印字体字重
|
|
348
|
+
* @param color 水印字体颜色
|
|
349
|
+
* @param content 水印内容
|
|
350
|
+
*/
|
|
351
|
+
function createH5Canvas(
|
|
352
|
+
canvasHeight: number,
|
|
353
|
+
canvasWidth: number,
|
|
354
|
+
contentWidth: number,
|
|
355
|
+
contentHeight: number,
|
|
356
|
+
rotate: number,
|
|
357
|
+
fontSize: number,
|
|
358
|
+
fontFamily: string,
|
|
359
|
+
fontStyle: string,
|
|
360
|
+
fontWeight: string | number,
|
|
361
|
+
color: string,
|
|
362
|
+
content: string,
|
|
363
|
+
image: string,
|
|
364
|
+
imageHeight: number,
|
|
365
|
+
imageWidth: number,
|
|
366
|
+
) {
|
|
367
|
+
const canvas = document.createElement('canvas')
|
|
368
|
+
const ctx = canvas.getContext('2d')
|
|
369
|
+
canvas.setAttribute('width', `${canvasWidth}px`)
|
|
370
|
+
canvas.setAttribute('height', `${canvasHeight}px`)
|
|
371
|
+
if (ctx) {
|
|
372
|
+
if (image) {
|
|
373
|
+
const img = new Image()
|
|
374
|
+
drawImageOffScreen(
|
|
375
|
+
ctx,
|
|
376
|
+
img,
|
|
377
|
+
image,
|
|
378
|
+
imageHeight,
|
|
379
|
+
imageWidth,
|
|
380
|
+
rotate,
|
|
381
|
+
contentWidth,
|
|
382
|
+
contentHeight,
|
|
383
|
+
canvas,
|
|
384
|
+
)
|
|
385
|
+
} else {
|
|
386
|
+
drawTextOffScreen(
|
|
387
|
+
ctx,
|
|
388
|
+
content,
|
|
389
|
+
contentWidth,
|
|
390
|
+
contentHeight,
|
|
391
|
+
rotate,
|
|
392
|
+
fontSize,
|
|
393
|
+
fontFamily,
|
|
394
|
+
fontStyle,
|
|
395
|
+
fontWeight,
|
|
396
|
+
color,
|
|
397
|
+
canvas,
|
|
398
|
+
)
|
|
399
|
+
}
|
|
400
|
+
} else {
|
|
401
|
+
console.error('无法获取canvas上下文,请确认当前环境是否支持canvas')
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* 绘制离屏文字canvas
|
|
407
|
+
* @param ctx canvas上下文
|
|
408
|
+
* @param content 水印内容
|
|
409
|
+
* @param contentWidth 水印宽度
|
|
410
|
+
* @param contentHeight 水印高度
|
|
411
|
+
* @param rotate 水印内容倾斜角度
|
|
412
|
+
* @param fontSize 水印字体大小
|
|
413
|
+
* @param fontFamily 水印字体系列
|
|
414
|
+
* @param fontStyle 水印字体样式
|
|
415
|
+
* @param fontWeight 水印字体字重
|
|
416
|
+
* @param color 水印字体颜色
|
|
417
|
+
* @param canvas canvas实例
|
|
418
|
+
*/
|
|
419
|
+
function drawTextOffScreen(
|
|
420
|
+
ctx: CanvasRenderingContext2D,
|
|
421
|
+
content: string,
|
|
422
|
+
contentWidth: number,
|
|
423
|
+
contentHeight: number,
|
|
424
|
+
rotate: number,
|
|
425
|
+
fontSize: number,
|
|
426
|
+
fontFamily: string,
|
|
427
|
+
fontStyle: string,
|
|
428
|
+
fontWeight: string | number,
|
|
429
|
+
color: string,
|
|
430
|
+
canvas: HTMLCanvasElement,
|
|
431
|
+
) {
|
|
432
|
+
ctx.textBaseline = 'middle'
|
|
433
|
+
ctx.textAlign = 'center'
|
|
434
|
+
ctx.translate(contentWidth / 2, contentWidth / 2)
|
|
435
|
+
ctx.rotate((Math.PI / 180) * rotate)
|
|
436
|
+
ctx.font = `${fontStyle} normal ${fontWeight} ${fontSize}px/${contentHeight}px ${fontFamily}`
|
|
437
|
+
ctx.fillStyle = color
|
|
438
|
+
ctx.fillText(content, 0, 0)
|
|
439
|
+
ctx.restore()
|
|
440
|
+
waterMarkUrl.value = canvas.toDataURL()
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* 绘制在屏文字canvas
|
|
445
|
+
* @param ctx canvas上下文
|
|
446
|
+
* @param content 水印内容
|
|
447
|
+
* @param contentWidth 水印宽度
|
|
448
|
+
* @param rotate 水印内容倾斜角度
|
|
449
|
+
* @param fontSize 水印字体大小
|
|
450
|
+
* @param color 水印字体颜色
|
|
451
|
+
*/
|
|
452
|
+
function drawTextOnScreen(
|
|
453
|
+
ctx: UniApp.CanvasContext,
|
|
454
|
+
content: string,
|
|
455
|
+
contentWidth: number,
|
|
456
|
+
rotate: number,
|
|
457
|
+
fontSize: number,
|
|
458
|
+
color: string,
|
|
459
|
+
) {
|
|
460
|
+
ctx.setTextBaseline('middle')
|
|
461
|
+
ctx.setTextAlign('center')
|
|
462
|
+
ctx.translate(contentWidth / 2, contentWidth / 2)
|
|
463
|
+
ctx.rotate((Math.PI / 180) * rotate)
|
|
464
|
+
ctx.setFillStyle(color)
|
|
465
|
+
ctx.setFontSize(fontSize)
|
|
466
|
+
ctx.fillText(content, 0, 0)
|
|
467
|
+
ctx.restore()
|
|
468
|
+
ctx.draw()
|
|
469
|
+
// #ifdef MP-DINGTALK
|
|
470
|
+
// 钉钉小程序的canvasToTempFilePath接口与其他平台不一样
|
|
471
|
+
;(ctx as any).toTempFilePath({
|
|
472
|
+
success(res: any) {
|
|
473
|
+
showCanvas.value = false
|
|
474
|
+
waterMarkUrl.value = res.filePath
|
|
475
|
+
},
|
|
476
|
+
})
|
|
477
|
+
// #endif
|
|
478
|
+
// #ifndef MP-DINGTALK
|
|
479
|
+
uni.canvasToTempFilePath({
|
|
480
|
+
canvasId: canvasId.value,
|
|
481
|
+
success: (res) => {
|
|
482
|
+
showCanvas.value = false
|
|
483
|
+
waterMarkUrl.value = res.tempFilePath
|
|
484
|
+
},
|
|
485
|
+
})
|
|
486
|
+
// #endif
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* 绘制离屏图片canvas
|
|
491
|
+
* @param ctx canvas上下文
|
|
492
|
+
* @param img 水印图片对象
|
|
493
|
+
* @param image 水印图片地址
|
|
494
|
+
* @param imageHeight 水印图片高度
|
|
495
|
+
* @param imageWidth 水印图片宽度
|
|
496
|
+
* @param rotate 水印内容倾斜角度
|
|
497
|
+
* @param contentWidth 水印宽度
|
|
498
|
+
* @param contentHeight 水印高度
|
|
499
|
+
* @param canvas canvas实例
|
|
500
|
+
*/
|
|
501
|
+
async function drawImageOffScreen(
|
|
502
|
+
ctx: CanvasRenderingContext2D,
|
|
503
|
+
img: HTMLImageElement,
|
|
504
|
+
image: string,
|
|
505
|
+
imageHeight: number,
|
|
506
|
+
imageWidth: number,
|
|
507
|
+
rotate: number,
|
|
508
|
+
contentWidth: number,
|
|
509
|
+
contentHeight: number,
|
|
510
|
+
canvas: HTMLCanvasElement,
|
|
511
|
+
) {
|
|
512
|
+
ctx.translate(contentWidth / 2, contentHeight / 2)
|
|
513
|
+
ctx.rotate((Math.PI / 180) * Number(rotate))
|
|
514
|
+
img.crossOrigin = 'anonymous'
|
|
515
|
+
img.referrerPolicy = 'no-referrer'
|
|
516
|
+
|
|
517
|
+
if (isBase64Image(image)) {
|
|
518
|
+
img.src = image
|
|
519
|
+
} else {
|
|
520
|
+
img.src = buildUrlWithParams(image, {
|
|
521
|
+
timestamp: `${new Date().getTime()}`,
|
|
522
|
+
})
|
|
523
|
+
}
|
|
524
|
+
img.onload = () => {
|
|
525
|
+
ctx.drawImage(
|
|
526
|
+
img,
|
|
527
|
+
(-imageWidth * pixelRatio.value) / 2,
|
|
528
|
+
(-imageHeight * pixelRatio.value) / 2,
|
|
529
|
+
imageWidth * pixelRatio.value,
|
|
530
|
+
imageHeight * pixelRatio.value,
|
|
531
|
+
)
|
|
532
|
+
ctx.restore()
|
|
533
|
+
waterMarkUrl.value = canvas.toDataURL()
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* 绘制在屏图片canvas
|
|
539
|
+
* @param ctx canvas上下文
|
|
540
|
+
* @param image 水印图片地址
|
|
541
|
+
* @param imageHeight 水印图片高度
|
|
542
|
+
* @param imageWidth 水印图片宽度
|
|
543
|
+
* @param rotate 水印内容倾斜角度
|
|
544
|
+
* @param contentWidth 水印宽度
|
|
545
|
+
* @param contentHeight 水印高度
|
|
546
|
+
*/
|
|
547
|
+
function drawImageOnScreen(
|
|
548
|
+
ctx: UniApp.CanvasContext,
|
|
549
|
+
image: string,
|
|
550
|
+
imageHeight: number,
|
|
551
|
+
imageWidth: number,
|
|
552
|
+
rotate: number,
|
|
553
|
+
contentWidth: number,
|
|
554
|
+
contentHeight: number,
|
|
555
|
+
) {
|
|
556
|
+
ctx.translate(contentWidth / 2, contentHeight / 2)
|
|
557
|
+
ctx.rotate((Math.PI / 180) * Number(rotate))
|
|
558
|
+
|
|
559
|
+
ctx.drawImage(
|
|
560
|
+
image,
|
|
561
|
+
(-imageWidth * pixelRatio.value) / 2,
|
|
562
|
+
(-imageHeight * pixelRatio.value) / 2,
|
|
563
|
+
imageWidth * pixelRatio.value,
|
|
564
|
+
imageHeight * pixelRatio.value,
|
|
565
|
+
)
|
|
566
|
+
ctx.restore()
|
|
567
|
+
ctx.draw(false, () => {
|
|
568
|
+
// #ifdef MP-DINGTALK
|
|
569
|
+
// 钉钉小程序的canvasToTempFilePath接口与其他平台不一样
|
|
570
|
+
;(ctx as any).toTempFilePath({
|
|
571
|
+
success(res: any) {
|
|
572
|
+
showCanvas.value = false
|
|
573
|
+
waterMarkUrl.value = res.filePath
|
|
574
|
+
},
|
|
575
|
+
})
|
|
576
|
+
// #endif
|
|
577
|
+
// #ifndef MP-DINGTALK
|
|
578
|
+
uni.canvasToTempFilePath({
|
|
579
|
+
canvasId: canvasId.value,
|
|
580
|
+
success: (res) => {
|
|
581
|
+
showCanvas.value = false
|
|
582
|
+
waterMarkUrl.value = res.tempFilePath
|
|
583
|
+
},
|
|
584
|
+
})
|
|
585
|
+
// #endif
|
|
586
|
+
})
|
|
587
|
+
}
|
|
588
|
+
</script>
|
|
589
|
+
|
|
590
|
+
<style lang="scss" scoped>
|
|
591
|
+
@import './index';
|
|
592
|
+
</style>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
* @Author: weisheng
|
|
3
|
+
* @Date: 2023-07-20 00:34:54
|
|
4
|
+
* @LastEditTime: 2023-07-21 17:52:56
|
|
5
|
+
* @LastEditors: weisheng
|
|
6
|
+
* @Description:
|
|
7
|
+
* @FilePath: \wot-design-uni\src\uni_modules\wot-design-uni\components\wot-design-uni\wot-design-uni.vue
|
|
8
|
+
* 记得注释
|
|
9
|
+
-->
|
|
10
|
+
<template>
|
|
11
|
+
<view></view>
|
|
12
|
+
</template>
|
|
13
|
+
<script></script>
|
|
14
|
+
<style lang="scss" scoped></style>
|