fontSize.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <section class="config" :key="displayName">
  3. <div class="config-label">
  4. <el-tooltip :content="displayName">
  5. <span>{{displayKeyName}}</span>
  6. </el-tooltip>
  7. </div>
  8. <div class="config-content">
  9. <el-select
  10. v-model="value"
  11. class="select"
  12. size="medium"
  13. @change="onSelectChange"
  14. >
  15. <el-option
  16. v-for="item in options"
  17. :key="item.value"
  18. :label="item.label"
  19. :value="item.value">
  20. </el-option>
  21. </el-select>
  22. </div>
  23. </section>
  24. </template>
  25. <style>
  26. .select {
  27. width: 100%;
  28. }
  29. </style>
  30. <script>
  31. const defaultFontSize = [
  32. '12px',
  33. '13px',
  34. '14px',
  35. '16px',
  36. '18px',
  37. '20px',
  38. '22px',
  39. '28px',
  40. '36px',
  41. '48px'
  42. ];
  43. import Mixin from './mixin';
  44. import { getStyleDisplayName } from '../utils/utils.js';
  45. export default {
  46. props: {
  47. componentName: {
  48. type: String
  49. },
  50. golbalValue: {
  51. type: Object
  52. }
  53. },
  54. data() {
  55. return {
  56. options: [],
  57. value: ''
  58. };
  59. },
  60. mixins: [Mixin],
  61. computed: {
  62. isGlobalInputValue() {
  63. return this.config.value.startsWith('$');
  64. }
  65. },
  66. methods: {
  67. onSelectChange(e) {
  68. this.onChange(e);
  69. },
  70. initSelectOption() {
  71. this.options = [];
  72. defaultFontSize.forEach((size) => {
  73. this.options.push({
  74. value: size,
  75. label: size
  76. });
  77. });
  78. const golbalTypography = this.golbalValue.typography;
  79. if (this.isGlobalInputValue && golbalTypography) {
  80. Object.keys(golbalTypography).forEach((font) => {
  81. if (font.includes('font-size')) {
  82. const size = golbalTypography[font];
  83. this.options.push({
  84. value: size.key,
  85. label: getStyleDisplayName(size)
  86. });
  87. }
  88. });
  89. }
  90. }
  91. },
  92. watch: {
  93. 'mergedValue': {
  94. immediate: true,
  95. handler(value) {
  96. this.initSelectOption();
  97. this.value = this.mergedValue;
  98. }
  99. }
  100. }
  101. };
  102. </script>