瀏覽代碼

新增上传设备文件svg图标页面,方便 修改配置文件使用

yunxing 4 年之前
父節點
當前提交
9daa427cc5
共有 4 個文件被更改,包括 212 次插入167 次删除
  1. 6 0
      src/router/index.ts
  2. 0 167
      src/views/mockData.js
  3. 52 0
      src/views/svgKey.json
  4. 154 0
      src/views/uploadEquipmentSvg.vue

+ 6 - 0
src/router/index.ts

@@ -17,6 +17,12 @@ const routes: Array<RouteConfig> = [
         name: "Home",
         component: () => import(/* webpackChunkName: "home" */ "../views/home.vue"),
     },
+    // 上传设备svg图标页面
+    {
+        path: "/svg",
+        name: "Svg",
+        component: () => import(/* webpackChunkName: "svg" */ "../views/uploadEquipmentSvg.vue"),
+    },
 ];
 
 const router = new VueRouter({

+ 0 - 167
src/views/mockData.js

@@ -1,167 +0,0 @@
-// 已发布模拟数据
-let yfbMocKdata = {
-    content: [
-        {
-            buildingId: "123A",
-            buildingName: "建筑A座",
-            floorList: [
-                {
-                    floorId: "1",
-                    floorName: "1层",
-                    floor: [
-                        {
-                            available: true,
-                            buildingId: "1",
-                            categoryId: "120103",
-                            createTime: "2020-10-29 11:15:08",
-                            floorId: "1",
-                            graphId: "2dd925178d164a96941c34326ad340e8",
-                            id: "376f578716fb48febe8fb291b527169f",
-                            label: ["接电话岁微内核你", "阿双方各施工好的好的"],
-                            lastUpdate: "2020-11-19 17:05:18",
-                            name: "个环境接口",
-                            note: "1",
-                            pic: "f1e7da10-1994-11eb-9680-fdc5a286ca5f.png",
-                            projectId: "Pj1101050029",
-                            state: 0,
-                            statistics: {},
-                            version: "2.1.0",
-                        },
-                        {
-                            available: true,
-                            buildingId: "1",
-                            categoryId: "110101",
-                            createTime: "2020-11-05 23:14:46",
-                            floorId: "1",
-                            graphId: "344745c9bc69485a89dd62ca7fdb4e54",
-                            id: "ee8ac7aeca514e4dbef5066a5674e199",
-                            label: [],
-                            lastUpdate: "2020-11-05 23:14:46",
-                            name: "北京东城",
-                            note: "1",
-                            pic: "37715eb0-1f55-11eb-ad39-a16c62663b78.png",
-                            projectId: "Pj1101050029",
-                            state: 0,
-                            statistics: {},
-                            version: "2.1.0",
-                        },
-                        {
-                            available: true,
-                            buildingId: "1",
-                            categoryId: "130201",
-                            createTime: "2020-10-29 11:19:14",
-                            floorId: "1",
-                            graphId: "36eddec793d747e3ab1e5a344f7d10cd",
-                            id: "38ba8b2679eb452ab1b0d30d3c0bccab",
-                            label: [1, 2, 3, 4, 5],
-                            lastUpdate: "2020-10-29 11:19:14",
-                            name: "好几年狂欢节",
-                            note: "1",
-                            pic: "847b0b90-1995-11eb-9680-fdc5a286ca5f.png",
-                            projectId: "Pj1101050029",
-                            state: 0,
-                            statistics: {},
-                            version: "2.1.0",
-                        },
-                    ],
-                },
-                {
-                    floorId: "2",
-                    floorName: "2层",
-                    floor: [
-                        {
-                            available: true,
-                            buildingId: "1",
-                            categoryId: "120103",
-                            createTime: "2020-10-29 11:15:08",
-                            floorId: "1",
-                            graphId: "2dd925178d164a96941c34326ad340e8",
-                            id: "376f578716fb48febe8fb291b527169f22222",
-                            label: ["接电话岁微内核你", "阿双方各施工好的好的"],
-                            lastUpdate: "2020-11-19 17:05:18",
-                            name: "个环境接口",
-                            note: "1",
-                            pic: "f1e7da10-1994-11eb-9680-fdc5a286ca5f.png",
-                            projectId: "Pj1101050029",
-                            state: 0,
-                            statistics: {},
-                            version: "2.1.0",
-                        },
-                        {
-                            available: true,
-                            buildingId: "1",
-                            categoryId: "120103",
-                            createTime: "2020-10-29 11:15:08",
-                            floorId: "1",
-                            graphId: "2dd925178d164a96941c34326ad340e8",
-                            id: "376f578716fb48febe8fb291b527169f33333",
-                            label: ["接电话岁微内核你"],
-                            lastUpdate: "2020-11-19 17:05:18",
-                            name: "个环境接口",
-                            note: "1",
-                            pic: "f1e7da10-1994-11eb-9680-fdc5a286ca5f.png",
-                            projectId: "Pj1101050029",
-                            state: 0,
-                            statistics: {},
-                            version: "2.1.0",
-                        },
-                    ],
-                },
-            ],
-        },
-        {
-            buildingId: "123B",
-            buildingName: "建筑B座",
-            floorList: [
-                {
-                    floorId: "1",
-                    floorName: "1层",
-                    floor: [
-                        {
-                            available: true,
-                            buildingId: "1",
-                            categoryId: "120103",
-                            createTime: "2020-10-29 11:15:08",
-                            floorId: "1",
-                            graphId: "2dd925178d164a96941c34326ad340e8",
-                            id: "376f578716fb48febe8fb291b527169f4444",
-                            label: ["阿双方各施工好的好的"],
-                            lastUpdate: "2020-11-19 17:05:18",
-                            name: "个环境接口",
-                            note: "1",
-                            pic: "f1e7da10-1994-11eb-9680-fdc5a286ca5f.png",
-                            projectId: "Pj1101050029",
-                            state: 0,
-                            statistics: {},
-                            version: "2.1.0",
-                        },
-                        {
-                            available: true,
-                            buildingId: "1",
-                            categoryId: "120103",
-                            createTime: "2020-10-29 11:15:08",
-                            floorId: "1",
-                            graphId: "2dd925178d164a96941c34326ad340e8",
-                            id: "376f578716fb48febe8fb291b527169f5555",
-                            label: ["阿双方各施工好的好的"],
-                            lastUpdate: "2020-11-19 17:05:18",
-                            name: "个环境接口",
-                            note: "1",
-                            pic: "f1e7da10-1994-11eb-9680-fdc5a286ca5f.png",
-                            projectId: "Pj1101050029",
-                            state: 0,
-                            statistics: {},
-                            version: "2.1.0",
-                        },
-                    ],
-                },
-            ],
-        },
-    ],
-    message: "",
-    pageNumber: 1,
-    pageSize: 50,
-    result: "success",
-    total: 1,
-};
-export { yfbMocKdata };

+ 52 - 0
src/views/svgKey.json

@@ -0,0 +1,52 @@
+{
+    "直流屏": "1611310993089.svg",
+    "直梯": "1611310993087.svg",
+    "DDC": "1611310993085.svg",
+    "照明控制箱": "1611310993091.svg",
+    "硬盘录像机": "1611310993092.svg",
+
+    "消火栓箱": "1611310993096.svg",
+    "消火栓供水加压泵": "1611310993097.svg",
+    "新风机组": "1611310993094.svg",
+    "消防水箱": "1611310993099.svg",
+
+    "消防手动报警按钮": "1611310993100.svg",
+    "污废水一体式提升机组": "1611310993104.svg",
+    "消防喷头": "1611310993102.svg",
+    "温度传感器": "1611310993105.svg",
+
+    "通风风机": "1611310993108.svg",
+    "位移传感器": "1611310993107.svg",
+
+    "停车位": "1611310993110.svg",
+
+    "湿度传感器": "1611310993112.svg",
+    "生活给水水泵": "1611310993115.svg",
+    "生活热水水泵": "1611310993114.svg",
+    "生活给水储水箱": "1611310993117.svg",
+
+    "人流量传感器": "1611310993119.svg",
+    "热风幕": "1611310993120.svg",
+    "潜污泵": "1611310993122.svg",
+    "浓度传感器": "1611310993125.svg",
+    "喷淋供水加压泵": "1611310993124.svg",
+    "门禁主机": "1611310993127.svg",
+    "门禁门锁": "1611310993129.svg",
+    "门禁控制箱": "1611310993131.svg",
+    "门": "1611310993132.svg",
+    "楼梯": "1611310993134.svg",
+    "空调机组": "1611310993135.svg",
+    "监控摄像头": "1611310993139.svg",
+    "监控主机": "1611310993137.svg",
+    "监控前端设备": "1611310993140.svg",
+    
+    "集水坑": "1611310993142.svg",
+    "火灾探测器": "1611310993143.svg",
+    "隔油池": "1611310993145.svg",
+    "高压开关柜": "1611310993146.svg",
+    "扶梯": "1611310993148.svg",
+    "风机盘管": "1611310993150.svg",
+    "防火卷帘门": "1611310993151.svg",
+    "窗": "1611310993153.svg",
+    "变压器": "1611310993155.svg"
+}

+ 154 - 0
src/views/uploadEquipmentSvg.vue

@@ -0,0 +1,154 @@
+<template>
+    <div class="upload-equipment-svg">
+        <el-upload
+            class="upload-svg"
+            action="#"
+            :on-preview="handlePreview"
+            :on-remove="handleRemove"
+            :before-remove="beforeRemove"
+            multiple
+            drag
+            :file-list="fileList"
+            :show-file-list="false"
+            :http-request="uploadSvg"
+        >
+            <div class="el-upload__text">将多个设备图标svg文件拖到此处,或<em>点击上传</em></div>
+        </el-upload>
+        <div class="file-list">
+            <h1>svg文件名:键值</h1>
+            <div class="file" v-for="file in fileList" :key="file.name">{{ file.svgName }} : {{ file.key }}</div>
+        </div>
+    </div>
+</template>
+<script>
+/**
+ * 上传设备svg图标页面
+ */
+import { imgServeUpload } from "@/api/imageservice";
+export default {
+    name: "icon",
+    props: {},
+    data() {
+        return {
+            fileList: [],
+        };
+    },
+    components: {},
+    beforeMount() {},
+    mounted() {
+        window.__svg = this;
+    },
+    methods: {
+        // 上传svg文件
+        uploadSvg(resData) {
+            const { file } = resData;
+            // eslint-disable-next-line @typescript-eslint/no-this-alias
+            const that = this;
+            const fileReader = new FileReader();
+            fileReader.readAsDataURL(file); //读取图片
+            // console.log(file);
+            const ftype = file.type;
+            const fname = file.name;
+            const uploadKey = file.uid;
+            const imgType = ftype.split(".")[ftype.length - 1];
+            fileReader.addEventListener("load", function () {
+                // 读取完成
+                const res = fileReader.result;
+                //将canvas的base64位图片转换成图片png的file
+                const blob = that.dataURLtoBlob(res, ftype);
+                //将其转换成file对象
+                const file = new File([blob], fname, {
+                    type: ftype,
+                    lastModified: Date.now(),
+                }); //blob转file
+
+                // try sending
+                const reader = new FileReader();
+                const fileType = file.name.split(".");
+                const imgType = fileType[fileType.length - 1];
+                const CreateTime = that.formatDate(new Date(file.lastModified));
+                reader.onloadend = function () {
+                    // 这个事件在读取结束后,无论成功或者失败都会触发
+                    // eslint-disable-next-line no-empty
+                    if (reader.error) {
+                    } else {
+                        // 构造 XMLHttpRequest 对象,发送文件 Binary 数据
+                        const xhr = new XMLHttpRequest();
+                        xhr.open("POST", `${imgServeUpload}${uploadKey}.${imgType}`);
+                        xhr.send(reader.result);
+                        xhr.onreadystatechange = function () {
+                            if (xhr.readyState == 4) {
+                                if (xhr.status == 200) {
+                                    const key = uploadKey + "." + imgType;
+                                    console.log(key, fname);
+                                    const svgName = fname.split(".svg")[0];
+                                    that.fileList.push({ svgName, key });
+                                    that.$message.success("上传成功!");
+                                }
+                            }
+                        };
+                    }
+                };
+                reader.readAsArrayBuffer(file);
+            });
+        },
+        dataURLtoBlob(dataURI, type) {
+            const binary = atob(dataURI.split(",")[1]);
+            const array = [];
+            for (let i = 0; i < binary.length; i++) {
+                array.push(binary.charCodeAt(i));
+            }
+            return new Blob([new Uint8Array(array)], { type: type });
+        },
+        formatDate(now) {
+            const year = now.getFullYear();
+            const month = now.getMonth() + 1;
+            const date = now.getDate();
+            const hour = now.getHours();
+            const minute = now.getMinutes();
+            const second = now.getSeconds();
+            return (
+                year +
+                "-" +
+                month +
+                "-" +
+                (date > 10 ? date : "0" + date) +
+                " " +
+                hour +
+                ":" +
+                (minute > 10 ? minute : "0" + minute) +
+                ":" +
+                (second > 10 ? second : "0" + second)
+            );
+        },
+        handleRemove(file, fileList) {
+            console.log(file, fileList);
+        },
+        handlePreview(file) {
+            console.log(file);
+        },
+        beforeRemove(file, fileList) {
+            return this.$confirm(`确定移除 ${file.name}?`);
+        },
+    },
+};
+</script>
+<style lang='less' scoped>
+.upload-equipment-svg {
+    width: 100%;
+    height: 100%;
+    padding: 50px;
+    /deep/ .el-upload-dragger {
+        display: flex;
+        justify-content: center;
+        align-items: center;
+    }
+    .file-list {
+        margin-top: 10px;
+        user-select: text !important;
+        .file {
+            user-select: text !important;
+        }
+    }
+}
+</style>