function.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. export const getQuery = (url) => {
  2. // str为?之后的参数部分字符串
  3. const str = url.substr(url.indexOf('?') + 1)
  4. // arr每个元素都是完整的参数键值
  5. const arr = str.split('&')
  6. // result为存储参数键值的集合
  7. const result = {}
  8. for (let i = 0; i < arr.length; i++) {
  9. // item的两个元素分别为参数名和参数值
  10. const item = arr[i].split('=')
  11. result[item[0]] = item[1]
  12. }
  13. return result
  14. }
  15. export function extractValuesFromString(inputString) {
  16. // 使用正则表达式来匹配 "&" 前面的 6 个字符和 "type" 及其值
  17. const regex = /([^&]{6})&type=([^&]+)/;
  18. const matches = inputString.match(regex);
  19. if (matches) {
  20. const extractedValueBeforeAmpersand = matches[1];
  21. const extractedType = matches[2];
  22. return { value: `8b${extractedValueBeforeAmpersand}`, type: extractedType };
  23. }
  24. return false; // 如果没有匹配,返回 null 或者其他适当的值
  25. }
  26. // 定时器
  27. export function waitByTime(settime = 100) {
  28. return new Promise((resolve) => {
  29. setTimeout(() => {
  30. resolve()
  31. }, settime)
  32. })
  33. }