<template>
<el-drawer :title="packageData.title" :visible="packageData.visible" @open="openDialog" @close="closeDialog"
:append-to-body="true" direction="rtl" :size="560" destroy-on-close>
<div class="el-drawer__main" style="flex: 1; overflow-y: auto;">
<div class="form-head">
<div class="form-head-title">应用编辑</div>
<div>
<el-input placeholder="请输入应用名称" style="width:400px;" v-model="searchQuery" @keyup.enter.native="scrollToApp" clearable class="input-with-select">
<el-button slot="append" @click="scrollToApp" icon="el-icon-search"></el-button>
</el-input>
</div>
</div>
<draggable v-model="appLists" @end="onDragEnd">
<div v-for="(item, index) in appLists" :key="index" :ref="'appItem' + index">
<div class="app-edit" :class="{ 'highlight': isHighlighted(item) }">
<div class="app-edit-left">
<img :src="item.logoMediaid" alt="" style="width: 45px; height: 45px" />
<span style="padding-left: 10px; font-size: 14px">{{ item.name }}</span>
</div>
<div class="app-edit-right">
<i class="el-icon-error" @click.stop="handleRemove(index)" style="color: red;font-size:20px;"></i>
</div>
</div>
<el-divider></el-divider>
</div>
</draggable>
</div>
<div class="el-drawer__action" style="" v-if="!packageData.disabled">
<el-button @click="closeDialog"> 返回 </el-button>
</div>
</el-drawer>
</template>
<script>
import draggable from "vuedraggable";
import { getUserInfo } from "@/utils/auth";
export default {
name: 'GroupManagerEditDrawer',
props: {
packageData: {
type: Object,
default: () => {
}
},
visible: {
type: Boolean,
default: false
},
appList: {
type: Array,
default: () => []
},
appGroupIndex: {
type: Number,
default: 0
},
},
components: {
draggable
},
computed: {},
watch: {
appList(){
this.appLists=this.appList
}
},
data() {
return {
appLists:[],
searchQuery: '',
userId: getUserInfo().userId
}
},
created() {
},
mounted() {
this.appLists=this.appList
},
methods: {
onDragEnd() {
// 处理拖拽结束后的逻辑
// console.log('拖拽结束', this.appLists);
},
scrollToApp() {
const searchTerm = this.searchQuery.trim().toLowerCase();
if (searchTerm) {
// 遍历 appList,找到第一个匹配项
for (let index = 0; index < this.appLists.length; index++) {
const item = this.appLists[index];
if (item.name.toLowerCase() === searchTerm) {
// 滚动到对应的项
this.$nextTick(() => {
const appItem = this.$refs['appItem' + index][0];
console.log(appItem,123456)
if (appItem) {
appItem.scrollIntoView({ behavior: 'smooth', block: 'start' });
}
});
break; // 找到匹配项后退出循环
}
}
}
},
isHighlighted(item) {
return item.name.toLowerCase() === this.searchQuery.trim().toLowerCase();
},
// 关闭drawer
closeDialog() {
this.$emit('update:visible', false)
},
// 打开drawer
openDialog() {
},
// 删除巡检项
handleRemove(index) {
this.appLists.splice(index, 1)
this.$emit("changeApp", this.appLists, this.appGroupIndex)
},
}
}
</script>
<style lang="scss" scoped>
@import "~@style/_theme";
::v-deep .el-drawer .el-drawer__header {
// background: #fff;
background: #fff !important;
border-bottom: 1px solid #e9eaf2;
font-weight: 600;
}
.highlight {
background: yellow; /* 高亮背景色 */
}
.el-drawer__action {
display: flex;
justify-content: flex-end;
padding-top: 16px;
}
.form-head {
display: flex;
justify-content: space-between;
align-items: center;
border-left: 5px solid $colorPrimary;
padding-left: 6px;
margin-bottom: 20px;
.form-head-title {
font-size: 16px;
font-weight: 600;
}
.form-head-right {
font-size: 14px;
color: #427af4;
//styleName: 四级文字常规;
font-weight: 400;
line-height: 22px;
}
}
.context-work-item {
text-align: center;
float: left;
padding: 10px 10px;
width: 25%;
p {
&:nth-of-type(2) {
font-size: 15px;
}
}
}
.app-edit {
display: flex;
justify-content: space-between;
.app-edit-left {
display: flex;
align-items: center;
.app-edit-left-icon {
width: 40px;
height: 40px;
border-radius: 50%;
background: #ccc;
margin-right: 10px;
}
}
.app-edit-right {
display: flex;
align-items: center;
.sort-icon {
width: 20px;
color: #427af4;
font-size: 20px;
padding-right: 10px
}
.el-icon-error {
margin-left: 32px;
}
}
}
::v-deep .el-form-item__content {
display: flex;
}
</style>
<style>
.hide .el-upload--picture-card {
display: none;
}
</style>
实现效果如下: