form-basic-content.vue
4.04 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<script setup lang="ts">
import { Layout, LayoutContent, LayoutSider, Form, FormItem, Input, InputNumber, Select } from '@arco-design/web-vue';
import ImageUpload from '@/components/image-upload/index.vue';
import RoleSelect from '@/views/operation/banner/components/role-select.vue';
import { Banner } from '@/utils/model';
import useBannerApi from '@/http/bannner';
import { computed, ref, watch } from 'vue';
import { FormInstance } from '@arco-design/web-vue/es/form';
import { pick } from 'lodash';
import { AttributeData } from '@/types/global';
import { promiseToBoolean } from '@/utils';
type FormType = Pick<Banner, 'name' | 'scope' | 'weight' | 'permission' | 'type' | 'cover' | 'content_picture'>;
const props = defineProps<{ init?: AttributeData; http: (params?: object) => Promise<any> }>();
const { scopeOption, typeOption } = useBannerApi;
const formVal = ref<FormType>({
name: '',
scope: 1,
weight: 0,
permission: [],
type: 1,
cover: '',
content_picture: '',
...pick(props.init, ['name', 'scope', 'weight', 'permission', 'type', 'cover', 'content_picture']),
});
const formRule = computed(() => {
return {
name: [{ required: true, message: '请输入名称' }],
scope: [{ required: true, message: '请选择展示位置' }],
weight: [{ required: true, message: '请输入权重' }],
permission: [{ required: true, message: '请选择浏览用户' }],
type: [{ required: true, message: '请选择类型' }],
cover: [{ required: true, message: '请选择封面' }],
content_picture: formVal.value.type === 1 ? [] : [{ required: true, message: '请输入链接地址' }],
};
});
const formRef = ref<FormInstance>();
watch(
() => formVal.value.type,
() => (formVal.value.content_picture = '')
);
const onSubmit = async (): Promise<boolean> => {
if (await formRef.value?.validate()) {
// eslint-disable-next-line prefer-promise-reject-errors
return Promise.reject(false);
}
return promiseToBoolean(props.http(formVal.value));
};
defineExpose({ onSubmit });
</script>
<template>
<Layout>
<LayoutContent class="content">
<Form ref="formRef" :model="formVal" :rules="formRule" auto-label-width>
<FormItem label="封面" field="cover" show-colon>
<ImageUpload v-model="formVal.cover" :width="500" :height="154" fit="contain" />
</FormItem>
<FormItem label="名称" field="name" show-colon>
<Input v-model="formVal.name" :max-length="30" show-word-limit placeholder="请输入" />
</FormItem>
<FormItem label="展示位置" field="scope" show-colon>
<Select v-model="formVal.scope" :options="scopeOption" placeholder="请选择" />
</FormItem>
<FormItem label="权重" field="weight" show-colon>
<InputNumber v-model="formVal.weight" :min="0" :max="200" placeholder="请输入" />
</FormItem>
<FormItem label="浏览用户" field="permission" show-colon>
<RoleSelect v-model="formVal.permission" :max-tag-count="3" style="height: 32px; width: 500px" />
</FormItem>
<FormItem label="类型" field="type" show-colon>
<Select v-model="formVal.type" :options="typeOption.filter((item) => [1, 2].includes(item.value))" placeholder="请选择" />
</FormItem>
<FormItem v-show="formVal.type === 2" label="详情" field="content_picture" show-colon row-class="mb-0">
<Input v-model="formVal.content_picture" placeholder="请输入" />
</FormItem>
</Form>
</LayoutContent>
<LayoutSider v-show="formVal.type === 1" class="side" :width="260">
<ImageUpload v-model="formVal.content_picture" :width="260" height="100%" min-height="414px" fit="fill" />
</LayoutSider>
</Layout>
</template>
<style scoped lang="less">
.side {
box-shadow: unset;
margin-left: 10px;
height: 414px;
:deep(.arco-upload-list-item) {
margin-top: 0 !important;
.arco-upload-picture-card {
height: 414px !important;
}
}
}
</style>