fontLineHeight.vue 1.9 KB

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