Skip to content

Commit

Permalink
feat: 支持清除前端/后端数据
Browse files Browse the repository at this point in the history
  • Loading branch information
xream committed Jan 27, 2024
1 parent ead1f6c commit 7c97c21
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sub-store-front-end",
"version": "2.14.99",
"version": "2.14.100",
"private": true,
"scripts": {
"dev": "vite --host",
Expand Down
18 changes: 18 additions & 0 deletions src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,24 @@ export default {
},
moreSettingPage: {
moreSettingTitle: 'More Setting',
clearData: {
label: 'Clear Backend Data',
title: 'Clear Backend Data',
content: 'Are you sure?',
conform: 'Confirm',
cancel: 'Cancel',
succeed: 'Clear succeed',
failed: 'Clear failed',
},
clearFrontEndData: {
label: 'Clear Front-End Data',
title: 'Clear Front-End Data',
content: 'Are you sure?',
conform: 'Confirm',
cancel: 'Cancel',
succeed: 'Clear succeed',
failed: 'Clear failed',
},
other: 'Other',
simple: 'Simple Mode',
islr: 'Card right swipe to call out',
Expand Down
18 changes: 18 additions & 0 deletions src/locales/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,24 @@ export default {
},
moreSettingPage: {
moreSettingTitle: '更多设置',
clearData: {
label: '清除后端数据',
title: '清除后端数据',
content: '确定要清除数据吗?',
conform: '确定',
cancel: '取消',
succeed: '清除成功',
failed: '清除失败',
},
clearFrontEndData: {
label: '清除前端数据',
title: '清除前端数据',
content: '确定要清除前端数据吗?',
conform: '确定',
cancel: '取消',
succeed: '清除成功',
failed: '清除失败',
},
other: '其他设置',
simple: '简洁模式',
islr: '卡片右滑呼出',
Expand Down
77 changes: 77 additions & 0 deletions src/views/settings/moreSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,36 @@
:ok-text="$t(`themeSettingPage.themePicker.confirm`)"
@confirm="confirm"
/>
<nut-cell-group>
<nut-cell
:title="$t(`moreSettingPage.clearFrontEndData.label`)"
class="change-themes"
@click.stop="clearFrontEndData"
is-link
></nut-cell>
<nut-cell
:title="$t(`moreSettingPage.clearData.label`)"
class="change-themes"
@click.stop="clearData"
is-link
></nut-cell>
</nut-cell-group>

</div>
</template>

<script lang="ts" setup>
import { initStores } from "@/utils/initApp";
import { Dialog, Toast } from '@nutui/nutui';
import { useSettingsStore } from '@/store/settings';
import { storeToRefs } from 'pinia';
import { useGlobalStore } from '@/store/global';
import { useMousePicker } from '@/hooks/useMousePicker';
import { useThemes } from '@/hooks/useThemes';
import { computed, ref, toRaw, watchEffect } from 'vue';
import { useI18n } from 'vue-i18n';
import { useAppNotifyStore } from "@/store/appNotify";
import { useSettingsApi } from "@/api/settings";
// import { Dialog } from '@nutui/nutui';
const { t } = useI18n();
Expand All @@ -182,6 +201,8 @@
istabBar2,
} = storeToRefs(globalStore);
const { showNotify } = useAppNotifyStore();
const InputHostApi = ref('');
const autoSwitchSync = ref(false);
const SimpleSwitch = ref(false);
Expand Down Expand Up @@ -293,6 +314,62 @@
? ishostApi.value.slice(0, 9) + '************'
: t(`moreSettingPage.yhostapi`);
};
const clearData = () => {
Dialog({
title: t('moreSettingPage.clearData.title'),
content: t('moreSettingPage.clearData.content'),
onCancel: () => {},
onOk: async () => {
try {
const res = await useSettingsApi().restoreSettings({ content: JSON.stringify({}) });
if (res?.data?.status === "success") {
await initStores(false, true, true);
showNotify({
type: "success",
title: t(`moreSettingPage.clearData.succeed`),
});
} else {
throw new Error('clear data failed')
}
} catch (e) {
showNotify({
type: "danger",
title: t(`moreSettingPage.clearData.failed`),
});
console.error(e);
}
},
popClass: 'auto-dialog',
cancelText: t('moreSettingPage.clearData.cancel'),
okText: t('moreSettingPage.clearData.conform'),
closeOnPopstate: true,
lockScroll: false,
});
};
const clearFrontEndData = () => {
Dialog({
title: t('moreSettingPage.clearFrontEndData.title'),
content: t('moreSettingPage.clearFrontEndData.content'),
onCancel: () => {},
onOk: async () => {
try {
localStorage.clear()
window.location.reload()
} catch (e) {
showNotify({
type: "danger",
title: t(`moreSettingPage.clearFrontEndData.failed`),
});
console.error(e);
}
},
popClass: 'auto-dialog',
cancelText: t('moreSettingPage.clearFrontEndData.cancel'),
okText: t('moreSettingPage.clearFrontEndData.conform'),
closeOnPopstate: true,
lockScroll: false,
});
};
// const exitEditMode = () => {
// setDisplayInfo();
Expand Down

0 comments on commit 7c97c21

Please sign in to comment.