提交 149812de 编写于 作者: ibizdev's avatar ibizdev

zhouweidong@lab.ibiz5.com 发布系统代码

上级 ad2c69ca
## v7.0.0-alpha.9 [2020-6-11]
### Bug修复
数值代码表多语言
树右键菜单滚动条样式bug
列表面板界面行为bug
多选视图界面逻辑修复
图表刷新bug修复
日历部件选中抛出数据逻辑调整
编辑视图,app-span显示0时不显示
树视图右键界面行为刷新bug
快捷菜单控制台报错bug
门户加载自定义模型错误时,正常显示默认看板
修复雷达图显示异常问题
修复编辑类、分页导航视图带数据标题问题
修复饼图、漏斗图 获取序列参数错误问题
### 功能新增及优化
#### 模板
看板和门户布局模板调整,支持门户部件标题栏界面行为组
支持数据选择、地址框、自动完成、下拉列表、标签、选项框列表、单选列表等编辑器导航参数调整
支持树导航栏、表格导航栏、列表导航栏、卡片导航栏、日历导航栏、表单关系界面、数据选择面板、分页导航面板、数据关系栏、界面行为、新建逻辑、编辑逻辑导航参数调整
支持图表无数据时显示暂无数据
支持表格新建默认值
支持日历部件右键菜单
支持表格列触发界面行为
面板布局调整
#### 基础文件
门户部件视图的样式
数据选择,地址框,自动完成,下拉列表,标签,选项框列表,单选列表等编辑器导航参数调整
表单项label位置
调整登录页面
穿梭框编辑器支持
## v7.0.0-alpha.8 [2020-6-4]
### Bug修复
......
......@@ -17,3 +17,30 @@
padding: 0 0 10px;
}
}
.app-form-item-label-left{
.app-form-item-label{
float: left;
text-align: right;
padding-right: 12px;
}
}
.app-form-item-label-right{
.app-form-item-label{
float: right;
text-align: left;
padding-left: 12px;
}
}
.app-form-item-label-top{
.app-form-item-label{
display: block;
padding-bottom: 10px;
}
}
.app-form-item-label-bottom{
.app-form-item-label{
display: block;
padding-top: 10px;
}
}
\ No newline at end of file
......@@ -21,12 +21,16 @@
:error="error"
:required="required"
:rules="rules"
:class="classes"
:label-width="this.isShowCaption ? !Object.is(this.labelPos, 'TOP') ? this.labelWidth : null : 0">
<span slot='label' v-if="this.isShowCaption && this.labelWidth > 0" :class="labelclasses">
:class="classes">
<div v-if="Object.is(this.labelPos,'BOTTOM') || Object.is(this.labelPos,'NONE') || !this.labelPos" class="slot-editor" :style="slotstyle">
<slot></slot>
</div>
<span v-if="!Object.is(this.labelPos,'NONE') && this.isShowCaption && this.labelWidth > 0" :style="labelstyle" :class="labelclasses">
{{this.isEmptyCaption ? '' : this.caption}}
</span>
<div v-if="Object.is(this.labelPos,'TOP') || Object.is(this.labelPos,'LEFT') || Object.is(this.labelPos,'RIGHT')" class="slot-editor" :style="slotstyle">
<slot></slot>
</div>
</form-item>
</div>
</div>
......@@ -167,9 +171,27 @@ export default class AppFormItem extends Vue {
* @memberof AppFormItem
*/
get classes(): string[] {
let posClass = '';
switch (this.labelPos) {
case 'TOP':
posClass = 'app-form-item-label-top';
break;
case 'LEFT':
posClass = 'app-form-item-label-left';
break;
case 'BOTTOM':
posClass = 'app-form-item-label-bottom';
break;
case 'RIGHT':
posClass = 'app-form-item-label-right';
break;
case 'NONE':
posClass = 'app-form-item-label-none';
break;
}
return [
'app-form-item',
Object.is(this.labelPos, 'TOP') ? 'app-form-item-label-top' : ''
posClass
];
}
......@@ -181,7 +203,33 @@ export default class AppFormItem extends Vue {
* @memberof AppFormItem
*/
get labelclasses():string{
return this.labelStyle?this.labelStyle:'';
return this.labelStyle?this.labelStyle+' app-form-item-label':'app-form-item-label';
}
/**
* label行内样式
*
* @readonly
* @type {string}
* @memberof AppFormItem
*/
get labelstyle():any{
return {width:this.labelWidth+'px'};
}
/**
* slot行内样式
*
* @readonly
* @type {string}
* @memberof AppFormItem
*/
get slotstyle():any{
if(Object.is(this.labelPos,'LEFT')){
return {marginLeft:this.labelWidth+'px'};
}else if(Object.is(this.labelPos,'RIGHT')){
return {marginRight:this.labelWidth+'px'};
}
}
/**
......
......@@ -3,7 +3,7 @@
@on-open-change="transferRefresh"
@on-change="dataChange"
v-model="dataRight"
:style="{width:width}"
:style="{width:width===undefined?'586px':width}"
multiple
>
<Option class="hidden" :value="item" v-for="(item,i) in dataRight" :key="i">{{findLabel(item)}}</Option>
......@@ -17,7 +17,6 @@ import { ElSelect } from "element-ui/types/select";
@Component({})
export default class AppTransfer extends Vue {
/**
* 左侧框数据
*/
......@@ -31,7 +30,7 @@ export default class AppTransfer extends Vue {
/**
* 穿梭框宽度
*/
@Prop() public width:any;
@Prop() public width: any;
/**
* 代码表服务对象
......@@ -54,7 +53,7 @@ export default class AppTransfer extends Vue {
/**
* 表单传入字符串值分隔符
*/
@Prop() public valueSeparator?: string;
@Prop() public valueSeparator!: string;
/**
* 当前选中值
* @type {any}
......@@ -78,27 +77,48 @@ export default class AppTransfer extends Vue {
*/
@Prop() public codelistType?: string;
/**
* 局部上下文导航参数
*
* @type {*}
* @memberof AppTransfer
*/
@Prop() public localContext!: any;
/**
* 局部导航参数
*
* @type {*}
* @memberof AppTransfer
*/
@Prop() public localParam!: any;
/**
* 组件change事件,右侧框数据变化时
* @memberof AppTransfer
*/
dataChange(e: any) {
let _valueSeparator: any;
_valueSeparator = this.initValueSeparator(_valueSeparator);
let newVal: any;
newVal = e.join(`${this.valueSeparator}`);
newVal = e.join(`${_valueSeparator}`);
if (newVal) {
this.$emit("change", newVal);
} else {
this.$emit("change", null);
}
}
/**
* 传入额外参数
*
* @type {*}
* @memberof AppTransfer
* 初始化valueSeparator
*/
@Prop() public itemParam?: any;
public initValueSeparator(_valueSeparator: any) {
if (this.valueSeparator === undefined) {
return ",";
} else {
return this.valueSeparator;
}
}
/**
* 视图上下文
......@@ -187,6 +207,7 @@ export default class AppTransfer extends Vue {
* @returns
* @memberof AppTransfer
*/
public handlePublicParams(arg: any) {
// 合并表单参数
arg.param = this.viewparams
......@@ -194,19 +215,21 @@ export default class AppTransfer extends Vue {
: {};
arg.context = this.context ? JSON.parse(JSON.stringify(this.context)) : {};
// 附加参数处理
if (this.itemParam && this.itemParam.context) {
let _context = this.$util.formatData(
if (this.localContext && Object.keys(this.localContext).length > 0) {
let _context = this.$util.computedNavData(
this.itemValue,
arg.context,
this.itemParam.context
arg.param,
this.localContext
);
Object.assign(arg.context, _context);
}
if (this.itemParam && this.itemParam.param) {
let _param = this.$util.formatData(
if (this.localParam && Object.keys(this.localParam).length > 0) {
let _param = this.$util.computedNavData(
this.itemValue,
arg.context,
arg.param,
this.itemParam.param
this.localParam
);
Object.assign(arg.param, _param);
}
......@@ -222,7 +245,7 @@ export default class AppTransfer extends Vue {
this.dataLeft.push({
key: elem.id,
value: elem.value,
label: elem.label,
label: elem.text,
disabled: elem.disabled
});
});
......@@ -231,16 +254,20 @@ export default class AppTransfer extends Vue {
* 初始化右侧框数据
*/
public initRight() {
let _valueSeparator: any;
_valueSeparator = this.initValueSeparator(_valueSeparator);
let _data: any = this.itemValue;
if (_data) {
let newData: any[] = _data.split(`${this.valueSeparator}`);
let _dataRight: any = [];
let newData: any[] = _data.split(`${_valueSeparator}`);
this.dataLeft.forEach((elem: any) => {
newData.forEach((item: any) => {
if (item === elem.value) {
this.dataRight.push(elem.key);
_dataRight.push(elem.key);
}
});
});
this.dataRight = _dataRight;
}
}
/**
......@@ -249,7 +276,6 @@ export default class AppTransfer extends Vue {
public transferRefresh(e: any) {
if (e && this.codelistType === "DYNAMIC") {
this.dataLeft = [];
this.dataRight = [];
this.dataHandle();
}
}
......
......@@ -89,6 +89,7 @@ export default class EditView2Engine extends EditViewEngine {
*/
public onFormLoad(arg: any = {}): void {
super.onFormLoad(arg);
this.view.formData = arg;
if (this.getDRBar()) {
const tag = this.getDRBar().name;
this.setViewState2({ tag: tag, action: 'state', viewdata: this.view.vieparams });
......@@ -103,6 +104,7 @@ export default class EditView2Engine extends EditViewEngine {
*/
public onFormSave(arg: any = {}): void {
super.onFormSave(arg);
this.view.formData = arg;
if (this.getDRBar()) {
const tag = this.getDRBar().name;
this.setViewState2({ tag: tag, action: 'state', viewdata: this.view.viewparams });
......
......@@ -89,6 +89,7 @@ export default class EditView3Engine extends EditViewEngine {
*/
public onFormLoad(arg: any = {}): void {
super.onFormLoad(arg);
this.view.formData = arg;
if (this.getDrTab()) {
const tag = this.getDrTab().name;
this.setViewState2({ tag: tag, action: 'state', viewdata: this.view.viewparams });
......@@ -103,6 +104,7 @@ export default class EditView3Engine extends EditViewEngine {
*/
public onFormSave(arg: any = {}): void {
super.onFormSave(arg);
this.view.formData = arg;
if (this.getDrTab()) {
const tag = this.getDrTab().name;
this.setViewState2({ tag: tag, action: 'state', viewdata: this.view.viewparams });
......
......@@ -48,6 +48,7 @@
ref='drbar'
:viewparams="viewparams"
:context="context"
:formData="formData"
@selectionchange="drbar_selectionchange($event)"
@load="drbar_load($event)"
@closeview="closeView($event)">
......@@ -1032,6 +1033,14 @@ export default class SYS_PERMISSIONEditView2Base extends Vue {
*/
public selection: any = {};
/**
* 表单数据
*
* @type {*}
* @memberof SYS_PERMISSIONEditView2Base
*/
public formData:any = {};
}
</script>
......
......@@ -48,6 +48,7 @@
ref='drbar'
:viewparams="viewparams"
:context="context"
:formData="formData"
@selectionchange="drbar_selectionchange($event)"
@load="drbar_load($event)"
@closeview="closeView($event)">
......@@ -1032,6 +1033,14 @@ export default class SYS_ROLE_PERMISSIONEditView2Base extends Vue {
*/
public selection: any = {};
/**
* 表单数据
*
* @type {*}
* @memberof SYS_ROLE_PERMISSIONEditView2Base
*/
public formData:any = {};
}
</script>
......
......@@ -48,6 +48,7 @@
ref='drbar'
:viewparams="viewparams"
:context="context"
:formData="formData"
@selectionchange="drbar_selectionchange($event)"
@load="drbar_load($event)"
@closeview="closeView($event)">
......@@ -1032,6 +1033,14 @@ export default class SYS_ROLEEditView2Base extends Vue {
*/
public selection: any = {};
/**
* 表单数据
*
* @type {*}
* @memberof SYS_ROLEEditView2Base
*/
public formData:any = {};
}
</script>
......
......@@ -48,6 +48,7 @@
ref='drbar'
:viewparams="viewparams"
:context="context"
:formData="formData"
@selectionchange="drbar_selectionchange($event)"
@load="drbar_load($event)"
@closeview="closeView($event)">
......@@ -1032,6 +1033,14 @@ export default class SYS_USER_ROLEEditView2Base extends Vue {
*/
public selection: any = {};
/**
* 表单数据
*
* @type {*}
* @memberof SYS_USER_ROLEEditView2Base
*/
public formData:any = {};
}
</script>
......
......@@ -48,6 +48,7 @@
ref='drbar'
:viewparams="viewparams"
:context="context"
:formData="formData"
@selectionchange="drbar_selectionchange($event)"
@load="drbar_load($event)"
@closeview="closeView($event)">
......@@ -1032,6 +1033,14 @@ export default class SYS_USEREditView2Base extends Vue {
*/
public selection: any = {};
/**
* 表单数据
*
* @type {*}
* @memberof SYS_USEREditView2Base
*/
public formData:any = {};
}
</script>
......
......@@ -44,7 +44,7 @@ export class UIActionTool {
*/
private static formatData(actionTarget: any, args: any,parentContext:any,parentParams:any, _params: any): any {
let _data: any = {};
if (Object.is(actionTarget, 'SINGLEKEY')) {
if (Object.is(actionTarget, 'SINGLEKEY') || Object.is(actionTarget, 'NONE')) {
let [arg] = args;
Object.keys(_params).forEach((name: string) => {
let hasProperty = true;
......
......@@ -128,7 +128,7 @@ export class ViewTool {
const [{ pathName, parameterName }] = parameters;
routePath = `/${pathName}`;
if (Object.keys(data).length > 0) {
routePath = `${routePath}/${qs.stringify(data, { delimiter: ';' })}`;
routePath = `${routePath}?${qs.stringify(data, { delimiter: ';' })}`;
}
} else if (parameters.length === 2) {
let [arg] = args;
......@@ -138,7 +138,7 @@ export class ViewTool {
arg[_parameterName] : null;
routePath = `/${_pathName}/${_value}/${_pathName2}`;
if (Object.keys(data).length > 0) {
routePath = `${routePath}/${qs.stringify(data, { delimiter: ';' })}`;
routePath = `${routePath}?${qs.stringify(data, { delimiter: ';' })}`;
}
}
return routePath;
......
......@@ -1573,6 +1573,7 @@ export default class MainBase extends Vue implements ControlInterface {
*/
public uiAction(row: any, tag: any, $event: any) {
// this.rowClick(row, true);
$event.stopPropagation();
}
/**
......
......@@ -1389,6 +1389,7 @@ export default class MainBase extends Vue implements ControlInterface {
*/
public uiAction(row: any, tag: any, $event: any) {
// this.rowClick(row, true);
$event.stopPropagation();
}
/**
......
......@@ -151,6 +151,7 @@ export default class DefaultBase extends Vue implements ControlInterface {
}
/**
* 获取多项数据
*
......@@ -179,6 +180,14 @@ export default class DefaultBase extends Vue implements ControlInterface {
*/
@Prop() public loadAction?: string;
/**
* 表单数据
*
* @type {*}
* @memberof DefaultBase
*/
@Prop({default:{}}) public formData?:any;
/**
* 数据选中项
*
......@@ -201,6 +210,15 @@ export default class DefaultBase extends Vue implements ControlInterface {
},
];
/**
* 关系栏数据项导航参数集合
*
* @type {any[]}
* @memberof DefaultBase
*/
public navParamsArray:Array<any> = [
];
/**
* 默认打开项
*
......@@ -323,6 +341,36 @@ export default class DefaultBase extends Vue implements ControlInterface {
return item;
}
/**
* 初始化导航参数
*
* @param {*} drItem
* @memberof DefaultBase
*/
public initNavParam(drItem:any){
let returnNavParam:any = {};
if(drItem && drItem.id){
let curDRItem:any = this.navParamsArray.find((item:any) =>{
return Object.is(item.id,drItem.id);
})
if(curDRItem){
let localContext:any = curDRItem.localContext;
let localViewParam:any = curDRItem.localViewParam;
if(localContext && Object.keys(localContext).length >0){
let _context:any = this.$util.computedNavData(this.formData,this.context,this.viewparams,localContext);
returnNavParam.localContext = _context;
}
if(localViewParam && Object.keys(localViewParam).length >0){
let _params:any = this.$util.computedNavData(this.formData,this.context,this.viewparams,localViewParam);
returnNavParam.localViewParam = _params;
}
return returnNavParam;
}else{
return null;
}
}
}
/**
* 节点选中
*
......@@ -334,13 +382,18 @@ export default class DefaultBase extends Vue implements ControlInterface {
if (Object.is(item.id, this.selection.id)) {
return;
}
this.$emit('selectionchange', [item]);
let localNavParam:any = this.initNavParam(item);
const refview = this.getDRBarItem({ nodetype: item.id });
this.selection = {};
const _context: any = { ...JSON.parse(JSON.stringify(this.context)) };
const _params: any = { ...JSON.parse(JSON.stringify(this.viewparams)) };
if(localNavParam && localNavParam.localContext){
Object.assign(_context,localNavParam.localContext);
}
const _params: any = {};
if(localNavParam && localNavParam.localViewParam){
Object.assign(_params,localNavParam.localViewParam);
}
if (refview && refview.parentdatajo) {
Object.assign(_context, refview.parentdatajo);
Object.assign(this.selection, { view: { viewname: refview.viewname }, data: _context, param: _params });
......
......@@ -1251,6 +1251,7 @@ export default class MainBase extends Vue implements ControlInterface {
*/
public uiAction(row: any, tag: any, $event: any) {
// this.rowClick(row, true);
$event.stopPropagation();
}
/**
......
......@@ -151,6 +151,7 @@ export default class DefaultBase extends Vue implements ControlInterface {
}
/**
* 获取多项数据
*
......@@ -179,6 +180,14 @@ export default class DefaultBase extends Vue implements ControlInterface {
*/
@Prop() public loadAction?: string;
/**
* 表单数据
*
* @type {*}
* @memberof DefaultBase
*/
@Prop({default:{}}) public formData?:any;
/**
* 数据选中项
*
......@@ -201,6 +210,15 @@ export default class DefaultBase extends Vue implements ControlInterface {
},
];
/**
* 关系栏数据项导航参数集合
*
* @type {any[]}
* @memberof DefaultBase
*/
public navParamsArray:Array<any> = [
];
/**
* 默认打开项
*
......@@ -323,6 +341,36 @@ export default class DefaultBase extends Vue implements ControlInterface {
return item;
}
/**
* 初始化导航参数
*
* @param {*} drItem
* @memberof DefaultBase
*/
public initNavParam(drItem:any){
let returnNavParam:any = {};
if(drItem && drItem.id){
let curDRItem:any = this.navParamsArray.find((item:any) =>{
return Object.is(item.id,drItem.id);
})
if(curDRItem){
let localContext:any = curDRItem.localContext;
let localViewParam:any = curDRItem.localViewParam;
if(localContext && Object.keys(localContext).length >0){
let _context:any = this.$util.computedNavData(this.formData,this.context,this.viewparams,localContext);
returnNavParam.localContext = _context;
}
if(localViewParam && Object.keys(localViewParam).length >0){
let _params:any = this.$util.computedNavData(this.formData,this.context,this.viewparams,localViewParam);
returnNavParam.localViewParam = _params;
}
return returnNavParam;
}else{
return null;
}
}
}
/**
* 节点选中
*
......@@ -334,13 +382,18 @@ export default class DefaultBase extends Vue implements ControlInterface {
if (Object.is(item.id, this.selection.id)) {
return;
}
this.$emit('selectionchange', [item]);
let localNavParam:any = this.initNavParam(item);
const refview = this.getDRBarItem({ nodetype: item.id });
this.selection = {};
const _context: any = { ...JSON.parse(JSON.stringify(this.context)) };
const _params: any = { ...JSON.parse(JSON.stringify(this.viewparams)) };
if(localNavParam && localNavParam.localContext){
Object.assign(_context,localNavParam.localContext);
}
const _params: any = {};
if(localNavParam && localNavParam.localViewParam){
Object.assign(_params,localNavParam.localViewParam);
}
if (refview && refview.parentdatajo) {
Object.assign(_context, refview.parentdatajo);
Object.assign(this.selection, { view: { viewname: refview.viewname }, data: _context, param: _params });
......
......@@ -1284,6 +1284,7 @@ export default class MainBase extends Vue implements ControlInterface {
*/
public uiAction(row: any, tag: any, $event: any) {
// this.rowClick(row, true);
$event.stopPropagation();
}
/**
......
......@@ -151,6 +151,7 @@ export default class DefaultBase extends Vue implements ControlInterface {
}
/**
* 获取多项数据
*
......@@ -179,6 +180,14 @@ export default class DefaultBase extends Vue implements ControlInterface {
*/
@Prop() public loadAction?: string;
/**
* 表单数据
*
* @type {*}
* @memberof DefaultBase
*/
@Prop({default:{}}) public formData?:any;
/**
* 数据选中项
*
......@@ -201,6 +210,15 @@ export default class DefaultBase extends Vue implements ControlInterface {
},
];
/**
* 关系栏数据项导航参数集合
*
* @type {any[]}
* @memberof DefaultBase
*/
public navParamsArray:Array<any> = [
];
/**
* 默认打开项
*
......@@ -323,6 +341,36 @@ export default class DefaultBase extends Vue implements ControlInterface {
return item;
}
/**
* 初始化导航参数
*
* @param {*} drItem
* @memberof DefaultBase
*/
public initNavParam(drItem:any){
let returnNavParam:any = {};
if(drItem && drItem.id){
let curDRItem:any = this.navParamsArray.find((item:any) =>{
return Object.is(item.id,drItem.id);
})
if(curDRItem){
let localContext:any = curDRItem.localContext;
let localViewParam:any = curDRItem.localViewParam;
if(localContext && Object.keys(localContext).length >0){
let _context:any = this.$util.computedNavData(this.formData,this.context,this.viewparams,localContext);
returnNavParam.localContext = _context;
}
if(localViewParam && Object.keys(localViewParam).length >0){
let _params:any = this.$util.computedNavData(this.formData,this.context,this.viewparams,localViewParam);
returnNavParam.localViewParam = _params;
}
return returnNavParam;
}else{
return null;
}
}
}
/**
* 节点选中
*
......@@ -334,13 +382,18 @@ export default class DefaultBase extends Vue implements ControlInterface {
if (Object.is(item.id, this.selection.id)) {
return;
}
this.$emit('selectionchange', [item]);
let localNavParam:any = this.initNavParam(item);
const refview = this.getDRBarItem({ nodetype: item.id });
this.selection = {};
const _context: any = { ...JSON.parse(JSON.stringify(this.context)) };
const _params: any = { ...JSON.parse(JSON.stringify(this.viewparams)) };
if(localNavParam && localNavParam.localContext){
Object.assign(_context,localNavParam.localContext);
}
const _params: any = {};
if(localNavParam && localNavParam.localViewParam){
Object.assign(_params,localNavParam.localViewParam);
}
if (refview && refview.parentdatajo) {
Object.assign(_context, refview.parentdatajo);
Object.assign(this.selection, { view: { viewname: refview.viewname }, data: _context, param: _params });
......
......@@ -1303,6 +1303,7 @@ export default class MainBase extends Vue implements ControlInterface {
*/
public uiAction(row: any, tag: any, $event: any) {
// this.rowClick(row, true);
$event.stopPropagation();
}
/**
......
......@@ -151,6 +151,7 @@ export default class DefaultBase extends Vue implements ControlInterface {
}
/**
* 获取多项数据
*
......@@ -179,6 +180,14 @@ export default class DefaultBase extends Vue implements ControlInterface {
*/
@Prop() public loadAction?: string;
/**
* 表单数据
*
* @type {*}
* @memberof DefaultBase
*/
@Prop({default:{}}) public formData?:any;
/**
* 数据选中项
*
......@@ -201,6 +210,15 @@ export default class DefaultBase extends Vue implements ControlInterface {
},
];
/**
* 关系栏数据项导航参数集合
*
* @type {any[]}
* @memberof DefaultBase
*/
public navParamsArray:Array<any> = [
];
/**
* 默认打开项
*
......@@ -323,6 +341,36 @@ export default class DefaultBase extends Vue implements ControlInterface {
return item;
}
/**
* 初始化导航参数
*
* @param {*} drItem
* @memberof DefaultBase
*/
public initNavParam(drItem:any){
let returnNavParam:any = {};
if(drItem && drItem.id){
let curDRItem:any = this.navParamsArray.find((item:any) =>{
return Object.is(item.id,drItem.id);
})
if(curDRItem){
let localContext:any = curDRItem.localContext;
let localViewParam:any = curDRItem.localViewParam;
if(localContext && Object.keys(localContext).length >0){
let _context:any = this.$util.computedNavData(this.formData,this.context,this.viewparams,localContext);
returnNavParam.localContext = _context;
}
if(localViewParam && Object.keys(localViewParam).length >0){
let _params:any = this.$util.computedNavData(this.formData,this.context,this.viewparams,localViewParam);
returnNavParam.localViewParam = _params;
}
return returnNavParam;
}else{
return null;
}
}
}
/**
* 节点选中
*
......@@ -334,13 +382,18 @@ export default class DefaultBase extends Vue implements ControlInterface {
if (Object.is(item.id, this.selection.id)) {
return;
}
this.$emit('selectionchange', [item]);
let localNavParam:any = this.initNavParam(item);
const refview = this.getDRBarItem({ nodetype: item.id });
this.selection = {};
const _context: any = { ...JSON.parse(JSON.stringify(this.context)) };
const _params: any = { ...JSON.parse(JSON.stringify(this.viewparams)) };
if(localNavParam && localNavParam.localContext){
Object.assign(_context,localNavParam.localContext);
}
const _params: any = {};
if(localNavParam && localNavParam.localViewParam){
Object.assign(_params,localNavParam.localViewParam);
}
if (refview && refview.parentdatajo) {
Object.assign(_context, refview.parentdatajo);
Object.assign(this.selection, { view: { viewname: refview.viewname }, data: _context, param: _params });
......
......@@ -1279,6 +1279,7 @@ export default class MainBase extends Vue implements ControlInterface {
*/
public uiAction(row: any, tag: any, $event: any) {
// this.rowClick(row, true);
$event.stopPropagation();
}
/**
......
......@@ -151,6 +151,7 @@ export default class DefaultBase extends Vue implements ControlInterface {
}
/**
* 获取多项数据
*
......@@ -179,6 +180,14 @@ export default class DefaultBase extends Vue implements ControlInterface {
*/
@Prop() public loadAction?: string;
/**
* 表单数据
*
* @type {*}
* @memberof DefaultBase
*/
@Prop({default:{}}) public formData?:any;
/**
* 数据选中项
*
......@@ -201,6 +210,15 @@ export default class DefaultBase extends Vue implements ControlInterface {
},
];
/**
* 关系栏数据项导航参数集合
*
* @type {any[]}
* @memberof DefaultBase
*/
public navParamsArray:Array<any> = [
];
/**
* 默认打开项
*
......@@ -323,6 +341,36 @@ export default class DefaultBase extends Vue implements ControlInterface {
return item;
}
/**
* 初始化导航参数
*
* @param {*} drItem
* @memberof DefaultBase
*/
public initNavParam(drItem:any){
let returnNavParam:any = {};
if(drItem && drItem.id){
let curDRItem:any = this.navParamsArray.find((item:any) =>{
return Object.is(item.id,drItem.id);
})
if(curDRItem){
let localContext:any = curDRItem.localContext;
let localViewParam:any = curDRItem.localViewParam;
if(localContext && Object.keys(localContext).length >0){
let _context:any = this.$util.computedNavData(this.formData,this.context,this.viewparams,localContext);
returnNavParam.localContext = _context;
}
if(localViewParam && Object.keys(localViewParam).length >0){
let _params:any = this.$util.computedNavData(this.formData,this.context,this.viewparams,localViewParam);
returnNavParam.localViewParam = _params;
}
return returnNavParam;
}else{
return null;
}
}
}
/**
* 节点选中
*
......@@ -334,13 +382,18 @@ export default class DefaultBase extends Vue implements ControlInterface {
if (Object.is(item.id, this.selection.id)) {
return;
}
this.$emit('selectionchange', [item]);
let localNavParam:any = this.initNavParam(item);
const refview = this.getDRBarItem({ nodetype: item.id });
this.selection = {};
const _context: any = { ...JSON.parse(JSON.stringify(this.context)) };
const _params: any = { ...JSON.parse(JSON.stringify(this.viewparams)) };
if(localNavParam && localNavParam.localContext){
Object.assign(_context,localNavParam.localContext);
}
const _params: any = {};
if(localNavParam && localNavParam.localViewParam){
Object.assign(_params,localNavParam.localViewParam);
}
if (refview && refview.parentdatajo) {
Object.assign(_context, refview.parentdatajo);
Object.assign(this.selection, { view: { viewname: refview.viewname }, data: _context, param: _params });
......
......@@ -1284,6 +1284,7 @@ export default class MainBase extends Vue implements ControlInterface {
*/
public uiAction(row: any, tag: any, $event: any) {
// this.rowClick(row, true);
$event.stopPropagation();
}
/**
......
......@@ -37,11 +37,6 @@
git clone -b master $para2 ibzuaa/
export NODE_OPTIONS=--max-old-space-size=4096
cd ibzuaa/
mvn clean package -Papi
cd ibzuaa-provider/ibzuaa-provider-api
mvn -Papi docker:build
mvn -Papi docker:push
docker -H $para1 stack deploy --compose-file=src/main/docker/ibzuaa-provider-api.yaml ibzlab-rt --with-registry-auth
</command>
</hudson.tasks.Shell>
</builders>
......
......@@ -22,10 +22,10 @@ import lombok.*;
import org.springframework.data.annotation.Transient;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.baomidou.mybatisplus.annotation.*;
import cn.ibizlab.util.domain.EntityMP;
/**
* 实体[认证日志]
*/
......@@ -33,6 +33,7 @@ import cn.ibizlab.util.domain.EntityMP;
@Setter
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(value = "handler")
@TableName(value = "IBZAUTHLOG",resultMap = "SysAuthLogResultMap")
public class SysAuthLog extends EntityMP implements Serializable {
......
......@@ -22,10 +22,10 @@ import lombok.*;
import org.springframework.data.annotation.Transient;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.baomidou.mybatisplus.annotation.*;
import cn.ibizlab.util.domain.EntityMP;
/**
* 实体[权限/资源]
*/
......@@ -33,6 +33,7 @@ import cn.ibizlab.util.domain.EntityMP;
@Setter
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(value = "handler")
@TableName(value = "IBZPERMISSION",resultMap = "SysPermissionResultMap")
public class SysPermission extends EntityMP implements Serializable {
......
......@@ -22,10 +22,10 @@ import lombok.*;
import org.springframework.data.annotation.Transient;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.baomidou.mybatisplus.annotation.*;
import cn.ibizlab.util.domain.EntityMP;
/**
* 实体[系统角色]
*/
......@@ -33,6 +33,7 @@ import cn.ibizlab.util.domain.EntityMP;
@Setter
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(value = "handler")
@TableName(value = "IBZROLE",resultMap = "SysRoleResultMap")
public class SysRole extends EntityMP implements Serializable {
......
......@@ -22,10 +22,10 @@ import lombok.*;
import org.springframework.data.annotation.Transient;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.baomidou.mybatisplus.annotation.*;
import cn.ibizlab.util.domain.EntityMP;
/**
* 实体[角色权限关系]
*/
......@@ -33,6 +33,7 @@ import cn.ibizlab.util.domain.EntityMP;
@Setter
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(value = "handler")
@TableName(value = "IBZROLE_PERMISSION",resultMap = "SysRolePermissionResultMap")
public class SysRolePermission extends EntityMP implements Serializable {
......
......@@ -22,10 +22,10 @@ import lombok.*;
import org.springframework.data.annotation.Transient;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.baomidou.mybatisplus.annotation.*;
import cn.ibizlab.util.domain.EntityMP;
/**
* 实体[系统用户]
*/
......@@ -33,6 +33,7 @@ import cn.ibizlab.util.domain.EntityMP;
@Setter
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(value = "handler")
@TableName(value = "IBZUSER",resultMap = "SysUserResultMap")
public class SysUser extends EntityMP implements Serializable {
......
......@@ -22,10 +22,10 @@ import lombok.*;
import org.springframework.data.annotation.Transient;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.baomidou.mybatisplus.annotation.*;
import cn.ibizlab.util.domain.EntityMP;
/**
* 实体[用户角色关系]
*/
......@@ -33,6 +33,7 @@ import cn.ibizlab.util.domain.EntityMP;
@Setter
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(value = "handler")
@TableName(value = "IBZUSER_ROLE",resultMap = "SysUserRoleResultMap")
public class SysUserRole extends EntityMP implements Serializable {
......
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd">
<!--输出实体[SYS_AUTHLOG]数据结构 -->
<changeSet author="a_A_5d9d78509" id="tab-sys_authlog-36-1">
<createTable tableName="IBZAUTHLOG">
<column name="LOGID" remarks="" type="VARCHAR(100)">
<constraints primaryKey="true" primaryKeyName="PK_SYS_AUTHLOG_LOGID"/>
</column>
<column name="USERNAME" remarks="" type="VARCHAR(100)">
</column>
<column name="PERSONNAME" remarks="" type="VARCHAR(100)">
</column>
<column name="DOMAIN" remarks="" type="VARCHAR(100)">
</column>
<column name="AUTHTIME" remarks="" type="DATETIME">
</column>
<column name="IPADDR" remarks="" type="VARCHAR(100)">
</column>
<column name="MACADDR" remarks="" type="VARCHAR(100)">
</column>
<column name="USERAGENT" remarks="" type="VARCHAR(100)">
</column>
<column name="AUTHCODE" remarks="" type="VARCHAR(15)">
</column>
</createTable>
</changeSet>
<!--输出实体[SYS_ROLE_PERMISSION]数据结构 -->
<changeSet author="a_A_5d9d78509" id="tab-sys_role_permission-93-2">
<createTable tableName="IBZROLE_PERMISSION">
<column name="SYS_ROLE_PERMISSIONID" remarks="" type="VARCHAR(100)">
<constraints primaryKey="true" primaryKeyName="PK_SYS_ROLE_PERMISSION_SYS_ROL"/>
</column>
<column name="SYS_ROLEID" remarks="" type="VARCHAR(100)">
</column>
<column name="SYS_PERMISSIONID" remarks="" type="VARCHAR(200)">
</column>
<column name="CREATEDATE" remarks="" type="DATETIME">
</column>
<column name="UPDATEDATE" remarks="" type="DATETIME">
</column>
</createTable>
</changeSet>
<!--输出实体[SYS_USER_ROLE]数据结构 -->
<changeSet author="a_A_5d9d78509" id="tab-sys_user_role-62-3">
<createTable tableName="IBZUSER_ROLE">
<column name="SYS_USER_ROLEID" remarks="" type="VARCHAR(100)">
<constraints primaryKey="true" primaryKeyName="PK_SYS_USER_ROLE_SYS_USER_ROLE"/>
</column>
<column name="SYS_ROLEID" remarks="" type="VARCHAR(100)">
</column>
<column name="SYS_USERID" remarks="" type="VARCHAR(100)">
</column>
<column name="CREATEDATE" remarks="" type="DATETIME">
</column>
<column name="UPDATEDATE" remarks="" type="DATETIME">
</column>
</createTable>
</changeSet>
<!--输出实体[SYS_ROLE]数据结构 -->
<changeSet author="a_A_5d9d78509" id="tab-sys_role-89-4">
<createTable tableName="IBZROLE">
<column name="SYS_ROLEID" remarks="" type="VARCHAR(100)">
<constraints primaryKey="true" primaryKeyName="PK_SYS_ROLE_SYS_ROLEID"/>
</column>
<column name="SYS_ROLENAME" remarks="" type="VARCHAR(200)">
</column>
<column name="MEMO" remarks="" type="VARCHAR(100)">
</column>
<column name="CREATEDATE" remarks="" type="DATETIME">
</column>
<column name="UPDATEDATE" remarks="" type="DATETIME">
</column>
</createTable>
</changeSet>
<!--输出实体[SYS_PSSYSTEM]数据结构 -->
<changeSet author="a_A_5d9d78509" id="tab-sys_pssystem-36-5">
<createTable tableName="IBZPSSYSTEM">
<column name="PSSYSTEMID" remarks="" type="VARCHAR(100)">
<constraints primaryKey="true" primaryKeyName="PK_SYS_PSSYSTEM_PSSYSTEMID"/>
</column>
<column name="PSSYSTEMNAME" remarks="" type="VARCHAR(100)">
</column>
<column name="SYSSTRUCTURE" remarks="" type="TEXT(1048576)">
</column>
<column name="APPS" remarks="" type="TEXT(1048576)">
</column>
<column name="MD5CHECK" remarks="" type="VARCHAR(100)">
</column>
<column name="SHOWORDER" remarks="" type="INT">
</column>
</createTable>
</changeSet>
<!--输出实体[SYS_PERMISSION]数据结构 -->
<changeSet author="a_A_5d9d78509" id="tab-sys_permission-219-6">
<createTable tableName="IBZPERMISSION">
<column name="SYS_PERMISSIONID" remarks="" type="VARCHAR(200)">
<constraints primaryKey="true" primaryKeyName="PK_SYS_PERMISSION_SYS_PERMISSI"/>
</column>
<column name="SYS_PERMISSIONNAME" remarks="" type="VARCHAR(200)">
</column>
<column name="PERMISSIONTYPE" remarks="" type="VARCHAR(60)">
</column>
<column name="PSSYSTEMID" remarks="" type="VARCHAR(100)">
</column>
<column name="ENABLE" remarks="" type="INT">
</column>
<column name="CREATEDATE" remarks="" type="DATETIME">
</column>
<column name="UPDATEDATE" remarks="" type="DATETIME">
</column>
</createTable>
</changeSet>
<!--输出实体[SYS_AUTHLOG]外键关系 -->
<!--输出实体[SYS_ROLE_PERMISSION]外键关系 -->
<changeSet author="a_A_5d9d78509" id="fk-sys_role_permission-93-7">
<addForeignKeyConstraint baseColumnNames="SYS_PERMISSIONID" baseTableName="IBZROLE_PERMISSION" constraintName="DER1N_SYS_ROLE_PERMISSION_SYS_" deferrable="false" initiallyDeferred="false" onDelete="RESTRICT" onUpdate="RESTRICT" referencedColumnNames="SYS_PERMISSIONID" referencedTableName="IBZPERMISSION" validate="true"/>
</changeSet>
<!--输出实体[SYS_USER_ROLE]外键关系 -->
<changeSet author="a_A_5d9d78509" id="fk-sys_user_role-62-9">
<addForeignKeyConstraint baseColumnNames="SYS_ROLEID" baseTableName="IBZUSER_ROLE" constraintName="DER1N_SYS_USER_ROLE_SYS_ROLE_S" deferrable="false" initiallyDeferred="false" onDelete="RESTRICT" onUpdate="RESTRICT" referencedColumnNames="SYS_ROLEID" referencedTableName="IBZROLE" validate="true"/>
</changeSet>
<!--输出实体[SYS_ROLE]外键关系 -->
<!--输出实体[SYS_PSSYSTEM]外键关系 -->
<!--输出实体[SYS_PERMISSION]外键关系 -->
</databaseChangeLog>
!!!!模版产生代码错误:----
Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??
----
----
FTL stack trace ("~" means nesting-related):
- Failed at: ${dbinst.getUserName()} [in template "CODETEMPL_zh_CN" at line 28, column 24]
----
\ No newline at end of file
......@@ -9,6 +9,6 @@ CMD echo "The application will start in ${IBIZ_SLEEP}s..." && \
sleep ${IBIZ_SLEEP} && \
java ${JAVA_OPTS} -Djava.security.egd=file:/dev/./urandom -jar /ibzuaa-provider-api.jar
EXPOSE 40002
EXPOSE 8081
ADD ibzuaa-provider-api.jar /ibzuaa-provider-api.jar
......@@ -3,21 +3,9 @@ services:
ibzuaa-provider-api:
image: registry.cn-shanghai.aliyuncs.com/ibizsys/ibzuaa-provider-api:latest
ports:
- "40002:40002"
- "8081:8081"
networks:
- agent_network
environment:
- SPRING_CLOUD_NACOS_DISCOVERY_IP=172.16.180.237
- SERVER_PORT=40002
- SPRING_CLOUD_NACOS_DISCOVERY_SERVER-ADDR=172.16.102.211:8848
- SPRING_REDIS_HOST=172.16.100.243
- SPRING_REDIS_PORT=6379
- SPRING_REDIS_DATABASE=0
- SPRING_DATASOURCE_USERNAME=a_A_5d9d78509
- SPRING_DATASOURCE_PASSWORD=@6dEfb3@
- SPRING_DATASOURCE_URL=jdbc:mysql://172.16.180.232:3306/a_A_5d9d78509?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&useOldAliasMetadataBehavior=true
- SPRING_DATASOURCE_DRIVER-CLASS-NAME=com.mysql.jdbc.Driver
- SPRING_DATASOURCE_DEFAULTSCHEMA=a_A_5d9d78509
deploy:
resources:
limits:
......
......@@ -22,4 +22,9 @@ public class IBZUAAFallback implements IBZUAAFeignClient {
public AuthenticationUser loginByUsername(String username) {
return null;
}
@Override
public String getPublicKey() {
return null;
}
}
......@@ -2,6 +2,7 @@ package cn.ibizlab.util.client;
import cn.ibizlab.util.security.AuthenticationUser;
import cn.ibizlab.util.security.AuthorizationLogin;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import com.alibaba.fastjson.JSONObject;
......@@ -28,4 +29,8 @@ public interface IBZUAAFeignClient
@PostMapping(value = "/uaa/loginbyusername")
AuthenticationUser loginByUsername(@RequestBody String username);
@Cacheable(value="ibzuaa_publickey")
@GetMapping(value = "/uaa/publickey")
String getPublicKey();
}
package cn.ibizlab.util.security;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Clock;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.impl.DefaultClock;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
public interface AuthTokenUtil {
@Component
public class AuthTokenUtil implements Serializable {
String generateToken(UserDetails userDetails);
private static final long serialVersionUID = -3301605591108950415L;
private Clock clock = DefaultClock.INSTANCE;
Boolean validateToken(String token, UserDetails userDetails);
@Value("${ibiz.jwt.secret:ibzsecret}")
private String secret;
String getUsernameFromToken(String token);
@Value("${ibiz.jwt.expiration:7200000}")
private Long expiration;
@Value("${ibiz.jwt.header:Authorization}")
private String tokenHeader;
public String getUsernameFromToken(String token) {
return getClaimFromToken(token, Claims::getSubject);
}
public Date getIssuedAtDateFromToken(String token) {
return getClaimFromToken(token, Claims::getIssuedAt);
}
public Date getExpirationDateFromToken(String token) {
return getClaimFromToken(token, Claims::getExpiration);
}
public <T> T getClaimFromToken(String token, Function<Claims, T> claimsResolver) {
final Claims claims = getAllClaimsFromToken(token);
return claimsResolver.apply(claims);
}
private Claims getAllClaimsFromToken(String token) {
return Jwts.parser()
.setSigningKey(secret)
.parseClaimsJws(token)
.getBody();
}
private Boolean isTokenExpired(String token) {
final Date expiration = getExpirationDateFromToken(token);
return expiration.before(clock.now());
}
private Boolean isCreatedBeforeLastPasswordReset(Date created, Date lastPasswordReset) {
return (lastPasswordReset != null && created.before(lastPasswordReset));
}
private Boolean ignoreTokenExpiration(String token) {
// here you specify tokens, for that the expiration is ignored
return false;
}
public String generateToken(UserDetails userDetails) {
Map<String, Object> claims = new HashMap<>();
return doGenerateToken(claims, userDetails.getUsername());
}
private String doGenerateToken(Map<String, Object> claims, String subject) {
final Date createdDate = clock.now();
final Date expirationDate = calculateExpirationDate(createdDate);
return Jwts.builder()
.setClaims(claims)
.setSubject(subject)
.setIssuedAt(createdDate)
.setExpiration(expirationDate)
.signWith(SignatureAlgorithm.HS512, secret)
.compact();
}
public Boolean canTokenBeRefreshed(String token, Date lastPasswordReset) {
final Date created = getIssuedAtDateFromToken(token);
return !isCreatedBeforeLastPasswordReset(created, lastPasswordReset)
&& (!isTokenExpired(token) || ignoreTokenExpiration(token));
}
public String refreshToken(String token) {
final Date createdDate = clock.now();
final Date expirationDate = calculateExpirationDate(createdDate);
final Claims claims = getAllClaimsFromToken(token);
claims.setIssuedAt(createdDate);
claims.setExpiration(expirationDate);
return Jwts.builder()
.setClaims(claims)
.signWith(SignatureAlgorithm.HS512, secret)
.compact();
}
public Boolean validateToken(String token, UserDetails userDetails) {
AuthenticationUser user = (AuthenticationUser) userDetails;
final Date created = getIssuedAtDateFromToken(token);
return (!isTokenExpired(token) );
}
private Date calculateExpirationDate(Date createdDate) {
return new Date(createdDate.getTime() + expiration);
}
/**
* Get the login of the current user.
*
* @return the login of the current user
*/
public static Optional<String> getCurrentUserLogin() {
SecurityContext securityContext = SecurityContextHolder.getContext();
return Optional.ofNullable(securityContext.getAuthentication())
.map(authentication -> {
if (authentication.getPrincipal() instanceof UserDetails) {
UserDetails springSecurityUser = (UserDetails) authentication.getPrincipal();
return springSecurityUser.getUsername();
} else if (authentication.getPrincipal() instanceof String) {
return (String) authentication.getPrincipal();
}
return null;
});
}
/**
* Check if a user is authenticated.
*
* @return true if the user is authenticated, false otherwise
*/
public static boolean isAuthenticated() {
SecurityContext securityContext = SecurityContextHolder.getContext();
return Optional.ofNullable(securityContext.getAuthentication())
.map(authentication -> authentication.getAuthorities().stream()
.noneMatch(grantedAuthority -> grantedAuthority.getAuthority().equals("ANONYMOUS")))
.orElse(false);
}
/**
* If the current user has a specific authority (security role).
* <p>
* The name of this method comes from the isUserInRole() method in the Servlet API
*
* @param authority the authority to check
* @return true if the current user has the authority, false otherwise
*/
public static boolean isCurrentUserInRole(String authority) {
SecurityContext securityContext = SecurityContextHolder.getContext();
return Optional.ofNullable(securityContext.getAuthentication())
.map(authentication -> authentication.getAuthorities().stream()
.anyMatch(grantedAuthority -> grantedAuthority.getAuthority().equals(authority)))
.orElse(false);
}
}
package cn.ibizlab.util.security;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Clock;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.impl.DefaultClock;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
@Component
@ConditionalOnExpression("(!${ibiz.enablePermissionValid:false})&&'${ibiz.auth.service:SimpleTokenUtil}'.equals('SimpleTokenUtil')")
public class SimpleTokenUtil implements AuthTokenUtil,Serializable {
private static final long serialVersionUID = -3301605591108950415L;
private Clock clock = DefaultClock.INSTANCE;
@Value("${ibiz.jwt.secret:ibzsecret}")
private String secret;
@Value("${ibiz.jwt.expiration:7200000}")
private Long expiration;
@Value("${ibiz.jwt.header:Authorization}")
private String tokenHeader;
public String getUsernameFromToken(String token) {
return getClaimFromToken(token, Claims::getSubject);
}
public Date getIssuedAtDateFromToken(String token) {
return getClaimFromToken(token, Claims::getIssuedAt);
}
public Date getExpirationDateFromToken(String token) {
return getClaimFromToken(token, Claims::getExpiration);
}
public <T> T getClaimFromToken(String token, Function<Claims, T> claimsResolver) {
final Claims claims = getAllClaimsFromToken(token);
return claimsResolver.apply(claims);
}
private Claims getAllClaimsFromToken(String token) {
return Jwts.parser()
.setSigningKey(secret)
.parseClaimsJws(token)
.getBody();
}
private Boolean isTokenExpired(String token) {
final Date expiration = getExpirationDateFromToken(token);
return expiration.before(clock.now());
}
private Boolean isCreatedBeforeLastPasswordReset(Date created, Date lastPasswordReset) {
return (lastPasswordReset != null && created.before(lastPasswordReset));
}
private Boolean ignoreTokenExpiration(String token) {
// here you specify tokens, for that the expiration is ignored
return false;
}
public String generateToken(UserDetails userDetails) {
Map<String, Object> claims = new HashMap<>();
return doGenerateToken(claims, userDetails.getUsername());
}
private String doGenerateToken(Map<String, Object> claims, String subject) {
final Date createdDate = clock.now();
final Date expirationDate = calculateExpirationDate(createdDate);
return Jwts.builder()
.setClaims(claims)
.setSubject(subject)
.setIssuedAt(createdDate)
.setExpiration(expirationDate)
.signWith(SignatureAlgorithm.HS512, secret)
.compact();
}
public Boolean canTokenBeRefreshed(String token, Date lastPasswordReset) {
final Date created = getIssuedAtDateFromToken(token);
return !isCreatedBeforeLastPasswordReset(created, lastPasswordReset)
&& (!isTokenExpired(token) || ignoreTokenExpiration(token));
}
public String refreshToken(String token) {
final Date createdDate = clock.now();
final Date expirationDate = calculateExpirationDate(createdDate);
final Claims claims = getAllClaimsFromToken(token);
claims.setIssuedAt(createdDate);
claims.setExpiration(expirationDate);
return Jwts.builder()
.setClaims(claims)
.signWith(SignatureAlgorithm.HS512, secret)
.compact();
}
public Boolean validateToken(String token, UserDetails userDetails) {
AuthenticationUser user = (AuthenticationUser) userDetails;
final Date created = getIssuedAtDateFromToken(token);
return (!isTokenExpired(token) );
}
private Date calculateExpirationDate(Date createdDate) {
return new Date(createdDate.getTime() + expiration);
}
/**
* Get the login of the current user.
*
* @return the login of the current user
*/
public static Optional<String> getCurrentUserLogin() {
SecurityContext securityContext = SecurityContextHolder.getContext();
return Optional.ofNullable(securityContext.getAuthentication())
.map(authentication -> {
if (authentication.getPrincipal() instanceof UserDetails) {
UserDetails springSecurityUser = (UserDetails) authentication.getPrincipal();
return springSecurityUser.getUsername();
} else if (authentication.getPrincipal() instanceof String) {
return (String) authentication.getPrincipal();
}
return null;
});
}
/**
* Check if a user is authenticated.
*
* @return true if the user is authenticated, false otherwise
*/
public static boolean isAuthenticated() {
SecurityContext securityContext = SecurityContextHolder.getContext();
return Optional.ofNullable(securityContext.getAuthentication())
.map(authentication -> authentication.getAuthorities().stream()
.noneMatch(grantedAuthority -> grantedAuthority.getAuthority().equals("ANONYMOUS")))
.orElse(false);
}
/**
* If the current user has a specific authority (security role).
* <p>
* The name of this method comes from the isUserInRole() method in the Servlet API
*
* @param authority the authority to check
* @return true if the current user has the authority, false otherwise
*/
public static boolean isCurrentUserInRole(String authority) {
SecurityContext securityContext = SecurityContextHolder.getContext();
return Optional.ofNullable(securityContext.getAuthentication())
.map(authentication -> authentication.getAuthorities().stream()
.anyMatch(grantedAuthority -> grantedAuthority.getAuthority().equals(authority)))
.orElse(false);
}
}
package cn.ibizlab.util.security;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Clock;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.impl.DefaultClock;
import lombok.SneakyThrows;
import cn.ibizlab.util.client.IBZUAAFeignClient;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;
import java.io.File;
import java.io.FileInputStream;
import java.io.Serializable;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
@Component
@ConditionalOnExpression("${ibiz.enablePermissionValid:false}||'${ibiz.auth.service:SimpleTokenUtil}'.equals('UAATokenUtil')")
public class UAATokenUtil implements AuthTokenUtil, Serializable {
private static final long serialVersionUID = -3301605591108950415L;
private Clock clock = DefaultClock.INSTANCE;
@Value("${ibiz.jwt.secret:ibzsecret}")
private String secret;
@Value("${ibiz.jwt.expiration:7200000}")
private Long expiration;
@Value("${ibiz.jwt.header:Authorization}")
private String tokenHeader;
@Autowired
private IBZUAAFeignClient uaaFeignClient;
public String getUsernameFromToken(String token) {
return getClaimFromToken(token, Claims::getSubject);
}
public Date getIssuedAtDateFromToken(String token) {
return getClaimFromToken(token, Claims::getIssuedAt);
}
public Date getExpirationDateFromToken(String token) {
return getClaimFromToken(token, Claims::getExpiration);
}
public <T> T getClaimFromToken(String token, Function<Claims, T> claimsResolver) {
final Claims claims = getAllClaimsFromToken(token);
return claimsResolver.apply(claims);
}
public Claims getAllClaimsFromToken(String token) {
PublicKey publicKey = getPublicKey(getPublicKeyString());
return Jwts.parser()
.setSigningKey(publicKey)
.parseClaimsJws(token)
.getBody();
}
private Boolean isTokenExpired(String token) {
final Date expiration = getExpirationDateFromToken(token);
return expiration.before(clock.now());
}
public String generateToken(UserDetails userDetails) {
return null;
}
public Boolean validateToken(String token, UserDetails userDetails) {
AuthenticationUser user = (AuthenticationUser) userDetails;
final Date created = getIssuedAtDateFromToken(token);
return (!isTokenExpired(token) );
}
private String getPublicKeyString(){
return uaaFeignClient.getPublicKey();
}
/**
* 获取PublicKey对象
* @param publicKeyBase64
* @return
* @throws NoSuchAlgorithmException
* @throws InvalidKeySpecException
*/
@SneakyThrows
public PublicKey getPublicKey(String publicKeyBase64) {
byte[] byteKey = Base64.decodeBase64(publicKeyBase64);
X509EncodedKeySpec x509EncodedKeySpec = new X509EncodedKeySpec(byteKey);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
return keyFactory.generatePublic(x509EncodedKeySpec);
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册