类名 common/service/Config.js
import { Zondy } from '../base'
/**
 * 全局配置信息<br/>
 * 示例如下:<br/>
 * <a href='#config1'>[1、设置全局token]</a><br/>
 * <a href='#config2'>[2、设置全局headers]</a><br/>
 * <a href='#config3'>[3、设置拦截器 - 在所有链接上设置拦截器]</a><br/>
 * <a href='#config4'>[4、设置拦截器 - 指定拦截器应用的url]</a><br/>
 * @class Config
 * @moduleEx ServiceModule
 * @param {Object} options 构造参数
 * @param {String} [options.tokenKey = 'token'] 设置全局token名,设置后,所有由基础库和插件库发出的请求链接都会带有该token
 * @param {String} [options.tokenValue = null] token值
 * @param {Object} [options.headers = {}] 请求头信息,设置后,所有由基础库发出的链接都会带有该请求头
 * @param {RequestConfig} [options.request = {}] 请求配置参数
 * @example <caption><h5 id='config1'>设置全局token</h5></caption>
 * // ES5引入方式
 * const { Config } = Zondy.Service
 * // ES6引入方式
 * import { Config } from "@mapgis/webclient-common
 * // 设置token名,如果不设置就默认维token
 * Config.tokenKey = '新token名'
 * // 设置token值,设置完毕后,所有由基础库和插件库发出的请求链接都会带有该token
 * Config.tokenValue = '新token值'
 *
 * @example <caption><h5 id='config2'>设置全局headers</h5></caption>
 * // ES5引入方式
 * const { Config } = Zondy.Service
 * // ES6引入方式
 * import { Config } from "@mapgis/webclient-common
 * // 设置请求头,设置后,所有由基础库发出的链接都会带有该请求头
 * Config.headers = {
 *   'Authorization': 'XXXXXXX'
 * }
 *
 * @example <caption><h5 id='config3'>设置拦截器 - 在所有链接上设置拦截器</h5></caption>
 * // ES5引入方式
 * const { Config } = Zondy.Service
 * // ES6引入方式
 * import { Config } from "@mapgis/webclient-common
 * // 当urls为''或undefined或者空数组时,设置的拦截器会应用到所有发送的请求上
 * Config.request.interceptors.push({
 *   // 确保urls为''或undefined或者空数组
 *   urls: [],
 *   // 设置请求发送前的拦截函数
 *   before: function (url) {
 *     // 做你的业务
 *     // 注意如果要影响请求链接,则要返回url
 *     return url
 *   },
 *   // 设置请求完成后的拦截函数
 *   after: function (response) {
 *     console.log("response:", response)
 *   }
 * })
 *
 * @example <caption><h5 id='config4'>设置拦截器 - 指定拦截器应用的url</h5></caption>
 * // ES5引入方式
 * const { Config } = Zondy.Service
 * // ES6引入方式
 * import { Config } from "@mapgis/webclient-common
 * // 指定要拦截的url
 * Config.request.interceptors.push({
 *   // 指定要拦截的url,可以指定一个或多个
 *   // 指定一个url
 *   // urls: url1,
 *   // 指定多个url
 *   urls: ['url1', 'url2'],
 *   // 设置请求发送前的拦截函数
 *   before: function (url) {
 *     // 做你的业务
 *     // 注意如果要影响请求链接,则要返回url
 *     return url
 *   },
 *   // 设置请求完成后的拦截函数
 *   after: function (response) {
 *     console.log("response:", response)
 *   }
 * },{
 *   // 指定要拦截的url,可以指定一个或多个
 *   // 指定一个url
 *   // urls: url3,
 *   // 指定多个url
 *   urls: ['url3', 'url4'],
 *   // 设置请求发送前的拦截函数
 *   before: function (url) {
 *     // 做你的业务
 *     // 注意如果要影响请求链接,则要返回url
 *     return url
 *   },
 *   // 设置请求完成后的拦截函数
 *   after: function (response) {
 *     console.log("response:", response)
 *   }
 * })
 */
const Config = {
  tokenKey: 'token',
  tokenValue: undefined,
  headers: {},
  request: {
    interceptors: []
  }
}
Zondy.Service.Config = Config
export default Config
构造函数
成员变量
方法
事件