custom.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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
  34. @click="
  35. () => {
  36. mapShow = true
  37. }
  38. "
  39. >打开小地图</kk-button
  40. >
  41. <kk-button
  42. type="primary"
  43. mr4
  44. @click="
  45. () => {
  46. mapShow = false
  47. }
  48. "
  49. >关闭小地图</kk-button
  50. >
  51. </div>
  52. <Teleport v-if="loading" to=".kankan-plugins">
  53. <kk-minmap ref="minMap" :show="mapShow">
  54. 自定义:<kk-icon type="updown" />
  55. </kk-minmap>
  56. </Teleport>
  57. </div>
  58. </template>
  59. <style>
  60. html,
  61. body,
  62. #app {
  63. width: 100%;
  64. height: 100%;
  65. padding: 0;
  66. margin: 0;
  67. }
  68. .scene {
  69. width: 100%;
  70. height: 100%;
  71. padding: 0;
  72. margin: 0;
  73. position: relative;
  74. }
  75. .test-control {
  76. width: 100%;
  77. position: absolute;
  78. top: 0;
  79. left: 0;
  80. height: 200px;
  81. z-index: 10;
  82. display: flex;
  83. flex-direction: row;
  84. justify-content: flex-start;
  85. align-items: center;
  86. }
  87. .kk-minmap[xui_min_map] {
  88. right: 20px;
  89. top: 20px;
  90. left: initial;
  91. width: 102px;
  92. height: 100px;
  93. border-bottom-left-radius: 0;
  94. border-bottom-right-radius: 0;
  95. }
  96. .kk-minmap__container {
  97. color: #fff;
  98. margin-top: 98%;
  99. font-size: 10px;
  100. background-color: rgba(0, 0, 0, 0.3);
  101. }
  102. </style>