fuint-uniapp-master/utils/request/index.js

(开头部分) 5KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

/**
 * request插件地址:https://ext.dcloud.net.cn/plugin?id=822
 */
import store from '@/store'
import request from './request'
import config from '@/config'

// 后端api地址
const baseURL = config.apiUrl

// 可以new多个request来支持多个域名请求
const $http = new request({
  // 接口请求地址
  baseUrl: baseURL,
  // 服务器本地上传文件地址
  fileUrl: baseURL,
  // 服务器上传图片默认url
  defaultUploadUrl: 'upload/image',
  // 设置请求头(如果使用报错跨域问题,可能是content-type请求类型和后台那边设置的不一致)
  header: {
    'content-type': 'application/json;charset=utf-8'
  },
  // 请求超时时间, 单位ms(默认300000)
  timeout: 300000,
  // 默认配置(可不写)
  config: {
    // 是否自动提示错误
    isPrompt: true,
    // 是否显示加载动画
    load: true,
    // 是否使用数据工厂
    isFactory: true
  }
})

// 当前接口请求数
let requestNum = 0
// 请求开始拦截器
$http.requestStart = options => {
  if (options.load) {
    if (requestNum <= 0) {
      // 打开加载动画
      uni.showLoading({
        title: '加载中',
        mask: true
      })
    }
    requestNum += 1
  }
  // 图片上传大小限制
  if (options.method == "FILE" && options.maxSize) {
    // 文件最大字节: options.maxSize 可以在调用方法的时候加入参数
    const maxSize = options.maxSize
    for (let item of options.files) {
      if (item.size > maxSize) {
        setTimeout(() => {
          uni.showToast({
            title: "图片过大,请重新上传",
            icon: "none"
          })
后面还有 140 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。