index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. <template>
  2. <div class="canvas-tool">
  3. <div class="left-handler">
  4. <div class="leftHandler-item" :class="{ disable: !canUndo }" v-tooltip="'撤销(Ctrl + Z)'" @click="undo()">
  5. <img src="./imgs/cx.png" alt="" />
  6. <div>撤销</div>
  7. </div>
  8. <div class="leftHandler-item" :class="{ disable: !canRedo }" v-tooltip="'恢复(Ctrl + Y)'" @click="redo()">
  9. <img src="./imgs/hf.png" alt="" />
  10. <div>恢复</div>
  11. </div>
  12. <div class="line"></div>
  13. <div class="leftHandler-item" :class="{ active: showNotesPanel }" v-tooltip="'批注'" @click="toggleNotesPanel()">
  14. <img src="./imgs/pz.png" alt="" />
  15. <div>批注</div>
  16. </div>
  17. <div class="leftHandler-item" :class="{ active: showSelectPanel }" v-tooltip="'选择'" @click="toggleSelectPanel()">
  18. <img src="./imgs/xz.png" alt="" />
  19. <div>选择</div>
  20. </div>
  21. <div class="leftHandler-item" :class="{ active: showSearchPanel }" v-tooltip="'查找/替换(Ctrl + F)'" @click="toggleSraechPanel()">
  22. <img src="./imgs/cz.png" alt="" />
  23. <div>查找</div>
  24. </div>
  25. <div class="line"></div>
  26. <Popover trigger="click" center>
  27. <template #content>
  28. <PopoverMenuItem @click="enterScreeningFromStart()">从头开始</PopoverMenuItem>
  29. <PopoverMenuItem @click="enterScreening()">从当前页开始</PopoverMenuItem>
  30. </template>
  31. <div class="arrow-btn">
  32. <div>播放</div>
  33. </div>
  34. </Popover>
  35. </div>
  36. <div class="add-element-handler">
  37. <FileInput @change="files => insertImageElement(files)">
  38. <div class="handler-item">
  39. <img class="itemImg" src="./imgs/sctp.png" alt="" />
  40. <div class="tit">图片</div>
  41. </div>
  42. </FileInput>
  43. <ElUpload
  44. action=""
  45. :show-file-list="false"
  46. accept=".mp4,.avi,.flv,.mp3,.wav,.m4a"
  47. :http-request="
  48. (fileData: any) => {
  49. handleUpload(fileData)
  50. return undefined
  51. }
  52. "
  53. >
  54. <div class="handler-item">
  55. <img class="itemImg" src="./imgs/scysp.png" alt="" />
  56. <div class="tit">音视频</div>
  57. </div>
  58. </ElUpload>
  59. <div class="handler-item" @click="cloudCoachVisible = true">
  60. <img class="itemImg" src="./imgs/yp.png" alt="" />
  61. <div class="tit">乐谱</div>
  62. </div>
  63. <!-- <div class="handler-item">
  64. <img class="itemImg" src="./imgs/jzlx.png" alt="" />
  65. <div class="tit">节奏练习</div>
  66. </div>
  67. <div class="handler-item">
  68. <img class="itemImg" src="./imgs/tylx.png" alt="" />
  69. <div class="tit">听音练习</div>
  70. </div>
  71. <div class="handler-item">
  72. <img class="itemImg" src="./imgs/zyk.png" alt="" />
  73. <div class="tit">资源库</div>
  74. </div> -->
  75. <div class="handler-item" @click="drawText()" :class="{ active: creatingElement?.type === 'text' }">
  76. <img class="itemImg" src="./imgs/wz.png" alt="" />
  77. <Popover trigger="click" v-model:value="textTypeSelectVisible" :offset="10">
  78. <template #content>
  79. <PopoverMenuItem
  80. center
  81. @click="
  82. () => {
  83. drawText()
  84. textTypeSelectVisible = false
  85. }
  86. "
  87. ><IconTextRotationNone /> 横向文本框</PopoverMenuItem
  88. >
  89. <PopoverMenuItem
  90. center
  91. @click="
  92. () => {
  93. drawText(true)
  94. textTypeSelectVisible = false
  95. }
  96. "
  97. ><IconTextRotationDown /> 竖向文本框</PopoverMenuItem
  98. >
  99. </template>
  100. <div class="charTit tit">
  101. <div>文字</div>
  102. <img src="./imgs/jiantou.png" alt="" />
  103. </div>
  104. </Popover>
  105. </div>
  106. <div class="handler-item" :class="{ active: creatingCustomShape || creatingElement?.type === 'shape' }" @click="shapePoolVisible = true">
  107. <Popover trigger="click" v-model:value="shapePoolVisible" :offset="10">
  108. <template #content>
  109. <ShapePool @select="shape => drawShape(shape)" />
  110. </template>
  111. <img class="itemImg" src="./imgs/xz1.png" alt="" />
  112. </Popover>
  113. <Popover trigger="click" v-model:value="shapeMenuVisible" :offset="10" @click.stop>
  114. <template #content>
  115. <PopoverMenuItem
  116. center
  117. @click="
  118. () => {
  119. drawCustomShape()
  120. shapeMenuVisible = false
  121. }
  122. "
  123. >自由绘制</PopoverMenuItem
  124. >
  125. </template>
  126. <div class="charTit tit">
  127. <div>形状</div>
  128. <img src="./imgs/jiantou.png" alt="" />
  129. </div>
  130. </Popover>
  131. </div>
  132. <div class="handler-item" :class="{ active: creatingElement?.type === 'line' }" @click="linePoolVisible = true">
  133. <img class="itemImg" src="./imgs/xt.png" alt="" />
  134. <Popover trigger="click" v-model:value="linePoolVisible" :offset="10" @click.stop>
  135. <template #content>
  136. <LinePool @select="line => drawLine(line)" />
  137. </template>
  138. <div class="tit">线条</div>
  139. </Popover>
  140. </div>
  141. <div class="handler-item" @click="moreToolsVisible = true">
  142. <img class="itemImg" src="./imgs/gdgj.png" alt="" />
  143. <Popover trigger="click" v-model:value="moreToolsVisible" :offset="10" @click.stop>
  144. <template #content>
  145. <PopoverMenuItem @click="chartPoolVisible = true">
  146. <Popover trigger="click" v-model:value="chartPoolVisible" placement="right" :offsetOne="50" :offset="36">
  147. <template #content>
  148. <ChartPool
  149. @select="
  150. chart => {
  151. createChartElement(chart)
  152. chartPoolVisible = false
  153. }
  154. "
  155. />
  156. </template>
  157. <div class="menuItem">
  158. <img src="./imgs/tb.png" alt="" />
  159. <div class="tit">图表</div>
  160. </div>
  161. </Popover>
  162. </PopoverMenuItem>
  163. <PopoverMenuItem @click="tableGeneratorVisible = true">
  164. <div class="menuItem">
  165. <img src="./imgs/bg.png" alt="" />
  166. <div class="tit">表格</div>
  167. </div>
  168. </PopoverMenuItem>
  169. <PopoverMenuItem
  170. @click="
  171. () => {
  172. moreToolsVisible = false
  173. latexEditorVisible = true
  174. }
  175. "
  176. >
  177. <div class="menuItem">
  178. <img src="./imgs/gs.png" alt="" />
  179. <div class="tit">公式</div>
  180. </div>
  181. </PopoverMenuItem>
  182. </template>
  183. <div class="tit">更多工具</div>
  184. </Popover>
  185. <Popover trigger="click" v-model:value="tableGeneratorVisible" placement="right" :offsetOne="200" :offset="70">
  186. <template #content>
  187. <TableGenerator
  188. @close="tableGeneratorVisible = false"
  189. @insert="
  190. ({ row, col }) => {
  191. createTableElement(row, col)
  192. tableGeneratorVisible = false
  193. }
  194. "
  195. />
  196. </template>
  197. </Popover>
  198. </div>
  199. </div>
  200. <div class="right-handler">
  201. <IconMinus class="rightHandler-item" v-tooltip="'画布缩小(Ctrl + -)'" @click="scaleCanvas('-')" />
  202. <Popover trigger="click" v-model:value="canvasScaleVisible">
  203. <template #content>
  204. <PopoverMenuItem center v-for="item in canvasScalePresetList" :key="item" @click="applyCanvasPresetScale(item)"
  205. >{{ item }}%</PopoverMenuItem
  206. >
  207. <PopoverMenuItem center @click="resetCanvas()">适应屏幕</PopoverMenuItem>
  208. </template>
  209. <div class="text" :class="{ canvasScaleVisible: canvasScaleVisible }">{{ canvasScalePercentage }}</div>
  210. </Popover>
  211. <IconPlus class="rightHandler-item" v-tooltip="'画布放大(Ctrl + =)'" @click="scaleCanvas('+')" />
  212. <IconFullScreen class="rightHandler-item resetCanvas" v-tooltip="'适应屏幕(Ctrl + 0)'" @click="resetCanvas()" />
  213. </div>
  214. <Modal v-model:visible="latexEditorVisible" :width="880">
  215. <LaTeXEditor
  216. @close="latexEditorVisible = false"
  217. @update="
  218. data => {
  219. createLatexElement(data)
  220. latexEditorVisible = false
  221. }
  222. "
  223. />
  224. </Modal>
  225. <Modal
  226. :contentStyle="{
  227. width: '70%',
  228. minWidth: '1200px',
  229. height: '86%',
  230. boxShadow: '0px 2px 10px 0px rgba(0,0,0,0.08)',
  231. borderRadius: '16px',
  232. border: '1px solid #DEDEDE',
  233. padding: '0'
  234. }"
  235. v-model:visible="cloudCoachVisible"
  236. >
  237. <cloudCoachList
  238. @update="handleCloudCoach"
  239. @close="
  240. () => {
  241. cloudCoachVisible = false
  242. }
  243. "
  244. />
  245. </Modal>
  246. </div>
  247. </template>
  248. <script lang="ts" setup>
  249. import { ref } from "vue"
  250. import { storeToRefs } from "pinia"
  251. import { useMainStore, useSnapshotStore } from "@/store"
  252. import { getImageDataURL } from "@/utils/image"
  253. import type { ShapePoolItem } from "@/configs/shapes"
  254. import type { LinePoolItem } from "@/configs/lines"
  255. import useScaleCanvas from "@/hooks/useScaleCanvas"
  256. import useHistorySnapshot from "@/hooks/useHistorySnapshot"
  257. import useCreateElement from "@/hooks/useCreateElement"
  258. import useScreening from "@/hooks/useScreening"
  259. import ShapePool from "./ShapePool.vue"
  260. import LinePool from "./LinePool.vue"
  261. import ChartPool from "./ChartPool.vue"
  262. import TableGenerator from "./TableGenerator.vue"
  263. import LaTeXEditor from "@/components/LaTeXEditor/index.vue"
  264. import FileInput from "@/components/FileInput.vue"
  265. import Modal from "@/components/Modal.vue"
  266. import Popover from "@/components/Popover.vue"
  267. import PopoverMenuItem from "@/components/PopoverMenuItem.vue"
  268. import { ElUpload, ElMessage, type UploadRequestOptions } from "element-plus"
  269. import cloudCoachList from "@/views/components/element/cloudCoachElement/cloudCoachList"
  270. import fileUpload from "@/utils/oss-file-upload"
  271. import usePptWork from "@/store/pptWork"
  272. const usePptWorkHook = usePptWork()
  273. const mainStore = useMainStore()
  274. const { creatingElement, creatingCustomShape, showSelectPanel, showSearchPanel, showNotesPanel } = storeToRefs(mainStore)
  275. const { canUndo, canRedo } = storeToRefs(useSnapshotStore())
  276. const { redo, undo } = useHistorySnapshot()
  277. const { scaleCanvas, setCanvasScalePercentage, resetCanvas, canvasScalePercentage } = useScaleCanvas()
  278. const canvasScalePresetList = [200, 150, 125, 100, 75, 50]
  279. const canvasScaleVisible = ref(false)
  280. const { enterScreening, enterScreeningFromStart } = useScreening()
  281. const applyCanvasPresetScale = (value: number) => {
  282. setCanvasScalePercentage(value)
  283. canvasScaleVisible.value = false
  284. }
  285. const {
  286. createImageElement,
  287. createChartElement,
  288. createTableElement,
  289. createLatexElement,
  290. createVideoElement,
  291. createAudioElement,
  292. createCloudCoachElement
  293. } = useCreateElement()
  294. const insertImageElement = (files: FileList) => {
  295. const imageFile = files[0]
  296. if (!imageFile) return
  297. getImageDataURL(imageFile).then(dataURL => createImageElement(dataURL))
  298. }
  299. const shapePoolVisible = ref(false)
  300. const linePoolVisible = ref(false)
  301. const chartPoolVisible = ref(false)
  302. const tableGeneratorVisible = ref(false)
  303. const latexEditorVisible = ref(false)
  304. const textTypeSelectVisible = ref(false)
  305. const shapeMenuVisible = ref(false)
  306. const cloudCoachVisible = ref(false)
  307. const moreToolsVisible = ref(false)
  308. // 音视频
  309. function handleUpload(fileData: UploadRequestOptions) {
  310. const type = /\.(mp3|wav|m4a)$/i.test(fileData.file.name) ? "audio" : "video"
  311. fileUpload(fileData.file.name, fileData.file, `${usePptWorkHook.id}/`)
  312. .then(res => {
  313. if (type === "audio") {
  314. createAudioElement(res)
  315. } else {
  316. createVideoElement(res)
  317. }
  318. })
  319. .catch(() => {
  320. ElMessage({
  321. showClose: true,
  322. message: "上传失败!",
  323. type: "error"
  324. })
  325. })
  326. }
  327. // 处理云教练创建
  328. function handleCloudCoach(id: string, name: string) {
  329. createCloudCoachElement(id, name)
  330. cloudCoachVisible.value = false
  331. }
  332. // 绘制文字范围
  333. const drawText = (vertical = false) => {
  334. mainStore.setCreatingElement({
  335. type: "text",
  336. vertical
  337. })
  338. }
  339. // 绘制形状范围
  340. const drawShape = (shape: ShapePoolItem) => {
  341. mainStore.setCreatingElement({
  342. type: "shape",
  343. data: shape
  344. })
  345. shapePoolVisible.value = false
  346. }
  347. // 绘制自定义任意多边形
  348. const drawCustomShape = () => {
  349. mainStore.setCreatingCustomShapeState(true)
  350. shapePoolVisible.value = false
  351. }
  352. // 绘制线条路径
  353. const drawLine = (line: LinePoolItem) => {
  354. mainStore.setCreatingElement({
  355. type: "line",
  356. data: line
  357. })
  358. linePoolVisible.value = false
  359. }
  360. // 打开选择面板
  361. const toggleSelectPanel = () => {
  362. mainStore.setSelectPanelState(!showSelectPanel.value)
  363. }
  364. // 打开搜索替换面板
  365. const toggleSraechPanel = () => {
  366. mainStore.setSearchPanelState(!showSearchPanel.value)
  367. }
  368. // 打开批注面板
  369. const toggleNotesPanel = () => {
  370. mainStore.setNotesPanelState(!showNotesPanel.value)
  371. }
  372. </script>
  373. <style lang="scss" scoped>
  374. .canvas-tool {
  375. position: relative;
  376. border-bottom: 1px solid $borderColor;
  377. background-color: #fff;
  378. display: flex;
  379. justify-content: space-between;
  380. padding: 0 24px;
  381. user-select: none;
  382. }
  383. .left-handler {
  384. margin-left: -6px;
  385. display: flex;
  386. align-items: center;
  387. .leftHandler-item {
  388. display: flex;
  389. flex-direction: column;
  390. justify-content: center;
  391. align-items: center;
  392. margin-right: 8px;
  393. padding: 4px 6px;
  394. cursor: pointer;
  395. &.disable {
  396. opacity: 0.5;
  397. cursor: not-allowed;
  398. background-color: transparent !important;
  399. }
  400. &:hover,
  401. &.active {
  402. background: rgba(34, 71, 133, 0.08);
  403. border-radius: 6px;
  404. }
  405. & > img {
  406. width: 20px;
  407. height: 20px;
  408. }
  409. & > div {
  410. margin-top: 4px;
  411. font-weight: 400;
  412. font-size: 12px;
  413. color: #131415;
  414. line-height: 17px;
  415. }
  416. }
  417. .line {
  418. margin-left: 6px;
  419. margin-right: 14px;
  420. width: 1px;
  421. height: calc(100% - 20px);
  422. background-color: $borderColor;
  423. }
  424. .arrow-btn {
  425. margin-left: 6px;
  426. display: flex;
  427. align-items: center;
  428. justify-content: center;
  429. width: 60px;
  430. height: 32px;
  431. background: linear-gradient(312deg, #1b7af8 0%, #3cbbff 100%);
  432. border-radius: 6px;
  433. font-weight: 600;
  434. font-size: 14px;
  435. color: #ffffff;
  436. line-height: 20px;
  437. cursor: pointer;
  438. &:hover {
  439. opacity: 0.8;
  440. }
  441. }
  442. }
  443. .add-element-handler {
  444. position: absolute;
  445. top: 50%;
  446. left: 50%;
  447. transform: translate(-50%, -50%);
  448. display: flex;
  449. .handler-item {
  450. display: flex;
  451. flex-direction: column;
  452. align-items: center;
  453. justify-content: center;
  454. cursor: pointer;
  455. width: 68px;
  456. height: 53px;
  457. &:hover,
  458. &.active {
  459. background: rgba(34, 71, 133, 0.08);
  460. border-radius: 6px;
  461. }
  462. .itemImg {
  463. width: 20px;
  464. height: 20px;
  465. }
  466. .tit {
  467. margin-top: 4px;
  468. font-weight: 400;
  469. font-size: 12px;
  470. color: #131415;
  471. line-height: 17px;
  472. }
  473. .charTit {
  474. display: flex;
  475. align-items: center;
  476. padding: 0 6px;
  477. border-radius: 4px;
  478. &:hover {
  479. background: rgba(34, 71, 133, 0.1);
  480. }
  481. > img {
  482. margin-left: 4px;
  483. width: 7px;
  484. height: 4px;
  485. }
  486. }
  487. }
  488. }
  489. .menuItem {
  490. display: flex;
  491. align-items: center;
  492. & > img {
  493. width: 20px;
  494. height: 20px;
  495. }
  496. & > .tit {
  497. margin-left: 16px;
  498. font-weight: 400;
  499. font-size: 14px;
  500. color: #333333;
  501. }
  502. }
  503. .right-handler {
  504. display: flex;
  505. align-items: center;
  506. .text {
  507. margin: 0 8px;
  508. width: 57px;
  509. height: 32px;
  510. line-height: 32px;
  511. text-align: center;
  512. cursor: pointer;
  513. &:hover,
  514. &.canvasScaleVisible {
  515. border-radius: 6px;
  516. background-color: rgba(34, 71, 133, 0.08);
  517. }
  518. }
  519. .rightHandler-item {
  520. font-size: 20px;
  521. color: #131415;
  522. cursor: pointer;
  523. &:hover {
  524. opacity: 0.5;
  525. }
  526. }
  527. .resetCanvas {
  528. margin-left: 20px;
  529. }
  530. }
  531. </style>