Index.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <template>
  2. <div class="theme-setting">
  3. {{ name }}
  4. <button @click="downloadScssVariables">点击下载主题变量</button>
  5. <ul>
  6. <li :key="item.key" v-for="item in formItems">
  7. <p
  8. ><b>{{ item.key }}</b
  9. >: {{ item.value }} (<del>{{ item.rawValue }}</del
  10. >)</p
  11. >
  12. <div>
  13. <n-color-picker
  14. v-if="['hex', 'rgb'].includes(item.inputType)"
  15. :show-alpha="item.inputType != 'hex'"
  16. :modes="['hex', 'rgb']"
  17. v-model:value="item.value"
  18. />
  19. <n-input v-else v-model:value="item.value" type="text" />
  20. </div>
  21. </li>
  22. </ul>
  23. </div>
  24. </template>
  25. <script lang="ts">
  26. import { defineComponent, watch } from 'vue';
  27. import { useThemeEditor } from './helper';
  28. import { NColorPicker, NInput } from 'naive-ui';
  29. export default defineComponent({
  30. name: 'theme-setting',
  31. props: {
  32. name: String
  33. },
  34. components: {
  35. NColorPicker,
  36. NInput
  37. },
  38. setup(props) {
  39. // 获取样式文件,正则匹配
  40. const { formItems, downloadScssVariables } = useThemeEditor();
  41. watch(
  42. () => formItems.value,
  43. (val) => {
  44. console.log(JSON.parse(JSON.stringify(val)));
  45. }
  46. );
  47. return { formItems, downloadScssVariables };
  48. }
  49. });
  50. </script>
  51. <style lang="scss" scoped>
  52. .theme-setting {
  53. li {
  54. list-style: none;
  55. margin-bottom: 12px;
  56. &::before {
  57. display: none;
  58. }
  59. .color-picker {
  60. width: 300px;
  61. margin-left: 20px;
  62. }
  63. p {
  64. font-size: 14px;
  65. text-overflow: ellipsis;
  66. }
  67. }
  68. }
  69. </style>