Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hls-easy-ui
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
easyUI
hls-easy-ui
Commits
7f2823df
Commit
7f2823df
authored
Sep 06, 2024
by
王纵
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
页面按钮默认方法提取到Dynamic组件
parent
47298b37
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
188 additions
and
85 deletions
+188
-85
index.vue
src/Dynamic/ConfigRenderComponent/DForm/index.vue
+2
-2
index.vue
src/Dynamic/LayoutButtons/index.vue
+80
-76
index.vue
src/Dynamic/index.vue
+25
-5
utils.js
src/Dynamic/utils/utils.js
+81
-2
No files found.
src/Dynamic/ConfigRenderComponent/DForm/index.vue
View file @
7f2823df
...
...
@@ -2,7 +2,7 @@
* @Author: zong.wang01@hand-china.com
* @Date: 2024-07-29 10:51:56
* @LastEditors: zong.wang01@hand-china.com
* @LastEditTime: 2024-0
8-21 15:43:2
5
* @LastEditTime: 2024-0
9-06 15:14:4
5
* @Version: 1.0.0
* @Description: 表单渲染
* @Copyright: Copyright (c) 2021, Hand-RongJing
...
...
@@ -235,7 +235,7 @@ export default {
this
.
fieldsObj
=
res
.
content
.
length
?
res
.
content
[
0
]
:
{};
this
.
dataLoadHandle
(
this
.
fieldsObj
,
this
.
tabInfo
.
tabCode
);
// 数据查询后的回调
this
.
setDataSetData
(
this
.
tabInfo
.
tabCode
,
{...
this
.
fieldsObj
});
// 保存一份原始数据
this
.
status
=
'upd
ate'
;
this
.
status
=
res
.
content
.
length
?
'update'
:
'cre
ate'
;
}
else
{
this
.
status
=
'create'
;
}
...
...
src/Dynamic/LayoutButtons/index.vue
View file @
7f2823df
...
...
@@ -2,7 +2,7 @@
* @Author: zong.wang01@hand-china.com
* @Date: 2024-07-31 15:09:30
* @LastEditors: zong.wang01@hand-china.com
* @LastEditTime: 2024-0
8-22 11:24:20
* @LastEditTime: 2024-0
9-06 15:15:19
* @Version: 1.0.0
* @Description: 页面按钮渲染
* @Copyright: Copyright (c) 2021, Hand-RongJing
...
...
@@ -73,6 +73,10 @@ export default {
type
:
Array
,
default
:
()
=>
[]
},
layoutButtonsDefaultFun
:
{
// 默认按钮方法 - 从父组件传入,是为了方便暴露给外层页面调用
type
:
Array
,
default
:
()
=>
[]
},
},
data
()
{
return
{
...
...
@@ -92,10 +96,10 @@ export default {
query
:
'search'
},
allFuns
:
[
{
name
:
'save'
,
clickFunction
:
this
.
saveFunction
,
},
//
{
//
name: 'save',
//
clickFunction: this.saveFunction,
//
},
// {
// name: 'query',
// clickFunction: this.query,
...
...
@@ -113,7 +117,7 @@ export default {
mounted
()
{
this
.
configInfo
=
this
.
dynamicInfo
().
config
;
this
.
readOnly
=
this
.
dynamicInfo
().
queryParams
.
readOnly
;
const
funcs
=
[...
this
.
allFuns
,
...
this
.
headerButtons
,
...
this
.
layoutButtonsFun
];
// 综合按钮方法
const
funcs
=
[...
this
.
layoutButtonsDefaultFun
,
...
this
.
headerButtons
,
...
this
.
layoutButtonsFun
];
// 综合按钮方法
this
.
allFuns
=
[...
new
Map
(
funcs
.
map
(
item
=>
[
item
.
name
,
item
])).
values
()];
this
.
layoutButtons
=
(
this
.
configInfo
.
layoutButtons
||
[]).
concat
(
this
.
headerButtons
).
filter
(
o
=>
this
.
allFuns
.
some
(
e
=>
e
.
name
===
o
.
name
));
this
.
init
();
...
...
@@ -145,77 +149,77 @@ export default {
// remove() {
// },
async
saveFunction
()
{
const
saveDataSet
=
this
.
dynamicInfo
().
dataSetObject
;
const
dataSets
=
{...
saveDataSet
};
for
(
let
key
in
dataSets
)
{
if
(
dataSets
.
hasOwnProperty
(
key
)
&&
dataSets
[
key
].
t
ype
===
'Form'
)
{
// 确保key是对象自身的属性
const
{
instanceRef
}
=
dataSets
[
key
];
if
(
instanceRef
)
{
const
values
=
await
instanceRef
.
validate
();
dataSets
[
key
].
submitValues
=
values
;
}
}
}
const
{
layoutCode
,
metaKeys
,
dataSetMap
}
=
this
.
getDataSets
(
dataSets
);
save
([{
layoutCode
,
metaKeys
,
...
dataSetMap
}]).
then
(
res
=>
{
Toast
.
success
(
'保存成功!'
);
})
},
getDataSets
(
dataSetTree
)
{
const
{
layoutCode
}
=
this
.
dynamicInfo
().
config
;
const
metaKeys
=
{
top
:
[]
};
const
dataSetMap
=
{};
const
serverNames
=
{};
const
saveCheckUrls
=
{};
const
delChackUrls
=
{};
Object
.
values
(
dataSetTree
).
forEach
(
config
=>
{
const
{
parentDataSetName
,
dataSetName
,
baseTable
,
parentTable
,
submitValues
,
savedCheckApi
}
=
config
;
//
async saveFunction() {
//
const saveDataSet = this.dynamicInfo().dataSetObject;
//
const dataSets = {...saveDataSet};
//
for (let key in dataSets) {
// if (dataSets.hasOwnProperty(key) && dataSets[key].tabT
ype==='Form') { // 确保key是对象自身的属性
//
const {instanceRef} = dataSets[key];
//
if(instanceRef) {
//
const values = await instanceRef.validate();
//
dataSets[key].submitValues = values;
//
}
//
}
//
}
//
const {layoutCode, metaKeys, dataSetMap} = this.getDataSets(dataSets);
//
save([{layoutCode, metaKeys, ...dataSetMap}]).then(res => {
//
Toast.success('保存成功!');
//
})
//
},
//
getDataSets(dataSetTree) {
//
const { layoutCode } = this.dynamicInfo().config;
//
const metaKeys = { top: [] };
//
const dataSetMap = {};
//
const serverNames = {};
//
const saveCheckUrls = {};
//
const delChackUrls = {};
//
Object.values(dataSetTree).forEach(config => {
//
const { parentDataSetName, dataSetName, baseTable, parentTable, submitValues, savedCheckApi } = config;
if
(
baseTable
!==
parentTable
)
{
// 不是同一数据源
if
(
parentDataSetName
)
{
if
(
dataSetMap
[
parentDataSetName
])
{
// 存在值
let
currentVal
=
dataSetMap
[
parentDataSetName
][
0
];
currentVal
[
dataSetName
]
=
submitValues
?
[
submitValues
.
allValues
]
:
[];
dataSetMap
[
parentDataSetName
]
=
[
currentVal
];
}
else
{
dataSetMap
[
parentDataSetName
]
=
[{
[
dataSetName
]:
submitValues
?
[
submitValues
.
allValues
]
:
[]
}]
}
metaKeys
[
parentDataSetName
].
push
(
dataSetName
);
metaKeys
[
dataSetName
]
=
[];
}
else
{
if
(
dataSetMap
[
dataSetName
])
{
// 存在值
let
currentVal
=
dataSetMap
[
dataSetName
][
0
];
currentVal
=
{...(
submitValues
?
submitValues
.
allValues
:
{}),
...
currentVal
};
if
(
currentVal
.
childrenDs
)
{
const
childs
=
[...
currentVal
.
childrenDs
];
delete
currentVal
.
childrenDs
;
childs
.
forEach
(
item
=>
{
currentVal
=
{...
currentVal
,
...
item
};
})
}
dataSetMap
[
dataSetName
]
=
[
currentVal
];
}
else
{
dataSetMap
[
dataSetName
]
=
submitValues
?
[
submitValues
.
allValues
]
:
[]
}
metaKeys
.
top
.
push
(
dataSetName
);
metaKeys
[
dataSetName
]
=
[];
}
}
else
if
(
baseTable
)
{
// 复用数据源
if
(
dataSetMap
[
parentDataSetName
])
{
let
currentVal
=
dataSetMap
[
parentDataSetName
][
0
];
dataSetMap
[
parentDataSetName
]
=
[{...
currentVal
,
...(
submitValues
?
submitValues
.
formValues
:
{})}];
}
else
{
dataSetMap
[
parentDataSetName
]
=
[{
childrenDs
:
submitValues
?
submitValues
.
formValues
:
{}}]
}
}
});
return
{
layoutCode
,
metaKeys
,
dataSetMap
,
serverNames
,
saveCheckUrls
,
delChackUrls
}
},
//
if (baseTable !== parentTable) { // 不是同一数据源
//
if (parentDataSetName) {
//
if (dataSetMap[parentDataSetName]) { // 存在值
//
let currentVal = dataSetMap[parentDataSetName][0];
//
currentVal[dataSetName] = submitValues ? [submitValues.allValues] : [];
//
dataSetMap[parentDataSetName] = [currentVal];
//
} else {
//
dataSetMap[parentDataSetName] = [{
//
[dataSetName]: submitValues ? [submitValues.allValues] : []
//
}]
//
}
//
metaKeys[parentDataSetName].push(dataSetName);
//
metaKeys[dataSetName] = [];
//
} else {
//
if (dataSetMap[dataSetName]) { // 存在值
//
let currentVal = dataSetMap[dataSetName][0];
//
currentVal = {...(submitValues ? submitValues.allValues : {}), ...currentVal};
//
if (currentVal.childrenDs) {
//
const childs = [...currentVal.childrenDs];
//
delete currentVal.childrenDs;
//
childs.forEach(item => {
//
currentVal = {...currentVal, ...item};
//
})
//
}
//
dataSetMap[dataSetName] = [currentVal];
//
} else {
//
dataSetMap[dataSetName] = submitValues ? [submitValues.allValues] : []
//
}
//
metaKeys.top.push(dataSetName);
//
metaKeys[dataSetName] = [];
//
}
//
} else if (baseTable) { // 复用数据源
//
if (dataSetMap[parentDataSetName]) {
//
let currentVal = dataSetMap[parentDataSetName][0];
//
dataSetMap[parentDataSetName] = [{...currentVal, ...(submitValues ? submitValues.formValues : {})}];
//
} else {
//
dataSetMap[parentDataSetName] = [{childrenDs: submitValues ? submitValues.formValues : {}}]
//
}
//
}
//
});
//
return {
//
layoutCode, metaKeys, dataSetMap, serverNames, saveCheckUrls, delChackUrls
//
}
//
},
}
}
</
script
>
...
...
src/Dynamic/index.vue
View file @
7f2823df
...
...
@@ -2,7 +2,7 @@
* @Author: zong.wang01@hand-china.com
* @Date: 2024-07-29 10:51:56
* @LastEditors: zong.wang01@hand-china.com
* @LastEditTime: 2024-0
8-21 16:52:03
* @LastEditTime: 2024-0
9-06 15:26:18
* @Version: 1.0.0
* @Description:
* @Copyright: Copyright (c) 2021, Hand-RongJing
...
...
@@ -30,24 +30,27 @@
v-if=
"configDatas.id"
:layoutButtonsFun=
"layoutButtons"
:headerButtons=
"headerButtons"
:layoutButtonsDefaultFun=
"layoutButtonsDefaultFun"
/>
</d-view>
</
template
>
<
script
>
import
{
NavBar
,
Loading
}
from
'vant'
;
import
{
NavBar
,
Loading
,
Toast
}
from
'vant'
;
import
{
DView
,
DHeader
,
DContent
,
DScroll
}
from
'./LayoutComponents'
;
import
LayoutButtons
from
'./LayoutButtons'
;
import
ConfigRenderComponent
from
'./ConfigRenderComponent/index.jsx'
;
import
{
query
,
queryRoute
}
from
'./service'
import
{
query
,
queryRoute
,
save
}
from
'./service'
import
'./index.less'
import
EventBus
from
'./utils/eventBus'
;
import
{
getLayoutSaveData
}
from
'./utils/utils'
;
export
default
{
name
:
'Dynamic'
,
components
:
{
[
Loading
.
name
]:
Loading
,
[
NavBar
.
name
]:
NavBar
,
[
Toast
.
name
]:
Toast
,
LayoutButtons
,
ConfigRenderComponent
,
DView
,
...
...
@@ -105,7 +108,13 @@ export default {
configDatas
:
{},
// 页面配置信息
params
:
{},
// 页面路由参数
dataSetObject
:
{},
// 页面配置信息的dataset
duplicateDs
:
{}
duplicateDs
:
{},
layoutButtonsDefaultFun
:
[
{
name
:
'save'
,
clickFunction
:
this
.
layoutSave
,
},
]
}
},
provide
()
{
...
...
@@ -140,7 +149,7 @@ export default {
this
.
loading
=
true
;
let
readOnly
=
false
// eslint-disable-next-line eqeqeq
if
(
this
.
params
.
readOnly
===
"YES"
||
this
.
params
.
readOnly
==
'
true'
)
{
if
(
this
.
params
.
readOnly
===
"YES"
||
this
.
params
.
readOnly
==
'
Y'
||
this
.
params
.
readOnly
==
'true'
||
this
.
params
.
readOnly
===
true
)
{
readOnly
=
true
}
...
...
@@ -196,6 +205,17 @@ export default {
// componentRenderers: this.componentRenderers // 组件渲染内容
}
},
// 布局按钮保存
async
layoutSave
()
{
const
data
=
await
getLayoutSaveData
(
this
.
getDynamicInfo
());
try
{
const
res
=
await
save
(
data
);
Toast
.
success
(
'保存成功!'
);
return
true
;
}
catch
(
err
)
{
throw
new
Error
(
"保存失败"
);
}
},
backClick
()
{
if
(
this
.
$attrs
[
'onGoBack'
])
{
this
.
$emit
(
'goBack'
);
...
...
src/Dynamic/utils/utils.js
View file @
7f2823df
...
...
@@ -2,7 +2,7 @@
* @Author: zong.wang01@hand-china.com
* @Date: 2024-07-30 14:39:47
* @LastEditors: zong.wang01@hand-china.com
* @LastEditTime: 2024-0
8-21 15:45:48
* @LastEditTime: 2024-0
9-06 15:24:17
* @Version: 1.0.0
* @Description: 工具类
* @Copyright: Copyright (c) 2021, Hand-RongJing
...
...
@@ -182,6 +182,84 @@ const isTenantRoleLevel = () => {
}
/**
* 获取页面布局保存数据
*/
const
getLayoutSaveData
=
async
(
dynamicInfo
)
=>
{
const
saveDataSet
=
dynamicInfo
.
dataSetObject
;
const
dataSets
=
{...
saveDataSet
};
for
(
let
key
in
dataSets
)
{
if
(
dataSets
.
hasOwnProperty
(
key
)
&&
dataSets
[
key
].
tabType
===
'Form'
)
{
// 确保key是对象自身的属性
const
{
instanceRef
}
=
dataSets
[
key
];
if
(
instanceRef
)
{
const
values
=
await
instanceRef
.
validate
();
dataSets
[
key
].
submitValues
=
values
;
}
}
}
const
{
layoutCode
,
metaKeys
,
dataSetMap
}
=
getDataSets
(
dynamicInfo
,
dataSets
);
return
[{
layoutCode
,
metaKeys
,
...
dataSetMap
}];
// save([{layoutCode, metaKeys, ...dataSetMap}]).then(res => {
// saveCallBack(res);
// })
}
const
getDataSets
=
(
dynamicInfo
,
dataSetTree
)
=>
{
const
{
layoutCode
}
=
dynamicInfo
.
config
;
const
metaKeys
=
{
top
:
[]
};
const
dataSetMap
=
{};
const
serverNames
=
{};
const
saveCheckUrls
=
{};
const
delChackUrls
=
{};
Object
.
values
(
dataSetTree
).
forEach
(
config
=>
{
const
{
parentDataSetName
,
dataSetName
,
baseTable
,
parentTable
,
submitValues
,
savedCheckApi
}
=
config
;
if
(
baseTable
!==
parentTable
)
{
// 不是同一数据源
if
(
parentDataSetName
)
{
if
(
dataSetMap
[
parentDataSetName
])
{
// 存在值
let
currentVal
=
dataSetMap
[
parentDataSetName
][
0
];
currentVal
[
dataSetName
]
=
submitValues
?
[
submitValues
.
allValues
]
:
[];
dataSetMap
[
parentDataSetName
]
=
[
currentVal
];
}
else
{
dataSetMap
[
parentDataSetName
]
=
[{
[
dataSetName
]:
submitValues
?
[
submitValues
.
allValues
]
:
[]
}]
}
metaKeys
[
parentDataSetName
].
push
(
dataSetName
);
metaKeys
[
dataSetName
]
=
[];
}
else
{
if
(
dataSetMap
[
dataSetName
])
{
// 存在值
let
currentVal
=
dataSetMap
[
dataSetName
][
0
];
currentVal
=
{...(
submitValues
?
submitValues
.
allValues
:
{}),
...
currentVal
};
if
(
currentVal
.
childrenDs
)
{
const
childs
=
[...
currentVal
.
childrenDs
];
delete
currentVal
.
childrenDs
;
childs
.
forEach
(
item
=>
{
currentVal
=
{...
currentVal
,
...
item
};
})
}
dataSetMap
[
dataSetName
]
=
[
currentVal
];
}
else
{
dataSetMap
[
dataSetName
]
=
submitValues
?
[
submitValues
.
allValues
]
:
[]
}
metaKeys
.
top
.
push
(
dataSetName
);
metaKeys
[
dataSetName
]
=
[];
}
}
else
if
(
baseTable
)
{
// 复用数据源
if
(
dataSetMap
[
parentDataSetName
])
{
let
currentVal
=
dataSetMap
[
parentDataSetName
][
0
];
dataSetMap
[
parentDataSetName
]
=
[{...
currentVal
,
...(
submitValues
?
submitValues
.
formValues
:
{})}];
}
else
{
dataSetMap
[
parentDataSetName
]
=
[{
childrenDs
:
submitValues
?
submitValues
.
formValues
:
{}}]
}
}
});
return
{
layoutCode
,
metaKeys
,
dataSetMap
,
serverNames
,
saveCheckUrls
,
delChackUrls
}
}
export
{
getCustomizedProp
,
getCustomized
,
...
...
@@ -193,5 +271,6 @@ export {
getRefByTabCode
,
getOrganizationId
,
getCurrentUser
,
isTenantRoleLevel
isTenantRoleLevel
,
getLayoutSaveData
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment