ctafts-add-or-detail.vue 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913
  1. <template>
  2. <div>
  3. <el-dialog
  4. :title="display ? '工艺详情' : '新建工艺'"
  5. width="70%"
  6. :close-on-click-modal="false"
  7. :visible.sync="visible">
  8. <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="auto">
  9. <el-row class="my-row">
  10. <el-col :span="8">
  11. <el-form-item label="工艺名称" prop="techName">
  12. <el-input v-model="dataForm.techName" :disabled="display" placeholder="工艺名称"></el-input>
  13. </el-form-item>
  14. </el-col>
  15. <el-col :span="8">
  16. <el-form-item label="工艺版本" prop="techVersion">
  17. <el-input v-model="dataForm.techVersion" :disabled="display" placeholder="工艺版本"></el-input>
  18. </el-form-item>
  19. </el-col>
  20. <el-col :span="8">
  21. <el-form-item label="产品" prop="productId">
  22. <el-select
  23. v-model="dataForm.productId"
  24. :disabled="display"
  25. remote
  26. placeholder="请选择">
  27. <el-option
  28. v-for="item in optionLevel"
  29. :key="item.productId"
  30. :label="item.productName"
  31. :value="item.productId">
  32. </el-option>
  33. </el-select>
  34. </el-form-item>
  35. </el-col>
  36. </el-row>
  37. <el-form-item label="备注说明">
  38. <el-input v-model="dataForm.notes" :disabled="display" placeholder="备注说明"></el-input>
  39. </el-form-item>
  40. <el-form-item label="" label-width="0px">
  41. <upload-component :display="display" :title="'附件'" :accept="'*'" :file-obj-list="fileList" @uploadSuccess="uploadSuccess"/>
  42. </el-form-item>
  43. <!-- <div class="super-flow-demo1">
  44. <div class="node-container">
  45. <span
  46. class="node-item"
  47. v-for="item in nodeItemList"
  48. @mousedown="evt => nodeItemMouseDown(evt, item.value)">
  49. {{ item.label }}
  50. </span>
  51. </div>
  52. <div
  53. class="flow-container"
  54. ref="flowContainer">
  55. <super-flow
  56. ref="superFlow"
  57. :graph-menu="graphMenuList"
  58. :node-menu="nodeMenuList"
  59. :link-menu="linkMenuList"
  60. :link-base-style="linkBaseStyle"
  61. :link-style="linkStyle"
  62. :link-desc="linkDesc">
  63. <template v-slot:node="{meta}">
  64. <div
  65. @mouseup="nodeMouseUp"
  66. @click="nodeClick"
  67. class="flow-node ellipsis">
  68. {{ meta.name }}
  69. </div>
  70. </template>
  71. </super-flow>
  72. </div>
  73. </div> -->
  74. <el-form-item label="工艺步骤" prop="nodeList">
  75. </el-form-item>
  76. <el-row class="my-row" style="height: 350px; background-color: #efefef;">
  77. <super-flow
  78. v-if="visible"
  79. ref="superFlow"
  80. :node-list="nodeList"
  81. :link-list="linkList"
  82. :graph-menu="graphMenuList"
  83. :node-menu="nodeMenuList"
  84. :link-menu="linkMenuList"
  85. :link-desc="linkDesc">
  86. <!-- <template v-slot="node">
  87. <div class="flow-node ellipsis">
  88. {{ node }}
  89. </div>
  90. </template> -->
  91. </super-flow>
  92. </el-row>
  93. </el-form>
  94. <span slot="footer" class="dialog-footer">
  95. <el-button @click="visible = false">取消</el-button>
  96. <el-button v-if="!display" type="primary" @click="dataFormSubmit()">确定</el-button>
  97. </span>
  98. </el-dialog>
  99. <el-dialog
  100. :title="drawerConf.title"
  101. :visible.sync="drawerConf.visible"
  102. :close-on-click-modal="false"
  103. width="500px">
  104. <el-form
  105. @keyup.native.enter="settingSubmit"
  106. @submit.native.prevent
  107. v-show="drawerConf.type === drawerType.node"
  108. ref="nodeSetting"
  109. :rules="dataRule1"
  110. :model="nodeSetting">
  111. <el-row class="my-row">
  112. <el-col :span="24">
  113. <el-form-item
  114. label="节点名称"
  115. prop="name">
  116. <el-input
  117. v-model="nodeSetting.name"
  118. placeholder="请输入节点名称"
  119. maxlength="30">
  120. </el-input>
  121. </el-form-item>
  122. </el-col>
  123. <el-col v-if="drawerConf.prop !== 'start' && drawerConf.prop !== 'end'" :span="12">
  124. <el-form-item
  125. label="节点类型"
  126. prop="type">
  127. <el-select
  128. v-model="nodeSetting.type"
  129. placeholder="请选择">
  130. <el-option
  131. v-for="item in optionsType"
  132. :key="item.value"
  133. :label="item.name"
  134. :value="item.value">
  135. </el-option>
  136. </el-select>
  137. </el-form-item>
  138. </el-col>
  139. <el-col v-if="drawerConf.prop !== 'end'" :span="12">
  140. <el-form-item
  141. label="工种"
  142. prop="workTypeId">
  143. <el-select
  144. v-model="nodeSetting.workTypeId"
  145. placeholder="请选择">
  146. <el-option
  147. v-for="item in optionsType1"
  148. :key="item.typeId"
  149. :label="item.name"
  150. :value="item.typeId">
  151. </el-option>
  152. </el-select>
  153. </el-form-item>
  154. </el-col>
  155. <el-col :span="24">
  156. <el-form-item
  157. label="节点备注"
  158. prop="desc">
  159. <el-input
  160. v-model="nodeSetting.desc"
  161. placeholder="请输入节点备注"
  162. maxlength="30">
  163. </el-input>
  164. </el-form-item>
  165. </el-col>
  166. </el-row>
  167. </el-form>
  168. <!-- <el-form
  169. @keyup.native.enter="settingSubmit"
  170. @submit.native.prevent
  171. v-show="drawerConf.type === drawerType.link"
  172. ref="linkSetting"
  173. :model="linkSetting">
  174. <el-form-item
  175. label="连线描述"
  176. prop="desc">
  177. <el-input
  178. v-model="linkSetting.desc"
  179. placeholder="请输入连线描述">
  180. </el-input>
  181. </el-form-item>
  182. </el-form> -->
  183. <span
  184. slot="footer"
  185. class="dialog-footer">
  186. <el-button
  187. @click="drawerConf.cancel">
  188. 取 消
  189. </el-button>
  190. <el-button
  191. type="primary"
  192. @click="settingSubmit">
  193. 确 定
  194. </el-button>
  195. </span>
  196. </el-dialog>
  197. </div>
  198. </template>
  199. <script>
  200. import { getInfo, getProduct, getWorkType, getStepId } from '@/api/crafts'
  201. import { uuid } from '../common/vue-super-flow/utils'
  202. import UploadComponent from '../common/upload-component'
  203. const drawerType = {
  204. node: 0,
  205. link: 1
  206. }
  207. export default {
  208. name: 'add-or-update',
  209. components: {UploadComponent},
  210. computed: {
  211. orgId: {
  212. get () { return this.$store.state.user.orgId }
  213. }
  214. },
  215. data () {
  216. return {
  217. drawerType,
  218. optionsType: [{value: '1', name: '生产'}, {value: '2', name: '检验'}],
  219. optionsType1: [],
  220. drawerConf: {
  221. title: '',
  222. visible: false,
  223. prop: '',
  224. type: null,
  225. info: null,
  226. open: (type, info) => {
  227. const conf = this.drawerConf
  228. conf.visible = true
  229. conf.type = type
  230. conf.info = info
  231. if (conf.type === drawerType.node) {
  232. conf.title = '节点'
  233. conf.prop = info.meta.prop
  234. if (this.$refs.nodeSetting) this.$refs.nodeSetting.resetFields()
  235. this.$set(this.nodeSetting, 'name', info.meta.name)
  236. this.$set(this.nodeSetting, 'desc', info.meta.desc)
  237. this.$set(this.nodeSetting, 'type', info.meta.type)
  238. this.$set(this.nodeSetting, 'workTypeId', info.meta.workTypeId)
  239. } else {
  240. conf.title = '连线'
  241. if (this.$refs.linkSetting) this.$refs.linkSetting.resetFields()
  242. // this.$set(this.linkSetting, 'desc', info.meta ? info.meta.desc : '')
  243. }
  244. },
  245. cancel: () => {
  246. this.drawerConf.visible = false
  247. if (this.drawerConf.type === drawerType.node) {
  248. this.$refs.nodeSetting.clearValidate()
  249. } else {
  250. this.$refs.linkSetting.clearValidate()
  251. }
  252. }
  253. },
  254. linkSetting: {
  255. desc: ''
  256. },
  257. nodeSetting: {
  258. name: '',
  259. desc: '',
  260. type: 1,
  261. workTypeId: ''
  262. },
  263. nodeList: [],
  264. linkList: [],
  265. datas: {},
  266. graphMenuList: [
  267. [
  268. {
  269. label: '开始节点',
  270. disable (graph) {
  271. return !!graph.nodeList.find(node => node.meta.prop === 'start')
  272. },
  273. selected: async (graph, coordinate) => {
  274. const start = graph.nodeList.find(node => node.meta.prop === 'start')
  275. let id = ''
  276. await getStepId().then(({ data }) => {
  277. id = data.data.stepId
  278. })
  279. if (!start) {
  280. graph.addNode({
  281. width: 90,
  282. height: 50,
  283. coordinate: coordinate,
  284. id: id,
  285. meta: {
  286. prop: 'start',
  287. name: '开始节点'
  288. }
  289. })
  290. }
  291. }
  292. },
  293. {
  294. label: '节点',
  295. disable: false,
  296. selected: async (graph, coordinate) => {
  297. let id = ''
  298. await getStepId().then(({ data }) => {
  299. id = data.data.stepId
  300. })
  301. graph.addNode({
  302. width: 120,
  303. height: 70,
  304. coordinate: coordinate,
  305. id: id,
  306. meta: {
  307. prop: 'condition',
  308. name: '节点名称'
  309. }
  310. })
  311. }
  312. },
  313. {
  314. label: '结束节点',
  315. disable (graph) {
  316. return !!graph.nodeList.find(point => point.meta.prop === 'end')
  317. },
  318. selected: async (graph, coordinate) => {
  319. let id = ''
  320. await getStepId().then(({ data }) => {
  321. id = data.data.stepId
  322. })
  323. graph.addNode({
  324. width: 90,
  325. height: 50,
  326. coordinate: coordinate,
  327. id: id,
  328. meta: {
  329. prop: 'end',
  330. name: '结束节点'
  331. }
  332. })
  333. }
  334. }
  335. ],
  336. [
  337. {
  338. label: '完成',
  339. selected: (graph, coordinate) => {
  340. graph.selectAll()
  341. this.datas = graph
  342. console.log(graph)
  343. }
  344. }
  345. ]
  346. ],
  347. nodeMenuList: [
  348. [
  349. {
  350. label: '删除',
  351. disable: false,
  352. hidden (node) {
  353. return node.meta.prop === 'start'
  354. },
  355. selected (node, coordinate) {
  356. node.remove()
  357. }
  358. }
  359. ],
  360. [
  361. {
  362. label: '编辑',
  363. selected: (node, coordinate) => {
  364. this.drawerConf.open(drawerType.node, node)
  365. }
  366. }
  367. ]
  368. ],
  369. linkMenuList: [
  370. [
  371. {
  372. label: '删除',
  373. selected: (link, coordinate) => {
  374. link.remove()
  375. }
  376. }
  377. ]
  378. // [
  379. // {
  380. // label: '编辑',
  381. // selected: (link, coordinate) => {
  382. // this.drawerConf.open(drawerType.link, link)
  383. // }
  384. // }
  385. // ]
  386. ],
  387. visible: false,
  388. display: false,
  389. fileList: [],
  390. dataList: [],
  391. id: 0,
  392. dataForm: {
  393. techName: '',
  394. techVersion: '',
  395. productId: '',
  396. notes: ''
  397. },
  398. previewPath: '',
  399. previewName: '',
  400. previewVisible: false,
  401. optionsProducts: [],
  402. optionLevel: [],
  403. nodeItemList: [
  404. {
  405. label: '开始节点',
  406. value: () => ({
  407. width: 120,
  408. height: 40,
  409. meta: {
  410. prop: 'start',
  411. name: '开始节点'
  412. }
  413. })
  414. },
  415. {
  416. label: '节点',
  417. value: () => ({
  418. width: 120,
  419. height: 40,
  420. meta: {
  421. prop: 'condition',
  422. name: '节点'
  423. }
  424. })
  425. },
  426. {
  427. label: '结束节点',
  428. value: () => ({
  429. width: 120,
  430. height: 40,
  431. meta: {
  432. prop: 'end',
  433. name: '结束节点'
  434. }
  435. })
  436. }
  437. ],
  438. dragConf: {
  439. isDown: false,
  440. isMove: false,
  441. offsetTop: 0,
  442. offsetLeft: 0,
  443. clientX: 0,
  444. clientY: 0,
  445. ele: null,
  446. info: null
  447. },
  448. linkBaseStyle: {
  449. color: '#666666', // line 颜色
  450. hover: '#FF0000', // line hover 的颜色
  451. textColor: '#666666', // line 描述文字颜色
  452. textHover: '#FF0000', // line 描述文字 hover 颜色
  453. font: '14px Arial', // line 描述文字 字体设置 参考 canvas font
  454. dotted: false, // 是否是虚线
  455. lineDash: [4, 4], // 虚线时生效
  456. background: 'rgba(255,255,255,0.6)' // 描述文字背景色
  457. },
  458. dataRule: {
  459. techName: [{ required: true, message: '工艺名称不能为空', trigger: 'blur' }],
  460. techVersion: [{ required: true, message: '工艺版本不能为空', trigger: 'blur' }],
  461. productId: [{ required: true, message: '产品不能为空', trigger: 'change' }]
  462. },
  463. dataRule1: {
  464. name: [{ required: true, message: '节点名称不能为空', trigger: 'blur' }],
  465. type: [{ required: true, message: '节点类型不能为空', trigger: 'change' }],
  466. workTypeId: [{ required: true, message: '工种不能为空', trigger: 'change' }]
  467. }
  468. }
  469. },
  470. created () {
  471. this.getWorkType()
  472. },
  473. methods: {
  474. async init (id, display) {
  475. this.nodeList = []
  476. this.linkList = []
  477. this.dataForm = {
  478. techName: '',
  479. techVersion: '',
  480. productId: '',
  481. notes: ''
  482. }
  483. this.visible = true
  484. this.display = display
  485. await getProduct({ current: 1, size: 20000 }).then(({data}) => {
  486. if (data && data.code === '200') {
  487. this.optionLevel = data.data.records
  488. }
  489. })
  490. if (!id) return
  491. await getInfo(id).then(async ({data}) => {
  492. if (data && data.code === '200') {
  493. this.dataForm = data.data
  494. // 图纸
  495. if (data.data.proTechnologyStepLists) {
  496. const dataline = []
  497. const datanode = []
  498. await data.data.proTechnologyStepLists.forEach((v, i) => {
  499. // eslint-disable-next-line no-unused-vars
  500. const sortNo = []
  501. const datas = v.sort((a, b) => Number(a['sortNo']) - Number(b['sortNo']))
  502. datas.forEach((item, index) => {
  503. const find = datanode.find(map => map.id === item.stepId)
  504. if (!find) {
  505. datanode.push({
  506. id: item.stepId,
  507. width: (index === 0 || item.workTypeId === '0') ? 90 : 120,
  508. height: (index === 0 || item.workTypeId === '0') ? 50 : 70,
  509. coordinate: item.coordinate.split(','),
  510. meta: {
  511. name: item.stepName,
  512. notes: item.notes || '',
  513. workTypeId: item.workTypeId || '',
  514. type: item.type || ''
  515. }
  516. })
  517. }
  518. const id = item.stepId
  519. if ((index + 1) < datas.length) {
  520. if (datas[index + 1]) {
  521. dataline.push({
  522. id: uuid('link'),
  523. startId: id,
  524. endId: datas[index + 1].stepId,
  525. meta: '',
  526. startAt: [(index === 0 || item.workTypeId === '0') ? 90 : 120, (index === 0 || item.workTypeId === '0') ? 25 : 35],
  527. endAt: [0, (index === 0 || item.workTypeId === '0') ? 25 : 35]
  528. })
  529. }
  530. }
  531. })
  532. })
  533. this.$nextTick(() => {
  534. setTimeout(() => {
  535. this.nodeList = datanode
  536. this.linkList = dataline
  537. }, 200)
  538. })
  539. }
  540. }
  541. })
  542. },
  543. getWorkType () {
  544. getWorkType().then(({data}) => {
  545. if (data && data.code === '200') {
  546. this.optionsType1 = data.data
  547. }
  548. })
  549. },
  550. handleRemove (file, fileList) {
  551. this.fileList = fileList
  552. },
  553. handleChange (file, fileList) {
  554. this.fileList = fileList
  555. },
  556. handleExceed (files, fileList) {
  557. this.$message.warning(`当前限制选择 5 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`)
  558. },
  559. validateField (type) {
  560. this.$refs.dataForm.validateField(type)
  561. },
  562. getLineData (dataAll, dList, lList, id, sortNo) {
  563. debugger
  564. const _l = []
  565. lList.forEach(l => {
  566. if (l.start.id === id) {
  567. _l.push(l.end.id)
  568. }
  569. })
  570. if (!sortNo) {
  571. const data = dList.filter(v => v.meta.prop === 'start')[0]
  572. _l.forEach(item => {
  573. dataAll.push([{
  574. 'notes': data.meta.desc || '',
  575. 'sortNo': 0,
  576. 'stepId': data.id,
  577. 'stepName': data.meta.name,
  578. 'workTypeId': v.meta.prop === 'end' ? '4' : (data.meta.workTypeId || null),
  579. 'type': data.meta.type || null,
  580. 'coordinate': data.coordinate.join(',')
  581. }])
  582. })
  583. }
  584. dList.forEach(v => {
  585. const _i = _l.indexOf(v.id)
  586. if (_i > -1) {
  587. if (!v.meta.workTypeId && v.meta.prop !== 'end') {
  588. this.$message.error('完善节点工种')
  589. return
  590. }
  591. if (!sortNo) {
  592. dataAll[_i].push({
  593. 'notes': v.meta.desc || '',
  594. 'sortNo': (sortNo + 1),
  595. 'stepId': v.id,
  596. 'stepName': v.meta.name,
  597. 'workTypeId': v.meta.prop === 'end' ? '4' : (v.meta.workTypeId || null),
  598. 'type': v.meta.type || null,
  599. 'coordinate': v.coordinate.join(',')
  600. })
  601. this.getLineData(dataAll[_i], dList, lList, v.id, (sortNo + 1))
  602. } else {
  603. let _has = false
  604. dataAll.forEach(items => {
  605. if (items.stepId === v.id) {
  606. _has = true
  607. }
  608. })
  609. if (!_has) {
  610. dataAll.push({
  611. 'notes': v.meta.desc || '',
  612. 'sortNo': (sortNo + 1),
  613. 'stepId': v.id,
  614. 'stepName': v.meta.name,
  615. 'workTypeId': v.meta.prop === 'end' ? 4 : (v.meta.workTypeId || ''),
  616. 'type': v.meta.type || '',
  617. 'coordinate': v.coordinate.join(',')
  618. })
  619. }
  620. this.getLineData(dataAll, dList, lList, v.id, (sortNo + 1))
  621. }
  622. }
  623. })
  624. },
  625. // 表单提交
  626. dataFormSubmit () {
  627. if (!this.datas.nodeList) {
  628. this.$message.error('请先完成流程图!')
  629. return
  630. }
  631. if (this.datas.nodeList.length <= 2) {
  632. this.$message.error('请先完成流程图!')
  633. return
  634. }
  635. this.$refs['dataForm'].validate((valid) => {
  636. if (valid) {
  637. const proTechnologyStepLists = []
  638. let has = false
  639. let has1 = false
  640. this.datas.nodeList.forEach(v => {
  641. if (v.meta.prop === 'start') {
  642. has = true
  643. this.getLineData(proTechnologyStepLists, this.datas.nodeList, this.datas.linkList, v.id, 0)
  644. }
  645. if (v.meta.prop === 'end') {
  646. has1 = true
  647. }
  648. })
  649. if (!has) {
  650. this.$message.error('成流程图没有开始结点!')
  651. return
  652. }
  653. if (!has1) {
  654. this.$message.error('成流程图没有结束结点!')
  655. return
  656. }
  657. if (proTechnologyStepLists.length === 0) {
  658. this.$message.error('请先完成流程图!')
  659. return
  660. }
  661. // 填充附件
  662. let fList = this.fileList
  663. if (fList.length > 0) {
  664. this.dataForm.attachList = []
  665. for (let i = 0; i < fList.length; i++) {
  666. this.dataForm.attachList.push({
  667. fileName: fList[i].name,
  668. url: fList[i].url
  669. })
  670. }
  671. }
  672. this.$http({
  673. url: this.$http.adornUrl(`/biz-service/technology/submit`),
  674. method: 'post',
  675. data: this.$http.adornData({...this.dataForm, proTechnologyStepLists: proTechnologyStepLists})
  676. }).then(({data}) => {
  677. if (data && data.code === '200') {
  678. this.$message({
  679. message: '操作成功',
  680. type: 'success',
  681. duration: 1500,
  682. onClose: () => {
  683. this.$emit('refreshDataList')
  684. this.visible = false
  685. }
  686. })
  687. } else {
  688. this.$message.error(data.msg)
  689. }
  690. })
  691. }
  692. })
  693. },
  694. enterIntercept (formNode, toNode, graph) {
  695. const formType = formNode.meta.prop
  696. switch (toNode.meta.prop) {
  697. case 'start':
  698. return false
  699. case 'approval':
  700. return [
  701. 'start',
  702. 'approval',
  703. 'condition',
  704. 'cc'
  705. ].includes(formType)
  706. case 'condition':
  707. return [
  708. 'start',
  709. 'approval',
  710. 'condition',
  711. 'cc'
  712. ].includes(formType)
  713. case 'end':
  714. return [
  715. 'approval',
  716. 'cc'
  717. ].includes(formType)
  718. default:
  719. return true
  720. }
  721. },
  722. outputIntercept (node, graph) {
  723. return !(node.meta.prop === 'end')
  724. },
  725. linkDesc (link) {
  726. return link.meta ? link.meta.desc : ''
  727. },
  728. settingSubmit () {
  729. this.$refs['nodeSetting'].validate((valid) => {
  730. if (valid) {
  731. const conf = this.drawerConf
  732. // 节点
  733. if (this.drawerConf.type === drawerType.node) {
  734. if (!conf.info.meta) conf.info.meta = {}
  735. Object.keys(this.nodeSetting).forEach(key => {
  736. this.$set(conf.info.meta, key, this.nodeSetting[key])
  737. })
  738. this.$refs.nodeSetting.resetFields()
  739. } else {
  740. // 连线
  741. if (!conf.info.meta) conf.info.meta = {}
  742. Object.keys(this.linkSetting).forEach(key => {
  743. this.$set(conf.info.meta, key, this.linkSetting[key])
  744. })
  745. this.$refs.linkSetting.resetFields()
  746. }
  747. conf.visible = false
  748. }
  749. })
  750. },
  751. uploadSuccess (fileList) {
  752. this.fileList = fileList
  753. },
  754. docMousemove ({ clientX, clientY }) {
  755. const conf = this.dragConf
  756. if (conf.isMove) {
  757. conf.ele.style.top = clientY - conf.offsetTop + 'px'
  758. conf.ele.style.left = clientX - conf.offsetLeft + 'px'
  759. } else if (conf.isDown) {
  760. // 鼠标移动量大于 5 时 移动状态生效
  761. conf.isMove =
  762. Math.abs(clientX - conf.clientX) > 5 || Math.abs(clientY - conf.clientY) > 5
  763. }
  764. },
  765. docMouseup ({ clientX, clientY }) {
  766. const conf = this.dragConf
  767. conf.isDown = false
  768. if (conf.isMove) {
  769. const {
  770. top,
  771. right,
  772. bottom,
  773. left
  774. } = this.$refs.flowContainer.getBoundingClientRect()
  775. // 判断鼠标是否进入 flow container
  776. if (clientX > left && clientX < right && clientY > top && clientY < bottom) {
  777. // 获取拖动元素左上角相对 super flow 区域原点坐标
  778. const coordinate = this.$refs.superFlow.getMouseCoordinate(
  779. clientX - conf.offsetLeft,
  780. clientY - conf.offsetTop
  781. )
  782. // 添加节点
  783. this.$refs.superFlow.addNode({
  784. coordinate,
  785. ...conf.info
  786. })
  787. }
  788. conf.isMove = false
  789. }
  790. if (conf.ele) {
  791. conf.ele.remove()
  792. conf.ele = null
  793. }
  794. },
  795. nodeItemMouseDown (evt, infoFun) {
  796. const {
  797. clientX,
  798. clientY,
  799. currentTarget
  800. } = evt
  801. const {
  802. top,
  803. left
  804. } = evt.currentTarget.getBoundingClientRect()
  805. const conf = this.dragConf
  806. const ele = currentTarget.cloneNode(true)
  807. Object.assign(this.dragConf, {
  808. offsetLeft: clientX - left,
  809. offsetTop: clientY - top,
  810. clientX: clientX,
  811. clientY: clientY,
  812. info: infoFun(),
  813. ele,
  814. isDown: true
  815. })
  816. ele.style.position = 'fixed'
  817. ele.style.margin = '0'
  818. ele.style.top = clientY - conf.offsetTop + 'px'
  819. ele.style.left = clientX - conf.offsetLeft + 'px'
  820. this.$el.appendChild(this.dragConf.ele)
  821. },
  822. linkStyle (link) {
  823. if (link.meta && link.meta.desc === '1') {
  824. return {
  825. color: 'red',
  826. hover: '#FF00FF',
  827. dotted: true
  828. }
  829. } else {
  830. return {}
  831. }
  832. },
  833. nodeMouseUp (evt) {
  834. evt.preventDefault()
  835. },
  836. nodeClick () {
  837. console.log(arguments)
  838. }
  839. }
  840. }
  841. </script>
  842. <style lang="less" scoped>
  843. .super-flow__node {
  844. .flow-node {
  845. > header {
  846. font-size : 14px;
  847. height : 32px;
  848. line-height : 32px;
  849. padding : 0 12px;
  850. color : #ffffff;
  851. }
  852. > section {
  853. text-align : center;
  854. line-height : 20px;
  855. overflow : hidden;
  856. padding : 6px 12px;
  857. word-break : break-all;
  858. }
  859. &.flow-node-start {
  860. > header {
  861. background-color : #55abfc;
  862. }
  863. }
  864. &.flow-node-condition {
  865. > header {
  866. background-color : #BC1D16;
  867. }
  868. }
  869. &.flow-node-approval {
  870. > header {
  871. background-color : rgba(188, 181, 58, 0.76);
  872. }
  873. }
  874. &.flow-node-cc {
  875. > header {
  876. background-color : #30b95c;
  877. }
  878. }
  879. &.flow-node-end {
  880. > header {
  881. height : 50px;
  882. line-height : 50px;
  883. background-color : rgb(0, 0, 0);
  884. }
  885. }
  886. }
  887. }
  888. </style>