main.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <div class="main" ref="mainPanel">
  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. {{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. padding: 0 18px 15px;
  26. overflow-y: auto;
  27. }
  28. .category-name {
  29. color: #C0C4CC;
  30. font-size: 18px;
  31. display: block;
  32. margin: 13px 0 3px 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 } 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. editorComponent(type) {
  81. switch (type) {
  82. case 'color':
  83. return ColorEditor;
  84. case 'fontWeight':
  85. return fontWeightEditor;
  86. case 'fontSize':
  87. return fontSizeEditor;
  88. case 'fontLineHeight':
  89. return fontLineHeightEditor;
  90. case 'borderRadius':
  91. return borderRadiusEditor;
  92. case 'boxShadow':
  93. return boxShadowEditor;
  94. default:
  95. return simpleTextEditor;
  96. }
  97. },
  98. onChange(e) {
  99. this.$emit('onChange', e);
  100. },
  101. showCategory(name, key) {
  102. if (!name) {
  103. return false;
  104. }
  105. if (!this.categoryDisplay[name] || this.categoryDisplay[name] === key) {
  106. this.categoryDisplay[name] = key;
  107. return true;
  108. }
  109. return false;
  110. }
  111. },
  112. data() {
  113. return {
  114. categoryDisplay: {}
  115. };
  116. },
  117. watch: {
  118. currentConfig: {
  119. handler() {
  120. this.$nextTick(() => {
  121. this.$refs.mainPanel.scrollTo(0, 0);
  122. });
  123. }
  124. }
  125. }
  126. };
  127. </script>