邃芒慧影、口播(PC) https://neuver.metavatar.cc/
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 

169 řádky
5.2 KiB

  1. /**
  2. * @description:使用JSON进行深度拷贝
  3. */
  4. export function deepCopy(data) {
  5. const copyData = JSON.stringify(data)
  6. return JSON.parse(copyData)
  7. }
  8. /**
  9. * @description 将bytes转化
  10. * @param {number} bytes
  11. * @return string
  12. */
  13. export function bytesToSize(bytes) {
  14. if (bytes === 0) return '0 B';
  15. var k = 1000, // or 1024
  16. sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
  17. i = Math.floor(Math.log(bytes) / Math.log(k));
  18. return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];
  19. }
  20. /**
  21. * @description 秒转化时分秒
  22. * @param {number} seconds
  23. * @return string
  24. */
  25. export function formatSeconds(value) {
  26. var theTime = parseInt(value);// 秒
  27. var theTime1 = 0;// 分
  28. var theTime2 = 0;// 小时
  29. if (theTime > 60) {
  30. theTime1 = parseInt(theTime / 60);
  31. theTime = parseInt(theTime % 60);
  32. if (theTime1 > 60) {
  33. theTime2 = parseInt(theTime1 / 60);
  34. theTime1 = parseInt(theTime1 % 60);
  35. }
  36. }
  37. var result = "" + parseInt(theTime) + " 秒";
  38. if (theTime1 > 0) {
  39. result = "" + parseInt(theTime1) + " 分" + result;
  40. }
  41. if (theTime2 > 0) {
  42. result = "" + parseInt(theTime2) + " 小时" + result;
  43. }
  44. return result;
  45. }
  46. /**
  47. * @description:滚动到对应id的位置
  48. * @param {type} id
  49. */
  50. export function scrollToID(id) {
  51. document.querySelector("#" + id).scrollIntoView({
  52. behavior: "smooth",
  53. block: "start",
  54. inline: "nearest",
  55. });
  56. }
  57. /**
  58. * @description 根据时间戳获取时间
  59. * @param {*} timestamp 必传,number类型,时间戳数据(10位及以下,10位至13位)
  60. * @param {*} format 选传,string类型,提供以下时间格式:YYYY-MM-DD hh:mm:ss、YYYY/MM/DD hh:mm:ss、YYYY.MM.DD hh:mm:ss、YYYY MM DD hh:mm:ss、YYYY年MM月DD日 hh:mm:ss、YYYY-MM-DD、YYYY/MM/DD、YYYY.MM.DD、YYYY MM DD、YYYY年MM月DD日;若不传,则默认为:YYYY-MM-DD
  61. * @returns 根据要求的时间格式
  62. * @version V 1.0, Created by YWQ, 2022.10.20
  63. */
  64. export function timestampToTime(timestamp, format) {
  65. //时间戳为10位需*1000,时间戳为13位不需乘1000
  66. const length = timestamp && timestamp.length ? timestamp.length : ''
  67. if (!length) return ""
  68. let date
  69. if (length <= 10) {
  70. date = new Date(timestamp * 1000)
  71. } else {
  72. date = new Date(timestamp)
  73. }
  74. let Y = String(date.getFullYear())
  75. let M = String(date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1)
  76. let D = String(date.getDate() + 1 < 10 ? '0' + (date.getDate()) : date.getDate())
  77. let h = String(date.getHours() + 1 < 10 ? '0' + (date.getHours()) : date.getHours())
  78. let m = String(date.getMinutes() + 1 < 10 ? '0' + (date.getMinutes()) : date.getMinutes())
  79. let s = String(date.getSeconds() + 1 < 10 ? '0' + (date.getSeconds()) : date.getSeconds())
  80. // return Y + M + D + h + m + s
  81. if (format == "YYYY-MM-DD hh:mm:ss") {
  82. return Y + "-" + M + "-" + D + " " + h + ":" + m + ":" + s
  83. } else if (format == "YYYY/MM/DD hh:mm:ss") {
  84. return Y + "/" + M + "/" + D + " " + h + ":" + m + ":" + s
  85. } else if (format == "YYYY.MM.DD hh:mm:ss") {
  86. return Y + "." + M + "." + D + " " + h + ":" + m + ":" + s
  87. } else if (format == "YYYY MM DD hh:mm:ss") {
  88. return Y + " " + M + " " + D + " " + h + ":" + m + ":" + s
  89. } else if (format == "YYYY年MM月DD日 hh:mm:ss") {
  90. return Y + "年" + M + "月" + D + "日" + " " + h + ":" + m + ":" + s
  91. } else if (format == "YYYY-MM-DD") {
  92. return Y + "-" + M + "-" + D
  93. } else if (format == "YYYY/MM/DD") {
  94. return Y + "/" + M + "/" + D
  95. } else if (format == "YYYY.MM.DD") {
  96. return Y + "." + M + "." + D
  97. } else if (format == "YYYY MM DD") {
  98. return Y + " " + M + " " + D
  99. } else if (format == "YYYY年MM月DD日") {
  100. return Y + "年" + M + "月" + D + "日"
  101. } else {
  102. return Y + "-" + M + "-" + D
  103. }
  104. }
  105. // /**
  106. // * @description:获取设备类型
  107. // * @returns PC端为null,移动端为设备类型(Array)
  108. // */
  109. // export function getDeviceType() {
  110. // return navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)
  111. // }
  112. /**
  113. * @description:根据经纬度计算距离
  114. * @param {*} locationInfo (lat1, lng1, lat2, lng2)
  115. * @return: distanceObj: { distance , distance_str }
  116. */
  117. export function getDistances(lat1, lng1, lat2, lng2) {
  118. function rad(d) {
  119. return d * Math.PI / 180.0;
  120. }
  121. var radLat1 = rad(lat1);
  122. var radLat2 = rad(lat2);
  123. var a = radLat1 - radLat2;
  124. var b = rad(lng1) - rad(lng2);
  125. var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
  126. Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
  127. s = s * 6378.137;
  128. s = Math.round(s * 10000) / 10000;
  129. var distance = s;
  130. var distance_str = "";
  131. if (parseInt(distance) >= 1) {
  132. distance_str = distance.toFixed(2) + "km";
  133. } else {
  134. distance_str = (distance * 1000).toFixed(2) + "m";
  135. }
  136. let objData = {
  137. distance: distance,
  138. distance_str: distance_str
  139. }
  140. return objData
  141. }
  142. /**
  143. * @description:文本打字机
  144. * @param {*} data (text,target,duration)
  145. */
  146. export function typeWriter(text, target, duration) {
  147. let i = 0;
  148. let timer = setInterval(() => {
  149. target += text[i];
  150. if (i + 1 == text.length) {
  151. clearInterval(timer);
  152. } else {
  153. i++;
  154. }
  155. }, duration || 100);
  156. }