ny
22 小时以前 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
<script lang="ts" setup>
import { markRaw, onMounted, reactive, toRefs } from 'vue';
import { useRoute, useRouter } from 'vue-router';
 
import { useMessage } from '@jnpf/hooks';
import { AesEncryption } from '@jnpf/utils';
 
import { useTabs } from '@vben/hooks';
 
import { getConfigData } from '#/api/onlineDev/shortLink';
 
import Form from './form/index.vue';
import List from './list/index.vue';
 
interface State {
  currentView: any;
  showPage: boolean;
  isPreview: boolean;
  modelId: string;
  config: any;
  encryption: string;
}
 
defineOptions({ name: 'FormShortLink' });
 
const { createMessage } = useMessage();
const { closeCurrentTab } = useTabs();
const state = reactive<State>({
  currentView: '',
  showPage: false,
  isPreview: false,
  modelId: '',
  config: {},
  encryption: '',
});
const { currentView, showPage, isPreview, modelId, config } = toRefs(state);
const router = useRouter();
 
function init() {
  const route = useRoute();
  if (!route.query.encryption) return;
  state.encryption = route.query.encryption as string;
  const aesEncryption = new AesEncryption({ useHex: true });
  const configStr = aesEncryption.decryptByAES(state.encryption);
  if (!configStr) return;
  const config = JSON.parse(configStr);
  state.modelId = config.modelId;
  if (!state.modelId) return;
  getConfig(config.type);
}
function getConfig(type) {
  getConfigData(state.modelId, state.encryption).then((res) => {
    if (res.code !== 200 || !res.data) {
      closeCurrentTab();
      router.replace('/404');
      createMessage.error(res.msg || '请求出错,请重试');
      return;
    }
    state.config = { ...res.data, encryption: state.encryption };
    state.currentView = type == 'form' ? markRaw(Form) : markRaw(List);
    state.showPage = true;
  });
}
 
onMounted(() => {
  init();
});
</script>
<template>
  <component :is="currentView" :config="config" :model-id="modelId" :is-preview="isPreview" v-if="showPage" />
</template>