import BaseServer from '../BaseServer'
import { Zondy } from '../../base'
/**
* 安全服务,服务地址:/igs/rest/services/SecurityServer
* @class SecurityServer
* @moduleEx ServiceModule
* @extends BaseServer
* @param {Object} options 构造参数
* @param {String} [options.url = 无] 服务基地址
* @example
* //初始化SecurityServer服务对象
* // ES5引入方式
* const { SecurityServer } = Zondy.Service
* // ES6引入方式
* import { SecurityServer } from "@mapgis/webclient-common
* const securityServer = new SecurityServer({
* //服务地址
* url: "http://localhost:8089/igs/rest/services/SecurityServer",
* });
*/
class SecurityServer extends BaseServer {
constructor(options) {
super(options)
}
/**
* @function SecurityServer.prototype.addToken
* @description 添加token,后端接口:http:/igs/rest/services/SecurityServer/tokens
* @param options 查询参数
* @param {Function} [options.success = 无] 查询成功回调函数,若使用Promise方式则不必填写
* @param {Function} [options.failure = 无] 查询失败回调函数,若使用Promise方式则不必填写
* @param {String} [options.userName = 无] 用户名,必填
* @param {String} [options.password = 无] 密码,必填
* @param {String} [options.clientType = 无] 客户端ip或者referer
* @param {String} [options.clientInfo = 无] ip或referer的内容,referer内容为web应用的基地址
* @param {Number} [options.expirationTime = 无] 失效时长,单位秒,必填
* @return {Promise<Object>}
* @example
* //回调方式
* securityServer.addToken({
* userName:'admin',
* password:'sa.mapgis',
* expirationTime:2592000,
* method: Zondy.Enum.FetchMethod.post,
* success:function(result){
* console.log("请求成功:", result);
* }
* })
* //promise方式
* securityServer.addToken({
* userName:'admin',
* password:'sa.mapgis',
* expirationTime:2592000,
* }).then(function (result) {
* console.log('请求成功:', result);
* }).catch(function (result) {
* console.log('请求失败:', result);
* });
*/
addToken(options) {
// 设置PATH PARAMETERS校验
const checkPathOpts = {
userName: {
type: 'String'
}
}
// 设置QUERY PARAMETERS校验
const checkQueryOpts = {
password: {
type: 'String',
required: true
},
clientType: {
type: 'String'
},
clientInfo: {
type: 'String'
},
expirationTime: {
type: 'Number',
required: true
}
}
// 调用基类的查询信息方法
return this._queryByParameters(
options,
checkPathOpts,
checkQueryOpts,
// 拼装返回基地址
function (url, options) {
return `${url}/tokens?${options.userName}`
}
)
}
}
Zondy.Service.SecurityServer = SecurityServer
export default SecurityServer