index.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. <template>
  2. <div id="addRelation">
  3. <!-- 数据字典对象类型 -->
  4. <el-row style="margin-bottom:16px;">
  5. <el-col :span="12">
  6. <el-button size="small" type="default" icon="el-icon-back" @click="goback"></el-button>
  7. <!-- <div style="display:inline-block;width:345px;margin-left:10px;">
  8. <dictionary-device @change="changeDictionary" :Related="false" :typeName="typeName"></dictionary-device>
  9. </div> -->
  10. </el-col>
  11. <el-col :span="12" class="text-right">
  12. <el-switch @change="changeType" v-model="isSwitch"></el-switch>
  13. <span style="padding:0 5px;">AI辅助</span>
  14. <el-button size="medium" @click="showHistory" class="ani-his-plus">
  15. 本次对应记录 {{num}}
  16. <span v-if="showPlus" :class="{'plusOne':true,'startAni':showPlus}">+1</span>
  17. </el-button>
  18. </el-col>
  19. </el-row>
  20. <!-- 列表及查询条件区域 -->
  21. <div class="table-container clearfix">
  22. <div class="left-table">
  23. <h5>未对应的{{typeName}}标识</h5>
  24. <!-- 查询条件 -->
  25. <div class="query-box clearfix">
  26. <div class="query-item">
  27. <label>{{typeName}}标识关键字</label>
  28. <el-input :placeholder="`请输入${typeName}标识关键字`" v-model="form.EquipmentMark" @keyup.enter.native="queryLeftTable">
  29. <i slot="suffix" class="el-input__icon el-icon-search" @click="queryLeftTable"></i>
  30. </el-input>
  31. </div>
  32. <div class="query-item">
  33. <label>数据源</label>
  34. <dataSource :Related="false" @change="changeDataSource" :typeName="typeName"></dataSource>
  35. </div>
  36. <div class="query-item">
  37. <label>位置标签</label>
  38. <locationFlag :Related="false" @change="changeLocationFlag" :typeName="typeName"></locationFlag>
  39. </div>
  40. </div>
  41. <!-- 左侧列表 -->
  42. <div class="table-box">
  43. <div class="l-custom-table custom-table" v-loading="lTableLoading">
  44. <el-table ref="lTableBody" :data="LtableData" tooltip-effect="dark" style="width: 100%" height="100%" @row-click="clickLeftRow"
  45. @selection-change="leftSelectionChange">
  46. <el-table-column label="数据源" align="right" show-overflow-tooltip>
  47. <template slot-scope="scope">{{ scope.row.Datasource }}</template>
  48. </el-table-column>
  49. <el-table-column label="位置标签" align="right">
  50. <template slot-scope="scope">
  51. <el-tooltip :content="scope.row.LocationFlag.toString()" placement="top">
  52. <div class="tool-tip">{{scope.row.LocationFlag.toString()}}</div>
  53. </el-tooltip>
  54. </template>
  55. </el-table-column>
  56. <!-- <el-table-column prop="SubTypeName" :label="`${typeName}类型关键字`" align="right" show-overflow-tooltip></el-table-column> -->
  57. <el-table-column prop="EquipmentMark" :label="`${typeName}标识`" show-overflow-tooltip align="right" width="200" class-name="bgf5">
  58. </el-table-column>
  59. <el-table-column type="selection" width="35" class-name="bgf5"></el-table-column>
  60. </el-table>
  61. </div>
  62. <!-- 智能推荐 -->
  63. <transition name="el-zoom-in-top">
  64. <div class="AIRecom" v-show="leftRecoList.length&&leftAI&&rArray.length">
  65. <div class="l-title">
  66. 可能对应的{{typeName}}标识
  67. <i class="el-icon-close" @click="leftRecoList=[]"></i>
  68. </div>
  69. <div v-for="(t,i) in leftRecoList" :key="t.id" class="l-ai-recom-item ai-recom-item" @click="selectAI(i,'l')">
  70. <p>
  71. <el-checkbox v-model="t.checked"></el-checkbox>
  72. <span>{{(t.Proximity*100).toFixed(2)}}%</span>
  73. </p>
  74. <p>{{t.EquipmentMark&&t.EquipmentMark!='null'?t.EquipmentMark:''}}</p>
  75. <p>{{t.LocationFlag.toString()}}</p>
  76. <!-- <p>{{t.address}}</p> -->
  77. </div>
  78. </div>
  79. </transition>
  80. </div>
  81. </div>
  82. <div class="right-table" style="float: right;">
  83. <h5>未对应的{{typeName}}实例</h5>
  84. <!-- 查询条件 -->
  85. <div class="query-box clearfix">
  86. <div class="query-item">
  87. <label>{{typeName}}实例关键字</label>
  88. <el-input :placeholder="`请输入${typeName}实例关键字`" v-model="form.ObjectLocalName" @keyup.enter.native="queryRightTable">
  89. <i slot="suffix" class="el-input__icon el-icon-search" @click="queryRightTable"></i>
  90. </el-input>
  91. </div>
  92. <div class="query-item">
  93. <label>所属建筑</label>
  94. <location-cas @change="changeLocation" :Related="false" :typeName="typeName" :isFloor="true"></location-cas>
  95. </div>
  96. </div>
  97. <!-- 右侧列表 -->
  98. <div class="table-box">
  99. <div class="r-custom-table custom-table" v-loading="rTableLoading">
  100. <el-table ref="rTableBody" :data="RtableData" tooltip-effect="dark" style="width: 100%" height="100%" @row-click="clickRightRow"
  101. @selection-change="rightSelectionChange">
  102. <el-table-column type="selection" width="35" class-name="bgf5"></el-table-column>
  103. <el-table-column :label="`${typeName}实例名称`" width="200" class-name="bgf5" show-overflow-tooltip>
  104. <template slot-scope="scope">{{ scope.row.ObjectLocalName }}</template>
  105. </el-table-column>
  106. <el-table-column prop="ObjectLocalCode" :label="`${typeName}本地编码`" show-overflow-tooltip></el-table-column>
  107. <el-table-column :label="`${typeName}顺序号`" show-overflow-tooltip>
  108. <template slot-scope="scope">
  109. <el-tooltip :content="(scope.row.ObjectSequenceID&&scope.row.ObjectSequenceID!='null')?scope.row.ObjectSequenceID:''"
  110. placement="top">
  111. <div class="tool-tip">
  112. {{(scope.row.ObjectSequenceID&&scope.row.ObjectSequenceID!='null')?scope.row.ObjectSequenceID:''}}</div>
  113. </el-tooltip>
  114. </template>
  115. </el-table-column>
  116. <!-- <el-table-column prop="CascadeEquipLocalName" label="所属设备实例" show-overflow-tooltip></el-table-column> -->
  117. <el-table-column label="所在建筑">
  118. <template slot-scope="scope">
  119. <el-tooltip :content="scope.row.BuildLocalName?scope.row.BuildLocalName:''" placement="top">
  120. <div class="tool-tip">
  121. {{scope.row.BuildLocalName?scope.row.BuildLocalName:''}}</div>
  122. </el-tooltip>
  123. </template>
  124. </el-table-column>
  125. <!-- <el-table-column prop="RoomLocalName" label="所在业务空间" show-overflow-tooltip></el-table-column> -->
  126. </el-table>
  127. </div>
  128. <!-- 智能推荐 -->
  129. <transition name="el-zoom-in-top">
  130. <div class="AIRecom" v-show="rightRecoList.length&&!leftAI&&lArray.length">
  131. <div class="r-title">
  132. 可能对应的{{typeName}}实例
  133. <i class="el-icon-close" @click="rightRecoList=[]"></i>
  134. </div>
  135. <div v-for="(t,i) in rightRecoList" :key="t.id" class="r-ai-recom-item ai-recom-item" @click="selectAI(i,'r')">
  136. <p>
  137. <el-checkbox v-model="t.checked"></el-checkbox>
  138. <span>{{(t.Proximity*100).toFixed(2)}}%</span>
  139. </p>
  140. <p>{{t.ObjectLocalName}}</p>
  141. <p>
  142. {{t.BuildLocalName&&t.BuildLocalName!='null'&&t.FloorLocalName&&t.FloorLocalName!='null'?t.BuildLocalName+'-'+t.FloorLocalName:''}}
  143. </p>
  144. <p>{{t.RoomLocalName&&t.RoomLocalName!='null'?t.RoomLocalName:''}}</p>
  145. <p>{{t.InstallLocation&&t.InstallLocation!='null'?t.InstallLocation:''}}</p>
  146. </div>
  147. </div>
  148. </transition>
  149. </div>
  150. </div>
  151. </div>
  152. <!-- 历史记录弹窗 -->
  153. <history-dialog ref="history" @delSuc="deleteSuc" :typeName="'space'"></history-dialog>
  154. </div>
  155. </template>
  156. <script>
  157. import tools from "@/utils/tools";
  158. import historyDialog from "@/components/point/dynamicdata/historyDialog";
  159. import locationCas from "@/components/point/dynamicdata/locationCascader";
  160. import dictionaryDevice from "@/components/point/dynamicdata/dictionaryDevice";
  161. import dataSource from "@/components/point/dynamicdata/dataSource";
  162. import locationFlag from "@/components/point/dynamicdata/locationFlag";
  163. import { mapGetters, mapActions } from "vuex";
  164. import {
  165. dynamicPendingobjs,
  166. dynamicPendingPoint,
  167. dynamicCreateRelation,
  168. dynamicDeleteRelation,
  169. dynamicPointTypeList,
  170. dynamicQueryAI
  171. } from "@/api/scan/request";
  172. export default {
  173. components: {
  174. historyDialog,
  175. locationCas,
  176. dictionaryDevice,
  177. dataSource,
  178. locationFlag
  179. },
  180. data() {
  181. return {
  182. isSwitch: true, //AI辅助
  183. typeName: "", //当前类型
  184. LtableData: [], //列表数据
  185. RtableData: [], //列表数据
  186. form: {
  187. EquipmentMark: "", //部件标识关键字
  188. SubTypeName: [], //数据字典部件类型
  189. LocationFlag: [], //位置标签
  190. Datasource: [], //数据源
  191. ObjectLocalName: "", //部件实例关键字
  192. locationVal: [] //所在位置下拉
  193. }, //查询条件
  194. leftRecoList: [], //左推荐
  195. rightRecoList: [], //右推荐
  196. leftAI: true, //左右推荐公用-互斥
  197. lArray: [], //左侧选中数据
  198. rArray: [], //右侧选中数据
  199. hasRequestedFlag: false, //用于标识是否关联过数据,若是则重新请求第一页数据,
  200. showPlus: false, //+1记录动画
  201. num: 0, //记录条数
  202. timer: null, //函数节流 延时器
  203. historyList: [], //操作历史
  204. lTableLoading: false, //loading
  205. rTableLoading: false,
  206. lPage: {
  207. pageNumber: 1,
  208. pageSize: 50,
  209. total: 0
  210. },
  211. rPage: {
  212. pageNumber: 1,
  213. pageSize: 50,
  214. total: 0
  215. }
  216. };
  217. },
  218. created() {
  219. this.typeName = this.$route.query.typeName;
  220. this.init();
  221. },
  222. mounted() {
  223. this.lTableBody = this.$refs.lTableBody.bodyWrapper;
  224. this.rTableBody = this.$refs.rTableBody.bodyWrapper;
  225. this.lTableBody.addEventListener("scroll", () => {
  226. // 滚动距离
  227. let scrollTop = this.lTableBody.scrollTop;
  228. // 变量windowHeight是可视区的高度
  229. let windowHeight =
  230. this.lTableBody.clientHeight || this.lTableBody.clientHeight;
  231. // 变量scrollHeight是滚动条的总高度
  232. let scrollHeight =
  233. this.lTableBody.scrollHeight || this.lTableBody.scrollHeight;
  234. if (scrollTop + windowHeight === scrollHeight) {
  235. if (this.lPage.pageNumber * this.lPage.pageSize < this.lPage.total) {
  236. this.lPage.pageNumber++;
  237. if (this.LtableData.length < 50) {
  238. this.lPage.pageNumber = 1
  239. }
  240. this.getLeftData();
  241. }
  242. }
  243. });
  244. this.rTableBody.addEventListener("scroll", () => {
  245. // 滚动距离
  246. let scrollTop = this.rTableBody.scrollTop;
  247. // 变量windowHeight是可视区的高度
  248. let windowHeight =
  249. this.rTableBody.clientHeight || this.rTableBody.clientHeight;
  250. // 变量scrollHeight是滚动条的总高度
  251. let scrollHeight =
  252. this.rTableBody.scrollHeight || this.rTableBody.scrollHeight;
  253. if (scrollTop + windowHeight === scrollHeight) {
  254. // 获取到的不是全部数据 当滚动到底部 继续获取新的数据
  255. if (this.rPage.pageNumber * this.rPage.pageSize < this.rPage.total) {
  256. this.rPage.pageNumber++;
  257. if (this.RtableData.length < 50) {
  258. this.rPage.pageNumber = 1
  259. }
  260. this.getRightData();
  261. }
  262. }
  263. });
  264. },
  265. computed: {
  266. ...mapGetters("layout", ["projectId"]),
  267. requestFlag() {
  268. return this.lArray.length > 0 && this.rArray.length > 0;
  269. }
  270. },
  271. methods: {
  272. init() {
  273. this.queryLeftTable();
  274. this.queryRightTable();
  275. },
  276. //切换AI辅助
  277. changeType() { },
  278. //推荐中的选择事件
  279. selectAI(i, l) {
  280. //i 索引 l 左侧AI or 右侧AI
  281. if (l == "l") {
  282. this.leftRecoList[i].checked = true;
  283. this.lArray = [];
  284. this.lArray.push(this.leftRecoList[i]);
  285. } else {
  286. this.rightRecoList[i].checked = true;
  287. this.rArray = [];
  288. this.rArray.push(this.rightRecoList[i]);
  289. }
  290. },
  291. //查看本次历史记录
  292. showHistory() {
  293. this.$refs.history.showDialog(this.historyList);
  294. },
  295. //重新获取数据
  296. reGetData() {
  297. //删除选中项
  298. this.delSelectedRows(this.lArray, this.rArray);
  299. let history = { leftList: this.lArray, rightList: this.rArray };
  300. this.historyList.push(history); //保存本次操作记录
  301. this.lArray = []; //清空选中list
  302. this.rArray = [];
  303. this.num++; //右上角操作记录
  304. this.showPlus = true;
  305. setTimeout(() => {
  306. this.showPlus = false;
  307. }, 800);
  308. },
  309. //少于20条请求数据-否则删除选中项
  310. delSelectedRows(lArray, rArray) {
  311. for (let li = this.LtableData.length - 1; li >= 0; li--) {
  312. for (let lj = 0; lj < lArray.length; lj++) {
  313. if (this.LtableData[li] && (this.LtableData[li].EquipmentMark == lArray[lj].EquipmentMark && this.LtableData[li].SubTypeCode == lArray[lj].SubTypeCode)) {
  314. // this.LtableData.splice(i, 1)
  315. delete this.LtableData[li]
  316. continue; //结束当前本轮循环,开始新的一轮循环
  317. }
  318. }
  319. }
  320. this.LtableData = this.LtableData.filter(item => {
  321. return !(item == 'undefined')
  322. })
  323. for (let ri = this.RtableData.length - 1; ri >= 0; ri--) {
  324. for (let rj = 0; rj < rArray.length; rj++) {
  325. if (this.RtableData[ri] && (this.RtableData[ri].ObjectID == rArray[rj].ObjectID && this.RtableData[ri].SubTypeCode == rArray[rj].SubTypeCode)) {
  326. // this.RtableData.splice(i, 1)
  327. delete this.RtableData[ri]
  328. continue; //结束当前本轮循环,开始新的一轮循环
  329. }
  330. }
  331. }
  332. this.RtableData = this.RtableData.filter(item => {
  333. return !(item == 'undefined')
  334. })
  335. if (this.LtableData.length < 20 && this.lPage.Total > 49) {
  336. this.queryLeftTable()
  337. }
  338. if (this.RtableData.length < 20 && this.rPage.Total > 49) {
  339. this.queryRightTable()
  340. }
  341. },
  342. //表格中的选中事件
  343. leftSelectionChange(selection) {
  344. this.lArray = selection;
  345. },
  346. rightSelectionChange(selection) {
  347. this.rArray = selection;
  348. },
  349. //查询左侧列表
  350. queryLeftTable() {
  351. this.lPage.pageNumber = 1;
  352. if (this.$refs.lTableBody && this.$refs.lTableBody.bodyWrapper) {
  353. this.$refs.lTableBody.bodyWrapper.scrollTop = 0
  354. }
  355. this.getLeftData();
  356. },
  357. //查询右侧列表
  358. queryRightTable() {
  359. this.rPage.pageNumber = 1;
  360. if (this.$refs.rTableBody && this.$refs.rTableBody.bodyWrapper) {
  361. this.$refs.rTableBody.bodyWrapper.scrollTop = 0
  362. }
  363. this.getRightData();
  364. },
  365. //获取待关联点位-左侧
  366. getLeftData() {
  367. let param = {
  368. PageNumber: this.lPage.pageNumber,
  369. PageSize: this.lPage.pageSize,
  370. TypeNameList: [this.typeName]
  371. };
  372. //处理查询条件(目前只是单个查,需后台支持)
  373. if (this.form.EquipmentMark && this.form.EquipmentMark.length) {
  374. param.EquipmentMark = this.form.EquipmentMark;
  375. }
  376. if (this.form.SubTypeName.length) {
  377. param.SubTypeNameList = this.form.SubTypeName;
  378. }
  379. if (this.form.LocationFlag.length) {
  380. param.LocationFlagList = this.form.LocationFlag;
  381. }
  382. if (this.form.Datasource.length) {
  383. param.DatasourceList = this.form.Datasource;
  384. }
  385. this.lTableLoading = true;
  386. dynamicPendingPoint(param, res => {
  387. this.lPage.total = res.PageSize < 50 ? res.PageSize : res.Total;
  388. if (this.lPage.pageNumber == 1) {
  389. this.LtableData = res.Content;
  390. } else {
  391. this.LtableData = this.LtableData.concat(res.Content);
  392. }
  393. this.lTableLoading = false;
  394. });
  395. },
  396. //获取待关联实例-右侧
  397. getRightData() {
  398. let param = {
  399. PageNumber: this.rPage.pageNumber,
  400. PageSize: this.rPage.pageSize,
  401. TypeNameList: [this.typeName]
  402. };
  403. //处理查询条件
  404. if (this.form.ObjectLocalName && this.form.ObjectLocalName.length) {
  405. param.ObjectLocalName = this.form.ObjectLocalName;
  406. }
  407. if (this.form.SubTypeName.length) {
  408. param.SubTypeNameList = this.form.SubTypeName;
  409. }
  410. if (this.form.locationVal.length > 0) {
  411. param.BuildLocalName = this.form.locationVal[0];
  412. }
  413. if (this.form.locationVal.length > 1) {
  414. param.FloorLocalName = this.form.locationVal[1];
  415. }
  416. if (this.form.locationVal.length > 2) {
  417. param.SpaceType = this.form.locationVal[2];
  418. }
  419. if (this.form.locationVal.length > 3) {
  420. param.RoomLocalName = this.form.locationVal[3];
  421. }
  422. if (!this.form.locationVal.length) {
  423. delete param.BuildLocalName
  424. delete param.FloorLocalName
  425. delete param.SpaceType
  426. delete param.RoomLocalName
  427. }
  428. this.rTableLoading = true;
  429. dynamicPendingobjs(param, res => {
  430. this.rPage.total = res.PageSize < 50 ? res.PageSize : res.Total;
  431. if (this.rPage.pageNumber == 1) {
  432. this.RtableData = res.Content;
  433. } else {
  434. this.RtableData = this.RtableData.concat(res.Content);
  435. }
  436. this.rTableLoading = false;
  437. });
  438. },
  439. //清除对应关系成功
  440. deleteSuc() {
  441. this.num--;
  442. this.queryLeftTable();
  443. this.queryRightTable();
  444. },
  445. //所在位置修改
  446. changeLocation(val) {
  447. this.form.locationVal = val;
  448. this.queryRightTable();
  449. },
  450. //数据字典部件类型修改
  451. changeDictionary(val) {
  452. this.form.SubTypeName = val;
  453. this.queryLeftTable();
  454. this.queryRightTable();
  455. },
  456. //数据源修改
  457. changeDataSource(val) {
  458. this.form.Datasource = val;
  459. this.queryLeftTable();
  460. },
  461. //修改位置标签
  462. changeLocationFlag(val) {
  463. this.form.LocationFlag = val;
  464. this.queryLeftTable();
  465. },
  466. //返回
  467. goback() {
  468. this.$router.push({ path: '/point/dynamicdata', query: { typeName: this.typeName } })
  469. },
  470. //点击行
  471. clickLeftRow(row, column, event) {
  472. this.$refs.lTableBody.toggleRowSelection(row);
  473. },
  474. //点击行
  475. clickRightRow(row, column, event) {
  476. this.$refs.rTableBody.toggleRowSelection(row);
  477. },
  478. },
  479. watch: {
  480. projectId(n, o) {
  481. this.init();
  482. },
  483. //判断两边是否均有选中值-创建关联
  484. requestFlag(n, o) {
  485. if (n) {
  486. this.rightRecoList = [];
  487. this.leftRecoList = [];
  488. let object = {
  489. Objs: this.rArray,
  490. Points: this.lArray
  491. };
  492. let param = [];
  493. param.push(object);
  494. setTimeout(() => {
  495. this.reGetData();
  496. }, 200)
  497. dynamicCreateRelation(param, res => {
  498. if (res.Result == "success") {
  499. this.$message.success("关联成功");
  500. }
  501. });
  502. }
  503. },
  504. //AI辅助-左侧
  505. lArray(n, o) {
  506. //先清空,返回结果后赋值
  507. this.rightRecoList = [];
  508. clearTimeout(this.timer);
  509. if (this.isSwitch && n.length) {
  510. this.timer = setTimeout(() => {
  511. let param = []
  512. n.map(item => {
  513. param.push({
  514. Points: [item],
  515. Top: 3,
  516. Proximity: 0.5
  517. })
  518. })
  519. dynamicQueryAI(param, res => {
  520. this.rightRecoList = res.Content[0].Objs;
  521. this.leftAI = !this.rightRecoList.length
  522. })
  523. }, 800)
  524. } else {
  525. this.rightRecoList = []
  526. this.leftAI = true;
  527. }
  528. },
  529. //AI辅助-右侧
  530. rArray(n, o) {
  531. this.leftRecoList = [];
  532. clearTimeout(this.timer);
  533. if (this.isSwitch && n.length) {
  534. this.timer = setTimeout(() => {
  535. let param = []
  536. n.map(item => {
  537. param.push({
  538. Objs: [item],
  539. Top: 3,
  540. Proximity: 0.5
  541. })
  542. })
  543. dynamicQueryAI(param, res => {
  544. this.leftRecoList = res.Content[0].Points;
  545. this.leftAI = !!this.leftRecoList.length
  546. })
  547. }, 800)
  548. } else {
  549. this.leftRecoList = []
  550. this.leftAI = false
  551. }
  552. }
  553. }
  554. };
  555. </script>
  556. <style lang="scss" scoped>
  557. @import "../addRelationCommon.scss";
  558. </style>
  559. <style>
  560. body {
  561. overflow-y: hidden;
  562. }
  563. </style>