Commit bddd72f8 authored by 王纵's avatar 王纵

表格删除、保存

parent f6a621e7
...@@ -297,25 +297,25 @@ export default { ...@@ -297,25 +297,25 @@ export default {
initScroll () { initScroll () {
let vm = this let vm = this
if (!this.$refs.scroll) return if (!this.$refs.scroll) return
if (this.height) { // if (this.height) {
this.$refs.scroll.style.height = this.height; // this.$refs.scroll.style.height = this.height;
} else { // } else {
const headerHeight = vm.getHeaderHeight() // const headerHeight = vm.getHeaderHeight()
const nextHeight = vm.getNextElementHeight() // const nextHeight = vm.getNextElementHeight()
this.$refs.scroll.style.height = `${this.$refs.scroll.getBoundingClientRect().height - headerHeight - nextHeight}px` // this.$refs.scroll.style.height = `${this.$refs.scroll.getBoundingClientRect().height - headerHeight - nextHeight}px`
} // }
// 设置scrollContent的最小高,实现高度不足时也有回弹效果 // // 设置scrollContent的最小高,实现高度不足时也有回弹效果
if (this.$refs.scrollContent) { // if (this.$refs.scrollContent) {
// const nextHeight = vm.getNextElementHeight() // // const nextHeight = vm.getNextElementHeight()
this.$refs.scrollContent.style.minHeight = window.getComputedStyle(this.$refs.scroll).height; // `${this.$refs.scroll.getBoundingClientRect().height}px` // this.$refs.scrollContent.style.minHeight = window.getComputedStyle(this.$refs.scroll).height; // `${this.$refs.scroll.getBoundingClientRect().height}px`
// this.$refs.scrollContent.style.paddingTop = `${headerHeight}px` // // this.$refs.scrollContent.style.paddingTop = `${headerHeight}px`
if (vm.hasFoot.footFlag) { // if (vm.hasFoot.footFlag) {
let height = vm.hasFoot.height || 88 // let height = vm.hasFoot.height || 88
// this.$refs.scrollContent.style.minHeight = `${this.$refs.scroll.getBoundingClientRect().height - height}px` // // this.$refs.scrollContent.style.minHeight = `${this.$refs.scroll.getBoundingClientRect().height - height}px`
this.$refs.scrollContent.style.paddingBottom = height + 'px' // this.$refs.scrollContent.style.paddingBottom = height + 'px'
} // }
} // }
const options = { const options = {
probeType: this.probeType, probeType: this.probeType,
......
...@@ -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:19:46 * @LastEditTime: 2024-08-12 11:15:28
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: 动态渲染-复选框组件 * @Description: 动态渲染-复选框组件
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
...@@ -51,8 +51,8 @@ export default { ...@@ -51,8 +51,8 @@ export default {
default: '' default: ''
}, },
value: { value: {
type: Boolean, type: Number | Boolean,
default: false, default: 0,
}, },
disabled: { disabled: {
type: Boolean, type: Boolean,
...@@ -71,7 +71,11 @@ export default { ...@@ -71,7 +71,11 @@ export default {
watch: { watch: {
value: function(newValue, oldValue) { value: function(newValue, oldValue) {
if (newValue !== oldValue) { if (newValue !== oldValue) {
this.currentValue = newValue if (typeof newValue === 'boolean') {
this.currentValue = newValue;
} else {
this.currentValue = Number(newValue) === 1 ? true : false;
}
} }
} }
}, },
......
...@@ -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:19:34 * @LastEditTime: 2024-08-12 14:09:57
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: 动态渲染-文本框组件 * @Description: 动态渲染-文本框组件
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
:required="required" :required="required"
:clearable="clearable" :clearable="clearable"
:formatter="formatter" :formatter="formatter"
:rules="[{ required: true, message: `请输入${label}` }]" :rules="[{ required, message: `请输入${label}` }]"
:error="false" :error="false"
> >
<d-label :label="label" :help="help" slot="label" /> <d-label :label="label" :help="help" slot="label" />
...@@ -102,7 +102,6 @@ export default { ...@@ -102,7 +102,6 @@ export default {
return val; return val;
}, },
fieldInput (val) { fieldInput (val) {
console.log('val', val)
this.$emit('input', val) this.$emit('input', val)
this.$emit('change', val) this.$emit('change', val)
}, },
......
...@@ -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:20:53 * @LastEditTime: 2024-08-12 11:15:21
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: 动态渲染-开关组件 * @Description: 动态渲染-开关组件
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
...@@ -50,8 +50,8 @@ export default { ...@@ -50,8 +50,8 @@ export default {
default: '' default: ''
}, },
value: { value: {
type: Boolean, type: Number | Boolean,
default: false, default: 0,
}, },
disabled: { disabled: {
type: Boolean, type: Boolean,
...@@ -70,15 +70,19 @@ export default { ...@@ -70,15 +70,19 @@ export default {
watch: { watch: {
value: function(newValue, oldValue) { value: function(newValue, oldValue) {
if (newValue !== oldValue) { if (newValue !== oldValue) {
this.currentValue = newValue if (typeof newValue === 'boolean') {
this.currentValue = newValue;
} else {
this.currentValue = Number(newValue) === 1 ? true : false;
}
} }
} }
}, },
methods: { methods: {
checked (flag) { checked (flag) {
if (!this.disable) { if (!this.disable) {
this.$emit('input', flag) this.$emit('input', flag ? 1 : 0);
this.$emit('change', flag) this.$emit('change', flag ? 1 : 0);
} }
}, },
}, },
......
...@@ -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 16:22:01 * @LastEditTime: 2024-08-11 10:44:31
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: 动态渲染-超链接组件 * @Description: 动态渲染-超链接组件
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
...@@ -19,10 +19,12 @@ ...@@ -19,10 +19,12 @@
<script> <script>
import {Cell, Checkbox} from 'vant'; import {Cell, Checkbox} from 'vant';
import DLabel from './DLabel';
export default { export default {
name: 'DUrl', name: 'DUrl',
components: { components: {
DLabel,
[Cell.name]: Cell, [Cell.name]: Cell,
[Checkbox.name]: Checkbox, [Checkbox.name]: Checkbox,
}, },
...@@ -36,8 +38,8 @@ export default { ...@@ -36,8 +38,8 @@ export default {
default: '' default: ''
}, },
value: { value: {
type: Boolean, type: String,
default: false, 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-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-09 22:40:43 * @LastEditTime: 2024-08-12 14:09:34
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: 表单渲染 * @Description: 表单渲染
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
<fragment> <fragment>
<DTitle v-if="showTitle" :title="tabInfo.description" :tabButtons="tabInfo.tabButtons || []" /> <DTitle v-if="showTitle" :title="tabInfo.description" :tabButtons="tabInfo.tabButtons || []" />
<van-form @submit="onSubmit" 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"
...@@ -109,6 +109,7 @@ import DCheckbox from './FormItem/DCheckbox'; ...@@ -109,6 +109,7 @@ 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 DButtons from '../DButtons';
import hlsHttp from '../../utils/hlsHttp';
export default { export default {
name: 'DForm', name: 'DForm',
...@@ -155,25 +156,44 @@ export default { ...@@ -155,25 +156,44 @@ export default {
} }
}, },
data () { data () {
let initFields = {}
this.fields.forEach(item => {
initFields[item.columnName] = null;
})
return { return {
fieldComponents: ['TextField',"TextArea", "Currency", "NumberField", "EmailField","CentField"], fieldComponents: ['TextField',"TextArea", "Currency", "NumberField", "EmailField","CentField"],
dateComponents: ["DatePicker", "DateTimePicker"], dateComponents: ["DatePicker", "DateTimePicker"],
componentTypes: ["UrlField"], componentTypes: ["UrlField"],
fieldList: [...this.fields], fieldList: [...this.fields],
fieldsObj: {...initFields} fieldsObj: {},
queryParams: {},
} }
}, },
inject: ['dynamicInfo'],
mounted() { mounted() {
this.init();
},
activated() {
console.log('D-form', this.fields) console.log('D-form', this.fields)
if (this.record && JSON.stringify(this.record) === '{}') { this.init();
this.fieldsObj = {...this.record};
}
}, },
methods: { methods: {
init() {
this.queryParams = this.dynamicInfo().queryParams;
if (JSON.stringify(this.record) === '{}') { // 新建
let initFields = {}
this.fields.forEach(item => {
initFields[item.columnName] = item.defaultValue ? item.defaultValue : null;
if (item.dataType === 'boolean') {
initFields[item.columnName] = item.defaultValue === '1' ? true : false;
}
})
this.fieldsObj = {...initFields};
} else { // 详情
this.fieldsObj = {...this.record};
}
if (this.tabInfo && this.tabInfo.readUrl) {
hlsHttp.get(this.tabInfo.readUrl, this.queryParams).then(res => {
this.fieldsObj = res.content.length ? res.content[0] : {};
})
}
},
getInputType(type) { getInputType(type) {
if (type === 'TextArea') { if (type === 'TextArea') {
return 'textarea'; return 'textarea';
...@@ -205,25 +225,26 @@ export default { ...@@ -205,25 +225,26 @@ export default {
} }
return {}; return {};
}, },
onSubmit() {
console.log('souusole', this.fieldsObj)
},
fieldChange(val) { fieldChange(val) {
console.log(val) // console.log(val)
}, },
validate() { validate() {
console.log('字段娇艳', this.fieldsObj)
this.$refs.formRef.submit(); this.$refs.formRef.submit();
// this.$refs.formRef.submit((res) => { const values = {...this.fieldsObj};
// console.log(res); this.originFields.forEach(item => {
// }, err => { if (item.bind) {
// console.log(err) const bindField = item.bind.split('.');
// }) if (bindField.length >1) {
// this.fields.forEach(field => { values[item.columnName] = values[bindField[0]] ? values[bindField[0]][bindField[1]] : undefined;
// if (!(this.fieldsObj[field.columnName])) { } else {
values[item.columnName] = values[bindField[0]];
// } }
// }) }
if (item.dataType === 'boolean') {
values[item.columnName] = values[item.columnName] ? 1 : 0;
}
})
return values;
} }
}, },
} }
......
/*
* @Author: zong.wang01@hand-china.com
* @Date: 2024-07-30 09:41:54
* @LastEditors: zong.wang01@hand-china.com
* @LastEditTime: 2024-08-11 10:28:01
* @Version: 1.0.0
* @Description: 表格列渲染
* @Copyright: Copyright (c) 2021, Hand-RongJing
*/
import Vue from 'vue';
const DTableTd = {
components: {
},
props: {
record: { // 数据
type: Object,
default: () => ({})
},
columnName: {
type: String,
default: '',
},
tdRender: {
type: Function,
default: null
}
},
data () {
return {
}
},
methods: {
},
// 为了弥补缺少的实例
// 提供第二个参数作为上下文
render: function (h, context) {
return this.tdRender ? this.tdRender(this.record) : <span>{this.$slots.default || (this.record[this.columnName] || '--')}</span>
}
};
export default DTableTd;
\ 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-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-09 15:19:07 * @LastEditTime: 2024-08-12 14:10:34
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: 表格渲染 * @Description: 表格渲染
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
...@@ -12,19 +12,35 @@ ...@@ -12,19 +12,35 @@
<DTitle :title="tabInfo.description" :tabButtons="tabInfo.tabButtons || []" :buttonsFun="buttonsClick" /> <DTitle :title="tabInfo.description" :tabButtons="tabInfo.tabButtons || []" :buttonsFun="buttonsClick" />
<scroll <scroll
ref="scroll" class="has-footer" :pullUp="true" :pull-down="true" @pullingUp="getList" ref="scroll" :pullUp="true" :pull-down="true" @pullingUp="getList"
@pullingDown="getList" @pullingDown="getList"
height="calc(100vh - 130px)" style="max-height: calc(100vh - 130px)"
> >
<van-checkbox-group v-model="checkResult"> <van-checkbox-group v-model="checkResult">
<div v-for="(item, index) in tableData" :key="item[tabInfo.primaryKey]" class="d-table" @click="showRecord(item, index)"> <div v-for="(item, pIndex) in tableData" :key="item[tabInfo.primaryKey]" class="d-table">
<fragment v-for="(column, index) in columns" :key="column.columnName" > <fragment v-for="(column, index) in columns" :key="column.columnName" >
<div v-if="index === 0" class="d-table-th"> <div v-if="index === 0" class="d-table-th">
<van-checkbox :name="item[tabInfo.primaryKey]">{{column.description}}: {{item[column.columnName]}}</van-checkbox> <van-checkbox :name="item[tabInfo.primaryKey]">
{{column.description}}:
<d-table-td
:tdRender="column.renderer"
:columnName="column.columnName"
:record="item" />
</van-checkbox>
<van-icon name="records-o" @click="showRecord(item, pIndex)"/>
</div> </div>
<div v-else class="d-table-tr" @click="toDetail"> <div v-else class="d-table-tr">
<span>{{column.description}}</span> <span>{{column.description}}</span>
<span>{{(column.validationTypeDisplay === 'Switch' ? (item[column.columnName] ? '是' : '否' ) : item[column.columnName]) || '--'}}</span> <d-table-td
:tdRender="column.renderer"
:columnName="column.columnName"
:record="item"
>
<template v-if="booleanType.includes(column.validationTypeDisplay)">
{{booleanDisplay[item[column.columnName]] || '--'}}
</template>
<!-- {{(column.validationTypeDisplay === 'Switch' ? (item[column.columnName] ? '是' : '否' ) : item[column.columnName]) || '--'}} -->
</d-table-td>
</div> </div>
</fragment> </fragment>
</div> </div>
...@@ -32,7 +48,14 @@ ...@@ -32,7 +48,14 @@
<van-popup v-model="visible" position="top" class="d-table-form-popup" get-container="body"> <van-popup v-model="visible" position="top" class="d-table-form-popup" get-container="body">
<div class="form-content"> <div class="form-content">
<d-form :fields="columns" :originFields="originColumns" ref="dformRef" :record="record" :showTitle="false" /> <d-form
v-if="visible"
:fields="columns"
:originFields="originColumns"
ref="dformRef"
:record="record"
:showTitle="false"
/>
</div> </div>
<div class="d-table-form-footer"> <div class="d-table-form-footer">
<van-button <van-button
...@@ -54,18 +77,23 @@ ...@@ -54,18 +77,23 @@
<script> <script>
import DTitle from '../DTitle'; import DTitle from '../DTitle';
import DForm from '../DForm'; import DForm from '../DForm';
import { Checkbox, CheckboxGroup, Popup, Button } from 'vant'; import DTableTd from './DTableTd.jsx';
import {get} from '../../utils/hlsHttp'; import { Checkbox, CheckboxGroup, Popup, Button, Icon, Toast } from 'vant';
import hlsHttp from '../../utils/hlsHttp';
import {getDataSetName, getOrganizationId} from '../../utils/utils';
export default { export default {
name: 'DTable', name: 'DTable',
components: { components: {
DTitle, DTitle,
DForm, DForm,
DTableTd,
[Button.name]: Button, [Button.name]: Button,
[Checkbox.name]: Checkbox, [Checkbox.name]: Checkbox,
[CheckboxGroup.name]: CheckboxGroup, [CheckboxGroup.name]: CheckboxGroup,
[Popup.name]: Popup, [Popup.name]: Popup,
[Icon.name]: Icon,
[Toast.name]: Toast,
}, },
props: { props: {
tabInfo: { // 配置信息 tabInfo: { // 配置信息
...@@ -85,8 +113,14 @@ export default { ...@@ -85,8 +113,14 @@ export default {
default: () => [], default: () => [],
} }
}, },
inject: ['dynamicInfo'],
data () { data () {
return { return {
booleanType: ['Switch', 'Radio', 'CheckBox'],
booleanDisplay: {
1: '是',
0: '否'
},
page: 0, page: 0,
size: 10, size: 10,
tableData: [], // 表格数据 tableData: [], // 表格数据
...@@ -94,22 +128,32 @@ export default { ...@@ -94,22 +128,32 @@ export default {
visible: false, visible: false,
record: {}, // 操作记录 record: {}, // 操作记录
recordIndex: -1, recordIndex: -1,
buttonsFun: {} buttonsFun: {},
dynamicConfigInfo: {},
} }
}, },
mounted() { mounted() {
this.dynamicConfigInfo = this.dynamicInfo();
this.init();
},
activated() {
this.dynamicConfigInfo = this.dynamicInfo();
this.init(); this.init();
}, },
methods: { methods: {
init() { init() {
this.page = 0;
this.tableData = [];
this.getList(); this.getList();
}, },
getList() { getList() {
// console.log('D-Table', this.columns)
const params = { const params = {
page: this.page, page: this.page,
size: this.size, size: this.size,
...this.dynamicConfigInfo.queryParams,
} }
get(this.tabInfo.readUrl, params).then(res => { hlsHttp.get(this.tabInfo.readUrl, params).then(res => {
this.tableData = this.tableData.concat(res.content || []); this.tableData = this.tableData.concat(res.content || []);
if (res.totalElements > this.tableData.length) { if (res.totalElements > this.tableData.length) {
this.page = this.page + 1; this.page = this.page + 1;
...@@ -125,29 +169,35 @@ export default { ...@@ -125,29 +169,35 @@ export default {
this.visible = true; this.visible = true;
}, },
saveRecord() { saveRecord() {
this.$refs.dformRef.validate(); const values = this.$refs.dformRef.validate();
// this.visible = false; hlsHttp.post(this.tabInfo.createUrl, [{...values, ...this.dynamicConfigInfo.queryParams}]).then(() => {
this.visible = false;
Toast.success('保存成功!');
this.init();
})
}, },
cancelRecord() { cancelRecord() {
this.visible = false; this.visible = false;
}, },
toDetail(e) {
e.stopPropagation();
e.preventDefault()
this.$router.push({
name: 'DynamicDetail',
// params: params
})
},
// 删除 // 删除
deleteRecords() { deleteRecords() {
let result = this.tableData.filter(o => this.checkResult.includes(o[this.tabInfo.primaryKey]));
const dataSetName = getDataSetName(this.dynamicConfigInfo.config, this.tabInfo.tabCode);
const url = this.tabInfo.destroyUrl ||
`/hllc/v1/${getOrganizationId()}/dynamic-crud/delete${dataSetName ? '?datasetName=' + dataSetName : ''}`;
hlsHttp.delete(url , result).then(res=> {
Toast.success('删除成功!');
this.init();
})
}, },
buttonsClick(btn) { buttonsClick(btn) {
console.log(btn)
switch (btn.name) { switch (btn.name) {
case 'create': case 'create':
this.showRecord({}, -1); if (this.tabInfo.createUrl) {
this.showRecord({}, -1);
} else {
Toast.fail('保存接口未配置,请检查配置');
}
break; break;
case 'query': case 'query':
console.log('查询') console.log('查询')
...@@ -170,6 +220,8 @@ export default { ...@@ -170,6 +220,8 @@ export default {
</script> </script>
<style scoped lang="less"> <style scoped lang="less">
@import '../../index.less';
.d-table { .d-table {
margin: 0 8px 12px 8px; margin: 0 8px 12px 8px;
padding: 4px 8px 12px 8px; padding: 4px 8px 12px 8px;
...@@ -184,12 +236,19 @@ export default { ...@@ -184,12 +236,19 @@ export default {
color: #646465; color: #646465;
} }
.d-table-th { .d-table-th {
display: flex;
justify-content: space-between;
align-items: center;
padding: 8px 0 12px 8px; padding: 8px 0 12px 8px;
border-bottom: 1px solid #F3F3F7;; border-bottom: 1px solid #F3F3F7;;
font-family: PingFangSC-Semibold; font-family: PingFangSC-Semibold;
font-size: 15px; font-size: 15px;
color: #4B4A4B; color: #4B4A4B;
font-weight: 600; font-weight: 600;
.van-icon-records-o {
font-size: 17px;
color: @primary-color;
}
} }
} }
.d-table-form-popup { .d-table-form-popup {
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
* @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-09 14:44:50 * @LastEditTime: 2024-08-11 10:52:17
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: * @Description:
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
*/ */
import Vue from 'vue'; import Vue from 'vue';
import {compact, head, isFunction, isNil, isNumber, isUndefined, upperFirst} from 'lodash'; import {compact, head, isFunction, isNil, isNumber, isUndefined, upperFirst} from 'lodash';
import {getCurrentUser} from '../utils/utils'; import {getCustomizedProp, getHeaderExtrasProp, getCurrentUser} from '../utils/utils';
/** /**
* 格式化代码 * 格式化代码
...@@ -93,20 +93,43 @@ export class ColumnBuilder extends BaseBuilder { ...@@ -93,20 +93,43 @@ export class ColumnBuilder extends BaseBuilder {
super.init(); super.init();
} }
getCustomizedRenderer(columnName) {
const currentRenderers = this.getCurrentRenderers(columnName, this.componentRenderers);
let renderer;
if (this.type === 'Table') {
renderer = currentRenderers.length > 0 ? currentRenderers[0].renderer : undefined;
} else if (this.type === 'Form') {
if (currentRenderers.length > 0 && isFunction(currentRenderers[0].renderer) && this.dataSet) {
renderer = currentRenderers[0].renderer({
dataSet: this.dataSet,
record: this.dataSet ? this.dataSet.current : undefined,
});
}
}
if (currentRenderers.length > 0) {
return { renderer, editor: currentRenderers[0].editor };
}
return { renderer };
}
getCurrentRenderers(columnName, renderers) {
return getCustomizedProp(this.layoutCode, this.tabCode, columnName, renderers);
}
/** /**
* 生成表单下字段组件数组 * 生成表单下字段组件数组
* @param {Array.<{columnName: string, columnSeq: number, rowSeq: number, cascadeValue: string, validationTypeDisplay: string, columnCount: number, rowCount: number, inputModeDisplay: string, width: number}>} fields * @param {Array.<{columnName: string, columnSeq: number, rowSeq: number, cascadeValue: string, validationTypeDisplay: string, columnCount: number, rowCount: number, inputModeDisplay: string, width: number}>} fields
* @param {string} cascadeKey * @param {string} cascadeKey
* @return * @return
*/ */
initFields(fields, cascadeKey = '') { initFields(fields, cascadeKey = '') {
const newFields = fields.map(field => { const newFields = fields.map(field => {
return { return {
...field, ...field,
readOnly: field.inputModeDisplay === "READONLY", readOnly: field.inputModeDisplay === "READONLY",
required: field.inputModeDisplay === "REQUIRED", required: field.inputModeDisplay === "REQUIRED",
clearFlag: field.clearButton === 'Y' clearFlag: field.clearButton === 'Y',
renderer: this.getCustomizedRenderer(field.columnName, field).renderer,
} }
// if (field.validationTypeDisplay === 'UrlField') { // if (field.validationTypeDisplay === 'UrlField') {
// const {renderer} = this.getCustomizedRenderer(field.columnName, field); // const {renderer} = this.getCustomizedRenderer(field.columnName, field);
...@@ -168,11 +191,13 @@ export class ColumnBuilder extends BaseBuilder { ...@@ -168,11 +191,13 @@ export class ColumnBuilder extends BaseBuilder {
case 'Table': case 'Table':
case 'Tree': { case 'Tree': {
const newFields = this.fields.map(field => { // .filter(o => o.isVisible === 'Y') const newFields = this.fields.map(field => { // .filter(o => o.isVisible === 'Y')
const customizedRenderer = this.getCustomizedRenderer(field.columnName);
return { return {
...field, ...field,
readOnly: field.inputModeDisplay === "READONLY", readOnly: field.inputModeDisplay === "READONLY",
required: field.inputModeDisplay === "REQUIRED", required: field.inputModeDisplay === "REQUIRED",
clearFlag: field.clearButton === 'Y' clearFlag: field.clearButton === 'Y',
renderer: customizedRenderer.renderer,
} }
}); });
// return newFields; // return newFields;
...@@ -561,7 +586,7 @@ class BaseComponentBuilder extends BaseBuilder { ...@@ -561,7 +586,7 @@ class BaseComponentBuilder extends BaseBuilder {
'query-form', 'query-form',
{ {
props: { props: {
fields: newFields, fields: newFields.fields,
originFields: newFields._originFields, originFields: newFields._originFields,
buttons: this.props.tabButtons, buttons: this.props.tabButtons,
tabInfo: this.props, tabInfo: this.props,
......
...@@ -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-09 14:39:09 * @LastEditTime: 2024-08-11 10:51:32
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: 查询表单渲染 * @Description: 查询表单渲染
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
...@@ -69,11 +69,11 @@ export default { ...@@ -69,11 +69,11 @@ export default {
searchValue: '', searchValue: '',
} }
}, },
inject: ['config', 'testname'], inject: ['config'],
mounted() { mounted() {
this.configDatas = this.config(); this.configDatas = this.config();
console.log('config', this.config()) console.log('query-form', this.fields)
}, },
methods: { methods: {
onSearch() { // 搜索 onSearch() { // 搜索
......
...@@ -2,15 +2,15 @@ ...@@ -2,15 +2,15 @@
* @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-09 11:10:49 * @LastEditTime: 2024-08-11 11:08:27
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: * @Description:
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
*/ */
import Vue from 'vue'; import Vue from 'vue';
import {Button} from 'vant' import {Button} from 'vant'
import layouts from '../layout'; import layouts from '../layout/index.js';
import {ColumnBuilder, TabButtonBuilder, ComponentBuilder} from './utils.jsx' import {ColumnBuilder, TabButtonBuilder, ComponentBuilder} from './LayoutBuilder.jsx'
import QueryForm from './QueryForm'; import QueryForm from './QueryForm';
import DTable from './DTable'; import DTable from './DTable';
import DForm from './DForm'; import DForm from './DForm';
...@@ -28,6 +28,10 @@ const ConfigRenderComponent = { ...@@ -28,6 +28,10 @@ const ConfigRenderComponent = {
type: Boolean, type: Boolean,
default: true default: true
}, },
componentRenderers: {
type: Array,
default: () => [],
},
staticLayoutTabs: { staticLayoutTabs: {
type: Array, type: Array,
default: () => [], default: () => [],
...@@ -40,7 +44,7 @@ const ConfigRenderComponent = { ...@@ -40,7 +44,7 @@ const ConfigRenderComponent = {
queryParams: {}, // 路由参数 queryParams: {}, // 路由参数
} }
}, },
inject: ['config'], inject: ['dynamicInfo'],
created() { created() {
this.queryParams = { this.queryParams = {
...this.$route.params, ...this.$route.params,
...@@ -48,7 +52,13 @@ const ConfigRenderComponent = { ...@@ -48,7 +52,13 @@ const ConfigRenderComponent = {
} }
}, },
mounted() { mounted() {
this.configInfo = this.config(); this.configInfo = this.dynamicInfo().config;
console.log('this.componentRenderers', this.componentRenderers, this.dynamicInfo())
},
activated () {
this.configInfo = this.dynamicInfo().config;
console.log('激活', this.dynamicInfo().queryParams);
}, },
methods: { methods: {
getTabs(layoutTabs, state, layoutCode, createElement) { getTabs(layoutTabs, state, layoutCode, createElement) {
...@@ -100,7 +110,7 @@ const ConfigRenderComponent = { ...@@ -100,7 +110,7 @@ const ConfigRenderComponent = {
// .withTableFooterRenderers(tableFooterRenderers) // .withTableFooterRenderers(tableFooterRenderers)
.withLayoutCode(childrenTab.layoutCode || layoutCode) .withLayoutCode(childrenTab.layoutCode || layoutCode)
.withParentTabCode(parentTabCode) .withParentTabCode(parentTabCode)
// .withComponentRenderers(componentRenderers) .withComponentRenderers(this.componentRenderers)
.build(); .build();
const findField = find(tabFields, { formatCascadeFlag: 'Y' }); const findField = find(tabFields, { formatCascadeFlag: 'Y' });
......
...@@ -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-09 17:48:37 * @LastEditTime: 2024-08-12 09:31:49
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: * @Description:
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
...@@ -16,7 +16,10 @@ ...@@ -16,7 +16,10 @@
</h-header> </h-header>
<h-content> <h-content>
<van-loading size="24px" vertical v-if="loading">加载中...</van-loading> <van-loading size="24px" vertical v-if="loading">加载中...</van-loading>
<config-render-component v-if="configDatas.id" /> <config-render-component
v-if="configDatas.id"
:componentRenderers="componentRenderers"
/>
</h-content> </h-content>
<layout-buttons v-if="configDatas.id" /> <layout-buttons v-if="configDatas.id" />
</h-view> </h-view>
...@@ -25,7 +28,7 @@ ...@@ -25,7 +28,7 @@
<script> <script>
import {Loading} from 'vant'; import {Loading} from 'vant';
import LayoutButtons from './LayoutButtons'; import LayoutButtons from './LayoutButtons';
import ConfigRenderComponent from './ConfigRenderComponent/init.jsx'; import ConfigRenderComponent from './ConfigRenderComponent/index.jsx';
import {query, queryRoute} from './service' import {query, queryRoute} from './service'
import './index.less' import './index.less'
...@@ -45,6 +48,10 @@ export default { ...@@ -45,6 +48,10 @@ export default {
type: Boolean, type: Boolean,
default: true default: true
}, },
componentRenderers: { // 组件渲染
type: Array,
default: () => []
}
}, },
data () { data () {
return { return {
...@@ -61,57 +68,78 @@ export default { ...@@ -61,57 +68,78 @@ export default {
}, },
provide() { provide() {
return { return {
testname: () => this.testname, config: () => this.configDatas, // 提供方法,注意提供的方法要写在return对象中
config: () => this.configDatas // 提供方法,注意提供的方法要写在return对象中 queryParams: () => this.queryParams,
dynamicInfo: () => ({ // 配置的所有信息
layoutCode: this.layoutCode,
config: this.configDatas,
queryParams: {
...this.$route.params,
...this.$route.query
},
componentRenderers: this.componentRenderers
})
}; };
}, },
created() { created() {
window.localStorage.setItem('access_token', '75d8f55f-4043-454c-a647-ef62a9bf7e5b'); window.localStorage.setItem('access_token', '1f22ae78-2ee2-470c-bea4-916396e5632c');
this.queryParams = { this.queryParams = {
...this.$route.params, ...this.$route.params,
...this.$route.query ...this.$route.query
} }
}, },
activated() {
this.queryParams = {
...this.$route.params,
...this.$route.query
}
console.log('activated', this.queryParams)
},
beforeMount() { beforeMount() {
this.layoutCodeQuery(); this.layoutCodeQuery();
}, },
methods: { methods: {
// 获取页面布局配置 // 获取页面布局配置
async layoutCodeQuery() { async layoutCodeQuery() {
// const {disabled} = this.props; // const {disabled} = this.props;
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.queryParams.readOnly === "YES" || this.queryParams.readOnly == 'true') {
readOnly = true readOnly = true
} }
// if (disabled) { // if (disabled) {
// readOnly = disabled // readOnly = disabled
// } // }
this.qpara = { this.qpara = {
...this.queryParams, ...this.queryParams,
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)) {
// return; // return;
// } // }
if (this.layoutCode) { let res = {datas: {}, params: {}}
const {datas, params} = await query( if (this.layoutCode) {
this.layoutCode, res = await query(this.layoutCode, this.qpara);
this.qpara, } else {
); res = await queryRoute(this.layoutCode, this.qpara);
this.configDatas = datas;
this.params = params;
} else {
const {datas, params} = await queryRoute(
this.$route.path,
this.qpara,
);
this.configDatas = datas;
this.params = params;
}
this.loading = false;
} }
const dataSetObj = this.transformDateSetTree(res.datas.dataSetsTree);
this.configDatas = {...res.datas, dataSetObject: dataSetObj};
this.params = res.params;
this.loading = false;
},
transformDateSetTree(tree) {
let obj = {};
if (tree) {
tree.forEach(dataSets => {
dataSets.forEach(config => {
obj[config.tabCode] = {...config}
})
})
}
return obj;
}
}, },
} }
</script> </script>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: zong.wang01@hand-china.com * @Author: zong.wang01@hand-china.com
* @Date: 2024-07-29 16:36:23 * @Date: 2024-07-29 16:36:23
* @LastEditors: zong.wang01@hand-china.com * @LastEditors: zong.wang01@hand-china.com
* @LastEditTime: 2024-08-02 10:52:06 * @LastEditTime: 2024-08-10 00:00:58
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: * @Description:
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
...@@ -183,6 +183,7 @@ export function post (url, param = {}) { ...@@ -183,6 +183,7 @@ export function post (url, param = {}) {
// console.log(postName + ' url ' + url) // console.log(postName + ' url ' + url)
// console.log(postName + ' parameter ' + JSON.stringify(param, '', 2)) // console.log(postName + ' parameter ' + JSON.stringify(param, '', 2))
// } // }
console.log(param)
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
withTokenAxios({ withTokenAxios({
method: 'post', method: 'post',
...@@ -197,7 +198,71 @@ export function post (url, param = {}) { ...@@ -197,7 +198,71 @@ export function post (url, param = {}) {
}) })
} }
// put
export function put (url, param = {}, queryParams = {}) {
param.user_id = window.localStorage.user_id
param.access_token = window.localStorage.access_token
let headers = {}
if (window.localStorage.access_token) {
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + window.localStorage.access_token,
}
} else {
headers = {
'Content-Type': 'application/json',
}
}
return new Promise((resolve, reject) => {
withTokenAxios({
method: 'put',
headers: headers,
url: process.env.apiPath + url,
data: param,
params: queryParams
}).then(res => {
resolve(res)
}).catch(err => {
reject(err)
})
})
}
// delete请求
export function deletes (url, param = {}, queryParams = {}) {
param.user_id = window.localStorage.user_id
param.access_token = window.localStorage.access_token
let headers = {}
if (window.localStorage.access_token) {
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + window.localStorage.access_token,
}
} else {
headers = {
'Content-Type': 'application/json',
}
}
return new Promise((resolve, reject) => {
withTokenAxios({
method: 'delete',
headers: headers,
url: process.env.apiPath + url,
data: param,
params: queryParams
}).then(res => {
resolve(res)
}).catch(err => {
reject(err)
})
})
}
export default { export default {
get: get, get: get,
post: post, post: post,
put: put,
delete: deletes
} }
...@@ -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-09 15:12:26 * @LastEditTime: 2024-08-11 15:27:32
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: 工具类 * @Description: 工具类
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
...@@ -29,6 +29,10 @@ const getHeaderExtrasProp = (layoutCode, tabCode, props) => { ...@@ -29,6 +29,10 @@ const getHeaderExtrasProp = (layoutCode, tabCode, props) => {
); );
}; };
const getDataSetName = (config, tabCode) => {
return config.dataSetObject[tabCode].dataSetName || '';
};
/** /**
* 判断对象为空 * 判断对象为空
* @param v * @param v
...@@ -119,4 +123,11 @@ const getCurrentUser = () => { ...@@ -119,4 +123,11 @@ const getCurrentUser = () => {
}; };
export { getCustomizedProp, getCustomized,getHeaderExtrasProp, getOrganizationId, getCurrentUser }; export {
getCustomizedProp,
getCustomized,
getHeaderExtrasProp,
getDataSetName,
getOrganizationId,
getCurrentUser
};
<template> <template>
<Dynamic layoutCode="BP001" /> <Dynamic layoutCode="BP001" :componentRenderers="componentRenderers" />
</template> </template>
<script> <script>
import {Icon} from 'vant';
export default { export default {
name: 'TestDynamic', name: 'TestDynamic',
components: {
[Icon.name]: Icon,
},
data () { data () {
return {} return {
componentRenderers: [
{
tabCode: 'G_QUERY_RESULT',
columnName: 'bpName',
renderer: (record) => {
return <span style="color: #3789ff" onClick={() => this.toDetail(record)}>{record.bpName} <van-icon name="arrow" /></span>
},
},
]
}
},
methods: {
toDetail(record) {
console.log({
bpId: record.bpId,
bpName: record.bpName,
bpCode: record.bpCode,
})
this.$router.push({
name: 'DynamicDetail',
params: {
bpId: record.bpId,
bpName: record.bpName,
bpCode: record.bpCode,
}
})
},
}, },
methods: {},
} }
</script> </script>
......
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