@mapgis/webclient-common
Version:
mapgis ES6 format for igserver
435 lines (184 loc) • 6.71 kB
HTML
<header id="page-title" class="page-title">
<span class="page-title-main">类名</span>
<span class="page-title-sub">Config</span>
</header>
<section>
<article>
<div class="container-overview">
<div class='vertical-section'>
<div class="members">
<div class="member">
<h4 class="name" id="Config">
<a class="href-link" href="#Config">#</a>
<span class="code-name" id="Config" style="font-size:30px">
new Config<span class="signature">(options)</span>
</span>
</h4>
<div class="description">
<p>全局配置信息<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/></p>
</div>
<h4>参数</h4>
<div class="table-container">
<table class="params table">
<thead>
<tr>
<th>名称</th>
<th>类型</th>
<th style="min-width: 100px;">默认值</th>
<th class="last">描述</th>
</tr>
</thead>
<tbody>
<tr class="deep-level-0">
<td class="name"><code>options</code></td>
<td class="type">
<span class="param-type">
Object
</span>
</td>
<td class="default">
</td>
<td class="description last"><p>构造参数</p></td>
</tr>
<tr class="deep-level-1">
<td class="name"><code>tokenKey</code></td>
<td class="type">
<span class="param-type">
String
</span>
</td>
<td class="default">
'token'
</td>
<td class="description last"><p>设置全局token名,设置后,所有由基础库和插件库发出的请求链接都会带有该token</p></td>
</tr>
<tr class="deep-level-1">
<td class="name"><code>tokenValue</code></td>
<td class="type">
<span class="param-type">
String
</span>
</td>
<td class="default">
null
</td>
<td class="description last"><p>token值</p></td>
</tr>
<tr class="deep-level-1">
<td class="name"><code>headers</code></td>
<td class="type">
<span class="param-type">
Object
</span>
</td>
<td class="default">
{}
</td>
<td class="description last"><p>请求头信息,设置后,所有由基础库发出的链接都会带有该请求头</p></td>
</tr>
<tr class="deep-level-1">
<td class="name"><code>request</code></td>
<td class="type">
<span class="param-type">
<a link="RequestConfig.html" onclick="getTypeHTML(event)" href="RequestConfig.html">RequestConfig</a>
</span>
</td>
<td class="default">
{}
</td>
<td class="description last"><p>请求配置参数</p></td>
</tr>
</tbody>
</table>
</div>
<dl class="details">
</dl>
<h5>示例</h5>
<p class="code-caption"><h5 id='config1'>设置全局token</h5></p>
<pre class="prettyprint"><code>// ES5引入方式
const { Config } = zondy.service
// ES6引入方式
import { Config } from "@mapgis/webclient-common
// 设置token名,如果不设置就默认维token
Config.tokenKey = '新token名'
// 设置token值,设置完毕后,所有由基础库和插件库发出的请求链接都会带有该token
Config.tokenValue = '新token值'</code></pre>
<p class="code-caption"><h5 id='config2'>设置全局headers</h5></p>
<pre class="prettyprint"><code>// ES5引入方式
const { Config } = zondy.service
// ES6引入方式
import { Config } from "@mapgis/webclient-common
// 设置请求头,设置后,所有由基础库发出的链接都会带有该请求头
Config.headers = {
'Authorization': 'XXXXXXX'
}</code></pre>
<p class="code-caption"><h5 id='config3'>设置拦截器 - 在所有链接上设置拦截器</h5></p>
<pre class="prettyprint"><code>// 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)
}
})</code></pre>
<p class="code-caption"><h5 id='config4'>设置拦截器 - 指定拦截器应用的url</h5></p>
<pre class="prettyprint"><code>// 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)
}
})</code></pre>
</div>
</div>
</div>
</div>
</article>
</section>