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

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

@ -9,6 +9,17 @@ class FormGroupMode {
static CONTAINER = 'container'; static CONTAINER = 'container';
} }
class FormGroupLayout {
/**
* form的布局方式
*/
static FORM = 'form';
/**
*
*/
static ROW = 'row';
}
/** /**
* *
*/ */
@ -27,4 +38,8 @@ export class Constant {
* `w-form-group` * `w-form-group`
*/ */
static FORM_GROUP_MODE = FormGroupMode; 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> <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> </template>
<script setup lang="ts"> <script setup lang="ts">
import { computed } from 'vue';
const props = defineProps({ const props = defineProps({
required: { type: Boolean, default: false }, required: { type: Boolean, default: false },
label: { type: String, default: '' }, label: { type: String, default: '' },
size: { type: Number, default: undefined }, 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> </script>

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

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

Loading…
Cancel
Save