YM
2024-11-20 c8d1e1ed1d5c8d20a9aad8554d51001afb3c6312
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<template>
  <div>
    <h2>手写识别</h2>
    <div class="box" style="width: 100%;height: 400px;">
      <graffiti :save="save" />
    </div>
    <div>
      <p>识别结果:</p>
 
      <div id="showData">
        <vue-latex :expression="content" display-mode />
      </div>
    </div>
    <h2>公式输入</h2>
    <math-field class="mathField" @input="handleInput" :menuItems="[]"></math-field>
  </div>
</template>
 
<script setup lang="ts">
  import { ref, nextTick, reactive, watch, onMounted, onBeforeMount, onBeforeUnmount, inject } from 'vue'
  import { MathfieldElement } from "mathlive"
  import graffiti from '@/components/graffiti/index.vue'
  const commonsVariable: any = inject('commonsVariable')
  const MG: any = inject('MG')
  const handleInput = (...data) => {
    console.log(data);
  }
 
  const content = ref('')
  const save = (data) => {
    console.log(data.split(",")[1]);
    MG.app
      .getLatexFormulaFromImage({
        base64Jpg: data.split(",")[1]
      })
      .then((res: any) => {
        content.value = res;
        nextTick(() => {
          
        })
      })
  }
 
</script>
 
<style lang="less">
  .mathField {
    width: 500px;
    margin-top: 10px;
  }
 
  #showData {
    border: 1px solid #ccc;
    padding: 20px;
    margin-top: 10px;
    margin-bottom: 50px;
  }
</style>