forked from github/dataease
Merge pull request #11752 from dataease/pr@dev-v2@fixDS
Pr@dev v2@fix ds
This commit is contained in:
commit
3c71d08358
@ -9,7 +9,7 @@ import java.io.Serializable;
|
||||
* </p>
|
||||
*
|
||||
* @author fit2cloud
|
||||
* @since 2024-08-23
|
||||
* @since 2024-08-26
|
||||
*/
|
||||
@TableName("core_font")
|
||||
public class CoreFont implements Serializable {
|
||||
@ -41,6 +41,11 @@ public class CoreFont implements Serializable {
|
||||
*/
|
||||
private Boolean isDefault;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Long updateTime;
|
||||
|
||||
/**
|
||||
* 是否内置
|
||||
*/
|
||||
@ -86,6 +91,14 @@ public class CoreFont implements Serializable {
|
||||
this.isDefault = isDefault;
|
||||
}
|
||||
|
||||
public Long getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(Long updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
public Boolean getIsBuiltin() {
|
||||
return isBuiltin;
|
||||
}
|
||||
@ -102,6 +115,7 @@ public class CoreFont implements Serializable {
|
||||
", fileName = " + fileName +
|
||||
", fileTransName = " + fileTransName +
|
||||
", isDefault = " + isDefault +
|
||||
", updateTime = " + updateTime +
|
||||
", isBuiltin = " + isBuiltin +
|
||||
"}";
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
* </p>
|
||||
*
|
||||
* @author fit2cloud
|
||||
* @since 2024-08-23
|
||||
* @since 2024-08-26
|
||||
*/
|
||||
@Mapper
|
||||
public interface CoreFontMapper extends BaseMapper<CoreFont> {
|
||||
|
@ -6,8 +6,10 @@ import io.dataease.exception.DEException;
|
||||
import io.dataease.font.dao.auto.entity.CoreFont;
|
||||
import io.dataease.font.dao.auto.mapper.CoreFontMapper;
|
||||
import io.dataease.utils.BeanUtils;
|
||||
import io.dataease.utils.FileUtils;
|
||||
import io.dataease.utils.IDUtils;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@ -41,22 +43,30 @@ public class FontManage {
|
||||
fontDto.setId(IDUtils.snowID());
|
||||
CoreFont coreFont = new CoreFont();
|
||||
BeanUtils.copyBean(coreFont, fontDto);
|
||||
coreFont.setUpdateTime(System.currentTimeMillis());
|
||||
coreFontMapper.insert(coreFont);
|
||||
return fontDto;
|
||||
}
|
||||
|
||||
|
||||
public FontDto edit(FontDto fontDto) {
|
||||
fontDto.setId(IDUtils.snowID());
|
||||
if (ObjectUtils.isEmpty(fontDto.getId())) {
|
||||
return create(fontDto);
|
||||
}
|
||||
CoreFont coreFont = new CoreFont();
|
||||
BeanUtils.copyBean(coreFont, fontDto);
|
||||
coreFont.setUpdateTime(System.currentTimeMillis());
|
||||
coreFontMapper.updateById(coreFont);
|
||||
return fontDto;
|
||||
}
|
||||
|
||||
public void delete(Long id) {
|
||||
coreFontMapper.deleteById(id);
|
||||
//TODO delete file
|
||||
CoreFont coreFont = coreFontMapper.selectById(id);
|
||||
if (coreFont != null) {
|
||||
coreFontMapper.deleteById(id);
|
||||
FileUtils.deleteFile(path + coreFont.getFileTransName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void changeDefault(FontDto fontDto) {
|
||||
@ -67,16 +77,9 @@ public class FontManage {
|
||||
coreFontMapper.update(record, queryWrapper);
|
||||
}
|
||||
|
||||
public void upload(MultipartFile file, long fontID) {
|
||||
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);
|
||||
public String upload(MultipartFile file) {
|
||||
String fileUuid = UUID.randomUUID().toString();
|
||||
saveFile(file, fileUuid);
|
||||
return saveFile(file, fileUuid);
|
||||
}
|
||||
|
||||
private static String saveFile(MultipartFile file, String fileNameUUID) throws DEException {
|
||||
|
@ -44,7 +44,7 @@ public class FontServer implements FontApi {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void upload(MultipartFile file, long fontID) throws DEException {
|
||||
fontManage.upload(file, fontID);
|
||||
public String upload(MultipartFile file) throws DEException {
|
||||
return fontManage.upload(file);
|
||||
}
|
||||
}
|
||||
|
@ -77,9 +77,10 @@ CREATE TABLE `core_font`
|
||||
(
|
||||
`id` bigint NOT NULL COMMENT 'ID',
|
||||
`name` varchar(255) NOT NULL COMMENT '字体名称',
|
||||
`file_name` varchar(255) NOT NULL COMMENT '文件名称',
|
||||
`file_trans_name` varchar(255) NOT NULL COMMENT '文件转换名称',
|
||||
`is_default` tinyint(1) NOT NULL COMMENT '是否默认',
|
||||
`is_BuiltIn` tinyint(1) NOT NULL COMMENT '是否内置',
|
||||
`file_name` varchar(255) default NULL COMMENT '文件名称',
|
||||
`file_trans_name` varchar(255) default NULL COMMENT '文件转换名称',
|
||||
`is_default` tinyint(1) default 0 COMMENT '是否默认',
|
||||
`update_time` bigint NOT NULL COMMENT '更新时间',
|
||||
`is_BuiltIn` tinyint(1) default 0 COMMENT '是否内置',
|
||||
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 => {
|
||||
return request.post({ url: '/typeface/delete/' + id, data: {} }).then(res => {
|
||||
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>
|
||||
import { ref, reactive } from 'vue'
|
||||
import { uploadFile } from '@/api/datasource'
|
||||
import { uploadFontFile } from '@/api/font'
|
||||
import FontInfo from './FontInfo.vue'
|
||||
import { ElMessage } from 'element-plus-secondary'
|
||||
import { edit } from '@/api/font'
|
||||
const state = reactive({
|
||||
fileList: null
|
||||
})
|
||||
const loading = ref(false)
|
||||
const upload = ref()
|
||||
const uploadFile = ref('')
|
||||
const fileName = ref('')
|
||||
const uploadExcel = () => {
|
||||
const formData = new FormData()
|
||||
formData.append('file', state.fileList.raw)
|
||||
fileName.value = state.fileList.raw.name
|
||||
loading.value = true
|
||||
return uploadFile(formData)
|
||||
.then(() => {
|
||||
return uploadFontFile(formData)
|
||||
.then(res => {
|
||||
uploadFile.value = res.data
|
||||
upload.value?.clearFiles()
|
||||
loading.value = false
|
||||
})
|
||||
@ -30,17 +35,18 @@ const uploadExcel = () => {
|
||||
}
|
||||
const dialogTitle = ref('')
|
||||
const dialogVisible = ref(false)
|
||||
const isRename = ref(false)
|
||||
|
||||
const init = (val, rename) => {
|
||||
dialogTitle.value = val || '添加字体'
|
||||
isRename.value = rename || false
|
||||
dialogVisible.value = true
|
||||
}
|
||||
const action = ref('')
|
||||
const ruleForm = reactive({
|
||||
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 = () => {
|
||||
state.fileList = null
|
||||
}
|
||||
@ -65,9 +71,25 @@ const uploadFail = response => {
|
||||
myError.replace('Error: ', '')
|
||||
}
|
||||
|
||||
const emits = defineEmits(['finish'])
|
||||
|
||||
const confirm = () => {
|
||||
ruleFormRef.value.validate(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
|
||||
dialogVisible.value = false
|
||||
}
|
||||
@ -85,10 +107,10 @@ const confirm = () => {
|
||||
label-width="auto"
|
||||
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-form-item>
|
||||
<el-form-item v-if="!isRename" label="字库文件">
|
||||
<el-form-item v-if="action !== 'rename'" label="字库文件">
|
||||
<el-upload
|
||||
action=""
|
||||
:multiple="false"
|
||||
|
@ -2,14 +2,14 @@
|
||||
import { onMounted, ref } from '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 fontList = ref([])
|
||||
|
||||
// const fontList = ref([1, 2, 3, 4, 5])
|
||||
const uploadDetail = ref()
|
||||
const uploadFont = (title, isRename?: boolean) => {
|
||||
uploadDetail.value.init(title, isRename)
|
||||
const uploadFont = (title, type, item) => {
|
||||
uploadDetail.value.init(title, type, item)
|
||||
}
|
||||
|
||||
const listFont = () => {
|
||||
@ -19,15 +19,23 @@ const listFont = () => {
|
||||
}
|
||||
|
||||
const deleteFont = item => {
|
||||
deleteById(item.id).then(res => {
|
||||
deleteById(item.id).then(() => {
|
||||
ElMessage.success('删除成功')
|
||||
listFont()
|
||||
})
|
||||
}
|
||||
|
||||
const setToDefault = item => {
|
||||
item.isDefault = 1
|
||||
changeDefault(item).then(res => {
|
||||
fontList.value = res
|
||||
edit(item).then(() => {
|
||||
ElMessage.success('设置成功')
|
||||
})
|
||||
}
|
||||
|
||||
const cancleDefault = item => {
|
||||
item.isDefault = 0
|
||||
edit(item).then(() => {
|
||||
ElMessage.success('取消成功')
|
||||
})
|
||||
}
|
||||
|
||||
@ -49,7 +57,7 @@ onMounted(() => {
|
||||
</template>
|
||||
</el-input>
|
||||
|
||||
<el-button type="primary">
|
||||
<el-button type="primary" @click="uploadFont('新建字体', 'create', {})">
|
||||
<template #icon>
|
||||
<Icon name="icon_add_outlined"></Icon>
|
||||
</template>
|
||||
@ -59,21 +67,31 @@ onMounted(() => {
|
||||
</div>
|
||||
<div class="font-content_list">
|
||||
<div class="font-content_item" v-for="ele in fontList" :key="ele">
|
||||
<span class="font-default">默认字体</span>
|
||||
<div class="font-name">PingFang <span class="font-type"> 系统内置 </span></div>
|
||||
<span v-if="ele.isDefault" class="font-default">默认字体</span>
|
||||
<div class="font-name">
|
||||
{{ ele.name }} <span v-if="ele.isBuiltin" class="font-type"> 系统内置 </span>
|
||||
</div>
|
||||
<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 class="font-upload_btn">
|
||||
<el-button @click="uploadFont('添加字体')" secondary>上传字库文件</el-button>
|
||||
<el-button @click="setToDefault(ele)" secondary>设为默认字体</el-button>
|
||||
<el-button @click="uploadFont('重命名', true)" secondary>重命名</el-button>
|
||||
<el-button @click="uploadFont('上传字库文件', 'uploadFile', ele)" 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>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<UploadDetail ref="uploadDetail"></UploadDetail>
|
||||
<UploadDetail @finish="listFont" ref="uploadDetail"></UploadDetail>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
|
@ -40,10 +40,10 @@ public interface FontApi {
|
||||
public void delete(@PathVariable("id") Long id);
|
||||
|
||||
@Operation(summary = "变更默认设置")
|
||||
@PostMapping("/changeDefault/")
|
||||
@PostMapping("/setDefault/")
|
||||
public void changeDefault(@RequestBody FontDto fontDto);
|
||||
|
||||
@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 Long updateTime;
|
||||
private Boolean isBuiltin;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user