main.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <div class="main">
  3. <!-- <span>{{configName}}</span> -->
  4. <div v-for="(config, key) in configByOrder" :key="key">
  5. <span
  6. v-if="showCategory(config.category, key + 1)"
  7. class="category-name"
  8. >
  9. {{getCategoryDisplayName(config.category)}}
  10. </span>
  11. <component
  12. :is="editorComponent(config.type)"
  13. :componentName=configName
  14. :config=config
  15. :userConfig=userConfigByType
  16. :golbalValue=globalValue
  17. @onChange=onChange
  18. >
  19. </component>
  20. </div>
  21. </div>
  22. </template>
  23. <style>
  24. .main {
  25. margin-bottom: 140px;
  26. padding: 10px;
  27. }
  28. .category-name {
  29. color: #C0C4CC;
  30. font-size: 18px;
  31. display: block;
  32. margin: 8px 0 4px 0;
  33. }
  34. </style>
  35. <script>
  36. import ColorEditor from './editor/color';
  37. import fontWeightEditor from './editor/fontWeight';
  38. import fontSizeEditor from './editor/fontSize';
  39. import fontLineHeightEditor from './editor/fontLineHeight';
  40. import borderRadiusEditor from './editor/borderRadius';
  41. import boxShadowEditor from './editor/boxShadow';
  42. import simpleTextEditor from './editor/simpleText';
  43. import { filterConfigType, getCategoryDisplayName } from './utils/utils.js';
  44. export default {
  45. components: {
  46. ColorEditor,
  47. fontSizeEditor,
  48. fontLineHeightEditor,
  49. simpleTextEditor,
  50. borderRadiusEditor,
  51. boxShadowEditor,
  52. fontWeightEditor
  53. },
  54. props: {
  55. defaultConfig: {
  56. type: Array
  57. },
  58. currentConfig: {
  59. type: Object
  60. },
  61. userConfig: {
  62. type: Object
  63. },
  64. globalValue: {
  65. type: Object
  66. }
  67. },
  68. computed: {
  69. configName() {
  70. return this.currentConfig.name;
  71. },
  72. userConfigByType() {
  73. return this.userConfig[filterConfigType(this.configName)];
  74. },
  75. configByOrder() {
  76. return this.currentConfig.config.sort((a, b) => (a.order - b.order));
  77. }
  78. },
  79. methods: {
  80. getCategoryDisplayName(key) {
  81. return getCategoryDisplayName(key);
  82. },
  83. editorComponent(type) {
  84. switch (type) {
  85. case 'color':
  86. return ColorEditor;
  87. case 'fontWeight':
  88. return fontWeightEditor;
  89. case 'fontSize':
  90. return fontSizeEditor;
  91. case 'fontLineHeight':
  92. return fontLineHeightEditor;
  93. case 'borderRadius':
  94. return borderRadiusEditor;
  95. case 'boxShadow':
  96. return boxShadowEditor;
  97. default:
  98. return simpleTextEditor;
  99. }
  100. },
  101. onChange(e) {
  102. this.$emit('onChange', e);
  103. },
  104. showCategory(name, key) {
  105. if (!name) {
  106. return false;
  107. }
  108. if (!this.categoryDisplay[name] || this.categoryDisplay[name] === key) {
  109. this.categoryDisplay[name] = key;
  110. return true;
  111. }
  112. return false;
  113. }
  114. },
  115. data() {
  116. return {
  117. categoryDisplay: {}
  118. };
  119. }
  120. };
  121. </script>