npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@keyblade/one-travel

v2.0.18

Published

KeyBlade OneTravel

Downloads

9

Readme

一码游SDK

一、工具类

1.oneTravelImageCheckAndTransform

import { oneTravelImageCheckAndTransform } from '@keyblade/one-travel'

/**
 * 一码游-图片检测及转换
 * @param {File | Blob} data - 文件数据
 * @param {String} fileName - 文件名称
 * @param {Object} [options] - 可选项
 * @param {Number} [options.imageMaxSize] - 图片最大值(单位M,主要用于错误提示)
 * @param {String} [options.imageAllowedType] - 图片允许的后缀类型(小写,如: png、jpg)
 * @param {Number} [options.imageMinWidth] - 图片最小宽度
 * @param {Number} [options.imageMinWidth] - 图片最小高度
 * @param {Number} [options.imageMaxWidth] - 图片最大宽度
 * @param {Number} [options.imageMaxHeight] - 图片最大高度
 */
export async function oneTravelImageCheckAndTransform(
  data: File | Blob,
  fileName: string,
  options?: {
    imageMaxSize?: number;
    imageAllowedType?: string[];
    // imageAllowedMineType?: string[]
    imageMinWidth?: number;
    imageMinHeight?: number;
    imageMaxWidth?: number;
    imageMaxHeight?: number;
  }
): Promise<{
  /** 是否成功 */
  success: boolean;
  /** 最终文件(有可能被转换) */
  file?: File | Blob;
  /** 是否被转换 */
  hasTransform?: boolean;
  /** 失败 */
  error?: {
    size?: boolean;
    format?: boolean;
    transform?: boolean;
    pixel?: boolean;
  },
  /** 错误消息 */
  errorMessage?: string;
}> {}

2.oneTravelImageCompressor

import { oneTravelImageCompressor } from '@keyblade/one-travel'

/**
 * 一码游-图片压缩
 * @param {File | Blob} data - File 或 Blob
 * @param {Object} options - 可选项
 * @param {Number} options.maxSize - 超过多少进行压缩(单位byte)
 * @param {Number} options.size - 压缩到多少M以内(单位byte)
 * @param {String[]} options.excludeAllowedTypes - 哪些类型不需要压缩(['image/gif'])
 */
export async function oneTravelImageCompressor(
  data: File | Blob,
  options?: {
    maxSize?: number;
    size?: number;
    excludeAllowedTypes?: string[]
  }
): Promise<{
  // 文件
  file: File | Blob;
  // 是否成功
  success: boolean;
  // 错误消息
  errorMessage?: string;
}>{}

3.oneTravelImgPondBeforeAddFile

/**
 * 一码游-拦截ImgPondBefore方法,对图片进行校验及转换
 * @param {Object} imgPondIns - ImgPond组件实例
 * @param {Object} [options] - 可选项
 * @param {Function} [options.onStart] - 校验及转换开始
 * @param {Function} [options.onSuccess] - 校验及转换成功
 * @param {Function} [options.onError] - 校验及转换失败
 */
export async function oneTravelImgPondBeforeAddFile(imgPondIns: any, options?: {
  onStart?: () => void,
  onSuccess?: () => void,
  onError?: (message: string) => void;
}) {}

使用步骤

1).绑定ref

<ImgPond
  ref="uploadImageImgPondRef"
/>

2).调用

import { oneTravelImgPondBeforeAddFile } from '@keyblade/one-travel'

const uploadImageImgPondRef = ref()
watch(() => uploadImageImgPondRef.value, () => {
  if (uploadImageImgPondRef.value) {
    let loadingIns: ElLoadingComponent
    oneTravelImgPondBeforeAddFile(uploadImageImgPondRef.value, {
      onStart: () => {
        loadingIns = Loading.service({text: '加载中...', fullscreen: true, customClass: 'tinymce-loading' })
      },
      onSuccess: () => {
        loadingIns?.close()
      },
      onError: (message) => {
        loadingIns?.close()
        Message.error(message)
      }
    })
  }
}, { immediate: true })