element-ui Mark the coordinate points after uploading the picture

element-ui Mark the coordinate points after uploading the picture

What is element-ui

element-ui is a desktop component library based on Vue.js 2.0 launched by the front-end team of Ele.me for developers, designers and product managers, while the corresponding framework for mobile phones is Mint UI. The entire UI style is simple and practical, and it also greatly improves the efficiency of developers. It is a very popular component library.

The page is roughly as follows:

The component uses the layer.open popup window of layui.

On the left is the form information and on the right is the drawing area.

Original file mapForm.vue

<template>
    <div class="mapForm">
        <div class="left">
            <el-form ref="form" :model="form" :rules="rules" label-width="160px">
                <el-form-item label="Map Name" prop="mapName">
                    <el-input v-model="form.mapName" size="mini" clearable class="formInputClass"></el-input>
                </el-form-item>
                <el-form-item label="Map description" prop="remarks">
                    <el-input type="textarea" v-model="form.remarks" size="mini" clearable class="formInputClass"></el-input>
                </el-form-item>
                <el-form-item label="Point information" prop="" v-if="mapList.length > 0">
                    <div class="mapContent">
                        <div v-for="(map,key) in mapList" :key="key">
                            <div class="pointAbscissaOrdinate"><span>Point coordinates {{key+1}}: {{map.abscissa}}-{{map.ordinate}}</span></div>
                            <el-select v-model="mapList[key]['point']" placeholder="Please select" class="selectClass" @change="changePoint">
                                <el-option v-for="(item, key) in pointList" :key="key" :label="item.name" :value="item.point">
                                </el-option>
                            </el-select>
                        </div>
                    </div>
                </el-form-item>
                <div class="btn">
                    <el-button @click="checkParams" type="primary">Submit</el-button>
                </div>
            </el-form>
        </div>
        <div class="right" id="">
            <div class="imgDiv" id="imgDiv" v-loading="loadStage">
                <img :src="fileSrc" width="1100" height="720" id="imgPainter" />
                <div class="marker" v-for="(item, key) in mapList" :key="key" :style="{top: item.ordinate+'px', 'left': item.abscissa+'px'}" @contextmenu.prevent="clearMarker(key)">
                    {{key+1}}
                    <div class="ponint">{{item.point}}</div>
                </div>
            </div>
            <div class="uploadBtn">
                <el-upload class="upload-demo" ref="upload" action="" :on-change="handleChange" :show-file-list="false" :on-remove="handleRemove" :auto-upload="false" style="display:inline-block;">
                    <el-button slot="trigger" size="mini" type="primary">Select file</el-button>
                </el-upload>
                <el-button @click="clearPic" type="danger">Clear all points</el-button>
            </div>
            <div class="info"><i class="el-icon-info"></i>Display size is 1100px*720px</div>
            <div class="info"><i class="el-icon-info"></i>Left mouse button punctuation in the picture frame</div>
            <div class="info"><i class="el-icon-info"></i>Right-click the marked point in the picture frame to delete the point</div>
        </div>
    </div>
</template>
<script>
export default {
    name: 'mapFormComponent',
    data() {
        return {
            form: {
                mapName: "",
            },
            rules:
                mapName: [
                    { required: true, message: "Please enter a map name", trigger: "blur" },
                ],
            },
            fileList: [],
            fileSrc: '',
            pointList: [
                { name: "Discharge port 1", point: "@FQ01" },
                { name: "Discharge port 2", point: "@FQ02" },
            ],
            mapList: [], //Array of zebra crossings canBiaoZhu: true, //Can it be marked pointColor: 'red', //Point color pointSize: 20, //Point size pointSelectList: {},
            notifyId: {},
            loadStage: false,
        };
    },
    created() { },
    mounted() {
        //Drawing area event binding let _this = this;
        if (document.getElementById('imgPainter')) {
            document.getElementById('imgPainter').onmousedown = (e) => {
                e = e || window.event
                if (e.button !== 2) { //Judge whether to right-click if (this.canBiaoZhu && this.fileSrc != '') { //Judge whether it is possible to mark and upload pictures var x = e.offsetX || e.layerX
                        var y = e.offsetY || e.layerY
                        this.mapList.push({
                            id: this.mapList.length + 1,
                            name: '',
                            abscissa: x,
                            coordinate: y,
                        })
                        // Set variables // this.pointSelectList.$set(0);
                        let key = `point`;
                        _this.$set(this.mapList[this.mapList.length - 1], key, "")
                    } else {
                        //Prompt to upload a picture// Only display once if (_this.notifyId.id)
                            _this.notifyId.close();
                        this.notifyId = _this.$notify.error({
                            title: 'Prompt information',
                            message: 'Please upload the image first and then add punctuation',
                            showClose: true,
                        });
                    }
                } else {
                    return false
                }
            }
        }
        // Right click to prevent var oDiv1 = document.getElementById('imgDiv');
        oDiv1.oncontextmenu = function (ev) {
            var e = e || window.event;
            //Prevent bubbling e.cancelBubble = true;
            //Prevent triggering of default event e.returnValue = false;
        }
    },
    methods: {
        changePoint() {
            /**point change */
            this.$forceUpdate();
        },
        clearMarker(index) {
            /**Clear marker */
            this.mapList.splice(index, 1);
        },
        handleChange(file, fileList) {
            this.loadStage = true;
            let fileName = file.name;
            let regex = /(.jpg|.jpeg|.gif|.png|.bmp)$/;
            if (regex.test(fileName.toLowerCase())) {
                this.fileSrc = URL.createObjectURL(file.raw) // Get the URL
                console.log(this.fileSrc);
            } else {
                this.$message.error('Please select the image file');
            }
            this.loadStage = false;
        },
        clearPic() {
            /**Clear image*/
            this.mapList = [];
        },
        checkParams() {
            /***
             * Verify submission information */
            this.$refs["form"].validate((valid) => {
                if (valid) {
                    let params = this.form;
                    this.submit(params);
                }
            });
        },
        async submit(params) {
            /**submit*/
            let resp = await this.$api.companyApiList
                .addEditCompany(params);
            if (resp.data.code != "error") {
                // Determine whether to add or modify this.$notify.success({
                    title: "Tips",
                    message: resp.data.msg,
                    showClose: true,
                });
                let type = params.id && params.id != '' ? 'edit' : 'add';
                this.$emit("update", type);
                // Clear form data this.$refs.form.resetFields();
            }
        },
    },
};
</script>
<style scoped lang="less">
/**
  Form style*/
.mapForm {
    display: flex;
    padding: 10px;
    border: 1px solid pink;
    .left {
        flex: 2;
        border-right: 1px dashed pink;
        margin-right: 4px;
        .mapContent {
            height: 700px;
            overflow-y: auto;
            .selectClass {
                margin: 0px 5px;
            }
            .pointAbscissaOrdinate {
                display: inline-block;
                width: 140px;
            }
        }
    }
    .right {
        flex: 8;
        // border: 1px solid pink;
        max-width: 1100px;
        .imgDiv {
            position: relative;
            height: 720px;
            border: 2px solid cornflowerblue;
            .marker {
                position: absolute;
                border-radius: 50%;
                z-index: 999;
                width: 20px;
                height: 20px;
                background-color: red;
                text-align: center;
                line-height: 20px;
                color: yellow;
                .ponint {
                    display: block;
                    position: absolute;
                    left: 20px;
                    top: 0px;
                    font-size: 12px;
                    color: blue;
                }
            }
            .marker:hover .ponint {
                display: block;
            }
        }
        .info {
            font-size: 12px;
        }
        .uploadBtn {
            margin: 10px 0px;
        }
    }
    .btn {
        padding-left: 160px;
    }
}
.formInputClass {
    width: 200px;
}
</style>

The effects of punctuation are as follows:

This is the end of this article about element-ui marking coordinate points after uploading pictures. For more relevant element-ui uploading picture content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Solution to Element-ui upload file upload restriction
  • Implementation of uploading multiple files at once with el-upload in element-ui
  • Element-ui file upload method to modify the file name example
  • Detailed explanation of the front-end processing of uploaded files in Element-UI
  • Element-ui hides the upload button function after uploading a picture
  • Element-ui implementation example of multiple file upload
  • Use of vue-cli3.0+element-ui upload component el-upload

<<:  Example of how to change the domestic source in Ubuntu 18.04

>>:  How to import Chinese data into csv in Navicat for SQLite

Recommend

CentOS8 installation tutorial of jdk8 / java8 (recommended)

Preface At first, I wanted to use wget to downloa...

About VUE's compilation scope and slot scope slot issues

What are slots? The slot directive is v-slot, whi...

A brief discussion on JS regular RegExp object

Table of contents 1. RegExp object 2. Grammar 2.1...

jQuery plugin to implement minesweeper game (2)

This article shares the second article of using j...

MySQL helps you understand index pushdown in seconds

Table of contents 1. The principle of index push-...

Implementation of Redis master-slave cluster based on Docker

Table of contents 1. Pull the Redis image 2. Crea...

CSS example code to hide the scroll bar and scroll the content

Preface When the HTML structure of a page contain...

Notes on using the blockquote tag

<br />Semanticization cannot be explained in...

Detailed explanation of MySQL high availability architecture

Table of contents introduction MySQL High Availab...

js realizes two-way data binding (accessor monitoring)

This article example shares the specific code of ...

How to implement a binary search tree using JavaScript

One of the most commonly used and discussed data ...