summary.vue
2.84 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
<script setup lang="ts">
import { reactive, ref, getCurrentInstance, onMounted } from "vue";
// import { eventCategory, handworkEdit } from "@/api/event";
import { useRoute } from "vue-router";
import { back } from "@/utils/tool";
import Photowall from "@/components/Photowall/index.vue";
import Tinymce from "@/components/Tinymce/index.vue";
import type { ElForm } from "element-plus";
let form = reactive({
data: {
summary: "",
imgs: "",
},
publicityPic: [],
dataType: "",
loading: false,
});
const ruleFormRef = ref<InstanceType<typeof ElForm>>();
let instance: ComponentInternalInstance | null = getCurrentInstance();
/**
* 表单验证规则
*/
const rules = reactive({
summary: [
{
required: true,
message: "请填写活动总结",
trigger: "change",
},
],
});
/**
* 表单重置
*/
const resetForm = (formEl: InstanceType<typeof ElForm> | undefined) => {
if (!formEl) return;
form.publicityPic = [];
window.tinymce.get(Tinymce.props.id.default).setContent("");
formEl.resetFields();
};
/**
* 表单提交
*/
const submitForm = (
formEl: InstanceType<typeof ElForm> | undefined,
type: number
) => {
form.loading = true;
if (!formEl) return;
formEl.validate(async (valid) => {
if (valid) {
console.log("post api");
} else {
instance?.proxy?.$message.error("请检查表单格式");
form.loading = false;
return false;
}
});
};
/**
* 多图上传组件回调
* @param {string} images 回调的图片urls
* @param {string} tagName 标签
*/
const handleFinish = (images) => {
form.publicityPic = [];
setTimeout(() => {
images.map((item) => {
form.publicityPic.push({
url: item,
});
});
}, 500);
};
onMounted(() => {
console.log(useRoute().query);
});
</script>
<template>
<div class="page-container">
<el-card class="form_card" style="max-width: 1303px">
<h1>活动总结</h1>
<el-form
:inline="true"
:model="form.data"
:rules="rules"
ref="ruleFormRef"
label-width="120px"
class="card-form"
>
<el-form-item label="活动总结" prop="summary" style="width: 100%">
<Tinymce v-model="form.data.summary"></Tinymce>
</el-form-item>
<el-form-item label="宣传图片" prop="imgs" style="width: 100%">
<Photowall
@finish="handleFinish"
:fileList="form.publicityPic"
></Photowall>
</el-form-item>
<el-form-item style="width: 100%" v-show="form.dataType !== 'detail'">
<el-button
type="primary"
@click.prevent="submitForm(ruleFormRef, 0)"
:loading="form.loading"
>保存</el-button
>
<el-button type="info" @click="back">返回</el-button>
</el-form-item>
</el-form>
</el-card>
</div>
</template>