imgDialog.vue 1.88 KB
<template>
  <a-modal
    title="图片"
    v-if='isVisible'
    v-model:visible="isVisible"
    width="1200px"
    height='90%'
    class="detail-modal"
  >
    <canvas id="myCanvas"></canvas>
    <img :src="imgUrl" alt="" id="img">
    <template #footer>
      <a-button @click="onCancel">返回</a-button>
    </template>
  </a-modal>
</template>

<script>
import { reactive, ref } from "vue";
export default {
  setup() {
    const isVisible = ref(false);
    const isLoading = ref(false);
    const detailData = ref({});
    const imgUrl = ref()
    const canvas = ref()
    const ctx = ref()
    const initDialog = (url,data) => {
        imgUrl.value = url
        isVisible.value = true;
        setTimeout(()=>{
            var imgscream=document.getElementById("img");
            let height = imgscream.offsetHeight;
            let width = imgscream.offsetWidth;
            canvas.value = document.getElementById("myCanvas");//初始化
            canvas.value.height = height;
            canvas.value.width = width;
            ctx.value = canvas.value.getContext("2d")
            ctx.value.drawImage(imgscream,0,0,width,height);
            ctx.value.beginPath();
            ctx.value.lineWidth = 3
            ctx.value.strokeStyle = "red";  
            ctx.value.moveTo(data.head_x_inSmall, data.head_y_inSmall);//起始位置
            ctx.value.lineTo(data.foot_x_inSmall, data.foot_y_inSmall);//停止位置
            ctx.value.stroke();
        },0)
    };
    const onCancel = () => {
        canvas.value = ''
        isVisible.value = false;
    };

    return {
        isVisible,
        onCancel,
        initDialog,
        isLoading,
        imgUrl,
        detailData
    };
  },
};
</script>
<style lang="less" scoped>
    #myCanvas{
        display: block;
        margin: 0 auto;
    }
    #img{
        position: relative;
        top: -5000px;
        float: left;
    }
</style>