solve bug of numbers
This commit is contained in:
+11
-11
@@ -148,18 +148,18 @@ const checkNumber = async (_rule: Rule, value: number) => {
|
||||
if (isBuyP) {
|
||||
// Skip wallet balance check if gateway is enabled
|
||||
if (!gatewayP) {
|
||||
if (!walletCash?.walletInfo?.cash && methodP == 'cash') {
|
||||
return Promise.reject('موجودی کیف پول ناکافی است')
|
||||
}
|
||||
if (!walletCash?.walletInfo?.gold && methodP == 'gold') {
|
||||
return Promise.reject('موجودی کیف طلا ناکافی است')
|
||||
}
|
||||
if (priceP * value > walletCash?.walletInfo?.cash && methodP == 'cash')
|
||||
return Promise.reject('موجودی کیف پول ناکافی است')
|
||||
if (amountP * value > walletCash?.walletInfo?.gold && methodP == 'gold')
|
||||
return Promise.reject('موجودی کیف طلا ناکافی است')
|
||||
if (!walletCash?.walletInfo?.cash && methodP == 'cash') {
|
||||
return Promise.reject('موجودی کیف پول ناکافی است')
|
||||
}
|
||||
return Promise.resolve()
|
||||
if (!walletCash?.walletInfo?.gold && methodP == 'gold') {
|
||||
return Promise.reject('موجودی کیف طلا ناکافی است')
|
||||
}
|
||||
if (priceP * value > walletCash?.walletInfo?.cash && methodP == 'cash')
|
||||
return Promise.reject('موجودی کیف پول ناکافی است')
|
||||
if (amountP * value > walletCash?.walletInfo?.gold && methodP == 'gold')
|
||||
return Promise.reject('موجودی کیف طلا ناکافی است')
|
||||
}
|
||||
return Promise.resolve()
|
||||
} else {
|
||||
if (value > NumP)
|
||||
return Promise.reject('موجودی محصول ناکافی است')
|
||||
|
||||
@@ -67,7 +67,7 @@ _axios.interceptors.response.use(
|
||||
removeToken()
|
||||
// Don't redirect to login if user is on buyProduct page
|
||||
if (router.currentRoute.value.name !== 'buyProduct') {
|
||||
await router.push({name: 'login'})
|
||||
await router.push({name: 'login'})
|
||||
}
|
||||
} else if (error.response && error.response.status == 403) {
|
||||
message.error('شما دسترسی لازم برای انجام این عملیات را ندارید')
|
||||
|
||||
@@ -397,16 +397,69 @@ const form = ref<Gold>({
|
||||
})
|
||||
const allowedAsciiCodeFloat = [46, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57]
|
||||
const allowedAsciiCodeInt = [48, 49, 50, 51, 52, 53, 54, 55, 56, 57]
|
||||
|
||||
// Function to convert Persian/Farsi numbers to English
|
||||
function convertPersianToEnglish(str: string): string {
|
||||
const persianNumbers = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹']
|
||||
const englishNumbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
|
||||
const persianDecimal = '٫'
|
||||
const englishDecimal = '.'
|
||||
|
||||
let result = str
|
||||
// Replace Persian numbers with English numbers
|
||||
for (let i = 0; i < persianNumbers.length; i++) {
|
||||
result = result.replace(new RegExp(persianNumbers[i], 'g'), englishNumbers[i])
|
||||
}
|
||||
// Replace Persian decimal separator with English decimal separator
|
||||
result = result.replace(new RegExp(persianDecimal, 'g'), englishDecimal)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// Handler for Persian number input
|
||||
function handlePersianNumberInput(event: Event) {
|
||||
const target = event.target as HTMLInputElement
|
||||
if (target && target.value) {
|
||||
const convertedValue = convertPersianToEnglish(target.value)
|
||||
if (convertedValue !== target.value) {
|
||||
form.value.goldValue = convertedValue as any
|
||||
}
|
||||
}
|
||||
}
|
||||
watch(form.value, () => {
|
||||
if (form.value.goldValue) {
|
||||
const lastCharGoldStr: string = form.value.goldValue.toString()
|
||||
const goldValueStr = form.value.goldValue.toString()
|
||||
// Convert Persian numbers to English
|
||||
const convertedValue = convertPersianToEnglish(goldValueStr)
|
||||
if (convertedValue !== goldValueStr) {
|
||||
const numericValue = parseFloat(convertedValue)
|
||||
form.value.goldValue = isNaN(numericValue) ? null : numericValue
|
||||
if (!isNaN(numericValue)) {
|
||||
calculateCash(numericValue)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
const lastCharGoldStr: string = goldValueStr
|
||||
if (!allowedAsciiCodeFloat.includes(lastCharGoldStr.slice(-1).charCodeAt(0))) {
|
||||
form.value.goldValue = isNaN(parseFloat(lastCharGoldStr.slice(0, -1))) ? null : parseFloat(lastCharGoldStr.slice(0, -1))
|
||||
calculateCash(form.value.goldValue)
|
||||
}
|
||||
}
|
||||
if (form.value.goldCash) {
|
||||
const lastCharCashStr: string = form.value.goldCash.toString()
|
||||
const goldCashStr = form.value.goldCash.toString()
|
||||
// Convert Persian numbers to English
|
||||
const convertedValue = convertPersianToEnglish(goldCashStr)
|
||||
if (convertedValue !== goldCashStr) {
|
||||
const numericValue = parseFloat(convertedValue.replaceAll(',', ''))
|
||||
form.value.goldCash = isNaN(numericValue) ? null : numericValue
|
||||
if (!isNaN(numericValue)) {
|
||||
calculateGold(numericValue)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
const lastCharCashStr: string = goldCashStr
|
||||
if (!allowedAsciiCodeInt.includes(lastCharCashStr.slice(-1).charCodeAt(0))) {
|
||||
form.value.goldCash = isNaN(parseFloat(lastCharCashStr.slice(0, -1))) ? null : parseFloat(lastCharCashStr.slice(0, -1))
|
||||
calculateGold(form.value.goldCash)
|
||||
|
||||
@@ -59,16 +59,16 @@ const showFilter = ref()
|
||||
const selectedProduct = ref<Product>()
|
||||
|
||||
function clickProduct(item: Product) {
|
||||
if(item?.show){
|
||||
if(item?.show){
|
||||
// Check if user is logged in
|
||||
if (!getToken()) {
|
||||
message.warning('برای خرید یا فروش محصولات، لطفا ابتدا وارد حساب کاربری خود شوید')
|
||||
router.push({ name: 'login' })
|
||||
return
|
||||
}
|
||||
showFilter.value = true
|
||||
selectedProduct.value = cloneDeep(item)
|
||||
}
|
||||
showFilter.value = true
|
||||
selectedProduct.value = cloneDeep(item)
|
||||
}
|
||||
}
|
||||
|
||||
function changeTab() {
|
||||
|
||||
Reference in New Issue
Block a user