PipeSelect.vue 4.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
<!--
 * @Author: your name
 * @Date: 2022-01-26 10:52:10
 * @LastEditTime: 2022-02-17 10:11:35
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: /test/hello-world/src/components/PipeColor.vue
-->
<template>
  <div>
    <div class="pipePressure"  :style="{ pointerEvents: dynamicPointerEvents }">
      <div class="container" id="div1">
          <div class="searchbar1">
              <form> 
                <table>
                <li v-for="data in newDatalist" :key="data.id" @click="goPage(data)">
                    {{data.pipeName}}
                </li>
                </table> 
              </form>
          </div>
      </div>
      <div class="input-group">
        <input class="input-field" type="text" v-model="inputText" placeholder="请输入管道名称...">
        <button class="close"  @click="handleClick">&times;</button>
      </div>
    </div>
  </div>
</template>

<script> 
import {
  getPipeForSelect
} from "@/api/bigWindow/getDevice";
export default {
  data(){
    return{
      downIcon: true,
      inputText:"",
      datalist:[],	//原始数据
      newDatalist:[],
      rowsToShow: 3, // 默认显示的行数
      maxRows: 6, // 最多显示的行数
      dynamicPointerEvents: 'none',
      }
    },
    created(){
      this.fetchData();
    },
    methods: {
      fetchData(){
        getPipeForSelect().then((res) => {
          if (res.data){
            this.datalist = res.data
          }
        })
      },
       goPage:function(data){
        var path = data.path.replaceAll("[[","").replaceAll("]]","").replaceAll("],["," ");
        var id = data.pipeId;
        let arrArea = path.split(" ")
        let centerLength = null;
        if (arrArea.length % 2 == 0) {
          centerLength = arrArea.length / 2;
        } else {
          centerLength = (arrArea.length + 1) /2;
        }
        if (centerLength != null) {
        this.$emit('transmit', arrArea[centerLength],id)
        } else {
          alert("数据异常")
        }
      },
      handleClick(){
        this.newDatalist=[];
        this.inputText = "";
        this.$emit('closeMediumPressureLine');
      }
    },
    watch:{//监听输入框的变化
          inputText:function(newText){
              this.dynamicPointerEvents = newText ? 'auto' : 'none';

              if(newText.length>0){
                  this.newDatalist.splice(0,this.newDatalist.length);//清空之前数组
                  for(let value of this.datalist){
                      if(value.pipeName.indexOf(newText)>-1){// 可以直接用indexOf(属性)
                          this.newDatalist.push(value);//一定要加this
                      }
                  }
              }else{
                  this.newDatalist=[];//输入框为空,等于原始数据
              }
          }
      },
};
</script>

<style lang="scss" scoped>

.pipePressure {
  width: 210px;
  height: auto;
  position: fixed;
  color: rgb(205, 219, 228);
  left: 660px;
  bottom: 50px;
  padding: 5px;
} 
form {
    position: relative;
    width: 300px;
    margin: 0 auto;
}
input {
    width: 100%;
    height: 42px;
    padding-left: 13px;
} 
.pipePressure input {
    border: 2px solid #7BA7AB;
    border-radius: 5px;
    background: #f9f0da1f;
    color: #9E9C9C;
}
li{
    text-align: left;
    width:100%;
    background: #f9f0da0c;
    list-style: none;
}
        
.container {
    height: 150px;
    overflow-y: auto;
    overflow-x: hidden;
    display:flex;
    flex-direction: column-reverse;
}

.input-group {
  position: relative;
  display: inline-block;
  pointer-events: auto;
}

.input-field {
  padding-right: 40px; /* Make space for the button */
  width: 200px; /* Adjust width as needed */
}

.close {
  font-size: 18px;
  font-weight: bold;
  color: #000;
  text-shadow: 0 1px 0 #fff;
  opacity: 0.5;
  float: right;
  margin-left: 10px;
  cursor: pointer;

  position: absolute;
  top: 0;
  right: 0;
  height: 100%; /* Match height with input */
  width: 40px; /* Adjust width as needed */
}
 
.close:hover {
  opacity: 1;
}

</style>