Browse Source

w-form内置的分组组件w-form-group增加layout属性

main
likunming 2 weeks ago
parent
commit
83253caa2f
  1. 17
      io.sc.platform.core.frontend/src/platform/components/form/FormGroup.vue
  2. 15
      io.sc.platform.core.frontend/src/platform/components/form/ts/Constant.ts
  3. 19
      io.sc.platform.core.frontend/src/platform/components/label/WLabel.vue
  4. 33
      io.sc.platform.core.frontend/src/platform/components/radio/WExtRadio.vue

17
io.sc.platform.core.frontend/src/platform/components/form/FormGroup.vue

@ -79,15 +79,16 @@ const props = defineProps({
class: { type: String, default: undefined },
// divcarddivcontainerdiv
style: { type: String, default: undefined },
// divleftrightcenterbetweenform
// divleftrightcenterbetween
//
// left = display: flex; justify-content: flex-start;
// right = display: flex; justify-content: flex-end;
// center = display: flex; justify-content: center;
// between = display: flex; justify-content: space-between;
// form = form ;
// classstylealigndivclassstylealignstyle
align: { type: String, default: undefined },
//
layout: { type: String, default: Constant.FORM_GROUP_LAYOUT.ROW },
// `align` `form` form
colsNum: { type: [Number, Object], default: 0 },
// 使alignx
@ -141,7 +142,7 @@ const jsonStyle2String = (json: any) => {
};
/**
* 快速布局对应的样
* 内置`row`布局对应的对齐方
*/
const alignJson = {
left: {
@ -160,10 +161,6 @@ const alignJson = {
value: 'between',
style: 'display:flex; justify-content: space-between;' + 'column-gap: ' + props.xGap + 'px;' + 'row-gap: ' + props.yGap + 'px;',
},
form: {
value: 'form',
style: jsonStyle2String(useFormLayoutStyleComputed.value),
},
};
/**
@ -216,7 +213,9 @@ const contentStyleComputed = computed(() => {
//
styleStr = props.style + (props.style.trim().endsWith(';') ? '' : ';');
}
if (props.align && Tools.hasOwnProperty(alignJson, props.align)) {
if (props.layout === Constant.FORM_GROUP_LAYOUT.FORM) {
styleStr += jsonStyle2String(useFormLayoutStyleComputed.value);
} else if (props.layout === Constant.FORM_GROUP_LAYOUT.ROW && props.align && Tools.hasOwnProperty(alignJson, props.align)) {
styleStr += alignJson[props.align]['style'];
}
return styleStr;
@ -227,7 +226,7 @@ const formElementDivStyle = (field: any) => {
if (field.style) {
styleStr = field.style + (field.style.trim().endsWith(';') ? '' : ';');
}
if (props.align && props.align === alignJson.form.value) {
if (props.layout === Constant.FORM_GROUP_LAYOUT.FORM) {
styleStr += jsonStyle2String(form.getFieldStyle(field));
}
return styleStr;

15
io.sc.platform.core.frontend/src/platform/components/form/ts/Constant.ts

@ -9,6 +9,17 @@ class FormGroupMode {
static CONTAINER = 'container';
}
class FormGroupLayout {
/**
* form的布局方式
*/
static FORM = 'form';
/**
*
*/
static ROW = 'row';
}
/**
*
*/
@ -27,4 +38,8 @@ export class Constant {
* `w-form-group`
*/
static FORM_GROUP_MODE = FormGroupMode;
/**
* `w-form-group`
*/
static FORM_GROUP_LAYOUT = FormGroupLayout;
}

19
io.sc.platform.core.frontend/src/platform/components/label/WLabel.vue

@ -1,10 +1,27 @@
<template>
<span :style="props.size ? 'font-size:' + props.size + 'px;' : ''"> <span v-if="props.required" style="color: red">*</span> {{ props.label }} </span>
<span :style="styleComputed">
<span v-if="props.required" style="color: red">*</span> {{ props.label }}
<slot name="after"></slot>
</span>
</template>
<script setup lang="ts">
import { computed } from 'vue';
const props = defineProps({
required: { type: Boolean, default: false },
label: { type: String, default: '' },
size: { type: Number, default: undefined },
light: { type: Boolean, default: false },
});
const styleComputed = computed(() => {
const style = {};
if (props.size) {
style['font-size'] = props.size + 'px';
}
if (props.light) {
style['font-weight'] = 700;
}
return style;
});
</script>

33
io.sc.platform.core.frontend/src/platform/components/radio/WExtRadio.vue

@ -1,9 +1,14 @@
<template>
<div v-show="fieldMethodsClass.getShow(props, modelValue)" class="w-ext-radio">
<w-label :required="fieldMethodsClass.getRequired(props, modelValue)" :label="attrs.label" :size="16"></w-label>
<w-label :required="fieldMethodsClass.getRequired(props, modelValue)" :label="attrs.label" :size="16" :light="lightLabelComputed">
<template v-if="props.hideOptions" #after>
<q-btn flat round color="primary" icon="expand" size="xs" @click="expandOptionsModelValue = !expandOptionsModelValue" />
</template>
</w-label>
<div class="w-ext-radios">
<template v-for="opt in props.options" :key="opt.value">
<q-radio
v-show="!props.hideOptions || opt['value'] === modelValue || expandOptionsModelValue"
v-model="modelValue"
:val="opt['value']"
:dense="props.dense"
@ -30,20 +35,23 @@
</div>
</template>
<script setup lang="ts">
import { ref, useAttrs, computed, onMounted } from 'vue';
import { FormFieldProps } from '@/platform/components/form/FormField.ts';
import { ref, useAttrs } from 'vue';
import { FormFieldMethods } from '../form/FormField';
const radioRef = ref();
const attrs = useAttrs();
const modelValue = defineModel<string | boolean | number>();
const descModelValue = ref('');
const expandOptionsModelValue = ref(false);
interface FieldProps extends FormFieldProps {
dense?: boolean;
options: Array<() => void>;
selectedColor?: string;
selectedLabelColor?: string;
hideOptions?: boolean; //
lightNotHideOptionsLabel?: boolean; // label
}
const props = withDefaults(defineProps<FieldProps>(), {
showIf: true,
@ -53,6 +61,8 @@ const props = withDefaults(defineProps<FieldProps>(), {
},
selectedColor: undefined,
selectedLabelColor: undefined,
hideOptions: false,
lightNotHideOptionsLabel: false,
});
class FieldMethods extends FormFieldMethods {
updateValue = (value_) => {
@ -84,14 +94,29 @@ const getDescValue = () => {
const setDescValue = (val: any) => {
descModelValue.value = val;
};
const getExpandOptionsModelValue = () => {
return expandOptionsModelValue.value;
};
const setExpandOptionsModelValue = (val: boolean) => {
expandOptionsModelValue.value = val;
};
const lightLabelComputed = computed(() => {
if (props.lightNotHideOptionsLabel && !props.hideOptions) {
return true;
}
return false;
});
defineExpose({
validate: fieldMethodsClass.validate,
setValue: fieldMethodsClass.setValue,
getValue: fieldMethodsClass.getValue,
clearValue: fieldMethodsClass.clearValue,
getDescValue: getDescValue,
setDescValue: setDescValue,
getDescValue,
setDescValue,
getExpandOptionsModelValue,
setExpandOptionsModelValue,
});
</script>

Loading…
Cancel
Save