DragPageModal.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <BasicModal
  3. v-bind="$attrs"
  4. :footer="null"
  5. wrapClassName="drag-design-process-modal"
  6. :style="{ top: '0', padding: '0' }"
  7. @register="registerModal"
  8. :bodyStyle="bodyStyle"
  9. :canFullscreen="false"
  10. :closable="false"
  11. defaultFullscreen
  12. destroyOnClose
  13. >
  14. <div id="dragEngineBox" style="height: 100vh; overflow-y: auto">
  15. <DragEngine
  16. v-if="refresh"
  17. :dragData="dragData"
  18. :pageId="pageId"
  19. :token="getToken()"
  20. :tenantId="getTenantId()"
  21. :lowAppId="lowAppId"
  22. :isLowApp="false"
  23. @save="handleSave"
  24. @close="handleClose"
  25. @scroll="handleScroll"
  26. @openWindow="openWindow"
  27. />
  28. </div>
  29. </BasicModal>
  30. <PasswordModal ref="passwordRef" @closed="closeModal" />
  31. </template>
  32. <script lang="ts" setup>
  33. import { ref, unref, reactive, nextTick, computed } from 'vue';
  34. import { getToken, getTenantId } from '/@/utils/auth';
  35. import { queryById } from '../page.api';
  36. import { BasicModal, useModalInner } from '/src/components/Modal';
  37. import { getCacheByDynKey } from '/@/utils/auth';
  38. import { JDragConfigEnum } from '/@/enums/jeecgEnum';
  39. import PasswordModal from './PasswordModal.vue';
  40. // 声明Emits
  41. const emit = defineEmits(['success', 'register', 'close']);
  42. const bodyStyle = {
  43. padding: '0',
  44. height: window.innerHeight + 'px',
  45. };
  46. //组件接受传参
  47. const props = defineProps({
  48. lowAppId: { type: String },
  49. // 是否低代码模式(简化使用难度)
  50. isLowApp: { type: Boolean, default: true },
  51. });
  52. //页面Id
  53. const pageId = ref('');
  54. const title = ref('');
  55. const refresh = ref(true);
  56. const passwordRef = ref();
  57. //拖拽信息
  58. const dragData = ref({
  59. componentData: [],
  60. name: '',
  61. coverUrl: '',
  62. backgroundColor: '',
  63. backgroundImage: '',
  64. designType: 100,
  65. theme: 'default',
  66. style: 'default',
  67. updateCount: null,
  68. });
  69. //表单赋值
  70. const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
  71. setModalProps({ showCancelBtn: false, showOkBtn: false });
  72. refresh.value = false;
  73. pageId.value = data.record.id;
  74. //校验保护码
  75. checkCode(data.record);
  76. title.value = `页面设计 [${data.record.name}]`;
  77. const res = await queryById({ id: unref(pageId) });
  78. if (res.success) {
  79. dragData.value.name = res.result.name;
  80. dragData.value.coverUrl = res.result.coverUrl;
  81. let template = res.result.template ? JSON.parse(res.result.template) : [];
  82. dragData.value.componentData = template;
  83. dragData.value.backgroundColor = res.result.backgroundColor;
  84. dragData.value.backgroundImage = res.result.backgroundImage;
  85. dragData.value.designType = res.result.designType;
  86. dragData.value.style = res.result.style || 'default';
  87. dragData.value.theme = res.result.theme || 'default';
  88. //设置乐观锁字段
  89. dragData.value.updateCount = res.result.updateCount;
  90. }
  91. setTimeout(() => {
  92. nextTick(() => {
  93. refresh.value = true;
  94. });
  95. }, 300);
  96. });
  97. /**
  98. * 检验保护码
  99. */
  100. function checkCode(result) {
  101. const password = result.protectionCode;
  102. let passIsExit = getCacheByDynKey(JDragConfigEnum.DRAG_CACHE_PREFIX + unref(pageId));
  103. let hasPassword = password && password.length > 0;
  104. if (hasPassword && !passIsExit) {
  105. passwordRef.value.showModal('design', result);
  106. passwordRef.value.extraMsg = '';
  107. }
  108. }
  109. /**
  110. * 关闭事件
  111. */
  112. function handleClose() {
  113. closeModal();
  114. emit('success');
  115. emit('close');
  116. }
  117. /**
  118. * 保存布局后的回调事件
  119. * @param data
  120. */
  121. function handleSave(data) {
  122. //保存后不关闭modal
  123. //closeModal()
  124. emit('success');
  125. }
  126. /**
  127. * 新增组件后的滚动事件
  128. * @param data
  129. */
  130. function handleScroll(scrollHeight) {
  131. let dom = document.getElementById('dragEngineBox');
  132. scrollIntoView(dom, scrollHeight);
  133. }
  134. /**
  135. * 模拟滚动效果
  136. * @param element 滚动元素
  137. * @param scrollHeight 滚动高度
  138. */
  139. function scrollIntoView(element, scrollHeight) {
  140. // 当前滚动高度
  141. let scrollTop = element.scrollTop;
  142. // 滚动step方法
  143. const step = () => {
  144. // 距离目标滚动距离
  145. let distance = scrollHeight - scrollTop;
  146. // 目标需要滚动的距离,也就是只走全部距离的十分之一
  147. scrollTop = scrollTop + distance / 10;
  148. if (Math.abs(distance) < 1) {
  149. element.scrollTo(0, scrollHeight);
  150. } else {
  151. element.scrollTo(0, scrollTop);
  152. setTimeout(step, 20);
  153. }
  154. };
  155. step();
  156. }
  157. /**
  158. * 打开分享
  159. * @param url
  160. */
  161. function openWindow(url) {
  162. window.open(url, '_blank');
  163. }
  164. </script>
  165. <style lang="less">
  166. @import '@qiaoqiaoyun/drag-free/lib/index.css';
  167. .drag-design-process-modal {
  168. .ant-modal-header {
  169. padding: 0 !important;
  170. }
  171. .ant-modal-body > .scrollbar {
  172. padding-top: 0;
  173. }
  174. .jeecg-modal-content > .scroll-container {
  175. padding: 0 !important;
  176. }
  177. }
  178. </style>