feat(P0): 替换全局Toast/Modal为uView组件,样式统一
This commit is contained in:
parent
2b6c8b4575
commit
0b09c9eed8
22
App.vue
22
App.vue
@ -1,3 +1,15 @@
|
||||
<script setup>
|
||||
// 全局注册u-toast组件
|
||||
import { useToast } from 'uview-plus'
|
||||
const toast = useToast()
|
||||
|
||||
// 挂载到全局
|
||||
uni.$u = {
|
||||
toast,
|
||||
showModal: useToast().showModal
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
onLaunch: function() {
|
||||
@ -12,6 +24,16 @@ export default {
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<view>
|
||||
<router-view />
|
||||
<!-- 全局toast组件 -->
|
||||
<u-toast ref="uToast" />
|
||||
<!-- 全局modal组件 -->
|
||||
<u-modal ref="uModal" />
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<style>
|
||||
/* 每个页面公共css */
|
||||
page {
|
||||
|
||||
@ -410,7 +410,7 @@ const fetchPortfolioData = async () => {
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取投资组合数据失败:', error);
|
||||
uni.showToast({ title: '加载失败,请重试', icon: 'none' });
|
||||
uni.$u.toast.error('加载失败,请重试');
|
||||
}
|
||||
};
|
||||
|
||||
@ -430,7 +430,7 @@ const fetchTransactions = async () => {
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取交易记录失败:', error);
|
||||
uni.showToast({ title: '加载交易记录失败', icon: 'none' });
|
||||
uni.$u.toast.error('加载交易记录失败');
|
||||
}
|
||||
};
|
||||
|
||||
@ -488,18 +488,18 @@ const resetTransactionForm = () => {
|
||||
const submitTransaction = async () => {
|
||||
// 表单验证
|
||||
if (!transactionForm.value.stockCode) {
|
||||
return uni.showToast({ title: transactionType.value === 'sell' ? '请选择要卖出的持仓' : '请输入股票代码', icon: 'none' });
|
||||
return uni.$u.toast.error(transactionType.value === 'sell' ? '请选择要卖出的持仓' : '请输入股票代码');
|
||||
}
|
||||
const amount = parseFloat(transactionForm.value.amount);
|
||||
if (!amount || amount <= 0) {
|
||||
return uni.showToast({ title: '请输入有效的数量', icon: 'none' });
|
||||
return uni.$u.toast.error('请输入有效的数量');
|
||||
}
|
||||
// 卖出时校验数量不超过持仓
|
||||
if (transactionType.value === 'sell' && amount > maxSellAmount.value) {
|
||||
return uni.showToast({ title: `卖出数量不能超过持仓数量 ${maxSellAmount.value}`, icon: 'none' });
|
||||
return uni.$u.toast.error(`卖出数量不能超过持仓数量 ${maxSellAmount.value}`);
|
||||
}
|
||||
if (!transactionForm.value.price || parseFloat(transactionForm.value.price) <= 0) {
|
||||
return uni.showToast({ title: '请输入有效的价格', icon: 'none' });
|
||||
return uni.$u.toast.error('请输入有效的价格');
|
||||
}
|
||||
|
||||
const transactionData = {
|
||||
@ -513,13 +513,12 @@ const submitTransaction = async () => {
|
||||
remark: transactionForm.value.remark
|
||||
};
|
||||
|
||||
uni.showLoading({ title: '提交中...' });
|
||||
uni.$u.toast.loading('提交中...');
|
||||
|
||||
try {
|
||||
const response = await api.assets.createTransaction(transactionData);
|
||||
if (response.code === 200) {
|
||||
uni.hideLoading();
|
||||
uni.showToast({ title: '交易提交成功', icon: 'success' });
|
||||
uni.$u.toast.success('交易提交成功');
|
||||
showTransactionForm.value = false;
|
||||
|
||||
// 重新获取交易记录
|
||||
@ -529,19 +528,20 @@ const submitTransaction = async () => {
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('创建交易失败:', error);
|
||||
uni.hideLoading();
|
||||
uni.showToast({ title: '提交失败,请重试', icon: 'none' });
|
||||
uni.$u.toast.error('提交失败,请重试');
|
||||
}
|
||||
};
|
||||
|
||||
// 删除组合
|
||||
const deletePortfolio = async () => {
|
||||
uni.showModal({
|
||||
uni.$u.showModal({
|
||||
title: '确认删除',
|
||||
content: '删除后所有持仓和交易记录都会丢失,确定要删除这个组合吗?',
|
||||
confirmText: '删除',
|
||||
confirmColor: '#EF4444',
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
uni.showLoading({ title: '删除中' });
|
||||
uni.$u.toast.loading('删除中');
|
||||
try {
|
||||
// 调用删除组合接口
|
||||
const response = await uni.request({
|
||||
@ -553,15 +553,13 @@ const deletePortfolio = async () => {
|
||||
});
|
||||
|
||||
if (response.statusCode === 200) {
|
||||
uni.hideLoading();
|
||||
uni.showToast({ title: '删除成功', icon: 'success' });
|
||||
uni.$u.toast.success('删除成功');
|
||||
setTimeout(() => uni.switchTab({ url: '/pages/index/index' }), 1500);
|
||||
} else {
|
||||
throw new Error('删除失败');
|
||||
}
|
||||
} catch (error) {
|
||||
uni.hideLoading();
|
||||
uni.showToast({ title: '删除失败,请重试', icon: 'none' });
|
||||
uni.$u.toast.error('删除失败,请重试');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -199,7 +199,7 @@ const requestWithRetry = async (url, method = 'GET', data = {}, headers = {}, re
|
||||
return await requestWithRetry(url, method, data, headers, retryCount + 1);
|
||||
} else {
|
||||
console.error('❌ 达到最大重试次数');
|
||||
uni.showToast({ title: '系统异常,请稍后重试', icon: 'none', duration: 2000 });
|
||||
uni.$u.toast.error('系统异常,请稍后重试');
|
||||
throw new Error('登录已过期,重试次数超限');
|
||||
}
|
||||
} else {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user