step2.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. <template>
  2. <div id="handsonStep2">
  3. <div class="btns-view">
  4. <el-button style="width:164px" @click="aiDiscern">AI自动识别</el-button>
  5. <el-button @click="discern(1)">批量识别对象类型关键字</el-button>
  6. <el-button @click="discern(2)">批量识别对象参数关键字</el-button>
  7. <el-button style="width:164px" @click="examine">检查&微调</el-button>
  8. <div style="float:right;">
  9. <el-button @click="reset">刷新</el-button>
  10. <el-button @click="saveData">保存</el-button>
  11. </div>
  12. </div>
  13. <div id="handsontableSteps1" class="middle_sty" v-loading="isLoading">
  14. <handsontable-component v-if="!!pages.total" @delete="delePoint" @mouseDown="clickTable" @change="changeHand" ref="handsontable"></handsontable-component>
  15. <div v-else class="center">
  16. <i class="icon-wushuju iconfont"></i> 暂无数据
  17. </div>
  18. </div>
  19. <div class="right">
  20. <pagination :page="pages" @change="changePage"></pagination>
  21. </div>
  22. <own-dialog :width="'60%'" :title="title" :dialogVisible="isDialogShow" @cancel="close">
  23. <find-keyword ref="findKeyword" :type="type" @change="changeHand"></find-keyword>
  24. </own-dialog>
  25. <own-dialog :width="'1200px'" :index="true" title="关键内容设别——检查&微调" :dialogVisible="examineDialog" @cancel="close">
  26. <!-- <find-keyword ref="findKeyword" :type="type"></find-keyword> -->
  27. <examine-main></examine-main>
  28. </own-dialog>
  29. <!-- <own-dialog :width="'1000px'" :index="true" title="关键内容设别——检查&微调" :dialogVisible="examineDialog" @cancel="close"> -->
  30. <!-- <find-keyword ref="findKeyword" :type="type"></find-keyword> -->
  31. <!-- <examine-main></examine-main>
  32. </own-dialog> -->
  33. <own-dialog :width="'500px'" :index="true" title="位置标签" :dialogVisible="localtionDialog" @cancel="localFalgChange">
  34. <localtion-falg :renderData="renderData" @changeTag="changeLoc"></localtion-falg>
  35. </own-dialog>
  36. <own-dialog :width="'500px'" :footer="footer" :index="true" :escape="false" :isModel="false" title="AI自动识别" :dialogVisible="aiDialog" @confirm="isTrue" @cancel="aiClose">
  37. <!-- <localtion-falg :renderData="renderData" @changeTag="changeLoc"></localtion-falg> -->
  38. <div v-if="hadTrue" style="height: 100px;">
  39. <el-progress :text-inside="true" :stroke-width="18" :percentage="usedNum"></el-progress>
  40. <p v-if="content.Current != content.Sum" class="center">正在识别,请稍后……({{content.Current}}/{{content.Sum}})</p>
  41. <p v-else class="center" style="margin-top:10px;">目前已识别 <i class="el-button--text">{{content.DiscernCount}}</i> 个点位,识别率为 <i class="el-button--text">{{content.DiscernRate}}</i></p>
  42. </div>
  43. <div v-else>
  44. <p>确认要人工智能识别么?</p>
  45. </div>
  46. </own-dialog>
  47. </div>
  48. </template>
  49. <script>
  50. import tools from "@/utils/scan/tools"
  51. import handsontableComponent from "@/components/common/handsontable"
  52. import examineMain from "@/components/config_point/examine_main"
  53. import headerArr from "@/utils/point_edit/steps2.js"
  54. import localtionFalg from "@/components/config_point/location_flag"
  55. import {
  56. changeHeader,
  57. showTypes
  58. } from "@/utils/handsontable/delType"
  59. import ownDialog from "@/components/el_pack/dialog"
  60. import {
  61. mapGetters,
  62. mapActions
  63. } from "vuex";
  64. import {
  65. queryPoint,
  66. updatePoint,
  67. deletePoint,
  68. AIFindPoint,
  69. AIPlan
  70. } from "@/fetch/point_http"
  71. import findKeyword from "@/components/config_point/find_keyword"
  72. import pagination from "@/components/common/myPagination"
  73. export default {
  74. data() {
  75. return {
  76. checked: false,
  77. settings: {},
  78. copyMain: [],
  79. isDialogShow: false,
  80. msg: "",
  81. hot: null,
  82. title: "",
  83. type: "",
  84. examineDialog: false,
  85. changeFlag: true,
  86. pages: {
  87. size: 50,
  88. sizes: [10, 30, 50, 100, 150, 200],
  89. total: 0,
  90. currentPage: 0
  91. },
  92. oldPage: {
  93. currentPage: 0,
  94. size: 10
  95. },
  96. localtionDialog: false,
  97. renderData: {},
  98. isLoading: false,
  99. aiDialog: false,
  100. hadTrue: false,//是否确定人工智能升级
  101. usedNum: 0,//识别百分比
  102. footer:{},
  103. content: {
  104. Current: 1,//当前识别
  105. DiscernCount: 1,//已识别个数
  106. DiscernRate: 1,//识别比例
  107. Sum: 2,//总数
  108. }
  109. }
  110. },
  111. created() {
  112. if (!this.protocolType) {
  113. this.$router.push({
  114. path: "/configPoint"
  115. })
  116. }
  117. },
  118. mounted() {
  119. this.getData()
  120. },
  121. computed: {
  122. ...mapGetters("project", [
  123. "datasourceId",
  124. "protocolType"
  125. ]),
  126. projectId () {
  127. return this.$store.getters['layout/projectId']
  128. }
  129. },
  130. methods: {
  131. clickTable(info, row) {
  132. // let activeCell = this.hot.getActiveEditor()
  133. // this.renderData = info
  134. // console.log(activeCell, 'activeCell')
  135. // if (activeCell.prop == "LocationFlag") {
  136. // this.localtionDialog = true
  137. // }
  138. },
  139. //人工智能识别
  140. aiDiscern(){
  141. this.hadTrue = false
  142. this.footer = {}
  143. this.aiDialog = true
  144. },
  145. //确认人工识别
  146. isTrue(){
  147. AIFindPoint({
  148. data: {
  149. DataSourceId: this.datasourceId
  150. },
  151. type: this.protocolType
  152. },res => {
  153. this.timer = setInterval(() => {
  154. this.getSchedule()
  155. }, 1000)
  156. this.hadTrue = true
  157. this.footer = null
  158. })
  159. },
  160. async getSchedule(){
  161. await AIPlan({
  162. type: this.protocolType,
  163. data: {
  164. DataSourceId: this.datasourceId
  165. }
  166. },res => {
  167. this.content = res.Content[0]
  168. this.usedNum = (this.content.Current/this.content.Sum).toFixed(2)*100
  169. if (this.usedNum >= 100) {
  170. clearInterval(this.timer)
  171. this.aiDialog = false
  172. this.reset()
  173. }
  174. })
  175. },
  176. changeLoc(val) {
  177. this.renderData.LocationFlag = val
  178. this.changeFlag = false
  179. },
  180. //关闭人工智能弹窗
  181. aiClose(){
  182. this.aiDialog = false
  183. clearInterval(this.timer)
  184. },
  185. //刷新
  186. reset() {
  187. if (!this.changeFlag) {
  188. this.$confirm("表格数据尚未保存,确定刷新吗?").then(_ => {
  189. this.changeFlag = true
  190. this.pages.currentPage = this.oldPage.currentPage
  191. this.pages.size = this.oldPage.size
  192. this.getData()
  193. })
  194. } else {
  195. this.getData()
  196. }
  197. },
  198. //删除点位
  199. delePoint(delData) {
  200. let param = {
  201. data: delData.map(item => {
  202. return item.Id
  203. }),
  204. type: this.protocolType
  205. }
  206. console.log(param, 'param')
  207. this.$confirm('你确定要删除点位吗?').then(_ => {
  208. console.log(param, 'param')
  209. deletePoint(param, res => {
  210. this.$message.success("删除成功")
  211. this.getData()
  212. })
  213. }).catch(_ => {
  214. this.$message("取消删除")
  215. this.getData()
  216. })
  217. },
  218. //页面发生更改
  219. changePage() {
  220. if (!this.changeFlag) {
  221. //发生更改,提示是否保存
  222. this.$confirm('存在数据未保存, 是否继续?', '提示', {
  223. confirmButtonText: '确定',
  224. cancelButtonText: '取消',
  225. type: 'warning'
  226. }).then(() => {
  227. this.getData()
  228. }).catch(() => {
  229. this.pages.currentPage = this.oldPage.currentPage
  230. this.pages.size = this.oldPage.size
  231. return false
  232. });
  233. } else {
  234. this.getData()
  235. }
  236. },
  237. /**
  238. * @param num 代表着1类型2参数
  239. *
  240. */
  241. discern(num) {
  242. if (num == 1) {
  243. this.title = "关键内容识别——批量识别对象类型关键字"
  244. this.type = "type"
  245. } else if (num == 2) {
  246. this.title = "关键内容识别——批量识别对象参数关键字"
  247. this.type = "arguments"
  248. }
  249. this.isChangeDo(this.dialogDo,this.elseDo,true)
  250. },
  251. isChangeDo(func,elseDo,falg = false){
  252. if (!this.changeFlag) {
  253. //发生更改,提示是否保存
  254. this.$confirm('存在数据未保存, 是否继续?', '提示', {
  255. confirmButtonText: '确定',
  256. cancelButtonText: '取消',
  257. type: 'warning'
  258. }).then(() => {
  259. func(falg)
  260. }).catch(() => {
  261. elseDo()
  262. });
  263. } else {
  264. func(falg)
  265. }
  266. },
  267. //否则
  268. elseDo(){
  269. this.pages.currentPage = this.oldPage.currentPage
  270. this.pages.size = this.oldPage.size
  271. return false
  272. },
  273. //处理弹窗
  274. dialogDo(flag){
  275. if(!!flag && !this.changeFlag){
  276. this.changeFlag = !this.changeFlag
  277. }
  278. this.isDialogShow = true
  279. this.$nextTick(() => {
  280. this.$refs.findKeyword.changeType(this.type)
  281. })
  282. },
  283. close() {
  284. this.isDialogShow = false
  285. this.examineDialog = false
  286. this.isChangeData()
  287. },
  288. localFalgChange() {
  289. this.localtionDialog = false
  290. },
  291. //判断是否修改,修改调用修改接口,否则调用获取最新数据
  292. isChangeData() {
  293. if (!this.changeFlag) {
  294. this.saveData(false)
  295. } else {
  296. this.getData()
  297. }
  298. },
  299. //点击检查按钮
  300. examine() {
  301. this.isChangeDo(this.examineTrue,this.elseDo,true)
  302. },
  303. examineTrue(flag){
  304. if(!!flag && !this.changeFlag){
  305. this.changeFlag = !this.changeFlag
  306. }
  307. this.examineDialog = true
  308. },
  309. //保存
  310. saveData(falg) {
  311. if (!!this.hot) {
  312. let data = this.hot.getSourceData(),
  313. changeData;
  314. changeData = data.map(item => {
  315. return {
  316. Id: item.Id,
  317. DatasourceId: item.DatasourceId,
  318. ProjectId: item.ProjectId,
  319. Description: item.Description || null,
  320. KeyEquipmentParameter: item.KeyEquipmentParameter || null,
  321. Remarks: item.Remarks || null,
  322. LocationFlag: item.LocationFlag || null,
  323. KeyEquipmentType: item.KeyEquipmentType || null
  324. }
  325. })
  326. updatePoint({
  327. data: {
  328. Content: changeData
  329. },
  330. type: this.protocolType
  331. }, res => {
  332. console.log(res)
  333. if (falg) {
  334. this.$message.success("保存成功")
  335. }
  336. this.changeFlag = true
  337. this.getData()
  338. })
  339. } else {
  340. this.$message.error("请确保存在数据")
  341. }
  342. },
  343. //发生更改
  344. changeHand(changeData, source) {
  345. console.log(changeData, source)
  346. if (!!changeData) {
  347. let tableData = this.hot.getSourceData()
  348. for(let i = 0; i < tableData.length; i++){
  349. let forFlag = true
  350. if(!tools.isObjectValueEqual(this.copyMain[i],tableData[i])) {
  351. this.changeFlag = false
  352. forFlag = false
  353. break
  354. } else if (i == tableData.length - 1 && forFlag) {
  355. this.changeFlag = true
  356. }
  357. }
  358. }
  359. console.log(this.changeFlag)
  360. return false
  361. },
  362. //获取初始数据
  363. getData() {
  364. this.isLoading = true
  365. let width, param, settings
  366. // width = (document.getElementById("app").clientWidth - 50) / headerArr.length
  367. param = {
  368. type: this.protocolType,
  369. data: {
  370. Filters: {
  371. DatasourceId: this.datasourceId,
  372. Used: true
  373. },
  374. "PageNumber": this.pages.currentPage || 1,
  375. "PageSize": this.pages.size,
  376. }
  377. }
  378. this.oldPage = {
  379. size: this.pages.size,
  380. currentPage: this.pages.currentPage
  381. }
  382. queryPoint(param, res => {
  383. console.log(res)
  384. settings = {
  385. data: res.Content,
  386. colHeaders: changeHeader(headerArr),
  387. columns: showTypes(headerArr),
  388. // colWidths: width,
  389. rowHeights: 30,
  390. maxRows: res.Content.length,
  391. contextMenu: {
  392. items: {
  393. remove_row: {
  394. name: "删除点位"
  395. }
  396. }
  397. }
  398. }
  399. this.copyMain = JSON.parse(JSON.stringify(res.Content))
  400. this.pages.total = res.Total
  401. this.isLoading = false
  402. if (!this.pages.total) {
  403. return false
  404. }
  405. this.$nextTick(_ => {
  406. this.hot = this.$refs.handsontable.init(settings)
  407. })
  408. console.log(this.hot)
  409. })
  410. },
  411. noSaveData() {
  412. return this.changeFlag
  413. }
  414. },
  415. components: {
  416. handsontableComponent,
  417. ownDialog,
  418. findKeyword,
  419. examineMain,
  420. pagination,
  421. localtionFalg
  422. }
  423. }
  424. </script>
  425. <style lang="scss" scoped>
  426. #handsonStep2 {
  427. flex: 1;
  428. display: flex;
  429. flex-flow: column;
  430. padding-bottom: 10px;
  431. .btns-view {
  432. height: 40px;
  433. line-height: 40px;
  434. margin-bottom: 10px;
  435. padding: 0 10px;
  436. }
  437. #handsontableSteps1 {
  438. flex: 1;
  439. overflow: hidden;
  440. position: relative;
  441. margin: 0 10px;
  442. }
  443. }
  444. </style>