计算价格 精度计算处理 decimal.js
import Decimal from 'decimal.js'
const calculation = (data: any, type: number) => {
const { priceProductShow, priceProductDiscount, skuNum } = data
const money = new Decimal(priceProductShow)
const count = new Decimal(priceProductDiscount)
const num = new Decimal(skuNum)
const add = money.mul(num).add(count).toNumber()
let temp = 0
if (type === 1) {
temp = new Decimal(totalMoney).add(new Decimal(add)).toNumber()
} else {
temp = new Decimal(totalMoney).sub(new Decimal(add)).toNumber()
}
return temp
}
加密工具 crypto-js
import CryptoJS from 'crypto-js';
const aesPassword = (password:any) => {
const p = password.split('');
if (p.length !== 16) {
for (let i = p.length; i < 16; i++) {
p[i] = '';
}
}
const txt = CryptoJS.enc.Utf8.parse(p.join(''));
const key = CryptoJS.enc.Utf8.parse('test');
const iv = CryptoJS.enc.Utf8.parse('test2');
const aesPassword = CryptoJS.AES.encrypt(txt, key, {
iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.ZeroPadding,
});
return aesPassword.ciphertext.toString(CryptoJS.enc.Base64);
};
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。