addForm.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. <template>
  2. <div class='add-form'>
  3. <div class='form2'>
  4. <div class='input-left'>
  5. <el-row :gutter='20'>
  6. <el-col :span='12'>
  7. <div>图例编码</div>
  8. <el-input v-model='ruleForm.Id' style='width:200px;height:32px;' disabled></el-input>
  9. </el-col>
  10. <el-col :span='12'>
  11. <div class='start'>图例名称</div>
  12. <el-input v-model='ruleForm.Name' style='width:200px;height:32px;'></el-input>
  13. </el-col>
  14. <el-col :span='12' style='margin-top:20px'>
  15. <div class>单位</div>
  16. <el-input v-model='ruleForm.Unit' style='width:200px;height:32px;'></el-input>
  17. </el-col>
  18. <el-col :span='12' style='margin-top:20px'>
  19. <div class='start'>图例类型</div>
  20. <el-select v-model='ruleForm.Type' placeholder='请选择' style='width:200px;height:32px' @change='initGraph'>
  21. <el-option v-for='item in options' :key='item.value' :label='item.label' :value='item.value'></el-option>
  22. </el-select>
  23. </el-col>
  24. </el-row>
  25. </div>
  26. <div class='input-right' ref='graph' v-show='ruleForm.Type=="Zone" || ruleForm.Type=="Image" || ruleForm.Type =="Line"'>
  27. <div v-show=' ruleForm.Type=="Image" && ruleForm.Url' class='input-right'>
  28. <img :key='key' :src='`/serve/topology-wanda/Picture/query/${ruleForm.Url}`' alt />
  29. <!-- {{ruleForm.Url}} -->
  30. </div>
  31. <canvas id='canvas' :width='canvasWidth' :height='canvasHeight' v-show='!(ruleForm.Type=="Image" && ruleForm.Url)'></canvas>
  32. </div>
  33. </div>
  34. <div v-if='ruleForm.Type=="Zone" || ruleForm.Type=="Line"' class='form3'>
  35. <div class='form3-top'>
  36. <span class='form3-span1 start' v-if='ruleForm.Type=="Zone"'>填充色以及透明度</span>
  37. <span class='form3-span3 start'>边框颜色</span>
  38. <span class='form3-span4'>边框线型</span>
  39. <span class='form3-span5'>边框粗细</span>
  40. </div>
  41. <div class='form3-bottom'>
  42. <el-color-picker
  43. v-if='ruleForm.Type=="Zone"'
  44. v-model='ruleForm.FillColor'
  45. style='margin:0 172px 0 10px'
  46. show-alpha
  47. @change='changBgColor'
  48. :color-format='"hex"'
  49. ></el-color-picker>
  50. <el-color-picker v-model='ruleForm.Color' style='margin:0 90px 0 10px' @change='changLineColor'></el-color-picker>
  51. <el-select
  52. v-model='ruleForm.LineDash'
  53. placeholder='请选择'
  54. size='small'
  55. style='width:160px;margin-right:24px'
  56. ref='select1'
  57. @change='changeLineType'
  58. >
  59. <el-option v-for='item in borderLineOption' :key='item.id' :label='item.src' :value='item.id'>
  60. <img :src='item.src' alt />
  61. </el-option>
  62. </el-select>
  63. <div style='position:relative'>
  64. <a-input-number id='inputNumber' v-model='ruleForm.LineWidth' :min='1' :max='10' ref='select' @change='changeLineWidth' />
  65. <span class='line-width'>px</span>
  66. </div>
  67. </div>
  68. </div>
  69. <div v-if='ruleForm.Type=="Image"' class='form5'>
  70. <div class='form5-top'>上传新图标</div>
  71. <div>
  72. <el-upload
  73. class='upload-demo'
  74. action='https://jsonplaceholder.typicode.com/posts/'
  75. :http-request='getFile'
  76. :file-list='fileList'
  77. :on-change='handleChange'
  78. :on-remove='handleRemove'
  79. >
  80. <el-button size='small' style='color:#1F2329;'>点击上传</el-button>
  81. </el-upload>
  82. </div>
  83. </div>
  84. <div v-if='ruleForm.Type!="None"' class='form4'>
  85. <div class='form4-top'>
  86. <span class='form4-span1'>专业/设备、位置类型:</span>
  87. <span class='form4-span3'>铺位可视化typeid</span>
  88. </div>
  89. <div class='form3-bottom'>
  90. <span class='device-list'>
  91. <TreeSelect
  92. tipPlace='top'
  93. width='200'
  94. style=' margin-right:48px;'
  95. :returnParentNode='true'
  96. :isShowAllChoice='true'
  97. :choseArea='true'
  98. :data='deviceList'
  99. @change='treeConfirmDevice'
  100. :hideClear='true'
  101. />
  102. </span>
  103. <TreeSelect
  104. tipPlace='top'
  105. width='200'
  106. :notNull='true'
  107. :returnParentNode='false'
  108. :isShowAllChoice='true'
  109. :choseArea='true'
  110. :data='typeVisualization'
  111. @change='treeConfirm'
  112. @focusChange='focusChange'
  113. :hideClear='true'
  114. :selectedIds='selectedIds'
  115. />
  116. </div>
  117. </div>
  118. </div>
  119. </template>
  120. <script>
  121. import { queryDeviceAndPOsition, createLegend, updateLegend, uploadImg, getVisualization } from '@/api/legendLibrary.js'
  122. import { FloorView } from '@/lib/FloorView'
  123. import { FloorScene } from '@/lib/FloorScene'
  124. import { GraphView } from '@/lib/GraphView'
  125. export default {
  126. data() {
  127. return {
  128. options: [
  129. {
  130. value: 'None',
  131. label: '非图例'
  132. },
  133. {
  134. value: 'Zone',
  135. label: '区域'
  136. },
  137. {
  138. value: 'Image',
  139. label: '图标'
  140. },
  141. {
  142. value: 'Line',
  143. label: '线条'
  144. }
  145. ],
  146. selectedIds: [],
  147. borderLineOption: [
  148. {
  149. id: 'solid',
  150. src: require('@/assets/imgs/1pxline.jpg')
  151. },
  152. {
  153. id: 'dashed',
  154. src: require('@/assets/imgs/dashedLine.jpg')
  155. },
  156. {
  157. id: 'dotted',
  158. src: require('@/assets/imgs/dotLine.jpg')
  159. }
  160. ],
  161. linepxOption: [
  162. {
  163. id: 1,
  164. src: require('@/assets/imgs/1pxline.jpg')
  165. },
  166. {
  167. id: 2,
  168. src: require('@/assets/imgs/2pxline.jpg')
  169. },
  170. {
  171. id: 3,
  172. src: require('@/assets/imgs/3pxline.jpg')
  173. }
  174. ],
  175. fileList: [],
  176. file: '',
  177. // this.ruleForm.Url 图标的key,/serve/topology-wanda/Picture/query/${this.ruleForm.Url}
  178. value: '',
  179. linepxObject: {
  180. src: ''
  181. },
  182. borderLineOptionObject: {
  183. src: ''
  184. },
  185. canvasWidth: 200,
  186. canvasHeight: 114,
  187. view: null,
  188. scene: null,
  189. typeVisualization: [],
  190. // majorList: [], //专业
  191. deviceList: [],
  192. key: 1
  193. }
  194. },
  195. props: ['ruleForm', 'title'],
  196. methods: {
  197. //业下设备分类和位置分类树形结构
  198. initQueryDeviceAndPOsition() {
  199. let postParams = {}
  200. queryDeviceAndPOsition({ postParams }).then(res => {
  201. this.deviceList = res.data
  202. })
  203. },
  204. handleRemove(file, fileList) {
  205. console.log(file, fileList, 'file')
  206. this.ruleForm.Url = ''
  207. },
  208. getFile(file) {
  209. // let imgSrc = document.querySelector('.input-right>img')
  210. // console.log(imgSrc)
  211. this.file = file.file
  212. var formData = new FormData()
  213. formData.append('file', file.file)
  214. if (this.ruleForm.Url) {
  215. formData.append('uid', this.ruleForm.Url)
  216. }
  217. let postParams = formData
  218. uploadImg({ postParams }).then(res => {
  219. if (res.Result == 'success') {
  220. this.key++
  221. this.$set(this.ruleForm, 'Url', res.EntityList[0])
  222. this.$message.success('图标上传成功!')
  223. }
  224. })
  225. },
  226. create() {
  227. //新增
  228. if (this.ruleForm.FillColor.indexOf('#') > -1) {
  229. this.ruleForm.FillColor = this.ruleForm.FillColor
  230. } else {
  231. this.ruleForm.FillColor = this.hexify(this.ruleForm.FillColor)
  232. }
  233. let postParams = {
  234. Content: [this.ruleForm]
  235. }
  236. createLegend({ postParams }).then(res => {
  237. if (res.Result == 'success') {
  238. this.$message.success('添加图例成功!')
  239. this.$emit('addSuccess')
  240. this.fileList = []
  241. } else {
  242. this.$message.error(res.Message)
  243. }
  244. })
  245. },
  246. update() {
  247. //修改
  248. if (this.ruleForm.FillColor.indexOf('#') > -1) {
  249. this.ruleForm.FillColor = this.ruleForm.FillColor
  250. } else {
  251. this.ruleForm.FillColor = this.hexify(this.ruleForm.FillColor)
  252. }
  253. let postParams = {
  254. Content: [this.ruleForm]
  255. }
  256. updateLegend({ postParams }).then(res => {
  257. if (res.Result == 'success') {
  258. this.$message.success('图例修改成功!')
  259. this.$emit('updateSuccess')
  260. this.fileList = []
  261. } else {
  262. this.$message.error(res.Message)
  263. }
  264. })
  265. },
  266. handleChange(file, fileList) {
  267. this.fileList = fileList.slice(-1)
  268. },
  269. clearGraphy(type) {
  270. if (!(this.view instanceof GraphView)) {
  271. this.view = new GraphView('canvas')
  272. }
  273. this.view.type = type
  274. if (this.ruleForm.FillColor.indexOf('#') > -1) {
  275. this.view.bgcolor = this.ruleForm.FillColor
  276. } else {
  277. this.view.bgcolor = this.hexify(this.ruleForm.FillColor)
  278. }
  279. this.view.strokecolor = this.ruleForm.Color
  280. this.view.lineType = this.ruleForm.LineDash
  281. this.view.lineWidth = this.ruleForm.LineWidth
  282. },
  283. initGraph() {
  284. if (this.ruleForm.Type == 'Zone' || this.ruleForm.Type == 'Line' || this.ruleForm.Type == 'Image') {
  285. //1是区域 0是线条
  286. this.clearGraphy(this.ruleForm.Type == 'Zone' ? 1 : this.ruleForm.Type == 'Line' ? 0 : 2)
  287. }
  288. },
  289. //rgba转成16进制
  290. hexify(color) {
  291. console.log(color, 'color')
  292. // var values = color
  293. // .replace(/rgba?\(/, '')
  294. // .replace(/\)/, '')
  295. // .replace(/[\s+]/g, '')
  296. // .split(',')
  297. // var a = parseFloat(values[3] || 1),
  298. // r = Math.floor(a * parseInt(values[0]) + (1 - a) * 255),
  299. // g = Math.floor(a * parseInt(values[1]) + (1 - a) * 255),
  300. // b = Math.floor(a * parseInt(values[2]) + (1 - a) * 255),
  301. // opacity = ''
  302. var opacity = ''
  303. var rgb = color.split(',')
  304. var r = parseInt(rgb[0].split('(')[1])
  305. var g = parseInt(rgb[1])
  306. var b = parseInt(rgb[2].split(')')[0])
  307. switch (parseFloat(rgb[3] || 1) + '') {
  308. case '0':
  309. opacity = '00'
  310. break
  311. case '0.05':
  312. opacity = '0C'
  313. break
  314. case '0.1':
  315. opacity = '19'
  316. break
  317. case '0.15':
  318. opacity = '26'
  319. break
  320. case '0.2':
  321. opacity = '33'
  322. break
  323. case '0.25':
  324. opacity = '3F'
  325. break
  326. case '0.3':
  327. opacity = '4C'
  328. break
  329. case '0.35':
  330. opacity = '59'
  331. break
  332. case '0.4':
  333. opacity = '66'
  334. break
  335. case '0.45':
  336. opacity = '72'
  337. break
  338. case '0.5':
  339. opacity = '7F'
  340. break
  341. case '0.55':
  342. opacity = '8C'
  343. break
  344. case '0.6':
  345. opacity = '99'
  346. break
  347. case '0.65':
  348. opacity = 'A5'
  349. break
  350. case '0.7':
  351. opacity = 'B2'
  352. break
  353. case '0.75':
  354. opacity = 'BF'
  355. break
  356. case '0.8':
  357. opacity = 'CC'
  358. break
  359. case '0.85':
  360. opacity = 'D8'
  361. break
  362. case '0.9':
  363. opacity = 'E5'
  364. break
  365. case '0.95':
  366. opacity = 'F2'
  367. break
  368. case '1':
  369. opacity = 'FF'
  370. break
  371. }
  372. var hex = '#' + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1) + opacity
  373. console.log(hex, 'hrc')
  374. return hex
  375. // return '#' + ('0' + r.toString(16)).slice(-2) + ('0' + g.toString(16)).slice(-2) + ('0' + b.toString(16)).slice(-2) + opacity
  376. },
  377. // 背景颜色改变
  378. changBgColor(val) {
  379. if (this.view) {
  380. this.view.bgcolor = this.hexify(val)
  381. }
  382. },
  383. // 线条颜色改变
  384. changLineColor(val) {
  385. if (this.view) {
  386. this.view.strokecolor = val
  387. }
  388. },
  389. //线条类型改变
  390. changeLineType(val) {
  391. this.$set(this.ruleForm, 'LineDash', val)
  392. this.borderLineOptionObject = val && this.borderLineOption.find(item => item.id == val)
  393. if (this.$refs.select1 && this.$refs.select1.$el) {
  394. this.$refs.select1.$el.children[0].children[0].setAttribute(
  395. 'style',
  396. 'background:url(' + this.borderLineOptionObject.src + ') center center no-repeat;color:transparent;'
  397. )
  398. }
  399. if (this.view) {
  400. this.view.lineType = val
  401. }
  402. },
  403. //线条宽度
  404. changeLineWidth(val) {
  405. this.$set(this.ruleForm, 'LineWidth', val)
  406. if (this.view) {
  407. this.view.lineWidth = Number(val)
  408. }
  409. },
  410. base64ToFile(dataurl, filename) {
  411. //console.log(dataurl, 'url')
  412. let arr = dataurl.split(',')
  413. let mime = arr[0].match(/:(.*?);/)[1]
  414. if (!filename) {
  415. filename = `${new Date().getTime()}.${mime.substr(mime.indexOf('/') + 1)}`
  416. }
  417. let bstr = atob(arr[1])
  418. let n = bstr.length
  419. let u8arr = new Uint8Array(n)
  420. while (n--) {
  421. u8arr[n] = bstr.charCodeAt(n)
  422. }
  423. return new File([u8arr], filename, { type: mime })
  424. },
  425. saveImg() {
  426. let vm = this
  427. if (this.view) {
  428. let data = this.view.canvasView.toDataURL('image/png')
  429. var formData = new FormData()
  430. formData.append('file', this.base64ToFile(data))
  431. let postParams = formData
  432. uploadImg({ postParams }).then(res => {
  433. if (res.Result == 'success') {
  434. this.$set(vm.ruleForm, 'Url', res.EntityList[0])
  435. this.$message.success('图标上传成功!')
  436. if (this.title == '添加图例库') {
  437. this.create()
  438. this.$emit('addSuccess')
  439. this.view.canvas.clearRect(0, 0, this.width, this.height)
  440. } else if (this.title == '修改图例库') {
  441. this.update()
  442. this.$emit('updateSuccess')
  443. this.view.canvas.clearRect(0, 0, this.width, this.height)
  444. } else {
  445. }
  446. }
  447. })
  448. }
  449. },
  450. // 铺位可视化
  451. treeConfirm(data) {
  452. //console.log(data, 'data')
  453. this.$set(this.ruleForm, 'InfoTypeId', data)
  454. },
  455. //位置/设备
  456. treeConfirmDevice(id, info) {
  457. // this.$set(this.ruleForm, 'InfoLocal', data)
  458. let InfoSystem = []
  459. let InfoLocal = []
  460. for (let i = 0; i < info.length; i++) {
  461. let type = info[i]
  462. if (type.name.includes('/')) {
  463. InfoLocal.push(type)
  464. //位置/设备
  465. this.$set(this.ruleForm, 'InfoLocal', InfoLocal)
  466. } else {
  467. InfoSystem.push(type)
  468. //专业
  469. this.$set(this.ruleForm, 'InfoSystem', InfoSystem)
  470. }
  471. }
  472. },
  473. focusChange(status) {
  474. // //console.log('focusChange', status)
  475. },
  476. visualization() {
  477. getVisualization({}).then(res => {
  478. this.typeVisualization =
  479. res.Data &&
  480. res.Data.map(i => {
  481. return {
  482. id: i.Id,
  483. name: i.Name,
  484. children: i.Children
  485. ? i.Children.map(j => {
  486. return {
  487. id: j.Id,
  488. name: j.Id + '-' + j.Name
  489. }
  490. })
  491. : []
  492. }
  493. })
  494. })
  495. },
  496. getTree(data) {
  497. return {
  498. id: data.Id,
  499. name: data.Name,
  500. children: data.Children ? data.Children.map(i => this.getTree(i)) : []
  501. }
  502. },
  503. focusChange(status) {
  504. //console.log('focusChange', status)
  505. }
  506. },
  507. mounted() {
  508. this.initQueryDeviceAndPOsition()
  509. this.visualization()
  510. if (this.title == '修改图例库') {
  511. this.changeLineWidth(this.ruleForm.LineWidth)
  512. this.changeLineType(this.ruleForm.LineDash)
  513. this.initGraph()
  514. }
  515. },
  516. updated() {
  517. if (this.title == '修改图例库') {
  518. this.changeLineWidth(this.ruleForm.LineWidth)
  519. this.changeLineType(this.ruleForm.LineDash)
  520. this.initGraph()
  521. }
  522. }
  523. }
  524. </script>
  525. <style lang='less' scoped>
  526. .add-form {
  527. color: #646c73;
  528. margin: 16px 0 0 72px;
  529. font-size: 14px;
  530. .start::after {
  531. content: '*';
  532. color: #f56c6c;
  533. margin-left: 4px;
  534. }
  535. .ant-input-number {
  536. border-radius: 4px 0 0 4px;
  537. }
  538. .form2 {
  539. display: flex;
  540. .input-left {
  541. width: 500px;
  542. .title {
  543. margin-right: 100px;
  544. margin: 20px 0 8px 0;
  545. display: inline-block;
  546. width: 250px;
  547. }
  548. .type {
  549. margin-right: 100px;
  550. margin: 20px 0 8px 0;
  551. display: inline-block;
  552. width: 250px;
  553. }
  554. }
  555. .input-right {
  556. width: 200px;
  557. height: 114px;
  558. background: rgba(245, 246, 247, 1);
  559. display: inline-block;
  560. display: flex;
  561. align-items: center;
  562. justify-content: center;
  563. img {
  564. width: 28px;
  565. height: 28px;
  566. }
  567. .model1 {
  568. width: 56px;
  569. height: 6px;
  570. }
  571. .model {
  572. width: 56px;
  573. height: 40px;
  574. }
  575. }
  576. }
  577. .form3 {
  578. width: 720px;
  579. height: 86px;
  580. background: rgba(245, 246, 247, 1);
  581. border-radius: 4px;
  582. margin-top: 20px;
  583. .form3-top {
  584. padding: 12px 0 8px 12px;
  585. .form3-span1 {
  586. margin-right: 102px;
  587. }
  588. .form3-span2 {
  589. margin-right: 78px;
  590. }
  591. .form3-span3 {
  592. margin-right: 64px;
  593. }
  594. .form3-span4 {
  595. margin-right: 130px;
  596. }
  597. }
  598. .form3-bottom {
  599. display: flex;
  600. }
  601. }
  602. .form4 {
  603. .form4-top {
  604. padding: 20px 0 8px 0;
  605. .form4-span1 {
  606. margin-right: 32px;
  607. }
  608. .form4-span2 {
  609. margin-right: 102px;
  610. }
  611. .form4-span3 {
  612. margin-left: 75px;
  613. }
  614. }
  615. }
  616. .form5 {
  617. width: 720px;
  618. height: 86px;
  619. background: rgba(245, 246, 247, 1);
  620. border-radius: 4px;
  621. margin-top: 20px;
  622. padding-left: 12px;
  623. .form5-top {
  624. padding: 12px 0 8px 0;
  625. }
  626. }
  627. .upload-demo {
  628. display: flex;
  629. }
  630. .line-width {
  631. display: inline-block;
  632. width: 35px;
  633. height: 32px;
  634. background: rgba(239, 240, 241, 1);
  635. border-radius: 0 4px 4px 0;
  636. border-right: 1px solid rgba(195, 198, 203, 1);
  637. border-top: 1px solid rgba(195, 198, 203, 1);
  638. border-bottom: 1px solid rgba(195, 198, 203, 1);
  639. position: absolute;
  640. text-align: center;
  641. }
  642. }
  643. </style>
  644. <style >
  645. .p-select-area {
  646. width: 480px !important;
  647. }
  648. .p-select-area .p-transfer-left {
  649. width: 236px !important;
  650. }
  651. .p-tree-node-check .p-tree-node-title .p-tree-node-name {
  652. word-break: break-all !important;
  653. white-space: normal !important;
  654. word-break: break-all !important;
  655. word-wrap: break-word !important;
  656. height: auto !important;
  657. line-height: 25px;
  658. }
  659. .p-select-area .p-transfer-right {
  660. width: 245px !important;
  661. }
  662. .p-select-area .p-transfer-right .p-transfer-selected .p-transfer-selected-item > span {
  663. word-break: break-all !important;
  664. white-space: normal !important;
  665. word-break: break-all !important;
  666. word-wrap: break-word !important;
  667. height: auto !important;
  668. line-height: 25px;
  669. display: block;
  670. width: 225px;
  671. padding-right: 3px;
  672. }
  673. </style>