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

@beisen-phoenix/file-list

v3.3.55

Published

显示文件预览的组件,此组件仅负责展示,没有内置功能。配合[上传](http://gitlab.beisencorp.com/ux-phoenix/upload)组件,可以组成上传加预览的功能

Downloads

885

Readme

文件预览组件

显示文件预览的组件,此组件仅负责展示,没有内置功能。配合上传组件,可以组成上传加预览的功能

参数,详情请看 interface 定义

// 文件对象,定义请看下面的 【文件数据格式的定义】
 interface IPreviewItemFile extends IUploadFileType{
  deletable?: boolean
}

// 列表布局方式
export enum EListLayout {
  vertical = 'vertical',
  horizontal = 'horizontal'
}

interface IUploadFileType {
    name: string; // 文件名称
    status: EStatus; // 文件状态
    mediaType: string; // 文件类型
    previewUrl?: string; // 文件预览地址
    downloadUrl?: string; // 文件下载地址
    percent?: number; // 文件上传进度
    raw?: File; // 源文件对象
    id?: string; //后端文件id
    lid?: string; //前端生成的临时id
}

关于lid 与 id

在文件被选中并且没有上传完成的过程中,需要给文件数据一个标识,所以会临时生成一个lid = 文件名 + 时间戳,当文件上传完成并且后端返回文件对象之后,建议给文件数据追加上id作为后续操作的标识

代码示例: 只显示文件预览

import React from 'react';
import FilePreview, {ListView, IPreviewItemFile, EListLayout} from '../../src';
import {EStatus} from '@reacted/upload-intf'

const files: IPreviewItemFile[] = [
  {
    id: 'dfdsfds',
    name: 'xxxxxf放的开龙卷风fdfsfjdklsfjdsl.png',
    previewUrl: 'http://stnew.beisen.com/ux/beisen-common/upaas-static/file-icons/zip.svg',
    status: EStatus.progress,
    mediaType: 'png',
    percent: 80
  },
  {
    id: 'fdsssss',
    name: '这个名字不很长.c',
    previewUrl: 'http://stnew.beisen.com/ux/beisen-common/upaas-static/file-icons/zip.svg',
    status: EStatus.uploadFinish,
    mediaType: 'doc',
    percent: 100,
    deletable: true
  },
  {
    id: 'fds',
    name: '这个名字长啊长长长和啊.exe',
    previewUrl: 'http://stnew.beisen.com/ux/beisen-common/upaas-static/file-icons/zip.svg',
    status: EStatus.done,
    mediaType: 'ppt',
    percent: 80 
  },
  {
    id: 'fdsss',
    name: '这个名字不很长.c',
    previewUrl: 'http://stnew.beisen.com/ux/beisen-common/upaas-static/file-icons/zip.svg',
    status: EStatus.done,
    mediaType: 'doc',
    percent: 80,
    deletable: true
  },
  {
    id: 'fdsx',
    name: 'aaaabbbccdd.exe',
    previewUrl: 'http://stnew.beisen.com/ux/beisen-common/upaas-static/file-icons/zip.svg',
    status: EStatus.error,
    mediaType: 'pnf',
    percent: 90
  }
];

export default function App(props: { url: string | ((f: any) => string) }) {
  return (
    <div style={{width: '60%'}}>
      <h3>块式预览</h3>
      <FilePreview files={files} edit />
      <h3>列表式:竖排</h3>
      <ListView files={files} edit width="400px"></ListView>
      <h3>列表式:横排</h3>
      <ListView files={files} layout={EListLayout.horizontal}></ListView>
    </div>
  );
}

代码示例: 上传 + 预览

import React, { useState, useCallback } from 'react';
import FilePreview, {ListView, EListLayout} from '../../src';
import Upload from '@beisen-phoenix/upload';
import {IUploadFileType, EMsgType} from '@reacted/upload-intf'

export default function App(props: { url: string | ((f: any) => string) }) {
  const [files, setFiles] = useState<IUploadFileType[]>([]);
  const handleChange = (files: IUploadFileType[]) => {
    console.log(files);
    setFiles(files);
  };
  const onError = useCallback(err => {
    let {log} = console;
    if (err.type === EMsgType.overLimit) {
      log('文件个数超出上限', err);
    }
    if (err.type === EMsgType.overSize) {
      log('文件体积超出上限',err);
    }
    if (err.type === EMsgType.networkFail) {
      log('网络出错', err);
    }
  }, []);

  const handleDelete = file => {
    let idx = files.findIndex(item => item.lid === file.lid);
    if (idx !== -1) {
      let newFiles = [...files.slice(0, idx), ...files.slice(idx + 1)];
      setFiles(newFiles);
    }
  };

  return (
    <div>
      <div>
        <Upload onChange={handleChange} onError={onError} url="hehe" files={files} multiple>
          <button>上传</button>
        </Upload>
      </div>
      <h3>块式列表</h3>
      <FilePreview files={files} edit onDelete={handleDelete} />
      <h3>列表式:竖排</h3>
      <ListView files={files} edit onDelete={handleDelete} width="50%"/>
      <h3>列表式:横排</h3>
      <ListView files={files} edit onDelete={handleDelete} layout={EListLayout.horizontal}/>
    </div>
  );
}