noob преди 3 години
родител
ревизия
9d70cddc9b
променени са 1 файла, в които са добавени 23 реда и са изтрити 46 реда
  1. 23 46
      src/pages/main/performance/components/sheet.vue

+ 23 - 46
src/pages/main/performance/components/sheet.vue

@@ -2,7 +2,7 @@
  * @Author       : yuanrunwei
  * @Date         : 2021-12-04 14:23:58
  * @LastEditors  : yuanrunwei
- * @LastEditTime : 2021-12-13 15:44:26
+ * @LastEditTime : 2021-12-13 16:15:11
  * @FilePath     : \spfm-market-front\src\pages\main\performance\components\sheet.vue
 -->
 
@@ -27,7 +27,6 @@
 </template>
 
 <script>
-import XLSX from "xlsx";
 import luckyexcel from "luckyexcel";
 export default {
     data() {
@@ -35,59 +34,37 @@ export default {
     },
     methods: {
         handleInit() {
+            this.handleCreate();
+        },
+        async handleCreate(file) {
+            let that = this;
             const options = {
                 container: "luckysheet",
-                title: "请上传模板",
                 lang: "zh",
                 showsheetbar: false,
+                hook: {
+                    cellUpdateBefore: function (row, column) {
+                        console.log(row, column);
+                        that.$message.error("您没有编辑权限");
+                        return false;
+                    },
+                },
             };
+            if (file) {
+                await new Promise((resolve) => {
+                    luckyexcel.transformExcelToLucky(file, (export_json) => {
+                        options.data = export_json.sheets;
+                        options.title = export_json.info.name;
+                        options.userInfo = export_json.info.name.creator;
+                        resolve();
+                    });
+                });
+            }
+
             window.luckysheet.create(options);
         },
-        handleCreate(file) {
-            let that = this;
-            luckyexcel.transformExcelToLucky(file, (export_json) => {
-                const options = {
-                    container: "luckysheet",
-                    data: export_json.sheets.map((element) => ({
-                        ...element,
-                        config: {
-                            ...element.config,
-                        },
-                    })),
-                    title: export_json.info.name,
-                    lang: "zh",
-                    showsheetbar: false,
-                    userInfo: export_json.info.name.creator,
-                    hook: {
-                        cellUpdateBefore: function (row, column) {
-                            console.log(row, column);
-                            that.$message.error("您没有编辑权限");
-                            return false;
-                        },
-                    },
-                };
-                window.luckysheet.create(options);
-            });
-        },
         async handleChange(response) {
             this.handleCreate(response.raw);
-            let binary = await this.handleFile(response.raw);
-            let workbook = XLSX.read(binary, {
-                type: "binary",
-                cellDates: true,
-            });
-            let sheet = workbook.Sheets[workbook.SheetNames[0]];
-            const data = XLSX.utils.sheet_to_json(sheet);
-            this.handleCreate(data);
-        },
-        handleFile(file) {
-            return new Promise((resolve) => {
-                let reader = new FileReader();
-                reader.readAsBinaryString(file);
-                reader.onload = (event) => {
-                    resolve(event.target.result);
-                };
-            });
         },
     },
     mounted() {