fontLineHeight.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <section class="config" :key="displayName">
  3. <div class="config-label">
  4. <el-tooltip :content="displayName" placement="top">
  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 defaultFontLineHeight = [
  32. '1',
  33. '1.3',
  34. '1.5',
  35. '1.7',
  36. '12px',
  37. '16px',
  38. '20px',
  39. '24px',
  40. '28px'
  41. ];
  42. import Mixin from './mixin';
  43. import { getStyleDisplayName } from '../utils/utils.js';
  44. export default {
  45. props: {
  46. componentName: {
  47. type: String
  48. },
  49. golbalValue: {
  50. type: Object
  51. }
  52. },
  53. data() {
  54. return {
  55. options: [],
  56. value: ''
  57. };
  58. },
  59. mixins: [Mixin],
  60. computed: {
  61. isGlobalInputValue() {
  62. return this.config.value.startsWith('$');
  63. }
  64. },
  65. methods: {
  66. onSelectChange(e) {
  67. this.onChange(e);
  68. },
  69. initSelectOption() {
  70. this.options = [];
  71. defaultFontLineHeight.forEach((size) => {
  72. this.options.push({
  73. value: size,
  74. label: size
  75. });
  76. });
  77. const golbalTypography = this.golbalValue.typography;
  78. if (this.isGlobalInputValue && golbalTypography) {
  79. Object.keys(golbalTypography).forEach((font) => {
  80. if (font.includes('font-line-height')) {
  81. const size = golbalTypography[font];
  82. this.options.push({
  83. value: size.key,
  84. label: getStyleDisplayName(size)
  85. });
  86. }
  87. });
  88. }
  89. }
  90. },
  91. watch: {
  92. 'mergedValue': {
  93. immediate: true,
  94. handler(value) {
  95. this.initSelectOption();
  96. this.value = this.mergedValue;
  97. }
  98. }
  99. }
  100. };
  101. </script>