feat: 新增关于页面 以及 lic更新功能

This commit is contained in:
fit2cloud-chenyw 2021-05-18 12:23:21 +08:00
parent 120dd256aa
commit 5fc32d6bba
8 changed files with 337 additions and 9 deletions

View File

@ -0,0 +1,32 @@
package io.dataease.controller;
import io.dataease.commons.license.F2CLicenseResponse;
import io.dataease.service.AboutService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Map;
@RequestMapping("/about")
@RestController
public class AboutController {
@Resource
private AboutService aboutService;
@PostMapping("/license/update")
public F2CLicenseResponse updateLicense(@RequestBody Map<String, String> map) {
return aboutService.updateLicense(map.get("license"));
}
@PostMapping("/license/validate")
public F2CLicenseResponse validateLicense(@RequestBody Map<String, String> map) {
return aboutService.validateLicense(map.get("license"));
}
@GetMapping("/build/version")
public Object getBuildVersion() {
return aboutService.getBuildVersion();
}
}

View File

@ -0,0 +1,54 @@
package io.dataease.service;
import io.dataease.commons.license.DefaultLicenseService;
import io.dataease.commons.license.F2CLicenseResponse;
import io.dataease.commons.utils.CommonBeanFactory;
import io.dataease.commons.utils.LogUtil;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.File;
import java.util.Optional;
@Service
public class AboutService {
private static final String BUILD_VERSION = "/opt/fit2cloud/conf/version";
private static final String product = "dataease";
@Resource
private DefaultLicenseService defaultLicenseService;
public F2CLicenseResponse updateLicense(String licenseKey) {
F2CLicenseResponse f2CLicenseResponse = defaultLicenseService.updateLicense(product, licenseKey);
return f2CLicenseResponse;
}
public F2CLicenseResponse validateLicense(String licenseKey) {
if (StringUtils.isNotBlank(licenseKey)) {
return defaultLicenseService.validateLicense(product, licenseKey);
} else {
return defaultLicenseService.validateLicense();
}
}
public String getBuildVersion() {
try {
File file = new File(BUILD_VERSION);
if (file.exists()) {
String version = FileUtils.readFileToString(file, "UTF-8");
if (StringUtils.isNotBlank(version)) {
return version;
}
}
String property = CommonBeanFactory.getBean(Environment.class).getProperty("cmp.version");
String result = Optional.ofNullable(property).orElse("V1.0");
return result;
} catch (Exception e) {
LogUtil.error("failed to get build version.", e);
}
return "unknown";
}
}

View File

@ -0,0 +1,24 @@
import request from '@/utils/request'
export function validate(data) {
return request({
url: '/about/license/validate',
method: 'post',
data
})
}
export function buildVersion() {
return request({
url: '/about/build/version',
method: 'get'
})
}
export function updateInfo(data) {
return request({
url: '/about/license/update',
method: 'post',
data
})
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

View File

@ -50,7 +50,11 @@ export default {
background-color: #c92100;
color: #fff;
text-align: center;
padding: 6px 11px;
/* padding: 6px 11px; */
position: fixed;
z-index: 1002;
top: 0;
width: 100%;
}
</style>

View File

@ -51,13 +51,16 @@
<el-dropdown-item>重置密码</el-dropdown-item>
</router-link>
<a href="https://panjiachen.github.io/vue-element-admin-site/#/" target="_blank">
<a href="/swagger-ui/index.html" target="_blank">
<el-dropdown-item>Docs</el-dropdown-item>
</a>
<a href="https://fit2cloud.com/" target="_blank">
<!-- <a href="https://fit2cloud.com/" target="_blank">
<el-dropdown-item>关于</el-dropdown-item>
</a>
</a> -->
<router-link to="/system/about">
<el-dropdown-item>关于</el-dropdown-item>
</router-link>
<el-dropdown-item divided @click.native="logout">
<span style="display:block;">退出</span>
</el-dropdown-item>

View File

@ -1,6 +1,6 @@
<template>
<div :class="classObj" class="app-wrapper">
<!-- <licbar /> -->
<licbar />
<topbar />
<div v-if="device==='mobile'&&sidebar.opened" class="drawer-bg" @click="handleClickOutside" />
<sidebar v-if="!sidebar.hide" class="sidebar-container" />
@ -18,8 +18,8 @@
<script>
import RightPanel from '@/components/RightPanel'
// import { Sidebar, Settings, AppMain, Topbar, Licbar } from './components'
import { Sidebar, Settings, AppMain, Topbar } from './components'
import { Sidebar, Settings, AppMain, Topbar, Licbar } from './components'
// import { Sidebar, Settings, AppMain, Topbar } from './components'
import ResizeMixin from './mixin/ResizeHandler'
export default {
@ -29,8 +29,8 @@ export default {
Sidebar,
Settings,
AppMain,
Topbar
// Licbar
Topbar,
Licbar
},
mixins: [ResizeMixin],
computed: {

View File

@ -0,0 +1,211 @@
<template>
<layout-content>
<div>
<el-card class="box-card about-card">
<div slot="header" class="clearfix license-header">
<img src="@/assets/DataEase-white.png" alt="" style="height: 80px;width: 400px;padding-top: 15px;">
</div>
<div class="license-content">
<div v-if="license.status === 'Fail'">License 无效</div>
<div v-if="license.status !== 'Fail'">
<table>
<tr>
<th>授权给</th>
<td>{{ license.corporation }}</td>
</tr>
<tr>
<th>过期时间</th>
<td>
<label v-if="license.status === 'expired'" style="color: red">{{ license.expired }} (已过期)</label>
<label v-if="license.status === 'valid'">{{ license.expired }}</label>
</td>
</tr>
<tr>
<th>授权数量</th>
<td>{{ license.count }}</td>
</tr>
<tr>
<th>版本</th>
<td>
<span v-if="license.edition">
<span v-if="license.edition === 'Standard'">标准版</span>
<span v-if="license.edition === 'Enterprise'">企业版</span>
</span>
</td>
</tr>
<tr>
<th>版本号</th>
<td>
<span>{{ build }}</span>
</td>
</tr>
</table>
</div>
<div class="md-padding" />
<div layout="row" layout-align="space-between center" class="lic_rooter">
<el-upload
action=""
:multiple="false"
:show-file-list="false"
:file-list="fileList"
accept=".key"
name="file"
:before-upload="beforeUpload"
>
<a class="md-primary pointer">更新 License</a>
</el-upload>
<a class="md-primary pointer" @click="support">获取技术支持</a>
</div>
</div>
</el-card>
</div>
</layout-content>
</template>
<script>
import LayoutContent from '@/components/business/LayoutContent'
import { validate, buildVersion, updateInfo } from '@/api/system/about'
import { getToken } from '@/utils/auth'
export default {
components: { LayoutContent },
data() {
return {
license: {},
version: null,
build: null,
licenseKey: '',
fileList: [],
headers: { Authorization: getToken() }
}
},
created() {
this.initVersion()
this.getLicenseInfo()
},
methods: {
initVersion() {
buildVersion().then(res => {
this.build = res.data
})
},
getLicenseInfo() {
// validate({}).then(res => {
// this.license = this.getLicense(res.data)
// console.log(this.license)
// })
this.validateHandler({}, res => {
this.license = this.getLicense(res.data)
})
},
validateHandler(param, success) {
validate(param).then(success)
},
getLicense(result) {
return {
status: result.status,
corporation: result.license ? result.license.corporation : '',
expired: result.license ? result.license.expired : '',
count: result.license ? result.license.count : '',
version: result.license ? result.license.version : '',
edition: result.license ? result.license.edition : ''
}
},
importLic(file) {
const reader = new FileReader()
reader.onload = function(e) {
this.licenseKey = e.target.result
this.validateHandler({ license: this.licenseKey }, response => {
this.updateLicense = this.getLicense(response.data)
this.update()
})
}.bind(this)
reader.readAsText(file)
},
update() {
const param = { license: this.licenseKey }
updateInfo(param).then(response => {
if (response.data.status === 'valid') {
this.$success(this.$t('i18n_mc_update_success'))
this.license = this.getLicense(response.data)
} else {
this.$warning(response.data.message)
}
})
},
support() {
const url = 'https://support.fit2cloud.com/'
window.open(url, '_blank')
},
beforeUpload(file) {
// console.log(file)
this.importLic(file)
return false
}
}
}
</script>
<style lang="scss" scoped>
.about-card {
background: inherit;
margin-top: 5%;
flex-direction: row;
margin-left: 20%;
margin-right: 20%;
width: 640px;
height: 400px;
position: relative;
>>>div.el-card__header {
padding: 0;
}
}
.license-header {
height: 100px;
background-image: url('../../../assets/license_header.png');
text-align: center;
padding: 20px 0;
background-size: 100% 100%;
}
.license-content {
font-size: 16px;
padding: 50px;
>>>table {
width: 100%;
}
>>>th {
text-align: left;
width: 45%;
}
>>>td {
display: table-cell;
vertical-align: inherit;
}
}
.md-padding {
padding: 10px;
}
.lic_rooter {
flex-direction: row;
box-sizing: border-box;
display: flex;
align-items: center;
align-content: center;
max-width: 100%;
justify-content: space-between;
>>>a{
color: rgb(10,123,224);
cursor: pointer;
}
}
</style>