validate.js 3.1 KB

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