addForm.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. <template>
  2. <div class='add-form'>
  3. <div class='form1'>
  4. <span class='span1'>图例编码</span>
  5. <span class='span2'>图例名称</span>
  6. <span class='span3' v-if='ruleForm.Type=="Zone" || ruleForm.Type=="Image"'>展示预览</span>
  7. </div>
  8. <div class='form2'>
  9. <div class='input-left'>
  10. <el-input v-model='ruleForm.Code' disabled style='width:200px;height:32px;margin-right:48px;'></el-input>
  11. <el-input v-model='ruleForm.Name' style='width:200px;height:32px;'></el-input>
  12. <div class='title'>单位</div>
  13. <div class='type'>图例类型</div>
  14. <el-input v-model='ruleForm.Unit' style='width:200px;height:32px;'></el-input>
  15. <el-select v-model='ruleForm.Type' placeholder='请选择' style='width:200px;height:32px;margin-left:46px' @change='initGraph'>
  16. <el-option v-for='item in options' :key='item.value' :label='item.label' :value='item.value'></el-option>
  17. </el-select>
  18. </div>
  19. <div class='input-right' ref='graph' v-show='ruleForm.Type=="Zone" || ruleForm.Type=="Image" || ruleForm.Type =="Line"'>
  20. <div v-show=' ruleForm.Type=="Image" && ruleForm.Url' class='input-right'>
  21. <img :src='`/serve/topology-wanda/Picture/query/${ruleForm.Url}`' alt />
  22. <!-- {{ruleForm.Url}} -->
  23. </div>
  24. <canvas id='canvas' :width='canvasWidth' :height='canvasHeight' v-show='!(ruleForm.Type=="Image" && ruleForm.Url)'></canvas>
  25. </div>
  26. </div>
  27. <div v-if='ruleForm.Type=="Zone" || ruleForm.Type=="Line"' class='form3'>
  28. <div class='form3-top'>
  29. <span class='form3-span1' v-if='ruleForm.Type=="Zone"'>填充色以及透明度</span>
  30. <span class='form3-span3'>边框颜色</span>
  31. <span class='form3-span4'>边框线型</span>
  32. <span class='form3-span5'>边框粗细</span>
  33. </div>
  34. <div class='form3-bottom'>
  35. <el-color-picker
  36. v-if='ruleForm.Type=="Zone"'
  37. v-model='ruleForm.FillColor'
  38. style='margin:0 172px 0 10px'
  39. show-alpha
  40. @change='changBgColor'
  41. :color-format='"hex"'
  42. ></el-color-picker>
  43. <el-color-picker v-model='ruleForm.Color' style='margin:0 90px 0 10px' @change='changLineColor'></el-color-picker>
  44. <el-select
  45. v-model='ruleForm.LineDash'
  46. placeholder='请选择'
  47. size='small'
  48. style='width:160px;margin-right:24px'
  49. ref='select1'
  50. @change='changeLineType'
  51. >
  52. <el-option v-for='item in borderLineOption' :key='item.id' :label='item.src' :value='item.id'>
  53. <img :src='item.src' alt />
  54. </el-option>
  55. </el-select>
  56. <div style='position:relative'>
  57. <a-input-number id='inputNumber' v-model='ruleForm.LineWidth' :min='1' :max='10' ref='select' @change='changeLineWidth' />
  58. <span class='line-width'>px</span>
  59. </div>
  60. </div>
  61. </div>
  62. <div v-if='ruleForm.Type=="Image"' class='form5'>
  63. <div class='form5-top'>上传新图标</div>
  64. <div>
  65. <el-upload
  66. class='upload-demo'
  67. action='https://jsonplaceholder.typicode.com/posts/'
  68. :http-request='getFile'
  69. :file-list='fileList'
  70. :on-change='handleChange'
  71. >
  72. <el-button size='small' style='color:#1F2329;'>点击上传</el-button>
  73. </el-upload>
  74. </div>
  75. </div>
  76. <div v-if='ruleForm.Type!="None"' class='form4'>
  77. <div class='form4-top'>
  78. <span class='form4-span1'>对应工程信息化中的位置/设备分类</span>
  79. <span class='form4-span2'>工程信息化的专业</span>
  80. <span class='form4-span3'>铺位可视化typeid</span>
  81. </div>
  82. <div class='form3-bottom'>
  83. <!-- <el-select v-model='value' placeholder='请选择' size='small' style='width:200px;margin-right:48px;'>
  84. <el-option v-for='item in options1' :key='item.value' :label='item.label' :value='item.value'></el-option>
  85. </el-select>
  86. <el-select v-model='value' placeholder='请选择' size='small' style='width:200px;margin-right:48px'>
  87. <el-option v-for='item in options2' :key='item.value' :label='item.label' :value='item.value'></el-option>
  88. </el-select>-->
  89. <TreeSelect
  90. tipPlace='top'
  91. width='200'
  92. style=' margin-right:48px;'
  93. :notNull='true'
  94. :returnParentNode='false'
  95. :isShowAllChoice='true'
  96. :choseArea='true'
  97. :data='deviceList'
  98. @change='treeConfirmDevice'
  99. />
  100. <TreeSelect
  101. tipPlace='top'
  102. width='200'
  103. style=' margin-right:48px;'
  104. :notNull='true'
  105. :returnParentNode='false'
  106. :isShowAllChoice='true'
  107. :choseArea='true'
  108. :data='majorList'
  109. @change='treeConfirmMajor'
  110. />
  111. <TreeSelect
  112. tipPlace='top'
  113. width='200'
  114. :notNull='true'
  115. :returnParentNode='false'
  116. :isShowAllChoice='true'
  117. :choseArea='true'
  118. :data='typeVisualization'
  119. @change='treeConfirm'
  120. @focusChange='focusChange'
  121. />
  122. </div>
  123. </div>
  124. </div>
  125. </template>
  126. <script>
  127. import { createLegend, updateLegend, uploadImg, getVisualization } from '@/api/legendLibrary.js'
  128. import { FloorView } from '@/lib/FloorView'
  129. import { FloorScene } from '@/lib/FloorScene'
  130. import { GraphView } from '@/lib/GraphView'
  131. export default {
  132. data() {
  133. return {
  134. options: [
  135. {
  136. value: 'None',
  137. label: '非图例'
  138. },
  139. {
  140. value: 'Zone',
  141. label: '区域'
  142. },
  143. {
  144. value: 'Image',
  145. label: '图标'
  146. },
  147. {
  148. value: 'Line',
  149. label: '线条'
  150. }
  151. ],
  152. options1: [],
  153. options2: [],
  154. options3: [],
  155. borderLineOption: [
  156. {
  157. id: 'solid',
  158. src: require('@/assets/imgs/1pxline.jpg')
  159. },
  160. {
  161. id: 'dashed',
  162. src: require('@/assets/imgs/dashedLine.jpg')
  163. },
  164. {
  165. id: 'dotted',
  166. src: require('@/assets/imgs/dotLine.jpg')
  167. }
  168. ],
  169. linepxOption: [
  170. {
  171. id: 1,
  172. src: require('@/assets/imgs/1pxline.jpg')
  173. },
  174. {
  175. id: 2,
  176. src: require('@/assets/imgs/2pxline.jpg')
  177. },
  178. {
  179. id: 3,
  180. src: require('@/assets/imgs/3pxline.jpg')
  181. }
  182. ],
  183. fileList: [],
  184. // this.ruleForm.Url 图标的key,/serve/topology-wanda/Picture/query/${this.ruleForm.Url}
  185. value: '',
  186. linepxObject: {
  187. src: ''
  188. },
  189. borderLineOptionObject: {
  190. src: ''
  191. },
  192. canvasWidth: 200,
  193. canvasHeight: 114,
  194. view: null,
  195. scene: null,
  196. typeVisualization: [],
  197. visualizationList: [], //已选铺位可视化
  198. majorList: [], //专业
  199. deviceList: []
  200. }
  201. },
  202. props: ['ruleForm', 'title'],
  203. methods: {
  204. getFile(file) {
  205. var formData = new FormData()
  206. formData.append('file', file.file)
  207. formData.append('uid', this.ruleForm.Url)
  208. let postParams = formData
  209. uploadImg({ postParams }).then(res => {
  210. if (res.Result == 'success') {
  211. this.$set(this.ruleForm, 'Url', res.EntityList[0])
  212. this.$message.success('图标上传成功!')
  213. }
  214. })
  215. },
  216. create() {
  217. //新增
  218. let postParams = {
  219. Content: [this.ruleForm]
  220. }
  221. createLegend({ postParams }).then(res => {
  222. if (res.Result == 'success') {
  223. this.$message.success('添加图例成功!')
  224. this.$emit('addSuccess')
  225. this.fileList = []
  226. } else {
  227. this.$message.error(res.Message)
  228. }
  229. })
  230. },
  231. update() {
  232. //修改
  233. let postParams = {
  234. Content: [this.ruleForm]
  235. }
  236. updateLegend({ postParams }).then(res => {
  237. if (res.Result == 'success') {
  238. this.$message.success('图例修改成功!')
  239. this.$emit('updateSuccess')
  240. this.fileList = []
  241. } else {
  242. this.$message.error(res.Message)
  243. }
  244. })
  245. },
  246. handleChange(file, fileList) {
  247. this.fileList = fileList.slice(-1)
  248. },
  249. clearGraphy(type) {
  250. if (!(this.view instanceof GraphView)) {
  251. this.view = new GraphView('canvas')
  252. }
  253. this.view.type = type
  254. if (this.ruleForm.FillColor.indexOf('#') > -1) {
  255. this.view.bgcolor = this.ruleForm.FillColor
  256. } else {
  257. this.view.bgcolor = this.hexify(this.ruleForm.FillColor)
  258. }
  259. this.view.strokecolor = this.ruleForm.Color
  260. this.view.lineType = this.ruleForm.LineDash
  261. this.view.lineWidth = this.ruleForm.LineWidth
  262. },
  263. initGraph() {
  264. if (this.ruleForm.Type == 'Zone' || this.ruleForm.Type == 'Line' || this.ruleForm.Type == 'Image') {
  265. //1是区域 0是线条
  266. this.clearGraphy(this.ruleForm.Type == 'Zone' ? 1 : this.ruleForm.Type == 'Line' ? 0 : 2)
  267. }
  268. },
  269. //rgba转成16进制
  270. hexify(color) {
  271. var values = color
  272. .replace(/rgba?\(/, '')
  273. .replace(/\)/, '')
  274. .replace(/[\s+]/g, '')
  275. .split(',')
  276. var a = parseFloat(values[3] || 1),
  277. r = Math.floor(a * parseInt(values[0]) + (1 - a) * 255),
  278. g = Math.floor(a * parseInt(values[1]) + (1 - a) * 255),
  279. b = Math.floor(a * parseInt(values[2]) + (1 - a) * 255)
  280. return '#' + ('0' + r.toString(16)).slice(-2) + ('0' + g.toString(16)).slice(-2) + ('0' + b.toString(16)).slice(-2)
  281. },
  282. // 背景颜色改变
  283. changBgColor(val) {
  284. if (this.view) {
  285. this.view.bgcolor = this.hexify(val)
  286. }
  287. },
  288. // 线条颜色改变
  289. changLineColor(val) {
  290. if (this.view) {
  291. this.view.strokecolor = val
  292. }
  293. },
  294. //线条类型改变
  295. changeLineType(val) {
  296. this.$set(this.ruleForm, 'LineDash', val)
  297. this.borderLineOptionObject = val && this.borderLineOption.find(item => item.id == val)
  298. if (this.$refs.select1 && this.$refs.select1.$el) {
  299. this.$refs.select1.$el.children[0].children[0].setAttribute(
  300. 'style',
  301. 'background:url(' + this.borderLineOptionObject.src + ') center center no-repeat;color:transparent;'
  302. )
  303. }
  304. if (this.view) {
  305. this.view.lineType = val
  306. }
  307. },
  308. //线条宽度
  309. changeLineWidth(val) {
  310. this.$set(this.ruleForm, 'LineWidth', val)
  311. // this.linepxObject = val && this.linepxOption.find(item => item.id == val)
  312. // if (this.$refs.select && this.$refs.select.$el) {
  313. // this.$refs.select.$el.children[0].children[0].setAttribute(
  314. // 'style',
  315. // 'background:url(' + this.linepxObject.src + ') center center no-repeat;color:transparent;'
  316. // )
  317. // }
  318. if (this.view) {
  319. this.view.lineWidth = Number(val)
  320. }
  321. },
  322. base64ToFile(dataurl, filename) {
  323. console.log(dataurl, 'url')
  324. let arr = dataurl.split(',')
  325. let mime = arr[0].match(/:(.*?);/)[1]
  326. if (!filename) {
  327. filename = `${new Date().getTime()}.${mime.substr(mime.indexOf('/') + 1)}`
  328. }
  329. let bstr = atob(arr[1])
  330. let n = bstr.length
  331. let u8arr = new Uint8Array(n)
  332. while (n--) {
  333. u8arr[n] = bstr.charCodeAt(n)
  334. }
  335. return new File([u8arr], filename, { type: mime })
  336. },
  337. saveImg() {
  338. if (this.view) {
  339. let data = this.view.canvasView.toDataURL('image/png')
  340. var formData = new FormData()
  341. formData.append('file', this.base64ToFile(data))
  342. let postParams = formData
  343. uploadImg({ postParams }).then(res => {
  344. if (res.Result == 'success') {
  345. this.$set(this.ruleForm, 'Url', res.EntityList[0])
  346. this.$message.success('图标上传成功!')
  347. if (this.title == '添加图例库') {
  348. this.create()
  349. this.$emit('addSuccess')
  350. this.view.canvas.clearRect(0, 0, this.width, this.height)
  351. } else if (this.title == '修改图例库') {
  352. this.update()
  353. this.$emit('updateSuccess')
  354. this.view.canvas.clearRect(0, 0, this.width, this.height)
  355. } else {
  356. }
  357. }
  358. })
  359. }
  360. },
  361. // 多选返回的id组
  362. treeConfirm(data) {
  363. console.log(data, 'data')
  364. this.visualizationList = data
  365. },
  366. //专业
  367. treeConfirmMajor(id, info) {
  368. console.log(id)
  369. },
  370. //位置/设备
  371. treeConfirmDevice(id, info) {
  372. console.log(id)
  373. },
  374. focusChange(status) {
  375. // console.log('focusChange', status)
  376. },
  377. visualization() {
  378. getVisualization({}).then(res => {
  379. this.typeVisualization = res.Data && res.Data.map(i => this.getTree(i))
  380. console.log(this.typeVisualization)
  381. })
  382. },
  383. getTree(data) {
  384. return {
  385. id: data.Id,
  386. name: data.Name,
  387. children: data.Children ? data.Children.map(i => this.getTree(i)) : []
  388. }
  389. },
  390. focusChange(status) {
  391. console.log('focusChange', status)
  392. }
  393. },
  394. mounted() {
  395. this.visualization()
  396. if (this.title == '修改图例库') {
  397. this.changeLineWidth(this.ruleForm.LineWidth)
  398. this.changeLineType(this.ruleForm.LineDash)
  399. this.initGraph()
  400. }
  401. },
  402. updated() {
  403. if (this.title == '修改图例库') {
  404. this.changeLineWidth(this.ruleForm.LineWidth)
  405. this.changeLineType(this.ruleForm.LineDash)
  406. this.initGraph()
  407. }
  408. }
  409. }
  410. </script>
  411. <style lang='less' scoped>
  412. .add-form {
  413. color: #646c73;
  414. margin: 16px 0 0 72px;
  415. font-size: 14px;
  416. .ant-input-number {
  417. border-radius: 4px 0 0 4px;
  418. }
  419. .form1 {
  420. margin-bottom: 8px;
  421. .span1 {
  422. margin-right: 192px;
  423. }
  424. .span2 {
  425. margin-right: 220px;
  426. }
  427. }
  428. .form2 {
  429. display: flex;
  430. .input-left {
  431. width: 500px;
  432. .title {
  433. margin-right: 100px;
  434. margin: 20px 0 8px 0;
  435. display: inline-block;
  436. width: 250px;
  437. }
  438. .type {
  439. margin-right: 100px;
  440. margin: 20px 0 8px 0;
  441. display: inline-block;
  442. width: 250px;
  443. }
  444. }
  445. .input-right {
  446. width: 200px;
  447. height: 114px;
  448. background: rgba(245, 246, 247, 1);
  449. display: inline-block;
  450. display: flex;
  451. align-items: center;
  452. justify-content: center;
  453. .model1 {
  454. width: 56px;
  455. height: 6px;
  456. }
  457. .model {
  458. width: 56px;
  459. height: 40px;
  460. }
  461. }
  462. }
  463. .form3 {
  464. width: 720px;
  465. height: 86px;
  466. background: rgba(245, 246, 247, 1);
  467. border-radius: 4px;
  468. margin-top: 20px;
  469. .form3-top {
  470. padding: 12px 0 8px 12px;
  471. .form3-span1 {
  472. margin-right: 102px;
  473. }
  474. .form3-span2 {
  475. margin-right: 78px;
  476. }
  477. .form3-span3 {
  478. margin-right: 64px;
  479. }
  480. .form3-span4 {
  481. margin-right: 130px;
  482. }
  483. }
  484. .form3-bottom {
  485. display: flex;
  486. }
  487. }
  488. .form4 {
  489. .form4-top {
  490. padding: 20px 0 8px 0;
  491. .form4-span1 {
  492. margin-right: 32px;
  493. }
  494. .form4-span2 {
  495. margin-right: 102px;
  496. }
  497. }
  498. }
  499. .form5 {
  500. width: 720px;
  501. height: 86px;
  502. background: rgba(245, 246, 247, 1);
  503. border-radius: 4px;
  504. margin-top: 20px;
  505. padding-left: 12px;
  506. .form5-top {
  507. padding: 12px 0 8px 0;
  508. }
  509. }
  510. .span2::after,
  511. .type::after,
  512. .form3-span1::after,
  513. .form3-span3::after {
  514. content: '*';
  515. color: #f56c6c;
  516. margin-left: 4px;
  517. }
  518. .upload-demo {
  519. display: flex;
  520. }
  521. .line-width {
  522. display: inline-block;
  523. width: 35px;
  524. height: 32px;
  525. background: rgba(239, 240, 241, 1);
  526. border-radius: 0 4px 4px 0;
  527. border-right: 1px solid rgba(195, 198, 203, 1);
  528. border-top: 1px solid rgba(195, 198, 203, 1);
  529. border-bottom: 1px solid rgba(195, 198, 203, 1);
  530. position: absolute;
  531. text-align: center;
  532. }
  533. }
  534. </style>