PPTist 画布工具栏

画布工具组件:

画布工具栏分类:

主要分布有左侧工具栏、中间插入元素工具栏以及右侧画布缩放工具栏三类

左侧工具栏
  • 撤销/重做:通过 useHistorySnapshot 实现

  • 面板切换:批注面板、选择窗格、查找替换

  • 响应式:小屏时收起为"更多"菜单

    //撤销重做
中间插入元素工具栏

insert-handler-item类名的里面是有下拉弹窗和弹窗组成的,popover说明只是弹窗的样式

  • 下拉框和弹窗构成
  • 弹窗构成
文本框

默认点击的时候选择横向文本框,vertical默认为false,点击垂直文本框的时候vertical为true,用来通知创建状态,这些方法设置创建状态,实际创建在画布上拖拽完成后触发。

复制代码
<div class="insert-handler-item group-btn" :class="{ 'active': creatingElement?.type === 'text' }" v-tooltip="'插入文字'">
  <div class="group-btn-main" @click="drawText()"><IconFontSize class="icon" /> <span class="text">文本框</span></div>

  <Popover trigger="click" v-model:value="textTypeSelectVisible" style="height: 100%;" :offset="10">
    <template #content>
      <PopoverMenuItem center @click="() => { drawText(); textTypeSelectVisible = false }"><IconTextRotationNone class="icon" /> 横向文本框</PopoverMenuItem>
      <PopoverMenuItem center @click="() => { drawText(true); textTypeSelectVisible = false }"><IconTextRotationDown class="icon" /> 竖向文本框</PopoverMenuItem>
    </template>
    <IconDown class="arrow" />
  </Popover>
</div>

const drawText = (vertical = false) => {
  mainStore.setCreatingElement({
    type: 'text',
    vertical,
  })
}

形状的同上,下次可以针对mainStore单独讲解一期他的状态

复制代码
// 绘制文字范围
const drawText = (vertical = false) => {
  mainStore.setCreatingElement({
    type: 'text',
    vertical,
  })
}

// 绘制形状范围
const drawShape = (shape: ShapePoolItem) => {
  mainStore.setCreatingElement({
    type: 'shape',
    data: shape,
  })
  shapePoolVisible.value = false
}

// 绘制自定义任意多边形
const drawCustomShape = () => {
  mainStore.setCreatingCustomShapeState(true)
  shapePoolVisible.value = false
}

// 绘制线条路径
const drawLine = (line: LinePoolItem) => {
  mainStore.setCreatingElement({
    type: 'line',
    data: line,
  })
  linePoolVisible.value = false
}

这是创建文本元素的几个状态:

复制代码
export interface CreatingTextElement {
  type: 'text'
  vertical?: boolean
}
export interface CreatingShapeElement {
  type: 'shape'
  data: ShapePoolItem
}
export interface CreatingLineElement {
  type: 'line'
  data: LinePoolItem
}
export type CreatingElement = CreatingTextElement | CreatingShapeElement | CreatingLineElement
图片
复制代码
const insertImageElement = (files: FileList) => {
  const imageFile = files[0]
  if (!imageFile) return
  getImageDataURL(imageFile).then(dataURL => createImageElement(dataURL))
}
线条

点击"线条"按钮会弹出 LinePool 组件,显示预设线条列表LinePool,LinePool 组件从 LINE_LIST 读取预设线条,将点击的线条传递给父组件。

复制代码
// 子组件
const selectLine = (line: LinePoolItem) => {
  emit('select', line)
}

// 父组件
// 绘制线条路径
const drawLine = (line: LinePoolItem) => {
  mainStore.setCreatingElement({
    type: 'line',
    data: line,
  })
  linePoolVisible.value = false
}
图表

从 ChartPool 选择类型,立即创建并插入到画布中心

复制代码
 <Popover trigger="click" v-model:value="chartPoolVisible" :offset="10">
    <template #content>
      <ChartPool @select="chart => { createChartElement(chart); chartPoolVisible = false }" />
    </template>
    <div class="insert-handler-item" v-tooltip="'插入图表'">
      <IconChartProportion class="icon" /> <span class="text">图表</span>
    </div>
  </Popover>

其他的都类似

右边工具栏
画布缩小和放大
复制代码
  <IconMinus class="handler-item viewport-size" v-tooltip="'画布缩小(Ctrl + -)'" @click="scaleCanvas('-')" />
  <IconPlus class="handler-item viewport-size" v-tooltip="'画布放大(Ctrl + =)'" @click="scaleCanvas('+')" />
缩放比例显示与预设
  • 功能:显示当前缩放比例,点击弹出预设菜单

  • 预设:200%、150%、125%、100%、75%、50%

  • 适应屏幕:一键重置到 90%

    {{ canvasScalePercentage }}
相关推荐
Ivanqhz1 小时前
Ping-Pong 双缓冲
开发语言·人工智能·python·深度学习·mlir
名字还没想好☜1 小时前
React 文件上传实战:预览 URL 回收、多文件逐个进度与拖拽放置区踩坑
前端·react·next.js
m0_734571761 小时前
深入理解C++ RAII
开发语言·c++
console.log('npc')1 小时前
06 — Model 层:数据模型与操作
前端·后端·node.js·express
泡海椒1 小时前
jquick-pdf 表格实战:动态数据 PDF 报表生成
java·开发语言·pdf
aramae2 小时前
模拟实现memset()(C语言)
c语言·开发语言·后端
linux_cfan2 小时前
16 · `custom-media-element`:属性拦截与转发
前端·javascript·音视频
右耳朵猫AI2 小时前
Web前端周刊2026W38 | React 19.3 发布、StyleX 深潜、jsdom 30.1 提速
前端·javascript·react.js·typescript·node.js
落魄大学生之流水线上谋生计2 小时前
GreenLife Carbon · OpenHarmony 智慧低碳生态平台
javascript
wuyk5552 小时前
【Socket 进阶之路】第 7 章 IO 多路复用 select & poll 完整实战|多 fd 监听、超时等待、优缺点横向对比
服务器·开发语言·网络·数据库·物联网