Merge branch 'main' of git.kaiyuancloud.cn:yumoqing/bricks
This commit is contained in:
commit
16c96b762d
@ -130,6 +130,7 @@ bricks.widgetBuild = async function(desc, widget, data){
|
|||||||
let opts = desc.options.params || {};
|
let opts = desc.options.params || {};
|
||||||
var jc = new bricks.HttpJson();
|
var jc = new bricks.HttpJson();
|
||||||
var desc1 = await jc.httpcall(url, { "method":method, "params":opts});
|
var desc1 = await jc.httpcall(url, { "method":method, "params":opts});
|
||||||
|
if (!desc1) return;
|
||||||
desc = desc1;
|
desc = desc1;
|
||||||
klassname = desc.widgettype;
|
klassname = desc.widgettype;
|
||||||
}
|
}
|
||||||
@ -464,7 +465,7 @@ bricks.App = class extends bricks.Layout {
|
|||||||
bricks.bug = opts.debug || false;
|
bricks.bug = opts.debug || false;
|
||||||
bricks.Body = this;
|
bricks.Body = this;
|
||||||
this.deviceid = bricks.deviceid(opts.appname || 'appname');
|
this.deviceid = bricks.deviceid(opts.appname || 'appname');
|
||||||
this.login_url = opts.login_url;
|
this.login_url = opts.login_url || '/rbac/userpassword_login.ui';
|
||||||
this.charsize = this.opts.charsize || 20;
|
this.charsize = this.opts.charsize || 20;
|
||||||
this.keyevent_blocked = false;
|
this.keyevent_blocked = false;
|
||||||
this.char_size = this.observable('charsize', this.charsize);
|
this.char_size = this.observable('charsize', this.charsize);
|
||||||
|
@ -97,7 +97,7 @@ bricks.Cols = class extends bricks.VBox {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
async load_first_page(params){
|
async load_first_page(params){
|
||||||
var p = bricks.extend({}, this.params);
|
var p = bricks.extend({}, this.data_params);
|
||||||
if (params){
|
if (params){
|
||||||
p = bricks.extend(p, params);
|
p = bricks.extend(p, params);
|
||||||
}
|
}
|
||||||
|
@ -83,6 +83,7 @@ bricks.EchartsExt = class extends bricks.VBox {
|
|||||||
this.valueFields = this.get_series(data);
|
this.valueFields = this.get_series(data);
|
||||||
data = this.pivotify(data);
|
data = this.pivotify(data);
|
||||||
}
|
}
|
||||||
|
this.chart = echarts.init(this.holder.dom_element);
|
||||||
var opts = this.setup_options(data);
|
var opts = this.setup_options(data);
|
||||||
opts.grid = {
|
opts.grid = {
|
||||||
left: '3%',
|
left: '3%',
|
||||||
|
@ -121,9 +121,36 @@ bricks.HttpText = class {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const fetchResult = await fetch(url, _params);
|
const fetchResult = await fetch(url, _params);
|
||||||
var result=null;
|
console.log('fetchResult.status=', fetchResult.status, url, 'login url=', bricks.app.login_url);
|
||||||
result = await this.get_result_data(fetchResult);
|
if (fetchResult.status == 401 && bricks.app.login_url){
|
||||||
if (fetchResult.ok){
|
console.log('go to login')
|
||||||
|
return await this.withLoginInfo(url, _params);
|
||||||
|
}
|
||||||
|
if (fetchResult.status == 403){
|
||||||
|
var w = new bricks.Error({
|
||||||
|
"title":"access error",
|
||||||
|
"auto_open":true,
|
||||||
|
"message":"you are forbidden to access it",
|
||||||
|
"archor":"cc",
|
||||||
|
"cheight":10,
|
||||||
|
"cwidth":16,
|
||||||
|
"timeout":5
|
||||||
|
});
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (! fetchResult.ok){
|
||||||
|
var w = new bricks.Error({
|
||||||
|
"title":"access error",
|
||||||
|
"auto_open":true,
|
||||||
|
"message":"server return error with error code" + fetchResult.status,
|
||||||
|
"archor":"cc",
|
||||||
|
"cheight":10,
|
||||||
|
"cwidth":16,
|
||||||
|
"timeout":5
|
||||||
|
});
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var result = await this.get_result_data(fetchResult);
|
||||||
var ck = objget(fetchResult.headers, 'Set-Cookie');
|
var ck = objget(fetchResult.headers, 'Set-Cookie');
|
||||||
if (ck){
|
if (ck){
|
||||||
var session = ck.split(';')[0];
|
var session = ck.split(';')[0];
|
||||||
@ -131,67 +158,18 @@ bricks.HttpText = class {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
if (fetchResult.status == 401 && bricks.app.login_url){
|
|
||||||
return await this.withLoginInfo(url, _params);
|
|
||||||
}
|
|
||||||
const resp_error = {
|
|
||||||
"type":"Error",
|
|
||||||
"message":result.message || 'Something went wrong',
|
|
||||||
"data":result.data || '',
|
|
||||||
"code":result.code || ''
|
|
||||||
};
|
|
||||||
error.info = resp_error;
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
async withLoginInfo(url, params){
|
async withLoginInfo(url, params){
|
||||||
var get_login_info = function(e){
|
var get_login_info = function(e){
|
||||||
bricks.debug('login info:', e.target.getValue());
|
bricks.debug('login info:', e.target.getValue());
|
||||||
return e.target.getValue();
|
return e.target.getValue();
|
||||||
}
|
}
|
||||||
var w = await bricks.widgetBuild({
|
var w = await bricks.widgetBuild({
|
||||||
"id":"login_form",
|
|
||||||
"widgettype":"urlwidget",
|
"widgettype":"urlwidget",
|
||||||
"options":{
|
"options":{
|
||||||
"url":bricks.app.login_url
|
"url":bricks.app.login_url
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var login_info = await new Promise((resolve, reject, w) => {
|
return null;
|
||||||
w.bind('submit', (event) => {
|
|
||||||
resolve(event.target.getValue());
|
|
||||||
event.target.dismiss();
|
|
||||||
});
|
|
||||||
w.bind('discard', (event) => {
|
|
||||||
resolve(null);
|
|
||||||
event.target.dismiss()
|
|
||||||
});
|
|
||||||
});
|
|
||||||
if (login_info){
|
|
||||||
this.set_authorization_header(params, lgin_info);
|
|
||||||
const fetchResult = await fetch(url, params);
|
|
||||||
var result=null;
|
|
||||||
result = await this.get_result_data(fetchResult);
|
|
||||||
if (fetchResult.ok){
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
if (fetchResult.status == 401){
|
|
||||||
return await this.withLoginInfo(url, params);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const resp_error = {
|
|
||||||
"type":"Error",
|
|
||||||
"message":result.message || 'Something went wrong',
|
|
||||||
"data":result.data || '',
|
|
||||||
"code":result.code || ''
|
|
||||||
};
|
|
||||||
const error = new Error();
|
|
||||||
error.info = resp_error;
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
set_authorization_header(params, lgin_info){
|
|
||||||
var auth = 'password' + '::' + login_info.user + '::' + login_info.password;
|
|
||||||
var rsa = bricks.app.rsa;
|
|
||||||
var code = rsa.encrypt(auth);
|
|
||||||
self.header.authorization = btoa(code)
|
|
||||||
}
|
}
|
||||||
async get(url, {headers=null, params=null}={}){
|
async get(url, {headers=null, params=null}={}){
|
||||||
return await this.httpcall(url, {
|
return await this.httpcall(url, {
|
||||||
|
Loading…
Reference in New Issue
Block a user