diff --git a/components.d.ts b/components.d.ts index 62272de..767f50a 100644 --- a/components.d.ts +++ b/components.d.ts @@ -8,10 +8,12 @@ export {} declare module 'vue' { export interface GlobalComponents { AButton: typeof import('ant-design-vue/es')['Button'] + ACheckbox: typeof import('ant-design-vue/es')['Checkbox'] AConfigProvider: typeof import('ant-design-vue/es')['ConfigProvider'] ADivider: typeof import('ant-design-vue/es')['Divider'] AForm: typeof import('ant-design-vue/es')['Form'] AFormItem: typeof import('ant-design-vue/es')['FormItem'] + AFormItemRest: typeof import('ant-design-vue/es')['FormItemRest'] AInput: typeof import('ant-design-vue/es')['Input'] AInputPassword: typeof import('ant-design-vue/es')['InputPassword'] AModal: typeof import('ant-design-vue/es')['Modal'] diff --git a/src/main.ts b/src/main.ts index cf35f95..b4421cf 100644 --- a/src/main.ts +++ b/src/main.ts @@ -62,6 +62,9 @@ export function setEnableAuthenticate() { function goToLogin(to: RouteLocationNormalized, next: NavigationGuardNext) { + if (to.name === 'buyProduct') { + return next() // Allow access to buyProduct without login + } if (to.name !== 'login') { return next({ name: 'login' }) // Redirect to login } else { @@ -135,9 +138,9 @@ router.beforeEach(async (to, from, next) => { return next() } } else { - // If no token, handle redirect to login or allow access to login or 404 - if (['login', '404'].includes(to.name as string)) { - return next() // Allow access to login or 404 + // If no token, handle redirect to login or allow access to login, 404, or buyProduct + if (['login', '404', 'buyProduct'].includes(to.name as string)) { + return next() // Allow access to login, 404, or buyProduct } goToLogin(to, next) // Redirect to login if no token } @@ -153,8 +156,8 @@ router.beforeEach(async (to, from, next) => { return next() // Proceed to the intended route } else { // If no token, ensure proper redirection to login or 404 - if (['login', '404'].includes(to.name as string)) { - return next() // Allow access to login or 404 + if (['login', '404', 'buyProduct'].includes(to.name as string)) { + return next() // Allow access to login, 404, or buyProduct } return next({ name: 'login' }) } diff --git a/src/models/gold.ts b/src/models/gold.ts index 1578a63..06a6e7f 100644 --- a/src/models/gold.ts +++ b/src/models/gold.ts @@ -3,6 +3,7 @@ export interface Gold { goldValue?: number | null, percentWallet?: number, method?:string, - goldVazn?: number | null + goldVazn?: number | null, + gateway?: boolean } \ No newline at end of file diff --git a/src/models/order.ts b/src/models/order.ts index 84fd9d9..eb602e0 100644 --- a/src/models/order.ts +++ b/src/models/order.ts @@ -20,4 +20,5 @@ export interface Order { "product_id"?:number "method"?:string "number"?:number + "gateway"?:boolean } \ No newline at end of file diff --git a/src/router/index.ts b/src/router/index.ts index 4078eb1..2757781 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -17,7 +17,7 @@ const router = createRouter({ { path: `/`, name: 'main', - redirect: {name: 'login'}, + redirect: {name: 'buyProduct'}, component: () => import('../views/base/index.vue'), children: [ { diff --git a/src/utils/inputRules.ts b/src/utils/inputRules.ts index 3ba610e..e851e12 100644 --- a/src/utils/inputRules.ts +++ b/src/utils/inputRules.ts @@ -135,6 +135,7 @@ let methodP = 'cash' let amountP = 0 let isBuyP = true let NumP = 0 +let gatewayP = false const checkNumber = async (_rule: Rule, value: number) => { @@ -145,18 +146,20 @@ const checkNumber = async (_rule: Rule, value: number) => { return Promise.reject('استفاده از اعداد اعشاری مجاز نمی باشد') } if (isBuyP) { - if (!walletCash?.walletInfo?.cash && methodP == 'cash') { - return Promise.reject('موجودی کیف پول ناکافی است') + // 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?.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('موجودی کیف طلا ناکافی است') - else - return Promise.resolve() + return Promise.resolve() } else { if (value > NumP) return Promise.reject('موجودی محصول ناکافی است') @@ -165,11 +168,12 @@ const checkNumber = async (_rule: Rule, value: number) => { } } -export const justNumber2 = (price: number, method?: string, amount?: number, isBuy?: boolean) => { +export const justNumber2 = (price: number, method?: string, amount?: number, isBuy?: boolean, gateway?: boolean) => { priceP = price methodP = method amountP = amount isBuyP = isBuy + gatewayP = gateway ?? false return { required: true, validator: checkNumber, diff --git a/src/utils/useAxios.ts b/src/utils/useAxios.ts index be18a90..9cc9cb5 100644 --- a/src/utils/useAxios.ts +++ b/src/utils/useAxios.ts @@ -65,8 +65,10 @@ _axios.interceptors.response.use( ///removeToken() console.log('error') removeToken() - // router.push({ name: 'login' }) - await router.push({name: 'login'}) + // Don't redirect to login if user is on buyProduct page + if (router.currentRoute.value.name !== 'buyProduct') { + await router.push({name: 'login'}) + } } else if (error.response && error.response.status == 403) { message.error('شما دسترسی لازم برای انجام این عملیات را ندارید') } else if (error.response && error.response.status == 422) { diff --git a/src/views/base/index.vue b/src/views/base/index.vue index 4af2dc2..6e84e65 100644 --- a/src/views/base/index.vue +++ b/src/views/base/index.vue @@ -43,6 +43,13 @@