specification.md 3.45 KB

示例axios配置

以下是本演示项目中main.js的片段截取

import axios from 'axios';

const request = axios.create({
  baseURL: 'http://localhost',
  timeout: 1000 * 60,
  withCredentials: true,
});

// respone 拦截器
request.interceptors.response.use(
  response => {
    const { data = {}, config } = response;
    const { code = 0 } = data;
    if (config && config.interceptors === false) { // 请求配置不做返回拦截的情况
      return response;
    } else {
      if (`${code}` === '0' || `${code}` === '200') { // 请求成功
        return data;
      } else { // 其它错误,开发环境提示
        return { code };
      }
    }
  },
  error => {
    return { code: 404 };
  });

Vue.prototype.$axios = request;

Scheme默认逻辑

  • 查询列表

传入$http时,如果没有配置searchAPI,则按照以下规则处理:

默认路径

option.searchMethod 或者默认为 /page

处理规则

(response) => {
  const { result = {} } = response || {};
  const { list = [] } = result || {};
  this.tableData = list;
  this.totalCount = result[totalCountAlias] || 0;
}
  • 查询数据

传入$http时,如果没有配置getAPI,则按照以下规则处理:

默认路径

option.getMethod/${id} 或者默认为 /id/${id}

处理规则

(response) => {
  const { result = {} } = response || {};
  this.setFormModel(result);
}
  • 查询详情

传入$http时,如果没有配置detailAPI,则按照以下规则处理:

默认路径

option.detailMethod/${id} 或者默认为 /info/${id}

处理规则

(response) => {
  const { result = {} } = response || {};
  this.setFormModel(result);
}
  • 新增保存

传入$http时,如果没有配置newMethod,则按照以下规则处理:

默认路径

option.newMethod 或者默认为 /add

处理规则

(response) => {
  const { code } = response || {};
  if (`${code}` === '0') {
    // ...
  }
}
  • 编辑保存

传入$http时,如果没有配置editMethod,则按照以下规则处理:

默认路径

option.editMethod 或者默认为 /update

处理规则

(response) => {
  const { code } = response || {};
  if (`${code}` === '0') {
    // ...
  }
}
  • 删除/批量删除

传入$http时,如果没有配置deleteMethod,则按照以下规则处理:

默认路径

option.deleteMethod 或者默认为 /delete

处理规则

(response) => {
  const { code } = response || {};
  if (`${code}` === '0') {
    // ...
  }
}

Scheme自定义API

使用方法见示例

  • searchAPI 查询列表
(param) => { // param 包含分页的搜索条件
  return { result, totalCount }; // result 数据源 Object类型; totalCount 总数 Number类型
}
  • detailAPI 查询详情
(param) => { // param 当前行数据
  return result; // result 查询结果 Object类型
}
  • getAPI 编辑查询数据
(param) => { // param 当前行数据
  return result; // result 查询结果 Object类型
}
  • deleteAPI 删除
(selection) => { // selection 选中的数据
  return result; // result 是否执行成功 Boolean类型
}
  • newAPI 新增保存
(model) => { // model 表单数据
  return result; // result 是否执行成功 Boolean类型
}
  • editAPI 编辑保存
(model) => { // model 表单数据
  return result; // result 是否执行成功 Boolean类型
}