step1.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. <template>
  2. <div id="handsonStep1">
  3. <div class="btns-view">
  4. <el-button style="float:right;margin-top:4px;margin-left:10px;width:120px;" @click="saveData">保存</el-button>
  5. <el-button style="float:right;margin-top:4px;width:120px;" @click="addRow">新增行</el-button>
  6. <el-button style="float:right;margin-top:4px;width:120px;" @click="downData">导出配置点位表</el-button>
  7. <el-button style="float:right;margin-top:4px;width:120px;" @click="updateExcel = true">导入Excel</el-button>
  8. <el-button style="float:right;margin-top:4px;width:120px;" @click="downloadExcel = true">导出Excel模板</el-button>
  9. <el-checkbox style="float:right;line-height:40px;" @change="getData" v-model="checked">只显示使用的原始点位</el-checkbox>
  10. <el-button @click="clickPointVal">获取原始点位当前值</el-button>
  11. </div>
  12. <div id="handsontableSteps1" class="middle_sty" v-loading="isLoading">
  13. <handsontable-component v-if="!!allData.length" @delete="delePoint" ref="handsontable" @mouseDown="clickTable" @change="changeHand"></handsontable-component>
  14. <div v-else class="center">
  15. <i class="iconwushuju iconfont"></i>
  16. 暂无数据
  17. </div>
  18. </div>
  19. <own-dialog :width="'500px'" :index="true" title="位置标签" :dialogVisible="localtionDialog" @cancel="closeFalg">
  20. <localtion-falg :renderData="renderData" @changeTag="changeLoc"></localtion-falg>
  21. </own-dialog>
  22. <own-dialog :width="'300px'" :index="true" title="导出excel模板" :dialogVisible="downloadExcel" @cancel="close">
  23. <div class="center">
  24. <el-button type="text" @click="download">下载模板</el-button>
  25. </div>
  26. </own-dialog>
  27. <own-dialog :width="'500px'" :index="true" :footer="footer" title="导出excel模板" :dialogVisible="updateExcel" @confirm="sureOfUpload" @cancel="close">
  28. <div class="center" style="height:100px;">
  29. <upload-file accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" @change="changeFile"></upload-file>
  30. </div>
  31. <div>
  32. <el-radio class="radio-left" v-model="radio" label="1">默认使用导入的全部原始点位</el-radio>
  33. <el-radio class="radio-left" v-model="radio" label="2">默认不使用导入的全部原始点位</el-radio>
  34. </div>
  35. </own-dialog>
  36. <div class="right">
  37. <pagination :page="pages" @change="changePage"></pagination>
  38. </div>
  39. </div>
  40. </template>
  41. <script>
  42. import handsontableComponent from "@/components/common/handsontable"
  43. import getHeaderSetting from "@/utils/point_edit/handson_header"
  44. import ownDialog from "@/components/el_pack/dialog"
  45. import localtionFalg from "@/components/config_point/location_flag"
  46. import pagination from "@/components/common/myPagination"
  47. // import "@/assets/js/chosen.jquery.min";
  48. // import "@/assets/js/handsontable-chosen-editor";
  49. // import Handsontable from "handsontable-pro"
  50. import {
  51. mapGetters,
  52. mapActions
  53. } from "vuex";
  54. import {
  55. changeHeader,
  56. showTypes
  57. } from "@/utils/handsontable/delType"
  58. import {
  59. queryPoint,
  60. updatePoint,
  61. createPoint,
  62. downloadTemplete,
  63. uploadPointFile,
  64. deletePoint,
  65. getPointValue
  66. } from "@/fetch/point_http"
  67. import uploadFile from "@/components/common/uploadFile"
  68. import axios from 'axios'
  69. export default {
  70. data() {
  71. return {
  72. checked: false,
  73. settings: {},
  74. hot: null,
  75. changeFlag: true, //是否发生修改
  76. localtionDialog: false,
  77. renderData: {},
  78. allData: [],
  79. pages: {
  80. size: 50,
  81. sizes: [10, 30, 50, 100, 150, 200],
  82. total: 0,
  83. currentPage: 0
  84. },
  85. oldPage: {
  86. currentPage: 0,
  87. size: 10
  88. },
  89. downloadExcel: false,
  90. isLoading: false,
  91. updateExcel: false,
  92. radio: '1',
  93. file: "", //上传的文件
  94. footer: {
  95. cancel: '取消',
  96. confirm: '确定'
  97. }
  98. }
  99. },
  100. computed: {
  101. ...mapGetters("project", [
  102. "projectId",
  103. "datasourceId",
  104. "protocolType"
  105. ])
  106. },
  107. created() {},
  108. mounted() {
  109. if (!this.datasourceId) {
  110. this.$router.push({
  111. path: "/point/pointsetting"
  112. })
  113. } else {
  114. this.getData()
  115. }
  116. },
  117. methods: {
  118. //关闭弹窗
  119. close() {
  120. this.downloadExcel = false
  121. this.updateExcel = false
  122. this.getData()
  123. },
  124. closeFalg() {
  125. this.localtionDialog = false
  126. },
  127. clickPointVal(){
  128. let data = this.hot.getSourceData()
  129. if(!data || !data.length){
  130. return false
  131. }
  132. let param = {
  133. data: {
  134. DataSourceId: this.datasourceId,
  135. PointIds: data.map(item => {
  136. return item.Id
  137. })
  138. },
  139. type: this.protocolType
  140. }
  141. getPointValue(param,res => {
  142. if(!!res.Content && res.Content.length){
  143. data.map(item => {
  144. res.Content.map(child => {
  145. if(item.Id == child.PointId){
  146. item.pointValue = child.Data.Data
  147. item.pointDate = child.Data.Time
  148. }
  149. })
  150. return item
  151. })
  152. }
  153. })
  154. },
  155. changeLoc(val) {
  156. this.renderData.LocationFlag = val
  157. this.changeFlag = false
  158. },
  159. downData() {
  160. let param = {
  161. method: 'post',
  162. url: `/pointconfig/point/${this.protocolType}/pointlist-export`,
  163. data: {
  164. DataSourceId: this.datasourceId
  165. },
  166. responseType: 'blob',
  167. headers: {
  168. ProjectId: this.projectId
  169. }
  170. }
  171. axios(param).then(function(res) {
  172. var blob = new Blob([res.data], {
  173. type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8'
  174. });
  175. var fileName = res.headers['content-disposition'];
  176. if (fileName)
  177. fileName = fileName.substring(fileName.indexOf('=') + 1);
  178. if ('download' in document.createElement('a')) { // 非IE下载
  179. const elink = document.createElement('a')
  180. elink.download = fileName
  181. elink.style.display = 'none'
  182. elink.href = URL.createObjectURL(blob)
  183. document.body.appendChild(elink)
  184. elink.click()
  185. URL.revokeObjectURL(elink.href) // 释放URL 对象
  186. document.body.removeChild(elink)
  187. } else { // IE10+下载
  188. navigator.msSaveBlob(blob, fileName)
  189. }
  190. }).catch(function(err) {
  191. })
  192. },
  193. //删除点位
  194. delePoint(delData) {
  195. let param = {
  196. data: delData.map(item => {
  197. return item.Id
  198. }),
  199. type: this.protocolType
  200. }
  201. console.log(delData,'delllll')
  202. if (!delData.length) {
  203. return false
  204. }
  205. if(!!delData){
  206. console.log(delData,'delData')
  207. if(!delData[0].Id){
  208. return false
  209. }
  210. }
  211. this.$confirm('你确定要删除点位吗?').then(_ => {
  212. deletePoint(param, res => {
  213. this.$message.success("删除成功")
  214. this.getData()
  215. })
  216. }).catch(_ => {
  217. this.$message("取消删除")
  218. this.getData()
  219. })
  220. },
  221. //下载excel模板
  222. download() {
  223. axios({
  224. method: 'post',
  225. url: `/pointconfig/point/${this.protocolType}/template-export`,
  226. data: {
  227. DataSourceId: this.datasourceId
  228. },
  229. headers: {
  230. ProjectId: this.projectId
  231. },
  232. responseType: 'blob'
  233. }).then(function(res) {
  234. var blob = new Blob([res.data], {
  235. type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8'
  236. });
  237. var fileName = res.headers['content-disposition'];
  238. if (fileName)
  239. fileName = fileName.substring(fileName.indexOf('=') + 1);
  240. if ('download' in document.createElement('a')) { // 非IE下载
  241. const elink = document.createElement('a')
  242. elink.download = fileName
  243. elink.style.display = 'none'
  244. elink.href = URL.createObjectURL(blob)
  245. document.body.appendChild(elink)
  246. elink.click()
  247. URL.revokeObjectURL(elink.href) // 释放URL 对象
  248. document.body.removeChild(elink)
  249. } else { // IE10+下载
  250. navigator.msSaveBlob(blob, fileName)
  251. }
  252. }).catch(function(err) {
  253. })
  254. },
  255. //点击表格
  256. clickTable(info, row) {
  257. let activeCell = this.hot.getActiveEditor()
  258. if(activeCell.prop == "Used"){
  259. info.Used = !info.Used
  260. }
  261. if (activeCell.prop == "LocationFlag") {
  262. this.renderData = info
  263. this.localtionDialog = true
  264. }
  265. },
  266. addRow() {
  267. if (!!this.allData.length) {
  268. let data = this.hot.getSourceData()
  269. data.unshift({
  270. Used: true,
  271. LocationFlag: []
  272. })
  273. this.hot.loadData(data)
  274. this.hot.updateSettings({
  275. maxRows: data.length
  276. })
  277. } else {
  278. this.allData = [{
  279. Used: true,
  280. LocationFlag: []
  281. }]
  282. this.createHot()
  283. }
  284. },
  285. //页面发生更改
  286. changePage() {
  287. if (!this.changeFlag) {
  288. //发生更改,提示是否保存
  289. this.$confirm('存在数据未保存, 是否继续?', '提示', {
  290. confirmButtonText: '确定',
  291. cancelButtonText: '取消',
  292. type: 'warning'
  293. }).then(() => {
  294. this.getData()
  295. }).catch(() => {
  296. this.pages.currentPage = this.oldPage.currentPage
  297. this.pages.size = this.oldPage.size
  298. return false
  299. });
  300. } else {
  301. this.getData()
  302. }
  303. },
  304. getData() {
  305. // width = (document.getElementById("app").clientWidth - 50) / header.length
  306. this.isLoading = true
  307. let param = {
  308. type: this.protocolType,
  309. data: {
  310. Filters: {
  311. DatasourceId: this.datasourceId,
  312. },
  313. "PageNumber": this.pages.currentPage || 1,
  314. "PageSize": this.pages.size,
  315. }
  316. }
  317. if (this.checked) {
  318. param.data.Filters.Used = true
  319. }
  320. this.oldPage = {
  321. size: this.pages.size,
  322. currentPage: this.pages.currentPage
  323. }
  324. queryPoint(param, res => {
  325. this.isLoading = false
  326. this.changeFlag = true
  327. this.allData = res.Content || []
  328. this.pages.total = res.Total
  329. this.createHot()
  330. })
  331. },
  332. //创建实例
  333. createHot() {
  334. let header, width, settings
  335. header = getHeaderSetting(this.protocolType)
  336. settings = {
  337. data: this.allData,
  338. colHeaders: changeHeader(header),
  339. columns: showTypes(header),
  340. rowHeights: 30,
  341. maxRows: this.allData.length,
  342. contextMenu: {
  343. items: {
  344. remove_row: {
  345. name: "删除点位"
  346. }
  347. }
  348. }
  349. }
  350. if (!this.allData.length) {
  351. return false
  352. }
  353. this.$nextTick(_ => {
  354. this.hot = this.$refs.handsontable.init(settings)
  355. })
  356. },
  357. //修改提示
  358. changeHand(changeData, source) {
  359. if (!!changeData) {
  360. this.changeFlag = false
  361. }
  362. return false
  363. },
  364. //保存
  365. saveData() {
  366. if (!!this.hot) {
  367. console.log(this.hot.getSourceData(),'getSourceData')
  368. let data = this.hot.getSourceData(),
  369. updateList = [],
  370. arr1 = [],
  371. createList = [];
  372. data.map(item => {
  373. if (!!item.Id) {
  374. delete item.CreateTime
  375. delete item.LastUpdate
  376. if(item.hasOwnProperty('pointDate')){
  377. delete item.pointDate
  378. }
  379. if(item.hasOwnProperty('pointValue')){
  380. delete item.pointValue
  381. }
  382. arr1.push(item)
  383. updateList.push(item)
  384. } else {
  385. createList.push(item)
  386. }
  387. })
  388. console.log(updateList,createList, arr1, "updateList")
  389. if (updateList.length) {
  390. this.update(updateList)
  391. }
  392. if (createList.length) {
  393. this.createList(createList)
  394. }
  395. } else {
  396. this.$message.error("请确保存在数据")
  397. }
  398. },
  399. async createList(createList) {
  400. let i = 0;
  401. for (i; i < createList.length; i++) {
  402. if (createList[i].hasOwnProperty("Description")) {
  403. await this.create(createList[i])
  404. }
  405. }
  406. this.changeFlag = true
  407. },
  408. async create(obj) {
  409. for (let key in obj) {
  410. if (key == "LocationFlag" && obj[key] == "") {
  411. obj[key] = []
  412. }
  413. if (obj[key] === "") {
  414. obj[key] = null
  415. }
  416. }
  417. obj.DatasourceId = this.datasourceId
  418. obj.ProjectId = this.projectId
  419. await createPoint({
  420. data: obj,
  421. type: this.protocolType
  422. }, res => {
  423. obj.Id = res.Id
  424. this.getData()
  425. })
  426. },
  427. /**
  428. * @param {更新list} updateList
  429. *
  430. * 更新点位
  431. */
  432. update(updateList) {
  433. updatePoint({
  434. data: {
  435. Content: updateList
  436. },
  437. type: this.protocolType
  438. }, res => {
  439. this.getData()
  440. })
  441. },
  442. //没有保存的时候弹窗
  443. noSaveData() {
  444. return this.changeFlag
  445. },
  446. //上传文件
  447. changeFile(file) {
  448. this.file = file[0] || ''
  449. },
  450. //确定上传
  451. sureOfUpload() {
  452. if (!!this.file) {
  453. //有文件进行上传
  454. let param = {
  455. data: new FormData(),
  456. type: this.protocolType
  457. };
  458. param.data.set('DataSourceId', this.datasourceId)
  459. param.data.set('Used', this.radio == 1 ? true : false)
  460. param.data.set('multipartFile', this.file.raw)
  461. uploadPointFile(param, res => {
  462. this.$message.success("上传成功")
  463. this.getData()
  464. this.updateExcel = false
  465. })
  466. } else {
  467. this.$message.info("请选择文件")
  468. }
  469. }
  470. },
  471. components: {
  472. handsontableComponent,
  473. ownDialog,
  474. localtionFalg,
  475. pagination,
  476. uploadFile
  477. },
  478. }
  479. </script>
  480. <style lang="scss" scoped>
  481. .radio-left {
  482. display: block;
  483. line-height: 30px;
  484. margin-left: 100px;
  485. }
  486. #handsonStep1 {
  487. flex: 1;
  488. display: flex;
  489. flex-flow: column;
  490. .btns-view {
  491. height: 40px;
  492. line-height: 40px;
  493. margin-bottom: 10px;
  494. padding: 0 10px;
  495. }
  496. #handsontableSteps1 {
  497. flex: 1;
  498. overflow: hidden;
  499. position: relative;
  500. margin: 0 10px;
  501. }
  502. }
  503. </style>