pull/70/head
q18idc 4 years ago
parent dd66424a34
commit 93ae63d6cc

@ -1,10 +1,13 @@
package cn.stylefeng.guns.modular.business.controller; package cn.stylefeng.guns.modular.business.controller;
import cn.hutool.core.lang.Dict;
import cn.stylefeng.guns.modular.business.service.DemoService; import cn.stylefeng.guns.modular.business.service.DemoService;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData; import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData; import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource; import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource; import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -34,4 +37,18 @@ public class DemoController {
return new SuccessResponseData(); return new SuccessResponseData();
} }
/**
*
* <p>
* requiredEncryption = true
* </p>
*
* @author fengshuonan
* @date 2021/1/24 10:59
*/
@PostResource(name = "示例加密方法", path = "/encode", requiredPermission = false, requiredLogin = false, requiredEncryption = true)
public ResponseData encode(@RequestBody Dict dict) {
return new SuccessResponseData(dict);
}
} }

@ -149,6 +149,7 @@ layui.config({
iconPicker: '../../expand/module/iconPicker/iconPicker', iconPicker: '../../expand/module/iconPicker/iconPicker',
ztree: '../../expand/module/ztree/ztree-object', ztree: '../../expand/module/ztree/ztree-object',
HttpRequest: '../../expand/module/HttpRequest/HttpRequest', HttpRequest: '../../expand/module/HttpRequest/HttpRequest',
HttpEncryptionRequest: '../../expand/module/HttpRequest/HttpEncryptionRequest',
func: '../../expand/module/func/func', func: '../../expand/module/func/func',
dict: '../../expand/module/dict/dict', dict: '../../expand/module/dict/dict',
gunsSelect: '../../expand/module/gunsSelect/gunsSelect', gunsSelect: '../../expand/module/gunsSelect/gunsSelect',

@ -0,0 +1,168 @@
/**
* httpajax
* @author fengshuonan
*/
layui.define(['jquery'], function (exports) {
var $ = layui.$;
/**
* ajax
*
* @param url url
* @param method httpgetpost
* @param successCallback
* @param errorCallback http500
*
* 使
*
* var request = new HttpEncryptionRequest('/user/list', 'get', function(data){
* // ...
* }, function(){
* // ...
* });
* request.start();
*/
var HttpEncryptionRequest = function (url, method, successCallback, errorCallback) {
// 请求的url一般传参时候需要带上contextPath
this.url = url;
// http请求的方法默认不传为post一般传 'get' 或 'post'
if (method === "" || method == null) {
this.method = "post";
} else {
this.method = method;
}
// 请求成功的回调
this.successCallback = successCallback;
// 请求失败的回调
this.errorCallback = errorCallback;
// 请求的数据
this.dataObject = {};
// 请求的content-type默认 "application/json"
this.contentType = "application/json";
// 预期服务器返回的数据类型,默认都为 json
this.dataType = "json";
// 默认请求都是同步,不开启异步
this.async = false;
};
HttpEncryptionRequest.prototype = {
/**
* http
*
* @param parseJsonFlag json true
*/
start: function (parseJsonFlag) {
var me = this;
var result = "";
// 如果请求需要转化为json则将data转为json
if (parseJsonFlag === true) {
me.dataObject = JSON.stringify(me.dataObject);
}
// 防止http请求缓存
if (this.url.indexOf("?") === -1) {
this.url = this.url + "?jstime=" + new Date().getTime();
} else {
this.url = this.url + "&jstime=" + new Date().getTime();
}
console.log(me.dataObject)
// 生成解密返回数据的key
// 初始化ajax
$.ajax({
type: me.method,
url: me.url,
contentType: me.contentType,
dataType: me.dataType,
async: me.async,
data: me.dataObject,
beforeSend: function (data) {
},
success: function (data) {
result = data;
if (me.successCallback !== undefined) {
me.successCallback(data);
}
},
error: function (xhr) {
if (me.errorCallback !== undefined) {
me.errorCallback(xhr.responseJSON);
}
}
});
return result;
},
/**
* key-value
*
* paramjson setJsonData(data)
*
* keykeyobjectobjectset
*
* @param key key
* @param value
*/
set: function (key, value) {
if (typeof key === "object") {
// 遍历object的属性
for (var item in key) {
if (typeof item != "function") {
this.dataObject[item] = key[item];
}
}
} else {
this.dataObject[key] = (typeof value === "undefined") ? $("#" + key).val() : value;
}
return this;
},
/**
*
*/
clear: function () {
this.dataObject = {};
return this;
},
/**
* content-type
*/
setContentType: function (contentType) {
this.contentType = contentType;
return this;
},
/**
* json
*/
setDataType: function (dataType) {
this.dataType = dataType;
return this;
},
/**
* true-false-
*/
setAsync: function (async) {
this.async = async;
return this;
}
};
exports('HttpEncryptionRequest', HttpEncryptionRequest);
});
Loading…
Cancel
Save