index.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import barcode from './barcode'
  2. const defalutOptions = {
  3. number: true,
  4. prefix: true,
  5. color: 'black',
  6. debug: false,
  7. onValid() {},
  8. onInvalid() {},
  9. onSuccess() {},
  10. onError() {},
  11. }
  12. Component({
  13. properties: {
  14. width: {
  15. type: Number,
  16. value: 200,
  17. },
  18. height: {
  19. type: Number,
  20. value: 100,
  21. },
  22. number: {
  23. type: String,
  24. value: '',
  25. observer(newVal) {
  26. this.draw({
  27. number: newVal,
  28. })
  29. },
  30. },
  31. options: {
  32. type: Object,
  33. value: defalutOptions,
  34. },
  35. canvasId: {
  36. type: String,
  37. value: 'wux-barcode',
  38. },
  39. },
  40. methods: {
  41. draw(opts = {}) {
  42. const { canvasId, number, width, height, options } = Object.assign({}, this.data, opts)
  43. new barcode(canvasId, number, Object.assign({ width, height }, options), this)
  44. },
  45. },
  46. })