Commit f5ee7b1c authored by 王纵's avatar 王纵

页面大保存默认逻辑

parent bddd72f8
<!--
* @Author: zong.wang01@hand-china.com
* @Date: 2024-07-31 15:09:30
* @LastEditors: zong.wang01@hand-china.com
* @LastEditTime: 2024-08-05 17:46:19
* @Version: 1.0.0
* @Description: 按钮渲染
* @Copyright: Copyright (c) 2021, Hand-RongJing
-->
<template>
<div class="d-buttons">
<van-button
v-for="btn in defaultBtns"
round
type="info"
size="mini"
:key="btn.name"
class="d-button"
@click="handlClick(btn)"
>{{btn.description}}</van-button>
<fragment v-if="buttons.length > num">
<span class="d-button-more" @click="more"><van-icon name="more-o" />更多</span>
<div class="d-button-more-content" :style="{display: moreVisible ? 'flex' : 'none'}">
<van-button
v-for="btn in hideBtns"
round
type="info"
size="mini"
:key="btn.name"
class="d-button"
@click="handlClick(btn)"
>{{btn.description}}</van-button>
</div>
</fragment>
<fragment v-else>
</fragment>
</div>
</template>
<script>
import { Button, Icon } from 'vant';
export default {
name: 'DButtons',
components: {
[Button.name]: Button,
[Icon.name]: Icon,
},
props: {
tabInfo: { // 配置信息
type: Object,
default: () => {}
},
buttons: {
type: Array,
default: () => [],
},
},
data () {
return {
num: 2,
defaultBtns: [],
hideBtns: [],
moreVisible: false,
}
},
mounted() {
document.addEventListener('click', this.clickEle, false)
this.init();
},
destroyed () {
document.removeEventListener('click', this.clickEle, false)
},
methods: {
clickEle (e) {
let content = document.querySelector('.d-buttons')
if ((content && !content.contains(e.target))) {
this.moreVisible = false;
}
},
init() {
if(this.buttons.length > this.num) {
this.defaultBtns = this.buttons.slice(0, this.num);
this.hideBtns = this.buttons.slice(this.num, this.buttons.length);
} else {
this.defaultBtns = [...this.buttons];
}
},
more() {
this.moreVisible = true;
},
handlClick(btn) {
this.moreVisible = false;
console.log(btn.name)
}
},
}
</script>
<style scoped lang="less">
.d-buttons {
display: flex;
position: relative;
align-items: center;
justify-content: end;
.d-button {
padding: 0 12px;
height: 24px;
margin-left: 12px;
}
.d-button-more {
color: #666666;
font-size: 12px;
padding: 5px 8px;
margin-left: 12px;
}
.d-button-more-content {
z-index: 1;
position: absolute;
right: 0;
top: 100%;
display: flex;
flex-direction: column;
.d-button {
margin-top: 8px;
}
}
}
</style>
...@@ -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-12 11:15:28 * @LastEditTime: 2024-08-13 15:47:01
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: 动态渲染-复选框组件 * @Description: 动态渲染-复选框组件
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
<van-field <van-field
:disabled="disabled" :disabled="disabled"
:required="required" :required="required"
:name="name"
:rules="[{ required, message: `请填写${label}` }]" :rules="[{ required, message: `请填写${label}` }]"
> >
<d-label :label="label" :help="help" slot="label" /> <d-label :label="label" :help="help" slot="label" />
...@@ -42,6 +43,10 @@ export default { ...@@ -42,6 +43,10 @@ export default {
DLabel DLabel
}, },
props: { props: {
name: {
type: String,
default: ''
},
help: { help: {
type: String, type: String,
default: '' default: ''
......
...@@ -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-09 18:21:29 * @LastEditTime: 2024-08-14 09:29:36
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: 动态渲染-日期组件 * @Description: 动态渲染-日期组件
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
readonly readonly
v-model="currentValue" v-model="currentValue"
placeholder="请选择" placeholder="请选择"
:name="name"
:disabled="disabled" :disabled="disabled"
:required="required" :required="required"
@click="showDate(true)" @click="showDate(true)"
...@@ -30,7 +31,7 @@ ...@@ -30,7 +31,7 @@
> >
<d-label :label="label" :help="help" slot="label" /> <d-label :label="label" :help="help" slot="label" />
<template slot="right-icon" > <template slot="right-icon" >
<van-icon name="clear" v-show="clearable && currentValue" @click="clear"/> <van-icon name="clear" v-show="!disabled && clearable && currentValue" @click="clear"/>
<img src="../../../assets/date-icon.png" alt="" class="right-icon"/> <img src="../../../assets/date-icon.png" alt="" class="right-icon"/>
</template> </template>
</van-field> </van-field>
...@@ -70,6 +71,10 @@ export default { ...@@ -70,6 +71,10 @@ export default {
type: String, type: String,
default: 'DatePicker' default: 'DatePicker'
}, },
name: {
type: String,
default: ''
},
help: { help: {
type: String, type: String,
default: '' default: ''
......
...@@ -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-12 14:09:57 * @LastEditTime: 2024-08-13 15:46:33
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: 动态渲染-文本框组件 * @Description: 动态渲染-文本框组件
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
v-model="currentValue" v-model="currentValue"
placeholder="请输入" placeholder="请输入"
@input="fieldInput" @input="fieldInput"
:name="name"
:type="fieldType[type]" :type="fieldType[type]"
:disabled="disabled" :disabled="disabled"
:required="required" :required="required"
...@@ -49,6 +50,10 @@ export default { ...@@ -49,6 +50,10 @@ export default {
type: String, type: String,
default: 'TextField', default: 'TextField',
}, },
name: {
type: String,
default: ''
},
help: { help: {
type: String, type: String,
default: '' default: ''
...@@ -58,7 +63,7 @@ export default { ...@@ -58,7 +63,7 @@ export default {
default: '' default: ''
}, },
value: { value: {
type: String, type: String | Number,
default: '', default: '',
}, },
disabled: { disabled: {
......
...@@ -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-09 22:36:54 * @LastEditTime: 2024-08-14 09:28:23
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: 动态渲染-Lov * @Description: 动态渲染-Lov
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
<van-field <van-field
v-model="fieldValue" v-model="fieldValue"
:name="name"
:disabled="disabled" :disabled="disabled"
:required="required" :required="required"
:rules="[{ required, message: `请选择${label}` }]" :rules="[{ required, message: `请选择${label}` }]"
...@@ -38,7 +39,7 @@ ...@@ -38,7 +39,7 @@
</div> </div>
</template> </template>
<template slot="right-icon" > <template slot="right-icon" >
<van-icon name="clear" v-show="clearable && !(!currentValue || currentValue.length === 0)" @click="clear"/> <van-icon name="clear" v-show="!disabled && clearable && !(!currentValue || currentValue.length === 0)" @click="clear"/>
<van-icon name="arrow" /> <van-icon name="arrow" />
</template> </template>
</van-field> </van-field>
...@@ -115,6 +116,10 @@ export default { ...@@ -115,6 +116,10 @@ export default {
type: Object, type: Object,
default: () => {} default: () => {}
}, },
name: {
type: String,
default: ''
},
help: { help: {
type: String, type: String,
default: '' default: ''
...@@ -163,6 +168,17 @@ export default { ...@@ -163,6 +168,17 @@ export default {
options: [], options: [],
} }
}, },
watch: {
value: {
handler(newValue, oldValue) {
if (JSON.stringify(newValue) !== JSON.stringify(oldValue)) {
this.currentValue = newValue;
this.fieldValue = newValue ? JSON.stringify(newValue) : '';
}
},
deep: true
}
},
mounted() { mounted() {
this.getLovConfig(); this.getLovConfig();
}, },
...@@ -170,7 +186,6 @@ export default { ...@@ -170,7 +186,6 @@ export default {
getLovConfig() { getLovConfig() {
hlsHttp.get(`/hpfm/v1/${getOrganizationId()}/lov-view/info`, {viewCode: this.fieldConfig.lovCode}).then(res => { hlsHttp.get(`/hpfm/v1/${getOrganizationId()}/lov-view/info`, {viewCode: this.fieldConfig.lovCode}).then(res => {
this.lovConfig = res; this.lovConfig = res;
// this.getLovData();
}); });
}, },
getLovData() { getLovData() {
......
...@@ -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-09 22:36:43 * @LastEditTime: 2024-08-14 09:28:54
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: 动态渲染-Select * @Description: 动态渲染-Select
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
<van-field <van-field
v-model="fieldValue" v-model="fieldValue"
:name="name"
:disabled="disabled" :disabled="disabled"
:required="required" :required="required"
:rules="[{ required, message: `请选择${label}` }]" :rules="[{ required, message: `请选择${label}` }]"
...@@ -36,33 +37,32 @@ ...@@ -36,33 +37,32 @@
</div> </div>
</template> </template>
<template slot="right-icon" > <template slot="right-icon" >
<van-icon name="clear" v-show="clearable && (currentValue.length || currentValue.meaning)" @click="clear"/> <van-icon name="clear" v-show="!disabled && clearable && (currentValue.length || currentValue.meaning)" @click="clear"/>
<van-icon name="arrow" /> <van-icon name="arrow" />
</template> </template>
</van-field> </van-field>
<van-popup v-model="visible" round position="bottom" class="d-select-popup"> <van-popup v-model="visible" round position="bottom" class="d-select-popup">
<div class="d-select-popup"> <div class="title">
<div class="title"> <span class="cancel" @click="showSelectOption(false)">取消</span>
<span class="cancel" @click="showSelectOption(false)">取消</span> <span class="title-label">请选择{{fieldConfig.description}}</span>
<span class="title-label">请选择{{fieldConfig.description}}</span> <span class="confirm" @click="onConfirm">确定</span>
<span class="confirm" @click="onConfirm">确定</span>
</div>
<ul class="list">
<li
v-for="(option, index) in options"
:class="option.selected ? 'item active' : 'item'"
:key="option.value"
@click="selectOption(option, index)"
>{{option.meaning}}</li>
</ul>
</div> </div>
<ul class="list">
<li
v-for="(option, index) in options"
:class="option._selected ? 'item active' : 'item'"
:key="option.value"
@click="selectOption(option, index)"
>{{option.meaning}}</li>
</ul>
</van-popup> </van-popup>
</div> </div>
</template> </template>
<script> <script>
import {isNumber} from 'lodash';
import {Cell, Switch, Icon, Popup, Field} from 'vant'; import {Cell, Switch, Icon, Popup, Field} from 'vant';
import DLabel from './DLabel'; import DLabel from './DLabel';
import hlsHttp from '../../../utils/hlsHttp'; import hlsHttp from '../../../utils/hlsHttp';
...@@ -87,6 +87,10 @@ export default { ...@@ -87,6 +87,10 @@ export default {
type: Boolean, type: Boolean,
default: false default: false
}, },
name: {
type: String,
default: ''
},
help: { help: {
type: String, type: String,
default: '' default: ''
...@@ -96,7 +100,7 @@ export default { ...@@ -96,7 +100,7 @@ export default {
default: '' default: ''
}, },
value: { value: {
type: String, type: String | Number,
default: '', default: '',
}, },
disabled: { disabled: {
...@@ -111,6 +115,10 @@ export default { ...@@ -111,6 +115,10 @@ export default {
type: Boolean, type: Boolean,
default: false, default: false,
}, },
cascadesParams: {
type: Object,
default: () => ({})
}
}, },
data () { data () {
return { return {
...@@ -123,28 +131,54 @@ export default { ...@@ -123,28 +131,54 @@ export default {
options: [], options: [],
} }
}, },
watch: {
value: function(newValue, oldValue) {
if (newValue !== oldValue) {
if (this.multiple) {
if (JSON.stringify(newValue) !== JSON.stringify(this.currentValue)) {
this.formatValue();
}
} else if (newValue !== this.currentValue.value) {
this.formatValue();
}
}
},
cascadesParams: {
handler(newValue, oldValue) {
if (JSON.stringify(newValue) !== JSON.stringify(oldValue)) {
this.getOptions();
}
},
deep: true
}
},
mounted() { mounted() {
this.getOptions(); this.getOptions();
}, },
methods: { methods: {
getOptions() { getOptions() {
hlsHttp.get(`/hpfm/v1/${getOrganizationId()}/lovs/data`, {lovCode: this.fieldConfig.lookupCode}).then(res => { hlsHttp.get(`/hpfm/v1/${getOrganizationId()}/lovs/data`, {lovCode: this.fieldConfig.lookupCode, ...this.cascadesParams}).then(res => {
// 处理值 this.options = res.map(item => ({...item, _selected: false}));
const selectData = []; });
const valueArr = (this.value || '').split(','); },
this.options = res.map(item => { formatValue() {
if (valueArr.includes(item.value)) { const selectData = [];
item.selected = true; const valueArr = isNumber(this.value) ? [this.value] : (this.value || '').split(',');
selectData.push({...item}); this.options = this.options.map(item => {
} if (valueArr.includes(item.value)) {
return item; item._selected = true;
}); selectData.push({...item});
if (this.multiple) { // 多选
this.currentValue = selectData;
} else { } else {
this.currentValue = selectData.length ? selectData : { meaning: '', value: '' }; item._selected = false;
} }
return item;
}); });
if (this.multiple) { // 多选
this.currentValue = selectData;
} else {
this.currentValue = selectData.length ? selectData[0] : { meaning: '', value: '' };
}
this.fieldValue = this.currentValue ? JSON.stringify(this.currentValue) : ''
}, },
showSelectOption(flag) { showSelectOption(flag) {
if (!this.disabled) { if (!this.disabled) {
...@@ -152,7 +186,7 @@ export default { ...@@ -152,7 +186,7 @@ export default {
} }
}, },
clear() { clear() {
this.options = this.options.map(o => ({...o, selected: false})); this.options = this.options.map(o => ({...o, _selected: false}));
if (this.multiple) { if (this.multiple) {
this.currentValue = []; this.currentValue = [];
} else { } else {
...@@ -162,20 +196,20 @@ export default { ...@@ -162,20 +196,20 @@ export default {
}, },
onConfirm() { onConfirm() {
if (this.multiple) { if (this.multiple) {
this.currentValue = this.options.filter(o => o.selected); this.currentValue = this.options.filter(o => o._selected);
const values = this.currentValue.map(o => o.value).join(','); const values = this.currentValue.map(o => o.value).join(',');
this.inputValue(values); this.inputValue(values);
} else { } else {
this.currentValue = this.options.find(o => o.selected); this.currentValue = this.options.find(o => o._selected);
this.inputValue(this.currentValue.value); this.inputValue(this.currentValue.value);
} }
this.showSelectOption(false); this.showSelectOption(false);
}, },
selectOption(val, index) { selectOption(val, index) {
if (!this.multiple) { if (!this.multiple) {
this.options = this.options.map(o => ({...o, selected: false})) this.options = this.options.map(o => ({...o, _selected: false}))
} }
this.$set(this.options[index], 'selected', !this.options[index].selected); this.$set(this.options[index], '_selected', !this.options[index]._selected);
}, },
inputValue(val) { inputValue(val) {
this.fieldValue = val ? JSON.stringify(val) : ''; this.fieldValue = val ? JSON.stringify(val) : '';
...@@ -196,6 +230,7 @@ export default { ...@@ -196,6 +230,7 @@ export default {
<style lang="less"> <style lang="less">
@import './index.less'; @import './index.less';
.d-select-popup { .d-select-popup {
max-height: 60%;
.title{ .title{
padding: 13px; padding: 13px;
display: flex; display: flex;
......
...@@ -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-12 11:15:21 * @LastEditTime: 2024-08-13 15:48:06
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: 动态渲染-开关组件 * @Description: 动态渲染-开关组件
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
<div class="d-form-item"> <div class="d-form-item">
<van-field <van-field
:name="name"
:disabled="disabled" :disabled="disabled"
:required="required" :required="required"
:rules="[{ required, message: `请填写${label}` }]" :rules="[{ required, message: `请填写${label}` }]"
...@@ -41,6 +42,10 @@ export default { ...@@ -41,6 +42,10 @@ export default {
DLabel DLabel
}, },
props: { props: {
name: {
type: String,
default: ''
},
help: { help: {
type: String, type: String,
default: '' default: ''
......
...@@ -2,25 +2,31 @@ ...@@ -2,25 +2,31 @@
* @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-12 14:09:34 * @LastEditTime: 2024-08-14 09:21:52
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: 表单渲染 * @Description: 表单渲染
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
--> -->
<template> <template>
<fragment> <fragment>
<DTitle v-if="showTitle" :title="tabInfo.description" :tabButtons="tabInfo.tabButtons || []" /> <DTitle
v-if="formType === 'normal'"
:title="tabInfo.description"
:tabButtons="tabInfo.tabButtons || []"
:showBtns="!readOnly"
/>
<van-form ref="formRef" error-message-align="right" input-align="right"> <van-form ref="formRef" error-message-align="right" input-align="right">
<fragment v-for="field in fieldList" :key="field.columnName"> <fragment v-for="field in fieldList" :key="field.columnName">
<d-field <d-field
v-if="fieldComponents.indexOf(field.validationTypeDisplay) > -1" v-if="fieldComponents.indexOf(field.validationTypeDisplay) > -1"
v-model="fieldsObj[field.columnName]" v-model="fieldsObj[field.columnName]"
:name="field.columnName"
:fieldConfig="field" :fieldConfig="field"
:type="field.validationTypeDisplay" :type="field.validationTypeDisplay"
:help="field.help" :help="field.help"
:label="field.description" :label="field.description"
:disabled="field.readOnly" :disabled="readOnly || field.readOnly"
:required="field.required" :required="field.required"
:clearable="field.clearFlag" :clearable="field.clearFlag"
/> />
...@@ -29,8 +35,9 @@ ...@@ -29,8 +35,9 @@
v-if="field.validationTypeDisplay === 'Switch'" v-if="field.validationTypeDisplay === 'Switch'"
:label="field.description" :label="field.description"
:help="field.help" :help="field.help"
:name="field.columnName"
v-model="fieldsObj[field.columnName]" v-model="fieldsObj[field.columnName]"
:disabled="field.readOnly" :disabled="readOnly || field.readOnly"
:required="field.required" :required="field.required"
@change="fieldChange" @change="fieldChange"
/> />
...@@ -39,8 +46,9 @@ ...@@ -39,8 +46,9 @@
v-if="field.validationTypeDisplay === 'CheckBox' || field.validationTypeDisplay === 'Radio'" v-if="field.validationTypeDisplay === 'CheckBox' || field.validationTypeDisplay === 'Radio'"
:label="field.description" :label="field.description"
:help="field.help" :help="field.help"
:name="field.columnName"
v-model="fieldsObj[field.columnName]" v-model="fieldsObj[field.columnName]"
:disabled="field.readOnly" :disabled="readOnly || field.readOnly"
:required="field.required" :required="field.required"
@change="fieldChange" @change="fieldChange"
/> />
...@@ -49,23 +57,26 @@ ...@@ -49,23 +57,26 @@
v-if="field.validationTypeDisplay === 'Select'" v-if="field.validationTypeDisplay === 'Select'"
v-model="fieldsObj[field.columnName]" v-model="fieldsObj[field.columnName]"
:help="field.help" :help="field.help"
:name="field.columnName"
:label="field.description" :label="field.description"
:fieldConfig="field" :fieldConfig="field"
:disabled="field.readOnly" :disabled="readOnly || field.readOnly"
:required="field.required" :required="field.required"
:clearable="field.clearFlag" :clearable="field.clearFlag"
:multiple="field.multiple === 1" :multiple="field.multiple === 1"
:cascadesParams="getCascadesParams(field)"
@change="fieldChange" @change="fieldChange"
/> />
<d-lov <d-lov
v-if="field.validationTypeDisplay === 'Lov'" v-if="field.validationTypeDisplay === 'Lov'"
v-model="fieldsObj[field.columnName]" v-model="fieldsObj[field.columnName]"
:name="field.columnName"
:record="fieldsObj" :record="fieldsObj"
:help="field.help" :help="field.help"
:label="field.description" :label="field.description"
:fieldConfig="field" :fieldConfig="field"
:disabled="field.readOnly" :disabled="readOnly || field.readOnly"
:required="field.required" :required="field.required"
:clearable="field.clearFlag" :clearable="field.clearFlag"
:cascadesParams="getCascadesParams(field)" :cascadesParams="getCascadesParams(field)"
...@@ -76,20 +87,22 @@ ...@@ -76,20 +87,22 @@
<d-date <d-date
v-if="dateComponents.indexOf(field.validationTypeDisplay) > -1" v-if="dateComponents.indexOf(field.validationTypeDisplay) > -1"
v-model="fieldsObj[field.columnName]" v-model="fieldsObj[field.columnName]"
:name="field.columnName"
:label="field.description" :label="field.description"
:help="field.help" :help="field.help"
:fieldConfig="field" :fieldConfig="field"
:disabled="field.readOnly" :disabled="readOnly || field.readOnly"
:required="field.required" :required="field.required"
:clearable="field.clearFlag" :clearable="field.clearFlag"
/> />
<d-url <d-url
v-if="field.validationTypeDisplay === 'UrlField'" v-if="field.validationTypeDisplay === 'UrlField'"
:name="field.columnName"
:label="field.description" :label="field.description"
:help="field.help" :help="field.help"
v-model="fieldsObj[field.columnName]" v-model="fieldsObj[field.columnName]"
:disabled="field.readOnly" :disabled="readOnly || field.readOnly"
:required="field.required" :required="field.required"
@change="fieldChange" @change="fieldChange"
/> />
...@@ -108,7 +121,6 @@ import DDate from './FormItem/DDate'; ...@@ -108,7 +121,6 @@ import DDate from './FormItem/DDate';
import DCheckbox from './FormItem/DCheckbox'; import DCheckbox from './FormItem/DCheckbox';
import DUrl from './FormItem/DUrl'; import DUrl from './FormItem/DUrl';
import DTitle from '../DTitle'; import DTitle from '../DTitle';
import DButtons from '../DButtons';
import hlsHttp from '../../utils/hlsHttp'; import hlsHttp from '../../utils/hlsHttp';
export default { export default {
...@@ -126,7 +138,6 @@ export default { ...@@ -126,7 +138,6 @@ export default {
DCheckbox, DCheckbox,
DUrl, DUrl,
DTitle, DTitle,
DButtons,
DCheckbox DCheckbox
}, },
props: { props: {
...@@ -136,7 +147,7 @@ export default { ...@@ -136,7 +147,7 @@ export default {
}, },
formType: { formType: {
type: String, type: String,
default: 'normal', // normal:正常表单, query: 查询表单 default: 'normal', // normal:正常表单, query: 查询表单, tableForm: 表格详情表单
}, },
showTitle: { showTitle: {
type: Boolean, type: Boolean,
...@@ -162,20 +173,25 @@ export default { ...@@ -162,20 +173,25 @@ export default {
componentTypes: ["UrlField"], componentTypes: ["UrlField"],
fieldList: [...this.fields], fieldList: [...this.fields],
fieldsObj: {}, fieldsObj: {},
originFieldsObj: {}, // 重置使用
queryParams: {}, queryParams: {},
readOnly: true,
status: 'add',
} }
}, },
inject: ['dynamicInfo'], inject: ['dynamicInfo', 'addFormRef', 'setDataSetData'],
mounted() { mounted() {
console.log('D-form', this.fields)
this.init(); this.init();
}, },
activated() { activated() {
console.log('D-form', this.fields) console.log('D-form-activated', this.fields)
this.init(); this.init();
}, },
methods: { methods: {
init() { async init() {
this.queryParams = this.dynamicInfo().queryParams; this.queryParams = this.dynamicInfo().queryParams;
this.readOnly = this.queryParams.readOnly;
if (JSON.stringify(this.record) === '{}') { // 新建 if (JSON.stringify(this.record) === '{}') { // 新建
let initFields = {} let initFields = {}
this.fields.forEach(item => { this.fields.forEach(item => {
...@@ -185,14 +201,44 @@ export default { ...@@ -185,14 +201,44 @@ export default {
} }
}) })
this.fieldsObj = {...initFields}; this.fieldsObj = {...initFields};
this.status = 'add';
} else { // 详情 } else { // 详情
this.fieldsObj = {...this.record}; this.fieldsObj = {...this.record};
this.status = 'update';
} }
if (this.tabInfo && this.tabInfo.readUrl) {
hlsHttp.get(this.tabInfo.readUrl, this.queryParams).then(res => { if (this.formType === 'normal') {
if (this.tabInfo.readUrl) {
const res = await hlsHttp.get(this.tabInfo.readUrl, this.queryParams)
this.fieldsObj = res.content.length ? res.content[0] : {}; this.fieldsObj = res.content.length ? res.content[0] : {};
}) this.addFormRef(this, this.tabInfo.tabCode); //正常表单保存表单组件实例,供页面整体保存时使用
this.setDataSetData(this.tabInfo.tabCode, {...this.fieldsObj}); // 保存一份原始数据
this.status = 'update';
} else {
this.status = 'add';
}
} }
this.formatFieldsValue();
},
formatFieldsValue() {
this.originFields.forEach(item => {
if (item.bind && this.fieldsObj[item.columnName]) { // 主要处理lov绑定字段
const bindField = item.bind.split('.');
if (bindField.length >1) {
if (this.fieldsObj[bindField[0]]) {
this.fieldsObj[bindField[0]][bindField[1]] = this.fieldsObj[item.columnName];
} else {
this.fieldsObj[bindField[0]] = {
[bindField[1]]: this.fieldsObj[item.columnName]
};
}
} else {
this.fieldsObj[bindField[0]] = this.fieldsObj[item.columnName];
}
}
})
this.originFieldsObj = {...this.fieldsObj};
console.log('this.fieldsObj', this.fieldsObj)
}, },
getInputType(type) { getInputType(type) {
if (type === 'TextArea') { if (type === 'TextArea') {
...@@ -229,22 +275,37 @@ export default { ...@@ -229,22 +275,37 @@ export default {
// console.log(val) // console.log(val)
}, },
validate() { validate() {
this.$refs.formRef.submit(); return new Promise((resolve, rejcet) => {
const values = {...this.fieldsObj}; this.$refs.formRef.validate().then(() => {
this.originFields.forEach(item => { const values = {...this.fieldsObj};
if (item.bind) { console.log('values', values)
const bindField = item.bind.split('.'); const formValues = {};
if (bindField.length >1) { this.originFields.forEach(item => {
values[item.columnName] = values[bindField[0]] ? values[bindField[0]][bindField[1]] : undefined; if (item.bind) {
} else { const bindField = item.bind.split('.');
values[item.columnName] = values[bindField[0]]; if (bindField.length >1) {
values[item.columnName] = values[bindField[0]] ? values[bindField[0]][bindField[1]] : values[item.columnName];
} else {
values[item.columnName] = values[bindField[0]] || values[item.columnName];
}
}
if (item.dataType === 'boolean') {
values[item.columnName] = values[item.columnName] ? 1 : 0;
}
formValues[item.columnName] = values[item.columnName];
});
const result = {
allValues: {...values, _status: this.status}, // 完整的数据,包含record或者接口查询的所有字段信息
formValues: {...formValues, _status: this.status} // 只包含配置的fileds信息
} }
} resolve(result);
if (item.dataType === 'boolean') { }).catch(errors => {
values[item.columnName] = values[item.columnName] ? 1 : 0; rejcet(errors);
} });
}) });
return values; },
reset() {
this.fieldsObj = {...this.originFieldsObj};
} }
}, },
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: zong.wang01@hand-china.com * @Author: zong.wang01@hand-china.com
* @Date: 2024-07-30 09:41:54 * @Date: 2024-07-30 09:41:54
* @LastEditors: zong.wang01@hand-china.com * @LastEditors: zong.wang01@hand-china.com
* @LastEditTime: 2024-08-11 10:28:01 * @LastEditTime: 2024-08-12 16:12:51
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: 表格列渲染 * @Description: 表格列渲染
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
...@@ -24,20 +24,31 @@ const DTableTd = { ...@@ -24,20 +24,31 @@ const DTableTd = {
tdRender: { tdRender: {
type: Function, type: Function,
default: null default: null
},
typeDisplay: {
type: String,
default: 'Field'
} }
}, },
data () { data () {
return { return {
} }
}, },
methods: { methods: {
columnValue() {
if (['Lov', 'Select'].includes(this.typeDisplay)) {
return this.record[`${this.columnName}Name`];
} else {
return this.record[this.columnName];
}
}
}, },
// 为了弥补缺少的实例 // 为了弥补缺少的实例
// 提供第二个参数作为上下文 // 提供第二个参数作为上下文
render: function (h, context) { render: function (h, context) {
return this.tdRender ? this.tdRender(this.record) : <span>{this.$slots.default || (this.record[this.columnName] || '--')}</span> return this.tdRender ?
this.tdRender(this.record) :
<span>{this.$slots.default || (this.columnValue() || '--')}</span>
} }
}; };
......
...@@ -2,14 +2,19 @@ ...@@ -2,14 +2,19 @@
* @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-12 14:10:34 * @LastEditTime: 2024-08-14 09:16:29
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: 表格渲染 * @Description: 表格渲染
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
--> -->
<template> <template>
<fragment> <fragment>
<DTitle :title="tabInfo.description" :tabButtons="tabInfo.tabButtons || []" :buttonsFun="buttonsClick" /> <DTitle
:title="tabInfo.description"
:tabButtons="tabInfo.tabButtons || []"
:buttonsFun="buttonsClick"
:showBtns="!readOnly"
/>
<scroll <scroll
ref="scroll" :pullUp="true" :pull-down="true" @pullingUp="getList" ref="scroll" :pullUp="true" :pull-down="true" @pullingUp="getList"
...@@ -27,7 +32,7 @@ ...@@ -27,7 +32,7 @@
:columnName="column.columnName" :columnName="column.columnName"
:record="item" /> :record="item" />
</van-checkbox> </van-checkbox>
<van-icon name="records-o" @click="showRecord(item, pIndex)"/> <van-icon name="records-o" v-if="showEdit" @click="showRecord(item, pIndex)"/>
</div> </div>
<div v-else class="d-table-tr"> <div v-else class="d-table-tr">
<span>{{column.description}}</span> <span>{{column.description}}</span>
...@@ -35,6 +40,7 @@ ...@@ -35,6 +40,7 @@
:tdRender="column.renderer" :tdRender="column.renderer"
:columnName="column.columnName" :columnName="column.columnName"
:record="item" :record="item"
:typeDisplay="column.validationTypeDisplay"
> >
<template v-if="booleanType.includes(column.validationTypeDisplay)"> <template v-if="booleanType.includes(column.validationTypeDisplay)">
{{booleanDisplay[item[column.columnName]] || '--'}} {{booleanDisplay[item[column.columnName]] || '--'}}
...@@ -54,7 +60,7 @@ ...@@ -54,7 +60,7 @@
:originFields="originColumns" :originFields="originColumns"
ref="dformRef" ref="dformRef"
:record="record" :record="record"
:showTitle="false" formType="tableForm"
/> />
</div> </div>
<div class="d-table-form-footer"> <div class="d-table-form-footer">
...@@ -81,6 +87,7 @@ import DTableTd from './DTableTd.jsx'; ...@@ -81,6 +87,7 @@ import DTableTd from './DTableTd.jsx';
import { Checkbox, CheckboxGroup, Popup, Button, Icon, Toast } from 'vant'; import { Checkbox, CheckboxGroup, Popup, Button, Icon, Toast } from 'vant';
import hlsHttp from '../../utils/hlsHttp'; import hlsHttp from '../../utils/hlsHttp';
import {getDataSetName, getOrganizationId} from '../../utils/utils'; import {getDataSetName, getOrganizationId} from '../../utils/utils';
import EventBus from '../../utils/eventBus';
export default { export default {
name: 'DTable', name: 'DTable',
...@@ -123,9 +130,12 @@ export default { ...@@ -123,9 +130,12 @@ export default {
}, },
page: 0, page: 0,
size: 10, size: 10,
queryParams: {},
tableData: [], // 表格数据 tableData: [], // 表格数据
checkResult: [], checkResult: [],
visible: false, visible: false,
showEdit: false,
readOnly: true,
record: {}, // 操作记录 record: {}, // 操作记录
recordIndex: -1, recordIndex: -1,
buttonsFun: {}, buttonsFun: {},
...@@ -140,8 +150,33 @@ export default { ...@@ -140,8 +150,33 @@ export default {
this.dynamicConfigInfo = this.dynamicInfo(); this.dynamicConfigInfo = this.dynamicInfo();
this.init(); this.init();
}, },
deactivated() {
EventBus.$off('tableQuery');
},
beforeDestroy() {
EventBus.$off('tableQuery');
},
methods: { methods: {
init() { init() {
if (this.tabInfo.queryTabCode) {
EventBus.$on('tableQuery', (data, queryTabCode) => {
if (this.tabInfo.queryTabCode === queryTabCode) {
this.queryParams = data;
this.refresh();
}
});
}
this.refresh();
this.readOnly = this.dynamicConfigInfo.queryParams.readOnly;
// 设置是否可以编辑
if (this.dynamicConfigInfo.queryParams.readOnly) {
this.showEdit = false;
} else {
this.showEdit = this.columns.some(o => !o.readOnly); // 存在可输入则显示编辑
}
},
refresh() {
this.page = 0; this.page = 0;
this.tableData = []; this.tableData = [];
this.getList(); this.getList();
...@@ -151,6 +186,7 @@ export default { ...@@ -151,6 +186,7 @@ export default {
const params = { const params = {
page: this.page, page: this.page,
size: this.size, size: this.size,
...this.queryParams,
...this.dynamicConfigInfo.queryParams, ...this.dynamicConfigInfo.queryParams,
} }
hlsHttp.get(this.tabInfo.readUrl, params).then(res => { hlsHttp.get(this.tabInfo.readUrl, params).then(res => {
...@@ -165,12 +201,21 @@ export default { ...@@ -165,12 +201,21 @@ export default {
}, },
showRecord(res, index) { showRecord(res, index) {
this.record = {...res}; this.record = {...res};
this.recordIndex = index; this.recordIndex = index;
this.visible = true; this.visible = true;
// if (this.tabInfo.createUrl) {
// this.record = {...res};
// this.recordIndex = index;
// this.visible = true;
// console.log('this.record', this.record)
// } else {
// Toast.fail('保存接口未配置,请检查配置');
// }
}, },
saveRecord() { async saveRecord() {
const values = this.$refs.dformRef.validate(); const {allValues} = await this.$refs.dformRef.validate();
hlsHttp.post(this.tabInfo.createUrl, [{...values, ...this.dynamicConfigInfo.queryParams}]).then(() => { hlsHttp.post(this.tabInfo.createUrl, [{...allValues, ...this.dynamicConfigInfo.queryParams}]).then(() => {
this.visible = false; this.visible = false;
Toast.success('保存成功!'); Toast.success('保存成功!');
this.init(); this.init();
...@@ -182,7 +227,7 @@ export default { ...@@ -182,7 +227,7 @@ export default {
// 删除 // 删除
deleteRecords() { deleteRecords() {
let result = this.tableData.filter(o => this.checkResult.includes(o[this.tabInfo.primaryKey])); let result = this.tableData.filter(o => this.checkResult.includes(o[this.tabInfo.primaryKey]));
const dataSetName = getDataSetName(this.dynamicConfigInfo.config, this.tabInfo.tabCode); const dataSetName = getDataSetName(this.dynamicConfigInfo.dataSetObject, this.tabInfo.tabCode);
const url = this.tabInfo.destroyUrl || const url = this.tabInfo.destroyUrl ||
`/hllc/v1/${getOrganizationId()}/dynamic-crud/delete${dataSetName ? '?datasetName=' + dataSetName : ''}`; `/hllc/v1/${getOrganizationId()}/dynamic-crud/delete${dataSetName ? '?datasetName=' + dataSetName : ''}`;
hlsHttp.delete(url , result).then(res=> { hlsHttp.delete(url , result).then(res=> {
...@@ -193,11 +238,7 @@ export default { ...@@ -193,11 +238,7 @@ export default {
buttonsClick(btn) { buttonsClick(btn) {
switch (btn.name) { switch (btn.name) {
case 'create': case 'create':
if (this.tabInfo.createUrl) { this.showRecord({}, -1);
this.showRecord({}, -1);
} else {
Toast.fail('保存接口未配置,请检查配置');
}
break; break;
case 'query': case 'query':
console.log('查询') console.log('查询')
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: zong.wang01@hand-china.com * @Author: zong.wang01@hand-china.com
* @Date: 2024-08-02 15:32:36 * @Date: 2024-08-02 15:32:36
* @LastEditors: zong.wang01@hand-china.com * @LastEditors: zong.wang01@hand-china.com
* @LastEditTime: 2024-08-09 10:16:37 * @LastEditTime: 2024-08-14 09:19:09
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: 组件头部渲染 * @Description: 组件头部渲染
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
<template> <template>
<div class="layout-title"> <div class="layout-title">
<div class="title">{{title}}</div> <div class="title">{{title}}</div>
<div class="title-btns"> <div class="title-btns" v-if="showBtns">
<van-button <van-button
v-for="btn in defaultBtns" v-for="btn in defaultBtns"
round round
...@@ -40,7 +40,6 @@ ...@@ -40,7 +40,6 @@
<script> <script>
import { Button, Icon, Popover } from 'vant'; import { Button, Icon, Popover } from 'vant';
import DButtons from '../DButtons';
export default { export default {
name: 'DTitle', name: 'DTitle',
...@@ -48,7 +47,6 @@ export default { ...@@ -48,7 +47,6 @@ export default {
[Icon.name]: Icon, [Icon.name]: Icon,
[Button.name]: Button, [Button.name]: Button,
[Popover.name]: Popover, [Popover.name]: Popover,
DButtons
}, },
props: { props: {
title: { title: {
...@@ -62,7 +60,12 @@ export default { ...@@ -62,7 +60,12 @@ export default {
buttonsFun: { buttonsFun: {
type: Function, type: Function,
default: () => {} default: () => {}
},
showBtns: {
type: Boolean,
default: false,
} }
}, },
data () { data () {
return { return {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: zong.wang01@hand-china.com * @Author: zong.wang01@hand-china.com
* @Date: 2024-07-30 21:21:37 * @Date: 2024-07-30 21:21:37
* @LastEditors: zong.wang01@hand-china.com * @LastEditors: zong.wang01@hand-china.com
* @LastEditTime: 2024-08-11 10:52:17 * @LastEditTime: 2024-08-13 16:41:48
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: * @Description:
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
...@@ -534,7 +534,8 @@ class BaseComponentBuilder extends BaseBuilder { ...@@ -534,7 +534,8 @@ class BaseComponentBuilder extends BaseBuilder {
buttons: this.buttons, buttons: this.buttons,
columns: this.columns.fields, columns: this.columns.fields,
originColumns: this.columns._originFields originColumns: this.columns._originFields
} },
ref:`DTABLE_${this.tabCode}`,
}, },
[] []
); );
...@@ -578,7 +579,8 @@ class BaseComponentBuilder extends BaseBuilder { ...@@ -578,7 +579,8 @@ class BaseComponentBuilder extends BaseBuilder {
fields: newFields.fields, fields: newFields.fields,
originFields: newFields._originFields, originFields: newFields._originFields,
tabInfo: this.props, tabInfo: this.props,
} },
ref:`DFORM_${this.tabCode}`,
} }
); );
} else { // 查询组件 } else { // 查询组件
......
...@@ -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-11 10:51:32 * @LastEditTime: 2024-08-13 17:52:35
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: 查询表单渲染 * @Description: 查询表单渲染
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
...@@ -22,24 +22,30 @@ ...@@ -22,24 +22,30 @@
</template> </template>
</van-search> </van-search>
<van-popup v-model="show" position="top"> <van-popup v-model="show" position="top" class="query-form-popup">
<DForm :fields="fields" :originFields="originFields" ref="dformRef" formType="query" :showTitle="false" /> <div class="query-form">
<div style="margin: 16px;"> <DForm :fields="fields" :originFields="originFields" ref="dformRef" formType="query" :showTitle="false" />
<h-button </div>
type="primary" <div class="query-form-btn">
<van-button
type="info"
v-for="btn in (tabInfo.tabButtons || [])" v-for="btn in (tabInfo.tabButtons || [])"
:key="btn.name" :key="btn.name"
style="margin-left: 10px" style="margin-left: 10px"
round
:plain="btn.name !== 'query'"
@click.native="btnFun(btn)" @click.native="btnFun(btn)"
>{{btn.description}}</h-button> >{{btn.description}}</van-button>
</div> </div>
</van-popup> </van-popup>
</div> </div>
</template> </template>
<script> <script>
import { Search, Icon, Popup } from 'vant'; import { Search, Icon, Popup, Button } from 'vant';
import DForm from '../DForm'; import DForm from '../DForm';
import EventBus from '../../utils/eventBus';
import { isNull, isUndefined } from '../../../../packages';
export default { export default {
name: 'QueryForm', name: 'QueryForm',
...@@ -47,7 +53,8 @@ export default { ...@@ -47,7 +53,8 @@ export default {
DForm, DForm,
[Search.name]: Search, [Search.name]: Search,
[Icon.name]: Icon, [Icon.name]: Icon,
[Popup.name]: Popup [Popup.name]: Popup,
[Button.name]: Button,
}, },
props: { props: {
fields: { fields: {
...@@ -69,11 +76,10 @@ export default { ...@@ -69,11 +76,10 @@ export default {
searchValue: '', searchValue: '',
} }
}, },
inject: ['config'], inject: ['dynamicInfo'],
mounted() { mounted() {
this.configDatas = this.config(); this.configDatas = this.dynamicInfo().config;
console.log('query-form', this.fields)
}, },
methods: { methods: {
onSearch() { // 搜索 onSearch() { // 搜索
...@@ -83,15 +89,48 @@ export default { ...@@ -83,15 +89,48 @@ export default {
this.show = true; this.show = true;
}, },
btnFun(btn) { btnFun(btn) {
console.log('过来了吗', this.$refs.dformRef) if (btn.name === 'query') {
this.$refs.dformRef.validate(); this.query();
} else if (btn.name === 'reset') {
this.reset();
}
},
async query() {
const {formValues} = await this.$refs.dformRef.validate();
let values = {};
Object.keys(formValues).forEach(key => {
if (!isNull(formValues[key]) && !isUndefined(formValues[key]) && formValues[key] !== '') {
values[key] = formValues[key];
}
});
EventBus.$emit('tableQuery', values, this.tabInfo.tabCode);
this.show = false;
},
reset() {
this.$refs.dformRef.reset()
} }
}, },
} }
</script> </script>
<style scoped lang="less"> <style scoped lang="less">
.content{ .query-form-popup {
//background-color: #cfcfcf; max-height: 60%;
} display: flex;
flex-direction: column;
overflow: hidden;
.query-form {
overflow: auto;
height: calc(100% - 50px);
}
.query-form-btn {
display: flex;
align-items: center;
padding: 10px;
.van-button {
flex: 1;
}
}
}
</style> </style>
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: zong.wang01@hand-china.com * @Author: zong.wang01@hand-china.com
* @Date: 2024-07-30 09:41:54 * @Date: 2024-07-30 09:41:54
* @LastEditors: zong.wang01@hand-china.com * @LastEditors: zong.wang01@hand-china.com
* @LastEditTime: 2024-08-11 11:08:27 * @LastEditTime: 2024-08-13 16:43:34
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: * @Description:
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
...@@ -54,6 +54,7 @@ const ConfigRenderComponent = { ...@@ -54,6 +54,7 @@ const ConfigRenderComponent = {
mounted() { mounted() {
this.configInfo = this.dynamicInfo().config; this.configInfo = this.dynamicInfo().config;
console.log('this.componentRenderers', this.componentRenderers, this.dynamicInfo()) console.log('this.componentRenderers', this.componentRenderers, this.dynamicInfo())
console.log(this.$refs);
}, },
activated () { activated () {
...@@ -136,14 +137,6 @@ const ConfigRenderComponent = { ...@@ -136,14 +137,6 @@ const ConfigRenderComponent = {
} }
const Layout = this.getLayout(layoutName); const Layout = this.getLayout(layoutName);
return <Layout componentNames={componentNames} components={components}/> return <Layout componentNames={componentNames} components={components}/>
// return new LayoutBuilder()
// .withLayout(this.getLayout(layoutName))
// .withTabCode(layoutTab.tabCode)
// // .withTabMap(tabMap)
// .withComponents(components)
// .withComponentNames(componentNames)
// // .withComponentFunctions(componentFunctions)
// .build();
}); });
}, },
getLayout(layoutName) { getLayout(layoutName) {
......
...@@ -2,13 +2,13 @@ ...@@ -2,13 +2,13 @@
* @Author: zong.wang01@hand-china.com * @Author: zong.wang01@hand-china.com
* @Date: 2024-07-31 15:09:30 * @Date: 2024-07-31 15:09:30
* @LastEditors: zong.wang01@hand-china.com * @LastEditors: zong.wang01@hand-china.com
* @LastEditTime: 2024-08-09 17:44:54 * @LastEditTime: 2024-08-14 09:14:38
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: 页面按钮渲染 * @Description: 页面按钮渲染
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
--> -->
<template> <template>
<div class="layout-buttons" :id="id"> <div class="layout-buttons" :id="id" v-if="!readOnly && layoutButtons.length">
<van-popover <van-popover
v-if="layoutButtons.length > num" v-if="layoutButtons.length > num"
v-model="moreVisible" v-model="moreVisible"
...@@ -45,8 +45,10 @@ ...@@ -45,8 +45,10 @@
</template> </template>
<script> <script>
import { Button, Icon, Popover } from 'vant'; import { Button, Icon, Popover, Toast } from 'vant';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import hlsHttp from '../utils/hlsHttp';
import { getOrganizationId } from '../utils/utils';
export default { export default {
name: 'LayoutButtons', name: 'LayoutButtons',
...@@ -54,8 +56,15 @@ export default { ...@@ -54,8 +56,15 @@ export default {
[Button.name]: Button, [Button.name]: Button,
[Icon.name]: Icon, [Icon.name]: Icon,
[Popover.name]: Popover, [Popover.name]: Popover,
[Toast.name]: Toast,
},
inject: ['dynamicInfo'],
props: {
parentContext: { // 是否需要返回键
type: Object,
default: () => ({})
},
}, },
inject: ['config'],
data () { data () {
return { return {
id: 'layoutButton' + uuidv4(), id: 'layoutButton' + uuidv4(),
...@@ -64,6 +73,7 @@ export default { ...@@ -64,6 +73,7 @@ export default {
num: 2, num: 2,
defaultBtns: [], defaultBtns: [],
hideBtns: [], hideBtns: [],
readOnly: true,
moreVisible: false, moreVisible: false,
buttonIcon: { buttonIcon: {
create: 'plus', create: 'plus',
...@@ -75,21 +85,12 @@ export default { ...@@ -75,21 +85,12 @@ export default {
} }
}, },
mounted() { mounted() {
this.configInfo = this.config(); this.configInfo = this.dynamicInfo().config;
this.readOnly = this.dynamicInfo().queryParams.readOnly;
this.layoutButtons = this.configInfo.layoutButtons || []; this.layoutButtons = this.configInfo.layoutButtons || [];
// document.addEventListener('click', this.clickEle, false)
this.init(); this.init();
}, },
destroyed () {
// document.removeEventListener('click', this.clickEle, false)
},
methods: { methods: {
// clickEle (e) {
// let content = document.querySelector('.layout-buttons-more')
// if ((content && !content.contains(e.target))) {
// this.moreVisible = false;
// }
// },
init() { init() {
if(this.layoutButtons.length > this.num) { if(this.layoutButtons.length > this.num) {
this.defaultBtns = this.layoutButtons.slice(0, this.num); this.defaultBtns = this.layoutButtons.slice(0, this.num);
...@@ -98,14 +99,86 @@ export default { ...@@ -98,14 +99,86 @@ export default {
this.defaultBtns = [...this.layoutButtons]; this.defaultBtns = [...this.layoutButtons];
} }
}, },
// more() {
// this.moreVisible = true;
// },
handlClick(btn) { handlClick(btn) {
this.moreVisible = false; this.moreVisible = false;
console.log(btn.name) if (btn.name === 'save') {
} this.saveFunction();
}, }
},
async saveFunction() {
const saveDataSet = this.dynamicInfo().dataSetObject;
const dataSets = {...saveDataSet};
for (let key in dataSets) {
if (dataSets.hasOwnProperty(key)) { // 确保key是对象自身的属性
const {formRef} = dataSets[key];
if(formRef) {
const values = await formRef.validate();
dataSets[key].submitValues = values;
}
}
}
const {layoutCode, metaKeys, dataSetMap} = this.getDataSets(dataSets);
hlsHttp.post(`/hllc/v1/${getOrganizationId()}/dynamic-crud/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
}
},
}
} }
</script> </script>
...@@ -125,6 +198,7 @@ export default { ...@@ -125,6 +198,7 @@ export default {
font-family: PingFangSC-Semibold; font-family: PingFangSC-Semibold;
font-size: 16px; font-size: 16px;
font-weight: 600; font-weight: 600;
flex: 1;
} }
.layout-button-more { .layout-button-more {
color: #666666; color: #666666;
...@@ -154,6 +228,7 @@ export default { ...@@ -154,6 +228,7 @@ export default {
box-shadow: 0px 0px 18px 0px rgba(0,0,0,0.2); box-shadow: 0px 0px 18px 0px rgba(0,0,0,0.2);
border-radius: 20px; border-radius: 20px;
white-space: nowrap; white-space: nowrap;
padding: 8px;
// margin: 6px 0; // margin: 6px 0;
// box-shadow: 0px 2px 2px 0px #3789ff; // box-shadow: 0px 2px 2px 0px #3789ff;
} }
......
...@@ -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-12 09:31:49 * @LastEditTime: 2024-08-13 13:02:20
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: * @Description:
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
:componentRenderers="componentRenderers" :componentRenderers="componentRenderers"
/> />
</h-content> </h-content>
<layout-buttons v-if="configDatas.id" /> <layout-buttons v-if="configDatas.id"/>
</h-view> </h-view>
</template> </template>
...@@ -31,6 +31,8 @@ import LayoutButtons from './LayoutButtons'; ...@@ -31,6 +31,8 @@ import LayoutButtons from './LayoutButtons';
import ConfigRenderComponent from './ConfigRenderComponent/index.jsx'; import ConfigRenderComponent from './ConfigRenderComponent/index.jsx';
import {query, queryRoute} from './service' import {query, queryRoute} from './service'
import './index.less' import './index.less'
import { getOrganizationId } from './utils/utils';
import Constants from './utils/Constants';
export default { export default {
name: 'Dynamic', name: 'Dynamic',
...@@ -58,42 +60,38 @@ export default { ...@@ -58,42 +60,38 @@ export default {
loading: false, loading: false,
queryParams: {}, // 查询参数 queryParams: {}, // 查询参数
qpara: {}, qpara: {},
configDatas: {}, configDatas: {}, // 页面配置信息
params: {}, params: {}, // 页面路由参数
config: { dataSetObject: {}, // 页面配置信息的dataset
datas: {}, duplicateDs: {}
params: {}
},
} }
}, },
provide() { provide() {
return { return {
config: () => this.configDatas, // 提供方法,注意提供的方法要写在return对象中 addFormRef: this.addFormRef,
queryParams: () => this.queryParams, setDataSetData: this.setDataSetData,
dynamicInfo: () => ({ // 配置的所有信息 dynamicInfo: () => ({ // 配置的所有信息
layoutCode: this.layoutCode, layoutCode: this.layoutCode,
config: this.configDatas, config: this.configDatas,
queryParams: { dataSetObject: this.dataSetObject,
...this.$route.params, queryParams: this.qpara,
...this.$route.query
},
componentRenderers: this.componentRenderers componentRenderers: this.componentRenderers
}) })
}; };
}, },
created() { created() {
window.localStorage.setItem('access_token', '1f22ae78-2ee2-470c-bea4-916396e5632c'); window.localStorage.setItem('access_token', '5d974657-7d25-4a4a-8195-6266f308a863');
this.queryParams = { this.params = {
...this.$route.params, ...this.$route.params,
...this.$route.query ...this.$route.query
} }
}, },
activated() { activated() {
this.queryParams = { this.params = {
...this.$route.params, ...this.$route.params,
...this.$route.query ...this.$route.query
} }
console.log('activated', this.queryParams) console.log('activated', this.params)
}, },
beforeMount() { beforeMount() {
this.layoutCodeQuery(); this.layoutCodeQuery();
...@@ -105,14 +103,14 @@ export default { ...@@ -105,14 +103,14 @@ export default {
this.loading = true; this.loading = true;
let readOnly = false let readOnly = false
// eslint-disable-next-line eqeqeq // eslint-disable-next-line eqeqeq
if (this.queryParams.readOnly === "YES" || this.queryParams.readOnly == 'true') { if (this.params.readOnly === "YES" || this.params.readOnly == 'true') {
readOnly = true readOnly = true
} }
// if (disabled) { // if (disabled) {
// readOnly = disabled // readOnly = disabled
// } // }
this.qpara = { this.qpara = {
...this.queryParams, ...this.params,
readOnly, readOnly,
}; };
// if (this.store.config.datas !== null && isEqual(this.qpara, this.store.config.param)) { // if (this.store.config.datas !== null && isEqual(this.qpara, this.store.config.param)) {
...@@ -124,10 +122,11 @@ export default { ...@@ -124,10 +122,11 @@ export default {
} else { } else {
res = await queryRoute(this.layoutCode, this.qpara); res = await queryRoute(this.layoutCode, this.qpara);
} }
const dataSetObj = this.transformDateSetTree(res.datas.dataSetsTree);
this.configDatas = {...res.datas, dataSetObject: dataSetObj};
this.params = res.params;
this.loading = false; this.loading = false;
this.configDatas = {...res.datas};
this.params = res.params;
this.dataSetObject = this.transformDateSetTree(res.datas.dataSetsTree);
// this.getDataSets(res.datas.dataSetsTree)
}, },
transformDateSetTree(tree) { transformDateSetTree(tree) {
let obj = {}; let obj = {};
...@@ -139,13 +138,17 @@ export default { ...@@ -139,13 +138,17 @@ export default {
}) })
} }
return obj; return obj;
} },
addFormRef(ref, tabCode) { // 添加表单实例
this.dataSetObject[tabCode].formRef = ref;
},
setDataSetData(tabCode, data) {
this.dataSetObject[tabCode].data = data;
},
}, },
} }
</script> </script>
<style scoped lang="less"> <style scoped lang="less">
.content{
//background-color: #cfcfcf;
}
</style> </style>
/*
* @Author: zong.wang01@hand-china.com
* @Date: 2024-08-13 17:18:28
* @LastEditors: zong.wang01@hand-china.com
* @LastEditTime: 2024-08-13 17:20:54
* @Version: 1.0.0
* @Description:
* @Copyright: Copyright (c) 2021, Hand-RongJing
*/
import Vue from 'vue';
const EventBus = new Vue();
export default EventBus;
\ No newline at end of file
...@@ -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-11 15:27:32 * @LastEditTime: 2024-08-13 16:10:43
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: 工具类 * @Description: 工具类
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
...@@ -30,7 +30,7 @@ const getHeaderExtrasProp = (layoutCode, tabCode, props) => { ...@@ -30,7 +30,7 @@ const getHeaderExtrasProp = (layoutCode, tabCode, props) => {
}; };
const getDataSetName = (config, tabCode) => { const getDataSetName = (config, tabCode) => {
return config.dataSetObject[tabCode].dataSetName || ''; return config[tabCode].dataSetName || '';
}; };
/** /**
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
* @Author: zong.wang01@hand-china.com * @Author: zong.wang01@hand-china.com
* @Date: 2024-07-31 18:41:49 * @Date: 2024-07-31 18:41:49
* @LastEditors: zong.wang01@hand-china.com * @LastEditors: zong.wang01@hand-china.com
* @LastEditTime: 2024-07-31 18:53:12 * @LastEditTime: 2024-08-13 10:47:38
* @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 layoutCode="BP001F1" /> <Dynamic layoutCode="PRJ005F1" />
</template> </template>
<script> <script>
......
<!--
* @Author: zong.wang01@hand-china.com
* @Date: 2024-07-29 11:02:22
* @LastEditors: zong.wang01@hand-china.com
* @LastEditTime: 2024-08-13 10:51:44
* @Version: 1.0.0
* @Description:
* @Copyright: Copyright (c) 2021, Hand-RongJing
-->
<template> <template>
<Dynamic layoutCode="BP001" :componentRenderers="componentRenderers" /> <Dynamic layoutCode="PRJ005" :componentRenderers="componentRenderers" />
</template> </template>
<script> <script>
...@@ -16,9 +25,9 @@ export default { ...@@ -16,9 +25,9 @@ export default {
componentRenderers: [ componentRenderers: [
{ {
tabCode: 'G_QUERY_RESULT', tabCode: 'G_QUERY_RESULT',
columnName: 'bpName', columnName: 'projectName',
renderer: (record) => { renderer: (record) => {
return <span style="color: #3789ff" onClick={() => this.toDetail(record)}>{record.bpName} <van-icon name="arrow" /></span> return <span style="color: #3789ff" onClick={() => this.toDetail(record)}>{record.projectName} <van-icon name="arrow" /></span>
}, },
}, },
] ]
...@@ -26,19 +35,20 @@ export default { ...@@ -26,19 +35,20 @@ export default {
}, },
methods: { methods: {
toDetail(record) { toDetail(record) {
console.log({ this.$router.push({
bpId: record.bpId,
bpName: record.bpName,
bpCode: record.bpCode,
})
this.$router.push({
name: 'DynamicDetail', name: 'DynamicDetail',
params: { params: {
bpId: record.bpId, projectId: record.projectId
bpName: record.bpName,
bpCode: record.bpCode,
} }
}) })
// this.$router.push({
// name: 'DynamicDetail',
// params: {
// bpId: record.bpId,
// bpName: record.bpName,
// bpCode: record.bpCode,
// }
// })
}, },
}, },
} }
......
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