basic.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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
  33. @click="
  34. () => {
  35. mapShow = true
  36. }
  37. "
  38. >打开小地图</kk-button
  39. >
  40. <kk-button
  41. type="primary"
  42. mr4
  43. @click="
  44. () => {
  45. mapShow = false
  46. }
  47. "
  48. >关闭小地图</kk-button
  49. >
  50. </div>
  51. <Teleport v-if="loading" to=".kankan-plugins">
  52. <kk-minmap ref="minMap" :show="mapShow" />
  53. </Teleport>
  54. </div>
  55. </template>
  56. <style>
  57. html,
  58. body,
  59. #app {
  60. width: 100%;
  61. height: 100%;
  62. padding: 0;
  63. margin: 0;
  64. }
  65. .scene {
  66. width: 100%;
  67. height: 100%;
  68. padding: 0;
  69. margin: 0;
  70. position: relative;
  71. }
  72. .test-control {
  73. width: 100%;
  74. position: absolute;
  75. top: 0;
  76. left: 0;
  77. height: 200px;
  78. z-index: 10;
  79. display: flex;
  80. flex-direction: row;
  81. justify-content: flex-end;
  82. align-items: center;
  83. }
  84. </style>