Skip to content

Commit

Permalink
fix: license 导入页面调整
Browse files Browse the repository at this point in the history
  • Loading branch information
john1298308460 committed Mar 13, 2024
1 parent 0daf7c1 commit 67183d2
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 25 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ build_frontend:

build_backend_on_linux:
cd $(SERVER_PATH) \
&& GOOS=$(GOOS) GOARCH=$(GOARCH) $(GOBUILD) -trimpath -ldflags '-s -w' -o $(BUILD_PATH)/$(APP_NAME) $(MAIN)
&& GOOS=$(GOOS) GOARCH=$(GOARCH) $(GOBUILD) -tags=xpack -trimpath -ldflags '-s -w' -o $(BUILD_PATH)/$(APP_NAME) $(MAIN)

build_backend_on_darwin:
cd $(SERVER_PATH) \
&& GOOS=linux GOARCH=amd64 $(GOBUILD) -trimpath -ldflags '-s -w' -o $(BUILD_PATH)/$(APP_NAME) $(MAIN)
cd $(SERVER_PATH) \
&& GOOS=linux GOARCH=amd64 $(GOBUILD) -tags=xpack -trimpath -ldflags '-s -w' -o $(BUILD_PATH)/$(APP_NAME) $(MAIN)

build_all: build_frontend build_backend_on_linux

Expand Down
11 changes: 8 additions & 3 deletions frontend/src/api/interface/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,14 @@ export namespace Setting {
}

export interface License extends CommonModel {
name: string;
appName: string;
licenseName: string;
assigneeName: string;
products: Array<Project>;
trial: boolean;
expiresAt: Date;
}

export interface Project extends CommonModel {
name: string;
expiresAt: number;
}
}
4 changes: 2 additions & 2 deletions frontend/src/api/modules/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export const UploadFileData = (params: FormData) => {
return http.upload<ResultData<Setting.License>>('/licenses/upload', params);
};

export const getLicense = (id: number) => {
return http.get<Setting.License>(`/licenses/${id}`);
export const getLicense = () => {
return http.get<Setting.License>(`/licenses/get`);
};

export const addLicense = (params: Setting.LicenseCreate) => {
Expand Down
47 changes: 30 additions & 17 deletions frontend/src/views/setting/about/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
v-model:file-list="uploaderFiles"
>
<template #trigger>
<el-button type="primary" v-if="license.name === ''">上传 License 文件</el-button>
<el-button type="primary" v-if="license.licenseName === ''">上传 License 文件</el-button>
<el-button type="primary" v-else>更新 License 文件</el-button>
</template>
<el-button
Expand All @@ -31,10 +31,10 @@
</el-button>
</el-upload>

<div class="flx-center" v-if="license.name !== ''">
<div class="version">{{ '版本类型:' + license.name }}</div>
<div class="flx-center" v-if="license.licenseName !== ''">
<div class="version">{{ '版本类型:' + license.licenseName }}</div>
<div class="version" style="margin-left: 20px">
{{ '有效期至:' + dateFormat(0, 0, license.expiresAt) }}
{{ '有效期至:' + license.expiresAt }}
</div>
</div>

Expand Down Expand Up @@ -67,24 +67,23 @@
</template>

<script lang="ts" setup>
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { getLicense, getSettingInfo, getSystemAvailable, UploadFileData } from '@/api/modules/setting';
import { onMounted, ref, reactive } from 'vue';
import { genFileId } from 'element-plus';
import { onMounted, reactive, ref } from 'vue';
import { genFileId, UploadFiles, UploadInstance, UploadProps, UploadRawFile } from 'element-plus';
import SystemUpgrade from '@/components/system-upgrade/index.vue';
import { UploadInstance, UploadProps, UploadRawFile, UploadFiles } from 'element-plus';
import { MsgError } from '@/utils/message';
import { dateFormat } from '@/utils/util';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const version = ref();
const loading = ref();
const uploaderFiles = ref<UploadFiles>([]);
const uploadRef = ref<UploadInstance>();
const license = reactive({
name: '',
appName: '',
licenseName: '',
trial: true,
expiresAt: new Date(),
expiresAt: '',
});
const search = async () => {
Expand All @@ -100,27 +99,41 @@ const handleExceed: UploadProps['onExceed'] = (files) => {
};
const get = async () => {
const res = await getLicense(1);
const res = await getLicense();
loading.value = false;
if (res.data !== undefined) {
license.name = res.data.name;
license.expiresAt = res.data.expiresAt;
license.licenseName = res.data.licenseName;
if (res.data.products[0].expiresAt === 0) {
license.expiresAt = '无限期';
} else {
license.expiresAt = timestampToDate(res.data.products[0].expiresAt);
}
}
};
const timestampToDate = (timestamp: number) => {
const date = new Date(timestamp);
const year = date.getFullYear();
const month = date.getMonth() + 1;
const day = date.getDate();
const hours = date.getHours();
const minutes = date.getMinutes();
const seconds = date.getSeconds();
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
};
const submit = async () => {
const files = uploaderFiles.value.slice();
if (files.length !== 1) {
MsgError('只能上传一个 License 文件');
}
const file = files[0];
loading.value = true;
const formData = new FormData();
formData.append('file', file.raw);
const res = await UploadFileData(formData);
loading.value = false;
license.appName = res.data.appName;
license.licenseName = res.data.licenseName;
await get();
loading.value = false;
};
const toDoc = () => {
Expand Down

0 comments on commit 67183d2

Please sign in to comment.