feat: 新增编码预览功能
- 后端新增 /rpc-api/base/code-gen/preview 接口 - SequenceAllocator.preview 查询序号但不消耗 - 前端操作列新增预览按钮,弹窗展示下一个编码
This commit is contained in:
@@ -79,3 +79,11 @@ export async function updateCodeRule(data: BaseCodeRuleApi.CodeRule) {
|
||||
export async function deleteCodeRule(id: number) {
|
||||
return requestClient.delete(`/base/code-rule/delete?id=${id}`);
|
||||
}
|
||||
|
||||
/** 预览下一个编码(不消耗序号) */
|
||||
export async function previewCode(ruleCode: string) {
|
||||
return requestClient.get<string>(
|
||||
'/rpc-api/base/code-gen/preview',
|
||||
{ params: { ruleCode } },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,10 +7,10 @@ import { ref } from 'vue';
|
||||
import { confirm, Page, useVbenModal } from '@vben/common-ui';
|
||||
import { isEmpty } from '@vben/utils';
|
||||
|
||||
import { message } from 'antdv-next';
|
||||
import { Modal, message } from 'antdv-next';
|
||||
|
||||
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { deleteCodeRule, getCodeRulePage } from '#/api/base/codegen';
|
||||
import { deleteCodeRule, getCodeRulePage, previewCode } from '#/api/base/codegen';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
import { useGridColumns, useGridFormSchema } from './data';
|
||||
@@ -51,7 +51,7 @@ async function handleDelete(row: BaseCodeRuleApi.CodeRule) {
|
||||
}
|
||||
}
|
||||
|
||||
/** 批量删除编码规则 */
|
||||
/** 批量删除 */
|
||||
async function handleDeleteBatch() {
|
||||
await confirm($t('ui.actionMessage.deleteBatchConfirm'));
|
||||
const hideLoading = message.loading({
|
||||
@@ -70,6 +70,25 @@ async function handleDeleteBatch() {
|
||||
}
|
||||
}
|
||||
|
||||
/** 预览下一个编码 */
|
||||
const previewVisible = ref(false);
|
||||
const previewLoading = ref(false);
|
||||
const previewCodeValue = ref('');
|
||||
const previewTitle = ref('');
|
||||
async function handlePreview(row: BaseCodeRuleApi.CodeRule) {
|
||||
previewTitle.value = row.ruleName;
|
||||
previewLoading.value = true;
|
||||
previewVisible.value = true;
|
||||
try {
|
||||
const result = await previewCode(row.ruleCode);
|
||||
previewCodeValue.value = result ?? '';
|
||||
} catch {
|
||||
previewCodeValue.value = '预览失败';
|
||||
} finally {
|
||||
previewLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
const checkedIds = ref<number[]>([]);
|
||||
function handleRowCheckboxChange({
|
||||
records,
|
||||
@@ -145,6 +164,13 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: '预览',
|
||||
type: 'link',
|
||||
icon: ACTION_ICON.SEARCH,
|
||||
auth: ['base:code-rule:query'],
|
||||
onClick: handlePreview.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: $t('common.edit'),
|
||||
type: 'link',
|
||||
@@ -167,5 +193,23 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
|
||||
<!-- 预览弹窗 -->
|
||||
<Modal
|
||||
v-model:open="previewVisible"
|
||||
title="编码预览"
|
||||
:footer="null"
|
||||
:width="500"
|
||||
>
|
||||
<div v-if="previewLoading" class="py-8 text-center text-gray-400">
|
||||
加载中...
|
||||
</div>
|
||||
<div v-else class="py-4">
|
||||
<p class="mb-2 text-sm text-gray-500">规则:{{ previewTitle }}</p>
|
||||
<p class="text-2xl font-mono font-bold tracking-wider text-blue-600">
|
||||
{{ previewCodeValue }}
|
||||
</p>
|
||||
</div>
|
||||
</Modal>
|
||||
</Page>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user