feat: 支持修改license申请
This commit is contained in:
@@ -7,6 +7,7 @@ import type { DescriptionItemSchema } from '#/components/description';
|
|||||||
|
|
||||||
import { h, ref } from 'vue';
|
import { h, ref } from 'vue';
|
||||||
|
|
||||||
|
import { useAccess } from '@vben/access';
|
||||||
import { formatDate, formatDateTime } from '@vben/utils';
|
import { formatDate, formatDateTime } from '@vben/utils';
|
||||||
|
|
||||||
import dayjs, { Dayjs } from 'dayjs';
|
import dayjs, { Dayjs } from 'dayjs';
|
||||||
@@ -20,6 +21,7 @@ import { DictTag } from '#/components/dict-tag';
|
|||||||
import { $t } from '#/locales';
|
import { $t } from '#/locales';
|
||||||
import { DICT_TYPE, getDictOptions, getRangePickerDefaultProps } from '#/utils';
|
import { DICT_TYPE, getDictOptions, getRangePickerDefaultProps } from '#/utils';
|
||||||
|
|
||||||
|
const { hasAccessByRoles } = useAccess();
|
||||||
const customerList = ref<CustomerApi.Customer[]>([]);
|
const customerList = ref<CustomerApi.Customer[]>([]);
|
||||||
const projectList = ref<ProjectApi.Project[]>([]);
|
const projectList = ref<ProjectApi.Project[]>([]);
|
||||||
export const formData = ref<LicenseApi.License>();
|
export const formData = ref<LicenseApi.License>();
|
||||||
@@ -105,7 +107,7 @@ export function useFormSchema(): VbenFormSchema[] {
|
|||||||
label: 'SN',
|
label: 'SN',
|
||||||
component: 'Input',
|
component: 'Input',
|
||||||
componentProps: {
|
componentProps: {
|
||||||
disabled: true,
|
// disabled: true,
|
||||||
},
|
},
|
||||||
dependencies: {
|
dependencies: {
|
||||||
trigger(values, form) {
|
trigger(values, form) {
|
||||||
@@ -125,15 +127,19 @@ export function useFormSchema(): VbenFormSchema[] {
|
|||||||
},
|
},
|
||||||
// 只有指定的字段改变时,才会触发
|
// 只有指定的字段改变时,才会触发
|
||||||
triggerFields: ['customerId', 'projectId', 'id'],
|
triggerFields: ['customerId', 'projectId', 'id'],
|
||||||
|
disabled: () => !hasAccessByRoles(['license_admin']),
|
||||||
},
|
},
|
||||||
rules: z.string().refine(
|
rules: z
|
||||||
async (value: string) => {
|
.string()
|
||||||
return await isLicenseSnUnique(value, formData.value?.id);
|
.max(8, $t('ui.formRules.maxLength', ['SN', 8]))
|
||||||
},
|
.refine(
|
||||||
(value) => ({
|
async (value: string) => {
|
||||||
message: $t('ui.formRules.alreadyExists', ['SN', value]),
|
return await isLicenseSnUnique(value, formData.value?.id);
|
||||||
}),
|
},
|
||||||
),
|
(value) => ({
|
||||||
|
message: $t('ui.formRules.alreadyExists', ['SN', value]),
|
||||||
|
}),
|
||||||
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fieldName: 'expiryDate',
|
fieldName: 'expiryDate',
|
||||||
|
|||||||
@@ -106,10 +106,6 @@ async function onDownload() {
|
|||||||
if (!formData.value?.fileUrl) {
|
if (!formData.value?.fileUrl) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const fileName = `${formData.value.fileUrl?.slice(
|
|
||||||
Math.max(0, formData.value.fileUrl.lastIndexOf('/') + 1),
|
|
||||||
formData.value.fileUrl.lastIndexOf('_'),
|
|
||||||
)}.tar.gz`;
|
|
||||||
|
|
||||||
const hideLoading = message.loading({
|
const hideLoading = message.loading({
|
||||||
content: '下载中...',
|
content: '下载中...',
|
||||||
@@ -121,7 +117,7 @@ async function onDownload() {
|
|||||||
const url = window.URL.createObjectURL(blob);
|
const url = window.URL.createObjectURL(blob);
|
||||||
const link = document.createElement('a');
|
const link = document.createElement('a');
|
||||||
link.href = url;
|
link.href = url;
|
||||||
link.download = fileName;
|
link.download = formData.value.fileUrl;
|
||||||
link.click();
|
link.click();
|
||||||
window.URL.revokeObjectURL(url);
|
window.URL.revokeObjectURL(url);
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -73,11 +73,6 @@ function onHistory(row: LicenseApi.License) {
|
|||||||
|
|
||||||
/** 下载License */
|
/** 下载License */
|
||||||
async function onDownload(row: LicenseApi.License) {
|
async function onDownload(row: LicenseApi.License) {
|
||||||
const fileName = `${row.fileUrl?.slice(
|
|
||||||
Math.max(0, row.fileUrl.lastIndexOf('/') + 1),
|
|
||||||
row.fileUrl.lastIndexOf('_'),
|
|
||||||
)}.tar.gz`;
|
|
||||||
|
|
||||||
const hideLoading = message.loading({
|
const hideLoading = message.loading({
|
||||||
content: '下载中...',
|
content: '下载中...',
|
||||||
key: 'action_key_msg',
|
key: 'action_key_msg',
|
||||||
@@ -88,7 +83,7 @@ async function onDownload(row: LicenseApi.License) {
|
|||||||
const url = window.URL.createObjectURL(blob);
|
const url = window.URL.createObjectURL(blob);
|
||||||
const link = document.createElement('a');
|
const link = document.createElement('a');
|
||||||
link.href = url;
|
link.href = url;
|
||||||
link.download = fileName;
|
link.download = row.fileUrl;
|
||||||
link.click();
|
link.click();
|
||||||
window.URL.revokeObjectURL(url);
|
window.URL.revokeObjectURL(url);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -101,6 +96,11 @@ function onReapply(row: LicenseApi.License) {
|
|||||||
formModalApi.setData(row).open();
|
formModalApi.setData(row).open();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 修改License */
|
||||||
|
function onEdit(row: LicenseApi.License) {
|
||||||
|
formModalApi.setData({ ...row, action: 1 }).open();
|
||||||
|
}
|
||||||
|
|
||||||
/** 删除License */
|
/** 删除License */
|
||||||
async function onDelete(row: LicenseApi.License) {
|
async function onDelete(row: LicenseApi.License) {
|
||||||
const hideLoading = message.loading({
|
const hideLoading = message.loading({
|
||||||
@@ -253,6 +253,14 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
|||||||
auth: ['license:license:query'],
|
auth: ['license:license:query'],
|
||||||
onClick: onHistory.bind(null, row),
|
onClick: onHistory.bind(null, row),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: $t('common.edit'),
|
||||||
|
type: 'link',
|
||||||
|
ifShow:
|
||||||
|
row.status === 4 || row.status === 1 || row.dataType === 1,
|
||||||
|
auth: ['license:license:update'],
|
||||||
|
onClick: onEdit.bind(null, row),
|
||||||
|
},
|
||||||
]"
|
]"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import {
|
|||||||
createLicense,
|
createLicense,
|
||||||
getLicense,
|
getLicense,
|
||||||
reapplyLicense,
|
reapplyLicense,
|
||||||
|
updateLicense,
|
||||||
} from '#/api/license/license';
|
} from '#/api/license/license';
|
||||||
import { $t } from '#/locales';
|
import { $t } from '#/locales';
|
||||||
import { DICT_TYPE, getDictOptions } from '#/utils';
|
import { DICT_TYPE, getDictOptions } from '#/utils';
|
||||||
@@ -34,13 +35,25 @@ const state = reactive({
|
|||||||
const neCodeRef = ref();
|
const neCodeRef = ref();
|
||||||
|
|
||||||
const getTitle = computed(() => {
|
const getTitle = computed(() => {
|
||||||
return formData.value?.id
|
if (formData.value?.id) {
|
||||||
? $t('license.reapplyAction', ['License'])
|
if (formData.value?.action === 1) {
|
||||||
: $t('license.applyAction', ['License']);
|
return $t('ui.actionTitle.edit', ['License']);
|
||||||
|
}
|
||||||
|
return $t('license.reapplyAction', ['License']);
|
||||||
|
} else {
|
||||||
|
return $t('license.applyAction', ['License']);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const getConfirmText = computed(() => {
|
const getConfirmText = computed(() => {
|
||||||
return formData.value?.id ? $t('license.reapply') : $t('license.apply');
|
if (formData.value?.id) {
|
||||||
|
if (formData.value?.action === 1) {
|
||||||
|
return $t('page.action.confirm');
|
||||||
|
}
|
||||||
|
return $t('license.reapply');
|
||||||
|
} else {
|
||||||
|
return $t('license.apply');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const [Form, formApi] = useVbenForm({
|
const [Form, formApi] = useVbenForm({
|
||||||
@@ -92,12 +105,19 @@ const [Modal, modalApi] = useVbenModal({
|
|||||||
const data = (await formApi.getValues()) as LicenseApi.License;
|
const data = (await formApi.getValues()) as LicenseApi.License;
|
||||||
data.neList = state.checkedList;
|
data.neList = state.checkedList;
|
||||||
data.neCodeList = state.neCodeList;
|
data.neCodeList = state.neCodeList;
|
||||||
|
const action = formData.value?.action || 0;
|
||||||
try {
|
try {
|
||||||
await (formData.value?.id ? reapplyLicense(data) : createLicense(data));
|
if (formData.value?.id) {
|
||||||
|
await (action === 1 ? updateLicense(data) : reapplyLicense(data));
|
||||||
|
} else {
|
||||||
|
await createLicense(data);
|
||||||
|
}
|
||||||
// 关闭并提示
|
// 关闭并提示
|
||||||
await modalApi.close();
|
await modalApi.close();
|
||||||
emit('success');
|
emit('success');
|
||||||
message.success($t('license.applySuccess'), 3);
|
action === 1
|
||||||
|
? message.success($t('ui.actionMessage.operationSuccess'))
|
||||||
|
: message.success($t('license.applySuccess'), 3);
|
||||||
} finally {
|
} finally {
|
||||||
modalApi.unlock();
|
modalApi.unlock();
|
||||||
}
|
}
|
||||||
@@ -114,16 +134,25 @@ const [Modal, modalApi] = useVbenModal({
|
|||||||
}
|
}
|
||||||
if (data.id) {
|
if (data.id) {
|
||||||
modalApi.setState({ loading: true });
|
modalApi.setState({ loading: true });
|
||||||
|
const action = data.action || 0; // 确保 action 字段存在
|
||||||
|
formData.value = { ...data, action };
|
||||||
data = await getLicense(data.id);
|
data = await getLicense(data.id);
|
||||||
|
data.action = action; // 保留 action 字段
|
||||||
}
|
}
|
||||||
// 处理数据
|
// 处理数据
|
||||||
data.expiryDate = data.expiryDate ? data.expiryDate.toString() : '';
|
data.expiryDate = data.expiryDate ? data.expiryDate.toString() : '';
|
||||||
// 设置到 values
|
// 设置到 values
|
||||||
formData.value = data;
|
formData.value = data;
|
||||||
state.checkedList = data.neList || [];
|
state.checkedList = data.neList || [];
|
||||||
|
|
||||||
state.neCodeList = data.neCodeList || [
|
state.neCodeList = data.neCodeList || [
|
||||||
{ neList: [], activationCode: '', id: 1 },
|
{ neList: [], activationCode: '', id: 1 },
|
||||||
];
|
];
|
||||||
|
if (state.neCodeList.length > 1) {
|
||||||
|
state.neCodeList = state.neCodeList.filter(
|
||||||
|
(item) => item.neList && item.neList.length > 0,
|
||||||
|
);
|
||||||
|
}
|
||||||
await formApi.setValues(formData.value);
|
await formApi.setValues(formData.value);
|
||||||
modalApi.setState({ loading: false });
|
modalApi.setState({ loading: false });
|
||||||
},
|
},
|
||||||
@@ -165,21 +194,10 @@ const addNeCode = () => {
|
|||||||
neList: [],
|
neList: [],
|
||||||
activationCode: '',
|
activationCode: '',
|
||||||
id: nextId++,
|
id: nextId++,
|
||||||
|
fileUrl: '',
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
const availableOptions = (groupIdx: number) => {
|
const availableOptions = () => {
|
||||||
// 其他分组已选标签
|
|
||||||
const otherSelected = new Set(
|
|
||||||
state.neCodeList
|
|
||||||
.filter((_, idx) => idx !== groupIdx)
|
|
||||||
.flatMap((g) => g.neList),
|
|
||||||
);
|
|
||||||
const aaaa = options.value?.map((item) => ({
|
|
||||||
...item,
|
|
||||||
options: item.options.filter(
|
|
||||||
(option: any) => !otherSelected.has(option.value),
|
|
||||||
),
|
|
||||||
}));
|
|
||||||
return options.value;
|
return options.value;
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -525,12 +525,14 @@ export function useGridColumns(
|
|||||||
{
|
{
|
||||||
field: 'commentNum',
|
field: 'commentNum',
|
||||||
title: $t('project.commentNum'),
|
title: $t('project.commentNum'),
|
||||||
minWidth: 90,
|
sortable: true,
|
||||||
|
minWidth: 100,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'applyCount',
|
field: 'applyCount',
|
||||||
title: $t('license.applyCount'),
|
title: $t('license.applyCount'),
|
||||||
minWidth: 120,
|
sortable: true,
|
||||||
|
minWidth: 130,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'updateTime',
|
field: 'updateTime',
|
||||||
|
|||||||
Reference in New Issue
Block a user