forked from github/dataease
feat: 字体管理
This commit is contained in:
parent
d3fce1d203
commit
6b062194a6
@ -6,8 +6,10 @@ import io.dataease.exception.DEException;
|
|||||||
import io.dataease.font.dao.auto.entity.CoreFont;
|
import io.dataease.font.dao.auto.entity.CoreFont;
|
||||||
import io.dataease.font.dao.auto.mapper.CoreFontMapper;
|
import io.dataease.font.dao.auto.mapper.CoreFontMapper;
|
||||||
import io.dataease.utils.BeanUtils;
|
import io.dataease.utils.BeanUtils;
|
||||||
|
import io.dataease.utils.FileUtils;
|
||||||
import io.dataease.utils.IDUtils;
|
import io.dataease.utils.IDUtils;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
@ -41,22 +43,30 @@ public class FontManage {
|
|||||||
fontDto.setId(IDUtils.snowID());
|
fontDto.setId(IDUtils.snowID());
|
||||||
CoreFont coreFont = new CoreFont();
|
CoreFont coreFont = new CoreFont();
|
||||||
BeanUtils.copyBean(coreFont, fontDto);
|
BeanUtils.copyBean(coreFont, fontDto);
|
||||||
|
coreFont.setUpdateTime(System.currentTimeMillis());
|
||||||
coreFontMapper.insert(coreFont);
|
coreFontMapper.insert(coreFont);
|
||||||
return fontDto;
|
return fontDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public FontDto edit(FontDto fontDto) {
|
public FontDto edit(FontDto fontDto) {
|
||||||
fontDto.setId(IDUtils.snowID());
|
if (ObjectUtils.isEmpty(fontDto.getId())) {
|
||||||
|
return create(fontDto);
|
||||||
|
}
|
||||||
CoreFont coreFont = new CoreFont();
|
CoreFont coreFont = new CoreFont();
|
||||||
BeanUtils.copyBean(coreFont, fontDto);
|
BeanUtils.copyBean(coreFont, fontDto);
|
||||||
|
coreFont.setUpdateTime(System.currentTimeMillis());
|
||||||
coreFontMapper.updateById(coreFont);
|
coreFontMapper.updateById(coreFont);
|
||||||
return fontDto;
|
return fontDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete(Long id) {
|
public void delete(Long id) {
|
||||||
coreFontMapper.deleteById(id);
|
CoreFont coreFont = coreFontMapper.selectById(id);
|
||||||
//TODO delete file
|
if (coreFont != null) {
|
||||||
|
coreFontMapper.deleteById(id);
|
||||||
|
FileUtils.deleteFile(path + coreFont.getFileTransName());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void changeDefault(FontDto fontDto) {
|
public void changeDefault(FontDto fontDto) {
|
||||||
@ -67,16 +77,9 @@ public class FontManage {
|
|||||||
coreFontMapper.update(record, queryWrapper);
|
coreFontMapper.update(record, queryWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void upload(MultipartFile file, long fontID) {
|
public String upload(MultipartFile file) {
|
||||||
String filename = file.getOriginalFilename();
|
|
||||||
QueryWrapper<CoreFont> queryWrapper = new QueryWrapper<>();
|
|
||||||
queryWrapper.eq("id", fontID);
|
|
||||||
CoreFont record = new CoreFont();
|
|
||||||
record.setFileName(filename);
|
|
||||||
record.setFileTransName(filename);
|
|
||||||
coreFontMapper.update(record, queryWrapper);
|
|
||||||
String fileUuid = UUID.randomUUID().toString();
|
String fileUuid = UUID.randomUUID().toString();
|
||||||
saveFile(file, fileUuid);
|
return saveFile(file, fileUuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String saveFile(MultipartFile file, String fileNameUUID) throws DEException {
|
private static String saveFile(MultipartFile file, String fileNameUUID) throws DEException {
|
||||||
|
@ -44,7 +44,7 @@ public class FontServer implements FontApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void upload(MultipartFile file, long fontID) throws DEException {
|
public String upload(MultipartFile file) throws DEException {
|
||||||
fontManage.upload(file, fontID);
|
return fontManage.upload(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,9 +77,10 @@ CREATE TABLE `core_font`
|
|||||||
(
|
(
|
||||||
`id` bigint NOT NULL COMMENT 'ID',
|
`id` bigint NOT NULL COMMENT 'ID',
|
||||||
`name` varchar(255) NOT NULL COMMENT '字体名称',
|
`name` varchar(255) NOT NULL COMMENT '字体名称',
|
||||||
`file_name` varchar(255) NOT NULL COMMENT '文件名称',
|
`file_name` varchar(255) default NULL COMMENT '文件名称',
|
||||||
`file_trans_name` varchar(255) NOT NULL COMMENT '文件转换名称',
|
`file_trans_name` varchar(255) default NULL COMMENT '文件转换名称',
|
||||||
`is_default` tinyint(1) NOT NULL COMMENT '是否默认',
|
`is_default` tinyint(1) default 0 COMMENT '是否默认',
|
||||||
`is_BuiltIn` tinyint(1) NOT NULL COMMENT '是否内置',
|
`update_time` bigint NOT NULL COMMENT '更新时间',
|
||||||
|
`is_BuiltIn` tinyint(1) default 0 COMMENT '是否内置',
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
);
|
);
|
||||||
|
@ -26,14 +26,21 @@ export const edit = (data = {}) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export const changeDefault = (data = {}) => {
|
|
||||||
return request.post({ url: '/typeface/changeDefault', data }).then(res => {
|
|
||||||
return res?.data
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export const deleteById = id => {
|
export const deleteById = id => {
|
||||||
return request.post({ url: '/typeface/delete/' + id, data: {} }).then(res => {
|
return request.post({ url: '/typeface/delete/' + id, data: {} }).then(res => {
|
||||||
return res?.data
|
return res?.data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const uploadFontFile = async (data): Promise<IResponse> => {
|
||||||
|
return request
|
||||||
|
.post({
|
||||||
|
url: '/typeface/uploadFile',
|
||||||
|
data,
|
||||||
|
loading: true,
|
||||||
|
headersType: 'multipart/form-data;'
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
return res
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@ -1,19 +1,24 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { ref, reactive } from 'vue'
|
import { ref, reactive } from 'vue'
|
||||||
import { uploadFile } from '@/api/datasource'
|
import { uploadFontFile } from '@/api/font'
|
||||||
import FontInfo from './FontInfo.vue'
|
import FontInfo from './FontInfo.vue'
|
||||||
import { ElMessage } from 'element-plus-secondary'
|
import { ElMessage } from 'element-plus-secondary'
|
||||||
|
import { edit } from '@/api/font'
|
||||||
const state = reactive({
|
const state = reactive({
|
||||||
fileList: null
|
fileList: null
|
||||||
})
|
})
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const upload = ref()
|
const upload = ref()
|
||||||
|
const uploadFile = ref('')
|
||||||
|
const fileName = ref('')
|
||||||
const uploadExcel = () => {
|
const uploadExcel = () => {
|
||||||
const formData = new FormData()
|
const formData = new FormData()
|
||||||
formData.append('file', state.fileList.raw)
|
formData.append('file', state.fileList.raw)
|
||||||
|
fileName.value = state.fileList.raw.name
|
||||||
loading.value = true
|
loading.value = true
|
||||||
return uploadFile(formData)
|
return uploadFontFile(formData)
|
||||||
.then(() => {
|
.then(res => {
|
||||||
|
uploadFile.value = res.data
|
||||||
upload.value?.clearFiles()
|
upload.value?.clearFiles()
|
||||||
loading.value = false
|
loading.value = false
|
||||||
})
|
})
|
||||||
@ -30,17 +35,18 @@ const uploadExcel = () => {
|
|||||||
}
|
}
|
||||||
const dialogTitle = ref('')
|
const dialogTitle = ref('')
|
||||||
const dialogVisible = ref(false)
|
const dialogVisible = ref(false)
|
||||||
const isRename = ref(false)
|
const action = ref('')
|
||||||
|
|
||||||
const init = (val, rename) => {
|
|
||||||
dialogTitle.value = val || '添加字体'
|
|
||||||
isRename.value = rename || false
|
|
||||||
dialogVisible.value = true
|
|
||||||
}
|
|
||||||
const ruleForm = reactive({
|
const ruleForm = reactive({
|
||||||
name: ''
|
name: ''
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const init = (val, type, item) => {
|
||||||
|
dialogTitle.value = val || '添加字体'
|
||||||
|
action.value = type
|
||||||
|
dialogVisible.value = true
|
||||||
|
Object.assign(ruleForm, JSON.parse(JSON.stringify(item)))
|
||||||
|
}
|
||||||
|
|
||||||
const fontDel = () => {
|
const fontDel = () => {
|
||||||
state.fileList = null
|
state.fileList = null
|
||||||
}
|
}
|
||||||
@ -65,9 +71,25 @@ const uploadFail = response => {
|
|||||||
myError.replace('Error: ', '')
|
myError.replace('Error: ', '')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const emits = defineEmits(['finish'])
|
||||||
|
|
||||||
const confirm = () => {
|
const confirm = () => {
|
||||||
ruleFormRef.value.validate(val => {
|
ruleFormRef.value.validate(val => {
|
||||||
if (val) {
|
if (val) {
|
||||||
|
if (action.value !== 'rename') {
|
||||||
|
if (uploadFile.value === '') {
|
||||||
|
ElMessage.error('请上传字库文件')
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
ruleForm.fileTransName = uploadFile.value
|
||||||
|
ruleForm.fileName = fileName.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
edit(ruleForm).then(res => {
|
||||||
|
ElMessage.success('成功')
|
||||||
|
dialogVisible.value = false
|
||||||
|
emits('finish')
|
||||||
|
})
|
||||||
state.fileList = null
|
state.fileList = null
|
||||||
dialogVisible.value = false
|
dialogVisible.value = false
|
||||||
}
|
}
|
||||||
@ -85,10 +107,10 @@ const confirm = () => {
|
|||||||
label-width="auto"
|
label-width="auto"
|
||||||
class="demo-ruleForm"
|
class="demo-ruleForm"
|
||||||
>
|
>
|
||||||
<el-form-item label="字体名称" prop="name">
|
<el-form-item v-if="action !== 'uploadFile'" label="字体名称" prop="name">
|
||||||
<el-input placeholder="请输入字体名称" v-model="ruleForm.name" />
|
<el-input placeholder="请输入字体名称" v-model="ruleForm.name" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item v-if="!isRename" label="字库文件">
|
<el-form-item v-if="action !== 'rename'" label="字库文件">
|
||||||
<el-upload
|
<el-upload
|
||||||
action=""
|
action=""
|
||||||
:multiple="false"
|
:multiple="false"
|
||||||
|
@ -2,14 +2,14 @@
|
|||||||
import { onMounted, ref } from 'vue'
|
import { onMounted, ref } from 'vue'
|
||||||
|
|
||||||
import UploadDetail from './UploadDetail.vue'
|
import UploadDetail from './UploadDetail.vue'
|
||||||
import { changeDefault, deleteById, list } from '@/api/font'
|
import { deleteById, edit, list } from '@/api/font'
|
||||||
|
import { ElMessage } from 'element-plus-secondary'
|
||||||
const fontKeyword = ref('')
|
const fontKeyword = ref('')
|
||||||
const fontList = ref([])
|
const fontList = ref([])
|
||||||
|
|
||||||
// const fontList = ref([1, 2, 3, 4, 5])
|
|
||||||
const uploadDetail = ref()
|
const uploadDetail = ref()
|
||||||
const uploadFont = (title, isRename?: boolean) => {
|
const uploadFont = (title, type, item) => {
|
||||||
uploadDetail.value.init(title, isRename)
|
uploadDetail.value.init(title, type, item)
|
||||||
}
|
}
|
||||||
|
|
||||||
const listFont = () => {
|
const listFont = () => {
|
||||||
@ -19,15 +19,23 @@ const listFont = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const deleteFont = item => {
|
const deleteFont = item => {
|
||||||
deleteById(item.id).then(res => {
|
deleteById(item.id).then(() => {
|
||||||
|
ElMessage.success('删除成功')
|
||||||
listFont()
|
listFont()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const setToDefault = item => {
|
const setToDefault = item => {
|
||||||
item.isDefault = 1
|
item.isDefault = 1
|
||||||
changeDefault(item).then(res => {
|
edit(item).then(() => {
|
||||||
fontList.value = res
|
ElMessage.success('设置成功')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const cancleDefault = item => {
|
||||||
|
item.isDefault = 0
|
||||||
|
edit(item).then(() => {
|
||||||
|
ElMessage.success('取消成功')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,7 +57,7 @@ onMounted(() => {
|
|||||||
</template>
|
</template>
|
||||||
</el-input>
|
</el-input>
|
||||||
|
|
||||||
<el-button type="primary">
|
<el-button type="primary" @click="uploadFont('新建字体', 'create', {})">
|
||||||
<template #icon>
|
<template #icon>
|
||||||
<Icon name="icon_add_outlined"></Icon>
|
<Icon name="icon_add_outlined"></Icon>
|
||||||
</template>
|
</template>
|
||||||
@ -59,21 +67,31 @@ onMounted(() => {
|
|||||||
</div>
|
</div>
|
||||||
<div class="font-content_list">
|
<div class="font-content_list">
|
||||||
<div class="font-content_item" v-for="ele in fontList" :key="ele">
|
<div class="font-content_item" v-for="ele in fontList" :key="ele">
|
||||||
<span class="font-default">默认字体</span>
|
<span v-if="ele.isDefault" class="font-default">默认字体</span>
|
||||||
<div class="font-name">PingFang <span class="font-type"> 系统内置 </span></div>
|
<div class="font-name">
|
||||||
|
{{ ele.name }} <span v-if="ele.isBuiltin" class="font-type"> 系统内置 </span>
|
||||||
|
</div>
|
||||||
<div class="font-update_time">
|
<div class="font-update_time">
|
||||||
更新时间:2022-04-20 20:35:08 <span class="line"></span> 字库文件:-
|
更新时间: {{ new Date(ele.updateTime).toLocaleString() }}
|
||||||
|
<span class="line"></span> 字库文件: {{ ele.fileName }}
|
||||||
</div>
|
</div>
|
||||||
<div class="font-upload_btn">
|
<div class="font-upload_btn">
|
||||||
<el-button @click="uploadFont('添加字体')" secondary>上传字库文件</el-button>
|
<el-button @click="uploadFont('上传字库文件', 'uploadFile', ele)" secondary
|
||||||
<el-button @click="setToDefault(ele)" secondary>设为默认字体</el-button>
|
>上传字库文件</el-button
|
||||||
<el-button @click="uploadFont('重命名', true)" secondary>重命名</el-button>
|
>
|
||||||
|
<el-button v-if="!ele.isDefault" @click="setToDefault(ele)" secondary
|
||||||
|
>设为默认字体</el-button
|
||||||
|
>
|
||||||
|
<el-button v-if="ele.isDefault" @click="cancleDefault(ele)" secondary
|
||||||
|
>取消默认字体</el-button
|
||||||
|
>
|
||||||
|
<el-button @click="uploadFont('重命名', 'rename', ele)" secondary>重命名</el-button>
|
||||||
<el-button @click="deleteFont(ele)" secondary>删除</el-button>
|
<el-button @click="deleteFont(ele)" secondary>删除</el-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<UploadDetail ref="uploadDetail"></UploadDetail>
|
<UploadDetail @finish="listFont" ref="uploadDetail"></UploadDetail>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style lang="less" scoped>
|
<style lang="less" scoped>
|
||||||
|
@ -40,10 +40,10 @@ public interface FontApi {
|
|||||||
public void delete(@PathVariable("id") Long id);
|
public void delete(@PathVariable("id") Long id);
|
||||||
|
|
||||||
@Operation(summary = "变更默认设置")
|
@Operation(summary = "变更默认设置")
|
||||||
@PostMapping("/changeDefault/")
|
@PostMapping("/setDefault/")
|
||||||
public void changeDefault(@RequestBody FontDto fontDto);
|
public void changeDefault(@RequestBody FontDto fontDto);
|
||||||
|
|
||||||
@PostMapping("/uploadFile")
|
@PostMapping("/uploadFile")
|
||||||
void upload(@RequestParam("file") MultipartFile file, @RequestParam("id") long fontID) throws DEException;
|
String upload(@RequestParam("file") MultipartFile file) throws DEException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ public class FontDto {
|
|||||||
* 是否默认
|
* 是否默认
|
||||||
*/
|
*/
|
||||||
private Boolean isDefault;
|
private Boolean isDefault;
|
||||||
|
private Long updateTime;
|
||||||
private Boolean isBuiltin;
|
private Boolean isBuiltin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user