Эх сурвалжийг харах

feat: useFlowStore processForm 读取调整 为 props 读取

lanceJiang 6 сар өмнө
parent
commit
3148bf8f9b

+ 9 - 1
src/components/scWorkflow/index.vue

@@ -27,7 +27,8 @@ export default {
 	provide() {
 		return {
 			select: this.selectHandle,
-			getRootConfig: this.getCurrentConfig
+			getRootConfig: this.getCurrentConfig,
+			getProcessForm: this.getProcessForm
 		}
 	},
 	props: {
@@ -35,6 +36,10 @@ export default {
 		disabled: {
 			type: Boolean,
 			default: false
+		},
+		processForm: {
+			type: Object,
+			default: () => ({})
 		}
 	},
 	data() {
@@ -64,6 +69,9 @@ export default {
 		getCurrentConfig() {
 			return this.nodeConfig
 		},
+		getProcessForm() {
+			return this.processForm || {}
+		},
 		update_activeSelected(newSelected) {
 			this.activeSelected.splice(0, this.activeSelected.length, ...newSelected)
 		},

+ 3 - 9
src/components/scWorkflow/nodes/approver.vue

@@ -223,7 +223,6 @@ import FormDetail from './formDetail'
 import addNode from './addNode'
 // import { Plus } from '@element-plus/icons-vue'
 import { mapState } from 'pinia' //引入映射函数
-import useFlowStore from '@/store/modules/flow'
 import {
 	approveTypeOptions,
 	approveType_1_options,
@@ -242,7 +241,7 @@ export default {
 		addNode,
 		FormDetail
 	},
-	inject: ['select'],
+	inject: ['select', 'getProcessForm'],
 	props: {
 		modelValue: { type: Object, default: () => {} },
 		disabled: {
@@ -270,12 +269,7 @@ export default {
 			rejectStart_options
 		}
 	},
-	computed: {
-		/*Plus() {
-			return Plus
-		},*/
-		...mapState(useFlowStore, ['processForm']) //映射函数,取出processForm
-	},
+	computed: {},
 	watch: {
 		modelValue() {
 			this.nodeConfig = this.modelValue
@@ -301,7 +295,7 @@ export default {
 		show() {
 			if (this.disabled) return
 			this.form = JSON.parse(JSON.stringify(this.nodeConfig))
-			const { formStructure } = JSON.parse(this.processForm)
+			const { formStructure } = this.getProcessForm()
 			const formConfig = this.form.extendConfig?.formConfig || []
 			const operateTable = (formStructure?.fields || []).map(item => {
 				let opera = '1'

+ 13 - 16
src/components/scWorkflow/nodes/branch.vue

@@ -161,9 +161,7 @@
 <script>
 import addNode from './addNode.vue'
 import { operatorType } from './config'
-import useFlowStore from '@/store/modules/flow'
 import { Delete, Plus, ArrowLeft, Close, ArrowRight, Edit } from '@element-plus/icons-vue'
-import { mapState } from 'pinia'
 import { getNodeKey } from '@/utils/workflow'
 import { ElMessage } from 'element-plus'
 import { $log } from '@/utils'
@@ -172,6 +170,7 @@ export default {
 	components: {
 		addNode
 	},
+	inject: ['getProcessForm'],
 	props: {
 		modelValue: { type: Object, default: () => {} },
 		disabled: {
@@ -191,29 +190,26 @@ export default {
 			local_formStructure: {}
 		}
 	},
-	computed: {
-		...mapState(useFlowStore, ['processForm']) //映射函数,取出processForm
-	},
 	watch: {
 		modelValue() {
 			this.nodeConfig = this.modelValue
-		},
-		processForm: {
-			handler(processForm) {
-				// console.error(processForm, 'processForm  change...', typeof processForm)
-				const { formStructure } = JSON.parse(processForm) // 表单设计字段
-				this.local_formStructure = formStructure
-				// 使用 filter 方法找到 required 属性为 true 的对象
-				this.expressionFormList = (formStructure?.fields || []).filter(item => item.options && item.options.required === true)
-				$log(this.expressionFormList, '这里打印出符合条件的表单对象')
-			},
-			immediate: true
+			this.getExpressionFormList()
 		}
 	},
 	mounted() {
 		this.nodeConfig = this.modelValue
+		this.getExpressionFormList()
 	},
 	methods: {
+		getExpressionFormList() {
+			// const { formStructure } = JSON.parse(processForm) // 表单设计字段
+			const { formStructure } = this.getProcessForm() // 表单设计字段
+			this.local_formStructure = formStructure
+			// 使用 filter 方法找到 required 属性为 true 的对象
+			this.expressionFormList = (formStructure?.fields || []).filter(item => item.options && item.options.required === true)
+			// console.error(formStructure, 'formStructure')
+			// $log(this.expressionFormList, '这里打印出符合条件的表单对象')
+		},
 		show(index) {
 			if (this.disabled) return
 			if (index === this.nodeConfig.conditionNodes.length - 1) {
@@ -336,6 +332,7 @@ export default {
 			const currentCondition = this.form.conditionList[conditionIdx]
 			const field = currentCondition[idx].field
 			const labelObj = this.expressionFormList.find(i => i.key === field)
+			// console.error(labelObj, 'labelObj  getCurrentItemLabel')
 			currentCondition[idx].showLabel = labelObj.label
 			currentCondition[idx].label = field
 		},

+ 12 - 15
src/components/scWorkflow/nodes/mergeBranch.vue

@@ -168,7 +168,6 @@
 <script>
 import addNode from './addNode.vue'
 import { operatorType } from './config'
-import useFlowStore from '@/store/modules/flow'
 import { Delete, Plus, ArrowLeft, Close, ArrowRight, Edit } from '@element-plus/icons-vue'
 import { mapState } from 'pinia'
 import { getNodeKey } from '@/utils/workflow'
@@ -179,6 +178,7 @@ export default {
 	components: {
 		addNode
 	},
+	inject: ['getProcessForm'],
 	props: {
 		modelValue: { type: Object, default: () => {} },
 		disabled: {
@@ -198,29 +198,26 @@ export default {
 			local_formStructure: {}
 		}
 	},
-	computed: {
-		...mapState(useFlowStore, ['processForm']) //映射函数,取出processForm
-	},
 	watch: {
 		modelValue() {
 			this.nodeConfig = this.modelValue
-		},
-		processForm: {
-			handler(processForm) {
-				// console.error(val, 'processForm  change...', typeof val)
-				const { formStructure } = JSON.parse(processForm) // 表单设计字段
-				this.local_formStructure = formStructure
-				// 使用 filter 方法找到 required 属性为 true 的对象
-				this.expressionFormList = (formStructure?.fields || []).filter(item => item.options && item.options.required === true)
-				$log(this.expressionFormList, '这里打印出符合条件的表单对象')
-			},
-			immediate: true
+			this.getExpressionFormList()
 		}
 	},
 	mounted() {
 		this.nodeConfig = this.modelValue
+		this.getExpressionFormList()
 	},
 	methods: {
+		getExpressionFormList() {
+			// const { formStructure } = JSON.parse(processForm) // 表单设计字段
+			const { formStructure } = this.getProcessForm() // 表单设计字段
+			this.local_formStructure = formStructure
+			// 使用 filter 方法找到 required 属性为 true 的对象
+			this.expressionFormList = (formStructure?.fields || []).filter(item => item.options && item.options.required === true)
+			// console.error(formStructure, 'formStructure')
+			// $log(this.expressionFormList, '这里打印出符合条件的表单对象')
+		},
 		show(index) {
 			if (this.disabled) return
 			if (index === this.nodeConfig.inclusiveNodes.length - 1) {

+ 3 - 3
src/components/scWorkflow/nodes/promoter.vue

@@ -67,7 +67,7 @@ export default {
 	components: {
 		addNode
 	},
-	inject: ['select'],
+	inject: ['select', 'getProcessForm'],
 	props: {
 		modelValue: { type: Object, default: () => {} },
 		disabled: {
@@ -87,7 +87,7 @@ export default {
 		/*Plus() {
 			return Plus
 		},*/
-		...mapState(useFlowStore, ['processForm', 'processType']) //映射函数,取出processForm\processType
+		...mapState(useFlowStore, [/*'processForm',*/ 'processType']) //映射函数,取出processForm\processType
 	},
 	watch: {
 		modelValue() {
@@ -103,7 +103,7 @@ export default {
 			this.form = JSON.parse(JSON.stringify(this.nodeConfig))
 			/* 自定义表单权限 - 发起人*/
 			if (this.processType === 'main') {
-				const { formStructure } = JSON.parse(this.processForm)
+				const { formStructure } = this.getProcessForm()
 				const formConfig = this.form.extendConfig?.formConfig || []
 				const operateTable = (formStructure?.fields || []).map(item => {
 					let opera = '1'

+ 11 - 16
src/components/scWorkflow/nodes/routeBranch.vue

@@ -185,8 +185,6 @@
 import addNode from './addNode'
 import { operatorType } from './config'
 import { ElMessage } from 'element-plus'
-import { mapState } from 'pinia'
-import useFlowStore from '@/store/modules/flow'
 import { getNodeKey } from '@/utils/workflow'
 import { $log } from '@/utils'
 
@@ -194,7 +192,7 @@ export default {
 	components: {
 		addNode
 	},
-	inject: ['getRootConfig'],
+	inject: ['getRootConfig', 'getProcessForm'],
 	props: {
 		modelValue: {
 			type: Object,
@@ -216,28 +214,25 @@ export default {
 			validNodeList: []
 		}
 	},
-	computed: {
-		...mapState(useFlowStore, ['processForm']) //映射函数,取出processForm
-	},
 	watch: {
 		modelValue() {
 			this.nodeConfig = this.modelValue
-		},
-		processForm: {
-			handler(processForm) {
-				const { formStructure } = JSON.parse(processForm) // 表单设计字段
-				this.local_formStructure = formStructure
-				// 使用 filter 方法找到 required 属性为 true 的对象
-				this.expressionFormList = (formStructure?.fields || []).filter(item => item.options && item.options.required === true)
-				$log(this.expressionFormList, '这里打印出符合条件的表单对象')
-			},
-			immediate: true
+			this.getExpressionFormList()
 		}
 	},
 	mounted() {
 		this.nodeConfig = this.modelValue
+		this.getExpressionFormList()
 	},
 	methods: {
+		getExpressionFormList() {
+			// const { formStructure } = JSON.parse(processForm) // 表单设计字段
+			const { formStructure } = this.getProcessForm() // 表单设计字段
+			this.local_formStructure = formStructure
+			// 使用 filter 方法找到 required 属性为 true 的对象
+			this.expressionFormList = (formStructure?.fields || []).filter(item => item.options && item.options.required === true)
+			// $log(this.expressionFormList, '这里打印出符合条件的表单对象')
+		},
 		queryValidNodeList() {
 			const validNodeList = []
 			const fn = data => {

+ 3 - 6
src/components/scWorkflow/nodes/subProcess.vue

@@ -111,14 +111,13 @@
 import addNode from './addNode'
 import { subProcessType } from './config'
 import { ElMessage } from 'element-plus'
-import { mapState } from 'pinia'
-import useFlowStore from '@/store/modules/flow'
 import process from '@/api/flow/process'
 
 export default {
 	components: {
 		addNode
 	},
+	inject: ['getProcessForm'],
 	props: {
 		modelValue: { type: Object, default: () => {} },
 		disabled: {
@@ -155,7 +154,8 @@ export default {
 			if (this.disabled) return
 			this.form = {}
 			this.form = JSON.parse(JSON.stringify(this.nodeConfig))
-			const { formStructure } = JSON.parse(this.processForm)
+			// const { formStructure } = JSON.parse(this.processForm)
+			const { formStructure } = this.getProcessForm()
 			const formConfig = this.form.extendConfig?.formConfig || []
 			const operateTable = (formStructure?.fields || []).map(item => {
 				let opera = '1'
@@ -250,9 +250,6 @@ export default {
 			const jumpRouterUrl = `${origin}/${hashFlag ? '#' : ''}/flow_create/child?id=${id}`
 			window.open(jumpRouterUrl)
 		}
-	},
-	computed: {
-		...mapState(useFlowStore, ['processForm']) //映射函数,取出processForm
 	}
 }
 </script>