Browse Source

表格优化提交

main
likunming 1 year ago
parent
commit
b23d7b404d
  1. 2
      io.sc.platform.core.frontend/package.json
  2. 14
      io.sc.platform.core.frontend/src/platform/components/form/WForm.vue
  3. 26
      io.sc.platform.core.frontend/src/platform/components/form/elements/WCheckbox.vue
  4. 136
      io.sc.platform.core.frontend/src/platform/components/form/elements/WCodeMirror.vue
  5. 188
      io.sc.platform.core.frontend/src/platform/components/form/elements/WColorInput.vue
  6. 188
      io.sc.platform.core.frontend/src/platform/components/form/elements/WColorInputPalette.vue
  7. 171
      io.sc.platform.core.frontend/src/platform/components/form/elements/WCron.vue
  8. 31
      io.sc.platform.core.frontend/src/platform/components/form/elements/WDate.vue
  9. 29
      io.sc.platform.core.frontend/src/platform/components/form/elements/WNumber.vue
  10. 17
      io.sc.platform.core.frontend/src/platform/components/form/elements/WOptionGroup.vue
  11. 27
      io.sc.platform.core.frontend/src/platform/components/form/elements/WPassword.vue
  12. 178
      io.sc.platform.core.frontend/src/platform/components/form/elements/WPosition.vue
  13. 27
      io.sc.platform.core.frontend/src/platform/components/form/elements/WSelect.vue
  14. 1
      io.sc.platform.core.frontend/src/platform/components/form/elements/WSelectUserText.vue
  15. 27
      io.sc.platform.core.frontend/src/platform/components/form/elements/WText.vue
  16. 32
      io.sc.platform.core.frontend/src/platform/components/form/elements/WTextBtn.vue
  17. 27
      io.sc.platform.core.frontend/src/platform/components/form/elements/WTextarea.vue

2
io.sc.platform.core.frontend/package.json

@ -1,6 +1,6 @@
{ {
"name": "platform-core", "name": "platform-core",
"version": "8.1.126", "version": "8.1.127",
"description": "前端核心包,用于快速构建前端的脚手架", "description": "前端核心包,用于快速构建前端的脚手架",
"//main": "库的主文件", "//main": "库的主文件",
"main": "dist/platform-core.js", "main": "dist/platform-core.js",

14
io.sc.platform.core.frontend/src/platform/components/form/WForm.vue

@ -8,7 +8,6 @@
v-if="field.name" v-if="field.name"
v-model="formData[field.name]" v-model="formData[field.name]"
v-bind="field" v-bind="field"
:form-data="formData"
:form="instance" :form="instance"
:class=" :class="
(field.colsFirst ? 'col-start-1 ' : ' ') + (field.colsFirst ? 'col-start-1 ' : ' ') +
@ -46,7 +45,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, reactive, watch, computed, toRaw, defineProps, useAttrs, getCurrentInstance } from 'vue'; import { ref, reactive, watch, computed, toRaw, defineProps, useAttrs, getCurrentInstance } from 'vue';
import { useQuasar } from 'quasar'; import { useQuasar } from 'quasar';
import { VueTools } from '@/platform'; import { VueTools, Tools } from '@/platform';
import { PageStatusEnum } from '@/platform/components/utils'; import { PageStatusEnum } from '@/platform/components/utils';
const $q = useQuasar(); const $q = useQuasar();
@ -74,8 +73,11 @@ const fiedType = {
checkbox: 'w-checkbox', checkbox: 'w-checkbox',
cron: 'w-cron', cron: 'w-cron',
'color-input': 'w-color-input', 'color-input': 'w-color-input',
colorInput: 'w-color-input',
'color-input-palette': 'w-color-input-palette', 'color-input-palette': 'w-color-input-palette',
colorInputPalette: 'w-color-input-palette',
'code-mirror': 'w-code-mirror', 'code-mirror': 'w-code-mirror',
codeMirror: 'w-code-mirror',
position: 'w-position', position: 'w-position',
date: 'w-date', date: 'w-date',
number: 'w-number', number: 'w-number',
@ -83,23 +85,25 @@ const fiedType = {
text: 'w-text', text: 'w-text',
textarea: 'w-textarea', textarea: 'w-textarea',
'text-btn': 'w-text-btn', 'text-btn': 'w-text-btn',
textBtn: 'w-text-btn',
password: 'w-password', password: 'w-password',
'option-group': 'w-option-group', 'option-group': 'w-option-group',
optionGroup: 'w-option-group',
}; };
const defaultValueHandler = (field) => { const defaultValueHandler = (field) => {
if (field.hasOwnProperty('defaultValue') && field.defaultValue !== null && field.defaultValue !== undefined) { if (!Tools.isEmpty(field.defaultValue)) {
return field.defaultValue; return field.defaultValue;
} else if (field.type === 'checkbox' || field.type === 'w-checkbox') { } else if (field.type === 'checkbox' || field.type === 'w-checkbox') {
return false; return false;
} else if (field.type === 'option-group' || field.type === 'w-option-group') { } else if (field.type === 'option-group' || field.type === 'w-option-group') {
if (field.optionType === 'radio') { if (field.optionType === 'radio') {
return null; return undefined;
} else { } else {
return []; return [];
} }
} }
return null; return undefined;
}; };
watch( watch(

26
io.sc.platform.core.frontend/src/platform/components/form/elements/WCheckbox.vue

@ -1,16 +1,16 @@
<template> <template>
<div v-show="showIfComputed"> <div v-show="showIfComputed">
<q-checkbox v-bind="attrs" :rules="rulesComputed" :disable="disableIfComputed"></q-checkbox> <q-checkbox v-model="checkboxValue" v-bind="attrs" :rules="rulesComputed" :disable="disableIfComputed" @update:model-value="updateModelValue"></q-checkbox>
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { computed, defineProps, useAttrs } from 'vue'; import { computed, defineProps, useAttrs, ref, watch } from 'vue';
// import { FormValidators } from '@/platform/components';
const attrs = useAttrs(); const attrs = useAttrs();
const inRules = attrs.rules; const rules = attrs.rules;
const props = defineProps({ const props = defineProps({
modelValue: { type: Boolean, default: false },
showIf: { showIf: {
type: Function, type: Function,
default: () => { default: () => {
@ -28,13 +28,21 @@ const props = defineProps({
default: undefined, default: undefined,
}, },
}); });
const emit = defineEmits(['update:modelValue']);
const checkboxValue = ref(props.modelValue);
watch(
() => props.modelValue,
(newVal, oldVal) => {
checkboxValue.value = newVal;
},
);
const rulesComputed = computed(() => { const rulesComputed = computed(() => {
let rules = inRules || <any>[]; let result = rules || <any>[];
if (!showIfComputed.value) { if (!showIfComputed.value) {
rules = []; result = [];
} }
return rules; return result;
}); });
const showIfComputed = computed(() => { const showIfComputed = computed(() => {
@ -43,4 +51,8 @@ const showIfComputed = computed(() => {
const disableIfComputed = computed(() => { const disableIfComputed = computed(() => {
return props.disableIf(props.form); return props.disableIf(props.form);
}); });
const updateModelValue = (value) => {
emit('update:modelValue', value);
};
</script> </script>

136
io.sc.platform.core.frontend/src/platform/components/form/elements/WCodeMirror.vue

@ -1,13 +1,48 @@
<template> <template>
<q-field v-bind="attrs" :stack-label="stackLabelRef" @focus="focus" @blur="blur"> <div v-show="showIfComputed">
<template #control> <q-field
<div ref="codemirrorRef" style="width: 100%"></div> ref="fieldRef"
</template> v-model="codeMirrorValue"
</q-field> :hide-bottom-space="true"
:hide-hint="true"
:outlined="true"
:dense="true"
v-bind="attrs"
:stack-label="stackLabelRef"
:rules="rulesComputed"
:readonly="readonlyIfComputed"
:disable="disableIfComputed"
style="position: relative"
@focus.stop.prevent="focus"
@blur.stop.prevent="blur"
@update:model-value="updateModelValue"
>
<template #label> <span v-if="requiredIfComputed" style="color: red">*</span> {{ attrs.label }}</template>
<template #control>
<div ref="codemirrorRef" style="width: 100%" @focus.stop.prevent="() => {}" @click.stop.prevent="() => {}"></div>
</template>
<template #append>
<q-btn
round
dense
flat
v-bind="attrs.button"
:style="{
content: '',
position: 'absolute',
bottom: '5px',
right: '5px',
}"
@click.stop.prevent="buttonClick(attrs.button)"
/>
</template>
</q-field>
</div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, useAttrs, onMounted, onUnmounted, watch } from 'vue'; import { ref, useAttrs, onMounted, onUnmounted, watch, computed, toRaw } from 'vue';
import { Tools } from '@/platform'; import { Tools } from '@/platform';
import { FormValidators } from '@/platform/components';
import { EditorView } from '@codemirror/view'; import { EditorView } from '@codemirror/view';
import { EditorState, Compartment } from '@codemirror/state'; import { EditorState, Compartment } from '@codemirror/state';
import * as view from '@codemirror/view'; import * as view from '@codemirror/view';
@ -25,7 +60,8 @@ import { sql } from '@codemirror/lang-sql';
import { xml } from '@codemirror/lang-xml'; import { xml } from '@codemirror/lang-xml';
const attrs = useAttrs(); const attrs = useAttrs();
const rules = attrs.rules;
const fieldRef = ref();
const props = defineProps({ const props = defineProps({
modelValue: { type: String, default: '' }, modelValue: { type: String, default: '' },
lang: { type: String, default: 'json' }, lang: { type: String, default: 'json' },
@ -33,9 +69,76 @@ const props = defineProps({
height: { type: [Number, String], default: undefined }, height: { type: [Number, String], default: undefined },
rows: { type: Number, default: 4 }, rows: { type: Number, default: 4 },
tabSize: { type: Number, default: 4 }, tabSize: { type: Number, default: 4 },
showIf: {
type: Function,
default: () => {
return true;
},
},
required: {
type: Boolean,
default: false,
},
requiredIf: {
type: Function,
default: undefined,
},
readonlyIf: {
type: Function,
default: () => {
return false;
},
},
disableIf: {
type: Function,
default: () => {
return false;
},
},
form: {
type: Object,
default: undefined,
},
}); });
const emits = defineEmits(['update:modelValue']); const emits = defineEmits(['update:modelValue']);
const codeMirrorValue = ref(props.modelValue);
watch(
() => props.modelValue,
(newVal, oldVal) => {
codeMirrorValue.value = newVal;
},
);
const rulesComputed = computed(() => {
let result = rules || <any>[];
if (showIfComputed.value && requiredIfComputed.value) {
result.push(FormValidators.required());
} else if (!showIfComputed.value) {
result = [];
}
if (fieldRef?.value) {
fieldRef.value.resetValidation();
}
return result;
});
const showIfComputed = computed(() => {
return props.showIf(props.form);
});
const requiredIfComputed = computed(() => {
if (props.requiredIf) {
return props.requiredIf(props.form) || false;
} else if (props.required) {
return true;
}
return false;
});
const readonlyIfComputed = computed(() => {
return props.readonlyIf(props.form);
});
const disableIfComputed = computed(() => {
return props.disableIf(props.form);
});
const basicSetup = [ const basicSetup = [
EditorState.allowMultipleSelections.of(true), EditorState.allowMultipleSelections.of(true),
@ -96,7 +199,7 @@ const codemirrorRef = ref();
// q-field stack-label field label // q-field stack-label field label
// field , label // field , label
// field , field label , label // field , field label , label
const stackLabelRef = ref(!Tools.isUndefinedOrNull(props.modelValue)); const stackLabelRef = ref(!Tools.isUndefinedOrNull(codeMirrorValue.value));
let editorView; let editorView;
let isFocus = false; let isFocus = false;
@ -123,14 +226,14 @@ onMounted(() => {
}), }),
], ],
parent: codemirrorRef.value, parent: codemirrorRef.value,
doc: props.modelValue, doc: codeMirrorValue.value,
}); });
watch( watch(
() => props.modelValue, () => codeMirrorValue.value,
() => { () => {
// ,, // ,,
if (!isFocus) { if (!isFocus) {
editorView.dispatch({ changes: { from: 0, to: editorView.state.doc.length, insert: props.modelValue } }); editorView.dispatch({ changes: { from: 0, to: editorView.state.doc.length, insert: codeMirrorValue.value } });
} }
}, },
); );
@ -165,6 +268,15 @@ const setValue = (value: string) => {
editorView.dispatch({ changes: { from: 0, to: editorView.state.doc.length, insert: value } }); editorView.dispatch({ changes: { from: 0, to: editorView.state.doc.length, insert: value } });
}; };
const updateModelValue = (value) => {
emits('update:modelValue', value);
};
const buttonClick = (button) => {
if (button.click) {
button.click(toRaw(codeMirrorValue), props.form);
}
};
defineExpose({ defineExpose({
getValue, getValue,
setValue, setValue,

188
io.sc.platform.core.frontend/src/platform/components/form/elements/WColorInput.vue

@ -1,67 +1,159 @@
<template> <template>
<q-input v-model="colorValueRef" @update:model-value="colorChanged"> <div v-show="showIfComputed">
<template #append> <q-input
<!-- 选择颜色按钮 --> ref="colorRef"
<q-btn v-model="colorValueRef"
icon="square" :hide-bottom-space="true"
size="10px" :hide-hint="true"
padding="2px" :outlined="true"
flat :dense="true"
square v-bind="attrs"
unelevated :rules="rulesComputed"
:title="$t('select')" :readonly="readonlyIfComputed"
:style="{ border: '1px solid #e5e7eb', color: computedColorValue, 'background-color': computedStoreBackgroundColorValue }" :disable="disableIfComputed"
> @update:model-value="colorChanged"
<q-popup-proxy v-model:model-value="isShow" anchor="bottom right" self="top right" :offset="[0, 10]"> >
<q-color <template #label> <span v-if="requiredIfComputed" style="color: red">*</span> {{ attrs.label }} </template>
v-model="colorValueRef" <template #append>
default-value="colorValueRef" <!-- 选择颜色按钮 -->
format-model="hex" <q-btn
default-view="palette" icon="square"
style="max-width: 250px" size="10px"
@update:model-value="colorChanged" padding="2px"
/> flat
</q-popup-proxy> square
</q-btn> unelevated
<!-- 恢复默认值按钮 --> :title="$t('select')"
<q-btn :style="{ border: '1px solid #e5e7eb', color: computedColorValue, 'background-color': computedStoreBackgroundColorValue }"
v-if="restore" >
icon="bi-arrow-counterclockwise" <q-popup-proxy v-model:model-value="isShow" anchor="bottom right" self="top right" :offset="[0, 10]">
size="10px" <q-color
padding="2px" v-model="colorValueRef"
flat default-value="colorValueRef"
square format-model="hex"
unelevated default-view="palette"
:title="$t('restore')" style="max-width: 250px"
:style="{ 'margin-left': '5px', border: '1px solid #e5e7eb', color: restoreValue, 'background-color': computedStoreBackgroundColorValue }" @update:model-value="colorChanged"
@click="restoreDefaultValue" />
></q-btn> </q-popup-proxy>
</template> </q-btn>
</q-input> <!-- 恢复默认值按钮 -->
<q-btn
v-if="restore"
icon="bi-arrow-counterclockwise"
size="10px"
padding="2px"
flat
square
unelevated
:title="$t('restore')"
:style="{ 'margin-left': '5px', border: '1px solid #e5e7eb', color: restoreValue, 'background-color': computedStoreBackgroundColorValue }"
@click="restoreDefaultValue"
></q-btn>
</template>
</q-input>
</div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, toRaw, computed } from 'vue'; import { ref, toRaw, computed, useAttrs, watch } from 'vue';
import { Tools } from '@/platform';
import { FormValidators } from '@/platform/components';
const attrs = useAttrs();
const rules = attrs.rules;
const colorRef = ref();
const props = defineProps({ const props = defineProps({
modelValue: { type: String, default: '#000000' }, modelValue: { type: String, default: '' },
restore: { type: Boolean, default: false }, restore: { type: Boolean, default: false },
showIf: {
type: Function,
default: () => {
return true;
},
},
required: {
type: Boolean,
default: false,
},
requiredIf: {
type: Function,
default: undefined,
},
readonlyIf: {
type: Function,
default: () => {
return false;
},
},
disableIf: {
type: Function,
default: () => {
return false;
},
},
form: {
type: Object,
default: undefined,
},
}); });
const emit = defineEmits(['update:modelValue']); const emit = defineEmits(['update:modelValue']);
const isShow = ref(false); const isShow = ref(false);
const colorValueRef = ref(props.modelValue || '#000000'); const defaultValue = '#000000';
const restoreValue = toRaw(props.modelValue || '#000000'); const colorValueRef = ref(props.modelValue || defaultValue);
if (Tools.isEmpty(props.modelValue)) {
emit('update:modelValue', colorValueRef.value);
}
const restoreValue = toRaw(props.modelValue || defaultValue);
watch(
() => props.modelValue,
(newVal, oldVal) => {
colorValueRef.value = newVal;
},
);
const computedColorValue = computed(() => { const computedColorValue = computed(() => {
return colorValueRef.value; return colorValueRef.value;
}); });
const computedBackgroundColorValue = computed(() => { // const computedBackgroundColorValue = computed(() => {
const color: string = toRaw(colorValueRef.value); // const color: string = toRaw(colorValueRef.value);
if (color.toLowerCase() === 'white' || color.toLowerCase() === '#ffffff' || color.toLowerCase() === '#fff') { // if (color.toLowerCase() === 'white' || color.toLowerCase() === '#ffffff' || color.toLowerCase() === '#fff') {
return '#eee'; // return '#eee';
// }
// return undefined;
// });
const rulesComputed = computed(() => {
let result = rules || <any>[];
if (showIfComputed.value && requiredIfComputed.value) {
result.push(FormValidators.required());
} else if (!showIfComputed.value) {
result = [];
} }
return undefined; if (colorRef?.value) {
colorRef.value.resetValidation();
}
return result;
});
const showIfComputed = computed(() => {
return props.showIf(props.form);
});
const requiredIfComputed = computed(() => {
if (props.requiredIf) {
return props.requiredIf(props.form) || false;
} else if (props.required) {
return true;
}
return false;
});
const readonlyIfComputed = computed(() => {
return props.readonlyIf(props.form);
});
const disableIfComputed = computed(() => {
return props.disableIf(props.form);
}); });
const computedStoreBackgroundColorValue = computed(() => { const computedStoreBackgroundColorValue = computed(() => {

188
io.sc.platform.core.frontend/src/platform/components/form/elements/WColorInputPalette.vue

@ -1,60 +1,108 @@
<template> <template>
<q-input v-model="colorValueRef" @update:model-value="colorSelected"> <div v-show="showIfComputed">
<template #append> <q-input
<!-- 选择颜色按钮 --> ref="colorRef"
<q-btn v-model="colorValueRef"
icon="bi-palette" :hide-bottom-space="true"
size="10px" :hide-hint="true"
padding="2px" :outlined="true"
flat :dense="true"
square v-bind="attrs"
unelevated :rules="rulesComputed"
:title="$t('select')" :readonly="readonlyIfComputed"
:class="`text-${computedColorValue}`" :disable="disableIfComputed"
:style="{ border: '1px solid #e5e7eb', 'background-color': computedBackgroundColorValue }" @update:model-value="colorSelected"
> >
<q-popup-proxy v-model:model-value="isShow" anchor="bottom right" self="top right" :offset="[0, 10]"> <template #label> <span v-if="requiredIfComputed" style="color: red">*</span> {{ attrs.label }} </template>
<div v-for="(colors, index) in quasarColors" :key="index" class="row"> <template #append>
<div <!-- 选择颜色按钮 -->
v-for="color in colors" <q-btn
:key="`${color}`" icon="bi-palette"
:class="`bg-${color}`" size="10px"
style="min-width: 20px; max-width: 20px; min-height: 20px; max-height: 20px" padding="2px"
@click="colorSelected(`${color}`)" flat
> square
<q-tooltip> {{ color }}</q-tooltip> unelevated
:title="$t('select')"
:class="`text-${computedColorValue}`"
:style="{ border: '1px solid #e5e7eb', 'background-color': computedBackgroundColorValue }"
>
<q-popup-proxy v-model:model-value="isShow" anchor="bottom right" self="top right" :offset="[0, 10]">
<div v-for="(colors, index) in quasarColors" :key="index" class="row">
<div
v-for="color in colors"
:key="`${color}`"
:class="`bg-${color}`"
style="min-width: 20px; max-width: 20px; min-height: 20px; max-height: 20px"
@click="colorSelected(`${color}`)"
>
<q-tooltip> {{ color }}</q-tooltip>
</div>
</div> </div>
</div> </q-popup-proxy>
</q-popup-proxy> </q-btn>
</q-btn> <!-- 恢复默认值按钮 -->
<!-- 恢复默认值按钮 --> <q-btn
<q-btn v-if="restore"
v-if="restore" icon="bi-arrow-counterclockwise"
icon="bi-arrow-counterclockwise" size="10px"
size="10px" padding="2px"
padding="2px" flat
flat square
square unelevated
unelevated :title="$t('restore')"
:title="$t('restore')" :class="`text-${restoreValue}`"
:class="`text-${restoreValue}`" :style="{ 'margin-left': '5px', border: '1px solid #e5e7eb', 'background-color': computedStoreBackgroundColorValue }"
:style="{ 'margin-left': '5px', border: '1px solid #e5e7eb', 'background-color': computedStoreBackgroundColorValue }" @click="restoreDefaultValue"
@click="restoreDefaultValue" ></q-btn>
></q-btn> </template>
</template> </q-input>
</q-input> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { mdiConsoleLine } from '@quasar/extras/mdi-v4'; import { ref, toRaw, computed, useAttrs, watch } from 'vue';
import { ref, toRaw, computed } from 'vue'; import { Tools } from '@/platform';
import { FormValidators } from '@/platform/components';
const attrs = useAttrs();
const rules = attrs.rules;
const colorRef = ref();
const props = defineProps({ const props = defineProps({
modelValue: { type: String, default: '#000000' }, modelValue: { type: String, default: '' },
restore: { type: Boolean, default: false }, restore: { type: Boolean, default: false },
showIf: {
type: Function,
default: () => {
return true;
},
},
required: {
type: Boolean,
default: false,
},
requiredIf: {
type: Function,
default: undefined,
},
readonlyIf: {
type: Function,
default: () => {
return false;
},
},
disableIf: {
type: Function,
default: () => {
return false;
},
},
form: {
type: Object,
default: undefined,
},
}); });
const emit = defineEmits(['update:modelValue']); const emit = defineEmits(['update:modelValue']);
const htmlColors = ['white', 'black'];
const quasarColors = [ const quasarColors = [
['red', 'red-1', 'red-2', 'red-3', 'red-4', 'red-5', 'red-6', 'red-7', 'red-8', 'red-9', 'red-10', 'red-11', 'red-12', 'red-13', 'red-14'], ['red', 'red-1', 'red-2', 'red-3', 'red-4', 'red-5', 'red-6', 'red-7', 'red-8', 'red-9', 'red-10', 'red-11', 'red-12', 'red-13', 'red-14'],
['pink', 'pink-1', 'pink-2', 'pink-3', 'pink-4', 'pink-5', 'pink-6', 'pink-7', 'pink-8', 'pink-9', 'pink-10', 'pink-11', 'pink-12', 'pink-13', 'pink-14'], ['pink', 'pink-1', 'pink-2', 'pink-3', 'pink-4', 'pink-5', 'pink-6', 'pink-7', 'pink-8', 'pink-9', 'pink-10', 'pink-11', 'pink-12', 'pink-13', 'pink-14'],
@ -271,8 +319,19 @@ const quasarColors = [
]; ];
const isShow = ref(false); const isShow = ref(false);
const colorValueRef = ref(props.modelValue || 'black'); const defaultValue = 'black';
const restoreValue = toRaw(props.modelValue || 'black'); const colorValueRef = ref(props.modelValue || defaultValue);
if (Tools.isEmpty(props.modelValue)) {
emit('update:modelValue', colorValueRef.value);
}
const restoreValue = toRaw(props.modelValue || defaultValue);
watch(
() => props.modelValue,
(newVal, oldVal) => {
colorValueRef.value = newVal;
},
);
const computedColorValue = computed(() => { const computedColorValue = computed(() => {
return colorValueRef.value; return colorValueRef.value;
@ -294,6 +353,37 @@ const computedStoreBackgroundColorValue = computed(() => {
return undefined; return undefined;
}); });
const rulesComputed = computed(() => {
let result = rules || <any>[];
if (showIfComputed.value && requiredIfComputed.value) {
result.push(FormValidators.required());
} else if (!showIfComputed.value) {
result = [];
}
if (colorRef?.value) {
colorRef.value.resetValidation();
}
return result;
});
const showIfComputed = computed(() => {
return props.showIf(props.form);
});
const requiredIfComputed = computed(() => {
if (props.requiredIf) {
return props.requiredIf(props.form) || false;
} else if (props.required) {
return true;
}
return false;
});
const readonlyIfComputed = computed(() => {
return props.readonlyIf(props.form);
});
const disableIfComputed = computed(() => {
return props.disableIf(props.form);
});
const colorSelected = (value) => { const colorSelected = (value) => {
colorValueRef.value = value; colorValueRef.value = value;
emit('update:modelValue', value); emit('update:modelValue', value);

171
io.sc.platform.core.frontend/src/platform/components/form/elements/WCron.vue

@ -1,50 +1,66 @@
<template> <template>
<q-input v-model="valueRef" :v-bind="attrs"> <div v-show="showIfComputed">
<template #append> <q-input
<!-- 选择颜色按钮 --> ref="cronRef"
<q-btn icon="bi-pencil-square" padding="2px" flat square unelevated :title="$t('select')"> v-model="valueRef"
<q-popup-proxy v-model:model-value="isShow" anchor="bottom right" self="top right" :offset="[0, 10]" style="width: 800px"> :hide-bottom-space="true"
<q-tabs v-model="selectedTab" no-caps> :hide-hint="true"
<q-tab name="second" :label="$t('second')" /> :outlined="true"
<q-tab name="minute" :label="$t('minute')" /> :dense="true"
<q-tab name="hour" :label="$t('hour')" /> v-bind="attrs"
<q-tab name="day" :label="$t('day')" /> :rules="rulesComputed"
<q-tab name="month" :label="$t('month')" /> :readonly="readonlyIfComputed"
<q-tab name="week" :label="$t('week')" /> :disable="disableIfComputed"
<q-tab name="year" :label="$t('year')" /> :v-bind="attrs"
</q-tabs> >
<template #label> <span v-if="requiredIfComputed" style="color: red">*</span> {{ attrs.label }} </template>
<template #append>
<!-- 选择颜色按钮 -->
<q-btn icon="bi-pencil-square" padding="2px" flat square unelevated :title="$t('select')">
<q-popup-proxy v-model:model-value="isShow" anchor="bottom right" self="top right" :offset="[0, 10]" style="width: 800px">
<q-tabs v-model="selectedTab" no-caps>
<q-tab name="second" :label="$t('second')" />
<q-tab name="minute" :label="$t('minute')" />
<q-tab name="hour" :label="$t('hour')" />
<q-tab name="day" :label="$t('day')" />
<q-tab name="month" :label="$t('month')" />
<q-tab name="week" :label="$t('week')" />
<q-tab name="year" :label="$t('year')" />
</q-tabs>
<q-tab-panels v-model="selectedTab" animated swipeable vertical transition-prev="jump-up" transition-next="jump-up" :keep-alive="true"> <q-tab-panels v-model="selectedTab" animated swipeable vertical transition-prev="jump-up" transition-next="jump-up" :keep-alive="true">
<q-tab-panel name="second"> <q-tab-panel name="second">
<SecondSegment v-model="secondValueRef" @update:model-value="valueChanged"></SecondSegment> <SecondSegment v-model="secondValueRef" @update:model-value="valueChanged"></SecondSegment>
</q-tab-panel> </q-tab-panel>
<q-tab-panel name="minute"> <q-tab-panel name="minute">
<MinuteSegment v-model="minuteValueRef" @update:model-value="valueChanged"></MinuteSegment> <MinuteSegment v-model="minuteValueRef" @update:model-value="valueChanged"></MinuteSegment>
</q-tab-panel> </q-tab-panel>
<q-tab-panel name="hour"> <q-tab-panel name="hour">
<HourSegment v-model="hourValueRef" @update:model-value="valueChanged"></HourSegment> <HourSegment v-model="hourValueRef" @update:model-value="valueChanged"></HourSegment>
</q-tab-panel> </q-tab-panel>
<q-tab-panel name="day"> <q-tab-panel name="day">
<DaySegment v-model="dayValueRef" @update:model-value="valueChanged"></DaySegment> <DaySegment v-model="dayValueRef" @update:model-value="valueChanged"></DaySegment>
</q-tab-panel> </q-tab-panel>
<q-tab-panel name="month"> <q-tab-panel name="month">
<MonthSegment v-model="monthValueRef" @update:model-value="valueChanged"></MonthSegment> <MonthSegment v-model="monthValueRef" @update:model-value="valueChanged"></MonthSegment>
</q-tab-panel> </q-tab-panel>
<q-tab-panel name="week"> <q-tab-panel name="week">
<WeekSegment v-model="weekValueRef" @update:model-value="valueChanged"></WeekSegment> <WeekSegment v-model="weekValueRef" @update:model-value="valueChanged"></WeekSegment>
</q-tab-panel> </q-tab-panel>
<q-tab-panel name="year"> <q-tab-panel name="year">
<YearSegment v-model="yearValueRef" @update:model-value="valueChanged"></YearSegment> <YearSegment v-model="yearValueRef" @update:model-value="valueChanged"></YearSegment>
</q-tab-panel> </q-tab-panel>
</q-tab-panels> </q-tab-panels>
</q-popup-proxy> </q-popup-proxy>
</q-btn> </q-btn>
</template> </template>
</q-input> </q-input>
</div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, useAttrs } from 'vue'; import { ref, useAttrs, watch, computed } from 'vue';
import { Tools } from '@/platform'; import { Tools } from '@/platform';
import { FormValidators } from '@/platform/components';
import SecondSegment from './w-cron-segment/SecondSegment.vue'; import SecondSegment from './w-cron-segment/SecondSegment.vue';
import MinuteSegment from './w-cron-segment/MinuteSegment.vue'; import MinuteSegment from './w-cron-segment/MinuteSegment.vue';
import HourSegment from './w-cron-segment/HourSegment.vue'; import HourSegment from './w-cron-segment/HourSegment.vue';
@ -54,9 +70,40 @@ import WeekSegment from './w-cron-segment/WeekSegment.vue';
import YearSegment from './w-cron-segment/YearSegment.vue'; import YearSegment from './w-cron-segment/YearSegment.vue';
const attrs = useAttrs(); const attrs = useAttrs();
const rules = attrs.rules;
const cronRef = ref();
const props = defineProps({ const props = defineProps({
modelValue: { type: String, default: '' }, modelValue: { type: String, default: '' },
showIf: {
type: Function,
default: () => {
return true;
},
},
required: {
type: Boolean,
default: false,
},
requiredIf: {
type: Function,
default: undefined,
},
readonlyIf: {
type: Function,
default: () => {
return false;
},
},
disableIf: {
type: Function,
default: () => {
return false;
},
},
form: {
type: Object,
default: undefined,
},
}); });
const emit = defineEmits(['update:modelValue']); const emit = defineEmits(['update:modelValue']);
@ -73,6 +120,44 @@ const monthValueRef = ref(splits[4]);
const weekValueRef = ref(splits[5]); const weekValueRef = ref(splits[5]);
const yearValueRef = ref(splits[6]); const yearValueRef = ref(splits[6]);
watch(
() => props.modelValue,
(newVal, oldVal) => {
valueRef.value = newVal;
},
);
const rulesComputed = computed(() => {
let result = rules || <any>[];
if (showIfComputed.value && requiredIfComputed.value) {
result.push(FormValidators.required());
} else if (!showIfComputed.value) {
result = [];
}
if (cronRef?.value) {
cronRef.value.resetValidation();
}
return result;
});
const showIfComputed = computed(() => {
return props.showIf(props.form);
});
const requiredIfComputed = computed(() => {
if (props.requiredIf) {
return props.requiredIf(props.form) || false;
} else if (props.required) {
return true;
}
return false;
});
const readonlyIfComputed = computed(() => {
return props.readonlyIf(props.form);
});
const disableIfComputed = computed(() => {
return props.disableIf(props.form);
});
const valueChanged = () => { const valueChanged = () => {
const values = []; const values = [];
values.push(secondValueRef.value ? secondValueRef.value : '*'); values.push(secondValueRef.value ? secondValueRef.value : '*');

31
io.sc.platform.core.frontend/src/platform/components/form/elements/WDate.vue

@ -2,6 +2,7 @@
<div v-show="showIfComputed"> <div v-show="showIfComputed">
<q-input <q-input
ref="dateRef" ref="dateRef"
v-model="dateValue"
:hide-bottom-space="true" :hide-bottom-space="true"
:hide-hint="true" :hide-hint="true"
:outlined="true" :outlined="true"
@ -10,12 +11,13 @@
:rules="rulesComputed" :rules="rulesComputed"
:readonly="readonlyIfComputed" :readonly="readonlyIfComputed"
:disable="disableIfComputed" :disable="disableIfComputed"
@update:model-value="updateModelValue"
> >
<template #label> <span v-if="requiredIfComputed" style="color: red">*</span> {{ attrs.label }}</template> <template #label> <span v-if="requiredIfComputed" style="color: red">*</span> {{ attrs.label }}</template>
<template #append> <template #append>
<q-icon :name="IconEnum.日期" class="cursor-pointer"> <q-icon :name="IconEnum.日期" class="cursor-pointer">
<q-popup-proxy cover transition-show="scale" transition-hide="scale"> <q-popup-proxy cover transition-show="scale" transition-hide="scale">
<q-date v-model="date" today-btn mask="YYYY-MM-DD"> <q-date v-model="dateValue" today-btn mask="YYYY-MM-DD" @update:model-value="updateModelValue">
<div class="row items-center justify-end"> <div class="row items-center justify-end">
<q-btn v-close-popup label="关闭" color="primary" flat /> <q-btn v-close-popup label="关闭" color="primary" flat />
</div> </div>
@ -33,10 +35,14 @@ import { FormValidators } from '@/platform/components';
import { IconEnum } from '@/platform/enums'; import { IconEnum } from '@/platform/enums';
const dateRef = ref(); const dateRef = ref();
const date = ref(null);
const attrs = useAttrs(); const attrs = useAttrs();
const inRules = attrs.rules; const rules = attrs.rules;
const props = defineProps({ const props = defineProps({
type: {
type: String,
default: 'w-date',
},
modelValue: { type: String, default: '' },
showIf: { showIf: {
type: Function, type: Function,
default: () => { default: () => {
@ -68,25 +74,26 @@ const props = defineProps({
default: undefined, default: undefined,
}, },
}); });
const emit = defineEmits(['update:modelValue']);
const dateValue = ref(props.modelValue);
watch( watch(
() => date.value, () => props.modelValue,
(newVal, oldVal) => { (newVal, oldVal) => {
attrs['form-data'][attrs.name] = newVal; dateValue.value = newVal;
}, },
); );
const rulesComputed = computed(() => { const rulesComputed = computed(() => {
let rules = inRules || <any>[]; let result = rules || <any>[];
if (showIfComputed.value && requiredIfComputed.value) { if (showIfComputed.value && requiredIfComputed.value) {
rules.push(FormValidators.required()); result.push(FormValidators.required());
} else if (!showIfComputed.value) { } else if (!showIfComputed.value) {
rules = []; result = [];
} }
if (dateRef?.value) { if (dateRef?.value) {
dateRef.value.resetValidation(); dateRef.value.resetValidation();
} }
return rules; return result;
}); });
const showIfComputed = computed(() => { const showIfComputed = computed(() => {
@ -106,4 +113,8 @@ const readonlyIfComputed = computed(() => {
const disableIfComputed = computed(() => { const disableIfComputed = computed(() => {
return props.disableIf(props.form); return props.disableIf(props.form);
}); });
const updateModelValue = (value) => {
emit('update:modelValue', value);
};
</script> </script>

29
io.sc.platform.core.frontend/src/platform/components/form/elements/WNumber.vue

@ -2,6 +2,7 @@
<div v-show="showIfComputed"> <div v-show="showIfComputed">
<q-input <q-input
ref="numberRef" ref="numberRef"
v-model="numberValue"
:hide-bottom-space="true" :hide-bottom-space="true"
:hide-hint="true" :hide-hint="true"
:outlined="true" :outlined="true"
@ -12,6 +13,7 @@
:rules="rulesComputed" :rules="rulesComputed"
:readonly="readonlyIfComputed" :readonly="readonlyIfComputed"
:disable="disableIfComputed" :disable="disableIfComputed"
@update:model-value="updateModelValue"
> >
<template #label> <span v-if="requiredIfComputed" style="color: red">*</span> {{ attrs.label }}</template> <template #label> <span v-if="requiredIfComputed" style="color: red">*</span> {{ attrs.label }}</template>
</q-input> </q-input>
@ -19,13 +21,14 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, computed, defineProps, useAttrs } from 'vue'; import { ref, computed, defineProps, useAttrs, watch } from 'vue';
import { FormValidators } from '@/platform/components'; import { FormValidators } from '@/platform/components';
const numberRef = ref(); const numberRef = ref();
const attrs = useAttrs(); const attrs = useAttrs();
const inRules = attrs.rules; const rules = attrs.rules;
const props = defineProps({ const props = defineProps({
modelValue: { type: Number, default: undefined },
precision: { type: Number, default: 0 }, precision: { type: Number, default: 0 },
showIf: { showIf: {
type: Function, type: Function,
@ -58,19 +61,27 @@ const props = defineProps({
default: undefined, default: undefined,
}, },
}); });
const emit = defineEmits(['update:modelValue']);
const numberValue = ref(props.modelValue);
watch(
() => props.modelValue,
(newVal, oldVal) => {
numberValue.value = newVal;
},
);
const rulesComputed = computed(() => { const rulesComputed = computed(() => {
let rules = inRules || <any>[]; let result = rules || <any>[];
rules.push(FormValidators.maxPrecision(props.precision)); result.push(FormValidators.maxPrecision(props.precision));
if (showIfComputed.value && requiredIfComputed.value) { if (showIfComputed.value && requiredIfComputed.value) {
rules.push(FormValidators.required()); result.push(FormValidators.required());
} else if (!showIfComputed.value) { } else if (!showIfComputed.value) {
rules = []; result = [];
} }
if (numberRef?.value) { if (numberRef?.value) {
numberRef.value.resetValidation(); numberRef.value.resetValidation();
} }
return rules; return result;
}); });
const showIfComputed = computed(() => { const showIfComputed = computed(() => {
@ -90,4 +101,8 @@ const readonlyIfComputed = computed(() => {
const disableIfComputed = computed(() => { const disableIfComputed = computed(() => {
return props.disableIf(props.form); return props.disableIf(props.form);
}); });
const updateModelValue = (value) => {
emit('update:modelValue', Number(value));
};
</script> </script>

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

@ -4,15 +4,16 @@
{{ label }} {{ label }}
</div> </div>
<q-separator /> <q-separator />
<q-option-group v-bind="attrs" :type="optionType" :disable="disableIfComputed" /> <q-option-group v-model="optionGroupValue" v-bind="attrs" :type="optionType" :disable="disableIfComputed" @update:model-value="updateModelValue" />
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { computed, defineProps, useAttrs } from 'vue'; import { computed, defineProps, useAttrs, ref, watch } from 'vue';
const attrs = useAttrs(); const attrs = useAttrs();
const props = defineProps({ const props = defineProps({
modelValue: { type: [Number, Boolean, String, Array], default: undefined },
type: { type: {
type: String, type: String,
default: '', default: '',
@ -42,6 +43,14 @@ const props = defineProps({
default: undefined, default: undefined,
}, },
}); });
const emit = defineEmits(['update:modelValue']);
const optionGroupValue = ref(props.modelValue);
watch(
() => props.modelValue,
(newVal, oldVal) => {
optionGroupValue.value = newVal;
},
);
const showIfComputed = computed(() => { const showIfComputed = computed(() => {
return props.showIf(props.form); return props.showIf(props.form);
@ -49,4 +58,8 @@ const showIfComputed = computed(() => {
const disableIfComputed = computed(() => { const disableIfComputed = computed(() => {
return props.disableIf(props.form); return props.disableIf(props.form);
}); });
const updateModelValue = (value) => {
emit('update:modelValue', value);
};
</script> </script>

27
io.sc.platform.core.frontend/src/platform/components/form/elements/WPassword.vue

@ -2,6 +2,7 @@
<div v-show="showIfComputed"> <div v-show="showIfComputed">
<q-input <q-input
ref="pwdRef" ref="pwdRef"
v-model="passwordValue"
:hide-bottom-space="true" :hide-bottom-space="true"
:hide-hint="true" :hide-hint="true"
:outlined="true" :outlined="true"
@ -12,6 +13,7 @@
:rules="rulesComputed" :rules="rulesComputed"
:readonly="readonlyIfComputed" :readonly="readonlyIfComputed"
:disable="disableIfComputed" :disable="disableIfComputed"
@update:model-value="updateModelValue"
> >
<template #label> <span v-if="requiredIfComputed" style="color: red">*</span> {{ attrs.label }}</template> <template #label> <span v-if="requiredIfComputed" style="color: red">*</span> {{ attrs.label }}</template>
</q-input> </q-input>
@ -19,13 +21,14 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, computed, defineProps, useAttrs } from 'vue'; import { ref, computed, defineProps, useAttrs, watch } from 'vue';
import { FormValidators } from '@/platform/components'; import { FormValidators } from '@/platform/components';
const pwdRef = ref(); const pwdRef = ref();
const attrs = useAttrs(); const attrs = useAttrs();
const inRules = attrs.rules; const rules = attrs.rules;
const props = defineProps({ const props = defineProps({
modelValue: { type: String, default: '' },
showIf: { showIf: {
type: Function, type: Function,
default: () => { default: () => {
@ -57,18 +60,26 @@ const props = defineProps({
default: undefined, default: undefined,
}, },
}); });
const emit = defineEmits(['update:modelValue']);
const passwordValue = ref(props.modelValue);
watch(
() => props.modelValue,
(newVal, oldVal) => {
passwordValue.value = newVal;
},
);
const rulesComputed = computed(() => { const rulesComputed = computed(() => {
let rules = inRules || <any>[]; let result = rules || <any>[];
if (showIfComputed.value && requiredIfComputed.value) { if (showIfComputed.value && requiredIfComputed.value) {
rules.push(FormValidators.required()); result.push(FormValidators.required());
} else if (!showIfComputed.value) { } else if (!showIfComputed.value) {
rules = []; result = [];
} }
if (pwdRef?.value) { if (pwdRef?.value) {
pwdRef.value.resetValidation(); pwdRef.value.resetValidation();
} }
return rules; return result;
}); });
const showIfComputed = computed(() => { const showIfComputed = computed(() => {
@ -88,4 +99,8 @@ const readonlyIfComputed = computed(() => {
const disableIfComputed = computed(() => { const disableIfComputed = computed(() => {
return props.disableIf(props.form); return props.disableIf(props.form);
}); });
const updateModelValue = (value) => {
emit('update:modelValue', value);
};
</script> </script>

178
io.sc.platform.core.frontend/src/platform/components/form/elements/WPosition.vue

@ -1,56 +1,106 @@
<template> <template>
<q-input v-model="positionValueRef" readonly @update:model-value="positionChanged"> <div v-show="showIfComputed">
<template #append> <q-input
<!-- 选择位置按钮 --> ref="positionRef"
<q-btn v-model="positionValueRef"
icon="bi-pin-angle" :hide-bottom-space="true"
size="10px" :hide-hint="true"
padding="2px" :outlined="true"
flat :dense="true"
square v-bind="attrs"
unelevated :rules="rulesComputed"
:title="$t('select')" :readonly="readonlyIfComputed"
:style="{ border: '1px solid #e5e7eb', 'background-color': computedStoreBackgroundColorValue }" :disable="disableIfComputed"
> @update:model-value="positionChanged"
<q-popup-proxy v-model:model-value="isShow" anchor="bottom right" self="top right" :offset="[0, 10]"> >
<div class="row q-col-gutter-sm q-pa-sm" style="width: 150px"> <template #label> <span v-if="requiredIfComputed" style="color: red">*</span> {{ attrs.label }} </template>
<div v-for="position in positionList" :key="position" class="col-4"> <template #append>
<q-btn <!-- 选择位置按钮 -->
unelevated <q-btn
:title="$t(position)" icon="bi-pin-angle"
:color="positionValueRef == position ? 'primary' : ''" size="10px"
:style="{ padding="2px"
width: '100%', flat
border: positionValueRef == position ? '' : '1px solid #dddddd', square
}" unelevated
@click="positionChanged(position)" :title="$t('select')"
></q-btn> :style="{ border: '1px solid #e5e7eb', 'background-color': computedStoreBackgroundColorValue }"
>
<q-popup-proxy v-model:model-value="isShow" anchor="bottom right" self="top right" :offset="[0, 10]">
<div class="row q-col-gutter-sm q-pa-sm" style="width: 150px">
<div v-for="position in positionList" :key="position" class="col-4">
<q-btn
unelevated
:title="$t(position)"
:color="positionValueRef == position ? 'primary' : ''"
:style="{
width: '100%',
border: positionValueRef == position ? '' : '1px solid #dddddd',
}"
@click="positionChanged(position)"
></q-btn>
</div>
</div> </div>
</div> </q-popup-proxy>
</q-popup-proxy> </q-btn>
</q-btn> <!-- 恢复默认值按钮 -->
<!-- 恢复默认值按钮 --> <q-btn
<q-btn v-if="restore"
v-if="restore" icon="bi-arrow-counterclockwise"
icon="bi-arrow-counterclockwise" size="10px"
size="10px" padding="2px"
padding="2px" flat
flat square
square unelevated
unelevated :title="$t('restore')"
:title="$t('restore')" :style="{ 'margin-left': '5px', border: '1px solid #e5e7eb', color: restoreValue, 'background-color': computedStoreBackgroundColorValue }"
:style="{ 'margin-left': '5px', border: '1px solid #e5e7eb', color: restoreValue, 'background-color': computedStoreBackgroundColorValue }" @click="restoreDefaultValue"
@click="restoreDefaultValue" ></q-btn>
></q-btn> </template>
</template> </q-input>
</q-input> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, toRaw, computed } from 'vue'; import { ref, toRaw, computed, useAttrs, watch } from 'vue';
import { Tools } from '@/platform';
import { FormValidators } from '@/platform/components';
const attrs = useAttrs();
const rules = attrs.rules;
const positionRef = ref();
const props = defineProps({ const props = defineProps({
modelValue: { type: String, default: '' }, modelValue: { type: String, default: '' },
restore: { type: Boolean, default: false }, restore: { type: Boolean, default: false },
showIf: {
type: Function,
default: () => {
return true;
},
},
required: {
type: Boolean,
default: false,
},
requiredIf: {
type: Function,
default: undefined,
},
readonlyIf: {
type: Function,
default: () => {
return true;
},
},
disableIf: {
type: Function,
default: () => {
return false;
},
},
form: {
type: Object,
default: undefined,
},
}); });
const emit = defineEmits(['update:modelValue']); const emit = defineEmits(['update:modelValue']);
@ -60,6 +110,13 @@ const isShow = ref(false);
const positionValueRef = ref(props.modelValue || ''); const positionValueRef = ref(props.modelValue || '');
const restoreValue = toRaw(props.modelValue || ''); const restoreValue = toRaw(props.modelValue || '');
watch(
() => props.modelValue,
(newVal, oldVal) => {
positionValueRef.value = newVal;
},
);
const computedStoreBackgroundColorValue = computed(() => { const computedStoreBackgroundColorValue = computed(() => {
const color: string = restoreValue; const color: string = restoreValue;
if (color.toLowerCase() === 'white' || color.toLowerCase() === '#ffffff' || color.toLowerCase() === '#fff') { if (color.toLowerCase() === 'white' || color.toLowerCase() === '#ffffff' || color.toLowerCase() === '#fff') {
@ -68,6 +125,37 @@ const computedStoreBackgroundColorValue = computed(() => {
return undefined; return undefined;
}); });
const rulesComputed = computed(() => {
let result = rules || <any>[];
if (showIfComputed.value && requiredIfComputed.value) {
result.push(FormValidators.required());
} else if (!showIfComputed.value) {
result = [];
}
if (positionRef?.value) {
positionRef.value.resetValidation();
}
return result;
});
const showIfComputed = computed(() => {
return props.showIf(props.form);
});
const requiredIfComputed = computed(() => {
if (props.requiredIf) {
return props.requiredIf(props.form) || false;
} else if (props.required) {
return true;
}
return false;
});
const readonlyIfComputed = computed(() => {
return props.readonlyIf(props.form);
});
const disableIfComputed = computed(() => {
return props.disableIf(props.form);
});
const positionChanged = (value) => { const positionChanged = (value) => {
positionValueRef.value = value; positionValueRef.value = value;
emit('update:modelValue', value); emit('update:modelValue', value);

27
io.sc.platform.core.frontend/src/platform/components/form/elements/WSelect.vue

@ -2,6 +2,7 @@
<div v-show="showIfComputed"> <div v-show="showIfComputed">
<q-select <q-select
ref="selectRef" ref="selectRef"
v-model="selectValue"
emit-value emit-value
map-options map-options
:hide-bottom-space="true" :hide-bottom-space="true"
@ -12,6 +13,7 @@
:rules="rulesComputed" :rules="rulesComputed"
:readonly="readonlyIfComputed" :readonly="readonlyIfComputed"
:disable="disableIfComputed" :disable="disableIfComputed"
@update:model-value="updateModelValue"
> >
<template #label> <span v-if="requiredIfComputed" style="color: red">*</span> {{ attrs.label }}</template> <template #label> <span v-if="requiredIfComputed" style="color: red">*</span> {{ attrs.label }}</template>
</q-select> </q-select>
@ -19,13 +21,14 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, computed, defineProps, useAttrs } from 'vue'; import { ref, computed, defineProps, useAttrs, watch } from 'vue';
import { FormValidators } from '@/platform/components'; import { FormValidators } from '@/platform/components';
const selectRef = ref(); const selectRef = ref();
const attrs = useAttrs(); const attrs = useAttrs();
const inRules = attrs.rules; const rules = attrs.rules;
const props = defineProps({ const props = defineProps({
modelValue: { type: [String, Number, Boolean, Array], default: '' },
showIf: { showIf: {
type: Function, type: Function,
default: () => { default: () => {
@ -57,18 +60,26 @@ const props = defineProps({
default: undefined, default: undefined,
}, },
}); });
const emit = defineEmits(['update:modelValue']);
const selectValue = ref(props.modelValue);
watch(
() => props.modelValue,
(newVal, oldVal) => {
selectValue.value = newVal;
},
);
const rulesComputed = computed(() => { const rulesComputed = computed(() => {
let rules = inRules || <any>[]; let result = rules || <any>[];
if (showIfComputed.value && requiredIfComputed.value) { if (showIfComputed.value && requiredIfComputed.value) {
rules.push(FormValidators.required()); result.push(FormValidators.required());
} else if (!showIfComputed.value) { } else if (!showIfComputed.value) {
rules = []; result = [];
} }
if (selectRef?.value) { if (selectRef?.value) {
selectRef.value.resetValidation(); selectRef.value.resetValidation();
} }
return rules; return result;
}); });
const showIfComputed = computed(() => { const showIfComputed = computed(() => {
@ -88,4 +99,8 @@ const readonlyIfComputed = computed(() => {
const disableIfComputed = computed(() => { const disableIfComputed = computed(() => {
return props.disableIf(props.form); return props.disableIf(props.form);
}); });
const updateModelValue = (value) => {
emit('update:modelValue', value);
};
</script> </script>

1
io.sc.platform.core.frontend/src/platform/components/form/elements/WSelectUserText.vue

@ -14,7 +14,6 @@
:disable="disableIfComputed" :disable="disableIfComputed"
> >
<template #label> <span v-if="requiredIfComputed" style="color: red">*</span> {{ attrs.label }}</template> <template #label> <span v-if="requiredIfComputed" style="color: red">*</span> {{ attrs.label }}</template>
</template>
</q-input> </q-input>
</div> </div>
</template> </template>

27
io.sc.platform.core.frontend/src/platform/components/form/elements/WText.vue

@ -2,6 +2,7 @@
<div v-show="showIfComputed"> <div v-show="showIfComputed">
<q-input <q-input
ref="textRef" ref="textRef"
v-model="textValue"
:hide-bottom-space="true" :hide-bottom-space="true"
:hide-hint="true" :hide-hint="true"
:outlined="true" :outlined="true"
@ -11,6 +12,7 @@
:rules="rulesComputed" :rules="rulesComputed"
:readonly="readonlyIfComputed" :readonly="readonlyIfComputed"
:disable="disableIfComputed" :disable="disableIfComputed"
@update:model-value="updateModelValue"
> >
<template #label> <span v-if="requiredIfComputed" style="color: red">*</span> {{ attrs.label }}</template> <template #label> <span v-if="requiredIfComputed" style="color: red">*</span> {{ attrs.label }}</template>
</q-input> </q-input>
@ -18,13 +20,14 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, computed, defineProps, useAttrs } from 'vue'; import { ref, computed, defineProps, useAttrs, watch } from 'vue';
import { FormValidators } from '@/platform/components'; import { FormValidators } from '@/platform/components';
const textRef = ref(); const textRef = ref();
const attrs = useAttrs(); const attrs = useAttrs();
const inRules = attrs.rules; const rules = attrs.rules;
const props = defineProps({ const props = defineProps({
modelValue: { type: String, default: '' },
showIf: { showIf: {
type: Function, type: Function,
default: () => { default: () => {
@ -56,18 +59,26 @@ const props = defineProps({
default: undefined, default: undefined,
}, },
}); });
const emit = defineEmits(['update:modelValue']);
const textValue = ref(props.modelValue);
watch(
() => props.modelValue,
(newVal, oldVal) => {
textValue.value = newVal;
},
);
const rulesComputed = computed(() => { const rulesComputed = computed(() => {
let rules = inRules || <any>[]; let result = rules || <any>[];
if (showIfComputed.value && requiredIfComputed.value) { if (showIfComputed.value && requiredIfComputed.value) {
rules.push(FormValidators.required()); result.push(FormValidators.required());
} else if (!showIfComputed.value) { } else if (!showIfComputed.value) {
rules = []; result = [];
} }
if (textRef?.value) { if (textRef?.value) {
textRef.value.resetValidation(); textRef.value.resetValidation();
} }
return rules; return result;
}); });
const showIfComputed = computed(() => { const showIfComputed = computed(() => {
@ -87,4 +98,8 @@ const readonlyIfComputed = computed(() => {
const disableIfComputed = computed(() => { const disableIfComputed = computed(() => {
return props.disableIf(props.form); return props.disableIf(props.form);
}); });
const updateModelValue = (value) => {
emit('update:modelValue', value);
};
</script> </script>

32
io.sc.platform.core.frontend/src/platform/components/form/elements/WTextBtn.vue

@ -2,6 +2,7 @@
<div v-show="showIfComputed"> <div v-show="showIfComputed">
<q-input <q-input
ref="textBtnRef" ref="textBtnRef"
v-model="textBtnValue"
:hide-bottom-space="true" :hide-bottom-space="true"
:hide-hint="true" :hide-hint="true"
:outlined="true" :outlined="true"
@ -11,6 +12,12 @@
:rules="rulesComputed" :rules="rulesComputed"
:readonly="readonlyIfComputed" :readonly="readonlyIfComputed"
:disable="disableIfComputed" :disable="disableIfComputed"
@focus="
() => {
console.info('ffffffff');
}
"
@update:model-value="updateModelValue"
> >
<template #label> <span v-if="requiredIfComputed" style="color: red">*</span> {{ attrs.label }}</template> <template #label> <span v-if="requiredIfComputed" style="color: red">*</span> {{ attrs.label }}</template>
<template v-if="attrs.button && attrs.buttonPosition === 'prepend'" #prepend> <template v-if="attrs.button && attrs.buttonPosition === 'prepend'" #prepend>
@ -30,13 +37,14 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, computed, defineProps, useAttrs } from 'vue'; import { ref, computed, defineProps, useAttrs, watch } from 'vue';
import { FormValidators } from '@/platform/components'; import { FormValidators } from '@/platform/components';
const textBtnRef = ref(); const textBtnRef = ref();
const attrs = useAttrs(); const attrs = useAttrs();
const inRules = attrs.rules; const rules = attrs.rules;
const props = defineProps({ const props = defineProps({
modelValue: { type: String, default: '' },
showIf: { showIf: {
type: Function, type: Function,
default: () => { default: () => {
@ -68,18 +76,26 @@ const props = defineProps({
default: undefined, default: undefined,
}, },
}); });
const emit = defineEmits(['update:modelValue']);
const textBtnValue = ref(props.modelValue);
watch(
() => props.modelValue,
(newVal, oldVal) => {
textBtnValue.value = newVal;
},
);
const rulesComputed = computed(() => { const rulesComputed = computed(() => {
let rules = inRules || <any>[]; let result = rules || <any>[];
if (showIfComputed.value && requiredIfComputed.value) { if (showIfComputed.value && requiredIfComputed.value) {
rules.push(FormValidators.required()); result.push(FormValidators.required());
} else if (!showIfComputed.value) { } else if (!showIfComputed.value) {
rules = []; result = [];
} }
if (textBtnRef?.value) { if (textBtnRef?.value) {
textBtnRef.value.resetValidation(); textBtnRef.value.resetValidation();
} }
return rules; return result;
}); });
const showIfComputed = computed(() => { const showIfComputed = computed(() => {
@ -99,4 +115,8 @@ const readonlyIfComputed = computed(() => {
const disableIfComputed = computed(() => { const disableIfComputed = computed(() => {
return props.disableIf(props.form); return props.disableIf(props.form);
}); });
const updateModelValue = (value) => {
emit('update:modelValue', value);
};
</script> </script>

27
io.sc.platform.core.frontend/src/platform/components/form/elements/WTextarea.vue

@ -2,6 +2,7 @@
<div v-show="showIfComputed"> <div v-show="showIfComputed">
<q-input <q-input
ref="textareaRef" ref="textareaRef"
v-model="textareaValue"
:hide-bottom-space="true" :hide-bottom-space="true"
:hide-hint="true" :hide-hint="true"
:outlined="true" :outlined="true"
@ -11,6 +12,7 @@
:rules="rulesComputed" :rules="rulesComputed"
:readonly="readonlyIfComputed" :readonly="readonlyIfComputed"
:disable="disableIfComputed" :disable="disableIfComputed"
@update:model-value="updateModelValue"
> >
<template #label> <span v-if="requiredIfComputed" style="color: red">*</span> {{ attrs.label }}</template> <template #label> <span v-if="requiredIfComputed" style="color: red">*</span> {{ attrs.label }}</template>
</q-input> </q-input>
@ -18,13 +20,14 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, computed, defineProps, useAttrs } from 'vue'; import { ref, computed, defineProps, useAttrs, watch } from 'vue';
import { FormValidators } from '@/platform/components'; import { FormValidators } from '@/platform/components';
const textareaRef = ref(); const textareaRef = ref();
const attrs = useAttrs(); const attrs = useAttrs();
const inRules = attrs.rules; const rules = attrs.rules;
const props = defineProps({ const props = defineProps({
modelValue: { type: String, default: '' },
showIf: { showIf: {
type: Function, type: Function,
default: () => { default: () => {
@ -56,18 +59,26 @@ const props = defineProps({
default: undefined, default: undefined,
}, },
}); });
const emit = defineEmits(['update:modelValue']);
const textareaValue = ref(props.modelValue);
watch(
() => props.modelValue,
(newVal, oldVal) => {
textareaValue.value = newVal;
},
);
const rulesComputed = computed(() => { const rulesComputed = computed(() => {
let rules = inRules || <any>[]; let result = rules || <any>[];
if (showIfComputed.value && requiredIfComputed.value) { if (showIfComputed.value && requiredIfComputed.value) {
rules.push(FormValidators.required()); result.push(FormValidators.required());
} else if (!showIfComputed.value) { } else if (!showIfComputed.value) {
rules = []; result = [];
} }
if (textareaRef?.value) { if (textareaRef?.value) {
textareaRef.value.resetValidation(); textareaRef.value.resetValidation();
} }
return rules; return result;
}); });
const showIfComputed = computed(() => { const showIfComputed = computed(() => {
@ -87,4 +98,8 @@ const readonlyIfComputed = computed(() => {
const disableIfComputed = computed(() => { const disableIfComputed = computed(() => {
return props.disableIf(props.form); return props.disableIf(props.form);
}); });
const updateModelValue = (value) => {
emit('update:modelValue', value);
};
</script> </script>

Loading…
Cancel
Save