index.js 849 B

123456789101112131415161718192021222324252627282930313233
  1. export const loadJs = (url) => {
  2. return new Promise((resolve, reject) => {
  3. const script = document.createElement('script')
  4. script.src = url
  5. script.type = 'text/javascript'
  6. document.body.appendChild(script)
  7. script.onload = () => {
  8. resolve()
  9. }
  10. })
  11. }
  12. export const loadCss = (url) => {
  13. return new Promise((resolve, reject) => {
  14. const link = document.createElement('link')
  15. link.rel = 'stylesheet'
  16. link.href = url
  17. document.head.appendChild(link)
  18. link.onload = () => {
  19. resolve()
  20. }
  21. })
  22. }
  23. export const generateUUID = () => {
  24. var d = new Date().getTime();
  25. var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
  26. var r = (d + Math.random()*16)%16 | 0;
  27. d = Math.floor(d/16);
  28. return (c=='x' ? r : (r&0x7|0x8)).toString(16);
  29. });
  30. return uuid;
  31. }