pass.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. function NoToChinese (num) {
  2. num = String(num)
  3. var chnNumChar = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九', '十']
  4. if (num == 0) {
  5. return chnNumChar[0]
  6. }
  7. let tmp = ''
  8. for (let i = 0; i < num.length; i++) {
  9. const ele = num.charAt(i)
  10. tmp += chnNumChar[ele]
  11. }
  12. return tmp
  13. }
  14. function randomWord (randomFlag, min, max) {
  15. let str = ''
  16. let range = min
  17. const arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
  18. // 随机产生
  19. if (randomFlag) {
  20. range = Math.round(Math.random() * (max - min)) + min
  21. }
  22. for (var i = 0; i < range; i++) {
  23. const pos = Math.round(Math.random() * (arr.length - 1))
  24. str += arr[pos]
  25. }
  26. return str
  27. }
  28. export function formatDate (time) {
  29. var weekArr = ['日', '一', '二', '三', '四', '五', '六']
  30. var date = new Date(time)
  31. var year = date.getFullYear()
  32. var month = date.getMonth() + 1
  33. var day = date.getDate()
  34. var week = '星期' + weekArr[date.getDay()]
  35. if (window.innerWidth < 1700) {
  36. return (
  37. year +
  38. '年' +
  39. (String(month).length > 1 ? month : '0' + month) +
  40. '月' +
  41. (String(day).length > 1 ? day : '0' + day) +
  42. '日' +
  43. '<br/>' +
  44. week
  45. )
  46. }
  47. return (
  48. year +
  49. '年' +
  50. (String(month).length > 1 ? month : '0' + month) +
  51. '月' +
  52. (String(day).length > 1 ? day : '0' + day) +
  53. '日' +
  54. ' ' +
  55. week
  56. )
  57. }
  58. export function smoothscrollpos (domName) {
  59. if (domName == '/') {
  60. return window.scrollTo(0, 0)
  61. }
  62. const smoothscroll = () => {
  63. const dom = document.getElementById(domName)
  64. // window.scrollTo({
  65. // top:dom.offsetTop - 100,
  66. // left:0,
  67. // behavior: "smooth"
  68. // })
  69. dom && window.scrollTo(0, dom.offsetTop - 120)
  70. }
  71. smoothscroll()
  72. }
  73. export function formatTime (time, fan = false) {
  74. let t1 = time.split(' ')[0].split('-')
  75. if (fan) {
  76. t1 = t1.map((item) => {
  77. const t = NoToChinese(item)
  78. return t
  79. })
  80. }
  81. return t1
  82. }
  83. export function encodeStr (str, strv = '') {
  84. const NUM = 2
  85. const front = randomWord(false, 8)
  86. const middle = randomWord(false, 8)
  87. const end = randomWord(false, 8)
  88. const str1 = str.substring(0, NUM)
  89. const str2 = str.substring(NUM)
  90. if (strv) {
  91. const strv1 = strv.substring(0, NUM)
  92. const strv2 = strv.substring(NUM)
  93. return [front + str2 + middle + str1 + end, front + strv2 + middle + strv1 + end]
  94. }
  95. return front + str2 + middle + str1 + end
  96. }
  97. export function decodeStr (str) {
  98. const NUM = 2
  99. const str1 = str.substring(8)
  100. const str2 = str1.substring(0, str1.length - 8)
  101. const front = str2.slice(-NUM)
  102. const end = str2.substring(0, str2.length - 8 - NUM)
  103. return front + end
  104. }