process.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. <template>
  2. <div class="mod-menu">
  3. <div class="my-menu">
  4. <div class="menu-head">流程类别</div>
  5. <div v-for="(item, index) in menuList" :key="item.id" @click="choseOne(index, item.id)" :class="{'menu-item': true, 'menu-active': active === index}">{{ item.name }}</div>
  6. </div>
  7. <div class="my-process">
  8. <div class="template_box">
  9. <div class="template_in">
  10. <div class="step_box">
  11. <div class='start-steps'>
  12. <button class='start-btn'>开始</button>
  13. </div>
  14. <draggable :list="list" disabled class="list-group" ghost-class="ghost" @start="dragging = true" @end="dragging = false" filter=".undraggable">
  15. <div class="step" v-for="(v, i) in list" :key="v.id">
  16. <textarea class="list-group-item" placeholder="请选择流程" maxlength='30' autofocus readonly="readonly" @focus='iptFocus(v, i)' @blur='iptBlur(v, i)' :value='v.step_name' />
  17. <div class='stepsAdd stepsAdd-before' @click='addBefore(i)'>+</div>
  18. <div class='stepsAdd stepsAdd-after' @click='addAfter(i)'>+</div>
  19. <div class='sb-close' @click='deleteStep(i)'>-</div>
  20. </div>
  21. <div class='end-steps undraggable'>
  22. <button class='end-btn'>结束</button>
  23. <div class='stepsAdd stepsAdd-end' v-if='showEndSteps' @click='addBefore()'>+</div>
  24. </div>
  25. </draggable>
  26. </div>
  27. <div class="stepInfo">
  28. <p>步骤详情(请点击上方加号添加步骤)</p>
  29. <div class="stepDetails">
  30. <el-form ref="stepForm" label-width="120px" :model="stepForm" :rules="stepRules">
  31. <el-form-item label="步骤名称:" prop="step_name">
  32. <el-input v-model="stepForm.step_name" @change='stepnameChange' :disabled="templateAddDisable" placeholder='请输入步骤名称' />
  33. </el-form-item>
  34. <el-form-item label="审批类型:" prop="step_type">
  35. <el-radio-group v-model="stepForm.step_type" @change='steptypeChange' :disabled="templateAddDisable">
  36. <el-radio label="1">会签</el-radio>
  37. <el-radio label="2">或签</el-radio>
  38. </el-radio-group>
  39. </el-form-item>
  40. <el-form-item label="节点审批员:" prop="step_func">
  41. <user-components v-model="stepForm.step_func" :userIds="stepForm.step_func" @change='featureChange' :disabled="templateAddDisable" style="width:100%;"/>
  42. </el-form-item>
  43. </el-form>
  44. </div>
  45. </div>
  46. <div class='confirmBox'>
  47. <el-button :disabled="list.length == 0" type='success' size='medium' style='padding:8px 18px; margin-left:20px; font-size:14px;' @click="deploy">部署</el-button>
  48. <el-button :disabled="list.length == 0" type='primary' size='medium' style='padding:8px 18px; margin-left:20px; font-size:14px;' @click="replace">重置</el-button>
  49. <el-button :disabled="list.length == 0" type='success' size='medium' style='padding:8px 18px; margin-left:20px; font-size:14px;' @click="confirm">提交</el-button>
  50. </div>
  51. </div>
  52. </div>
  53. <!-- <el-steps :active="process.length" align-center>
  54. <el-step v-for="item in process" :key="item.num" :title="item.name" description="可以写流程备注"></el-step>
  55. </el-steps> -->
  56. </div>
  57. <!-- 弹窗, 新增 / 修改 -->
  58. <!-- <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update> -->
  59. </div>
  60. </template>
  61. <script>
  62. // import AddOrUpdate from './menu-add-or-update'
  63. import draggable from 'vuedraggable'
  64. import { workflowUpdate, workflowList, workflowInfot, workflowDeploy } from '@/api/workflow'
  65. import UserComponents from '../common/user-components'
  66. export default {
  67. data () {
  68. return {
  69. id: 0,
  70. showEndSteps: true,
  71. dragging: false,
  72. active: 0,
  73. menuList: [],
  74. list: [],
  75. templateAddDisable: true,
  76. featureItem: [
  77. { id: '1', label: 'Jenkins构建', value: 'build' },
  78. { id: '2', label: '应用部署', value: 'deploy' },
  79. { id: '3', label: '应用验证', value: 'validate' },
  80. { id: '4', label: '镜像同步', value: 'sync' }
  81. ],
  82. stepForm: {
  83. new_or_edit: 'new',
  84. step_name: '',
  85. step_type: '',
  86. step_func: []
  87. },
  88. stepRules: {
  89. step_name: [{ required: true, message: '步骤名称不能为空', trigger: 'blur' }],
  90. step_type: [{ required: true, message: '审批类型不能为空', trigger: 'blur' }],
  91. step_func: [{ required: true, message: '节点审批员不能为空', trigger: 'change' }]
  92. },
  93. index: '',
  94. selectValue: '',
  95. addOrUpdateVisible: false,
  96. item: {}
  97. }
  98. },
  99. components: {
  100. draggable,
  101. UserComponents
  102. },
  103. activated () {
  104. this.getDataList()
  105. },
  106. methods: {
  107. // 获取数据列表
  108. getDataList () {
  109. workflowList({ current: 1, size: 100 }).then(({ data }) => {
  110. if (data.code === '200') {
  111. this.menuList = data.data.records
  112. this.workflowInfot(this.menuList[0].id)
  113. } else {
  114. this.$message.error(data.msg)
  115. }
  116. })
  117. },
  118. workflowInfot (id) {
  119. this.list = []
  120. workflowInfot(id).then(({ data }) => {
  121. if (data.code === '200') {
  122. this.item = data.data
  123. if (this.item.workFlowStepVOs) {
  124. this.item.workFlowStepVOs.forEach((v, index) => {
  125. this.list.push({
  126. id: index + 1,
  127. new_or_edit: 'new',
  128. step_name: v.name,
  129. step_type: v.type,
  130. step_func: v.assigneeIds
  131. })
  132. if (index === 0) {
  133. this.stepForm.step_name = v.name
  134. this.stepForm.step_type = v.type
  135. this.stepForm.step_func = v.assigneeIds
  136. this.templateAddDisable = false
  137. }
  138. })
  139. this.id = this.item.workFlowStepVOs.length - 1
  140. this.$nextTick(() => {
  141. let stepsArrey = document.querySelectorAll('textarea')
  142. this.index = 0
  143. for (let i = 0; i < stepsArrey.length; i++) {
  144. stepsArrey[i].style.backgroundColor = '#ecf5ff'
  145. stepsArrey[i].style.color = '#409eff'
  146. }
  147. stepsArrey[this.index].style.backgroundColor = '#409eff'
  148. stepsArrey[this.index].style.color = '#fff'
  149. })
  150. }
  151. } else {
  152. this.$message.error(data.msg || '未获取到数据')
  153. }
  154. })
  155. },
  156. choseOne (index, id) {
  157. this.active = index
  158. this.workflowInfot(id)
  159. },
  160. // 添加
  161. addBefore (i) {
  162. this.templateAddDisable = false
  163. this.stepForm.step_name = ''
  164. this.stepForm.step_type = ''
  165. this.stepForm.step_func = []
  166. this.list.splice(i, 0, {
  167. id: this.id++,
  168. new_or_edit: 'new',
  169. step_name: '',
  170. step_type: '',
  171. step_func: []
  172. })
  173. if (this.list.length !== 0) {
  174. this.showEndSteps = false
  175. }
  176. this.selectValue = ''
  177. let stepsArrey = document.getElementsByTagName('textarea')
  178. if (i) {
  179. window.setTimeout(() => {
  180. stepsArrey[i].focus()
  181. }, 0)
  182. } else {
  183. window.setTimeout(() => {
  184. stepsArrey[0].focus()
  185. }, 0)
  186. }
  187. },
  188. addAfter (i) {
  189. this.stepForm.step_name = ''
  190. this.stepForm.step_type = ''
  191. this.stepForm.step_func = []
  192. let stepsArrey = document.getElementsByTagName('textarea')
  193. if (i === 0) {
  194. i = i + 1
  195. window.setTimeout(() => { stepsArrey[1].focus() }, 0)
  196. } else if (i > 0) {
  197. i = i + 1
  198. window.setTimeout(() => { stepsArrey[i].focus() }, 0)
  199. }
  200. this.list.splice(i, 0, {
  201. id: this.id++,
  202. new_or_edit: 'new',
  203. step_name: '',
  204. step_type: '',
  205. step_func: []
  206. })
  207. },
  208. deleteStep (i) {
  209. this.list.splice(i, 1)
  210. if (this.list.length === 0) {
  211. this.showEndSteps = true
  212. this.templateAddDisable = true
  213. this.stepForm = { new_or_edit: 'new', step_name: '', step_type: '', step_func: [] }
  214. }
  215. let stepsArrey = document.querySelectorAll('textarea')
  216. for (let i = 0; i < stepsArrey.length; i++) {
  217. stepsArrey[i].style.backgroundColor = '#ecf5ff'
  218. stepsArrey[i].style.color = '#409eff'
  219. }
  220. },
  221. iptFocus (v, i) {
  222. this.stepForm.step_name = v.step_name
  223. this.stepForm.step_type = v.step_type
  224. this.stepForm.step_func = v.step_func
  225. let stepsArrey = document.querySelectorAll('textarea')
  226. this.index = i
  227. for (let i = 0; i < stepsArrey.length; i++) {
  228. stepsArrey[i].style.backgroundColor = '#ecf5ff'
  229. stepsArrey[i].style.color = '#409eff'
  230. }
  231. stepsArrey[this.index].style.backgroundColor = '#409eff'
  232. stepsArrey[this.index].style.color = '#fff'
  233. },
  234. iptBlur (v, i) {
  235. this.index = i
  236. },
  237. stepnameChange (selVal) {
  238. this.list[this.index].step_name = selVal
  239. this.stepForm.step_name = selVal
  240. },
  241. steptypeChange (selVal) {
  242. this.list[this.index].step_type = selVal
  243. },
  244. featureChange (selVal) {
  245. this.list[this.index].step_func = selVal
  246. this.stepForm.step_func = selVal
  247. },
  248. confirm () {
  249. if (this.stepForm.step_name === '') return this.$message.error('步骤名称不能为空')
  250. if (this.stepForm.step_type === '') return this.$message.error('审批类型不能为空')
  251. if (this.stepForm.step_func.length === 0) return this.$message.error('节点审批员不能为空')
  252. let stepsMessage = []
  253. let stepsArrey = document.querySelectorAll('textarea')
  254. for (let i = 0; i < stepsArrey.length; i++) {
  255. stepsArrey[i].style.backgroundColor = '#ecf5ff'
  256. stepsArrey[i].style.color = '#409eff'
  257. }
  258. for (let i = 0; i < stepsArrey.length; i++) {
  259. if (stepsArrey[i].value !== '') {
  260. stepsMessage.push(stepsArrey[i].value)
  261. } else {
  262. for (let i = 0; i < stepsArrey.length; i++) {
  263. if (stepsArrey[i].value === '') {
  264. stepsArrey[i].style.backgroundColor = '#EE1111'
  265. stepsArrey[i].style.color = '#fff'
  266. };
  267. }
  268. return this.$message({type: 'error', message: '请填写完整的流程'})
  269. }
  270. }
  271. const myList = []
  272. this.list.forEach((v, index) => {
  273. myList.push({
  274. assigneeIds: v.step_func,
  275. assigneeType: 1,
  276. name: v.step_name,
  277. type: v.step_type,
  278. sort: index + 1
  279. })
  280. })
  281. let params = {
  282. name: this.item.name,
  283. content: this.item.content,
  284. id: this.item.id,
  285. code: this.item.code,
  286. workFlowStepVOs: myList
  287. }
  288. workflowUpdate(params).then(({ data }) => {
  289. if (data.code === '200') {
  290. this.$message({
  291. message: '操作成功',
  292. type: 'success',
  293. duration: 1500,
  294. onClose: () => {
  295. }
  296. })
  297. } else {
  298. this.$message.error(data.msg)
  299. }
  300. })
  301. },
  302. replace () {
  303. this.list = []
  304. this.stepForm = { new_or_edit: 'new', step_name: '', step_type: '', step_func: '' }
  305. this.templateAddDisable = true
  306. this.showEndSteps = true
  307. },
  308. deploy () {
  309. this.$confirm(`确定对[流程“${this.item.name}”]进行[部署]操作?`, '提示', {
  310. confirmButtonText: '确定',
  311. cancelButtonText: '取消',
  312. type: 'warning'
  313. }).then(() => {
  314. workflowDeploy({modelId: this.item.modelId}).then(({ data }) => {
  315. if (data.code === '200') {
  316. this.$message({
  317. message: '操作成功',
  318. type: 'success',
  319. duration: 1500,
  320. onClose: () => {
  321. }
  322. })
  323. } else {
  324. this.$message.error(data.msg)
  325. }
  326. })
  327. }).catch(() => {})
  328. }
  329. }
  330. }
  331. </script>
  332. <style lang="scss" scoped>
  333. .my-menu{
  334. width: 200px;
  335. position: absolute;
  336. top: 20px;
  337. bottom: 30px;
  338. background: #efefef;
  339. .menu-head{
  340. background-color: #17B3A3;
  341. color: #fff;
  342. font-size: 20px;
  343. line-height: 40px;
  344. padding-left: 10px;
  345. margin-bottom: 10px;
  346. }
  347. .menu-item{
  348. padding-left: 10px;
  349. line-height: 30px;
  350. font-size: 14px;
  351. &:hover{
  352. cursor: pointer;
  353. }
  354. }
  355. .menu-active{
  356. color: #fff;
  357. background-color: #17B3A3;
  358. }
  359. }
  360. .my-process{
  361. padding-left: 210px;
  362. }
  363. .template_box {
  364. background-color: #fff;
  365. .template_in {
  366. padding: 15px 0;
  367. width: 100%;
  368. letter-spacing: 1px;
  369. }
  370. }
  371. /deep/ .el-form-item--small.el-form-item {
  372. margin-bottom: 12px;
  373. }
  374. /deep/ .el-input--small .el-input__inner, .el-input--small .el-textarea__inner {
  375. font-size: 12px;
  376. }
  377. /deep/ .el-input--small .el-textarea__inner {
  378. font-size: 12px;
  379. }
  380. /deep/ .el-input--small .el-input__inner {
  381. height: 28px;
  382. line-height: 28px;
  383. }
  384. /deep/ textarea {
  385. font: 400 13.3333px Arial;
  386. resize: none;
  387. }
  388. /deep/ .step_box textarea {
  389. outline: 0;
  390. caret-color: transparent;
  391. }
  392. .step_box textarea::-webkit-input-placeholder {
  393. color: #ccc;
  394. }
  395. .templateInfo {
  396. padding: 0 30px 2px 50px;
  397. margin: 0 auto;
  398. margin-top: 10px;
  399. width: 600px;
  400. }
  401. .stepInfo {
  402. background-image: linear-gradient(to right, #ccc 0%, #ccc 50%, transparent 50%);
  403. background-size: 14px 2px;
  404. background-repeat: repeat-x;
  405. padding: 10px;
  406. margin: 10px auto 25px;
  407. width: 600px;
  408. p {
  409. font-size: 14px;
  410. color: grey;
  411. margin: 5px 0 15px -10px;
  412. }
  413. }
  414. .confirmBox {
  415. text-align: center;
  416. }
  417. button {
  418. outline: 0;
  419. }
  420. .step_box {
  421. min-height: 72px;
  422. width: 100%;
  423. text-align: center;
  424. display: flex;
  425. justify-content:center;
  426. .start-steps{
  427. width: 120px;
  428. position: relative;
  429. padding: 15px 30px 15px 0;
  430. }
  431. .end-steps {
  432. width: 90px;
  433. position: relative;
  434. padding: 15px 30px 15px 0;
  435. }
  436. .end-steps {
  437. box-sizing: border-box;
  438. position: relative;
  439. padding: 15px 0 15px 15px;
  440. .stepsAdd {
  441. left: -19px;
  442. }
  443. }
  444. .start-btn,
  445. .end-btn {
  446. width: 90px;
  447. height: 40px;
  448. border: 1px solid #b3d8ff;
  449. border-radius: 20px;
  450. text-align: center;
  451. color: #409eff;
  452. line-height: 40px;
  453. font-size: 12px;
  454. cursor: pointer;
  455. background: #ecf5ff;
  456. }
  457. }
  458. .end-steps::before {
  459. content: '';
  460. position: absolute;
  461. top: 50%;
  462. left: -30px;
  463. width: 40px;
  464. height: 1px;
  465. background: #c0c4cc;
  466. }
  467. .end-steps::after {
  468. position: absolute;
  469. content: '';
  470. width: 0;
  471. height: 0;
  472. border-width: 5px;
  473. border-style: dashed solid;
  474. top: 50%;
  475. left: 10px;
  476. margin-top: -4px;
  477. border-color: transparent transparent transparent #c0c4cc;
  478. }
  479. .stepsAdd-before {
  480. display: none;
  481. left: -19px;
  482. z-index: 2;
  483. }
  484. .stepsAdd {
  485. font-size: 14px;
  486. text-align: center;
  487. position: absolute;
  488. top: 50%;
  489. border-radius: 100%;
  490. width: 20px;
  491. height: 20px;
  492. line-height: 18px;
  493. margin-top: -10px;
  494. background-color: #409eff;
  495. color: #fff;
  496. z-index: 1;
  497. cursor: pointer;
  498. }
  499. .stepsAdd-end {
  500. display: block;
  501. }
  502. .stepsAdd-after {
  503. display: none;
  504. right: -1px;
  505. z-index: 2;
  506. }
  507. .end-steps:hover {
  508. .stepsAdd-after {
  509. display: block;
  510. }
  511. }
  512. .step:hover {
  513. .stepsAdd-before {
  514. display: block;
  515. }
  516. .stepsAdd-after {
  517. display: block;
  518. }
  519. .sb-close {
  520. display: block;
  521. }
  522. }
  523. .sb-close {
  524. cursor: default;
  525. display: none;
  526. width: 16px;
  527. height: 16px;
  528. border-radius: 16px;
  529. color: #fff;
  530. text-align: center;
  531. position: absolute;
  532. color: #fff;
  533. background: #f56c6c;
  534. font-size: 16px;
  535. border-radius: 50%;
  536. top: 3px;
  537. right: 23px;
  538. line-height: 12px;
  539. }
  540. .buttons {
  541. margin-top: 35px;
  542. }
  543. .ghost {
  544. opacity: 0.5;
  545. background: #c8ebfb;
  546. }
  547. .list-group {
  548. display: flex;
  549. flex-wrap: wrap;
  550. }
  551. .step::before {
  552. content: '';
  553. position: absolute;
  554. top: 50%;
  555. left: -30px;
  556. width: 40px;
  557. height: 1px;
  558. background: #c0c4cc;
  559. }
  560. .step {
  561. position: relative;
  562. padding: 10px 30px 10px 15px;
  563. }
  564. .step::after {
  565. position: absolute;
  566. content: '';
  567. width: 0;
  568. height: 0;
  569. border-width: 5px;
  570. border-style: dashed solid;
  571. top: 50%;
  572. left: 10px;
  573. margin-top: -4px;
  574. border-color: transparent transparent transparent #c0c4cc;
  575. }
  576. .list-group-item {
  577. position: relative;
  578. width: 90px;
  579. box-sizing: border-box;
  580. border-radius: 4px;
  581. border: 1px solid #409eff;
  582. height: 48px;
  583. overflow: hidden;
  584. cursor: pointer;
  585. text-align: center;
  586. padding: 0 5px;
  587. font-size: 12px;
  588. line-height: 48px;
  589. background: #ecf5ff;
  590. color: #409eff;
  591. }
  592. </style>