SheetExcel.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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.style.maxWidth = sheetDom.clientWidth - 70 +'px';
  41. }, 300);
  42. },
  43. copyDisable(e){
  44. // 变向的禁止复制
  45. // console.log(e.target.value && e.target.value.indexOf('lucksheet'));
  46. this.copyData()
  47. if(!this.limit.disabled) return
  48. if(e.target.value && e.target.value.indexOf('lucksheet')){
  49. luckysheet.enterEditMode();
  50. // luckysheet.exitEditMode();
  51. return false
  52. }
  53. },
  54. copyData() {
  55. let rangeArr = luckysheet.getRangeArray('twoDimensional');
  56. let str = ''
  57. rangeArr.forEach((item,r_index) => {
  58. let row = ''
  59. item.forEach((cell,index) => {
  60. row+= `${index!==0?'\t':''}${cell||''}`
  61. })
  62. str+= r_index===rangeArr.length-1 ? row : `${row}\n`
  63. });
  64. copyFit(str)
  65. },
  66. updateEmit(){
  67. this.$emit("updated")
  68. }
  69. },
  70. destroyed() {
  71. luckysheet.destroy();
  72. },
  73. mounted() {
  74. this.init();
  75. document.addEventListener('copy',this.copyDisable)
  76. },
  77. beforeDestroy(){
  78. document.removeEventListener('copy',this.copyDisable)
  79. }
  80. }
  81. </script>
  82. <style scoped lang="scss">
  83. #sheet-container {
  84. margin:0;padding:0;
  85. position:absolute;
  86. width:100%;left: 0px;top: 0;bottom:0px;
  87. }
  88. </style>
  89. <style lang="scss">
  90. .luckysheet .toolbar {
  91. background: none;
  92. margin: 0;
  93. padding: 0;
  94. }
  95. .luckysheet-input-box {
  96. z-index: 99999;
  97. }
  98. </style>