feat: 修改请求接口以支持可选的loading显示,优化用户体验

This commit is contained in:
yangzhe 2025-07-15 15:31:56 +08:00
parent da1e52aba5
commit 39e67894ee
2 changed files with 6 additions and 3 deletions

View File

@ -92,7 +92,7 @@ const install = (Vue, vm) => {
/** 首页ai对话 */
// 发送消息
let SendMessageApi = (params = {}) => vm.$u.post('api/ChatAI/CreateChat', params);
let SendMessageApi = (params = {}) => vm.$u.post('api/ChatAI/CreateChat', params, {showLoading: false});
// 获取历史对话列表
let GetConversationPage = (params = {}) => vm.$u.get('api/ChatAI/GetConversationPage', params);
// 获取对话详情

View File

@ -26,6 +26,9 @@ class Request {
options.header = Object.assign({}, this.config.header, options.header);
options.method = options.method || this.config.method;
// 从请求选项中获取showLoading参数如果未定义则使用全局配置
const showLoading = options.header.showLoading !== undefined ? options.header.showLoading : this.config.showLoading;
return new Promise((resolve, reject) => {
options.complete = (response) => {
// 请求返回后隐藏loading(如果请求返回快的话可能会没有loading)
@ -81,7 +84,7 @@ class Request {
// 是否显示loading
// 加一个是否已有timer定时器的判断否则有两个同时请求的时候后者会清除前者的定时器id
// 而没有清除前者的定时器导致前者超时一直显示loading
if(this.config.showLoading && !this.config.timer) {
if(showLoading && !this.config.timer) {
this.config.timer = setTimeout(() => {
uni.showLoading({
title: this.config.loadingText,
@ -109,7 +112,7 @@ class Request {
dataType: 'json',
// 此参数无需处理因为5+和支付宝小程序不支持默认为text即可
responseType: 'text',
showLoading: false, // 是否显示请求中的loading
showLoading: true, // 是否显示请求中的loading
loadingText: '请求中...',
loadingTime: 800, // 在此时间内请求还没回来的话就显示加载中动画单位ms
timer: null, // 定时器