validate.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 (/dev/.test(url)) { // dev 环境
  26. returnUrl = 'http://mstudev.dayaedu.com'
  27. } else if (/test/.test(url)) { // dev 环境
  28. returnUrl = 'http://mstutest.dayaedu.com'
  29. } else if (/online/.test(url)) { //线上
  30. returnUrl = 'https://mstuonline.dayaedu.com'
  31. } else { // 默认dev环境
  32. returnUrl = 'http://mstudev.dayaedu.com'
  33. }
  34. return returnUrl
  35. }
  36. // 老师地址
  37. export function vaildTeacherUrl() {
  38. let url = window.location.href
  39. let returnUrl = ''
  40. if (/dev/.test(url)) { // dev 环境
  41. returnUrl = 'http://mteadev.dayaedu.com'
  42. } else if (/test/.test(url)) { // dev 环境
  43. returnUrl = 'http://mteatest.dayaedu.com'
  44. } else if (/online/.test(url)) { //线上
  45. returnUrl = 'https://mteaonline.dayaedu.com'
  46. } else { // 默认dev环境
  47. returnUrl = 'http://mteadev.dayaedu.com'
  48. }
  49. return returnUrl
  50. }
  51. // 教务地址
  52. export function vaildTeachingUrl() {
  53. let url = window.location.href
  54. let returnUrl = ''
  55. if (/dev/.test(url)) { // dev 环境
  56. returnUrl = 'http://mandev.dayaedu.com/'
  57. } else if (/test/.test(url)) { // dev 环境
  58. returnUrl = 'http://mantest.dayaedu.com'
  59. } else if (/online/.test(url)) { //线上
  60. returnUrl = 'https://manonline.dayaedu.com'
  61. } else { // 默认dev环境
  62. returnUrl = 'http://mandev.dayaedu.com'
  63. }
  64. return returnUrl
  65. }
  66. export function nextMonthLastDay(year, month) { //日期显示为次月最后一天
  67. // var time = date ? new Date(date) : new Date();
  68. // var year = time.getFullYear();
  69. // //var year = 1900; //用于测试
  70. // var month = time.getMonth() + 2;
  71. if (month > 12) {
  72. month = month - 12;
  73. year = year + 1;
  74. }
  75. var day = nextMonthDay(year, month);
  76. return [year, month, day];
  77. }
  78. function nextMonthDay(year, month) { //判断每月多少天
  79. var day31 = [1, 3, 5, 7, 8, 10, 12];
  80. var day30 = [4, 6, 9, 11];
  81. if (day31.indexOf(month) > -1) {
  82. return 31;
  83. } else if (day30.indexOf(month) > -1) {
  84. return 30;
  85. } else {
  86. if (isLeapYear(year)) {
  87. return 29;
  88. } else {
  89. return 28;
  90. }
  91. }
  92. }
  93. function isLeapYear(year) { //判断是否为闰年
  94. return (year % 4 == 0) && (year % 100 != 0 || year % 400 == 0);
  95. }