validate.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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.href;
  24. let returnUrl = "";
  25. if (/online/.test(url)) {
  26. //线上
  27. returnUrl = "https://mstuonline.dayaedu.com";
  28. } else if (/dev/.test(url)) {
  29. // dev 环境
  30. returnUrl = "http://mstudev.dayaedu.com";
  31. } else if (/test/.test(url)) {
  32. // dev 环境
  33. returnUrl = "http://mstutest.dayaedu.com";
  34. } else {
  35. // 默认dev环境
  36. returnUrl = "http://mstutest.dayaedu.com";
  37. }
  38. return returnUrl;
  39. }
  40. // 老师地址
  41. export function vaildTeacherUrl() {
  42. let url = window.location.href;
  43. let returnUrl = "";
  44. if (/online/.test(url)) {
  45. //线上
  46. returnUrl = "https://mteaonline.dayaedu.com";
  47. } else if (/dev/.test(url)) {
  48. // dev 环境
  49. returnUrl = "http://mteadev.dayaedu.com";
  50. } else if (/test/.test(url)) {
  51. // dev 环境
  52. returnUrl = "http://mteatest.dayaedu.com";
  53. } else {
  54. // 默认dev环境
  55. returnUrl = "https://mteatest.dayaedu.com";
  56. }
  57. return returnUrl;
  58. }
  59. // 教务地址
  60. export function vaildTeachingUrl() {
  61. let url = window.location.href;
  62. let returnUrl = "";
  63. if (/online/.test(url)) {
  64. //线上
  65. returnUrl = "https://manonline.dayaedu.com";
  66. } else if (/dev/.test(url)) {
  67. // dev 环境
  68. returnUrl = "http://mandev.dayaedu.com";
  69. } else if (/test/.test(url)) {
  70. // dev 环境
  71. returnUrl = "http://mantest.dayaedu.com";
  72. } else {
  73. // 默认dev环境
  74. returnUrl = "http://mantest.dayaedu.com";
  75. }
  76. return returnUrl;
  77. }
  78. // OA地址
  79. export function validOaUrl() {
  80. let url = window.location.href;
  81. let returnUrl = "";
  82. if (/online/.test(url)) {
  83. //线上
  84. returnUrl = "https://oaonline.dayaedu.com";
  85. } else if (/dev/.test(url)) {
  86. // dev 环境
  87. returnUrl = "http://oadev.dayaedu.com";
  88. } else if (/test/.test(url)) {
  89. // dev 环境
  90. returnUrl = "https://oatest.dayaedu.com";
  91. } else {
  92. // 默认dev环境
  93. returnUrl = "http://oatest.dayaedu.com";
  94. }
  95. return returnUrl;
  96. }
  97. // 商城地址
  98. export function validMallUrl() {
  99. let url = window.location.href;
  100. let returnUrl = "";
  101. if (/online/.test(url)) {
  102. //线上
  103. returnUrl = "https://online.dayaedu.com/mall/";
  104. } else if (/dev/.test(url)) {
  105. // dev 环境
  106. returnUrl = "https://dev.dayaedu.com/mall/";
  107. } else if (/test/.test(url)) {
  108. // dev 环境
  109. returnUrl = "https://test.dayaedu.com/mall/";
  110. } else {
  111. // 默认dev环境
  112. returnUrl = "https://test.dayaedu.com/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. }