validate.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /**
  2. * @param {string} path
  3. * @returns {Boolean}
  4. */
  5. export function isExternal(path) {
  6. return /^(https?:|mailto:|tel:)/.test(path);
  7. }
  8. /**
  9. * @param {string} str
  10. * @returns {Boolean}
  11. */
  12. export function validUsername(str) {
  13. const valid_map = ["admin", "editor"];
  14. return valid_map.indexOf(str.trim()) >= 0;
  15. }
  16. // 手机号验证
  17. export function isvalidPhone(str) {
  18. const reg = /^1[3|4|5|6|7|8|9][0-9]\d{8}$/;
  19. return reg.test(str);
  20. }
  21. // 学生地址
  22. export function vaildStudentUrl() {
  23. let url = window.location.hostname;
  24. let returnUrl = "";
  25. if (/dev/.test(url)) {
  26. // dev 环境
  27. returnUrl = "https://dev.gym.lexiaoya.cn/mdaya";
  28. } else if (/test/.test(url)) {
  29. // dev 环境
  30. returnUrl = "https://test.gym.lexiaoya.cn/mdaya";
  31. } else {
  32. returnUrl = "https://gym.lexiaoya.cn/mdaya";
  33. }
  34. return returnUrl;
  35. }
  36. // 老师地址
  37. export function vaildTeacherUrl() {
  38. let url = window.location.hostname;
  39. let returnUrl = "";
  40. if (/dev/.test(url)) {
  41. // dev 环境
  42. returnUrl = "https://dev.gym.lexiaoya.cn/mteacher";
  43. } else if (/test/.test(url)) {
  44. // dev 环境
  45. returnUrl = "https://test.gym.lexiaoya.cn/mteacher";
  46. } else {
  47. // 线上环境
  48. returnUrl = "https://gym.lexiaoya.cn/mteacher";
  49. }
  50. return returnUrl;
  51. }
  52. // 教务地址
  53. export function vaildTeachingUrl() {
  54. let url = window.location.hostname;
  55. let returnUrl = "";
  56. if (/dev/.test(url)) {
  57. // dev 环境
  58. returnUrl = "https://dev.gym.lexiaoya.cn/manager";
  59. } else if (/test/.test(url)) {
  60. // dev 环境
  61. returnUrl = "https://test.gym.lexiaoya.cn/manager";
  62. } else {
  63. // 线上环境
  64. returnUrl = "https://gym.lexiaoya.cn/manager";
  65. }
  66. return returnUrl;
  67. }
  68. // 学校地址
  69. export function vaildSchoolUrl() {
  70. let url = window.location.hostname;
  71. let returnUrl = "";
  72. if (/dev/.test(url)) {
  73. // dev 环境
  74. returnUrl = "https://dev.gym.lexiaoya.cn/school";
  75. } else if (/test/.test(url)) {
  76. // dev 环境
  77. returnUrl = "https://test.gym.lexiaoya.cn/school";
  78. } else {
  79. // 线上环境
  80. returnUrl = "https://gym.lexiaoya.cn/school";
  81. }
  82. return returnUrl;
  83. }
  84. // OA地址
  85. export function validOaUrl() {
  86. let url = window.location.hostname;
  87. let returnUrl = "";
  88. if (/dev/.test(url)) {
  89. // dev 环境
  90. returnUrl = "https://dev.gym.lexiaoya.cn/oa";
  91. } else if (/test/.test(url)) {
  92. // dev 环境
  93. returnUrl = "https://test.gym.lexiaoya.cn/oa";
  94. } else {
  95. // 线上环境
  96. returnUrl = "https://gym.lexiaoya.cn/oa";
  97. }
  98. return returnUrl;
  99. }
  100. // 商城地址
  101. export function validMallUrl() {
  102. let url = window.location.hostname;
  103. let returnUrl = "";
  104. if (/dev/.test(url)) {
  105. // dev 环境
  106. returnUrl = "https://dev.gym.lexiaoya.cn/mall/";
  107. } else if (/test/.test(url)) {
  108. // dev 环境
  109. returnUrl = "https://test.gym.lexiaoya.cn/mall/";
  110. } else {
  111. // 线上环境
  112. returnUrl = "https://gym.lexiaoya.cn/mall/";
  113. }
  114. return returnUrl;
  115. }
  116. export function nextMonthLastDay(year, month) {
  117. //日期显示为次月最后一天
  118. // var time = date ? new Date(date) : new Date();
  119. // var year = time.getFullYear();
  120. // //var year = 1900; //用于测试
  121. // var month = time.getMonth() + 2;
  122. if (month > 12) {
  123. month = month - 12;
  124. year = year + 1;
  125. }
  126. var day = nextMonthDay(year, month);
  127. return [year, month, day];
  128. }
  129. function nextMonthDay(year, month) {
  130. //判断每月多少天
  131. var day31 = [1, 3, 5, 7, 8, 10, 12];
  132. var day30 = [4, 6, 9, 11];
  133. if (day31.indexOf(month) > -1) {
  134. return 31;
  135. } else if (day30.indexOf(month) > -1) {
  136. return 30;
  137. } else {
  138. if (isLeapYear(year)) {
  139. return 29;
  140. } else {
  141. return 28;
  142. }
  143. }
  144. }
  145. function isLeapYear(year) {
  146. //判断是否为闰年
  147. return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
  148. }