SheetExcel.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <div id="sheet-container">
  3. </div>
  4. </template>
  5. <script>
  6. import { copyFit } from '@/utils/svgToblob.js';
  7. import { initSheet } from '../common/option';
  8. export default {
  9. props: {
  10. option: {
  11. type: Object,
  12. default: ''
  13. },
  14. sheetInfo: {
  15. type: Object,
  16. default: ()=>{}
  17. },
  18. limit: {
  19. type: Object,
  20. default: ()=>{
  21. return {disabled:false}
  22. }
  23. },
  24. },
  25. data() {
  26. return {
  27. sheetObj: {}
  28. }
  29. },
  30. methods: {
  31. init() {
  32. let optionData = this.option ? this.option : {};
  33. let callbackItems={updated:this.updateEmit}
  34. initSheet('sheet-container',optionData,this.sheetInfo,this.limit,callbackItems)
  35. setTimeout(() => {
  36. //获取sheet-container的宽度,设置更多操作的宽度
  37. //#luckysheet-icon-morebtn-div
  38. const sheetDom = document.querySelector('#sheet-container')
  39. const morebtn = document.querySelector('#luckysheet-icon-morebtn-div')
  40. morebtn && (morebtn.style.maxWidth = sheetDom.clientWidth - 70 +'px')
  41. }, 300);
  42. },
  43. copyDisable(e){
  44. // 变向的禁止复制
  45. // this.copyData()
  46. if(!this.limit.disabled) return
  47. if(e.target && e.target.getAttribute('data-type') && e.target.getAttribute('data-type').indexOf('lucksheet')){
  48. luckysheet.enterEditMode();
  49. // luckysheet.exitEditMode();
  50. return false
  51. }
  52. },
  53. // 单元格内的文字分段
  54. getCellContent(arr) {
  55. if(!arr||!arr.length) return ''
  56. let cellStr = ''
  57. arr.forEach(_ => {
  58. cellStr+=_.v.replace(/\r/,'').replace(/\n/,'')
  59. })
  60. return cellStr;
  61. },
  62. updateEmit(){
  63. this.$emit("updated")
  64. }
  65. },
  66. destroyed() {
  67. luckysheet.destroy();
  68. },
  69. mounted() {
  70. this.init();
  71. document.addEventListener('copy',this.copyDisable)
  72. },
  73. beforeDestroy(){
  74. document.removeEventListener('copy',this.copyDisable)
  75. }
  76. }
  77. </script>
  78. <style scoped lang="scss">
  79. #sheet-container {
  80. margin:0;padding:0;
  81. position:absolute;
  82. width:100%;left: 0px;top: 0;bottom:0px;
  83. }
  84. </style>
  85. <style lang="scss">
  86. .luckysheet .toolbar {
  87. background: none;
  88. margin: 0;
  89. padding: 0;
  90. }
  91. .luckysheet-input-box {
  92. z-index: 99999;
  93. }
  94. </style>