Commit 1e780e6d authored by 王纵's avatar 王纵

表单提供change事件回调

parent e74e91c7
...@@ -90,7 +90,7 @@ export default { ...@@ -90,7 +90,7 @@ export default {
checked (flag) { checked (flag) {
if (!this.disabled) { if (!this.disabled) {
this.$emit('input', flag) this.$emit('input', flag)
this.$emit('change', flag) this.$emit('change', this.name, flag)
} }
}, },
}, },
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: zong.wang01@hand-china.com * @Author: zong.wang01@hand-china.com
* @Date: 2024-08-01 09:55:12 * @Date: 2024-08-01 09:55:12
* @LastEditors: zong.wang01@hand-china.com * @LastEditors: zong.wang01@hand-china.com
* @LastEditTime: 2024-08-19 11:20:34 * @LastEditTime: 2024-10-12 11:31:24
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: 动态渲染-文本框组件 * @Description: 动态渲染-文本框组件
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
...@@ -123,8 +123,8 @@ export default { ...@@ -123,8 +123,8 @@ export default {
}, },
methods: { methods: {
fieldInput (val) { fieldInput (val) {
this.$emit('input', Number(val)); this.$emit('input', val ? Number(val) : '')
this.$emit('change', Number(val)); this.$emit('change', this.name, val ? Number(val) : '')
}, },
onFocus() { onFocus() {
this.focused = true; this.focused = true;
......
...@@ -2,22 +2,13 @@ ...@@ -2,22 +2,13 @@
* @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-09-19 15:34:42 * @LastEditTime: 2024-10-12 11:30:35
* @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="d-form-item"> <div class="d-form-item">
<!-- <van-cell center :required="required">
<d-label :label="label" :help="help" slot="title" />
<span @click="showDate(true)" class="cell-value">
<input placeholder="请选择" :value="currentValue" readonly class="value-input"/>
<van-icon name="clear" v-show="clearable && currentValue" @click="clear"/>
<img src="../../../assets/date-icon.png" alt="" class="right-icon" v-show="!(clearable && currentValue)"/>
</span>
</van-cell> -->
<van-field <van-field
readonly readonly
v-model="description" v-model="description"
...@@ -32,7 +23,7 @@ ...@@ -32,7 +23,7 @@
<template #label> <template #label>
<d-label :label="label" :help="help" /> <d-label :label="label" :help="help" />
</template> </template>
<template #right-icon> <template #right-icon>
<van-icon name="clear" v-show="!disabled && 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" v-show="!disabled"/> <img src="../../../assets/date-icon.png" alt="" class="right-icon" v-show="!disabled"/>
...@@ -64,9 +55,9 @@ ...@@ -64,9 +55,9 @@
</template> </template>
<script> <script>
import {Cell, DatetimePicker, Popup, Icon, Field, Picker} from 'vant'; import {Cell, DatetimePicker, Popup, Icon, Field, Picker} from 'vant'
import DLabel from './DLabel'; import DLabel from './DLabel'
import {dateFormat} from '../../../utils/utils'; import {dateFormat} from '../../../utils/utils'
export default { export default {
name: 'DDate', name: 'DDate',
...@@ -86,7 +77,7 @@ export default { ...@@ -86,7 +77,7 @@ export default {
}, },
type: { type: {
type: String, type: String,
default: 'date', //'DatePicker' default: 'date' // 'DatePicker'
}, },
name: { name: {
type: String, type: String,
...@@ -102,19 +93,19 @@ export default { ...@@ -102,19 +93,19 @@ export default {
}, },
value: { value: {
type: String, type: String,
default: "", default: ''
}, },
disabled: { disabled: {
type: Boolean, type: Boolean,
default: false, default: false
}, },
required: { required: {
type: Boolean, type: Boolean,
default: false, default: false
}, },
clearable: { clearable: {
type: Boolean, type: Boolean,
default: false, default: false
} }
}, },
data () { data () {
...@@ -127,94 +118,97 @@ export default { ...@@ -127,94 +118,97 @@ export default {
month: 'year-month', month: 'year-month',
year: 'year-month', year: 'year-month',
week: 'date', week: 'date',
date: 'date', date: 'date'
}, },
currentValue: '', currentValue: '',
description: '', description: '',
pickerValue: '', pickerValue: '',
visible: false, visible: false,
columns: [], columns: []
} }
}, },
watch: { watch: {
value: function(newValue, oldValue) { value: function (newValue, oldValue) {
if (newValue !== oldValue && this.currentValue !== newValue) { if (newValue !== oldValue && this.currentValue !== newValue) {
this.currentValue = newValue; this.currentValue = newValue
if (newValue) { if (newValue) {
this.dateParse(this.currentValue); this.dateParse(this.currentValue)
} }
} }
} }
}, },
mounted() { mounted () {
this.init(); this.init()
}, },
methods: { methods: {
init() { init () {
this.currentValue = this.value
if (this.value) {
this.dateParse(this.currentValue)
}
if (this.type === 'year') { if (this.type === 'year') {
this.setColumns(); this.setColumns()
} }
}, },
setColumns() { setColumns () {
const currentYear = new Date().getFullYear(); const currentYear = new Date().getFullYear()
const cols = [currentYear]; const cols = [currentYear]
for (let i = 1; i <= 10; i++) { for (let i = 1; i <= 10; i++) {
cols.unshift(currentYear - i); cols.unshift(currentYear - i)
cols.push(currentYear + i); cols.push(currentYear + i)
} }
this.columns = cols; this.columns = cols
}, },
dateParse(val) { dateParse (val) {
if (val) { if (val) {
const {value, description} = dateFormat(this.type, new Date(val)); const {value, description} = dateFormat(this.type, new Date(val))
this.currentValue = value; this.currentValue = value
this.description = description; this.description = description
} else { } else {
this.currentValue = val; this.currentValue = val
this.description = val; this.description = val
} }
}, },
filter(type, options) { filter (type, options) {
if (this.type === 'year' && type === 'month') { if (this.type === 'year' && type === 'month') {
return ['', '', '', '']; return ['', '', '', '']
} }
return options; return options
}, },
clear(e) { clear (e) {
e.preventDefault() e.preventDefault()
e.stopPropagation() e.stopPropagation()
this.dateConfirm('') this.dateConfirm('')
}, },
showDate(flag) { showDate (flag) {
if (!this.disabled) { if (!this.disabled) {
this.visible = flag; this.visible = flag
if (flag) { if (flag) {
this.pickerValue = this.currentValue ? new Date(this.currentValue) : ''; this.pickerValue = this.currentValue ? new Date(this.currentValue) : ''
if (this.type === 'year') { if (this.type === 'year') {
this.$refs.yearRef.setValues([this.description]); this.$refs.yearRef.setValues([this.description])
} }
} }
} }
}, },
dateConfirm(date) { dateConfirm (date) {
this.showDate(false); this.showDate(false)
if (date) { if (date) {
if (this.type === 'year') { if (this.type === 'year') {
this.currentValue = `${date}-00-00`; this.currentValue = `${date}-00-00`
this.description = date; this.description = date
} else { } else {
const {value, description} = dateFormat(this.type, date); const {value, description} = dateFormat(this.type, date)
this.currentValue = value; this.currentValue = value
this.description = description; this.description = description
} }
} else { } else {
this.currentValue = ''; this.currentValue = ''
this.description = ''; this.description = ''
} }
this.$emit('input', this.currentValue); this.$emit('input', this.currentValue)
this.$emit('change', this.currentValue); this.$emit('change', this.name, this.currentValue)
}, }
// dateFormat(type, time) { // 时间格式化 2019-09-08 // dateFormat(type, time) { // 时间格式化 2019-09-08
// let year = time.getFullYear(); // let year = time.getFullYear();
// let month = this.suppField(time.getMonth() + 1); // let month = this.suppField(time.getMonth() + 1);
...@@ -247,7 +241,7 @@ export default { ...@@ -247,7 +241,7 @@ export default {
// suppField(num) { // 补充显示 // suppField(num) { // 补充显示
// return `${num < 10 ? `0`: ''}${num}`; // return `${num < 10 ? `0`: ''}${num}`;
// } // }
}, }
} }
</script> </script>
......
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
* @Author: zong.wang01@hand-china.com * @Author: zong.wang01@hand-china.com
* @Date: 2024-08-01 09:55:12 * @Date: 2024-08-01 09:55:12
* @LastEditors: zong.wang01@hand-china.com * @LastEditors: zong.wang01@hand-china.com
* @LastEditTime: 2024-08-19 11:22:50 * @LastEditTime: 2024-10-12 11:31:50
* @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="d-form-item"> <div class="d-form-item">
<van-field <van-field
v-model="currentValue" v-model="currentValue"
:placeholder="disabled ? '' : '请输入'" :placeholder="disabled ? '' : '请输入'"
@input="fieldInput" @input="fieldInput"
...@@ -26,21 +26,21 @@ ...@@ -26,21 +26,21 @@
<template #label> <template #label>
<d-label :label="label" :help="help" /> <d-label :label="label" :help="help" />
</template> </template>
<template #extra> <template #extra>
<span v-if="type === 'CentField'">%</span> <span v-if="type === 'CentField'">%</span>
</template> </template>
</van-field> </van-field>
</div> </div>
</template> </template>
<script> <script>
import {Cell, Field, Icon} from 'vant'; import {Cell, Field, Icon} from 'vant'
import DLabel from './DLabel'; import DLabel from './DLabel'
export default { export default {
name: 'DCheckbox', name: 'DField',
components: { components: {
[Cell.name]: Cell, [Cell.name]: Cell,
[Field.name]: Field, [Field.name]: Field,
...@@ -50,11 +50,11 @@ export default { ...@@ -50,11 +50,11 @@ export default {
props: { props: {
fieldConfig: { fieldConfig: {
type: Object, type: Object,
default: {} default: () => ({})
}, },
type: { type: {
type: String, type: String,
default: 'TextField', default: 'TextField'
}, },
name: { name: {
type: String, type: String,
...@@ -69,47 +69,47 @@ export default { ...@@ -69,47 +69,47 @@ export default {
default: '' default: ''
}, },
value: { value: {
type: String | Number, type: [String, Number],
default: '', default: ''
}, },
disabled: { disabled: {
type: Boolean, type: Boolean,
default: false, default: false
}, },
required: { required: {
type: Boolean, type: Boolean,
default: false, default: false
}, },
clearable: { clearable: {
type: Boolean, type: Boolean,
default: false, default: false
} }
}, },
data () { data () {
return { return {
fieldType: { fieldType: {
TextField: 'text', TextField: 'text',
TextArea: 'textarea', TextArea: 'textarea',
NumberField: 'number', NumberField: 'number',
EmailField: 'text', EmailField: 'text',
CentField: 'number' CentField: 'number'
}, },
currentValue: '',
} }
}, },
watch: { computed: {
value: function(newValue, oldValue) { currentValue: {
if (newValue !== oldValue && this.currentValue !== newValue) { get() {
this.currentValue = newValue; return this.value
} },
set() {}
} }
}, },
methods: { methods: {
fieldInput (val) { fieldInput (val) {
this.$emit('input', val) this.$emit('input', val)
this.$emit('change', val) this.$emit('change', this.name, val)
}, }
}, }
} }
</script> </script>
......
...@@ -2,28 +2,13 @@ ...@@ -2,28 +2,13 @@
* @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-09-19 15:34:48 * @LastEditTime: 2024-10-12 15:00:31
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: 动态渲染-Lov * @Description: 动态渲染-Lov
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
--> -->
<template> <template>
<div class="d-form-item d-lov"> <div class="d-form-item d-lov">
<!-- <van-cell center :required="required" :title="label">
<d-label :label="label" :help="help" slot="title" />
<template #right-icon>
<span @click="changeVisible(true)">
<span v-if="multiple">
<van-tag v-for="(val, index) in currentValue" closeable size="medium" @close="del(val, index)" :key="val[lovConfig.valueField]">{{val[lovConfig.displayField]}}</van-tag>
</span>
<span v-if="!currentValue || currentValue.length === 0" class="placeholder">请选择</span>
<span v-else>{{currentValue[lovConfig.displayField || 'label']}}</span>
</span>
<van-icon name="arrow" style="margin-left: 5px" />
</template>
</van-cell> -->
<van-field <van-field
v-model="fieldValue" v-model="fieldValue"
:name="name" :name="name"
...@@ -34,15 +19,15 @@ ...@@ -34,15 +19,15 @@
<template #label> <template #label>
<d-label :label="label" :help="help" /> <d-label :label="label" :help="help" />
</template> </template>
<template #input> <template #input>
<div @click="changeVisible(true)" class="cell-value"> <div @click="changeVisible(true)" class="cell-value">
<span v-if="!currentValue || currentValue.length === 0" class="placeholder">{{disabled ? '' : '请选择'}}</span> <span v-if="!fieldValue" class="placeholder">{{disabled ? '' : '请选择'}}</span>
<span v-else>{{valueDisplay()}}</span> <span v-else>{{valueDisplay()}}</span>
</div> </div>
</template> </template>
<template #right-icon > <template #right-icon >
<van-icon name="clear" v-show="!disabled && clearable && !(!currentValue || currentValue.length === 0)" @click="clear"/> <van-icon name="clear" v-show="!disabled && clearable && fieldValue" @click="clear"/>
<van-icon name="arrow" v-show="!disabled" /> <van-icon name="arrow" v-show="!disabled" />
</template> </template>
</van-field> </van-field>
...@@ -59,13 +44,17 @@ ...@@ -59,13 +44,17 @@
placeholder="搜索" placeholder="搜索"
@search="onSearch" @search="onSearch"
/> />
<d-scroll <van-list
ref="scroll" v-model="loading"
:pullUp="true" :finished="finished"
@pullingUp="getLovData"> :immediateCheck="false"
finished-text="没有更多了"
@load="getLovData"
style="overflow: auto;"
>
<ul class="list"> <ul class="list">
<li <li
v-for="item in lovData" v-for="item in lovData"
:class="value === item[lovConfig.valueField] ? 'item active' : 'item'" :class="value === item[lovConfig.valueField] ? 'item active' : 'item'"
:key="item[lovConfig.valueField]" :key="item[lovConfig.valueField]"
> >
...@@ -86,7 +75,7 @@ ...@@ -86,7 +75,7 @@
</div> </div>
</li> </li>
</ul> </ul>
</d-scroll> </van-list>
<div class="footer" v-if="multiple"> <div class="footer" v-if="multiple">
<van-checkbox shape="square" v-model="selectAllFlag" @change="selectAllData">全选</van-checkbox> <van-checkbox shape="square" v-model="selectAllFlag" @change="selectAllData">全选</van-checkbox>
<button type="primary" @click="confirm">确定</button> <button type="primary" @click="confirm">确定</button>
...@@ -96,16 +85,15 @@ ...@@ -96,16 +85,15 @@
</template> </template>
<script> <script>
import {Cell, Switch, Icon, Popup, Search, Checkbox, Tag, Field} from 'vant'; import {Cell, Switch, Icon, Popup, Search, Checkbox, Tag, Field, List} from 'vant'
import DLabel from './DLabel'; import DLabel from './DLabel'
import {DScroll} from '../../../LayoutComponents'; import {getLovConfig, getLovData} from '../../../service'
import {getLovConfig, getLovData} from '../../../service';
export default { export default {
name: 'DLov', name: 'DLov',
components: { components: {
DLabel, DLabel,
DScroll, [List.name]: List,
[Cell.name]: Cell, [Cell.name]: Cell,
[Switch.name]: Switch, [Switch.name]: Switch,
[Icon.name]: Icon, [Icon.name]: Icon,
...@@ -113,7 +101,7 @@ export default { ...@@ -113,7 +101,7 @@ export default {
[Search.name]: Search, [Search.name]: Search,
[Checkbox.name]: Checkbox, [Checkbox.name]: Checkbox,
[Tag.name]: Tag, [Tag.name]: Tag,
[Field.name]: Field, [Field.name]: Field
}, },
props: { props: {
fieldConfig: { fieldConfig: {
...@@ -133,24 +121,24 @@ export default { ...@@ -133,24 +121,24 @@ export default {
default: '' default: ''
}, },
value: { value: {
type: Object | Array, type: [Object, Array],
default: () => ({}), default: () => undefined
}, },
disabled: { disabled: {
type: Boolean, type: Boolean,
default: false, default: false
}, },
required: { required: {
type: Boolean, type: Boolean,
default: false, default: false
}, },
multiple: { // 是否多选 multiple: { // 是否多选
type: Boolean, type: Boolean,
default: false, default: false
}, },
clearable: { clearable: {
type: Boolean, type: Boolean,
default: false, default: false
}, },
cascadesParams: { cascadesParams: {
type: Object, type: Object,
...@@ -162,7 +150,7 @@ export default { ...@@ -162,7 +150,7 @@ export default {
fieldValue: '', // 该变量纯粹用来判断是否有选值,给form校验用 fieldValue: '', // 该变量纯粹用来判断是否有选值,给form校验用
lovConfig: {}, // lov配置 lovConfig: {}, // lov配置
lovData: [], lovData: [],
searchValue: '', //搜索字段 searchValue: '', // 搜索字段
selectAllFlag: false, selectAllFlag: false,
page: 0, page: 0,
size: 10, size: 10,
...@@ -170,21 +158,27 @@ export default { ...@@ -170,21 +158,27 @@ export default {
testValue: false, testValue: false,
visible: false, visible: false,
options: [], options: [],
loading: false,
finished: false,
} }
}, },
watch: { watch: {
value: { value: {
handler(newValue, oldValue) { handler (newValue, oldValue) {
console.log(' this.handler', newValue, oldValue)
if (JSON.stringify(newValue) !== JSON.stringify(oldValue)) { if (JSON.stringify(newValue) !== JSON.stringify(oldValue)) {
this.currentValue = newValue; this.currentValue = newValue
this.fieldValue = newValue ? JSON.stringify(newValue) : ''; this.fieldValue = newValue ? JSON.stringify(newValue) : ''
} }
}, },
deep: true deep: true
} }
}, },
mounted() { mounted () {
this.getLovConfig(); this.currentValue = this.value
this.fieldValue = this.value ? JSON.stringify(this.value) : ''
console.log(' this.currentValue', this.currentValue)
this.getLovConfig()
}, },
methods: { methods: {
getLovConfig() { getLovConfig() {
...@@ -192,83 +186,80 @@ export default { ...@@ -192,83 +186,80 @@ export default {
this.lovConfig = res; this.lovConfig = res;
}); });
}, },
getLovData() { getLovData () {
const {queryUrl, lovCode} = this.lovConfig; const {queryUrl, lovCode, queryFields} = this.lovConfig
const params = { const params = {
lovCode, lovCode,
page: this.page, page: this.page,
size: this.size, size: this.size,
[queryFields[0].field]: this.searchValue,
...this.cascadesParams ...this.cascadesParams
}; }
this.loading = true
getLovData(queryUrl, params).then(res => { getLovData(queryUrl, params).then(res => {
this.lovData = this.lovData.concat(res.content.map(item => ({...item, _selected: false}))); this.lovData = this.lovData.concat(res.content.map(item => ({...item, _selected: false})))
if (res.totalElements > this.lovData.length) { if (res.totalElements > this.lovData.length) {
this.page = this.page + 1; this.page = this.page + 1
this.$refs.scroll.update(false) this.finished = false
} else { } else {
this.$refs.scroll.update(true) this.finished = true
} }
}); }).finally(() => {
this.loading = false
})
}, },
changeVisible(flag) { changeVisible (flag) {
if (!this.disabled) { if (!this.disabled) {
this.visible = flag; this.visible = flag
if (flag) { if (flag) {
if (this.cascadesParams && JSON.stringify(this.cascadesParams) !== '{}') { // 存在级联查询参数 if (this.cascadesParams && JSON.stringify(this.cascadesParams) !== '{}') { // 存在级联查询参数
this.page = 0; this.page = 0
this.getLovData(); this.lovData = []
this.getLovData()
} else if (this.lovData.length === 0) { } else if (this.lovData.length === 0) {
this.getLovData() this.getLovData()
} }
} }
} }
}, },
selectData(val) { selectData (val) {
this.currentValue = val; this.currentValue = val
this.changeVisible(false); this.changeVisible(false)
this.inputValue(this.currentValue); this.inputValue(this.currentValue)
}, },
// 确定 // 确定
confirm() { confirm () {
this.changeVisible(false); this.changeVisible(false)
const data = this.lovData.filter(o => o._selected); const data = this.lovData.filter(o => o._selected)
this.currentValue = data; this.currentValue = data
this.inputValue(this.currentValue); this.inputValue(this.currentValue)
}, },
// 删除 - 暂时无用 onSearch () {
del(val, index) { this.page = 0;
const newData = [...this.currentValue]; this.lovData = [];
newData.splice(index, 1); this.getLovData();
this.currentValue = [...newData];
this.$emit('input', this.currentValue);
this.$emit('change', this.currentValue);
const lindex = this.lovData.findIndex(o => o[this.lovConfig.valueField] === o[this.lovConfig.valueField]);
this.lovData[lindex]._selected = false;
},
onSearch() {
}, },
// 全选 // 全选
selectAllData(flag) { selectAllData (flag) {
this.lovData = this.lovData.map(o => ({...o, _selected: flag})); this.lovData = this.lovData.map(o => ({...o, _selected: flag}))
}, },
inputValue(val) { inputValue (val) {
this.fieldValue = val ? JSON.stringify(val) : ''; this.fieldValue = val ? JSON.stringify(val) : ''
this.$emit('input', val); this.$emit('input', val)
this.$emit('change', val); this.$emit('change', this.name, val)
}, },
valueDisplay() { valueDisplay () {
console.log('this.currentValue', this.currentValue)
if (this.multiple) { if (this.multiple) {
return this.currentValue.map(o => o[this.lovConfig.displayField]).join('、'); return this.currentValue.map(o => o[this.lovConfig.displayField]).join('、')
} else { } else {
return this.currentValue[this.lovConfig.displayField]; return this.currentValue[this.lovConfig.displayField]
} }
}, },
clear() { clear () {
this.inputValue(undefined); this.currentValue = undefined
}, this.inputValue(undefined)
}, }
}
} }
</script> </script>
...@@ -307,7 +298,7 @@ export default { ...@@ -307,7 +298,7 @@ export default {
} }
.list { .list {
padding: 0 16px; padding: 0 16px;
.item { .item {
font-size: 14px; font-size: 14px;
color: #383F45; color: #383F45;
...@@ -339,7 +330,6 @@ export default { ...@@ -339,7 +330,6 @@ export default {
.van-checkbox__label { .van-checkbox__label {
flex: 1; flex: 1;
} }
} }
</style> </style>
...@@ -2,26 +2,13 @@ ...@@ -2,26 +2,13 @@
* @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-09-19 15:34:53 * @LastEditTime: 2024-10-12 14:56:42
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: 动态渲染-Select * @Description: 动态渲染-Select
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
--> -->
<template> <template>
<div class="d-form-item d-select"> <div class="d-form-item d-select">
<!-- <van-cell
center
:required="required"
:class="disabled && 'van-field--disabled'"
>
<d-label :label="label" :help="help" slot="title" />
<div @click="showSelectOption(true)" class="cell-value">
<input placeholder="请选择" :value="currentValue.meaning" readonly class="value-input"/>
<van-icon name="arrow" />
</div>
</van-cell> -->
<van-field <van-field
v-model="fieldValue" v-model="fieldValue"
:name="name" :name="name"
...@@ -44,7 +31,6 @@ ...@@ -44,7 +31,6 @@
</template> </template>
</van-field> </van-field>
<van-popup v-model="visible" round position="bottom" class="d-select-popup" get-container="body"> <van-popup v-model="visible" round position="bottom" class="d-select-popup" get-container="body">
<div class="title"> <div class="title">
<span class="cancel" @click="showSelectOption(false)">取消</span> <span class="cancel" @click="showSelectOption(false)">取消</span>
...@@ -52,8 +38,8 @@ ...@@ -52,8 +38,8 @@
<span class="confirm" @click="onConfirm">确定</span> <span class="confirm" @click="onConfirm">确定</span>
</div> </div>
<ul class="list"> <ul class="list">
<li <li
v-for="(option, index) in options" v-for="(option, index) in options"
:class="option._selected ? 'item active' : 'item'" :class="option._selected ? 'item active' : 'item'"
:key="option.value" :key="option.value"
@click="selectOption(option, index)" @click="selectOption(option, index)"
...@@ -101,20 +87,20 @@ export default { ...@@ -101,20 +87,20 @@ export default {
default: '' default: ''
}, },
value: { value: {
type: String | Number, type: [String, Number],
default: '', default: ''
}, },
disabled: { disabled: {
type: Boolean, type: Boolean,
default: false, default: false
}, },
required: { required: {
type: Boolean, type: Boolean,
default: false, default: false
}, },
clearable: { clearable: {
type: Boolean, type: Boolean,
default: false, default: false
}, },
cascadesParams: { cascadesParams: {
type: Object, type: Object,
...@@ -129,39 +115,60 @@ export default { ...@@ -129,39 +115,60 @@ export default {
value: '' value: ''
}, },
visible: false, visible: false,
options: [], options: []
} }
}, },
inject: ['dynamicInfo'],
watch: { watch: {
value: function(newValue, oldValue) { value: function (newValue, oldValue) {
if (newValue !== oldValue) { if (newValue !== oldValue) {
if (this.multiple) { if (this.multiple) {
if (JSON.stringify(newValue) !== JSON.stringify(this.currentValue)) { if (JSON.stringify(newValue) !== JSON.stringify(this.currentValue)) {
this.formatValue(); this.formatValue()
} }
} else if (newValue !== this.currentValue.value) { } else if (newValue !== this.currentValue.value) {
this.formatValue(); this.formatValue()
} }
} }
}, },
cascadesParams: { cascadesParams: {
handler(newValue, oldValue) { handler (newValue, oldValue) {
if (JSON.stringify(newValue) !== JSON.stringify(oldValue)) { if (JSON.stringify(newValue) !== JSON.stringify(oldValue)) {
this.getOptions(); this.getOptions()
}
},
deep: true
},
fieldConfig: {
handler (newValue, oldValue) {
if (JSON.stringify(newValue) !== JSON.stringify(oldValue)) {
if (JSON.stringify(newValue.queryParams) !== JSON.stringify(oldValue.queryParams) ||
newValue.lookupCode !== oldValue.lookupCode ||
JSON.stringify(newValue.selectOptions) !== JSON.stringify(oldValue.selectOptions)) {
this.getOptions();
}
} }
}, },
deep: true deep: true
} }
}, },
mounted() { mounted () {
this.getOptions(); this.getOptions()
}, },
methods: { methods: {
getOptions() { getOptions() {
getSelectOptions({lovCode: this.fieldConfig.lookupCode, ...this.cascadesParams}).then(res => { if (this.fieldConfig.lookupCode) { // 取值列表code
getSelectOptions({lovCode: this.fieldConfig.lookupCode, ...this.cascadesParams}).then(res => {
this.options = res.map(item => ({...item, _selected: false})); this.options = res.map(item => ({...item, _selected: false}));
this.formatValue(); this.formatValue();
}); });
} else { // 取传递的options
this.options = (this.fieldConfig.selectOptions || []).map(item => ({
...item,
_selected: false,
}))
this.formatValue();
}
}, },
formatValue() { formatValue() {
const selectData = []; const selectData = [];
...@@ -220,7 +227,7 @@ export default { ...@@ -220,7 +227,7 @@ export default {
inputValue(val) { inputValue(val) {
this.fieldValue = val ? JSON.stringify(val) : ''; this.fieldValue = val ? JSON.stringify(val) : '';
this.$emit('input', val); this.$emit('input', val);
this.$emit('change', val); this.$emit('change', this.name, this.currentValue)
}, },
valueDisplay() { valueDisplay() {
if (this.multiple) { if (this.multiple) {
...@@ -276,7 +283,7 @@ export default { ...@@ -276,7 +283,7 @@ export default {
font: normal normal normal 14px / 1 'vant-icon'; font: normal normal normal 14px / 1 'vant-icon';
font: normal normal normal 14px / 1 var(--van-icon-font-family, 'vant-icon'); font: normal normal normal 14px / 1 var(--van-icon-font-family, 'vant-icon');
text-rendering: auto; text-rendering: auto;
color: @primary-color; color: var(--theme-color);
&::after { &::after {
position: absolute; position: absolute;
right: 0; right: 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-19 11:22:20 * @LastEditTime: 2024-10-12 15:05:05
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: 动态渲染-开关组件 * @Description: 动态渲染-开关组件
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
...@@ -89,7 +89,7 @@ export default { ...@@ -89,7 +89,7 @@ export default {
checked (flag) { checked (flag) {
if (!this.disabled) { if (!this.disabled) {
this.$emit('input', flag ? 1 : 0); this.$emit('input', flag ? 1 : 0);
this.$emit('change', flag ? 1 : 0); this.$emit('change', this.name, 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-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-09-23 11:07:17 * @LastEditTime: 2024-10-12 15:25:23
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: 表单渲染 * @Description: 表单渲染
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
:disabled="readOnly || field.readOnly" :disabled="readOnly || field.readOnly"
:required="field.required" :required="field.required"
:clearable="field.clearFlag" :clearable="field.clearFlag"
@change="fieldChange"
/> />
<d-currency <d-currency
...@@ -41,6 +42,7 @@ ...@@ -41,6 +42,7 @@
:disabled="readOnly || field.readOnly" :disabled="readOnly || field.readOnly"
:required="field.required" :required="field.required"
:clearable="field.clearFlag" :clearable="field.clearFlag"
@change="fieldChange"
/> />
<d-switch <d-switch
...@@ -77,6 +79,7 @@ ...@@ -77,6 +79,7 @@
:clearable="field.clearFlag" :clearable="field.clearFlag"
:multiple="field.multiple === 1" :multiple="field.multiple === 1"
:cascadesParams="getCascadesParams(field)" :cascadesParams="getCascadesParams(field)"
:routeParams="queryParams"
@change="fieldChange" @change="fieldChange"
/> />
...@@ -93,6 +96,7 @@ ...@@ -93,6 +96,7 @@
:clearable="field.clearFlag" :clearable="field.clearFlag"
:cascadesParams="getCascadesParams(field)" :cascadesParams="getCascadesParams(field)"
:multiple="field.multiple === 1" :multiple="field.multiple === 1"
:routeParams="queryParams"
@change="fieldChange" @change="fieldChange"
/> />
...@@ -107,6 +111,7 @@ ...@@ -107,6 +111,7 @@
:disabled="readOnly || field.readOnly" :disabled="readOnly || field.readOnly"
:required="field.required" :required="field.required"
:clearable="field.clearFlag" :clearable="field.clearFlag"
@change="fieldChange"
/> />
<d-url <d-url
...@@ -247,6 +252,7 @@ export default { ...@@ -247,6 +252,7 @@ export default {
} }
} }
}) })
this.fieldsObj = {...this.fieldsObj}
this.originFieldsObj = {...this.fieldsObj}; this.originFieldsObj = {...this.fieldsObj};
}, },
async loadData() { async loadData() {
...@@ -291,7 +297,8 @@ export default { ...@@ -291,7 +297,8 @@ export default {
} }
return {}; return {};
}, },
fieldChange(val) { fieldChange (name, val) {
this.dynamicInfo().formUpdate(this.tabInfo.tabCode, this, name, val, this.fieldsObj)
// console.log(val) // console.log(val)
}, },
validate() { validate() {
...@@ -365,6 +372,15 @@ export default { ...@@ -365,6 +372,15 @@ export default {
setFieldsValue(fieldsValue) { setFieldsValue(fieldsValue) {
this.fieldsObj = {...this.fieldsObj, ...fieldsValue}; this.fieldsObj = {...this.fieldsObj, ...fieldsValue};
}, },
setFieldConfig (columnName, config) {
const index = this.fieldList.findIndex(o => o.columnName === columnName);
if (index > -1) {
this.fieldList[index] = {
...this.fieldList[index],
...config
}
}
},
buttonsClick(btn) { buttonsClick(btn) {
const customBtn = this.componentButtons.find(o => o.name === btn.name); // 采用页面传入的方法 const customBtn = this.componentButtons.find(o => o.name === btn.name); // 采用页面传入的方法
if (customBtn && customBtn.clickFunction) { if (customBtn && customBtn.clickFunction) {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: zong.wang01@hand-china.com * @Author: zong.wang01@hand-china.com
* @Date: 2024-08-16 09:39:36 * @Date: 2024-08-16 09:39:36
* @LastEditors: zong.wang01@hand-china.com * @LastEditors: zong.wang01@hand-china.com
* @LastEditTime: 2024-09-19 15:27:44 * @LastEditTime: 2024-10-12 14:57:31
* @Version: 1.0.0 * @Version: 1.0.0
* @Description: * @Description:
* @Copyright: Copyright (c) 2021, Hand-RongJing * @Copyright: Copyright (c) 2021, Hand-RongJing
...@@ -50,7 +50,7 @@ export default { ...@@ -50,7 +50,7 @@ export default {
} }
}, },
created() { created() {
window.localStorage.access_token = '71fc3203-0d1b-4f62-adea-d08dd473c0cc' window.localStorage.access_token = 'f5872e6f-6e47-498f-ba2c-db07470f0f25'
}, },
methods: { methods: {
configLoadHandle(config) { // 查询配置信息之后的回调 configLoadHandle(config) { // 查询配置信息之后的回调
......
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