canvas+fabric实现时间刻度尺+长方形数据展示

前言

我们前面实现了时间刻度尺,现在在时间刻度尺里面画一个长方形,长方形里面有数据展示。

效果

实现

1.先实现时间刻度尺

2.鼠标移动、按下事件监听并画出对应效果

3.在刻度尺里面画对应的长方形数据展示

<template>
  <div>
      <canvas id="rulerCanvas" width="1200" height="400"></canvas>

      <div style="margin-top: 20px">
          <el-button type="primary" @click="test0">添加空标记</el-button>
          <el-button type="primary" @click="test1">添加锅</el-button>
          <el-button type="primary" @click="test2">添加用料</el-button>
          <el-button type="primary" @click="test3">添加菜盒</el-button>
          <el-button type="primary" @click="test4">添加结束录制</el-button>
          <el-button type="primary" @click="test5" plain>清空全部</el-button>
      </div>

      <div style="margin-top: 20px">
          <span style="margin-right: 6px">开启鼠标弹框</span><el-switch v-model="value1" />
      </div>

      <el-dialog v-model="dialogVisible" title="添加调料" width="500">
          <div>
              <el-input v-model="input1" style="width: 240px" />
          </div>
          <div style="margin-top: 10px">
              <el-input v-model="input2" style="width: 240px" />
          </div>
          <template #footer>
              <div>
                  <el-button @click="dialogVisible = false">取消</el-button>
                  <el-button type="primary" @click="dialogConfirm">确认</el-button>
              </div>
          </template>
      </el-dialog>
  </div>
</template>
<script setup>
import * as fabric  from 'fabric';
import {ref, onMounted} from 'vue';

const value1 = ref(false);
const dialogVisible = ref(false);
const input1 = ref("测试商品名称");
const input2 = ref("");
const dialogConfirm = () => {
  dialogVisible.value = false;
  console.log("====添加====")
};

let left = 40;

const test0 = () => {
  draw0();
};
const test1 = () => {
  draw1()
};
const test2 = () => {
  draw();
};
const test3 = () => {
  draw();
};
const test4 = () => {
  draw4();
};
const test5 = () => {
  console.log("清空全部");
  // canvas.value.clear();
};

const canvas = ref(null);

onMounted(() => {
  drawRuler();
});


// const onClickItem = ref(false);

const onMouseDown = (options) => {
  if (value1.value) {
    console.log("====onMouseMove====", options);
    let startNumber = options.pointer.x - 40;
    let timeNumber = parseInt(startNumber / 20);
    input2.value = timeToStr(timeNumber);
    dialogVisible.value = true;
  }
};

let movDummyLine = null;
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

An_s

你的鼓励将是我创作的最大动力

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

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

打赏作者

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

抵扣说明:

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

余额充值