FeedbackDrawer.vue
3 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
<template>
<BasicDrawer v-bind="$attrs" @register="registerDrawer" title="意见反馈预览" width="30%">
<BasicForm @register="registerForm">
<template #iconSelect>
<div style="width: 22vw; display: flex; flex-wrap: wrap">
<template v-for="(item, index) in feedBackImgUrl" :key="index">
<span style="display: none">{{ index }}</span>
<div>
<Upload list-type="picture-card" :openFileDialogOnClick="false">
<img
style="width: 100%; height: 11vh"
@click="handlePreview(item)"
:src="item"
alt="avatar"
/>
</Upload>
</div>
</template>
<Modal
:visible="previewVisible"
:title="previewTitle"
:footer="null"
@cancel="handleCancel"
>
<img alt="example" style="width: 100%" :src="previewImage" />
</Modal>
</div>
</template>
</BasicForm>
</BasicDrawer>
</template>
<script lang="ts">
import { defineComponent, ref } from 'vue';
import { BasicForm, useForm } from '/@/components/Form';
import { formSchema } from './config.data';
import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
import { Upload } from 'ant-design-vue';
import { Modal } from 'ant-design-vue';
export default defineComponent({
name: 'ContactDrawer',
components: { BasicDrawer, BasicForm, Upload, Modal },
emits: ['success', 'register'],
setup(_) {
const feedBackImgUrl = ref([]);
const previewVisible = ref(false);
const previewImage = ref('');
const previewTitle = ref('');
const [registerForm, { setFieldsValue, resetFields }] = useForm({
labelWidth: 120,
schemas: formSchema,
showActionButtonGroup: false,
});
const [registerDrawer, { setDrawerProps }] = useDrawerInner(async (data) => {
await resetFields();
feedBackImgUrl.value = [];
setDrawerProps({ confirmLoading: false });
await setFieldsValue(data.record);
if (data.record.images) {
const imageFormJson = JSON.parse(data.record.images);
feedBackImgUrl.value = imageFormJson;
}
if (data.record.contact) {
const contactFormJson = JSON.parse(data.record.contact);
await setFieldsValue({
email: contactFormJson.email,
phone: contactFormJson.phone,
qq: contactFormJson.qq,
});
}
});
const handlePreview = async (item) => {
previewVisible.value = true;
previewImage.value = item;
previewTitle.value = '预览图片';
};
const handleCancel = () => {
previewVisible.value = false;
};
return {
registerDrawer,
registerForm,
feedBackImgUrl,
handlePreview,
previewVisible,
handleCancel,
previewImage,
previewTitle,
};
},
});
</script>