青锋信息
青锋微信号:QF_qingfeng1024
青锋官网:http://www.qingfeng.plus/
组件使用
设计器新增组件
点击【自定义表单信息】-【新增/编辑】打开表单设计器,在青锋自定义表单下面新增了:当前用户/组织组件和选择用户/组织组件。
当前用户/组织组件
拖拽当前用户/组织组件,在右侧空间属性设置中,需要设置组件的内容设置:
1、当前用户:默认展示当前登录者的名称。
2、当前组织:默认展示当前登录者的组织名称。
选择用户/组织组件
拖拽选择用户/组织组件,在右侧空间属性设置中,需要设置组件的内容设置:
1、选择单用户:点击表单输入框,弹出单用户选择器,选择系统用户。
2、选择单组织:点击表单输入框,弹出单组织选择器,选择系统组织。
3、选择多用户:点击表单输入框,弹出多用户选择器,选择系统用户。
4、选择多组织:点击表单输入框,弹出多组织选择器,选择系统组织。
表单示例
vue端改造
mainjs中设置KFormDesign.setConfig
在main.js中新增组件内容
新增代码如下:
// 引入自定义组件
import currentUserOrganize from './components/k-form-design/customize/currentUserOrganize'
import selectUserOrganize from './components/k-form-design/customize/selectUserOrganize'
Vue.config.productionTip = false
// 使用KFormDesign的setConfig函数添加自定义组件
KFormDesign.setConfig({
title: '青锋定义字段',
list: [
{
type: 'loginUserOrganize', // 组件类型
label: '当前用户/组织', // 组件名称
// icon: 'icon-zidingyiyemian',
component: currentUserOrganize, // 组件
options: {
option_type:"",
defaultValue: "", // 默认值
multiple: false, // 多选
disabled: false, // 禁用
width: '100%', // 宽度
min: 0, // 最小值
max: 99, // 最大值
clearable: true, // 可清除
placeholder: '请选择', // 占位内容
showSearch: false // 可搜索
},
model: '', // 数据字段
key: '',
rules: [ // 校验规则
{
required: false,
message: '必填项'
}
]
},
{
type: 'selectUserOrganize', // 组件类型
label: '选择用户/组织', // 组件名称
// icon: 'icon-zidingyiyemian',
component: selectUserOrganize, // 组件
options: {
option_type:"",
defaultValue: "", // 默认值
multiple: false, // 多选
disabled: false, // 禁用
width: '100%', // 宽度
min: 0, // 最小值
max: 99, // 最大值
clearable: true, // 可清除
placeholder: '请选择', // 占位内容
showSearch: false // 可搜索
},
model: '', // 数据字段
key: '',
rules: [ // 校验规则
{
required: false,
message: '必填项'
}
]
}
]
})
Vue.use(KFormDesign)
新增currentUserOrganize当前用户或组织组件
<template>
<div>
<a-input
hidden
v-model="value"
@input="handleChange"
/>
<a-input v-model="name" v-if="disabled" disabled />
<a-input v-model="name" v-if="!disabled" readOnly placeholder="请输入" @input="handleChange" />
</div>
</template>
<script>
import { mapGetters } from 'vuex'
export default {
name: 'cc',
props: ['record', 'value','disabled'],
// props: {
// record: {
// type: Object,
// require: true
// },
// value: {
// type: String,
// default: ''
// }
// },
data() {
return {
name:''
};
},
methods: {
handleChange (e) {
console.log(e.target.value)
// 使用 onChange 事件修改值
this.$emit('change', e.target.value)
}
},
computed: {
...mapGetters(['currentUser'])
},
mounted () {
console.log("::::"+this.disabled)
// 打印接收的options
if(this.value==''){
if(this.record.options.option_type=='0'){
this.value=this.currentUser.id+":"+this.currentUser.name;
this.name = this.currentUser.name;
this.$emit('change', this.value)
}else if(this.record.options.option_type=='1'){
this.value=this.currentUser.orgPd.organize_id+":"+this.currentUser.orgPd.organize_name
this.name = this.currentUser.orgPd.organize_name;
this.$emit('change', this.value)
}
}else{
this.name = this.value.split(":")[1];
this.$emit('change', this.value)
}
}
}
</script>
新增selectUserOrganize选择用户及组织组件
<template>
<div>
<a-input
hidden
v-model="value"
@input="handleChange"
/>
<a-input
v-model="name"
placeholder="请输入"
v-if="disabled"
disabled
/>
<a-input
v-model="name"
readOnly
placeholder="请输入"
v-if="!disabled"
@click="selectData"
@input="handleChange"
/>
</div>
</template>
<script>
import SelectOneUser from "@/views/system/User/SelectOneUser";
import SelectMoreUser from "@/views/system/User/SelectMoreUser";
import SelectOneOrganize from "@/views/system/Organize/SelectOneOrganize";
import SelectMoreOrganize from "@/views/system/Organize/SelectMoreOrganize";
export default {
name: "cc",
props: ["record", "value","disabled"],
// props: {
// record: {
// type: Object,
// require: true
// },
// value: {
// type: String,
// default: ''
// }
// },
data() {
return {
name:''
};
},
methods: {
handleChange(e) {
console.log(e.target.value);
// 使用 onChange 事件修改值
this.$emit("change", e.target.value);
},
selectData() {
if (this.record.options.option_type == "0") {
const user = {
user_id: this.value.split(":")[0],
user_name: this.value.split(":")[1]
};
this.dialog(SelectOneUser, user);
} else if (this.record.options.option_type == "1") {
const organize = {
organize_id: this.value.split(":")[0],
organize_name: this.value.split(":")[1]
};
this.dialog(SelectOneOrganize, organize);
} else if (this.record.options.option_type == "2") {
const users = {
user_ids: this.value.split(":")[0],
user_names: this.value.split(":")[1]
};
this.dialog(SelectMoreUser, users);
} else if (this.record.options.option_type == "3") {
const organizes = {
organize_ids: this.value.split(":")[0],
organize_names: this.value.split(":")[1]
};
console.log(organizes)
this.dialog(SelectMoreOrganize, organizes);
}
},
dialog(component, record) {
const that = this;
this.$dialog(
component,
// component props
{
record,
on: {
ok() {
console.log("ok 回调");
},
cancel() {
console.log("cancel 回调");
},
close() {
console.log("modal close 回调");
},
initValue(value, type) {
that.name=value.split(":")[1];
that.value=value;
that.$emit("change", value);
},
},
},
// modal props
{
title: "操作",
width: 800,
height: 500,
centered: true,
maskClosable: false,
okText: "确认",
cancelText: "取消",
}
);
},
},
mounted() {
// 打印接收的options
console.log(this.record);
// console.log(this.value)
this.name = this.value.split(":")[1];
},
updated(){
this.name = this.value.split(":")[1];
}
};
</script>
修改拓展设计器的属性
属性修改文件:formItemProperties
增加代码
说明:通过selectItem.type可以获取组件定义的类型,通过点击不同的类型,切换属性内容。
<a-form-item
v-if="typeof options.option_type !== 'undefined' && selectItem.type === 'loginUserOrganize'"
label="选择-当前用户或组织"
>
<a-select default-value="0" v-model="options.option_type">
<a-select-option value="0">
当前用户
</a-select-option>
<a-select-option value="1">
当前组织
</a-select-option>
</a-select>
</a-form-item>
<a-form-item
v-if="typeof options.option_type !== 'undefined' && selectItem.type === 'selectUserOrganize'"
label="选择-当前用户或组织"
>
<a-select default-value="0" v-model="options.option_type">
<a-select-option value="0">
选择单用户
</a-select-option>
<a-select-option value="1">
选择单组织
</a-select-option>
<a-select-option value="2">
选择多用户
</a-select-option>
<a-select-option value="3">
选择多组织
</a-select-option>
</a-select>
</a-form-item>
java后端改造
修改VformServiceImpl
新增代码
//自定义字段的拓展类型
if(vfield.getField_type().equals("loginUserOrganize")||vfield.getField_type().equals("loginUserOrganize")){
String option_type = pp.get("option_type").toString();
vfield.setOption_type(option_type);
}