base.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. const base = {
  2. reg: {
  3. idCard: /^\d{6}(18|19|20)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|[xX])$/,
  4. phone: /^1(?:3\d|4[4-9]|5[0-35-9]|6[67]|7[013-8]|8\d|9\d)\d{8}$/,
  5. email: /^([a-zA-Z0-9]+[_|_|.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|_|.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/
  6. },
  7. isImg: function (url) {
  8. var temp = []
  9. temp = url.toString().split('.')
  10. if (temp[temp.length - 1].toLowerCase() === 'png' || temp[temp.length - 1].toLowerCase() === 'jpg') {
  11. return true
  12. } else {
  13. return false
  14. }
  15. },
  16. isTypeBySend: function (fileName, typeArr) {
  17. if (typeof fileName !== 'string') return
  18. let name = fileName.toLowerCase()
  19. let boo = false
  20. typeArr.forEach(item => {
  21. console.log(name.endsWith(item))
  22. if (name.endsWith(item)) {
  23. boo = true
  24. }
  25. })
  26. return boo
  27. },
  28. timestampToTime: function (timestamp) {
  29. var date = new Date(Number(timestamp))// 时间戳为10位需*1000,时间戳为13位的话不需乘1000
  30. var Y = date.getFullYear() + '-'
  31. var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'
  32. var D = date.getDate() + ' '
  33. // var h = date.getHours() + ':'
  34. // var m = date.getMinutes() + ':'
  35. // var s = date.getSeconds()
  36. return Y + M + D
  37. },
  38. dateFormat: function (fmt, that) {
  39. var o = {
  40. 'M+': that.getMonth() + 1, // 月份
  41. 'd+': that.getDate(), // 日
  42. 'h+': that.getHours(), // 小时
  43. 'm+': that.getMinutes(), // 分
  44. 's+': that.getSeconds(), // 秒
  45. 'q+': Math.floor((that.getMonth() + 3) / 3), // 季度
  46. S: that.getMilliseconds() // 毫秒
  47. }
  48. if (/(y+)/.test(fmt)) {
  49. fmt = fmt.replace(
  50. RegExp.$1,
  51. (that.getFullYear() + '').substr(4 - RegExp.$1.length)
  52. )
  53. }
  54. for (var k in o) {
  55. if (new RegExp('(' + k + ')').test(fmt)) {
  56. fmt = fmt.replace(
  57. RegExp.$1,
  58. RegExp.$1.length === 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length)
  59. )
  60. }
  61. }
  62. return fmt
  63. }
  64. }
  65. export { base }