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

Briefly describe mysql monitoring group replication

Original text: https://dev.mysql.com/doc/refman/8...

mysql 5.7.18 winx64 free installation configuration method

1. Download 2. Decompression 3. Add the path envi...

How to call a piece of HTML code together on multiple HTML pages

Method 1: Use script method: Create a common head...

Detailed explanation of log processing of Docker containers

Docker has many log plug-ins. The default is to u...

MySQL 5.7 installation-free configuration graphic tutorial

Mysql is a popular and easy-to-use database softw...

80 lines of code to write a Webpack plugin and publish it to npm

1. Introduction I have been studying the principl...

Tutorial on installing Tomcat server under Windows

1 Download and prepare First, we need to download...

How to install docker on ubuntu20.04 LTS

Zero: Uninstall old version Older versions of Doc...

Summary of the differences between Vue's watch, computed, and methods

Table of contents 1 Introduction 2 Basic usage 2....

Solve the problem of MySQL using not in to include null values

Notice! ! ! select * from user where uid not in (...

Learning Vue instructions

Table of contents 1. v-text (v-instruction name =...