feat: release
This commit is contained in:
9
api/release.js
Normal file
9
api/release.js
Normal file
@@ -0,0 +1,9 @@
|
||||
import { request } from "@/utils/request.js";
|
||||
|
||||
export const releaseTopic = async (data) => {
|
||||
return request({
|
||||
url: "/api/rating/topic/release",
|
||||
method: "POST",
|
||||
data,
|
||||
});
|
||||
};
|
||||
@@ -159,6 +159,8 @@
|
||||
<script setup>
|
||||
import { reactive, ref } from "vue";
|
||||
import { getStatusBarHeight } from "@/utils/system";
|
||||
import { releaseTopic } from "@/api/release";
|
||||
import { smartNavigateBack } from "@/utils/page";
|
||||
|
||||
const statusBarHeight = ref(getStatusBarHeight() || 0);
|
||||
|
||||
@@ -193,9 +195,7 @@ const participants = ref([
|
||||
]);
|
||||
|
||||
const goBack = () => {
|
||||
uni.navigateBack({
|
||||
delta: 1,
|
||||
});
|
||||
smartNavigateBack();
|
||||
};
|
||||
|
||||
const handlePreview = () => {
|
||||
@@ -293,7 +293,7 @@ const removeParticipant = (id) => {
|
||||
participants.value = participants.value.filter((item) => item.id !== id);
|
||||
};
|
||||
|
||||
const handleSubmit = () => {
|
||||
const handleSubmit = async () => {
|
||||
if (!formData.topic.trim()) {
|
||||
uni.showToast({ title: '请输入话题', icon: 'none' });
|
||||
return;
|
||||
@@ -311,16 +311,29 @@ const handleSubmit = () => {
|
||||
}
|
||||
|
||||
uni.showLoading({ title: '发布中...' });
|
||||
setTimeout(() => {
|
||||
try {
|
||||
const payload = {
|
||||
...formData,
|
||||
participants: participants.value,
|
||||
};
|
||||
|
||||
await releaseTopic(payload);
|
||||
|
||||
uni.hideLoading();
|
||||
uni.showToast({
|
||||
title: "发布成功",
|
||||
icon: "success",
|
||||
});
|
||||
setTimeout(() => {
|
||||
uni.navigateBack();
|
||||
}, 1500);
|
||||
}, 1000);
|
||||
|
||||
smartNavigateBack({ delay: 1500 });
|
||||
} catch (error) {
|
||||
uni.hideLoading();
|
||||
uni.showToast({
|
||||
title: "发布失败,请重试",
|
||||
icon: "none",
|
||||
});
|
||||
console.error("发布失败:", error);
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
|
||||
41
utils/page.js
Normal file
41
utils/page.js
Normal file
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* 页面跳转相关工具方法
|
||||
*/
|
||||
|
||||
/**
|
||||
* 智能返回方法:默认返回上一页,如果页面栈只有1层(没有上一页),则返回到首页
|
||||
*
|
||||
* @param {Object} options 配置参数
|
||||
* @param {number} options.delay 延迟执行的时间,单位毫秒,默认 0
|
||||
* @param {string} options.homePath 首页的路径,默认为 '/pages/index/index'
|
||||
*/
|
||||
export const smartNavigateBack = (options = {}) => {
|
||||
const { delay = 0, homePath = '/pages/index/index' } = options;
|
||||
|
||||
const executeBack = () => {
|
||||
const pages = getCurrentPages();
|
||||
if (pages.length > 1) {
|
||||
// 有上一页,直接返回
|
||||
uni.navigateBack({
|
||||
delta: 1
|
||||
});
|
||||
} else {
|
||||
// 页面栈只有一层,返回首页
|
||||
uni.switchTab({
|
||||
url: homePath,
|
||||
fail: () => {
|
||||
// 如果首页不是 tabBar 页面,则使用 reLaunch
|
||||
uni.reLaunch({
|
||||
url: homePath
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
if (delay > 0) {
|
||||
setTimeout(executeBack, delay);
|
||||
} else {
|
||||
executeBack();
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user