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
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
<script lang="ts" setup>
import type { FormInstance } from 'ant-design-vue';
 
import { nextTick, reactive, ref, toRefs } from 'vue';
 
import { BasicModal, useModal, useModalInner } from '@jnpf/ui/modal';
import { downloadByUrl } from '@jnpf/utils';
 
import { downloadCode } from '#/api/onlineDev/visualDev';
import { useBaseStore } from '#/store';
 
import AliasModal from './AliasModal.vue';
import PreviewModal from './PreviewModal.vue';
 
interface State {
  dataForm: any;
  moduleOptions: any[];
  tables: any[];
  type: number;
  id: string;
  hasPackage: boolean;
  fullName: string;
  webType: number;
}
 
defineEmits(['register']);
const baseStore = useBaseStore();
const [registerModal, { changeOkLoading, closeModal }] = useModalInner(init);
const [registerPreviewModal, { openModal: openPreviewModal }] = useModal();
const [registerAliasModal, { openModal: openAliasModal }] = useModal();
const formElRef = ref<FormInstance>();
const state = reactive<State>({
  dataForm: {
    module: '',
    modulePackageName: 'jnpf',
    description: '',
    enableFlow: 0,
  },
  moduleOptions: [],
  tables: [],
  type: 0,
  id: '',
  hasPackage: false,
  fullName: '',
  webType: 2,
});
const { dataForm, type, moduleOptions, hasPackage, webType } = toRefs(state);
 
function init(data) {
  state.tables = data.tables ? JSON.parse(data.tables) : [];
  state.id = data.id;
  state.type = data.type || 0;
  state.hasPackage = !!data.hasPackage;
  state.fullName = data.fullName || '';
  state.webType = data.webType || 2;
  state.dataForm.description = '';
  state.dataForm.enableFlow = 0;
  getOptions();
  nextTick(() => {
    formElRef.value?.clearValidate();
    if (data.webType == 4) return;
    const mainTable = state.tables.length ? state.tables.find((o) => o.typeId == '1').table : '';
    state.dataForm.description = mainTable;
  });
}
function getOptions() {
  baseStore.getDictionaryData('createModule').then((res) => {
    state.moduleOptions = res as any;
    if (state.moduleOptions.length) state.dataForm.module = state.moduleOptions[0].id;
  });
}
async function handleSubmit() {
  try {
    const values = await formElRef.value?.validate();
    if (!values) return;
    changeOkLoading(true);
    downloadCode(state.id, state.dataForm)
      .then((res) => {
        downloadByUrl({ url: res.data.url });
        closeModal();
      })
      .catch(() => {
        changeOkLoading(false);
      });
  } catch {}
}
function handlePreview() {
  openPreviewModal(true, { id: state.id, fullName: state.fullName, ...state.dataForm });
}
function handleAlias() {
  openAliasModal(true, { id: state.id, fullName: state.fullName });
}
</script>
<template>
  <BasicModal v-bind="$attrs" @register="registerModal" title="输出设置" ok-text="下载代码" @ok="handleSubmit">
    <template #insertFooter>
      <a-space :size="10" class="float-left">
        <a-button @click="handlePreview">代码预览</a-button>
        <a-button @click="handleAlias" v-if="webType != 4">命名规范</a-button>
      </a-space>
    </template>
    <a-alert message="注意:以下只能包含数字、字母、下划线、小圆点,不能用数字开头,不能是关键字或保留字。" type="warning" show-icon class="!mb-[18px]" />
    <a-form :colon="false" :label-col="{ style: { width: '100px' } }" :model="dataForm" ref="formElRef">
      <a-form-item label="模块命名" name="module" v-if="type != 3" :rules="[{ required: true, message: '必填', trigger: 'change' }]">
        <jnpf-select v-model:value="dataForm.module" :options="moduleOptions" placeholder="请选择" show-search />
      </a-form-item>
      <a-form-item name="modulePackageName" :rules="[{ required: true, message: '必填', trigger: 'blur' }]" v-if="hasPackage">
        <template #label>模块包名<BasicHelp text="修改包名需要调整controller和mapper扫描配置" /></template>
        <a-input v-model:value="dataForm.modulePackageName" placeholder="请输入" />
      </a-form-item>
      <a-form-item label="功能描述" name="description" :rules="[{ required: true, message: '必填', trigger: 'blur' }]">
        <a-input v-model:value="dataForm.description" placeholder="请输入" />
      </a-form-item>
      <a-form-item label="流程模板" name="enableFlow" v-if="webType != 4">
        <jnpf-switch v-model:value="dataForm.enableFlow" />
      </a-form-item>
    </a-form>
  </BasicModal>
  <PreviewModal @register="registerPreviewModal" />
  <AliasModal @register="registerAliasModal" />
</template>