mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-19 09:14:27 +08:00
support using duplicate checker to prevent duplicate submissions for new transaction record
This commit is contained in:
+25
-1
@@ -2,6 +2,8 @@ import Clipboard from 'clipboard';
|
||||
import CryptoJS from 'crypto-js';
|
||||
import uaParser from 'ua-parser-js';
|
||||
|
||||
import { base64encode } from './common.js';
|
||||
|
||||
export function asyncLoadAssets(type, assetUrl) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
let addElement = false;
|
||||
@@ -71,10 +73,32 @@ export function asyncLoadAssets(type, assetUrl) {
|
||||
}
|
||||
|
||||
export function generateRandomString() {
|
||||
const baseString = 'ebk_' + Math.round(new Date().getTime() / 1000) + '_' + Math.random();
|
||||
let baseString = 'ebk_' + new Date().getTime();
|
||||
|
||||
if (crypto && crypto.getRandomValues) {
|
||||
const randoms = new Uint8Array(256);
|
||||
crypto.getRandomValues(randoms);
|
||||
baseString += '_' + base64encode(randoms);
|
||||
} else {
|
||||
baseString += '_' + Math.random();
|
||||
}
|
||||
|
||||
return CryptoJS.SHA256(baseString).toString();
|
||||
}
|
||||
|
||||
export function generateRandomUUID() {
|
||||
const randomString = generateRandomString();
|
||||
|
||||
// convert hash string to UUID Version 8
|
||||
const uuid = randomString.substring(0, 8) + '-'
|
||||
+ randomString.substring(8, 12) + '-'
|
||||
+ '8' + randomString.substring(13, 16) + '-'
|
||||
+ (0x8 | (parseInt(randomString.charAt(16), 16) & 0x3)).toString(16) + randomString.substring(17, 20) + '-'
|
||||
+ randomString.substring(20, 32);
|
||||
|
||||
return uuid;
|
||||
}
|
||||
|
||||
export function parseUserAgent(ua) {
|
||||
const uaParseRet = uaParser(ua);
|
||||
|
||||
|
||||
+9
-6
@@ -238,7 +238,7 @@ export default {
|
||||
getAccount: ({ id }) => {
|
||||
return axios.get('v1/accounts/get.json?id=' + id);
|
||||
},
|
||||
addAccount: ({ category, type, name, icon, color, currency, balance, comment, subAccounts }) => {
|
||||
addAccount: ({ category, type, name, icon, color, currency, balance, comment, subAccounts, clientSessionId }) => {
|
||||
return axios.post('v1/accounts/add.json', {
|
||||
category,
|
||||
type,
|
||||
@@ -248,7 +248,8 @@ export default {
|
||||
currency,
|
||||
balance,
|
||||
comment,
|
||||
subAccounts
|
||||
subAccounts,
|
||||
clientSessionId
|
||||
});
|
||||
},
|
||||
modifyAccount: ({ id, category, name, icon, color, comment, hidden, subAccounts }) => {
|
||||
@@ -383,7 +384,7 @@ export default {
|
||||
getTransaction: ({ id }) => {
|
||||
return axios.get(`v1/transactions/get.json?id=${id}&trim_account=true&trim_category=true&trim_tag=true`);
|
||||
},
|
||||
addTransaction: ({ type, categoryId, time, sourceAccountId, destinationAccountId, sourceAmount, destinationAmount, hideAmount, tagIds, comment, geoLocation, utcOffset }) => {
|
||||
addTransaction: ({ type, categoryId, time, sourceAccountId, destinationAccountId, sourceAmount, destinationAmount, hideAmount, tagIds, comment, geoLocation, utcOffset, clientSessionId }) => {
|
||||
return axios.post('v1/transactions/add.json', {
|
||||
type,
|
||||
categoryId,
|
||||
@@ -396,7 +397,8 @@ export default {
|
||||
tagIds,
|
||||
comment,
|
||||
geoLocation,
|
||||
utcOffset
|
||||
utcOffset,
|
||||
clientSessionId
|
||||
});
|
||||
},
|
||||
modifyTransaction: ({ id, type, categoryId, time, sourceAccountId, destinationAccountId, sourceAmount, destinationAmount, hideAmount, tagIds, comment, geoLocation, utcOffset }) => {
|
||||
@@ -427,14 +429,15 @@ export default {
|
||||
getTransactionCategory: ({ id }) => {
|
||||
return axios.get('v1/transaction/categories/get.json?id=' + id);
|
||||
},
|
||||
addTransactionCategory: ({ name, type, parentId, icon, color, comment }) => {
|
||||
addTransactionCategory: ({ name, type, parentId, icon, color, comment, clientSessionId }) => {
|
||||
return axios.post('v1/transaction/categories/add.json', {
|
||||
name,
|
||||
type,
|
||||
parentId,
|
||||
icon,
|
||||
color,
|
||||
comment
|
||||
comment,
|
||||
clientSessionId
|
||||
});
|
||||
},
|
||||
addTransactionCategoryBatch: ({ categories }) => {
|
||||
|
||||
Reference in New Issue
Block a user