Commit 464eb892e3c920ed1cc5f1d489c802ebff96b798

Authored by 杨泽宇
1 parent c9b846b0

活动总结

docs/develop/component.md
@@ -22,7 +22,9 @@ @@ -22,7 +22,9 @@
22 22
23 ## 富文本 23 ## 富文本
24 * 代码位置:[src/components/Tinymce](http://bj.gitlab.cnlive.com/cnlive_project/cnlive-community-web-vue/blob/dev/src/components/Tinymce) 24 * 代码位置:[src/components/Tinymce](http://bj.gitlab.cnlive.com/cnlive_project/cnlive-community-web-vue/blob/dev/src/components/Tinymce)
  25 + * 官方文档:[Tinymce](http://tinymce.ax-z.cn/)
25 * Emit: `update:modelValue(content)` 26 * Emit: `update:modelValue(content)`
  27 + * 表单重置清空内容:`window.tinymce.get(Tinymce.props.id.default).setContent("")`
26 * 组件属性: 28 * 组件属性:
27 29
28 | propName | propType | propAttr | propDesc | propDefault | 30 | propName | propType | propAttr | propDesc | propDefault |
src/components/Tinymce/index.vue
@@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
6 import { ref, onMounted, onUnmounted } from "vue"; 6 import { ref, onMounted, onUnmounted } from "vue";
7 import { uploadPicSource } from "@/api/user/login"; 7 import { uploadPicSource } from "@/api/user/login";
8 import { toolbar, plugins } from "./settings/index"; 8 import { toolbar, plugins } from "./settings/index";
9 -import load from './settings/load'; 9 +import load from "./settings/load";
10 import { ElMessage, ElLoading } from "element-plus"; 10 import { ElMessage, ElLoading } from "element-plus";
11 11
12 /** 12 /**
@@ -37,15 +37,15 @@ const props = withDefaults(defineProps<Props>(), { @@ -37,15 +37,15 @@ const props = withDefaults(defineProps<Props>(), {
37 const emit = defineEmits<{ 37 const emit = defineEmits<{
38 (e: "update:modelValue", val: string): void; 38 (e: "update:modelValue", val: string): void;
39 }>(); 39 }>();
40 -const cdnUrl = ref('https://unpkg.com/tinymce@5.10.3/tinymce.min.js')  
41 -let pageLoading = ref(null) 40 +const cdnUrl = ref("https://unpkg.com/tinymce@5.10.3/tinymce.min.js");
  41 +let pageLoading = ref(null);
42 // 删除tinymce实例 42 // 删除tinymce实例
43 const destroyTinymce = () => { 43 const destroyTinymce = () => {
44 - const tinymce = window.tinymce.get(props.id)  
45 - if(tinymce) {  
46 - tinymce.destroy() 44 + const tinymce = window.tinymce.get(props.id);
  45 + if (tinymce) {
  46 + tinymce.destroy();
47 } 47 }
48 -} 48 +};
49 // 初始化tinymce实例 49 // 初始化tinymce实例
50 const initTinymce = () => { 50 const initTinymce = () => {
51 tinymce.init({ 51 tinymce.init({
@@ -88,7 +88,7 @@ const initTinymce = () =&gt; { @@ -88,7 +88,7 @@ const initTinymce = () =&gt; {
88 }, 88 },
89 // 内容改变监听 89 // 内容改变监听
90 init_instance_callback: (editor) => { 90 init_instance_callback: (editor) => {
91 - pageLoading.close() 91 + pageLoading.close();
92 // 赋默认值 92 // 赋默认值
93 if (props.modelValue) { 93 if (props.modelValue) {
94 editor.setContent(props.modelValue); 94 editor.setContent(props.modelValue);
@@ -97,24 +97,24 @@ const initTinymce = () =&gt; { @@ -97,24 +97,24 @@ const initTinymce = () =&gt; {
97 editor.on("NodeChange Change KeyUp SetContent", () => { 97 editor.on("NodeChange Change KeyUp SetContent", () => {
98 emit("update:modelValue", editor.getContent()); 98 emit("update:modelValue", editor.getContent());
99 }); 99 });
100 - }, 100 + }
101 }); 101 });
102 -} 102 +};
103 onUnmounted(() => { 103 onUnmounted(() => {
104 - destroyTinymce()  
105 -}) 104 + destroyTinymce();
  105 +});
106 onMounted(() => { 106 onMounted(() => {
107 pageLoading = ElLoading.service({ 107 pageLoading = ElLoading.service({
108 lock: true, 108 lock: true,
109 - text: '加载中,请稍候...'  
110 - }) 109 + text: "加载中,请稍候...",
  110 + });
111 load(cdnUrl.value, (err) => { 111 load(cdnUrl.value, (err) => {
112 if (err) { 112 if (err) {
113 ElMessage.error(err.message); 113 ElMessage.error(err.message);
114 - return 114 + return;
115 } 115 }
116 - initTinymce()  
117 - }) 116 + initTinymce();
  117 + });
118 }); 118 });
119 </script> 119 </script>
120 120
src/router/modules/event.ts
@@ -19,6 +19,11 @@ const event = { @@ -19,6 +19,11 @@ const event = {
19 component: () => import('@/views/event/handwork/edit.vue'), 19 component: () => import('@/views/event/handwork/edit.vue'),
20 meta: { title: '活动编辑' } 20 meta: { title: '活动编辑' }
21 }, { 21 }, {
  22 + path: '/event/summary',
  23 + name: 'summary',
  24 + component: () => import('@/views/event/handwork/summary.vue'),
  25 + meta: { title: '活动总结' }
  26 + }, {
22 path: '/event/signup', 27 path: '/event/signup',
23 name: 'signup', 28 name: 'signup',
24 component: () => import('@/views/event/handwork/signup.vue'), 29 component: () => import('@/views/event/handwork/signup.vue'),
src/views/event/handwork/edit.vue
1 <script setup lang="ts"> 1 <script setup lang="ts">
2 -import { reactive, ref, getCurrentInstance, onMounted, nextTick } from "vue"; 2 +import { reactive, ref, getCurrentInstance, onMounted } from "vue";
3 import { eventCategory, handworkEdit } from "@/api/event"; 3 import { eventCategory, handworkEdit } from "@/api/event";
4 import { useRoute } from "vue-router"; 4 import { useRoute } from "vue-router";
5 import { back } from "@/utils/tool"; 5 import { back } from "@/utils/tool";
@@ -160,6 +160,11 @@ const rules = reactive({ @@ -160,6 +160,11 @@ const rules = reactive({
160 */ 160 */
161 const resetForm = (formEl: InstanceType<typeof ElForm> | undefined) => { 161 const resetForm = (formEl: InstanceType<typeof ElForm> | undefined) => {
162 if (!formEl) return; 162 if (!formEl) return;
  163 + form.publicityPic = [];
  164 + form.value1 = [];
  165 + form.value2 = [];
  166 + form.communityList = [];
  167 + window.tinymce.get(Tinymce.props.id.default).setContent("");
163 formEl.resetFields(); 168 formEl.resetFields();
164 }; 169 };
165 /** 170 /**
@@ -266,9 +271,6 @@ const handleFinish = (images) =&gt; { @@ -266,9 +271,6 @@ const handleFinish = (images) =&gt; {
266 }); 271 });
267 }, 500); 272 }, 500);
268 }; 273 };
269 -const getContent = (data) => {  
270 - console.log(data);  
271 -};  
272 onMounted(() => { 274 onMounted(() => {
273 getCategory(); 275 getCategory();
274 getCommunityList(); 276 getCommunityList();
@@ -301,6 +303,11 @@ onMounted(() =&gt; { @@ -301,6 +303,11 @@ onMounted(() =&gt; {
301 }); 303 });
302 } 304 }
303 } 305 }
  306 + // setTimeout(() => {
  307 + // console.log(window.tinymce.get(Tinymce.props.id.default))
  308 + // console.log(Tinymce.props.id.default)
  309 + // window.tinymce.get(Tinymce.props.id.default).setContent('tengxi')
  310 + // }, 500)
304 }); 311 });
305 </script> 312 </script>
306 313
@@ -316,7 +323,6 @@ onMounted(() =&gt; { @@ -316,7 +323,6 @@ onMounted(() =&gt; {
316 ref="ruleFormRef" 323 ref="ruleFormRef"
317 label-width="120px" 324 label-width="120px"
318 class="card-form" 325 class="card-form"
319 - :disabled="form.dataType === 'detail'"  
320 > 326 >
321 <el-form-item label="活动名称" prop="name" style="width: 100%"> 327 <el-form-item label="活动名称" prop="name" style="width: 100%">
322 <el-input 328 <el-input
src/views/event/handwork/index.vue
@@ -312,6 +312,13 @@ onMounted(() =&gt; { @@ -312,6 +312,13 @@ onMounted(() =&gt; {
312 >查看人员</router-link 312 >查看人员</router-link
313 ></el-button 313 ></el-button
314 > 314 >
  315 + <!-- 活动结束以后可以填写活动总结 -->
  316 + <el-button type="text" v-show="new Date(scope.row.endTime) < new Date()"
  317 + ><router-link
  318 + :to="{ path: '/event/summary', query: { id: scope.row.id } }"
  319 + >活动总结</router-link
  320 + ></el-button
  321 + >
315 <el-button 322 <el-button
316 type="text" 323 type="text"
317 @click="handleDelete(scope.row.id)" 324 @click="handleDelete(scope.row.id)"
src/views/event/handwork/summary.vue 0 → 100644
  1 +<script setup lang="ts">
  2 +import { reactive, ref, getCurrentInstance, onMounted } from "vue";
  3 +// import { eventCategory, handworkEdit } from "@/api/event";
  4 +import { useRoute } from "vue-router";
  5 +import { back } from "@/utils/tool";
  6 +import Photowall from "@/components/Photowall/index.vue";
  7 +import Tinymce from "@/components/Tinymce/index.vue";
  8 +import type { ElForm } from "element-plus";
  9 +let form = reactive({
  10 + data: {
  11 + summary: "",
  12 + imgs: "",
  13 + },
  14 + publicityPic: [],
  15 + dataType: "",
  16 + loading: false,
  17 +});
  18 +const ruleFormRef = ref<InstanceType<typeof ElForm>>();
  19 +let instance: ComponentInternalInstance | null = getCurrentInstance();
  20 +/**
  21 + * 表单验证规则
  22 + */
  23 +const rules = reactive({
  24 + summary: [
  25 + {
  26 + required: true,
  27 + message: "请填写活动总结",
  28 + trigger: "change",
  29 + },
  30 + ],
  31 +});
  32 +/**
  33 + * 表单重置
  34 + */
  35 +const resetForm = (formEl: InstanceType<typeof ElForm> | undefined) => {
  36 + if (!formEl) return;
  37 + form.publicityPic = [];
  38 + window.tinymce.get(Tinymce.props.id.default).setContent("");
  39 + formEl.resetFields();
  40 +};
  41 +/**
  42 + * 表单提交
  43 + */
  44 +const submitForm = (
  45 + formEl: InstanceType<typeof ElForm> | undefined,
  46 + type: number
  47 +) => {
  48 + form.loading = true;
  49 + if (!formEl) return;
  50 + formEl.validate(async (valid) => {
  51 + if (valid) {
  52 + console.log("post api");
  53 + } else {
  54 + instance?.proxy?.$message.error("请检查表单格式");
  55 + form.loading = false;
  56 + return false;
  57 + }
  58 + });
  59 +};
  60 +/**
  61 + * 多图上传组件回调
  62 + * @param {string} images 回调的图片urls
  63 + * @param {string} tagName 标签
  64 + */
  65 +const handleFinish = (images) => {
  66 + form.publicityPic = [];
  67 + setTimeout(() => {
  68 + images.map((item) => {
  69 + form.publicityPic.push({
  70 + url: item,
  71 + });
  72 + });
  73 + }, 500);
  74 +};
  75 +onMounted(() => {
  76 + console.log(useRoute().query);
  77 +});
  78 +</script>
  79 +
  80 +<template>
  81 + <div class="page-container">
  82 + <el-card class="form_card" style="max-width: 1303px">
  83 + <h1>活动总结</h1>
  84 + <el-form
  85 + :inline="true"
  86 + :model="form.data"
  87 + :rules="rules"
  88 + ref="ruleFormRef"
  89 + label-width="120px"
  90 + class="card-form"
  91 + >
  92 + <el-form-item label="活动总结" prop="summary" style="width: 100%">
  93 + <Tinymce v-model="form.data.summary"></Tinymce>
  94 + </el-form-item>
  95 + <el-form-item label="宣传图片" prop="imgs" style="width: 100%">
  96 + <Photowall
  97 + @finish="handleFinish"
  98 + :fileList="form.publicityPic"
  99 + ></Photowall>
  100 + </el-form-item>
  101 + <el-form-item style="width: 100%" v-show="form.dataType !== 'detail'">
  102 + <el-button
  103 + type="primary"
  104 + @click.prevent="submitForm(ruleFormRef, 0)"
  105 + :loading="form.loading"
  106 + >保存</el-button
  107 + >
  108 + <el-button type="info" @click="back">返回</el-button>
  109 + </el-form-item>
  110 + </el-form>
  111 + </el-card>
  112 + </div>
  113 +</template>