app.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. let _app
  2. let _num
  3. let deferred = KanKan.Deferred()
  4. export function createApp(opitons = {}, forceNew = false) {
  5. if (_app) {
  6. return
  7. }
  8. opitons.deploy = process.env.VUE_APP_DEPLOY
  9. opitons.region = process.env.VUE_APP_REGION_URL
  10. opitons.resource = process.env.VUE_APP_RESOURCE_URL
  11. _num = opitons.num
  12. _app = new KanKan(opitons)
  13. deferred.resolve(_app)
  14. window.__sdk = _app
  15. if (opitons.mobile) {
  16. document.body.setAttribute('is-mobile', true)
  17. }
  18. return _app
  19. }
  20. export function createAppSingle(opitons = {}) {
  21. opitons.deploy = process.env.VUE_APP_DEPLOY
  22. opitons.region = process.env.VUE_APP_REGION_URL
  23. opitons.resource = process.env.VUE_APP_RESOURCE_URL
  24. if (opitons.mobile) {
  25. document.body.setAttribute('is-mobile', true)
  26. }
  27. var app = new KanKan(opitons)
  28. if (!_app) {
  29. _app = app
  30. deferred.resolve(_app)
  31. window.__sdk = _app
  32. }
  33. return app
  34. }
  35. export function useApp() {
  36. if (_app) {
  37. return Promise.resolve(_app)
  38. }
  39. return deferred
  40. }
  41. export function getApp() {
  42. return _app
  43. }
  44. export function getNum() {
  45. return _num
  46. }