SettingFooter.vue 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <template>
  2. <div :class="prefixCls">
  3. <a-button type="primary" block @click="handleCopy">
  4. <CopyOutlined class="mr-2" />
  5. {{ t('layout.setting.copyBtn') }}
  6. </a-button>
  7. <a-button color="warning" block @click="handleResetSetting" class="my-3">
  8. <RedoOutlined class="mr-2" />
  9. {{ t('common.resetText') }}
  10. </a-button>
  11. <a-button color="error" block @click="handleClearAndRedo">
  12. <RedoOutlined class="mr-2" />
  13. {{ t('layout.setting.clearBtn') }}
  14. </a-button>
  15. </div>
  16. </template>
  17. <script lang="ts">
  18. import { defineComponent, unref } from 'vue';
  19. import { CopyOutlined, RedoOutlined } from '@ant-design/icons-vue';
  20. import { useAppStore } from '/@/store/modules/app';
  21. import { usePermissionStore } from '/@/store/modules/permission';
  22. import { useMultipleTabStore } from '/@/store/modules/multipleTab';
  23. import { useUserStore } from '/@/store/modules/user';
  24. import { useDesign } from '/@/hooks/web/useDesign';
  25. import { useI18n } from '/@/hooks/web/useI18n';
  26. import { useMessage } from '/@/hooks/web/useMessage';
  27. import { useCopyToClipboard } from '/@/hooks/web/useCopyToClipboard';
  28. import { updateColorWeak } from '/@/logics/theme/updateColorWeak';
  29. import { updateGrayMode } from '/@/logics/theme/updateGrayMode';
  30. import defaultSetting from '/@/settings/projectSetting';
  31. export default defineComponent({
  32. name: 'SettingFooter',
  33. components: { CopyOutlined, RedoOutlined },
  34. setup() {
  35. const permissionStore = usePermissionStore();
  36. const { prefixCls } = useDesign('setting-footer');
  37. const { t } = useI18n();
  38. const { createSuccessModal, createMessage } = useMessage();
  39. const tabStore = useMultipleTabStore();
  40. const userStore = useUserStore();
  41. const appStore = useAppStore();
  42. function handleCopy() {
  43. const { isSuccessRef } = useCopyToClipboard(JSON.stringify(unref(appStore.getProjectConfig), null, 2));
  44. unref(isSuccessRef) &&
  45. createSuccessModal({
  46. title: t('layout.setting.operatingTitle'),
  47. content: t('layout.setting.operatingContent'),
  48. });
  49. }
  50. function handleResetSetting() {
  51. try {
  52. appStore.setProjectConfig(defaultSetting);
  53. const { colorWeak, grayMode } = defaultSetting;
  54. // updateTheme(themeColor);
  55. updateColorWeak(colorWeak);
  56. updateGrayMode(grayMode);
  57. createMessage.success(t('layout.setting.resetSuccess'));
  58. } catch (error) {
  59. createMessage.error(error);
  60. }
  61. }
  62. function handleClearAndRedo() {
  63. localStorage.clear();
  64. appStore.resetAllState();
  65. permissionStore.resetState();
  66. tabStore.resetState();
  67. userStore.resetState();
  68. location.reload();
  69. }
  70. return {
  71. prefixCls,
  72. t,
  73. handleCopy,
  74. handleResetSetting,
  75. handleClearAndRedo,
  76. };
  77. },
  78. });
  79. </script>
  80. <style lang="less" scoped>
  81. @prefix-cls: ~'@{namespace}-setting-footer';
  82. .@{prefix-cls} {
  83. display: flex;
  84. flex-direction: column;
  85. align-items: center;
  86. }
  87. </style>