FontStyle.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <div class="font-style">
  3. <span class="cus-btn" :class="{ 'active-btn': bold }"
  4. ><BoldOutlined @click="handleBold"
  5. /></span>
  6. <span class="cus-btn" :class="{ 'active-btn': italic }"
  7. ><ItalicOutlined @click="handleItalic"
  8. /></span>
  9. <!-- <span class="cus-btn" :class="{ 'active-btn': underline }"
  10. ><UnderlineOutlined @click="handleUnderline"
  11. /></span> -->
  12. <InputNumber
  13. size="small"
  14. :value="size"
  15. :min="12"
  16. :step="1"
  17. :precision="0"
  18. style="width: 80px"
  19. @change="handleChange"
  20. >
  21. <template #addonAfter>px</template>
  22. </InputNumber>
  23. </div>
  24. </template>
  25. <script setup lang="ts">
  26. import { defineProps, defineEmits, ref } from "vue";
  27. import {
  28. BoldOutlined,
  29. ItalicOutlined,
  30. // UnderlineOutlined,
  31. } from "@ant-design/icons-vue";
  32. import { InputNumber } from "ant-design-vue";
  33. const props = defineProps<{
  34. value: {
  35. size: number;
  36. bold: boolean;
  37. italic: boolean;
  38. // underline: boolean;
  39. };
  40. }>();
  41. const emit = defineEmits(["update:value"]);
  42. const bold = ref(props.value?.bold);
  43. const italic = ref(props.value?.italic);
  44. // const underline = ref(props.value?.underline);
  45. const size = ref(props.value?.size);
  46. const handleUpdate = () => {
  47. emit("update:value", {
  48. size: size.value,
  49. bold: bold.value,
  50. italic: italic.value,
  51. // underline: underline.value,
  52. });
  53. };
  54. const handleBold = () => {
  55. bold.value = !bold.value;
  56. handleUpdate();
  57. };
  58. const handleItalic = () => {
  59. italic.value = !italic.value;
  60. handleUpdate();
  61. };
  62. // const handleUnderline = () => {
  63. // underline.value = !underline.value;
  64. // handleUpdate();
  65. // };
  66. const handleChange = (val: number) => {
  67. size.value = val;
  68. handleUpdate();
  69. };
  70. </script>
  71. <style lang="less" scoped>
  72. .font-style {
  73. display: flex;
  74. justify-content: space-between;
  75. }
  76. .active-btn {
  77. color: #1890ff;
  78. }
  79. </style>