NewInputBar.vue 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <template>
  2. <el-autocomplete placeholder="请输入实体"
  3. v-model="newModel.id"
  4. class="input-with-select topological-analysis-input"
  5. :fetch-suggestions="querySearchAsync"
  6. :trigger-on-focus="false"
  7. @select="handleSelect"
  8. @keyup.enter.native="onNew">
  9. <template slot="prepend">
  10. <span class="el-icon-place"></span>
  11. </template>
  12. <el-button slot="append" @click="onNew">
  13. <span class="el-icon-circle-plus-outline" style="font-size:16px;font-weight:600;color:green;"></span>
  14. </el-button>
  15. </el-autocomplete>
  16. </template>
  17. <script>
  18. import _ from 'lodash';
  19. export default {
  20. name: "NewInputBar",
  21. data(){
  22. return {
  23. newModel: {
  24. id: "",
  25. value: ""
  26. },
  27. entity: {
  28. list: [],
  29. timeout: null
  30. }
  31. }
  32. },
  33. methods:{
  34. onNew(){
  35. const self = this;
  36. let id = this.newModel.id && this.newModel.id.trim()
  37. if (!id) {
  38. return;
  39. }
  40. self.$parent.$parent.$parent.trace.nodes.push({
  41. id: this.newModel.id,
  42. cell: {edge:false}
  43. })
  44. this.newModel.id = "";
  45. },
  46. querySearchAsync(term, cb) {
  47. if(_.isEmpty(term)){
  48. return false;
  49. }
  50. this.m3.callFS("/matrix/graph/entity-search-by-term.js",encodeURIComponent(term)).then(res=>{
  51. let entitys = res.message;
  52. let results = term ? entitys.filter(this.createStateFilter(term)) : entitys;
  53. clearTimeout(this.entity.timeout);
  54. this.entity.timeout = setTimeout(() => {
  55. cb(results);
  56. }, 50 * Math.random());
  57. })
  58. },
  59. createStateFilter(term) {
  60. return (state) => {
  61. return (state.value.toLowerCase().indexOf(term.toLowerCase()) === 0);
  62. };
  63. },
  64. handleSelect(item) {
  65. this.onNew();
  66. }
  67. }
  68. }
  69. </script>