test.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <template>
  2. <div class="p-4">
  3. <template
  4. v-for="(item, index) in [
  5. 'businessModel1',
  6. 'businessModel2',
  7. 'businessModel3',
  8. ]"
  9. >
  10. <el-card class="mt-2">
  11. <div>
  12. iframe地址: {{ iframeUrlCpt + '?haveOrNo=' + state[item].haveOrNo }}
  13. </div>
  14. <div>
  15. <el-button type="primary" @click="onDetail(item)"
  16. >许可范围 {{ index + 1 }}</el-button
  17. >
  18. {{ state[item].list.length }} 条数据
  19. </div>
  20. <div>
  21. <CzrFormColumn
  22. label="haveOrNo"
  23. v-model:param="state[item].haveOrNo"
  24. link="radio"
  25. :options="DictionaryStore.businessModelHaveOrNoList"
  26. />
  27. </div>
  28. <div>
  29. <el-input
  30. type="textarea"
  31. v-model="state[item].strs"
  32. disabled
  33. :rows="4"
  34. />
  35. </div>
  36. </el-card>
  37. </template>
  38. <CzrDialog
  39. :show="state.detail.show"
  40. title="一级表单的弹窗"
  41. width="90%"
  42. height="90%"
  43. :show-close="false"
  44. :show-submit="false"
  45. @onClose="state.detail.show = false"
  46. >
  47. <iframe
  48. v-if="state.detail.show"
  49. class="w-full h-full"
  50. :src="state.detail.transfer.url"
  51. id="iframe"
  52. ref="ref_iframe"
  53. @load="onIframeInit"
  54. />
  55. </CzrDialog>
  56. </div>
  57. </template>
  58. <script setup lang="ts">
  59. import { computed, getCurrentInstance, onMounted, reactive, ref } from 'vue'
  60. import { ElMessageBox } from 'element-plus'
  61. import { useDictionaryStore } from '@/stores'
  62. const DictionaryStore = useDictionaryStore()
  63. const emit = defineEmits([])
  64. const props = defineProps({})
  65. const { proxy }: any = getCurrentInstance()
  66. const state: any = reactive({
  67. businessModel1: {
  68. strs: '',
  69. ids: '',
  70. list: [],
  71. haveOrNo: 1,
  72. },
  73. businessModel2: {
  74. strs: '',
  75. ids: '',
  76. list: [],
  77. haveOrNo: 0,
  78. },
  79. businessModel3: {
  80. strs: '',
  81. ids: '',
  82. list: [],
  83. haveOrNo: 0,
  84. },
  85. detail: {
  86. show: false,
  87. transfer: {},
  88. },
  89. })
  90. const ref_iframe = ref()
  91. const iframeUrlCpt = computed(
  92. () => `${location.origin}/${import.meta.env.VITE_BASE}/business-model/form`,
  93. )
  94. const onDetail = (key) => {
  95. state.detail.transfer = {
  96. url: iframeUrlCpt.value + '?haveOrNo=' + state[key].haveOrNo,
  97. key: key,
  98. }
  99. state.detail.show = true
  100. }
  101. const onIframeInit = () => {
  102. setTimeout(() => {
  103. ref_iframe.value.contentWindow.postMessage(
  104. {
  105. type: 'getFormIframeData',
  106. data: {
  107. formItem: '一级表单formItem',
  108. wfList: JSON.stringify(state[state.detail.transfer.key].list),
  109. },
  110. },
  111. '*',
  112. )
  113. }, 100)
  114. }
  115. onMounted(() => {
  116. window.addEventListener('message', (e) => {
  117. const data = e.data
  118. if (data.type === 'onCloseIframe') {
  119. console.log('二级表单发送关闭消息,onCloseIframe')
  120. state.detail.show = false
  121. } else if (data.type === 'onConfirmIframe') {
  122. console.log('二级表单发送提交消息,onConfirmIframe')
  123. console.log(data.data)
  124. const { formItem, msgData } = data.data
  125. const { ids, list, strs } = JSON.parse(msgData)
  126. state[state.detail.transfer.key].strs = strs
  127. state[state.detail.transfer.key].ids = ids
  128. state[state.detail.transfer.key].list = list
  129. state.detail.show = false
  130. }
  131. })
  132. })
  133. </script>
  134. <style lang="scss" scoped></style>