basic.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <script setup lang="ts">
  2. import { onMounted, onUnmounted, provide, ref } from 'vue'
  3. import { KkButton, KkMinmap } from 'kankan-components'
  4. const loading = ref(false)
  5. const mapShow = ref(false)
  6. const minMap = ref(null)
  7. onMounted(() => {
  8. const __win = window as any
  9. if (!__win.__sdk) {
  10. const __sdk = (__win.__sdk = new __win.KanKan({
  11. num: 'KJ-t-wOXfx2SDFy',
  12. server: '#DEMOSEVER#',
  13. }))
  14. provide('__sdk', __sdk)
  15. __sdk.Scene.on('ready', () => (loading.value = true))
  16. __sdk.use('MinMap').then(() => {
  17. mapShow.value = true
  18. })
  19. __sdk.mount('#scene').render()
  20. }
  21. })
  22. onUnmounted(() => {
  23. const __win = window as any
  24. if (__win.__sdk) {
  25. __win.__sdk = null
  26. }
  27. })
  28. </script>
  29. <template>
  30. <div id="scene" class="scene">
  31. <div class="test-control">
  32. <kk-button @click="mapShow = true">打开小地图</kk-button>
  33. <kk-button type="primary" mr4 @click="mapShow = false"
  34. >关闭小地图</kk-button
  35. >
  36. </div>
  37. <Teleport v-if="loading" to=".kankan-plugins">
  38. <kk-minmap ref="minMap" :show="mapShow" />
  39. </Teleport>
  40. </div>
  41. </template>
  42. <style>
  43. html,
  44. body,
  45. #app {
  46. width: 100%;
  47. height: 100%;
  48. padding: 0;
  49. margin: 0;
  50. }
  51. .scene {
  52. width: 100%;
  53. height: 100%;
  54. padding: 0;
  55. margin: 0;
  56. position: relative;
  57. }
  58. .test-control {
  59. width: 100%;
  60. position: absolute;
  61. top: 0;
  62. left: 0;
  63. height: 200px;
  64. z-index: 10;
  65. display: flex;
  66. flex-direction: row;
  67. justify-content: flex-end;
  68. align-items: center;
  69. }
  70. </style>