|
@@ -4,12 +4,8 @@ import { onMounted, ref, unref } from 'vue'
|
|
|
import consola from 'consola'
|
|
|
|
|
|
const instance = (window as any).KanKan
|
|
|
-
|
|
|
-interface AppInstance {
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
+let app: KanKanInstance;
|
|
|
+const deferred = instance.Deferred()
|
|
|
interface appOptions {
|
|
|
region?: string
|
|
|
resource?: string
|
|
@@ -23,41 +19,28 @@ interface appOptions {
|
|
|
// })
|
|
|
|
|
|
// let deferred = KanKan.Deferred()
|
|
|
-export function useApp(options?: appOptions): [
|
|
|
- any,
|
|
|
-
|
|
|
-] {
|
|
|
- let app = null;
|
|
|
- const deferred = instance.Deferred()
|
|
|
- function register() {
|
|
|
- if (app) {
|
|
|
- return app
|
|
|
- }
|
|
|
- consola.log(import.meta.env)
|
|
|
- if (options) {
|
|
|
- if (!options?.region) {
|
|
|
- options.region = import.meta.env.VUE_APP_REGION_URL
|
|
|
- }
|
|
|
- if (!options?.resource) {
|
|
|
- options.region = import.meta.env.VUE_APP_RESOURCE_URL
|
|
|
- }
|
|
|
- if (!options?.resource) {
|
|
|
- options.server = '/'
|
|
|
- }
|
|
|
- console.log('options', options)
|
|
|
- if (!instance) {
|
|
|
- consola.error('kankan SDK 没有引入!')
|
|
|
- }
|
|
|
- const _app = new instance(options)
|
|
|
- deferred.resolve(_app);
|
|
|
- (window as any).__sdk = _app
|
|
|
- app = _app
|
|
|
- return app
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
+export function createApp(options: appOptions): Promise<KanKanInstance> {
|
|
|
+ if (!options?.region) {
|
|
|
+ options.region = import.meta.env.VUE_APP_REGION_URL
|
|
|
+ }
|
|
|
+ if (!options?.resource) {
|
|
|
+ options.region = import.meta.env.VUE_APP_RESOURCE_URL
|
|
|
+ }
|
|
|
+ if (!options?.resource) {
|
|
|
+ options.server = '/'
|
|
|
}
|
|
|
+ console.log('options', options)
|
|
|
+ if (!instance) {
|
|
|
+ consola.error('kankan SDK 没有引入!')
|
|
|
+ }
|
|
|
+ const _app = new instance(options)
|
|
|
+ deferred.resolve(_app);
|
|
|
+ (window as any).__sdk = _app
|
|
|
+ app = _app
|
|
|
+ return Promise.resolve(app)
|
|
|
+}
|
|
|
+
|
|
|
+export function useApp(): Promise<KanKanInstance | null> {
|
|
|
|
|
|
- return [register()];
|
|
|
}
|
|
|
|