version: v4.4.6

This commit is contained in:
XiaoDaiGua-Ray 2023-12-15 22:26:36 +08:00
parent 8a6f983bf3
commit 45be191112
10 changed files with 70 additions and 60 deletions

View File

@ -1,5 +1,32 @@
# CHANGE LOG # CHANGE LOG
## 4.4.6
## Feats
- `vite` 配置项
- `cdn`
- 移除不能被 `cdn` 引入的包配置
- 移除 `vue-demi` 本地包依赖,仅在 `cdn` 引入。因为某些插件依赖改包
## Fixes
- `hooks` 相关
- `UseDomToImageOptions` 方法
- 修复 `options.imageType` 必填的错误
- 修复该方法在执行失败时,没有正确的返回错误状态与执行错误钩子方法。现在在执行失败或者获取未正确获取到元素的时候,会返回 `Promise.reject` 状态,并且会执行 `createdError` 钩子方法
- 修改 `createdError` 钩子方法回调参数类型
- 修改 `created` 钩子方法回调参数类型
- 修复 `finally` 方法不能正确执行的问题
- `utils` 相关
- `printDom` 方法
- 新增配置项 `base64``true`
- 修改 `printOptions` 类型,剔除 `base64` 属性,因为该配置项始终应该为 `true`,即使你手动配置为 `false`,也会被强制转换为 `true`
- `components` 相关
- `RTable`
- 修复打印的时候,可能会出现颜色不正确的问题
- 现在打印的时候,会将整个表格(包括:表头、表格、表格分页、表格底部区域)全部打印
## 4.4.5 ## 4.4.5
## Feats ## Feats

View File

@ -1,7 +1,7 @@
{ {
"name": "ray-template", "name": "ray-template",
"private": false, "private": false,
"version": "4.4.5", "version": "4.4.6",
"type": "module", "type": "module",
"engines": { "engines": {
"node": "^18.0.0 || >=20.0.0", "node": "^18.0.0 || >=20.0.0",
@ -49,7 +49,6 @@
"pinia-plugin-persistedstate": "^3.2.0", "pinia-plugin-persistedstate": "^3.2.0",
"print-js": "^1.6.0", "print-js": "^1.6.0",
"vue": "^3.3.11", "vue": "^3.3.11",
"vue-demi": "0.14.6",
"vue-hooks-plus": "1.8.5", "vue-hooks-plus": "1.8.5",
"vue-i18n": "^9.8.0", "vue-i18n": "^9.8.0",
"vue-router": "^4.2.5", "vue-router": "^4.2.5",

3
pnpm-lock.yaml generated
View File

@ -56,9 +56,6 @@ dependencies:
vue: vue:
specifier: ^3.3.11 specifier: ^3.3.11
version: 3.3.11(typescript@5.2.2) version: 3.3.11(typescript@5.2.2)
vue-demi:
specifier: 0.14.6
version: 0.14.6(vue@3.3.11)
vue-hooks-plus: vue-hooks-plus:
specifier: 1.8.5 specifier: 1.8.5
version: 1.8.5(vue@3.3.11) version: 1.8.5(vue@3.3.11)

View File

@ -175,7 +175,6 @@ export default defineComponent({
uuidTable, uuidTable,
uuidWrapper, uuidWrapper,
wrapperRef, wrapperRef,
tableRef: rTableInst,
}) })
expose({ expose({
rTableInst, rTableInst,

View File

@ -22,7 +22,7 @@ export default defineComponent({
name: 'TablePrint', name: 'TablePrint',
props, props,
setup(props) { setup(props) {
const { tableRef } = inject<TableProvider>( const { wrapperRef } = inject<TableProvider>(
config.tableKey, config.tableKey,
{} as TableProvider, {} as TableProvider,
) )
@ -41,7 +41,7 @@ export default defineComponent({
printOptions.documentTitle = typeof title === 'string' ? title : '' printOptions.documentTitle = typeof title === 'string' ? title : ''
} }
printDom(tableRef, { printDom(wrapperRef, {
printOptions, printOptions,
domToImageOptions, domToImageOptions,
}) })

View File

@ -17,6 +17,8 @@ import type { BasicTarget, TargetType } from '@/types/modules/vue'
export type ImageType = keyof typeof domToImageMethods export type ImageType = keyof typeof domToImageMethods
export type DomToImageResult = string | Blob | Uint8ClampedArray | undefined
export interface UseDomToImageOptions extends ReDomToImageOptions { export interface UseDomToImageOptions extends ReDomToImageOptions {
/** /**
* *
@ -25,7 +27,7 @@ export interface UseDomToImageOptions extends ReDomToImageOptions {
* *
* @default jpeg * @default jpeg
*/ */
imageType: ImageType imageType?: ImageType
/** /**
* *
* *
@ -44,27 +46,23 @@ export interface UseDomToImageOptions extends ReDomToImageOptions {
* dom * dom
*/ */
created?: <T extends TargetType = Element>( created?: <T extends TargetType = Element>(
result: DomToImageResult,
element: T, element: T,
result: string | Blob | Uint8ClampedArray | undefined,
) => void ) => void
/** /**
* *
* @param element current dom
* @param error dom to image error * @param error dom to image error
* *
* dom * dom
*/ */
createdError?: <T extends TargetType = Element>( createdError?: (error?: Error) => void
element: T,
error: Error,
) => void
/** /**
* *
* @param element current dom * @param element current dom
* *
* dom * dom
*/ */
finally?: <T extends TargetType = Element>(element: T) => void finally?: () => void
} }
const domToImageMethods = { const domToImageMethods = {
@ -99,29 +97,45 @@ export const useDomToImage = <T extends HTMLElement>(
target: BasicTarget<T>, target: BasicTarget<T>,
options?: UseDomToImageOptions, options?: UseDomToImageOptions,
) => { ) => {
const { beforeCreate, created, createdError } = options ?? {} const {
beforeCreate,
created,
createdError,
finally: _finally,
} = options ?? {}
const run = (imageType: UseDomToImageOptions['imageType'] = 'jpeg') => { const run = (
imageType: UseDomToImageOptions['imageType'] = 'jpeg',
): Promise<DomToImageResult> => {
return new Promise((resolve, reject) => {
const element = unrefElement(target) const element = unrefElement(target)
beforeCreate?.(element) beforeCreate?.(element)
if (element) { if (!element) {
createdError?.()
return reject('useDomToImage: element is undefined.')
}
const type = imageType ?? options?.imageType const type = imageType ?? options?.imageType
const matchFc = domToImageMethods[type] || domToImageMethods['jpeg'] const matchFc = domToImageMethods[type] || domToImageMethods['jpeg']
return matchFc(element, options) matchFc(element, options)
.then((res) => { .then((res) => {
created?.(element, res) created?.(res, element)
return Promise.resolve(res) return resolve(res)
}) })
.catch((error) => { .catch((error: Error) => {
createdError?.(element, error as Error) createdError?.(error)
return Promise.reject(error as Error) return reject(error)
})
.finally(() => {
_finally?.()
})
}) })
}
} }
return { return {

View File

@ -27,7 +27,7 @@ export type UsePrintTarget<T = any> =
* const { print } = usePrint(refDom, {}) * const { print } = usePrint(refDom, {})
* @example * @example
* const { print } = usePrint('#id', {}) * const { print } = usePrint('#id', {})
* const { print } = usePrint('base64', {}) * const { print } = usePrint('base64', {}) // 设置为 base64 时,一定要设置配置项 base64 为 true
* const { print } = usePrint('https://xxx.com/xxx.png', {}) * const { print } = usePrint('https://xxx.com/xxx.png', {})
* const { print } = usePrint(new Blob(), {}) * const { print } = usePrint(new Blob(), {})
*/ */

View File

@ -16,7 +16,7 @@ import type { UsePrintOptions, UseDomToImageOptions } from '@/hooks/web'
import type { BasicTarget } from '@/types/modules/vue' import type { BasicTarget } from '@/types/modules/vue'
export interface PrintDomOptions { export interface PrintDomOptions {
printOptions?: Omit<UsePrintOptions, 'printable' | 'type'> printOptions?: Omit<UsePrintOptions, 'printable' | 'type' | 'base64'>
domToImageOptions?: Omit<UseDomToImageOptions, 'imageType'> domToImageOptions?: Omit<UseDomToImageOptions, 'imageType'>
} }
@ -28,7 +28,7 @@ export interface PrintDomOptions {
* useDomToImage print-js Ref Dom * useDomToImage print-js Ref Dom
* dom * dom
* *
* printOptions printable type 使 ts * printOptions printable, type, base64 使 ts
* 使 jpeg 使 * 使 jpeg 使
* *
* useDomToImage imageType * useDomToImage imageType
@ -59,7 +59,9 @@ export const printDom = <T extends HTMLElement>(
?.then((res) => { ?.then((res) => {
const { print } = usePrint(res, { const { print } = usePrint(res, {
type: 'image', type: 'image',
...omit(printOptions as UsePrintOptions, ['type']), base64: true,
targetStyles: ['*'],
...omit(printOptions as UsePrintOptions, ['type', 'base64']),
}) })
print() print()

View File

@ -199,7 +199,6 @@ const TableView = defineComponent({
}} }}
</RCollapseGrid> </RCollapseGrid>
<RTable <RTable
style="margin-top: 18px"
scrollX={2000} scrollX={2000}
title={ title={
<NSpace align="center"> <NSpace align="center">

View File

@ -86,11 +86,6 @@ function onlyBuildOptions(mode: string) {
resolve: resolve:
'https://cdn.staticfile.org/vue-i18n/9.8.0/vue-i18n.global.min.js', 'https://cdn.staticfile.org/vue-i18n/9.8.0/vue-i18n.global.min.js',
}, },
{
name: 'dayjs',
global: 'dayjs',
resolve: 'https://cdn.staticfile.org/dayjs/1.11.10/dayjs.min.js',
},
{ {
name: 'echarts', name: 'echarts',
global: 'echarts', global: 'echarts',
@ -106,28 +101,6 @@ function onlyBuildOptions(mode: string) {
global: 'axios', global: 'axios',
resolve: 'https://cdn.staticfile.org/axios/1.6.2/axios.min.js', resolve: 'https://cdn.staticfile.org/axios/1.6.2/axios.min.js',
}, },
{
name: 'print-js',
global: 'printJS',
resolve: 'https://cdn.staticfile.org/print-js/1.6.0/print.min.js',
},
{
name: 'dom-to-image',
global: 'domtoimage',
resolve:
'https://cdn.staticfile.org/dom-to-image/2.6.0/dom-to-image.min.js',
},
{
name: 'clipboard',
global: 'ClipboardJS',
resolve:
'https://cdn.staticfile.org/clipboard.js/2.0.11/clipboard.min.js',
},
{
name: 'lodash-es',
global: '_',
resolve: 'https://cdn.staticfile.org/lodash.js/4.17.21/lodash.min.js',
},
], ],
}), }),
] ]