cafe-ofd

1.1.9 • Public • Published

Cafe-OFD

NPM Publish NPM version GitHub stars GitHub issues GitHub forks

Render OFD files on Vue pages using ofd.js.

  • 😊 Vue 2.0 + ofd.js, Thanks ofd.js!
  • 😂 Support for modern browsers (IE11);

Install

npm install cafe-ofd --save

Quick Start

import cafeOfd from 'cafe-ofd'
import 'cafe-ofd/package/index.css'
Vue.use(cafeOfd)

Example

Demo:http://demo.const.team/ofd/

ofd test file download:

Note: the use of print, need to cooperate with the print style.

<template>
  <cafe-ofd ref="ofd" :filePath="file" @on-success="load" @on-scroll="scroll">
    <div slot="header">
      <input type="file" ref="file" class="hidden" accept=".ofd" @change="fileChanged">
    </div>
    <div slot="footer">
      <button @click="plus">plus</button>
      <button @click="minus">minus</button>
      <button @click="pre" :disabled="currentNum <= 1">pre</button>
      <input type="number" :min="1" :max="pageNum" v-model.number="currentNum" @change="pageChange(currentNum)">
      <button @click="next" :disabled="currentNum >= pageNum">next</button>
      <button @click="print">print</button>
    </div>
  </cafe-ofd>
</template>

<script>
export default {
  name: 'app',
  components: {},
  data() {
    //这里存放数据
    return {
      currentNum: null,
      file: null,
      pageNum: null
    };
  },
  methods: {
    load(val) {
      this.pageNum = val;
    },
    fileChanged() {
      this.file = this.$refs.file.files[0];
    },
    plus() {
      this.$refs.ofd.scale(50);
    },
    minus() {
      this.$refs.ofd.scale(-50);
    },
    next() {
      this.$refs.ofd.nextPage();
    },
    pre() {
      this.$refs.ofd.prePage();
    },
    pageChange(val) {
      this.$refs.ofd.goToPage(val);
    },
    print() {
      this.$refs.ofd.printFile();
    },
    scroll(val) {
      this.currentNum = val;
    }
  }
};
</script>

<style>
* {
  margin: 0;
  padding: 0;
}
html,
body,
#app {
  width: 100%;
  height: 100%;
  overflow: hidden;
}
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}
@media print {
  html,
  body,
  #app {
    height: auto;
    overflow: auto;
  }
}
</style>

Attributes

Attribute Description Type Accepted Values Default
filePath ofd source string
width ofd width number 900

Events

Event Name Description Parameters
on-success success event page count, ofd Object
on-error error event error
on-scroll scroll event current page, ofd Object

Methods

Method Description Parameters
scale scale steps
prePage pre page
nextPage next page
goToPage go to page page number
printFile Print all ofd

Slot

name Description
header header slot
footer footer slot

Readme

Keywords

Package Sidebar

Install

npm i cafe-ofd

Weekly Downloads

3

Version

1.1.9

License

MIT

Unpacked Size

4.18 MB

Total Files

8

Last publish

Collaborators

  • wangdaodao