ny
昨天 282fbc6488f4e8ceb5fda759f963ee88fbf7b999
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<script lang="ts" setup>
import type { TreeActionType } from '@jnpf/ui';
 
import { computed, nextTick, reactive, ref, toRefs, unref } from 'vue';
 
import { BasicLeftTree } from '@jnpf/ui';
import { BasicModal, useModalInner } from '@jnpf/ui/modal';
 
import { usePreferences } from '@vben/preferences';
 
import { CodeDiff } from 'v-code-diff';
 
import { codePreview } from '#/api/onlineDev/visualDev';
import logoImg from '#/assets/images/jnpf.png';
import { $t } from '#/locales';
 
interface State {
  treeData: any[];
  currentId: string;
  oldFileContent: string;
  currentContent: string;
  editorLanguage: string;
  key: number;
  fullName: string;
}
 
defineEmits(['register']);
const leftTreeRef = ref<Nullable<TreeActionType>>(null);
const { isDark } = usePreferences();
const [registerModal, { closeModal, changeLoading }] = useModalInner(init);
const state = reactive<State>({
  treeData: [],
  currentId: '',
  oldFileContent: '',
  currentContent: '',
  editorLanguage: 'html',
  key: Date.now(),
  fullName: '',
});
const { treeData, oldFileContent, currentContent, editorLanguage, key, fullName } = toRefs(state);
 
const getThemeColor = computed(() => (isDark.value ? 'dark' : 'light'));
 
function init(data) {
  state.fullName = data.fullName || '';
  state.key = Date.now();
  changeLoading(true);
  const query = {
    module: data.module || 'system',
    description: data.description,
    modulePackageName: data.modulePackageName || '',
    enableFlow: data.enableFlow,
    contrast: true,
  };
  codePreview(data.id, query).then((res) => {
    state.treeData = res.data.list.map((o) => ({ ...o, disabled: true }));
    state.currentId = state.treeData[0].children[0].id;
    state.currentContent = state.treeData[0].children[0].fileContent;
    state.oldFileContent = state.treeData[0].children[0].oldFileContent;
    state.editorLanguage = getLanguage(state.treeData[0].children[0]);
    nextTick(() => {
      const leftTree = unref(leftTreeRef);
      leftTree?.setSelectedKeys([state.currentId]);
      changeLoading(false);
    });
  });
}
function handleTreeSelect(id, node) {
  state.key = Date.now();
  state.currentId = id;
  state.currentContent = node.fileContent;
  state.oldFileContent = node.oldFileContent;
  state.editorLanguage = getLanguage(node);
}
function getLanguage(node) {
  return ['app', 'web'].includes(node.fileType) ? 'html' : ['js', 'ts'].includes(node.folderName) ? 'js' : 'java';
}
</script>
<template>
  <BasicModal
    v-bind="$attrs"
    @register="registerModal"
    default-fullscreen
    :footer="null"
    :closable="false"
    :keyboard="false"
    class="jnpf-full-modal full-modal designer-modal">
    <template #title>
      <div class="jnpf-full-modal-header">
        <div class="header-title">
          <img :src="logoImg" class="header-logo" />
          <span class="header-dot"></span>
          <a-tooltip :title="fullName">
            <p class="header-txt">{{ fullName }}</p>
          </a-tooltip>
        </div>
        <a-steps :current="1" type="navigation" size="small" class="header-steps tab-steps">
          <a-step title="代码预览" />
        </a-steps>
        <a-space class="options" :size="10">
          <a-button @click="closeModal()">{{ $t('common.closeText') }}</a-button>
        </a-space>
      </div>
    </template>
    <div class="jnpf-content-wrapper">
      <div class="jnpf-content-wrapper-left">
        <BasicLeftTree :show-search="false" ref="leftTreeRef" :field-names="{ title: 'fileName' }" :tree-data="treeData" @select="handleTreeSelect" />
      </div>
      <div class="jnpf-content-wrapper-center">
        <div class="jnpf-content-wrapper-content bg-white">
          <CodeDiff
            :old-string="oldFileContent"
            :new-string="currentContent"
            output-format="side-by-side"
            :language="editorLanguage"
            :theme="getThemeColor"
            :context="99999"
            :key="key" />
        </div>
      </div>
    </div>
  </BasicModal>
</template>
<style lang="scss">
.code-diff-view {
  height: 100% !important;
  margin-top: unset !important;
  margin-bottom: unset !important;
  background-color: var(--component-background) !important;
  border: unset !important;
 
  .file-header,
  .empty-cell {
    background-color: var(--component-background) !important;
  }
}
</style>