Commit b1d07201 authored by 王纵's avatar 王纵

表单表格优化

parent 53972300
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: zong.wang01@hand-china.com * @Author: zong.wang01@hand-china.com
* @Date: 2024-08-01 09:55:12 * @Date: 2024-08-01 09:55:12
* @LastEditors: zong.wang01@hand-china.com * @LastEditors: zong.wang01@hand-china.com
* @LastEditTime: 2024-08-19 11:21:18 * @LastEditTime: 2024-08-20 09:56:05
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: 动态渲染-Lov * @Description: 动态渲染-Lov
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
...@@ -116,7 +116,7 @@ export default { ...@@ -116,7 +116,7 @@ export default {
props: { props: {
fieldConfig: { fieldConfig: {
type: Object, type: Object,
default: () => {} default: () => ({})
}, },
name: { name: {
type: String, type: String,
...@@ -132,7 +132,7 @@ export default { ...@@ -132,7 +132,7 @@ export default {
}, },
value: { value: {
type: Object | Array, type: Object | Array,
default: () => {}, default: () => ({}),
}, },
disabled: { disabled: {
type: Boolean, type: Boolean,
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: zong.wang01@hand-china.com * @Author: zong.wang01@hand-china.com
* @Date: 2024-08-01 09:55:12 * @Date: 2024-08-01 09:55:12
* @LastEditors: zong.wang01@hand-china.com * @LastEditors: zong.wang01@hand-china.com
* @LastEditTime: 2024-08-19 11:22:10 * @LastEditTime: 2024-08-20 09:55:39
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: 动态渲染-Select * @Description: 动态渲染-Select
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
...@@ -176,10 +176,11 @@ export default { ...@@ -176,10 +176,11 @@ export default {
}); });
if (this.multiple) { // 多选 if (this.multiple) { // 多选
this.currentValue = selectData; this.currentValue = selectData;
this.fieldValue = this.currentValue.length ? JSON.stringify(this.currentValue) : ''
} else { } else {
this.currentValue = selectData.length ? selectData[0] : { meaning: '', value: '' }; this.currentValue = selectData.length ? selectData[0] : { meaning: '', value: '' };
this.fieldValue = this.currentValue.value;
} }
this.fieldValue = this.currentValue ? JSON.stringify(this.currentValue) : ''
}, },
showSelectOption(flag) { showSelectOption(flag) {
if (!this.disabled) { if (!this.disabled) {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: zong.wang01@hand-china.com * @Author: zong.wang01@hand-china.com
* @Date: 2024-07-29 10:51:56 * @Date: 2024-07-29 10:51:56
* @LastEditors: zong.wang01@hand-china.com * @LastEditors: zong.wang01@hand-china.com
* @LastEditTime: 2024-08-19 10:59:43 * @LastEditTime: 2024-08-20 12:11:27
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: 表单渲染 * @Description: 表单渲染
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
...@@ -119,7 +119,7 @@ ...@@ -119,7 +119,7 @@
:fieldConfig="field" :fieldConfig="field"
:disabled="readOnly || field.readOnly" :disabled="readOnly || field.readOnly"
:required="field.required" :required="field.required"
:getCurrentRecord="getCurrentRecord" :getCurrentRecord="getFieldsValue"
@change="fieldChange" @change="fieldChange"
/> />
</fragment> </fragment>
...@@ -199,7 +199,7 @@ export default { ...@@ -199,7 +199,7 @@ export default {
originFieldsObj: {}, // 重置使用 originFieldsObj: {}, // 重置使用
queryParams: {}, queryParams: {},
readOnly: true, readOnly: true,
status: 'add', status: 'create',
} }
}, },
mounted() { mounted() {
...@@ -221,23 +221,23 @@ export default { ...@@ -221,23 +221,23 @@ export default {
} }
}) })
this.fieldsObj = {...initFields}; this.fieldsObj = {...initFields};
this.status = 'add'; this.status = 'create';
} else { // 详情 } else { // 详情
this.fieldsObj = {...this.record}; this.fieldsObj = {...this.record};
this.status = 'update'; this.status = 'update';
} }
if (this.formType === 'normal') { if (this.formType === 'normal') {
this.addFormRef(this, this.tabInfo.tabCode); //正常表单保存表单组件实例,供页面整体保存时使用
if (this.tabInfo.readUrl) { if (this.tabInfo.readUrl) {
// console.log('D-form-activated', this.tabInfo.readUrl, JSON.stringify(this.queryParams)) // console.log('D-form-activated', this.tabInfo.readUrl, JSON.stringify(this.queryParams))
const res = await getFormData(this.tabInfo.readUrl, this.queryParams) const res = await getFormData(this.tabInfo.readUrl, this.queryParams)
this.fieldsObj = res.content.length ? res.content[0] : {}; this.fieldsObj = res.content.length ? res.content[0] : {};
this.dataLoadHandle(this.fieldsObj, this.tabInfo.tabCode); // 数据查询后的回调 this.dataLoadHandle(this.fieldsObj, this.tabInfo.tabCode); // 数据查询后的回调
this.addFormRef(this, this.tabInfo.tabCode); //正常表单保存表单组件实例,供页面整体保存时使用
this.setDataSetData(this.tabInfo.tabCode, {...this.fieldsObj}); // 保存一份原始数据 this.setDataSetData(this.tabInfo.tabCode, {...this.fieldsObj}); // 保存一份原始数据
this.status = 'update'; this.status = 'update';
} else { } else {
this.status = 'add'; this.status = 'create';
} }
} }
this.formatFieldsValue(); this.formatFieldsValue();
...@@ -335,9 +335,19 @@ export default { ...@@ -335,9 +335,19 @@ export default {
reset() { reset() {
this.fieldsObj = {...this.originFieldsObj}; this.fieldsObj = {...this.originFieldsObj};
}, },
getCurrentRecord() { getFieldsValue(names) {
if (names && names.length) {
let fieldsValue = {};
names.forEach(n => {
fieldsValue[n] = this.fieldsObj[n];
});
return fieldsValue;
}
return this.fieldsObj; return this.fieldsObj;
}, },
setFieldsValue(fieldsValue) {
this.fieldsObj = {...this.fieldsObj, ...fieldsValue};
},
buttonsClick(btn) { buttonsClick(btn) {
const customBtn = this.componentButtons.find(o => o.name === btn.name); // 采用页面传入的方法 const customBtn = this.componentButtons.find(o => o.name === btn.name); // 采用页面传入的方法
if (customBtn && customBtn.clickFunction) { if (customBtn && customBtn.clickFunction) {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: zong.wang01@hand-china.com * @Author: zong.wang01@hand-china.com
* @Date: 2024-07-29 10:51:56 * @Date: 2024-07-29 10:51:56
* @LastEditors: zong.wang01@hand-china.com * @LastEditors: zong.wang01@hand-china.com
* @LastEditTime: 2024-08-19 16:00:59 * @LastEditTime: 2024-08-20 22:52:04
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: 表格渲染 * @Description: 表格渲染
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
...@@ -166,22 +166,17 @@ export default { ...@@ -166,22 +166,17 @@ export default {
this.init(); this.init();
}, },
deactivated() { deactivated() {
EventBus.$off('tableQuery'); EventBus.$off('tableQuery', this.listenHandle);
}, },
beforeDestroy() { beforeDestroy() {
EventBus.$off('tableQuery'); EventBus.$off('tableQuery', this.listenHandle);
}, },
methods: { methods: {
init() { init() {
this.$nextTick(() => { this.$nextTick(() => {
this.dynamicConfigInfo = this.dynamicInfo(); this.dynamicConfigInfo = this.dynamicInfo();
if (this.tabInfo.queryTabCode) { if (this.tabInfo.queryTabCode) {
EventBus.$on('tableQuery', (data, queryTabCode) => { EventBus.$on('tableQuery', this.listenHandle);
if (this.tabInfo.queryTabCode === queryTabCode) {
this.queryParams = data;
this.refresh();
}
});
} }
this.refresh(); this.refresh();
...@@ -194,6 +189,12 @@ export default { ...@@ -194,6 +189,12 @@ export default {
} }
}) })
}, },
listenHandle(data) {
if (this.tabInfo.queryTabCode === data.tabCode) {
this.queryParams = data.values;
this.refresh();
}
},
refresh() { refresh() {
this.page = 0; this.page = 0;
this.tableData = []; this.tableData = [];
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: zong.wang01@hand-china.com * @Author: zong.wang01@hand-china.com
* @Date: 2024-07-29 10:51:56 * @Date: 2024-07-29 10:51:56
* @LastEditors: zong.wang01@hand-china.com * @LastEditors: zong.wang01@hand-china.com
* @LastEditTime: 2024-08-16 15:15:24 * @LastEditTime: 2024-08-20 22:51:47
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: 查询表单渲染 * @Description: 查询表单渲染
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
...@@ -116,7 +116,7 @@ export default { ...@@ -116,7 +116,7 @@ export default {
} }
}); });
delete values._status; delete values._status;
EventBus.$emit('tableQuery', values, this.tabInfo.tabCode); EventBus.$emit('tableQuery', {values, tabCode: this.tabInfo.tabCode});
this.show = false; this.show = false;
}, },
reset() { reset() {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: zong.wang01@hand-china.com * @Author: zong.wang01@hand-china.com
* @Date: 2024-07-30 14:39:47 * @Date: 2024-07-30 14:39:47
* @LastEditors: zong.wang01@hand-china.com * @LastEditors: zong.wang01@hand-china.com
* @LastEditTime: 2024-08-16 11:27:44 * @LastEditTime: 2024-08-20 09:57:50
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: 工具类 * @Description: 工具类
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
...@@ -94,6 +94,25 @@ const dateFormat = (type, time) => { // 时间格式化 2019-09-08 ...@@ -94,6 +94,25 @@ const dateFormat = (type, time) => { // 时间格式化 2019-09-08
} }
}; };
// 根据tabcode获取对应的表单值
const getFormValuesByTabCode = async (dataSets, tabCode) => {
const formRef = dataSets[tabCode].formRef;
if (formRef) {
const values = await formRef.validate();
return values;
}
return {
allValues: {},
formValues: {}
}
}
// 根据tabcode获取对应的组件ref
const getRefByTabCode = (dataSets, tabCode) => {
const formRef = dataSets[tabCode].formRef;
return formRef;
}
const getOrganizationId = () => { const getOrganizationId = () => {
return 0; return 0;
// const globalState = getDvaApp()._store.getState(); // const globalState = getDvaApp()._store.getState();
...@@ -161,6 +180,8 @@ export { ...@@ -161,6 +180,8 @@ export {
getDataSetName, getDataSetName,
dateFormat, dateFormat,
detectOS, detectOS,
getFormValuesByTabCode,
getRefByTabCode,
getOrganizationId, getOrganizationId,
getCurrentUser getCurrentUser
}; };
<!-- <!--
* @Author: zong.wang01@hand-china.com * @Author: zong.wang01@hand-china.com
* @Date: 2024-07-31 18:41:49 * @Date: 2024-08-16 09:39:36
* @LastEditors: zong.wang01@hand-china.com * @LastEditors: zong.wang01@hand-china.com
* @LastEditTime: 2024-08-15 17:42:00 * @LastEditTime: 2024-08-20 11:42:31
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: * @Description: 商机维护详情
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
--> -->
<template> <template>
<Dynamic <Dynamic
layoutCode="PRJ005F1" layoutCode="CN001F1"
:componentRenderers="componentRenderers" :showTitle="false"
:headerButtons="headerButtons" :componentRenderers="componentRenderers"
:layoutButtons="layoutButtons"
:staticLayoutTabs="staticLayoutTabs"
:configLoadHandle="configLoadHandle" :configLoadHandle="configLoadHandle"
:dataLoadHandle="dataLoadHandle" :dataLoadHandle="dataLoadHandle"
:layoutButtons="layoutButtons"
ref="dynamicRef" ref="dynamicRef"
/> />
</template> </template>
<script> <script>
import {Button} from 'vant'; import { NavBar, Button, Search, List, Toast, Dialog } from 'vant';
import Dynamic from '../Dynamic'
import {getFormValuesByTabCode} from '../Dynamic/utils/utils'
// import chanceApi from '../api/chance'
export default { export default {
name: 'DynamicDetail', name: 'DynamicDetail',
components: { components: {
[Button.name]: Button Dynamic,
[NavBar.name]: NavBar,
[Button.name]: Button,
[Search.name]: Search,
[List.name]: List,
[Toast.name]: Toast,
[Dialog.name]: Dialog,
}, },
data () { data () {
return { return {
buttonText: '嵌入内容', config: {},
componentRenderers: [ componentRenderers: [
{ {
tabCode: 'F_BASIC', tabCode: 'G_QUERY_RESULT',
columnName: 'test', columnName: 'projectName',
renderer: (field, getRecord) => { renderer: (record, index) => {
return <span>328388</span> return <span style="color: #3789ff" onClick={() => this.toDetail(record)}>{record.projectName} <van-icon name="arrow" /></span>
}, },
}, },
], ],
headerButtons: [
{
description: '复制',
name: "copy",
},
{
description: '新建',
name: "new",
},
],
layoutButtons: { layoutButtons: {
submit: this.handleHeaderSubmit, submit: this.submit,
remove: this.handleDelete, save: this.save,
copy: this.handleCopyClick
}, },
staticLayoutTabs: [
{
tabCode: 'F_STATIC',
component: (props) => {
return (
<van-button onClick={this.handleCopyClick}>{this.buttonText}</van-button>
)
},
},
]
} }
}, },
methods: { methods: {
configLoadHandle(config) { // 查询配置信息之后的回调 configLoadHandle(config) { // 查询配置信息之后的回调
console.log('configLoadHandle', config) console.log('configLoadHandle', config)
this.config = config;
}, },
dataLoadHandle(data, tabCode) { dataLoadHandle(data, tabCode) {
console.log(tabCode, data); console.log(tabCode, data);
}, },
handleCopyClick() { async save() {
console.log('复制') let saveValues = {};
this.buttonText = '复制' const saveDataSet = this.config.dataSetObject;
const basiceValues = await getFormValuesByTabCode(saveDataSet, 'F_BASIC');
saveValues = {...basiceValues.allValues};
const schemeValues = await getFormValuesByTabCode(saveDataSet, 'F_SCHEME');
saveValues = {...saveValues, ...schemeValues.formValues};
console.log('saveValues', saveValues);
const datas = {
...saveValues,
chanceContactInfoList: [],
chanceProcessList: [],
chanceAttachmentList: []
};
// let res = await chanceApi.save(datas);
// Toast.success('操作成功!');
},
async submit() {
const saveDataSet = this.config.dataSetObject;
const basiceValues = await getFormValuesByTabCode(saveDataSet, 'F_BASIC');
const schemeValues = await getFormValuesByTabCode(saveDataSet, 'F_SCHEME');
let saveValues = {...basiceValues.allValues, ...schemeValues.formValues};
const datas = {
...saveValues,
chanceContactInfoList: [],
chanceProcessList: [],
chanceAttachmentList: []
};
if (saveValues.chanceName == null || saveValues.bpNameLov == null) {
Toast.fail('请输入必填项!');
} else {
Dialog.confirm({
title: '确定提交工作流吗',
// message:'如果解决方法是丑陋的,那就肯定还有更好的解决方法,只是还没有发现而已。',
}).then(() => {
const { chanceId } = this.config.queryParams;
this.checkApproval(chanceId, datas);
});
}
}, },
handleHeaderSubmit() { async checkApproval(chanceId, datas) {
console.log("点击提交") const response = await chanceApi.checkApproval(chanceId);
this.buttonText = '提交' if (response.length === 0) {
this.submitCallback(datas);
} else {
Dialog.confirm({
title: '自选审批人',
// message:'如果解决方法是丑陋的,那就肯定还有更好的解决方法,只是还没有发现而已。',
}).then(() => {
this.submitCallback(datas)
});
// C7nModal.open({
// title: '自选审批人',
// closable: true,
// destroyOnClose: true,
// keyboardClosable: true,
// footer: null,
// children: (
// <OptionalApprovalForm itemList={response} callBack={() => this.submitCallback(datas)} />
// )
// });
}
}, },
handleDelete() { submitCallback(datas) {
console.log("点击删除") // const promise = chanceApi.submit(datas);
// promise.then(
// () => {
// Toast.success('提交成功');
// this.goBack();
// },
// err => {
// Toast.fail(err.message);
// }
// );
}, },
handleNew() {
console.log("点击新建")
}
}, },
} };
</script> </script>
<style lang="less"> <style lang="stylus" scoped>
h4{
font-size: 20px;
margin-left: 15px;
}
a{
width: 100%;
}
</style> </style>
<!-- <!--
* @Author: zong.wang01@hand-china.com * @Author: zong.wang01@hand-china.com
* @Date: 2024-07-29 11:02:22 * @Date: 2024-08-16 09:39:36
* @LastEditors: zong.wang01@hand-china.com * @LastEditors: zong.wang01@hand-china.com
* @LastEditTime: 2024-08-19 14:27:09 * @LastEditTime: 2024-08-20 11:41:44
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: * @Description:
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
--> -->
<template> <template>
<Dynamic <Dynamic
layoutCode="CN001" layoutCode="CN001"
:showTitle="true" :showTitle="false"
:componentRenderers="componentRenderers" :componentRenderers="componentRenderers"
:configLoadHandle="configLoadHandle" :configLoadHandle="configLoadHandle"
:dataLoadHandle="dataLoadHandle" :dataLoadHandle="dataLoadHandle"
:layoutButtons="layoutButtons"
ref="dynamicRef" ref="dynamicRef"
/> />
</template> </template>
<script> <script>
import {Icon} from 'vant'; import { NavBar, Button, Search, List, Toast } from 'vant';
import Dynamic from '../Dynamic'
export default { export default {
name: 'TestDynamic', name: 'TestDynamic',
components: { components: {
[Icon.name]: Icon, Dynamic,
[NavBar.name]: NavBar,
[Button.name]: Button,
[Search.name]: Search,
[List.name]: List,
[Toast.name]: Toast,
}, },
data () { data () {
return { return {
componentRenderers: [ componentRenderers: [
{ {
tabCode: 'G_QUERY_RESULT', tabCode: 'G_RESULT',
columnName: 'projectName', columnName: 'chanceName',
renderer: (record, index) => { renderer: (record, index) => {
return <span style="color: #3789ff" onClick={() => this.toDetail(record)}>{record.projectName} <van-icon name="arrow" /></span> return <span style="color: #3789ff" onClick={() => this.toDetail(record)}>{record.chanceName} <van-icon name="arrow" /></span>
}, },
}, },
] ],
layoutButtons: {
create: this.create,
},
} }
}, },
created() {
window.localStorage.setItem('access_token', '6cb71898-2af9-4c27-a042-b9887b0675f4');
},
methods: { methods: {
configLoadHandle(config) { // 查询配置信息之后的回调 configLoadHandle(config) { // 查询配置信息之后的回调
console.log('configLoadHandle', config) console.log('configLoadHandle', config)
...@@ -51,31 +57,30 @@ export default { ...@@ -51,31 +57,30 @@ export default {
console.log(tabCode, data); console.log(tabCode, data);
}, },
toDetail(record) { toDetail(record) {
this.$router.push({ let readOnly = 'false';
if (
record.chanceStatus === 'APPROVING' ||
record.chanceStatus === 'APPROVED'
) {
readOnly = 'true'
}
this.$router.push({
name: 'DynamicDetail', name: 'DynamicDetail',
params: { params: {
projectId: record.projectId chanceId: record.chanceId,
readOnly
} }
}) })
// this.$router.push({
// name: 'DynamicDetail',
// params: {
// bpId: record.bpId,
// bpName: record.bpName,
// bpCode: record.bpCode,
// }
// })
}, },
create() {
this.$router.push({
name: 'ChanceCreate'
})
}
}, },
} };
</script> </script>
<style lang="less"> <style lang="stylus" scoped>
h4{
font-size: 20px;
margin-left: 15px;
}
a{
width: 100%;
}
</style> </style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment