index.vue 20 KB

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