2026-01-18 13:01:46 +03:30
|
|
|
/*
|
|
|
|
|
export function inputRules(title?: string) {
|
|
|
|
|
if (title) {
|
|
|
|
|
return [required(title)]
|
|
|
|
|
} else {
|
|
|
|
|
return [required]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function inputLenRules(len: number, title?: string) {
|
|
|
|
|
if (title) {
|
|
|
|
|
return [
|
|
|
|
|
required(title),
|
|
|
|
|
lenthValidation(len)
|
|
|
|
|
]
|
|
|
|
|
} else {
|
|
|
|
|
return [
|
|
|
|
|
required,
|
|
|
|
|
lenthValidation(len)
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*export const persianValidation = computed(() => {
|
|
|
|
|
const temp = inputRules()
|
|
|
|
|
temp.push({ pattern: /^[A-Za-z]*$/, message: 'فقط حروف انگلیسی مجاز است' })
|
|
|
|
|
return temp
|
|
|
|
|
})*/
|
|
|
|
|
|
|
|
|
|
import {computed, ref} from 'vue'
|
|
|
|
|
import type {Rule} from 'ant-design-vue/es/form'
|
|
|
|
|
import {useWalletStore} from "@/store/walletStore";
|
2026-06-03 19:54:23 +03:30
|
|
|
import { isCashLikeDealMethod, getInsufficientCashWalletMessage, getInsufficientGoldWalletMessage } from '@/utils/productDealMethod'
|
2026-01-18 13:01:46 +03:30
|
|
|
|
|
|
|
|
export const mobileValidation = (title?: string) => {
|
|
|
|
|
return {len: 11, message: `شماره همراه باید 11 رقم باشد`}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const required = (title?: string) => {
|
|
|
|
|
if (title) {
|
|
|
|
|
return {required: true, message: `پر کردن ${title} الزامی است`}
|
|
|
|
|
} else {
|
|
|
|
|
return {required: true, message: `پر کردن مورد بالا الزامی است`}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// function checkCodeMeli(code)
|
|
|
|
|
// {
|
|
|
|
|
//
|
|
|
|
|
// let L=code.length;
|
|
|
|
|
// if(L<8 || parseInt(code,10)==0) return false;
|
|
|
|
|
// code=('0000'+code).substr(L+4-10);
|
|
|
|
|
// if(parseInt(code.substr(3,6),10)==0) return false;
|
|
|
|
|
// let c=parseInt(code.substr(9,1),10);
|
|
|
|
|
// let s=0;
|
|
|
|
|
// for(let i=0;i<9;i++)
|
|
|
|
|
// s+=parseInt(code.substr(i,1),10)*(10-i);
|
|
|
|
|
// s=s%11;
|
|
|
|
|
// return (s<2 && c==s) || (s>=2 && c==(11-s));
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
export const cardNumberValidation = (title?: string) => {
|
|
|
|
|
return { len: 16, message: `شماره کارت باید 16 رقم باشد` }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const isValidNationalCode = (code) => {
|
|
|
|
|
if (code.length !== 10 || /(\d)(\1){9}/.test(code)) return false
|
|
|
|
|
|
|
|
|
|
let sum = 0,
|
|
|
|
|
chars = code.split(''),
|
|
|
|
|
lastDigit,
|
|
|
|
|
remainder
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < 9; i++) sum += +chars[i] * (10 - i)
|
|
|
|
|
|
|
|
|
|
remainder = sum % 11
|
|
|
|
|
lastDigit = remainder < 2 ? remainder : 11 - remainder
|
|
|
|
|
|
|
|
|
|
return +chars[9] === lastDigit
|
|
|
|
|
}
|
|
|
|
|
export const requireNationalCode = (code?: string) => {
|
|
|
|
|
return {required: true, validator: validateNCode, trigger: 'change'}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function validateNCode(rule: Rule, value: any) {
|
|
|
|
|
if (!value) {
|
|
|
|
|
return Promise.reject('وارد کردن کد ملی الزامیست')
|
|
|
|
|
}
|
|
|
|
|
if (isValidNationalCode(value)) return Promise.resolve()
|
|
|
|
|
else return Promise.reject('کد ملی وارد شده نامعتبر است')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function inputLenRules(len: number, title?: string) {
|
|
|
|
|
if (title) {
|
|
|
|
|
return [
|
|
|
|
|
{required: true, message: `پر کردن ${title} الزامی است`},
|
|
|
|
|
{len: len, message: `تعداد کاراکتر باید ${len} عدد باشد`}
|
|
|
|
|
]
|
|
|
|
|
} else {
|
|
|
|
|
return [
|
|
|
|
|
{required: true, message: 'پر کردن مورد بالا الزامی است'},
|
|
|
|
|
{len: len, message: `تعداد کاراکتر باید ${len} عدد باشد`}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const persianValidation = computed(() => {
|
|
|
|
|
return {
|
|
|
|
|
pattern: /^[A-Za-z]*$/,
|
|
|
|
|
message: 'فقط حروف انگلیسی مجاز است'
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export const isValidPersian = () => {
|
|
|
|
|
return {
|
|
|
|
|
pattern: /^[\u0600-\u06FF\s]+$/,
|
|
|
|
|
message: 'فقط حروف فارسی مجاز است'
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const lengthValidation = (len: number) => {
|
|
|
|
|
return {len: len, message: `تعداد کاراکتر باید ${len} عدد باشد`}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const justNumber = () => {
|
|
|
|
|
return {
|
|
|
|
|
required: true,
|
|
|
|
|
type: 'regexp',
|
|
|
|
|
pattern: /\d+/g,
|
|
|
|
|
message: 'لطفا اطلاعات را به صورت عدد و نقطه وارد کنید'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const walletCash = useWalletStore()
|
|
|
|
|
let priceP = 0
|
|
|
|
|
let methodP = 'cash'
|
|
|
|
|
let amountP =0
|
|
|
|
|
let isBuyP=true
|
|
|
|
|
let NumP=0
|
2026-06-03 19:54:23 +03:30
|
|
|
let groupTypeP: string | undefined
|
2026-01-18 13:01:46 +03:30
|
|
|
const checkNumber = async (_rule: Rule, value: number) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!value) {
|
|
|
|
|
return Promise.reject('تعداد محصول را مشخص کنید');
|
|
|
|
|
}
|
|
|
|
|
if (value % 1 !== 0) {
|
|
|
|
|
return Promise.reject('استفاده از اعداد اعشاری مجاز نمی باشد')
|
|
|
|
|
}
|
|
|
|
|
if (isBuyP){
|
2026-06-01 17:19:45 +03:30
|
|
|
if (!walletCash?.walletInfo?.cash && isCashLikeDealMethod(methodP)){
|
2026-06-03 19:54:23 +03:30
|
|
|
return Promise.reject(getInsufficientCashWalletMessage(groupTypeP))
|
2026-01-18 13:01:46 +03:30
|
|
|
}
|
|
|
|
|
if (!walletCash?.walletInfo?.gold && methodP == 'gold'){
|
2026-06-03 19:54:23 +03:30
|
|
|
return Promise.reject(getInsufficientGoldWalletMessage(groupTypeP))
|
2026-01-18 13:01:46 +03:30
|
|
|
}
|
2026-06-01 17:19:45 +03:30
|
|
|
if (priceP * value > walletCash?.walletInfo?.cash && isCashLikeDealMethod(methodP))
|
2026-06-03 19:54:23 +03:30
|
|
|
return Promise.reject(getInsufficientCashWalletMessage(groupTypeP))
|
2026-01-18 13:01:46 +03:30
|
|
|
if (amountP * value > walletCash?.walletInfo?.gold && methodP == 'gold')
|
2026-06-03 19:54:23 +03:30
|
|
|
return Promise.reject(getInsufficientGoldWalletMessage(groupTypeP))
|
2026-01-18 13:01:46 +03:30
|
|
|
else
|
|
|
|
|
return Promise.resolve();
|
|
|
|
|
}else {
|
|
|
|
|
if (value > NumP)
|
|
|
|
|
return Promise.reject('موجودی محصول ناکافی است')
|
|
|
|
|
else
|
|
|
|
|
return Promise.resolve();
|
2026-02-03 16:18:53 +03:30
|
|
|
}
|
2026-01-18 13:01:46 +03:30
|
|
|
}
|
|
|
|
|
|
2026-06-03 19:54:23 +03:30
|
|
|
export const justNumber2 = (price: number, method?: string , amount?:number ,isBuy?:boolean, groupType?: string) => {
|
2026-01-18 13:01:46 +03:30
|
|
|
priceP = price
|
|
|
|
|
methodP = method
|
|
|
|
|
amountP=amount
|
|
|
|
|
isBuyP=isBuy
|
2026-06-03 19:54:23 +03:30
|
|
|
groupTypeP = groupType
|
2026-01-18 13:01:46 +03:30
|
|
|
return {
|
|
|
|
|
required: true,
|
|
|
|
|
validator: checkNumber,
|
|
|
|
|
trigger: 'change'
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-02-03 16:18:53 +03:30
|
|
|
|
2026-01-18 13:01:46 +03:30
|
|
|
export const justNumber3 = (price: number, Num?:number ,isBuy?:boolean) => {
|
|
|
|
|
priceP = price
|
|
|
|
|
NumP=Num
|
|
|
|
|
isBuyP=isBuy
|
|
|
|
|
return {
|
|
|
|
|
required: true,
|
|
|
|
|
validator: checkNumber,
|
|
|
|
|
trigger: 'change'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const ruleNumber = () => {
|
|
|
|
|
console.log('445455')
|
|
|
|
|
return {
|
|
|
|
|
required: true,
|
|
|
|
|
message: 'لطفا نحوه خرید',
|
|
|
|
|
trigger: 'change'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const guideTypePassword = ref<{}>({
|
|
|
|
|
text: '',
|
|
|
|
|
color: ''
|
|
|
|
|
})
|
2026-02-03 16:18:53 +03:30
|
|
|
|
2026-01-18 13:01:46 +03:30
|
|
|
export const passwordRules = () => {
|
|
|
|
|
return [
|
|
|
|
|
{
|
|
|
|
|
validator: (rule: Rule, value: any) => {
|
|
|
|
|
if (value.length < 6) {
|
|
|
|
|
return Promise.reject('رمز عبور حداقل 6 رقم')
|
|
|
|
|
}
|
|
|
|
|
const lengthCriteria = value.length >= 8
|
|
|
|
|
const letterCriteria = /[A-Za-z]/.test(value)
|
|
|
|
|
const numberCriteria = /\d/.test(value)
|
|
|
|
|
const specialCharacterCriteria = /[@$!%*#?&]/.test(value)
|
|
|
|
|
const criteriaMet = [
|
|
|
|
|
lengthCriteria,
|
|
|
|
|
letterCriteria,
|
|
|
|
|
numberCriteria,
|
|
|
|
|
specialCharacterCriteria
|
|
|
|
|
].filter(Boolean).length
|
|
|
|
|
if (criteriaMet === 4) {
|
|
|
|
|
guideTypePassword.value = {
|
|
|
|
|
text: 'سطح : قوی',
|
|
|
|
|
color: 'text-green'
|
|
|
|
|
}
|
|
|
|
|
return Promise.resolve();
|
|
|
|
|
} else if (criteriaMet === 3) {
|
|
|
|
|
guideTypePassword.value = {
|
|
|
|
|
text: 'سطح : متوسط',
|
|
|
|
|
color: 'midLevel'
|
|
|
|
|
}
|
|
|
|
|
return Promise.resolve();
|
|
|
|
|
} else {
|
|
|
|
|
guideTypePassword.value = {
|
|
|
|
|
text: 'سطح : ضعیف',
|
|
|
|
|
color: 'week'
|
|
|
|
|
}
|
|
|
|
|
return Promise.resolve();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
2026-02-03 16:18:53 +03:30
|
|
|
|
|
|
|
|
export const englishNumberRule = () => {
|
|
|
|
|
return {
|
2026-02-05 11:41:04 +03:30
|
|
|
validator: (_: any, value: string | number) => {
|
|
|
|
|
const str = value != null ? String(value) : ''
|
|
|
|
|
if (!str) return Promise.resolve()
|
|
|
|
|
const isEnglishDigitsOnly = /^[0-9]+$/.test(str)
|
|
|
|
|
if (!isEnglishDigitsOnly) {
|
2026-02-03 16:18:53 +03:30
|
|
|
return Promise.reject('لطفاً فقط از اعداد انگلیسی استفاده کنید')
|
|
|
|
|
}
|
|
|
|
|
return Promise.resolve()
|
|
|
|
|
},
|
2026-02-05 11:41:04 +03:30
|
|
|
trigger: ['change', 'blur'],
|
2026-02-03 16:18:53 +03:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-05 11:41:04 +03:30
|
|
|
|