style: 优化标签编辑界面

This commit is contained in:
jmal 2024-03-19 11:17:32 +08:00
parent 57ed3fce69
commit 98f642290a
4 changed files with 82 additions and 15 deletions

View File

@ -65,15 +65,11 @@ export default {
} }
}, },
// 为文件分配标签 // 为文件分配标签
setTags: function(params, data) { setTags: function(data) {
return request({ return request({
url: 'setTag', url: 'setTag',
method: 'post', method: 'post',
data: data, data
params: params,
paramsSerializer: function(params) {
return qs.stringify(params, { arrayFormat: 'repeat' })
}
}) })
}, },
// 将文件设为公共文件 // 将文件设为公共文件

View File

@ -1,6 +1,16 @@
<template> <template>
<di> <di>
<el-dialog :title='"将标签分配给 \"" + showName + "\""' style="{'font-weight': 600}" :visible.sync="tagDialogVisible" @close="tagDialogClose"> <message-dialog
title="确认信息"
content="检测到未保存的内容,是否在离开前保存修改?"
:show.sync="isSaveDialogVisible"
operatButtonText="放弃修改"
confirmButtonText="保存"
@operating="closeConfirmDialog"
@confirm="confirmUpdate"
>
</message-dialog>
<el-dialog :title='"将标签分配给 \"" + showName + "\""' style="{'font-weight': 600}" :visible.sync="tagDialogVisible" :before-close="beforeClose" @close="tagDialogClose">
<div class="tag-content"> <div class="tag-content">
<el-tag <el-tag
:key="tag.name" :key="tag.name"
@ -35,8 +45,9 @@
<el-button v-else class="button-new-tag" size="small" @click="showInput">+ 新标签</el-button> <el-button v-else class="button-new-tag" size="small" @click="showInput">+ 新标签</el-button>
<div class="tag-list"> <div class="tag-list">
<p>现有标签: </p> <p v-if="existingTags.length > 0">现有标签: </p>
<el-button <el-button
v-if="!isEditMode"
size="small" size="small"
:key="tag.name" :key="tag.name"
v-for="tag in existingTags" v-for="tag in existingTags"
@ -44,12 +55,23 @@
<svg-icon :style="{ color: tag.color, fontSize: '14px' }" icon-class="tag2"></svg-icon> <svg-icon :style="{ color: tag.color, fontSize: '14px' }" icon-class="tag2"></svg-icon>
{{tag.name}} {{tag.name}}
</el-button> </el-button>
<div v-if="isEditMode">
<el-tag
:key="tag.name"
v-for="tag in existingTags"
:closable="isEditMode"
:disable-transitions="false"
@close="handleCloseCurrentTags(tag.name)">
<svg-icon :style="{ color: tag.color, fontSize: '14px' }" icon-class="tag2"></svg-icon>
{{tag.name}}
</el-tag>
</div>
</div> </div>
</div> </div>
<div slot="footer" class="dialog-footer"> <div slot="footer" class="dialog-footer">
<el-button size="small" type="primary" @click="submitTag" v-loading="saveLoading">保存 <el-button v-if="existingTags.length > 0 || isEditMode" size="small" @click="editMode" >{{ isEditMode ? '取消编辑' : '编辑现有标签' }}</el-button>
</el-button> <el-button size="small" type="primary" @click="submitTag" v-loading="saveLoading">保存</el-button>
</div> </div>
</el-dialog> </el-dialog>
</di> </di>
@ -60,10 +82,12 @@
import fileApi from '@/api/file-api' import fileApi from '@/api/file-api'
import tagApi from '@/api/tag' import tagApi from '@/api/tag'
import { Sketch } from 'vue-color' import { Sketch } from 'vue-color'
import MessageDialog from "@/components/message/MessageDialog.vue";
export default { export default {
name: "TagDialog", name: "TagDialog",
components: { components: {
MessageDialog,
'sketch-picker': Sketch 'sketch-picker': Sketch
}, },
props: { props: {
@ -89,7 +113,11 @@ export default {
saveLoading: false, saveLoading: false,
colors: { colors: {
hex: '#f56c6c', hex: '#f56c6c',
} },
isEditMode: false,
remoteTagIdList: [],
isSaveDialogVisible: false,
hasChange: false,
} }
}, },
watch: { watch: {
@ -144,6 +172,12 @@ export default {
this.tags.splice(index, 1) this.tags.splice(index, 1)
this.updateExistingTags() this.updateExistingTags()
}, },
handleCloseCurrentTags(tagName) {
let index = this.existingTags.findIndex(item => item.name === tagName)
const removeTag = this.existingTags.splice(index, 1)
this.remoteTagIdList.push(removeTag[0].id)
this.hasChange = true
},
showInput() { showInput() {
this.inputVisible = true; this.inputVisible = true;
this.$nextTick(_ => { this.$nextTick(_ => {
@ -159,34 +193,64 @@ export default {
this.$message.error('标签已存在'); this.$message.error('标签已存在');
return; return;
} }
this.hasChange = true
this.tags.push({ name: inputValue, color: this.defaultTagColor}); this.tags.push({ name: inputValue, color: this.defaultTagColor});
} }
this.inputVisible = false; this.inputVisible = false;
this.inputValue = ''; this.inputValue = '';
}, },
addTag(tag) { addTag(tag) {
this.hasChange = true
// 是否有相同的标签 // 是否有相同的标签
this.tags.push({ name: tag.name, color: tag.color }); this.tags.push({ name: tag.name, color: tag.color });
this.updateExistingTags() this.updateExistingTags()
}, },
closeConfirmDialog() {
this.isSaveDialogVisible = false
this.hasChange = true
this.tagDialogClose();
},
beforeClose(done) {
if (this.hasChange) {
this.isSaveDialogVisible = true
} else {
done()
this.isSaveDialogVisible = false
}
},
tagDialogClose() { tagDialogClose() {
this.tagDialogVisible = false
this.$emit('update:status', this.tagDialogVisible) this.$emit('update:status', this.tagDialogVisible)
this.isEditMode = false
},
editMode() {
this.isEditMode = !this.isEditMode
if (!this.isEditMode) {
this.remoteTagIdList = []
}
this.updateExistingTags()
},
confirmUpdate() {
this.submitTag()
}, },
submitTag() { submitTag() {
this.saveLoading = true this.saveLoading = true
// 提取出文件id // 提取出文件id
const fileIdList = this.fileList.map(item => item.id) const fileIdList = this.fileList.map(item => item.id)
fileApi.setTags({fileIds: fileIdList}, this.tags).then(() => { fileApi.setTags({fileIds: fileIdList, tagList: this.tags, removeTagIds: this.remoteTagIdList}).then(() => {
this.saveLoading = false this.saveLoading = false
this.$message.success('保存成功'); this.$message.success('保存成功');
this.$emit('onSuccess') this.$emit('onSuccess')
this.hasChange = false
this.tagDialogVisible = false this.tagDialogVisible = false
this.isSaveDialogVisible = false
this.tagDialogClose() this.tagDialogClose()
}).catch(() => { }).catch(() => {
this.saveLoading = false this.saveLoading = false
}) })
}, },
updateColor(color, tag) { updateColor(color, tag) {
this.hasChange = true
// 更新tags // 更新tags
this.tags.forEach(item => { this.tags.forEach(item => {
if (item.name === tag.name) { if (item.name === tag.name) {

View File

@ -182,9 +182,13 @@ export default {
this.showTag = true this.showTag = true
} }
tagApi.tagList({userId: this.$store.state.user.userId}).then(res => { tagApi.tagList({userId: this.$store.state.user.userId}).then(res => {
this.tagList = res.data this.setTagListData(res.data)
}) })
}, },
setTagListData(tagList) {
this.tagList = tagList
this.showTag = this.tagList.length > 0
},
onmessage(msg) { onmessage(msg) {
const takeUpSpace = msg.space const takeUpSpace = msg.space
if (takeUpSpace) { if (takeUpSpace) {
@ -193,6 +197,9 @@ export default {
const percentage = Number((space/this.userInfo.quota * 100).toFixed(1)) const percentage = Number((space/this.userInfo.quota * 100).toFixed(1))
this.percentage = percentage > 100 ? 100 : percentage this.percentage = percentage > 100 ? 100 : percentage
} }
if (msg.url === 'updateTags') {
this.setTagListData(msg.body)
}
}, },
copyWebDAVLink(className) { copyWebDAVLink(className) {
let clipboard = new Clipboard(className) let clipboard = new Clipboard(className)

View File

@ -18,12 +18,12 @@ export function connectToSSE(username) {
if (timer) { if (timer) {
clearInterval(timer); clearInterval(timer);
} }
// 15s检测一次连接状态 // 1s检测一次连接状态
timer = setInterval(() => { timer = setInterval(() => {
if (eventSource.readyState === 2) { if (eventSource.readyState === 2) {
connectToSSE(username); connectToSSE(username);
} }
}, 15000); }, 1000);
} else { } else {
console.error('EventSource is not supported by the browser'); console.error('EventSource is not supported by the browser');