fontWeight.vue 2.1 KB

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