mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-14 23:17:33 +08:00
add clearing user data in ui
This commit is contained in:
@@ -648,6 +648,11 @@ export default {
|
||||
'Unable to update user profile': 'Unable to update user profile',
|
||||
'Data Management': 'Data Management',
|
||||
'Export Data': 'Export Data',
|
||||
'Clear User Data': 'Clear User Data',
|
||||
'Are you sure you want to clear all data?': 'Are you sure you want to clear all data?',
|
||||
'You CANNOT undo this action. This will clear your accounts, categories, tags and transactions data. Please input your current password to confirm.': 'You CANNOT undo this action. This will clear your accounts, categories, tags and transactions data. Please input your current password to confirm.',
|
||||
'All user data has been cleared': 'All user data has been cleared',
|
||||
'Unable to clear user data': 'Unable to clear user data',
|
||||
'Device & Sessions': 'Device & Sessions',
|
||||
'Logout All': 'Logout All',
|
||||
'Unable to get session list': 'Unable to get session list',
|
||||
|
||||
@@ -648,6 +648,11 @@ export default {
|
||||
'Unable to update user profile': '无法更新用户信息',
|
||||
'Data Management': '数据管理',
|
||||
'Export Data': '导出数据',
|
||||
'Clear User Data': '清除用户数据',
|
||||
'Are you sure you want to clear all data?': '您确定要清除所有数据?',
|
||||
'You CANNOT undo this action. This will clear your accounts, categories, tags and transactions data. Please input your current password to confirm.': '您不能撤销该操作。该操作将会清除您的账号、分类、标签以及交易数据。请输入您当前的密码以确认。',
|
||||
'All user data has been cleared': '用户所有数据已经清空',
|
||||
'Unable to clear user data': '无法清除用户数据',
|
||||
'Device & Sessions': '设备和会话',
|
||||
'Logout All': '注销全部',
|
||||
'Unable to get session list': '无法获取会话列表',
|
||||
|
||||
@@ -52,6 +52,7 @@ import {
|
||||
logout,
|
||||
getCurrentUserProfile,
|
||||
updateUserProfile,
|
||||
clearUserData,
|
||||
clearUserInfoState,
|
||||
resetState,
|
||||
currentUserNickname,
|
||||
@@ -735,6 +736,7 @@ const stores = {
|
||||
logout,
|
||||
getCurrentUserProfile,
|
||||
updateUserProfile,
|
||||
clearUserData,
|
||||
clearUserInfoState,
|
||||
resetState,
|
||||
|
||||
|
||||
+46
-1
@@ -11,7 +11,9 @@ import {
|
||||
CLEAR_USER_INFO,
|
||||
|
||||
UPDATE_ACCOUNT_LIST_INVALID_STATE,
|
||||
UPDATE_TRANSACTION_OVERVIEW_INVALID_STATE
|
||||
UPDATE_TRANSACTION_OVERVIEW_INVALID_STATE,
|
||||
UPDATE_TRANSACTION_CATEGORY_LIST_INVALID_STATE,
|
||||
UPDATE_TRANSACTION_TAG_LIST_INVALID_STATE
|
||||
} from './mutations.js';
|
||||
|
||||
export function authorize(context, { loginName, password }) {
|
||||
@@ -271,6 +273,49 @@ export function updateUserProfile(context, { profile, currentPassword }) {
|
||||
});
|
||||
}
|
||||
|
||||
export function clearUserData(context, { password }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
services.clearData({
|
||||
password: password
|
||||
}).then(response => {
|
||||
const data = response.data;
|
||||
|
||||
if (!data || !data.success || !data.result) {
|
||||
reject({ message: 'Unable to clear user data' });
|
||||
return;
|
||||
}
|
||||
|
||||
if (!context.state.accountListStateInvalid) {
|
||||
context.commit(UPDATE_ACCOUNT_LIST_INVALID_STATE, true);
|
||||
}
|
||||
|
||||
if (!context.state.transactionCategoryListStateInvalid) {
|
||||
context.commit(UPDATE_TRANSACTION_CATEGORY_LIST_INVALID_STATE, true);
|
||||
}
|
||||
|
||||
if (!context.state.transactionTagListStateInvalid) {
|
||||
context.commit(UPDATE_TRANSACTION_TAG_LIST_INVALID_STATE, true);
|
||||
}
|
||||
|
||||
if (!context.state.transactionOverviewStateInvalid) {
|
||||
context.commit(UPDATE_TRANSACTION_OVERVIEW_INVALID_STATE, true);
|
||||
}
|
||||
|
||||
resolve(data.result);
|
||||
}).catch(error => {
|
||||
logger.error('failed to clear user data', error);
|
||||
|
||||
if (error && error.processed) {
|
||||
reject(error);
|
||||
} else if (error.response && error.response.data && error.response.data.errorMessage) {
|
||||
reject({ error: error.response.data });
|
||||
} else {
|
||||
reject({ message: 'Unable to clear user data' });
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function clearUserInfoState(context) {
|
||||
context.commit(CLEAR_USER_INFO);
|
||||
}
|
||||
|
||||
@@ -6,16 +6,61 @@
|
||||
<f7-card-content class="no-safe-areas" :padding="false">
|
||||
<f7-list>
|
||||
<f7-list-button external no-chevron target="_blank" :link="`${$constants.api.baseUrlPath}/data/export.csv?token=${$user.getToken()}`">{{ $t('Export Data') }}</f7-list-button>
|
||||
<f7-list-button color="red" @click="clearData(null)">{{ $t('Clear User Data') }}</f7-list-button>
|
||||
</f7-list>
|
||||
</f7-card-content>
|
||||
</f7-card>
|
||||
|
||||
<password-input-sheet :title="$t('Are you sure you want to clear all data?')"
|
||||
:hint="$t('You CANNOT undo this action. This will clear your accounts, categories, tags and transactions data. Please input your current password to confirm.')"
|
||||
:show.sync="showInputPasswordSheetForClearData"
|
||||
:confirm-disabled="clearingData"
|
||||
:cancel-disabled="clearingData"
|
||||
v-model="currentPasswordForClearData"
|
||||
@password:confirm="clearData">
|
||||
</password-input-sheet>
|
||||
</f7-page>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {};
|
||||
return {
|
||||
currentPasswordForClearData: '',
|
||||
clearingData: false,
|
||||
showInputPasswordSheetForClearData: false,
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
clearData(password) {
|
||||
const self = this;
|
||||
|
||||
if (!password) {
|
||||
self.currentPasswordForClearData = '';
|
||||
self.showInputPasswordSheetForClearData = true;
|
||||
return;
|
||||
}
|
||||
|
||||
self.clearingData = true;
|
||||
self.$showLoading(() => self.clearingData);
|
||||
|
||||
self.$store.dispatch('clearUserData', {
|
||||
password: password
|
||||
}).then(() => {
|
||||
self.clearingData = false;
|
||||
self.$hideLoading();
|
||||
|
||||
self.showInputPasswordSheetForClearData = false;
|
||||
self.$toast('All user data has been cleared');
|
||||
}).catch(error => {
|
||||
self.clearingData = false;
|
||||
self.$hideLoading();
|
||||
|
||||
if (!error.processed) {
|
||||
self.$toast(error.message || error);
|
||||
}
|
||||
});
|
||||
},
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user