fontWeight.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 defaultFontWeight = [
  29. 'normal',
  30. 'bold',
  31. 'bolder',
  32. 'lighter',
  33. '100',
  34. '200',
  35. '300',
  36. '400',
  37. '500',
  38. '600',
  39. '700',
  40. '800',
  41. '900',
  42. 'inherit'
  43. ];
  44. import Mixin from './mixin';
  45. import { getStyleDisplayName } from '../utils/utils.js';
  46. export default {
  47. props: {
  48. componentName: {
  49. type: String
  50. },
  51. golbalValue: {
  52. type: Object
  53. }
  54. },
  55. data() {
  56. return {
  57. options: [],
  58. value: ''
  59. };
  60. },
  61. mixins: [Mixin],
  62. computed: {
  63. isGlobalInputValue() {
  64. return this.config.value.startsWith('$');
  65. }
  66. },
  67. methods: {
  68. onSelectChange(e) {
  69. this.onChange(e);
  70. },
  71. initSelectOption() {
  72. this.options = [];
  73. defaultFontWeight.forEach((weight) => {
  74. this.options.push({
  75. value: weight,
  76. label: weight
  77. });
  78. });
  79. const golbalTypography = this.golbalValue.typography;
  80. if (this.isGlobalInputValue && golbalTypography) {
  81. Object.keys(golbalTypography).forEach((font) => {
  82. if (font.includes('font-weight')) {
  83. const weight = golbalTypography[font];
  84. this.options.push({
  85. value: weight.key,
  86. label: getStyleDisplayName(weight)
  87. });
  88. }
  89. });
  90. }
  91. }
  92. },
  93. watch: {
  94. 'mergedValue': {
  95. immediate: true,
  96. handler(value) {
  97. this.initSelectOption();
  98. this.value = this.mergedValue;
  99. }
  100. }
  101. }
  102. };
  103. </script>