utils.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. export const getLocalToken = () => localStorage.getItem("token");
  2. export const saveLocalToken = (token: string) => localStorage.setItem("token", token);
  3. export const removeLocalToken = () => localStorage.removeItem("token");
  4. import type { Ref } from "vue";
  5. import { useI18n } from "vue-i18n";
  6. // export const emailRules = [
  7. // (v:any) => /^[a-z.0-9]+@[a-z.-]+\.[a-z]+$/i.test(v) || 'Must be a valid e-mail.',
  8. // ];
  9. // export const required = [
  10. // (v:any) => !!v || ('This field is required.'),
  11. // ];
  12. export function emailRules() {
  13. const { t } = useI18n();
  14. return [(v:any) => /^[a-z.0-9]+@[a-z.-]+\.[a-z]+$/i.test(v) || t('emailRules')];
  15. }
  16. export function required() {
  17. const { t } = useI18n();
  18. return [(v: any) => !!v || t('required')];
  19. }
  20. export const nameRules = [
  21. (v:any) => !!v || 'Name is required.',
  22. ];
  23. export const password1Rules = [
  24. (v:any) => !!v || 'Password is required.',
  25. (v:any) => (v && v.length >= 8) || 'Password must be more than 8 characters',
  26. ];
  27. export const usePassword2Rules = (password1:Ref<string>) => [
  28. (password2:string) => (password2 === password1.value) || 'Input same password.',
  29. ]