mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-18 00:34:28 +08:00
automatically save transaction draft
This commit is contained in:
+10
-3
@@ -2,7 +2,10 @@ import axios from 'axios';
|
||||
|
||||
import apiConstants from '@/consts/api.js';
|
||||
import userState from './userstate.js';
|
||||
import { isBoolean } from './common.js';
|
||||
import {
|
||||
isDefined,
|
||||
isBoolean
|
||||
} from './common.js';
|
||||
import {
|
||||
getGoogleMapAPIKey,
|
||||
getBaiduMapAK,
|
||||
@@ -395,8 +398,12 @@ export default {
|
||||
|
||||
return axios.get(`v1/transactions/amounts.json?use_transaction_timezone=${useTransactionTimezone}` + (queryParams.length ? '&query=' + queryParams.join('|') : ''));
|
||||
},
|
||||
getTransaction: ({ id }) => {
|
||||
return axios.get(`v1/transactions/get.json?id=${id}&with_pictures=true&trim_account=true&trim_category=true&trim_tag=true`);
|
||||
getTransaction: ({ id, withPictures }) => {
|
||||
if (!isDefined(withPictures)) {
|
||||
withPictures = true;
|
||||
}
|
||||
|
||||
return axios.get(`v1/transactions/get.json?id=${id}&with_pictures=${withPictures}&trim_account=true&trim_category=true&trim_tag=true`);
|
||||
},
|
||||
addTransaction: ({ type, categoryId, time, sourceAccountId, destinationAccountId, sourceAmount, destinationAmount, hideAmount, tagIds, pictureIds, comment, geoLocation, utcOffset, clientSessionId }) => {
|
||||
return axios.post('v1/transactions/add.json', {
|
||||
|
||||
@@ -11,6 +11,7 @@ const defaultSettings = {
|
||||
applicationLock: false,
|
||||
applicationLockWebAuthn: false,
|
||||
autoUpdateExchangeRatesData: true,
|
||||
autoSaveTransactionDraft: 'disabled',
|
||||
autoGetCurrentGeoLocation: false,
|
||||
showAmountInHomePage: true,
|
||||
timezoneUsedForStatisticsInHomePage: timezoneConstants.defaultTimezoneTypesUsedForStatistics,
|
||||
@@ -157,6 +158,14 @@ export function setAutoUpdateExchangeRatesData(value) {
|
||||
setOption('autoUpdateExchangeRatesData', value);
|
||||
}
|
||||
|
||||
export function getAutoSaveTransactionDraft() {
|
||||
return getOption('autoSaveTransactionDraft');
|
||||
}
|
||||
|
||||
export function setAutoSaveTransactionDraft(value) {
|
||||
setOption('autoSaveTransactionDraft', value);
|
||||
}
|
||||
|
||||
export function isAutoGetCurrentGeoLocation() {
|
||||
return getOption('autoGetCurrentGeoLocation');
|
||||
}
|
||||
|
||||
@@ -165,10 +165,7 @@ export function setTransactionModelByTransaction(transaction, transaction2, allC
|
||||
|
||||
transaction.hideAmount = transaction2.hideAmount;
|
||||
transaction.tagIds = transaction2.tagIds || [];
|
||||
|
||||
if (setContextData) {
|
||||
transaction.pictures = transaction2.pictures || [];
|
||||
}
|
||||
transaction.pictures = transaction2.pictures || [];
|
||||
|
||||
transaction.comment = transaction2.comment;
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ const appLockSecretBaseStringPrefix = 'EBK_LOCK_SECRET_';
|
||||
const tokenLocalStorageKey = 'ebk_user_token';
|
||||
const webauthnConfigLocalStorageKey = 'ebk_user_webauthn_config';
|
||||
const userInfoLocalStorageKey = 'ebk_user_info';
|
||||
const transactionDraftLocalStorageKey = 'ebk_user_draft_transaction';
|
||||
|
||||
const tokenSessionStorageKey = 'ebk_user_session_token';
|
||||
const encryptedTokenSessionStorageKey = 'ebk_user_session_encrypted_token';
|
||||
@@ -59,6 +60,21 @@ function getUserInfo() {
|
||||
return JSON.parse(data);
|
||||
}
|
||||
|
||||
function getUserTransactionDraft() {
|
||||
let data = localStorage.getItem(transactionDraftLocalStorageKey);
|
||||
|
||||
if (!data) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isEnableApplicationLock()) {
|
||||
const appLockState = getUserAppLockState();
|
||||
data = getDecryptedToken(data, appLockState);
|
||||
}
|
||||
|
||||
return JSON.parse(data);
|
||||
}
|
||||
|
||||
function getUserAppLockState() {
|
||||
const data = sessionStorage.getItem(appLockStateSessionStorageKey);
|
||||
return JSON.parse(data);
|
||||
@@ -183,10 +199,29 @@ function updateUserInfo(user) {
|
||||
}
|
||||
}
|
||||
|
||||
function updateUserTransactionDraft(transaction) {
|
||||
if (!isObject(transaction)) {
|
||||
return;
|
||||
}
|
||||
|
||||
let data = JSON.stringify(transaction);
|
||||
|
||||
if (isEnableApplicationLock()) {
|
||||
const appLockState = getUserAppLockState();
|
||||
data = getEncryptedToken(data, appLockState);
|
||||
}
|
||||
|
||||
localStorage.setItem(transactionDraftLocalStorageKey, data);
|
||||
}
|
||||
|
||||
function clearUserInfo() {
|
||||
localStorage.removeItem(userInfoLocalStorageKey);
|
||||
}
|
||||
|
||||
function clearUserTransactionDraft() {
|
||||
localStorage.removeItem(transactionDraftLocalStorageKey);
|
||||
}
|
||||
|
||||
function clearSessionToken() {
|
||||
sessionStorage.removeItem(tokenSessionStorageKey);
|
||||
sessionStorage.removeItem(encryptedTokenSessionStorageKey);
|
||||
@@ -201,12 +236,14 @@ function clearTokenAndUserInfo(clearAppLockState) {
|
||||
sessionStorage.removeItem(tokenSessionStorageKey);
|
||||
sessionStorage.removeItem(encryptedTokenSessionStorageKey);
|
||||
localStorage.removeItem(tokenLocalStorageKey);
|
||||
clearUserTransactionDraft();
|
||||
clearUserInfo();
|
||||
}
|
||||
|
||||
export default {
|
||||
getToken,
|
||||
getUserInfo,
|
||||
getUserTransactionDraft,
|
||||
getUserAppLockState,
|
||||
isUserLogined,
|
||||
isUserUnlocked,
|
||||
@@ -219,8 +256,10 @@ export default {
|
||||
decryptToken,
|
||||
isCorrectPinCode,
|
||||
updateToken,
|
||||
updateUserTransactionDraft,
|
||||
updateUserInfo,
|
||||
clearUserInfo,
|
||||
clearUserTransactionDraft,
|
||||
clearSessionToken,
|
||||
clearTokenAndUserInfo
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user