2026-03-24 12:18:39 +08:00
|
|
|
<template>
|
2026-03-29 19:46:50 +08:00
|
|
|
<el-dialog
|
|
|
|
|
v-model="dialogVisible"
|
|
|
|
|
class="luntan-tech-dialog"
|
|
|
|
|
title="发布帖子"
|
|
|
|
|
width="60%"
|
|
|
|
|
:before-close="handleClose"
|
2026-04-01 00:14:43 +08:00
|
|
|
:append-to-body="true"
|
2026-03-29 19:46:50 +08:00
|
|
|
>
|
|
|
|
|
<div style="overflow: auto; height: 60vh">
|
|
|
|
|
<el-form :model="form" :rules="rules" ref="formRef" label-width="80px">
|
|
|
|
|
<el-form-item label="标题" prop="title">
|
|
|
|
|
<el-input
|
|
|
|
|
v-model="form.title"
|
|
|
|
|
placeholder="请输入帖子标题"
|
|
|
|
|
maxlength="50"
|
|
|
|
|
show-word-limit
|
|
|
|
|
/>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
|
|
<el-form-item label="内容" prop="content">
|
|
|
|
|
<el-input
|
|
|
|
|
v-model="form.content"
|
|
|
|
|
type="textarea"
|
|
|
|
|
:rows="6"
|
|
|
|
|
placeholder="请输入帖子内容"
|
|
|
|
|
maxlength="500"
|
|
|
|
|
show-word-limit
|
|
|
|
|
/>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
|
|
<el-form-item label="表情">
|
|
|
|
|
<V3Emoji
|
|
|
|
|
:options-name="optionsName"
|
|
|
|
|
@click-emoji="onEmojiClick"
|
|
|
|
|
:recent="true"
|
|
|
|
|
/>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
|
|
<el-form-item label="图片">
|
|
|
|
|
<Upload v-model="imageIds" :limit="9" :isImg="true" :isAll="true" />
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<template #footer>
|
|
|
|
|
<el-button @click="handleClose">取消</el-button>
|
|
|
|
|
<el-button type="primary" @click="handleSubmit" :loading="submitting">
|
|
|
|
|
发布
|
|
|
|
|
</el-button>
|
|
|
|
|
</template>
|
|
|
|
|
</el-dialog>
|
2026-03-24 12:18:39 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2026-03-29 19:46:50 +08:00
|
|
|
import { ref, watch } from "vue";
|
|
|
|
|
import { ElMessage } from "element-plus";
|
|
|
|
|
import V3Emoji from "vue3-emoji";
|
|
|
|
|
import { tbGsxtXxltSave } from "@/api/tbGsxtXxltHf";
|
|
|
|
|
import { getItem } from "@/utils/storage.js";
|
|
|
|
|
import Upload from "@/components/MyComponents/Upload/index.vue";
|
2026-03-24 12:18:39 +08:00
|
|
|
|
|
|
|
|
const optionsName = {
|
2026-03-29 19:46:50 +08:00
|
|
|
"Smileys & Emotion": "笑脸&表情",
|
|
|
|
|
"Food & Drink": "食物&饮料",
|
|
|
|
|
"Animals & Nature": "动物&自然",
|
|
|
|
|
"Travel & Places": "旅行&地点",
|
|
|
|
|
"People & Body": "人物&身体",
|
|
|
|
|
Objects: "物品",
|
|
|
|
|
Symbols: "符号",
|
|
|
|
|
Flags: "旗帜",
|
|
|
|
|
Activities: "活动"
|
|
|
|
|
};
|
2026-03-24 12:18:39 +08:00
|
|
|
|
|
|
|
|
const props = defineProps({
|
2026-03-29 19:46:50 +08:00
|
|
|
modelValue: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false
|
|
|
|
|
}
|
|
|
|
|
});
|
2026-03-24 12:18:39 +08:00
|
|
|
|
2026-03-29 19:46:50 +08:00
|
|
|
const emit = defineEmits(["update:modelValue", "success"]);
|
2026-03-24 12:18:39 +08:00
|
|
|
|
2026-03-29 19:46:50 +08:00
|
|
|
const dialogVisible = ref(false);
|
|
|
|
|
const formRef = ref();
|
|
|
|
|
const submitting = ref(false);
|
|
|
|
|
const imageIds = ref([]);
|
2026-03-24 12:18:39 +08:00
|
|
|
|
|
|
|
|
const form = ref({
|
2026-03-29 19:46:50 +08:00
|
|
|
title: "",
|
|
|
|
|
content: ""
|
|
|
|
|
});
|
2026-03-24 12:18:39 +08:00
|
|
|
|
|
|
|
|
const rules = {
|
2026-03-29 19:46:50 +08:00
|
|
|
title: [{ required: true, message: "请输入标题", trigger: "blur" }],
|
|
|
|
|
content: [{ required: true, message: "请输入内容", trigger: "blur" }]
|
|
|
|
|
};
|
2026-03-24 12:18:39 +08:00
|
|
|
|
2026-03-29 19:46:50 +08:00
|
|
|
watch(
|
|
|
|
|
() => props.modelValue,
|
|
|
|
|
(val) => {
|
|
|
|
|
dialogVisible.value = val;
|
|
|
|
|
}
|
|
|
|
|
);
|
2026-03-24 12:18:39 +08:00
|
|
|
|
|
|
|
|
watch(dialogVisible, (val) => {
|
2026-03-29 19:46:50 +08:00
|
|
|
emit("update:modelValue", val);
|
|
|
|
|
if (!val) {
|
|
|
|
|
resetForm();
|
|
|
|
|
}
|
|
|
|
|
});
|
2026-03-24 12:18:39 +08:00
|
|
|
|
|
|
|
|
const onEmojiClick = (emoji) => {
|
2026-03-29 19:46:50 +08:00
|
|
|
form.value.content += emoji;
|
|
|
|
|
};
|
2026-03-24 12:18:39 +08:00
|
|
|
|
|
|
|
|
const handleClose = () => {
|
2026-03-29 19:46:50 +08:00
|
|
|
dialogVisible.value = false;
|
|
|
|
|
};
|
2026-03-24 12:18:39 +08:00
|
|
|
|
|
|
|
|
const handleSubmit = async () => {
|
2026-03-29 19:46:50 +08:00
|
|
|
if (!formRef.value) return;
|
|
|
|
|
|
|
|
|
|
await formRef.value.validate(async (valid) => {
|
|
|
|
|
if (valid) {
|
|
|
|
|
submitting.value = true;
|
|
|
|
|
try {
|
|
|
|
|
const ltmasg = getItem("ltmasg");
|
|
|
|
|
|
|
|
|
|
const postData = {
|
|
|
|
|
title: form.value.title,
|
|
|
|
|
content: form.value.content,
|
|
|
|
|
tp: imageIds.value.join(","),
|
|
|
|
|
fbrsfzh: ltmasg?.sfzh || "",
|
|
|
|
|
fbrxm: ltmasg?.xm || "",
|
|
|
|
|
fbrtx: ltmasg?.tx || ""
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await tbGsxtXxltSave(postData);
|
|
|
|
|
|
|
|
|
|
ElMessage.success("发布成功");
|
|
|
|
|
emit("success");
|
|
|
|
|
handleClose();
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("发布失败", error);
|
|
|
|
|
ElMessage.error("发布失败");
|
|
|
|
|
} finally {
|
|
|
|
|
submitting.value = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
2026-03-24 12:18:39 +08:00
|
|
|
|
|
|
|
|
const resetForm = () => {
|
2026-03-29 19:46:50 +08:00
|
|
|
form.value = {
|
|
|
|
|
title: "",
|
|
|
|
|
content: ""
|
|
|
|
|
};
|
|
|
|
|
imageIds.value = [];
|
|
|
|
|
formRef.value?.resetFields();
|
|
|
|
|
};
|
2026-03-24 12:18:39 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
2026-03-29 19:46:50 +08:00
|
|
|
// Upload 等子组件样式在各自内部
|
|
|
|
|
::v-deep .form-item-box {
|
|
|
|
|
width: 100% !important;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
|
@import "../styles/luntan-dialog-tech.scss";
|
|
|
|
|
</style>
|