|
@@ -3,6 +3,7 @@ import WdButton from 'wot-design-uni/components/wd-button/wd-button.vue'
|
|
|
import WdInput from 'wot-design-uni/components/wd-input/wd-input.vue'
|
|
|
import WdPicker from 'wot-design-uni/components/wd-picker/wd-picker.vue'
|
|
|
import { ref } from 'vue'
|
|
|
+import { ConfigProviderThemeVars } from 'wot-design-uni'
|
|
|
|
|
|
const modelValue = defineModel({
|
|
|
type: Object,
|
|
@@ -53,6 +54,24 @@ const verticalDefaultProps = {
|
|
|
block: true,
|
|
|
},
|
|
|
}
|
|
|
+const horizontalDefaultProps = {
|
|
|
+ TextField: {
|
|
|
+ customClass: 'text-red!',
|
|
|
+ placeholderClass: 'text-black/30',
|
|
|
+ },
|
|
|
+ Select: {
|
|
|
+ customClass: 'text-black/30! border-b-1 border-b-[#e1e1e1] border-b-solid',
|
|
|
+ },
|
|
|
+ Radio: {
|
|
|
+ customClass: 'my--4!',
|
|
|
+ },
|
|
|
+}
|
|
|
+const themeVars: ConfigProviderThemeVars = {
|
|
|
+ cellPadding: '0',
|
|
|
+ cellWrapperPadding: '10rpx',
|
|
|
+ radioButtonRadius: '8rpx',
|
|
|
+ radioButtonBg: 'transparent',
|
|
|
+}
|
|
|
const submit = () => {
|
|
|
emits('submit', modelValue)
|
|
|
}
|
|
@@ -62,60 +81,86 @@ defineExpose({
|
|
|
})
|
|
|
</script>
|
|
|
<template>
|
|
|
- <wd-form ref="form" :model="modelValue">
|
|
|
- <template
|
|
|
- v-for="([prop, { type, label, props }], index) in Object.entries(schema)"
|
|
|
- :key="index"
|
|
|
- >
|
|
|
- <div class="grid mb-4">
|
|
|
- <label
|
|
|
- v-if="type !== 'Submit' && direction === 'vertical'"
|
|
|
- class="text-black/40 text-sm font-normal font-['PingFang SC'] leading-relaxed mb-1"
|
|
|
- :for="prop"
|
|
|
- >
|
|
|
- {{ label || prop }}
|
|
|
- </label>
|
|
|
- <!-- #ifdef H5 -->
|
|
|
- <component :is="types[type]" :name="prop" v-bind="defaultProps[type]">
|
|
|
- <span v-if="type === 'Submit'">提交</span>
|
|
|
- </component>
|
|
|
- <!-- #endif -->
|
|
|
- <!-- #ifdef MP-WEIXIN -->
|
|
|
- <wd-input
|
|
|
- v-if="type === 'TextField'"
|
|
|
- v-bind="{
|
|
|
- ...(direction === 'vertical' ? verticalDefaultProps[type] : {}),
|
|
|
- ...props,
|
|
|
- }"
|
|
|
- v-model="modelValue[prop]"
|
|
|
- ></wd-input>
|
|
|
- <wd-picker
|
|
|
- v-if="type === 'Select'"
|
|
|
- v-bind="{ label, ...props }"
|
|
|
- v-model="modelValue[prop]"
|
|
|
- ></wd-picker>
|
|
|
- <wd-radio-group
|
|
|
- v-if="type === 'Radio'"
|
|
|
- v-bind="{ label, ...props, cell: true, shape: 'button' }"
|
|
|
- v-model="modelValue[prop]"
|
|
|
- >
|
|
|
- <template v-for="{ label, value } of props.columns" :key="value">
|
|
|
- <wd-radio :value="value">{{ label }}</wd-radio>
|
|
|
- </template>
|
|
|
- </wd-radio-group>
|
|
|
- <wd-button
|
|
|
- v-if="type === 'Submit'"
|
|
|
- v-bind="{
|
|
|
- ...(direction === 'vertical' ? verticalDefaultProps[type] : {}),
|
|
|
- ...props,
|
|
|
- formType: 'submit',
|
|
|
- }"
|
|
|
- @click="submit"
|
|
|
+ <wd-config-provider :theme-vars="themeVars">
|
|
|
+ <wd-form ref="form" :model="modelValue">
|
|
|
+ <template
|
|
|
+ v-for="([prop, { type, label, props }], index) in Object.entries(schema)"
|
|
|
+ :key="index"
|
|
|
+ >
|
|
|
+ <div
|
|
|
+ class="grid mb-4"
|
|
|
+ :class="[direction === 'horizontal' ? 'items-center' : '']"
|
|
|
+ :style="
|
|
|
+ direction === 'horizontal'
|
|
|
+ ? { 'grid-template-columns': `${props.labelWidth} auto` }
|
|
|
+ : {}
|
|
|
+ "
|
|
|
>
|
|
|
- <span v-if="type === 'Submit'">提交</span>
|
|
|
- </wd-button>
|
|
|
- <!-- #endif -->
|
|
|
- </div>
|
|
|
- </template>
|
|
|
- </wd-form>
|
|
|
+ <label
|
|
|
+ v-if="type !== 'Submit'"
|
|
|
+ class="text-sm font-normal leading-relaxed"
|
|
|
+ :class="[direction === 'horizontal' ? 'text-black/60' : 'mb-1 text-black/40']"
|
|
|
+ :for="prop"
|
|
|
+ >
|
|
|
+ {{ label || prop }}
|
|
|
+ </label>
|
|
|
+ <!-- #ifdef H5 -->
|
|
|
+ <component :is="types[type]" :name="prop" v-bind="defaultProps[type]">
|
|
|
+ <span v-if="type === 'Submit'">提交</span>
|
|
|
+ </component>
|
|
|
+ <!-- #endif -->
|
|
|
+ <!-- #ifdef MP-WEIXIN -->
|
|
|
+ <wd-input
|
|
|
+ v-if="type === 'TextField'"
|
|
|
+ v-bind="{
|
|
|
+ ...(direction === 'vertical'
|
|
|
+ ? verticalDefaultProps[type]
|
|
|
+ : horizontalDefaultProps[type]),
|
|
|
+ ...props,
|
|
|
+ }"
|
|
|
+ v-model="modelValue[prop]"
|
|
|
+ ></wd-input>
|
|
|
+ <wd-picker
|
|
|
+ v-if="type === 'Select'"
|
|
|
+ v-bind="{
|
|
|
+ ...(direction === 'vertical'
|
|
|
+ ? verticalDefaultProps[type]
|
|
|
+ : horizontalDefaultProps[type]),
|
|
|
+ cell: false,
|
|
|
+ ...props,
|
|
|
+ }"
|
|
|
+ v-model="modelValue[prop]"
|
|
|
+ ></wd-picker>
|
|
|
+ <wd-radio-group
|
|
|
+ v-if="type === 'Radio'"
|
|
|
+ v-bind="{
|
|
|
+ ...(direction === 'vertical'
|
|
|
+ ? verticalDefaultProps[type]
|
|
|
+ : horizontalDefaultProps[type]),
|
|
|
+ ...props,
|
|
|
+ cell: true,
|
|
|
+ shape: 'button',
|
|
|
+ }"
|
|
|
+ v-model="modelValue[prop]"
|
|
|
+ >
|
|
|
+ <template v-for="{ label, value } of props.columns" :key="value">
|
|
|
+ <wd-radio :value="value">{{ label }}</wd-radio>
|
|
|
+ </template>
|
|
|
+ </wd-radio-group>
|
|
|
+ <wd-button
|
|
|
+ v-if="type === 'Submit'"
|
|
|
+ v-bind="{
|
|
|
+ ...(direction === 'vertical' ? verticalDefaultProps[type] : {}),
|
|
|
+ ...props,
|
|
|
+ formType: 'submit',
|
|
|
+ }"
|
|
|
+ @click="submit"
|
|
|
+ >
|
|
|
+ <span v-if="type === 'Submit'">提交</span>
|
|
|
+ </wd-button>
|
|
|
+ <!-- #endif -->
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ </wd-form>
|
|
|
+ </wd-config-provider>
|
|
|
</template>
|