Elizabeth's proactive approach involves introducing urinal toilet attachment , an ingenious concept that optimizes space and functionality.

index.vue 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <div>
  3. <el-dialog
  4. :visible.sync="msgTipVisible"
  5. width="40%"
  6. >
  7. <span>若执行排班导入,系统将会清除当前已有临时排班数据,是否继续导入?</span>
  8. <span slot="footer" class="dialog-footer">
  9. <el-button @click="msgTipVisible = false">取 消</el-button>
  10. <el-button type="primary" @click="handleUpload()">确 定</el-button>
  11. </span>
  12. </el-dialog>
  13. <input id="excel-upload-input" ref="excel-upload-input" type="file" accept=".xlsx,.xls,.xltx," @change="handleClick">
  14. <el-button :loading="loading" style="margin-left:16px;" size="mini" type="primary" @click="msgTipVisible = true">点击导入
  15. </el-button>
  16. </div>
  17. </template>
  18. <script>
  19. import XLSX from 'xlsx'
  20. export default {
  21. name: "scheduleUploadExcel",
  22. props: {
  23. beforeUpload: Function,
  24. onSuccess: Function
  25. },
  26. data() {
  27. return {
  28. loading: false,
  29. msgTipVisible:false,
  30. excelData: {
  31. header: null,
  32. results: null
  33. }
  34. }
  35. },
  36. methods: {
  37. generateDate({ header, results }) {
  38. console.log("header",header)
  39. console.log("results",results)
  40. this.excelData.header = header
  41. this.excelData.results = results
  42. this.onSuccess && this.onSuccess(this.excelData)
  43. },
  44. handleDrop(e) {
  45. e.stopPropagation()
  46. e.preventDefault()
  47. if (this.loading) return
  48. const files = e.dataTransfer.files
  49. if (files.length !== 1) {
  50. this.$message.error('Only support uploading one file!')
  51. return
  52. }
  53. const rawFile = files[0] // only use files[0]
  54. if (!this.isExcel(rawFile)) {
  55. this.$message.error('Only supports upload .xlsx, .xls, .csv suffix files')
  56. return false
  57. }
  58. this.upload(rawFile)
  59. e.stopPropagation()
  60. e.preventDefault()
  61. },
  62. handleDragover(e) {
  63. e.stopPropagation()
  64. e.preventDefault()
  65. e.dataTransfer.dropEffect = 'copy'
  66. },
  67. handleUpload() {
  68. this.msgTipVisible = false
  69. document.getElementById('excel-upload-input').click()
  70. },
  71. handleClick(e) {
  72. const files = e.target.files
  73. const rawFile = files[0] // only use files[0]
  74. console.log("rawfiel",rawFile)
  75. if (!rawFile)
  76. return
  77. this.upload(rawFile)
  78. },
  79. upload(rawFile) {
  80. console.log("触发了吗")
  81. this.$refs['excel-upload-input'].value = null // fix can't select the same excel
  82. console.log("3333",this.beforeUpload)
  83. if (!this.beforeUpload) {
  84. this.readerData(rawFile)
  85. return
  86. }
  87. const before = this.beforeUpload(rawFile)
  88. console.log("before",before)
  89. if (before) {
  90. this.readerData(rawFile)
  91. }
  92. },
  93. readerData(rawFile) {
  94. this.loading = true
  95. return new Promise((resolve, reject) => {
  96. const reader = new FileReader()
  97. reader.onload = e => {
  98. const data = e.target.result
  99. const fixedData = this.fixdata(data)
  100. const workbook = XLSX.read(btoa(fixedData), { type: 'base64' })
  101. const firstSheetName = workbook.SheetNames[0]
  102. const worksheet = workbook.Sheets[firstSheetName]
  103. const header = this.get_header_row(worksheet)
  104. const results = XLSX.utils.sheet_to_json(worksheet)
  105. this.generateDate({ header, results })
  106. this.loading = false
  107. resolve()
  108. }
  109. reader.readAsArrayBuffer(rawFile)
  110. })
  111. },
  112. fixdata(data) {
  113. let o = ''
  114. let l = 0
  115. const w = 10240
  116. for (; l < data.byteLength / w; ++l) o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w, l * w + w)))
  117. o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w)))
  118. return o
  119. },
  120. get_header_row(sheet) {
  121. if(sheet['!ref'] == undefined){
  122. this.loading = false
  123. return
  124. }
  125. const headers = []
  126. const range = XLSX.utils.decode_range(sheet['!ref'])
  127. let C
  128. const R = range.s.r /* start in the first row */
  129. for (C = range.s.c; C <= range.e.c; ++C) { /* walk every column in the range */
  130. var cell = sheet[XLSX.utils.encode_cell({ c: C, r: R })] /* find the cell in the first row */
  131. var hdr = 'UNKNOWN ' + C // <-- replace with your desired default
  132. if (cell && cell.t) hdr = XLSX.utils.format_cell(cell)
  133. headers.push(hdr)
  134. }
  135. return headers
  136. },
  137. isExcel(file) {
  138. console.log("file",file)
  139. return /\.(xlsx|xls|csv)$/.test(file.name)
  140. }
  141. }
  142. }
  143. </script>
  144. <style scoped>
  145. #excel-upload-input {
  146. display: none;
  147. z-index: -9999;
  148. }
  149. #drop {
  150. border: 2px dashed #bbb;
  151. width: 600px;
  152. height: 160px;
  153. line-height: 160px;
  154. margin: 0 auto;
  155. font-size: 24px;
  156. border-radius: 5px;
  157. text-align: center;
  158. color: #bbb;
  159. position: relative;
  160. }
  161. </style>