step2-form-content.vue
3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<script setup lang="ts">
import { Form, FormItem, InputTag } from '@arco-design/web-vue';
import UserSelect from '@/components/user-select/index.vue';
import { ref, computed } from 'vue';
import { FieldRule, FormInstance } from '@arco-design/web-vue/es/form';
import { useVModels } from '@vueuse/core';
import { get, set } from 'lodash';
const props = defineProps<{ loading?: boolean; modelValue?: any }>();
const emits = defineEmits(['update:modelValue', 'update:loading']);
const formRef = ref<FormInstance>();
const { modelValue: formValue } = useVModels(props, emits);
const lyricistIds = computed({
get: () => get(formValue.value, 'expand.lyricist.ids', []),
set: (val) => set(formValue.value, 'expand.lyricist.ids', val),
});
const lyricistSupplement = computed({
get: () => get(formValue.value, 'expand.lyricist.supplement', []),
set: (val) => set(formValue.value, 'expand.lyricist.supplement', val),
});
const composerIds = computed({
get: () => get(formValue.value, 'expand.composer.ids', []),
set: (val) => set(formValue.value, 'expand.composer.ids', val),
});
const composerSupplement = computed({
get: () => get(formValue.value, 'expand.composer.supplement', []),
set: (val) => set(formValue.value, 'expand.composer.supplement', val),
});
const checkMaxUser = (value: any, cb: (error?: string) => void) => (value && value.length > 2 ? cb('最大选择2人') : false);
const formRule = {
'expand.lyricist.supplement': [{ type: 'array', validator: (value, cb) => checkMaxUser(value, cb) }],
'expand.composer.supplement': [{ type: 'array', validator: (value, cb) => checkMaxUser(value, cb) }],
'estimate_release_at': [{ required: true, message: '请选择预计发布时间' }],
} as Record<string, FieldRule[]>;
defineExpose({
onValid: (callback?: () => void) => formRef.value?.validate((errors) => !errors && callback?.()),
});
</script>
<template>
<Form ref="formRef" :model="formValue" :rules="formRule" :auto-label-width="true" size="small">
<FormItem label="词作者(用户)" field="expand.lyricist.ids" :show-colon="true">
<UserSelect v-model="lyricistIds" placeholder="请选择用户" :multiple="true" :allow-search="true" :limit="2" />
</FormItem>
<FormItem label="词作者(未注册)" field="expand.lyricist.supplement" :show-colon="true">
<InputTag v-model="lyricistSupplement" placeholder="输入完成回车键分隔" :max-tag-count="2" :unique-value="true" />
<template #extra>
<div>注意:上方填1项即可,歌曲信息中【用户】可点击跳转用户主页,【未注册】仅显示;</div>
</template>
</FormItem>
<FormItem label="曲作者(用户)" field="expand.composer.ids" :show-colon="true">
<UserSelect v-model="composerIds" placeholder="请选择用户" :multiple="true" :allow-search="true" :limit="2" />
</FormItem>
<FormItem label="曲作者(未注册)" field="expand.composer.supplement" :show-colon="true">
<InputTag v-model="composerSupplement" placeholder="输入完成回车键分隔" :max-tag-count="2" :unique-value="true" />
<template #extra>
<div>注意:上方填1项即可,歌曲信息中【用户】可点击跳转用户主页,【未注册】仅显示;</div>
</template>
</FormItem>
</Form>
</template>
<style scoped lang="less"></style>