Skip to content

Commit

Permalink
refactor: 优化生成预览功能,增加复制按钮
Browse files Browse the repository at this point in the history
1.增加复制按钮
2.移除模板内协议头信息
  • Loading branch information
Charles7c committed Dec 20, 2023
1 parent 4017029 commit 505ba49
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 159 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package ${packageName}.${subPackageName};

import top.charles7c.continew.starter.extension.crud.enums.Api;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package ${packageName}.${subPackageName};

import java.io.Serial;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package ${packageName}.${subPackageName};

import java.io.Serial;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package ${packageName}.${subPackageName};

import top.charles7c.continew.starter.extension.crud.base.BaseMapper;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package ${packageName}.${subPackageName};

import java.io.Serial;
Expand Down
16 changes: 0 additions & 16 deletions continew-admin-tool/src/main/resources/templates/generator/Req.ftl
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package ${packageName}.${subPackageName};

import java.io.Serial;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package ${packageName}.${subPackageName};

import java.io.Serial;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package ${packageName}.${subPackageName};

import top.charles7c.continew.starter.extension.crud.base.BaseService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package ${packageName}.${subPackageName};

import lombok.RequiredArgsConstructor;
Expand Down
70 changes: 55 additions & 15 deletions continew-admin-ui/src/views/tool/generator/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -286,26 +286,38 @@
render-to-body
@cancel="handlePreviewCancel"
>
<a-scrollbar style="height: 700px; overflow: auto">
<a-tabs type="card" size="large">
<a-tab-pane
v-for="item in generatePreviewList"
:key="item.fileName"
:title="item.fileName"
<div>
<a-scrollbar style="height: 700px; overflow: auto">
<a-link
style="position: absolute; right: 20px; top: 50px; z-index: 999"
@click="handleCopy"
>
<codemirror
v-model="item.content"
:autofocus="true"
:extensions="extensions"
/>
</a-tab-pane>
</a-tabs>
</a-scrollbar>
<template #icon>
<icon-copy size="large" />
</template>
复制
</a-link>
<a-tabs size="large" @tab-click="handleTabClick">
<a-tab-pane
v-for="item in generatePreviewList"
:key="item.fileName"
:title="item.fileName"
>
<codemirror
v-model="item.content"
:autofocus="true"
:extensions="extensions"
/>
</a-tab-pane>
</a-tabs>
</a-scrollbar>
</div>
</a-modal>
</template>

<script lang="ts" setup>
import { getCurrentInstance, ref, toRefs, reactive } from 'vue';
import { getCurrentInstance, ref, toRefs, reactive, watch } from 'vue';
import { useClipboard } from '@vueuse/core';
import { Codemirror } from 'vue-codemirror';
import { java } from '@codemirror/lang-java';
import { javascript } from '@codemirror/lang-javascript';
Expand All @@ -331,6 +343,7 @@
'query_type_enum',
);
const { copy, copied } = useClipboard();
const extensions = [java(), javascript()];
const tableList = ref<TableRecord[]>([]);
const fieldConfigList = ref<FieldConfigRecord[]>([]);
Expand All @@ -340,6 +353,7 @@
const loading = ref(false);
const visible = ref(false);
const fieldConfigLoading = ref(false);
const copyCodeContent = ref();
const generatePreviewList = ref<GeneratePreviewRecord[]>([]);
const previewVisible = ref(false);
Expand Down Expand Up @@ -463,6 +477,7 @@
const handlePreview = (tableName: string) => {
preview(tableName).then((res) => {
generatePreviewList.value = res.data;
copyCodeContent.value = generatePreviewList.value[0].content;
previewVisible.value = true;
});
};
Expand All @@ -472,9 +487,34 @@
*/
const handlePreviewCancel = () => {
generatePreviewList.value = [];
copyCodeContent.value = '';
previewVisible.value = false;
};
/**
* 点击 Tab
*
* @param key Tab 键
*/
const handleTabClick = (key: any) => {
copyCodeContent.value = generatePreviewList.value.filter(
(p) => p.fileName === key,
)[0].content;
};
/**
* 复制代码
*
*/
const handleCopy = () => {
copy(copyCodeContent.value);
};
watch(copied, () => {
if (copied.value) {
proxy.$message.success('复制成功');
}
});
/**
* 生成代码
*
Expand Down

0 comments on commit 505ba49

Please sign in to comment.