suerprisePlus
2024-07-30 e5e65bb50cbfb973f98191993ab559767eff7a53
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<template>
    <div class="atlasBox" v-loading="gLoading">
        <el-form :inline="true" :model="formInline" class="demo-form-inline">
            <el-form-item label="上传数据">
                <el-input :placeholder="placeholder" v-model="formInline.file">
 
                    <i slot="suffix" @click="onClickInputFile" class="el-input__icon el-icon-upload2"></i>
                </el-input>
            </el-form-item>
 
            <el-form-item>
                <el-button type="primary" size="small" plain icon="el-icon-setting" @click="onSubmit">分 析</el-button>
                <el-button type="info" size="small" plain icon="el-icon-refresh" @click="onRefresh">重 置</el-button>
            </el-form-item>
        </el-form>
 
        <input size="small" id="fromFile" type="file" style="display: none;" accept=".xlsx,.xls"
            @change="onFileInputChange"></input>
        <el-divider />
        <div class="atlasContnt">
            <el-table v-show="showTable" height=" calc(100% - 1px)" style="  width:100%" :data="tableData">
                <el-table-column v-for="(item, index) in tableDataHeader" :key="index" align="center" :prop="item.name
                    " :label="item.name"></el-table-column>
            </el-table>
 
            <el-carousel v-show="!showTable" style="height: 100%;" :interval="5000" arrow="always">
                <el-carousel-item v-for="(item, key) in carouseList" :key="key">
                    <el-image class="image" :src="item.src" :preview-src-list="[item.src]">
                    </el-image>
                </el-carousel-item>
            </el-carousel>
 
        </div>
    </div>
</template>
 
<script>
import XLSX from 'xlsx'
import $ from "jquery";
export default {
    data() {
        return {
            formInline: {
                file: ''
            },
            placeholder: "请选择要上传的数据",
            selectFileType: ".xlsx,.xls",
            tableData: [],
            tableDataHeader: [],
            gLoading: false,
            showTable: true,
            carouseList: [],
        }
    },
    methods: {
        onSubmit() {
            var fs = document.getElementById("fromFile");
            if (fs.files.length == 0) {
                this.$store.state.setLoading = false;
                return this.$message("请选择需要上传的数据文件");
            }
            this.gLoading = true;
            var formFile = new FormData();
            var fileObj = fs.files[0]
            formFile.append("file", fileObj); //加入文件对象
            document.getElementById('fromFile').vlaue = "";
            this.formInline.file = ''
            const that = this;
            $.ajax(
                config.pyServices + "/scatterplot",
                {
                    type: 'POST',
                    data: formFile,
                    async: true,
                    cache: false,
                    contentType: false,
                    processData: false,
                    success: (rs) => {
                        that.showTable = false;
                        that.setShowImage(rs);
                        that.gLoading = false
 
                    },
                    error: (rs) => {
                        that.gLoading = false
                    },
                })
        },
        onRefresh() {
            this.gLoading = false;
            this.showTable = true;
            this.carouseList = [];
            this.tableData = [];
            this.tableDataHeader = [];
            document.getElementById('fromFile').vlaue = "";
            this.formInline.file = ''
        },
        setShowImage(response) {
 
            const std = [];
            for (var key in response) {
                std.push({
                    src: config.pyServices + '/image?file_name=' + response[key]
                })
            }
            this.carouseList = std
        },
        onClickInputFile() {
            document.getElementById('fromFile').click();
        },
        onFileInputChange(event) {
 
            var that = this
            // 拿取文件对象
            let f = event.currentTarget.files[0]
 
            this.formInline.file = f.name
            // 用FileReader来读取
            let reader = new FileReader()
            // 重写FileReader上的readAsBinaryString方法
            FileReader.prototype.readAsBinaryString = (f) => {
                let binary = ''
                let wb // 读取完成的数据
                let outdata // 你需要的数据
                let reader = new FileReader()
 
                reader.onload = (e) => {
                    // 读取成Uint8Array,再转换为Unicode编码(Unicode占两个字节)
                    let bytes = new Uint8Array(reader.result)
                    let length = bytes.byteLength
                    for (let i = 0; i < length; i++) {
                        binary += String.fromCharCode(bytes[i])
                    }
 
                    // 接下来就是xlsx了,具体可看api
                    wb = XLSX.read(binary, {
                        type: 'binary'
                    })
                    outdata = XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]])
                    var str = outdata[0];
                    var std = [];
                    for (var key in str) {
 
                        std.push({ name: key })
 
                    }
                    that.tableDataHeader = std
                    that.tableData = outdata
                }
 
                reader.readAsArrayBuffer(f)
            }
            reader.readAsBinaryString(f)
 
        }
    }
};
</script>
 
<style lang="scss" scoped>
.atlasBox {
    width: calc(100% - 20px);
    height: calc(100% - 20px);
    position: absolute;
    margin: 10px;
    border-radius: 5px;
    display: flex;
    flex-direction: column;
 
    // background: yellowgreen;
    ::v-deep.el-divider--horizontal {
        margin: 0px;
        margin-bottom: 10px;
    }
 
    ::v-deep.el-form-item {
        margin-bottom: 15px;
        margin-top: 10px;
    }
 
    .atlasContnt {
        flex: 1;
 
        .image {
            width: 100%;
            height: 95%;
        }
 
        ::v-deep.el-carousel__container {
            height: 100%;
 
        }
 
        ::v-deep.el-carousel__button {
            background: #409EFF !important
        }
 
        // background: skyblue;
        // ::v-deep.el-carousel__container {
        //     height: 100%;
 
        // }
 
        // ::v-deep.el-carousel__button {
        //     background: #409EFF !important
        // }
    }
}
</style>