feat: 修改请求接口以支持可选的loading显示,优化用户体验
This commit is contained in:
parent
da1e52aba5
commit
39e67894ee
|
@ -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);
|
||||
// 获取对话详情
|
||||
|
|
|
@ -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, // 定时器
|
||||
|
|
Loading…
Reference in New Issue