From 39e67894ee9748505aaef2205541d41bf2e1670c Mon Sep 17 00:00:00 2001 From: yangzhe Date: Tue, 15 Jul 2025 15:31:56 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BB=A5=E6=94=AF=E6=8C=81=E5=8F=AF=E9=80=89?= =?UTF-8?q?=E7=9A=84loading=E6=98=BE=E7=A4=BA=EF=BC=8C=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=BD=93=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/http.api.js | 2 +- uview-ui/libs/request/index.js | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/common/http.api.js b/common/http.api.js index b0758b2..50f0720 100644 --- a/common/http.api.js +++ b/common/http.api.js @@ -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); // 获取对话详情 diff --git a/uview-ui/libs/request/index.js b/uview-ui/libs/request/index.js index 8bf38b0..cdd50f7 100644 --- a/uview-ui/libs/request/index.js +++ b/uview-ui/libs/request/index.js @@ -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, // 定时器