Blame view

src/layouts/default/setting/components/SettingFooter.vue 3.09 KB
1
2
3
4
5
6
7
8
9
<template>
  <div :class="prefixCls">
    <a-button type="primary" block @click="handleCopy">
      <CopyOutlined class="mr-2" />
      {{ t('layout.setting.copyBtn') }}
    </a-button>

    <a-button color="warning" block @click="handleResetSetting" class="my-3">
      <RedoOutlined class="mr-2" />
vben authored
10
      {{ t('common.resetText') }}
11
12
13
14
15
16
17
18
19
20
21
22
    </a-button>

    <a-button color="error" block @click="handleClearAndRedo">
      <RedoOutlined class="mr-2" />
      {{ t('layout.setting.clearBtn') }}
    </a-button>
  </div>
</template>
<script lang="ts">
  import { defineComponent, unref } from 'vue';

  import { CopyOutlined, RedoOutlined } from '@ant-design/icons-vue';
23
Vben authored
24
25
26
27
  import { useAppStore } from '/@/store/modules/app';
  import { usePermissionStore } from '/@/store/modules/permission';
  import { useMultipleTabStore } from '/@/store/modules/multipleTab';
  import { useUserStore } from '/@/store/modules/user';
28
29
30

  import { useDesign } from '/@/hooks/web/useDesign';
  import { useI18n } from '/@/hooks/web/useI18n';
31
32
  import { useMessage } from '/@/hooks/web/useMessage';
  import { useCopyToClipboard } from '/@/hooks/web/useCopyToClipboard';
33
vben authored
34
35
  import { updateColorWeak } from '/@/logics/theme/updateColorWeak';
  import { updateGrayMode } from '/@/logics/theme/updateGrayMode';
36
  import defaultSetting from '/@/settings/projectSetting';
Vben authored
37
38
39
40
41
  export default defineComponent({
    name: 'SettingFooter',
    components: { CopyOutlined, RedoOutlined },
    setup() {
Vben authored
42
      const permissionStore = usePermissionStore();
43
44
45
      const { prefixCls } = useDesign('setting-footer');
      const { t } = useI18n();
      const { createSuccessModal, createMessage } = useMessage();
Vben authored
46
47
48
      const tabStore = useMultipleTabStore();
      const userStore = useUserStore();
      const appStore = useAppStore();
49
50

      function handleCopy() {
Vben authored
51
        const { isSuccessRef } = useCopyToClipboard(
vben authored
52
          JSON.stringify(unref(appStore.getProjectConfig), null, 2),
Vben authored
53
        );
54
55
56
57
58
59
60
61
        unref(isSuccessRef) &&
          createSuccessModal({
            title: t('layout.setting.operatingTitle'),
            content: t('layout.setting.operatingContent'),
          });
      }
      function handleResetSetting() {
        try {
Vben authored
62
          appStore.setProjectConfig(defaultSetting);
63
64
65
66
67
          const { colorWeak, grayMode } = defaultSetting;
          // updateTheme(themeColor);
          updateColorWeak(colorWeak);
          updateGrayMode(grayMode);
          createMessage.success(t('layout.setting.resetSuccess'));
vben authored
68
        } catch (error: any) {
69
70
71
72
73
74
          createMessage.error(error);
        }
      }

      function handleClearAndRedo() {
        localStorage.clear();
Vben authored
75
76
77
78
        appStore.resetAllState();
        permissionStore.resetState();
        tabStore.resetState();
        userStore.resetState();
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
        location.reload();
      }
      return {
        prefixCls,
        t,
        handleCopy,
        handleResetSetting,
        handleClearAndRedo,
      };
    },
  });
</script>
<style lang="less" scoped>
  @prefix-cls: ~'@{namespace}-setting-footer';

  .@{prefix-cls} {
    display: flex;
    flex-direction: column;
    align-items: center;
  }
</style>