tool-button.vue 1.7 KB
Newer Older
璃白.'s avatar
璃白. 已提交
1
<template>
璃白.'s avatar
璃白. 已提交
2 3 4 5 6
  <div
    v-tip.top="info.tip"
    @click="handleTool(info.name, info.startStr, info.endStr)"
    class="tool_button"
  >
璃白.'s avatar
璃白. 已提交
7 8 9 10
    <span :class="['icon iconfont', `icon-${info.icon}`]"></span>
  </div>
</template>
<script>
璃白.'s avatar
璃白. 已提交
11
import { formatText } from "@/assets/js/utils";
璃白.'s avatar
璃白. 已提交
12 13 14 15 16
export default {
  props: {
    info: {
      type: Object,
      default: () => {}
璃白.'s avatar
璃白. 已提交
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
    },
    fullScreen: {
      type: Boolean,
      default: false
    },
    text: {
      type: String,
      default: ''
    },
    selectionInfo: {
      type: Object,
      default: ()=>{}
    },
    uploadPath: {
      type: String,
      default: ''
璃白.'s avatar
璃白. 已提交
33 34
    }
  },
璃白.'s avatar
璃白. 已提交
35 36 37 38
  data() {
    return {
      ulNum: 1
    }
璃白.'s avatar
璃白. 已提交
39 40
  },
  methods: {
璃白.'s avatar
璃白. 已提交
41
    handleTool(type, startStr, endStr) {
璃白.'s avatar
璃白. 已提交
42 43 44 45 46 47 48
      switch (type) {
        case "bold":
        case "italic":
        case "quote":
        case "code":
        case "link":
        case "ul":
璃白.'s avatar
璃白. 已提交
49 50
        case "task":
        case "table":
璃白.'s avatar
璃白. 已提交
51
          this.updateText(startStr, endStr);
璃白.'s avatar
璃白. 已提交
52 53 54
          break;
        case "ol":
          let ulNum = this.ulNum;
璃白.'s avatar
璃白. 已提交
55 56
          this.updateText(`\n${ulNum}. `, "");
          this.ulNum++
璃白.'s avatar
璃白. 已提交
57 58
          break;
        case "fullScreen":
璃白.'s avatar
璃白. 已提交
59
          this.$emit('setFullScreen', true)
璃白.'s avatar
璃白. 已提交
60 61 62 63
          break;
        default:
          break;
      }
璃白.'s avatar
璃白. 已提交
64 65 66 67 68 69 70
    },
    updateText(startStr, endStr) {
      const originalText = this.text
      const selectionInfo = this.selectionInfo
     const newText = formatText(originalText, selectionInfo, startStr, endStr)
      this.$emit('updateText',newText)
   }
璃白.'s avatar
璃白. 已提交
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
  }
};
</script>
<style lang="less" scoped>
.tool_button {
  .icon {
    font-size: 18px;
    color: var(--md-editor-text-color);
    cursor: pointer;
    &:hover {
      color: var(--md-editor-text-color-active);
    }
  }
}
</style>