index.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <template>
  2. <wrapper
  3. fill
  4. margin
  5. padding
  6. background
  7. >
  8. <el-tabs
  9. :value="active"
  10. class="c-tabs has-bottom-padding"
  11. @tab-click="onTabClick"
  12. >
  13. <el-tab-pane
  14. label="待审核"
  15. name="1"
  16. />
  17. <el-tab-pane
  18. label="已审核"
  19. name="2"
  20. />
  21. <el-tab-pane
  22. label="驳回"
  23. name="3"
  24. />
  25. </el-tabs>
  26. <schema-table
  27. ref="table"
  28. :schema="schema"
  29. @row-click="onToggle"
  30. />
  31. <preview-dialog ref="previewDialog" />
  32. <material-dialog ref="materialDialog" />
  33. <table-dialog
  34. ref="tableDialog"
  35. title="流程历史"
  36. :schema="historySchema"
  37. />
  38. </wrapper>
  39. </template>
  40. <script>
  41. import {
  42. getMyWorkflows,
  43. calendarPublishRestart,
  44. viewHistory,
  45. deleteWorkflow
  46. } from '@/api/workflow'
  47. import {
  48. PublishTargetType,
  49. State,
  50. EventTarget
  51. } from '@/constant'
  52. import { transformCalendarRelease } from '@/views/screen/review/utils'
  53. const Category = {
  54. ASSET: 'minio',
  55. PROGRAM: 'item',
  56. PROGRAM_RECUR: 'carousel',
  57. SCHEDULE: 'program',
  58. CALENDAR: 'calendar'
  59. }
  60. const CategoryInfo = {
  61. [Category.ASSET]: '资源',
  62. [Category.PROGRAM]: '节目',
  63. [Category.PROGRAM_RECUR]: '轮播',
  64. [Category.SCHEDULE]: '排期'
  65. }
  66. export default {
  67. name: 'MyWorkflows',
  68. data () {
  69. return {
  70. active: `${State.SUBMITTED}`,
  71. workflowId: ''
  72. }
  73. },
  74. computed: {
  75. isRejected () {
  76. return this.active === `${State.REJECTED}`
  77. },
  78. schema () {
  79. const isRejected = this.isRejected
  80. return {
  81. condition: { status: Number(this.active) },
  82. list: getMyWorkflows,
  83. transform: this.transformWorkflow,
  84. cols: [
  85. { type: 'expand', refresh: true, render: this.renderRelative },
  86. { prop: 'priority', label: '优先级', width: 80, align: 'center' },
  87. { prop: 'priorityInfo', label: '', width: 80, align: 'center' },
  88. { prop: 'targetInfo', label: '上播内容', width: 80, align: 'center' },
  89. { prop: 'targetName', label: '', 'min-width': 100 },
  90. isRejected ? { prop: 'reason', label: '驳回原因', 'min-width': 100 } : { prop: 'updateTime', label: this.active === `${State.SUBMITTED}` ? '提交时间' : '审批时间', 'min-width': 100 },
  91. { type: 'invoke', width: 200, render: [
  92. isRejected ? { label: '编辑', allow: ({ canResubmit }) => canResubmit, on: this.onEdit } : { label: '查看', on: this.onView },
  93. isRejected ? { label: '重提交', allow: ({ canResubmit }) => canResubmit, on: this.onResubmit } : null,
  94. { label: '历史', on: this.onViewHistory },
  95. isRejected ? { label: '删除', on: this.onDel } : null
  96. ].filter(Boolean) }
  97. ]
  98. }
  99. },
  100. historySchema () {
  101. return {
  102. props: { rowClassName: this.isShowExpend },
  103. listeners: { 'row-click': this.onToggleHistory },
  104. condition: { workflowId: this.workflowId },
  105. list: viewHistory,
  106. transform: this.transformHistory,
  107. cols: [
  108. { type: 'expand', render: this.renderReason },
  109. { prop: 'handledBy', label: '处理人', width: 100 },
  110. { prop: 'createTime', label: '时间' },
  111. { prop: 'tag', type: 'tag' },
  112. { prop: 'reason', label: '备注' }
  113. ]
  114. }
  115. }
  116. },
  117. methods: {
  118. isShowExpend ({ row }) {
  119. if (row.status !== State.REJECTED) {
  120. return 'hide-expend'
  121. }
  122. return ''
  123. },
  124. renderRelative (data, h) {
  125. return h('div', { staticClass: 'o-info' }, [
  126. h('div', null, data.desc),
  127. h('div', { staticClass: 'c-sibling-item--v' }, `设备:${data.device}`),
  128. ...(this.isRejected
  129. ? this.renderRelativeItems(data, h, false)
  130. : [])
  131. ])
  132. },
  133. renderReason (data, h) {
  134. return data.status === State.REJECTED
  135. ? h('div', { staticClass: 'o-info' }, [
  136. ...this.renderRelativeItems(data, h)
  137. ])
  138. : null
  139. },
  140. renderRelativeItems (data, h, isView = true) {
  141. const children = []
  142. if (data.status === State.REJECTED) {
  143. if (data.canResubmit) {
  144. if (data.rejectEvent?.length) {
  145. children.push(h('div', {
  146. staticClass: 'c-sibling-item--v'
  147. }, '驳回对象:'))
  148. children.push(
  149. h('div', {
  150. staticClass: 'l-flex--col',
  151. staticStyle: { 'align-items': 'flex-start' }
  152. }, data.rejectEvent.map(item => this.renderRejectItem(item, h, isView)))
  153. )
  154. }
  155. } else {
  156. children.push(h('div', {
  157. staticClass: 'c-sibling-item--v u-color--error'
  158. }, '发布驳回'))
  159. }
  160. }
  161. return children
  162. },
  163. renderRejectItem (item, h, isView = false) {
  164. const category = CategoryInfo[item.category]
  165. const canClick = !isView && !!category
  166. return h('div', {
  167. staticClass: canClick ? 'u-color--blue has-active u-pointer' : 'u-color--black',
  168. staticStyle: { padding: '4px 0' },
  169. on: canClick
  170. ? {
  171. click: $event => {
  172. $event.stopPropagation()
  173. this.onViewOrEditItem(item)
  174. }
  175. }
  176. : null
  177. }, `${category || ''} ${item.name}`)
  178. },
  179. onViewHistory ({ workflowId }) {
  180. this.workflowId = workflowId
  181. this.$refs.tableDialog.show()
  182. },
  183. onTabClick ({ name: active }) {
  184. if (this.active !== active) {
  185. this.active = active
  186. }
  187. },
  188. transformWorkflow (data) {
  189. return {
  190. workflowId: data.id,
  191. updateTime: data.updateTime,
  192. ...transformCalendarRelease(data.calendarRelease),
  193. ...this.getStatus(data)
  194. }
  195. },
  196. transformHistory (data) {
  197. const { status } = data
  198. return {
  199. ...data,
  200. ...this.getStatus(data),
  201. tag: {
  202. type: ['', 'primary', 'success', 'danger'][status],
  203. label: ['草稿', '提交', '通过', '驳回'][status]
  204. }
  205. }
  206. },
  207. getStatus ({ status, rejectEvent, reason }) {
  208. if (status === State.REJECTED) {
  209. const events = JSON.parse(rejectEvent)
  210. const canResubmit = !(events && events.length === 1 && events[0].category === Category.CALENDAR)
  211. return {
  212. status,
  213. canResubmit,
  214. rejectEvent: (events || []).filter(({ category }) => category !== Category.CALENDAR),
  215. reason
  216. }
  217. }
  218. return {
  219. status,
  220. canResubmit: false
  221. }
  222. },
  223. onToggle (row) {
  224. this.$refs.table.getInst().toggleRowExpansion(row)
  225. },
  226. onToggleHistory (row) {
  227. if (row.status === State.REJECTED) {
  228. this.$refs.tableDialog.getTable().getInst().toggleRowExpansion(row)
  229. }
  230. },
  231. onView ({ target }) {
  232. this.$refs.materialDialog.showPublishTarget(target)
  233. },
  234. onEdit ({ target: { type, detail } }) {
  235. switch (type) {
  236. case PublishTargetType.CALENDAR:
  237. this.$router.push({
  238. name: 'schedule-design',
  239. params: { id: detail }
  240. })
  241. break
  242. case PublishTargetType.EVENT:
  243. if (detail.target.type === EventTarget.RECUR) {
  244. this.$router.push({
  245. name: 'recur-design',
  246. params: { id: detail.target.id }
  247. })
  248. } else {
  249. this.$designProgram(detail.target.id)
  250. }
  251. break
  252. default:
  253. break
  254. }
  255. },
  256. onViewOrEditItem (data) {
  257. switch (data.category) {
  258. case Category.ASSET:
  259. this.$refs.previewDialog.show({
  260. type: data.type,
  261. url: data.id
  262. })
  263. break
  264. case Category.PROGRAM:
  265. this.$designProgram(data.id)
  266. break
  267. case Category.PROGRAM_RECUR:
  268. this.$router.push({
  269. name: 'recur-design',
  270. params: { id: data.id }
  271. })
  272. break
  273. case Category.SCHEDULE:
  274. this.$router.push({
  275. name: 'schedule-design',
  276. params: { id: data.id }
  277. })
  278. break
  279. default:
  280. break
  281. }
  282. },
  283. onResubmit (item) {
  284. calendarPublishRestart(item.workflowId, item.name).then(() => {
  285. this.$refs.table.decrease(1)
  286. })
  287. },
  288. onDel ({ workflowId }) {
  289. deleteWorkflow(workflowId).then(() => {
  290. this.$refs.table.decrease(1)
  291. })
  292. }
  293. }
  294. }
  295. </script>
  296. <style lang="scss" scoped>
  297. ::v-deep .hide-expend .el-table__expand-icon {
  298. display: none;
  299. }
  300. </style>