index.vue 20 KB

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