DataBase.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <script setup lang="ts">
  2. import {
  3. nextTick,
  4. onActivated,
  5. onDeactivated,
  6. onMounted,
  7. ref
  8. } from "vue";
  9. import {userInfoStore} from "@/utils/store-public";
  10. import DataBaseDialog from "@/views/data-base/data-base-api/components/DataBaseDialog.vue";
  11. const iframe = ref<HTMLIFrameElement | null>(null)
  12. // @ts-ignore
  13. const src = import.meta.env.VITE_DATA_BASE + '/magic/web/index.html'
  14. // const src = 'http://192.168.56.1:8991'
  15. // const src = 'http://172.16.32.160:9205/magic/web/index.html'
  16. const func = {
  17. 'user': user
  18. }
  19. const dialogRef = ref()
  20. function user() {
  21. dialogRef.value!.openDialog()
  22. }
  23. const getMessage = (e: { data: string}) => {
  24. const data : {
  25. name: string
  26. } = JSON.parse(e.data)
  27. // @ts-ignore
  28. func[data.name] && func[data.name]()
  29. }
  30. onDeactivated(() => {
  31. window.removeEventListener('message', getMessage)
  32. })
  33. onActivated(() => {
  34. window.addEventListener('message', getMessage)
  35. })
  36. onMounted(async () => {
  37. await nextTick()
  38. iframe.value!.onload = () => {
  39. const data = {
  40. token: userInfoStore.value.token,
  41. name: 'setToken'
  42. }
  43. // @ts-ignore
  44. iframe.value.contentWindow.postMessage(JSON.stringify(data), '*')
  45. }
  46. })
  47. </script>
  48. <template>
  49. <DataBaseDialog ref="dialogRef"/>
  50. <iframe :src="src"
  51. width="100%"
  52. height="100%"
  53. style="border: 0"
  54. ref="iframe"/>
  55. </template>
  56. <style lang="scss">
  57. </style>