|
|
@@ -12,6 +12,7 @@
|
|
|
/>
|
|
|
<div class="c-sibling-item--v u-font-size--sm u-color--black u-bold">目标设备</div>
|
|
|
<schema-table
|
|
|
+ ref="deviceTable"
|
|
|
class="c-sibling-item--v"
|
|
|
:schema="deviceSchema"
|
|
|
/>
|
|
|
@@ -22,6 +23,7 @@
|
|
|
|
|
|
<script>
|
|
|
import { State } from '@/constant'
|
|
|
+import { cancelPublishByDevice } from '../api'
|
|
|
|
|
|
export default {
|
|
|
name: 'WorkflowDetailDialog',
|
|
|
@@ -40,10 +42,32 @@ export default {
|
|
|
] }
|
|
|
]
|
|
|
},
|
|
|
- deviceSchema: {
|
|
|
+ options: {
|
|
|
+ history: false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ deviceSchema () {
|
|
|
+ const canInvoke = this.options.history && this.workflow.status !== State.CANCEL
|
|
|
+ const canBatch = canInvoke && this.workflow.devices.length > 1
|
|
|
+
|
|
|
+ return {
|
|
|
nonPagination: true,
|
|
|
+ listeners: canBatch
|
|
|
+ ? {
|
|
|
+ 'row-click': this.onToggleSelection,
|
|
|
+ 'selection-change': this.onSelectionChange
|
|
|
+ }
|
|
|
+ : null,
|
|
|
list: this.getWorkflowDevices,
|
|
|
+ buttons: canBatch
|
|
|
+ ? [
|
|
|
+ { label: '下架', on: this.onCancelPublishByDevices }
|
|
|
+ ]
|
|
|
+ : null,
|
|
|
cols: [
|
|
|
+ canBatch && { type: 'selection', selectable: ({ singlePublishState }) => singlePublishState === State.RESOLVED },
|
|
|
{ prop: 'deviceName', label: '设备名称' },
|
|
|
{ label: '发布状态', type: 'tag', render: ({ singlePublishState }) => {
|
|
|
switch (singlePublishState) {
|
|
|
@@ -70,14 +94,19 @@ export default {
|
|
|
default:
|
|
|
return null
|
|
|
}
|
|
|
- } }
|
|
|
- ]
|
|
|
+ } },
|
|
|
+ canInvoke && { type: 'invoke', render: [
|
|
|
+ { label: '下架', allow: ({ singlePublishState }) => singlePublishState === State.RESOLVED, on: this.onCancelPublishByDevice }
|
|
|
+ ] }
|
|
|
+ ].filter(Boolean)
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
- show (workflow) {
|
|
|
+ show (workflow, options) {
|
|
|
+ this.$selectionItems = null
|
|
|
this.workflow = workflow
|
|
|
+ this.options = { ...options }
|
|
|
this.$refs.dialog.show()
|
|
|
},
|
|
|
getList () {
|
|
|
@@ -88,6 +117,43 @@ export default {
|
|
|
},
|
|
|
onView ({ target }) {
|
|
|
this.$refs.materialDialog.showPublishTarget(target)
|
|
|
+ },
|
|
|
+ onCancelPublishByDevice (device) {
|
|
|
+ cancelPublishByDevice(this.workflow.id, [device.deviceId]).then(() => {
|
|
|
+ device.singlePublishState = State.CANCEL
|
|
|
+ if (!this.workflow.devices.some(({ singlePublishState }) => singlePublishState !== State.CANCEL)) {
|
|
|
+ this.workflow.status = State.CANCEL
|
|
|
+ }
|
|
|
+ this.$refs.deviceTable.getInst().toggleRowSelection(device, false)
|
|
|
+ })
|
|
|
+ },
|
|
|
+ onToggleSelection (row) {
|
|
|
+ if (row.singlePublishState !== State.RESOLVED) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ this.$refs.deviceTable.getInst().toggleRowSelection(row)
|
|
|
+ },
|
|
|
+ onSelectionChange (val) {
|
|
|
+ console.log(val)
|
|
|
+ this.$selectionItems = val
|
|
|
+ },
|
|
|
+ onCancelPublishByDevices () {
|
|
|
+ if (!this.$selectionItems?.length) {
|
|
|
+ this.$message({
|
|
|
+ type: 'warning',
|
|
|
+ message: '请选择需要下架发布内容的设备'
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ cancelPublishByDevice(this.workflow.id, this.$selectionItems.map(({ deviceId }) => deviceId)).then(() => {
|
|
|
+ this.$selectionItems.forEach(device => {
|
|
|
+ device.singlePublishState = State.CANCEL
|
|
|
+ this.$refs.deviceTable.getInst().toggleRowSelection(device, false)
|
|
|
+ })
|
|
|
+ if (!this.workflow.devices.some(({ singlePublishState }) => singlePublishState !== State.CANCEL)) {
|
|
|
+ this.workflow.status = State.CANCEL
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
}
|
|
|
}
|