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

sa-file-previewer

v0.1.41

Published

集成VueOffice的文件预览组件

Downloads

49

Readme

SaFilePreviewer

一款基于vue-office对 Vue3 项目中预览docxxlsxpdf文件的组件,支持 ts 代码提示,使用方式简单快捷。

安装

yarn add sa-file-previewer

使用

// main.ts

import SaFilePreviewer from "sa-file-previewer";
import "sa-file-previewer/dist/style.css";
...

app.use(SaFilePreviewer);
<!-- example.vue -->
<template>
    <FilePreviewer :fileUrl="xxxx.docx"></FilePreviewer>
</template>

<script setup lang="ts">
import { FilePreviewer } from "sa-file-previewer";

<script>

说明

如果fileUrl的链接包含文件后缀格式,即只需传递fileUrl参数即可,组件会根据链接地址推断文件格式,若文件地址不包含文件后缀格式,需显式传递fileType参数(string),目前支持格式为:

  • docx
  • xlsx
  • pdf

当然,也可在业务侧先判断文件格式是否受支持,再做后续处理,例如:

<!-- example.vue -->
<template>
    <el-upload
      :on-preview="handleFilePreview"
      ...
    </el-upload>

    <FilePreviewer :fileUrl="xxxx.docx"></FilePreviewer>
</template>

<script setup lang="ts">
import { FilePreviewer, isFileSupported } from "sa-file-previewer";

const fileUrl = ref('xxx.xx')
const handleFilePreview = (file: UploadFile) => {
  const fileType = file.url.split(".").pop();
  if (isFileSupported(fileType)) {
    fileUrl.value = file.url;
    filePreviewDlg.openDialog();
  } else {
    ElMessage.error("不支持预览该格式文件");
  }
};
<script>

参数接口

enum SupportFileTypes {
  Docx = "docx",
  Pdf = "pdf",
  Xlsx = "xlsx",
}

interface BaseProps {
  /**
   * 文件url地址,需包含后缀
   */
  fileUrl: string;
  /**
   * 文件类型,默认根据url获取
   */
  fileType?: string;
  /**
   * 预览高度
   *
   *  @default '800px'
   */
  height?: string;
}

interface ExcelProps extends BaseProps {
  /**
   * Excel预览配置
   * 如果预览的文件是excel文件,则可以配置如下参数
   *
   * @example
   *  options:{
          minColLength?: number;  //excel最少渲染多少列,如果想实现xlsx文件内容有几列,就渲染几列,可以将此值设置为0.
          showContextmenu?: boolean; //是否显示右键菜单,默认false
      },

      @reference https://501351981.github.io/vue-office/examples/docs/guide/js-preview.html
   */
  excelOptions?: any;
}

interface Props extends BaseProps, ExcelProps {}

基于

Vue3

Vue-Office