custom.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <script setup lang="ts">
  2. import { onMounted, onUnmounted, provide, ref } from 'vue'
  3. import { KkButton, KkIcon, 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 改变主配色
  17. __sdk.use('MinMap', { theme: { camera_fillStyle: '#B8A965' } }).then(() => {
  18. mapShow.value = true
  19. })
  20. __sdk.mount('#scene').render()
  21. }
  22. })
  23. onUnmounted(() => {
  24. const __win = window as any
  25. if (__win.__sdk) {
  26. __win.__sdk = null
  27. }
  28. })
  29. </script>
  30. <template>
  31. <div id="scene" class="scene">
  32. <div class="test-control">
  33. <kk-button @click="mapShow = true">打开小地图</kk-button>
  34. <kk-button type="primary" mr4 @click="() => (mapShow = false)"
  35. >关闭小地图</kk-button
  36. >
  37. </div>
  38. <Teleport v-if="loading" to=".kankan-plugins">
  39. <kk-minmap ref="minMap" :show="mapShow">
  40. 自定义:<kk-icon type="updown" />
  41. </kk-minmap>
  42. </Teleport>
  43. </div>
  44. </template>
  45. <style>
  46. html,
  47. body,
  48. #app {
  49. width: 100%;
  50. height: 100%;
  51. padding: 0;
  52. margin: 0;
  53. }
  54. .scene {
  55. width: 100%;
  56. height: 100%;
  57. padding: 0;
  58. margin: 0;
  59. position: relative;
  60. }
  61. .test-control {
  62. width: 100%;
  63. position: absolute;
  64. top: 0;
  65. left: 0;
  66. height: 200px;
  67. z-index: 10;
  68. display: flex;
  69. flex-direction: row;
  70. justify-content: flex-start;
  71. align-items: center;
  72. }
  73. .kk-minmap[xui_min_map] {
  74. right: 20px;
  75. top: 20px;
  76. left: initial;
  77. width: 102px;
  78. height: 100px;
  79. border-bottom-left-radius: 0;
  80. border-bottom-right-radius: 0;
  81. }
  82. .kk-minmap__container {
  83. color: #fff;
  84. margin-top: 98%;
  85. font-size: 10px;
  86. background-color: rgba(0, 0, 0, 0.3);
  87. }
  88. </style>