verify.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { RuleObject } from "ant-design-vue/lib/form/interface";
  2. // 验证 挂牌数量
  3. /**
  4. *
  5. * @param delistingQty 起摘数量
  6. * @param 挂牌数量对应的key
  7. * @param minivalue 最小单位
  8. * @param maxValue 最大数量(可选)
  9. * @returns
  10. */
  11. export const useVerifyListingNum = <T extends object, k extends keyof T>(formState: T, key: k, minivalue: number, maxValue?: number) => {
  12. const v_num = async (rule: RuleObject, value: number) => {
  13. if (value) {
  14. if (formState[key] && value < (formState[key] as unknown as number)) {
  15. return Promise.reject(`挂牌数量不能小于起摘数量`)
  16. }
  17. if (value < minivalue) {
  18. return Promise.reject(`挂牌数量不能小于${minivalue}`)
  19. }
  20. if (maxValue && value > maxValue) {
  21. return Promise.reject(`挂牌数量不能大于${maxValue}`)
  22. }
  23. if (value % minivalue) {
  24. return Promise.reject(`挂牌数量不是${minivalue}的倍数`)
  25. }
  26. return Promise.resolve();
  27. } else {
  28. return Promise.reject('请输入挂牌数量')
  29. }
  30. };
  31. return { v_num }
  32. }