feat: release

This commit is contained in:
zzc
2026-05-20 23:16:53 +08:00
parent 0143a08af7
commit 48c7cebac1
4 changed files with 142 additions and 26 deletions

View File

@@ -17,7 +17,7 @@
<view class="content-wrap">
<view class="topic-editor card-block">
<textarea
v-model="formData.topic"
v-model="formData.title"
class="topic-input"
maxlength="40"
placeholder="输入一个有争议的话题..."
@@ -34,10 +34,10 @@
/>
</view>
<view class="cover-card" :class="{ 'has-cover': formData.cover }" @tap="chooseCover">
<view class="cover-card" :class="{ 'has-cover': formData.coverUrl }" @tap="chooseCover">
<image
v-if="formData.cover"
:src="formData.cover"
v-if="formData.coverUrl"
:src="formData.coverUrl"
class="cover-image"
mode="aspectFill"
/>
@@ -50,12 +50,12 @@
<view class="category-group">
<view
v-for="category in categories"
:key="category"
:key="category.id"
class="category-chip"
:class="{ active: formData.category === category }"
@tap="formData.category = category"
:class="{ active: formData.categoryId === category.id }"
@tap="formData.categoryId = category.id"
>
{{ category }}
{{ category.title }}
</view>
</view>
@@ -158,20 +158,45 @@
<script setup>
import { reactive, ref } from "vue";
import { onLoad } from "@dcloudio/uni-app";
import { getStatusBarHeight } from "@/utils/system";
import { releaseTopic } from "@/api/release";
import { releaseTopic, fetchTopicCategories } from "@/api/release";
import { smartNavigateBack } from "@/utils/page";
import {
uploadImage,
} from "@/utils/common.js";
const statusBarHeight = ref(getStatusBarHeight() || 0);
const categories = ["历史", "数码", "城市", "景点", "动漫", "影视"];
const categories = ref([]);
const loadCategories = async () => {
try {
const res = await fetchTopicCategories();
// 假设返回结构为 { data: { list: [{ id: 1, title: '历史' }, ...] } }
// 或者直接是一个数组 [{ id: 1, title: '历史' }, ...]
// 根据实际返回结构调整
const list = res?.data?.list || res?.list || res || [];
categories.value = list;
// 如果存在分类且未选择,则默认选中第一个
if (categories.value.length > 0 && !formData.categoryId) {
formData.categoryId = categories.value[0].id;
}
} catch (error) {
console.error("获取分类失败:", error);
}
};
onLoad(() => {
loadCategories();
});
const formData = reactive({
topic: "",
title: "",
description: "",
cover: "",
category: "历史",
tags: ["历史", "皇帝"],
coverUrl: "",
categoryId: "",
allowComment: true,
allowPk: true,
anonymous: false,
@@ -186,12 +211,6 @@ const participants = ref([
desc: "一句话简介",
avatar: "",
},
{
id: 2,
name: "汉武帝",
desc: "开疆拓土,大汉盛世",
avatar: "https://api.dicebear.com/7.x/avataaars/svg?seed=hanwudi",
},
]);
const goBack = () => {
@@ -239,6 +258,22 @@ const chooseCover = () => {
});
};
const onAvatarSelect = async (url) => {
if (!url) return;
uni.showLoading({ title: "上传中...", mask: true });
try {
const imageUrl = await uploadImage(url);
formData.coverUrl = imageUrl;
uni.hideLoading();
} catch (e) {
uni.hideLoading();
uni.showToast({ title: e || "上传失败", icon: "none" });
console.error("Upload avatar error", e);
}
};
const chooseParticipantAvatar = (index) => {
uni.chooseImage({
count: 1,
@@ -294,14 +329,18 @@ const removeParticipant = (id) => {
};
const handleSubmit = async () => {
if (!formData.topic.trim()) {
if (!formData.title.trim()) {
uni.showToast({ title: '请输入话题', icon: 'none' });
return;
}
if (!formData.cover) {
if (!formData.coverUrl) {
uni.showToast({ title: '请上传封面图', icon: 'none' });
return;
}
if (!formData.categoryId) {
uni.showToast({ title: '请选择话题分类', icon: 'none' });
return;
}
// 检查是否有空的对象名称
const hasEmptyName = participants.value.some(p => !p.name.trim());
@@ -316,7 +355,7 @@ const handleSubmit = async () => {
...formData,
participants: participants.value,
};
console.log(11111, payload)
await releaseTopic(payload);
uni.hideLoading();