ant design pro 实现审核图片盖章功能

介绍: 鼠标变成图章,点击后,在图片对应位置加盖公章功能。

如图所示:
在这里插入图片描述
源代码:

import { Card, Modal} from 'antd';
import React, { Component } from 'react';
import { connect } from 'dva';
const { confirm } = Modal;
@connect(({ project, loading }) => ({
    project: project,
    loading: loading.models.project,
}))
@Form.create()

export default class AidCheck extends Component {

    constructor(porps) {
        super(porps);
        this.state = {
            value: {
                files:[]
            },
            //后台需要数据
            pointerArr:[],
            //鼠标图案
            cursorImg:'url(https://cdn.jsdelivr.net/gh/moezx/cdn@3.1.9/img/Sakura/cursor/normal.cur), auto',
            //章图案
            chapterImg:'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1523059142,3498552467&fm=26&gp=0.jpg'

        }
    }

    componentDidMount = () => {
        document.getElementById('img').style.cursor = this.state.cursorImg
    }


    handleSeal = () => {//盖章
      //提交pointerArr数据给后台
    }
    handCancelSeal = () => { //取消盖章
        let paras = document.getElementsByClassName('chapterImg');
        while (paras[0]) {
            paras[0].parentNode.removeChild(paras[0]);
        }
        this.setState({
            pointerArr:[]
        })
    }
    getPosition = (e,index)=>{
        e.persist()
        const { chapterImg } = this.state
        let x = e.clientX - e.target.x;
        let y = e.clientY - e.target.y;
        //或者
        //let x = Math.abs(currentE.clientX - currentE.target.x);
        //let y = Math.abs(currentE.clientY - currentE.target.y);
        let arr = []

        confirm({
            title: '确认在此处盖章嘛?',
            content: '',
            okText: '确认',
            cancelText: '取消',
            onOk:()=>{
                let IMG = document.createElement('img')
                IMG.src = chapterImg
                IMG.style.width = '130px'
                IMG.style.height = '130px'
                IMG.className = 'chapterImg'
                IMG.style.position = 'absolute'
                IMG.style.top = e.pageY - 180 +'px'
                IMG.style.left = x-40+'px' 
                //或者 
                //IMG.style.left = currentE.clientX - (currentE.target.offsetLeft + currentE.target.offsetWidth + 250 )+'px'
                document.getElementById('img').appendChild(IMG)
                arr.push({
                    index,
                    x,
                    y
                })
                this.setState({
                    pointerArr:arr
                })
            },
            onCancel() {
              console.log('Cancel');
            },
        });
        console.log(e,index ,x,y)
        console.log(x,y,'---')
    }

    render() {
        const { value} = this.state;
        return (
              <Card bordered={false} title="协议预览" style={{flex:1,marginLeft:'10px',position:'relative'}} id='img'>
                  {value.files.map((i,index)=><img src={i.sourceUrl} style={{ width: '595px', height: 'auto', display:'block'}} onClick={(e)=>this.getPosition(e,index)}/>)}
              </Card> 
        )
    }
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

刘斩仙的笔记本

富贵险中求

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值