step1-form-content.vue
2.97 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
73
74
75
76
77
<script setup lang="ts">
import { Form, FormItem, Input, Message, Select } from '@arco-design/web-vue';
import { computed, ref } from 'vue';
import AvatarUpload from '@/components/avatar-upload/index.vue';
import { FieldRule, FormInstance } from '@arco-design/web-vue/es/form';
import { useSelectionStore } from '@/store';
import { get, set } from 'lodash';
import { useVModels } from '@vueuse/core';
const props = withDefaults(defineProps<{ loading?: boolean; modelValue?: any; filterProject?: (value: any) => boolean }>(), {
filterProject: () => true,
});
const emits = defineEmits(['update:modelValue', 'update:loading']);
const formRef = ref<FormInstance>();
const { modelValue: formValue } = useVModels(props, emits);
const formRule = {
'cover': [{ type: 'string', required: true, message: '请上传活动封面' }],
'song_name': [{ type: 'string', required: true, message: '请输入歌曲名称' }],
'expand.tag_ids': [
{ type: 'array', required: false, message: '请选择关联标签' },
{ type: 'array', maxLength: 3, message: '关联标签最多选中3个' },
],
'project_id': [{ type: 'number', min: 1, required: true, message: '请选择关联厂牌' }],
} as Record<string, FieldRule[]>;
const tagIds = computed({
get: () => get(formValue.value, 'expand.tag_ids', []),
set: (val) => set(formValue.value, 'expand.tag_ids', val),
});
const { activityTagOptions, projectOptions } = useSelectionStore();
const onTagExceedLimitError = (content: string, duration = 1000) => Message.warning({ content, duration });
defineExpose({
onValid: (callback?: () => void) => formRef.value?.validate((errors) => !errors && callback?.()),
});
</script>
<template>
<Form ref="formRef" :model="formValue" :rules="formRule" :auto-label-width="true">
<FormItem label="封面图片" field="cover" :show-colon="true">
<AvatarUpload v-model="formValue.cover" :size="100" shape="square" />
</FormItem>
<FormItem label="歌曲名称" field="song_name" :show-colon="true">
<Input v-model="formValue.song_name" :max-length="100" :show-word-limit="true" placeholder="请输入" />
</FormItem>
<FormItem label="曲风标签" field="expand.tag_ids" :show-colon="true">
<Select
v-model="tagIds"
:options="activityTagOptions"
:limit="3"
:field-names="{ value: 'id', label: 'name' }"
:fallback-option="false"
:virtual-list-props="{ height: 200 }"
:multiple="true"
placeholder="请选择"
@exceed-limit="onTagExceedLimitError('关联标签最多选中3个')"
/>
</FormItem>
<FormItem label="关联厂牌" field="project_id" :show-colon="true">
<Select
v-model="formValue.project_id"
:options="projectOptions.filter((item) => filterProject(item))"
:field-names="{ value: 'id', label: 'name' }"
:fallback-option="false"
:allow-search="true"
placeholder="请选择"
/>
</FormItem>
</Form>
</template>
<style scoped lang="less"></style>