Files
aida_front/src/component/LibraryPage/setLabel.vue

472 lines
12 KiB
Vue
Raw Normal View History

2023-11-07 09:30:25 +08:00
<template>
<a-modal class="library_setLabel"
v-model:visible="setLabelShow"
:footer="null"
title="Edit tag"
width="65%"
:maskClosable="false"
:centered="true"
2023-11-09 16:55:20 +08:00
@cancel="clearSetLabel"
2023-11-07 09:30:25 +08:00
>
2023-11-08 13:01:45 +08:00
<div class="setLabel_centent">
2023-11-09 10:16:18 +08:00
<ul class="optionsItem">
<li class="optionsItem_title" v-for="optionsItem,optionsIndex in options" :key="optionsItem.id">
<div class="setLabel_text">
<a-checkbox v-model:checked="optionsItem.checkAll" @change="onCheckAllChange(optionsItem)"></a-checkbox>
2023-11-13 09:52:57 +08:00
<span v-show="!optionsItem.openType" :title="optionsItem.classificationName">{{ optionsItem.classificationName }}</span>
2023-11-09 10:16:18 +08:00
<input v-show="optionsItem.openType" type="text" v-model="itemName">
2023-11-13 09:52:57 +08:00
<i v-show="optionsItem.openType" @click.stop="putName(optionsIndex,'affirm',optionsItem)" class="fi fi-br-check"></i>
2023-11-09 10:16:18 +08:00
<i v-show="!optionsItem.openType" @click.stop="putName(optionsIndex,'put',optionsItem)" class="fi fi-rr-edit"></i>
</div>
<ul class="childrenItem active" v-mousewheel>
2023-11-09 13:49:10 +08:00
<li class="childrenItem_title setLabel_text" v-for="childrenItem,childrenIndex in optionsItem.childList" :key="childrenItem.id">
<a-checkbox v-model:checked="childrenItem.checkAll" @change="onCheckAllchildrenItem(optionsItem)"></a-checkbox>
2023-11-13 09:52:57 +08:00
<span v-show="!childrenItem.openType" :title="childrenItem.classificationName">{{ childrenItem.classificationName }}</span>
2023-11-09 10:16:18 +08:00
<input v-show="childrenItem.openType" type="text" v-model="itemName">
2023-11-13 09:52:57 +08:00
<i v-show="childrenItem.openType" @click.stop="putName(childrenIndex,'affirm',childrenItem)" class="fi fi-br-check"></i>
2023-11-09 10:16:18 +08:00
<i v-show="!childrenItem.openType" @click.stop="putName(childrenIndex,'put',childrenItem)" class="fi fi-rr-edit"></i>
</li>
2023-11-09 16:55:20 +08:00
<li class="newLabel setLabel_text">
2023-11-09 10:16:18 +08:00
<input v-show="optionsItem.addOpenType" type="text" v-model="itemName">
<i @click.stop="putName(-1,'affirm',optionsItem)" v-show="optionsItem.addOpenType" class="fi fi-br-check"></i>
2023-11-13 09:52:57 +08:00
<div class="addLabel" v-show="!optionsItem.addOpenType" @click="newLabel(optionsItem,optionsItem.id)">+</div>
2023-11-09 10:16:18 +08:00
</li>
2023-11-08 13:01:45 +08:00
</ul>
</li>
2023-11-09 16:55:20 +08:00
<li class="newLabel setLabel_text optionsItem_title">
2023-11-13 09:52:57 +08:00
<div>
<input v-show="openType" type="text" v-model="itemName">
<i @click.stop="putName(-1,'affirm','')" v-show="openType" class="fi fi-br-check"></i>
<div class="addLabel" v-show="!openType" @click="newLabel('','')">+</div>
</div>
<div class="started_btn" @click="removeLabel(options)">删除</div>
2023-11-09 10:16:18 +08:00
</li>
2023-11-08 09:31:40 +08:00
</ul>
</div>
2023-11-07 09:30:25 +08:00
</a-modal>
</template>
<script lang="ts">
2023-11-09 10:16:18 +08:00
import { defineComponent,ref,createVNode,watch,nextTick,inject} from 'vue'
2023-11-07 09:30:25 +08:00
import { Https } from "@/tool/https";
import {dataURLtoFile,base64toFile} from "@/tool/util"
import { getCookie } from "@/tool/cookie";
import 'vue-cropper/dist/index.css'
import { VueCropper } from "vue-cropper";
import { useStore } from "vuex";
import { useI18n } from 'vue-i18n';
import { Modal,message,Upload,CascaderProps } from 'ant-design-vue';
export default defineComponent({
components:{
VueCropper,
},
setup() {
let multiple = ref(false)
2023-11-08 13:01:45 +08:00
let indeterminate = ref(true)
2023-11-09 13:49:10 +08:00
let options:any = ref([])//父组件传过来的数据
2023-11-09 10:16:18 +08:00
let type:any = inject('type')//父组件传过来的数据
2023-11-08 13:01:45 +08:00
let checkedList = ref([])
2023-11-09 10:16:18 +08:00
let openType = ref(false)
let itemName = ref('')
2023-11-07 09:30:25 +08:00
let {t} = useI18n()
return {
multiple,
2023-11-08 13:01:45 +08:00
indeterminate,
2023-11-07 09:30:25 +08:00
value: ref<string[]>([]),
options,
2023-11-08 13:01:45 +08:00
checkedList,
2023-11-09 10:16:18 +08:00
openType,
type,
itemName,
2023-11-07 09:30:25 +08:00
t
}
},
data(){
return{
setLabelShow:false,
}
},
mounted(){
},
watch: {
2023-11-08 13:01:45 +08:00
2023-11-07 09:30:25 +08:00
},
2023-11-09 10:16:18 +08:00
directives:{
mousewheel:{
mounted (el) {
2023-11-09 16:55:20 +08:00
let bodyDom:any = document.getElementsByClassName('setLabel_centent')[0]
2023-11-09 10:16:18 +08:00
nextTick().then(()=>{
2023-11-09 16:55:20 +08:00
let domParent:any = document.getElementsByClassName('childrenItem')
let mouseover = (event:any)=>{
event.stopPropagation()
2023-11-09 10:16:18 +08:00
bodyDom.classList.add('active')
}
2023-11-09 16:55:20 +08:00
let mouseleave = (event:any)=>{
event.stopPropagation()
2023-11-09 10:16:18 +08:00
bodyDom.classList.remove('active')
}
for (let index = 0; index < domParent.length; index++) {
2023-11-09 16:55:20 +08:00
domParent[index].addEventListener('mouseover',mouseover,false)
domParent[index].addEventListener('mouseleave',mouseleave,false)
2023-11-09 10:16:18 +08:00
}
el.addEventListener('wheel',(e:WheelEvent)=>{
let num = 0
if(e.deltaY > 0){
num = 25
}else{
num = -25
}
el.scrollBy(num, 0);
},true)
})
}
}
},
2023-11-07 09:30:25 +08:00
methods:{
2023-11-09 13:49:10 +08:00
init(str:any,data:any){
2023-11-07 09:30:25 +08:00
this.setLabelShow = true
if(str === 'add'){
this.multiple = false
}else{
this.multiple = true
}
2023-11-09 13:49:10 +08:00
this.clearOpenType()
this.options = data
2023-11-07 09:30:25 +08:00
},
clearSetLabel(){
2023-11-09 13:49:10 +08:00
this.clearOpenType()
2023-11-09 16:55:20 +08:00
let parent:any = this.$parent
parent.getClass()
2023-11-08 13:01:45 +08:00
},
2023-11-09 10:16:18 +08:00
onCheckAllChange(value:any){
2023-11-09 13:49:10 +08:00
if(value?.childList){
value?.childList.forEach((item:any) => {
item.checkAll = value.checkAll
});
}
},
onCheckAllchildrenItem(value:any){
let boor = value?.childList.every( (item:any) => item.checkAll )
if(boor){
value.checkAll = true
}else{
value.checkAll = false
}
},
clearOpenType(){
this.options.forEach((optionsItem:any) => {
optionsItem.openType = false
optionsItem.addOpenType = false
if(optionsItem?.children){
optionsItem?.children?.forEach((childrenItem:any) => {
childrenItem.openType = false
});
}
2023-11-09 10:16:18 +08:00
});
2023-11-09 13:49:10 +08:00
this.openType = false
2023-11-09 10:16:18 +08:00
},
putName(index:number,v:string,item:any){
2023-11-09 13:49:10 +08:00
let data:any
2023-11-09 10:16:18 +08:00
if(v == 'put'){
2023-11-09 13:49:10 +08:00
this.clearOpenType()
2023-11-09 10:16:18 +08:00
item.openType = true
2023-11-09 13:49:10 +08:00
this.itemName = item.classificationName
2023-11-09 10:16:18 +08:00
// this.options[index].openType = true
// this.itemName = this.workspace.workspaceList[index].workSpaceName
}else if(v == 'affirm'){
if(index == -1){
if(this.itemName == ''){
message.warning(this.t('Habit.jsContent2'));
}else{
2023-11-09 13:49:10 +08:00
2023-11-09 10:16:18 +08:00
if(item){
item.addOpenType = false
2023-11-09 13:49:10 +08:00
data = {
classificationName:this.itemName,
parentId:item.id
}
2023-11-09 10:16:18 +08:00
}else{
this.openType = false
2023-11-09 13:49:10 +08:00
data = {
classificationName:this.itemName,
parentId:''
}
2023-11-09 10:16:18 +08:00
}
}
}else{
2023-11-09 13:49:10 +08:00
data = {
id:item.id,
classificationName:this.itemName,
}
item.classificationName = this.itemName
2023-11-09 10:16:18 +08:00
item.openType = false
}
2023-11-09 13:49:10 +08:00
this.addLabel(data)
2023-11-09 10:16:18 +08:00
}
},
2023-11-09 13:49:10 +08:00
newLabel(item:any,id:any){
this.itemName = ''
this.clearOpenType()
2023-11-09 10:16:18 +08:00
2023-11-09 13:49:10 +08:00
if(item){
item.addOpenType = true
}else{
this.openType = true
}
},
removeLabel(val:any){
2023-11-09 16:55:20 +08:00
let data = {
"classificationIdList": [],
"deleteConfirm": 0,
}
let classificationIdList:any = []
2023-11-09 13:49:10 +08:00
this.clearOpenType()
val.forEach((optionsItem:any) => {
if(optionsItem.checkAll){
2023-11-09 16:55:20 +08:00
classificationIdList.push(optionsItem.id)
2023-11-09 10:16:18 +08:00
}else{
2023-11-09 13:49:10 +08:00
if(optionsItem.childList){
optionsItem.childList.forEach((childrenItem:any) => {
if(childrenItem.checkAll){
2023-11-09 16:55:20 +08:00
classificationIdList.push(childrenItem.id)
2023-11-09 13:49:10 +08:00
}
});
}
2023-11-09 10:16:18 +08:00
}
2023-11-09 13:49:10 +08:00
});
2023-11-09 16:55:20 +08:00
data.classificationIdList = classificationIdList
2023-11-09 13:49:10 +08:00
this.deleteClass(data)
2023-11-09 10:16:18 +08:00
},
2023-11-09 13:49:10 +08:00
addLabel(val:any){
2023-11-09 10:16:18 +08:00
let data = this.setLabelData()
2023-11-09 13:49:10 +08:00
if(val.parentId){//新增
data.parentId = val.parentId
}
if(val.id){//修改
data.id = val.id
}
data.classificationName = val.classificationName
2023-11-09 10:16:18 +08:00
Https.axiosPost(Https.httpUrls.saveOrUpdate, data).then(
(rv: any) => {
2023-11-09 13:49:10 +08:00
this.getClass()
2023-11-09 10:16:18 +08:00
}
).catch((res)=>{
2023-11-09 13:49:10 +08:00
});
},
deleteClass(data:any){
Https.axiosPost(Https.httpUrls.classificationDelete, data).then(
(rv: any) => {
2023-11-09 16:55:20 +08:00
this.getClass()
2023-11-09 13:49:10 +08:00
}
).catch((res)=>{
});
},
getClass(){
let data = this.setLabelData()
Https.axiosPost(Https.httpUrls.queryClassification, data).then(
(rv: any) => {
this.options = rv
}
).catch((res)=>{
2023-11-09 10:16:18 +08:00
});
},
setLabelData(){
let data = {
"classificationIdList": [],
"classificationName": "123221",
"createTime": "",
"deleteConfirm": '',
"id": '',
"libraryId": '',
"parentId": '',
"type": this.type?.selectCode._value,
"updateTime": "",
"userId": ''
}
return data
}
2023-11-07 09:30:25 +08:00
}
})
</script>
<style lang="less">
.library_setLabel{
2023-11-08 13:01:45 +08:00
.setLabel_centent{
display: flex;
flex-direction: column;
2023-11-09 10:16:18 +08:00
// height: 300px;
max-height: 65rem;
overflow-y: auto;
// border-radius: ;
2023-11-13 09:52:57 +08:00
position: relative;
2023-11-10 10:56:18 +08:00
&.setLabel_centent::-webkit-scrollbar{display: none;}
2023-11-09 16:55:20 +08:00
&.active{
overflow: hidden;
}
2023-11-13 09:52:57 +08:00
2023-11-08 13:01:45 +08:00
ul{
display: flex;
li{
width: 100%;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
2023-11-09 10:16:18 +08:00
i{
cursor: pointer;
}
input{
border: 0;
width: 80%;
background: rgba(0,0,0,0);
}
2023-11-13 09:52:57 +08:00
2023-11-09 10:16:18 +08:00
}
.setLabel_text{
display: flex;
flex-direction: row;
align-items: center;
2023-11-09 16:55:20 +08:00
padding: .5rem 1rem;
width: 16rem;
2023-11-13 09:52:57 +08:00
margin: 2rem 2rem;
2023-11-09 16:55:20 +08:00
border-radius: 1rem;
2023-11-09 10:16:18 +08:00
justify-content: space-between;
flex-shrink: 0;
2023-11-13 09:52:57 +08:00
font-size: 1.8rem;
font-weight: 900;
2023-11-09 10:16:18 +08:00
i{
display: flex;
}
2023-11-13 09:52:57 +08:00
>span{
max-width: 60%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
2023-11-09 10:16:18 +08:00
}
2023-11-13 09:52:57 +08:00
2023-11-09 10:16:18 +08:00
}
.optionsItem{
flex-direction: column;
2023-11-13 09:52:57 +08:00
padding: 1rem;
2023-11-09 16:55:20 +08:00
.optionsItem_title{
2023-11-13 09:52:57 +08:00
margin-bottom: 2rem;
2023-11-09 16:55:20 +08:00
border-radius: 1rem;
2023-11-13 09:52:57 +08:00
align-items: flex-start;
background-color: #f9f9f9;
border: 0.1rem solid #ebebeb;
2023-11-09 16:55:20 +08:00
// border-bottom: 2px solid rgba(0,0,0,.2);
2023-11-13 09:52:57 +08:00
box-shadow: 0px 0px 5px 0px rgba(0,0,0,.3);
2023-11-09 10:16:18 +08:00
>label{
align-items: center;
}
.childrenItem{
max-width: 100%;
overflow: hidden;
overflow-x: auto;
2023-11-13 09:52:57 +08:00
// padding-bottom: 2rem;
.setLabel_text{
font-weight: 300;
margin: 1rem 1rem;
background: #f0f0f0;
// background: #d5d5d5;
font-size: 1.4rem;
label{
transform: scale(.8);
}
.fi-rr-edit{
opacity: 0;
transition: .3s all;
}
}
.setLabel_text:hover{
// background: #efefef;
.fi-rr-edit{
opacity: 1;
}
}
2023-11-09 10:16:18 +08:00
&.active::-webkit-scrollbar-button:single-button{
display: none;
}
&.active::-webkit-scrollbar {
/* 竖轴的宽度 */
width: 1rem;
/* 横轴的高度 */
height: 1rem;
transition: all .3s;
}
/* 进度 */
&.active::-webkit-scrollbar-thumb {
border-radius: 1rem;
background: rgba(238, 238, 244, 0);
}
/* 轨道 */
&.active::-webkit-scrollbar-track {
border-radius: 1rem;
background: rgba(238, 238, 244, 0);
}
&.active:hover {
// overflow-x: scroll;
&.active::-webkit-scrollbar-thumb {
background: #543087;
}
/* 轨道 */
&.active::-webkit-scrollbar-track {
background: rgba(84, 48, 135,.2);
}
}
}
}
.newLabel{
text-align: center;
justify-content: center;
2023-11-09 16:55:20 +08:00
&.optionsItem_title{
width: 100%;
margin: 0;
2023-11-13 09:52:57 +08:00
justify-content: space-around;
border: none;
background: none;
position: sticky;
background: #fff;
border: none;
>div{
}
.started_btn{
width: auto;
position: sticky;
top: 0;
z-index: 999;
// margin-right: auto;
}
}
>div{
display: flex;
width: 16rem;
display: flex;
align-items: center;
justify-content: center;
2023-11-09 16:55:20 +08:00
}
2023-11-13 09:52:57 +08:00
.addLabel{
2023-11-09 10:16:18 +08:00
border-radius: 50%;
border: 1px solid #000;
display: inline-block;
width: 2rem;
height: 2rem;
line-height: 2rem;
text-align: center;
2023-11-09 16:55:20 +08:00
cursor: pointer;
2023-11-09 10:16:18 +08:00
}
i{
cursor: pointer;
}
2023-11-08 13:01:45 +08:00
}
}
}
2023-11-07 09:30:25 +08:00
}
</style>