feat: 流程设计器表单字段必填配置

3.x
ssc 3 years ago
parent 066828c91e
commit 0da53c668c
  1. 2
      src/views/plugin/workflow/components/custom-fields/wf-user-select/index.vue
  2. 75
      src/views/plugin/workflow/components/nf-dept-select/index.vue
  3. 20
      src/views/plugin/workflow/mixins/ex-form.js
  4. 30
      src/views/plugin/workflow/utils/index.js

@ -35,7 +35,7 @@ export default {
size: { size: {
type: String, type: String,
default: () => { default: () => {
return 'small' return 'default'
} }
}, },
readonly: { readonly: {

@ -1,12 +1,15 @@
<template> <template>
<el-dialog ref="nf-dialog" <el-dialog
ref="nf-dialog"
class="nf-dialog" class="nf-dialog"
v-model="visible" v-model="visible"
title="部门选择" title="部门选择"
width="60%" width="60%"
:before-close="handleClose" :before-close="handleClose"
append-to-body> append-to-body
<avue-crud v-if="isInit" >
<avue-crud
v-if="isInit && visible"
:option="option" :option="option"
:table-loading="loading" :table-loading="loading"
:data="data" :data="data"
@ -14,21 +17,18 @@
ref="crud" ref="crud"
@search-change="searchChange" @search-change="searchChange"
@search-reset="searchReset" @search-reset="searchReset"
@selection-change="selectionList=$event" @selection-change="selectionList = $event"
@row-click="rowClick" @row-click="rowClick"
@on-load="onLoad" @on-load="onLoad"
@tree-load="treeLoad"> @tree-load="treeLoad"
>
</avue-crud> </avue-crud>
<template #footer> <template #footer>
<span class="dialog-footer"> <span class="dialog-footer">
<el-button @click="handleClose" <el-button @click="handleClose" size="default">取消</el-button>
size="default">取消</el-button> <el-button type="primary" @click="handleConfirm" size="default">确定</el-button>
<el-button type="primary"
@click="handleConfirm"
size="default">确定</el-button>
</span> </span>
</template> </template>
</el-dialog> </el-dialog>
</template> </template>
<script> <script>
@ -40,20 +40,20 @@ export default {
}, },
watch: { watch: {
visible: { visible: {
handler (val) { handler(val) {
if (val) this.changeDefaultChecked() if (val) this.changeDefaultChecked()
}, },
} }
}, },
computed: { computed: {
ids () { ids() {
let ids = []; let ids = [];
this.selectionList.forEach(ele => { this.selectionList.forEach(ele => {
ids.push(ele[this.props.id]); ids.push(ele[this.props.id]);
}); });
return ids.join(","); return ids.join(",");
}, },
names () { names() {
let names = []; let names = [];
this.selectionList.forEach(ele => { this.selectionList.forEach(ele => {
names.push(ele[this.props.name]); names.push(ele[this.props.name]);
@ -61,7 +61,7 @@ export default {
return names.join(","); return names.join(",");
} }
}, },
data () { data() {
return { return {
isInit: false, isInit: false,
visible: false, visible: false,
@ -113,11 +113,11 @@ export default {
} }
} }
}, },
mounted () { mounted() {
this.init() this.init()
}, },
methods: { methods: {
init () { init() {
if (!this.isInit) { if (!this.isInit) {
if (this.customOption) { if (this.customOption) {
const { deptColumn, deptProps } = this.customOption const { deptColumn, deptProps } = this.customOption
@ -127,7 +127,7 @@ export default {
this.isInit = true this.isInit = true
} }
}, },
handleConfirm () { handleConfirm() {
if (this.selectionList.length === 0) { if (this.selectionList.length === 0) {
this.$message.warning("请至少选择一项") this.$message.warning("请至少选择一项")
return return
@ -135,16 +135,16 @@ export default {
this.$emit('confirm', this.ids, this.names) this.$emit('confirm', this.ids, this.names)
this.handleClose() this.handleClose()
}, },
handleClose (done) { handleClose(done) {
// this.selectionClear() // this.selectionClear()
this.visible = false this.visible = false
if (done && typeof done == 'function') done() if (done && typeof done == 'function') done()
}, },
searchReset () { searchReset() {
this.query = {} this.query = {}
this.onLoad(this.page) this.onLoad(this.page)
}, },
searchChange (params, done) { searchChange(params, done) {
this.query = { this.query = {
...params, ...params,
parentId: '' parentId: ''
@ -153,26 +153,31 @@ export default {
this.onLoad(this.page, params) this.onLoad(this.page, params)
done() done()
}, },
selectionClear () { selectionClear() {
this.selectionList = [] this.selectionList = []
if (this.$refs.crud) this.$refs.crud.toggleSelection() if (this.$refs.crud) this.$refs.crud.toggleSelection()
}, },
rowClick (row) { rowClick(row) {
this.$refs.crud.toggleSelection([row]) this.$refs.crud.toggleSelection([row])
}, },
changeDefaultChecked () { changeDefaultChecked() {
this.selectionClear() // this.selectionClear()
if (this.defaultChecked) { if (this.defaultChecked) {
const checks = this.defaultChecked.split(",") const checks = this.defaultChecked.split(",")
if (checks.length > 0) { if (checks.length > 0) {
setTimeout(() => {
checks.forEach(c => { checks.forEach(c => {
const row = this.findRow(this.data, c) let row = this.findRow(this.data, c)
if (row) this.$refs.crud.toggleRowSelection(row, true) if (!row) {
row = this.selectionList.find(d => d.id == c) //
}
if (row && this.$refs.crud) this.$refs.crud.toggleRowSelection(row, true)
}) })
}, 500)
} }
} }
}, },
findRow (list, id) { findRow(list, id) {
if (!list) return if (!list) return
for (let i = 0; i < list.length; i++) { for (let i = 0; i < list.length; i++) {
const data = list[i] const data = list[i]
@ -180,7 +185,7 @@ export default {
else if (data.children) return this.findRow(data.children, id) else if (data.children) return this.findRow(data.children, id)
} }
}, },
onLoad (page, params = {}) { onLoad(page, params = {}) {
this.loading = true; this.loading = true;
const param = { const param = {
parentId: 0, parentId: 0,
@ -189,15 +194,21 @@ export default {
this.$axios.get(this.url, { params: param }).then(res => { this.$axios.get(this.url, { params: param }).then(res => {
this.data = this.getAsVal(res, this.props.data) || [] this.data = this.getAsVal(res, this.props.data) || []
this.loading = false this.loading = false
this.changeDefaultChecked()
}) })
}, },
treeLoad (tree, treeNode, resolve) { treeLoad(tree, treeNode, resolve) {
const parentId = tree.id; const parentId = tree.id;
this.$axios.get(this.url, { params: { parentId } }).then(res => { this.$axios.get(this.url, { params: { parentId } }).then(res => {
resolve(this.getAsVal(res, this.props.data) || []); const list = this.getAsVal(res, this.props.data) || []
resolve(list)
const parent = this.findRow(this.data, parentId)
parent.children = list
this.changeDefaultChecked()
}) })
}, },
getAsVal (obj, bind = '') { getAsVal(obj, bind = '') {
let result = this.deepClone(obj) let result = this.deepClone(obj)
if (this.validatenull(bind)) return result if (this.validatenull(bind)) return result
bind.split('.').forEach(ele => { bind.split('.').forEach(ele => {

@ -18,9 +18,12 @@ import defaultValues from './default-values.js'
import Print from '../utils/print.js' import Print from '../utils/print.js'
import Watermark from '../utils/watermark.js' import Watermark from '../utils/watermark.js'
import { versionCompare } from '../utils/index.js'
import { mapGetters } from 'vuex' import { mapGetters } from 'vuex'
import { version } from '@nutflow/nf-design-elp'
export default { export default {
mixins: [defaultValues], mixins: [defaultValues],
computed: { computed: {
@ -89,7 +92,7 @@ export default {
} }
}) })
}, },
// 根据可读可写,过滤avue column // 根据可读可写,过滤column
filterAvueColumn(column, taskForm, isExForm = false, props = { filterAvueColumn(column, taskForm, isExForm = false, props = {
label: 'label', label: 'label',
prop: 'prop' prop: 'prop'
@ -103,6 +106,9 @@ export default {
const values = [] const values = []
const vars = [] const vars = []
const versionFlag106 = version && versionCompare(version, '1.0.6')
column.forEach(col => { column.forEach(col => {
let c = taskForm.find(s => s.id == col[props.prop]) let c = taskForm.find(s => s.id == col[props.prop])
if (c && c.readable) { if (c && c.readable) {
@ -144,6 +150,18 @@ export default {
}) })
} }
col.display = true col.display = true
// 处理字段必填
let required = false
if (versionFlag106) { // 1.0.6及版本以下,required默认为true
required = true
} else { // 1.0.7流程设计器表单配置支持required属性
required = c.required
}
if (!required && col.rules) {
const index = col.rules.findIndex(c => c.required)
if (index != -1) col.rules.splice(index, 1)
}
} else { } else {
col.display = false col.display = false
} }

@ -0,0 +1,30 @@
/**
* 判断版本号v2是否小于等于v1
*/
export const versionCompare = (v1, v2) => {
if (!v1 || !v2) return true
let v1Arr = v1.split('.')
let v2Arr = v2.split('.')
const len = Math.max(v1Arr.length, v2Arr.length)
// 调整两个版本号位数相同
while (v1Arr.length < len) {
v1Arr.push('0')
}
while (v2Arr.length < len) {
v2Arr.push('0')
}
// 循环判断每位数的大小
for (let i = 0; i < len; i++) {
const num1 = parseInt(v1Arr[i])
const num2 = parseInt(v2Arr[i])
if (num1 > num2) {
return false
} else if (num1 < num2) {
return true
}
}
return true
}
Loading…
Cancel
Save