form-page-content.vue
4.5 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<script setup lang="ts">
import { Col, Form, FormItem, Input, InputNumber, Row, Select, Layout, LayoutContent, LayoutSider } from '@arco-design/web-vue';
import { onBeforeUnmount, ref, shallowRef } from 'vue';
import { FieldRule, FormInstance } from '@arco-design/web-vue/es/form';
import ImageUpload from '@/components/image-upload/index.vue';
import useBannerApi from '@/http/bannner';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { Editor, Toolbar } from '@wangeditor/editor-for-vue';
import { Boot } from '@wangeditor/editor';
import '@/views/operation/notification/module';
import { AttributeData } from '@/types/global';
import { pick } from 'lodash';
import { promiseToBoolean } from '@/utils';
import RoleSelect from '@/views/operation/banner/components/role-select.vue';
const props = defineProps<{ init?: AttributeData; http: (params?: object) => Promise<any> }>();
const { scopeOption } = useBannerApi;
const formRef = ref<FormInstance>();
const editorRef = shallowRef();
Boot.setEditorConfig({ readOnly: false });
const onCreateEditor = (editor: unknown) => {
editorRef.value = editor;
};
onBeforeUnmount(() => {
const editor = editorRef.value;
if (editor == null) return;
editor.destroy();
});
const formVal = ref({
name: '',
scope: 1,
weight: 0,
permission: [],
type: 4,
cover: '',
content: '',
...pick(props.init, ['name', 'scope', 'weight', 'permission', 'type', 'cover', 'content']),
});
const formRule = {
link_type: [{ required: true, message: '请选择关联类型' }],
link_id: [{ type: 'number', min: 1, required: true, message: '请选择关联对象' }],
title: [{ required: true, message: '请输入名称' }],
content: [{ required: true, message: '请输入推荐语' }],
} as Record<string, FieldRule[]>;
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>
<Form ref="formRef" :model="formVal" :rules="formRule" style="width: 1321px" auto-label-width label-align="right">
<Row :gutter="16">
<Col flex="auto">
<FormItem label="名称" field="name" show-colon row-class="form-item">
<Input v-model="formVal.name" :max-length="30" show-word-limit placeholder="请输入" />
</FormItem>
<FormItem label="展示位置" field="scope" show-colon row-class="form-item">
<Select v-model="formVal.scope" :options="scopeOption" placeholder="请选择" />
</FormItem>
<FormItem label="权重" field="weight" show-colon row-class="form-item">
<InputNumber v-model="formVal.weight" :min="0" :max="200" placeholder="请输入" />
</FormItem>
<FormItem label="浏览用户" field="permission" show-colon row-class="mb-0">
<RoleSelect v-model="formVal.permission" :max-tag-count="6" style="height: 32px" />
</FormItem>
</Col>
<Col flex="420px">
<FormItem label="封面" field="cover" row-class="mb-0" hide-label>
<ImageUpload v-model="formVal.cover" :width="380" :height="156" fit="fill" class="cover" />
</FormItem>
</Col>
<Col :span="24" style="margin-top: 16px; margin-bottom: -24px">
<Toolbar style="border-top: 1px solid #ccc; border-bottom: 1px solid #ccc" :editor="editorRef" />
<Layout>
<LayoutContent>
<Editor v-model="formVal.content" style="height: 400px" @on-created="onCreateEditor" />
</LayoutContent>
<LayoutSider class="rich" :width="420">
<!-- eslint-disable vue/no-v-html -->
<div class="content" v-html="formVal.content" />
<!--eslint-enable-->
</LayoutSider>
</Layout>
</Col>
</Row>
</Form>
</template>
<style scoped lang="less">
.form-item {
margin-bottom: 10px !important;
}
:deep(.arco-upload-list-item) {
margin-top: 0 !important;
}
.rich {
box-shadow: unset;
border-left: 1px solid #e8e8e8;
.content {
overflow-y: auto;
height: 400px;
padding: 0 10px;
:deep(img) {
height: auto !important;
max-width: 100%;
object-fit: contain;
}
:deep(video) {
max-width: 100%;
height: auto !important;
display: block;
margin: 0 auto;
}
}
}
</style>