1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-02-13 03:50:07 +08:00

feat: support adding license modification feature (#7838)

This commit is contained in:
ssongliu 2025-02-10 18:17:11 +08:00 committed by GitHub
parent 364edbe2ca
commit a0d01d9a55
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 37 additions and 18 deletions

View File

@ -5,13 +5,16 @@ import { ResPage, SearchWithPage, DescriptionUpdate, ReqPage } from '../interfac
import { Setting } from '../interface/setting';
// license
export const uploadFileData = (params: FormData) => {
return http.upload('/core/licenses/upload', params);
export const uploadLicense = (oldLicense: string, params: FormData) => {
if (oldLicense === '') {
return http.upload('/core/licenses/upload', params);
}
return http.upload('/core/licenses/update', params);
};
export const SearchLicense = (params: ReqPage) => {
export const searchLicense = (params: ReqPage) => {
return http.post<ResPage<Setting.License>>('/core/licenses/search', params);
};
export const DeleteLicense = (id: number, force: boolean) => {
export const deleteLicense = (id: number, force: boolean) => {
return http.post('/core/licenses/del', { id: id, force: force });
};
export const getLicenseStatus = () => {

View File

@ -1,5 +1,5 @@
<template>
<DrawerPro v-model="open" :header="$t('commons.table.group')" size="large" :back="handleClose">
<DrawerPro v-model="open" :header="$t('commons.table.group')" @close="handleClose" size="large" :back="handleClose">
<template #content>
<ComplexTable :data="data" @search="search()">
<template #toolbar>

View File

@ -44,7 +44,7 @@
import i18n from '@/lang';
import { ref } from 'vue';
import { MsgSuccess } from '@/utils/message';
import { uploadFileData } from '@/api/modules/setting';
import { uploadLicense } from '@/api/modules/setting';
import { GlobalStore } from '@/store';
import { UploadFile, UploadFiles, UploadInstance, UploadProps, UploadRawFile, genFileId } from 'element-plus';
import { useTheme } from '@/global/use-theme';
@ -57,6 +57,18 @@ const open = ref(false);
const uploadRef = ref<UploadInstance>();
const uploaderFiles = ref<UploadFiles>([]);
const oldLicense = ref();
interface DialogProps {
oldLicense: string;
}
const acceptParams = (params: DialogProps) => {
oldLicense.value = params?.oldLicense || '';
uploaderFiles.value = [];
uploadRef.value?.clearFiles();
open.value = true;
};
const handleClose = () => {
open.value = false;
uploadRef.value!.clearFiles();
@ -88,8 +100,9 @@ const submit = async () => {
const file = uploaderFiles.value[0];
const formData = new FormData();
formData.append('file', file.raw);
formData.append('title', oldLicense.value);
loading.value = true;
await uploadFileData(formData)
await uploadLicense(oldLicense.value, formData)
.then(async () => {
globalStore.isProductPro = true;
const xpackRes = await getXpackSetting();
@ -113,12 +126,6 @@ const submit = async () => {
});
};
const acceptParams = () => {
uploaderFiles.value = [];
uploadRef.value?.clearFiles();
open.value = true;
};
defineExpose({
acceptParams,
});

View File

@ -64,7 +64,6 @@ const onBind = async (formEl: FormInstance | undefined) => {
loading.value = false;
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
globalStore.isProductPro = false;
globalStore.themeConfig.isGold = false;
window.location.reload();
})
.catch(() => {

View File

@ -28,7 +28,7 @@ import { FormInstance } from 'element-plus';
import { ref } from 'vue';
import i18n from '@/lang';
import { MsgSuccess } from '@/utils/message';
import { DeleteLicense } from '@/api/modules/setting';
import { deleteLicense } from '@/api/modules/setting';
let form = reactive({
id: 0,
@ -56,7 +56,7 @@ const acceptParams = async (prop: DialogProps) => {
const submit = async () => {
loading.value = true;
DeleteLicense(form.id, form.forceDelete)
deleteLicense(form.id, form.forceDelete)
.then(() => {
loading.value = false;
emit('search');

View File

@ -85,7 +85,7 @@
<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
import { SearchLicense, syncLicense, unbindLicense } from '@/api/modules/setting';
import { searchLicense, syncLicense, unbindLicense } from '@/api/modules/setting';
import LicenseImport from '@/components/license-import/index.vue';
import LicenseDelete from '@/views/setting/license/delete/index.vue';
import LicenseBind from '@/views/setting/license/bind/index.vue';
@ -165,7 +165,7 @@ const search = async () => {
page: paginationConfig.currentPage,
pageSize: paginationConfig.pageSize,
};
await SearchLicense(params)
await searchLicense(params)
.then((res) => {
loading.value = false;
data.value = res.data.items || [];
@ -176,6 +176,7 @@ const search = async () => {
? i18n.global.t('license.indefinitePeriod')
: timestampToDate(Number(item.productPro));
}
paginationConfig.total = res.data.total;
})
.catch(() => {
loading.value = false;
@ -233,6 +234,15 @@ const buttons = [
onUnbind(row);
},
},
{
label: i18n.global.t('commons.button.edit'),
disabled: (row: any) => {
return row.status === 'Free';
},
click: (row: any) => {
licenseRef.value.acceptParams({ oldLicense: row.licenseName });
},
},
{
label: i18n.global.t('commons.button.sync'),
disabled: (row: any) => {