0.4.2 • Published 3 months ago

@sadais/uploader v0.4.2

Weekly downloads
-
License
MIT
Repository
-
Last release
3 months ago

开始

# 安装依赖
npx yarn
# 监听实时构建`/dist`
npm run dev
# 只构建`/dist`一次,不作监听
npm run build

发布包到私服

# 登录npm服务器
npm login --registry https://registry.npmjs.org
# 发布
npm publish

发布之前测试

在当前工程,没有创建组件的单元测试,只能通过把构建后的东西复制到某个项目的 node_modules

比如当前 package.json 的包名是 "@sadais/uploader" , 发布前要在 A 项目中测试 "@sadais/uploader", 在 A 项目的 node_modules 新建 @sadais/uploader , 再把 /dist/ 和 package.json 拷贝到 A 项目的 node_modules/@sadais/uploader

使用

import { UploaderInstance,UPLOADER_TYPE } from '@sadais/uploader';
const uploader = new UploaderInstance(
  {type:UPLOADER_TYPE.ALIYUN,getOptionFun:async (type) => {
      // 获取option示例
      const { head, data } = await apiGetUploadOption(type)
      if (head.ret !== this.$consts.RET_CODE.SUCCESS) return null
      return data
  }}
)

// 获取上传options示例
export const apiGetUploadOption = async type => {
  const params = {
    storageenum: type
  }
  const { data } = await request.get('/api/manage/v1/storage/getstoragesignature', params)
  return data
}

// 调用说明
//单文件上传
const {data,head:{msg,ret}} = await uploader.uploadFile(file)
// 0-成功 1-失败
if(ret===this.$consts.RET_CODE.SUCCESS){
  const url = data
}
//多文件上传
const {successUrls,failUrls} = await uploader.uploadFiles(files)
// successUrls-上传成功的url数组
// failUrls-上传失败的fileName数组

//通用上传,支持单文件和多文件
const [{index,url,ret}] = await uploader.upload(file|files)
// 返回数组
// index:上传文件的下标;
// ret:状态,0-成功,1-失败;
// url:上传成功的路径 或 上传失败的文件名

发布完成后

在 A 项目安装

# use yarn
npx yarn add @sadais/uploader -S

# use npm or pnpm
npx pnpm install @sadais/uploader -S
0.3.9

3 months ago

0.3.8

3 months ago

0.4.1

3 months ago

0.4.0

3 months ago

0.4.2

3 months ago

0.3.6

2 years ago

0.3.5

2 years ago

0.3.7

2 years ago

0.3.2

2 years ago

0.3.4

2 years ago

0.3.3

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.1.2

2 years ago