Overview
ScriptUtil is packed APIs that you can use to design the interactions between elements through scripts in application design.
Basic Rules
- The namespace of form templates created under an application is the current application namespace. Its format is developer_app name. Namespace of form templates created on the supOS system is system.tip
You can check the namespace of object templates on their basic information page, and properties on the property list.
- When using scriptUtil APIs, with repeated alias, we recommend adding namespace to differentiate them from each other during calling. Otherwise, objects with same aliases will be called at the order of starting from the application, to supOS platform and to other applications.
- When using scriptUtil APIs (callFunction excluded) on supOS V2.80.01.02 and later versions, add a parameter version: 'V2'. Older versions like V2.70.01.00 uses version: 'V1' (embedded).
- When using scriptUtil APIs that are related to form templates (add, delete, insert and search) supOS V2.80.01.02 and later versions, we recommend using callFunction instead to unify service calling.
API Description
Service Execution
executeSrciptService
- objName: Required. Locate the corresponding template or instance.
- serviceName: Required. Service name that you want to call.
- params: Optional. Input parameters of the service.
- cb[callback]: Callback function.
- version: Version number. Mostly for differentiating V2.7 and V3.0.
// call service under a form template
var objName = 'namespace.templateName';
// call service under an instance of an entity template
var objName = 'namespace.templateName/instanceName';
scriptUtil.executeScriptService({
objName, // template or instance
serviceName:"namespace.querySQLExec", // service namespace and service alias
// input parameters of service
params:{ },
version: 'V2',
// callback function
cb:function(res){
console.log('res', res);
}
// custom request parameters
});
getRequestUrl
// url is https://www.baidu.com?id=123&code=456
var data = scriptUtil.getRequestUrl();
console.log(data)
// return data
{
id: 123,
code: 456
}
getTimeZone
var Offset = scriptUtil.getTimeZone();
console.log(Offset)
reload
// refresh the page in 50 ms
scriptUtil.reload(50);
refreshWorkflow
var Offset = scriptUtil.refreshWorkflow();
copy
- (any) refers to the data to be copied.
scriptUtil.copy(any);
request
- (string): Refers to the request url.
- (object): Refers to input parameters.
- method: Request method such as POST/GET/DELETE/PUT.
- body: Input parameters.
var url = '/api/openapi/notification/v1/message';
var param = {
method: 'POST', //request method such as GET, POST, PUT and DELETE
body: {}, //optional
headers: {} //optional
};
scriptUtil.request(url, param).then(res=>{
console.log(res)
});
scriptUtilReact Component
registerReactDom
- (component): Component instance.
- (object): Props.
scriptUtil.registerReactDom(this, this.props);
logoutReactDom
- (component): Component instance.
- (object): Props.
scriptUtil.logoutReactDom(this, this.props);
getRegisterReactDom
var reactInstance = scriptUtil.getRegisterReactDom('htdiv-xxxx');
reactInstance.getValue()
getFormData
scriptUtil.getFormData(['title', 'name', 'age']);
setFormData
scriptUtil.setFormData({ title: 'test data' });
submitDefaultValue
- (component): Form component instance.
- (string): To-be-set values of form component instance.
- (string): Tag. 1 means automatically submit the form and 0 means manual submit.info
Automatic submit is only valid when setting Linkage to Automatic in Page Configuration in free layout.
const component = scriptUtil.getRegisterReactDom('ctrlId');
scriptUtil.submitDefaultValue(component, 'search value', '1');
General Tool of scriptUtil
Alert
- (string): Message.
- (function): Callbackinfo
Callback is only triggered when clicking ok on the pop-up window.
scriptUtil.Alert('Prompted Successfully', () => {
console.log('Click OK');
});
showMessage
- (string): Message.
- (string): Message type, including success/warning/info/error.
scriptUtil.showMessage('Message', 'success');
timestampFormat
- (number): Timestamp.
- (string): Time format.
scriptUtil.timestampFormat(1587109353040, 'YYYY-MM-DD HH:mm:ss');
// "2020-04-17 15:42:33"
timestampAntiFormat
scriptUtil.timestampAntiFormat('2021-05-01 01:00:00');
// 1619802000000
regRexGroup
const reg = scriptUtil.regRexGroup('mobilePhone');
const variable_1 = '18866668888';
const variable_3 = '1886666777';
reg.test(variable_1); //true;
reg.test(variable_3); //false;
isVaild
scriptUtil.isVaild(['ctrlId1', 'ctrlId2', 'ctrlId3']);
getFormatterMap
scriptUtil.getFormatterMap(['ctrlId1', 'ctrlId2', 'ctrlId3']);
parseTableMap
- (array): Data source.
- (object): Map.
- (string): Index.
// parseTableMap(data, map, index = 'number')
const data = [{name:'Emma',age: 123},{name:'Judy',age: 33}];
const map = {name: 'name',age: 'age'}
const result = scriptUtil.parseTableMap(data,map, 'number')
console.log(result)
[
{
"number": 1,
"name": "Emma",
"age": 123
},
{
"number": 2,
"name": "Judy",
"age": 33
}
]
objKeySort
- (object): Data source.
- (array): Field array that needs to be sorted.
const data = {name:'Emma',age: 123, sex: 'F'}
const sort = ['sex', 'age', 'name']
const result = scriptUtil.objKeySort(data,sort)
console.log(result)
{
sex: 'F'
age: 123,
name:'Emma',
}
getEditRow
var result = scriptUtil.getEditRow('table component id')
JSONToExcelConvertor
- (array): Data source.
- (array): Data title.
- (array): Data key, corresponding to data title.
- (string): Exported file name.
- (string): Exported file extension, including csv/xls.
scriptUtil.JSONToExcelConvertor({
data: [{ name: 'Emma', age: '12', sex: 'F' }],
dataTitle: ['name', 'age', 'sex'],
dataKey: ['name', 'age', 'sex'],
fileName: 'test file',
extension: 'xls',
});
scriptUtil Page Operation
closeCurrentPage
scriptUtil.closeCurrentPage();
openPage
- (string): Url of the target page and if no targets, open a new page.
- (string): Name of target property or page. You can select from blank (new page)/parent (parent page)/self (replace current page)/top (any locadable page)/name (page name)
- (array): Data key, corresponding to data title.
- (boolean): Feature. Whether or not support customization.
- (string): openConfig[JSON]. Page configruation.
// blank page
scriptUtil.openPage('url', '_blank');
// replace current page
scriptUtil.openPage('url', '_self');
// empty page with set size
scriptUtil.openPage('url', '_blank', true, '{"height":400,"width":400}');
showModal
scriptUtil.showModal(`{
"width":800,
"height":600,
"padding":{"paddingTop":24,"paddingBottom":24,"paddingLeft":24,"paddingRight":24},
"modelTitle":"title",
"needTitle":true,
"fontSize":14,
"fontColor":"#000000",
"titleBgColor":"#ebeef5",
"contentBgColor":"#ffffff",
"modalIsCenter":true,
"url":"/#/runtime-fullscreen/runtime-fullscreen/Page_401bf68ecd634809a7cf36fe44b73f59",
"sandbox":"allow-forms allow-same-origin allow-scripts allow-popups allow-downloads",
"isSandbox":true
}`)
closeModal
scriptUtil.closeModal();
closeParentModal
window.parent.scriptUtil.closeModal();
scriptUtil Database Operation
addDataTable
- dataSource: Table name.
- properties: Specific data to be added to the database.
- version: Version number.
- function: Callback parameter. Only accept one result parameter.
const param = {
'namespace.p1': 'p1',
'namespace.p2': 'p2',
};
scriptUtil.addDataTable(
{
dataSource: 'namespace.tableName',
properties: [param], //must be array type
version: 'V2',
},
function (res) {
console.log('res', res);
}
);
delDataTable
- dataSource: Table name.
- properties: Specific data to be deleted from the database. ID needs to be specified.
- version: Version number.
- function: Callback parameter. Only accept one result parameter.
const param = {
id: 'xxx', //can only delete data based on id.
};
scriptUtil.delDataTable(
{
dataSource: 'namespace.tableName',
properties: [param], //must be array type
version: 'V2',
},
function (res) {
console.log('res', res);
}
);
updateDataTable
- dataSource: Table name.
- properties: Specific data to be updated to the database.
- keys: Object. Similar to where conditions.
- version: Version number.
- function: Callback parameter. Only accept one result parameter.
//Update condition: code is 1623219467408
//Update result: comDetailAdd is Ningbo, Zhejiang Province
var dataSource = 'supyoung_companyreg.company_reg';
var param = {
comDetailAdd: 'Ningbo, Zhejiang Province', //field to be updated
};
var keys = {
'supyoung_companyreg.code': '1623219467408',//key must appear with namespace
};
scriptUtil.updateDataTable(
{
dataSource,
properties: [param], // must be array type
keys,
version: 'V2',
},
function (res) {
console.log('res', res);
}
);
queryDataTable
- dataSource: Table name.
- filters: Object.
- fields: Array. Optional. Column array and ; is used to separate multiple columns. When fields are empty, all columns are returned.
- order: Optional. Sorting order.
- distinct: Optional. Whether to deduplicate data. It is false when no input parameters by default and only valid when fields is not empty.
- pageIndex: optional. Start page of the query. It is 1 by default.
- pageSize: Optional. Page size of the query. It is 50 by default.
- Custom search conditions: Optional. Union set. ’%xxx%’ represents fuzzy matching.
- version: Version number.
- function: Callback parameter. Only accept one result parameter.
//Update condition: code is 1623219467408
//Update result: comDetailAdd is Ningbo, Zhejiang Province
var namespace = "supyoung_companyreg"
var dataSource = namespace+'.company_reg';
scriptUtil.queryDataTable(
{
dataSource,
filters: {
fields:['desc'],//search for specified field
order: [
{
"order": "code",//field to be sorted
"sort": "desc" //desc -descending order asc-ascending order
}
],
distinct: true,
pageIndex: 1,
pageSize: 5,
"supyoung_companyreg.company":"%xx%",//search for company named xx (namespace is required)
},
version: 'V2'
},
function(res) {
console.log('res', res);
}
);
callFunction
- path: Required. Service path, which can be template alias/template namespace.template alias for service under object template and template alias/instance alias or template namespace.template alias/instance alias for service under object instance.
- service: Required. Service alias or service namespace.service alias.
- params: Optional. Input parameters of the service.
- Calling service under object template
scriptUtil.callFunction('templateNamespace.templateName', 'callService', {a: 1});
- Calling service under object instance
scriptUtil.callFunction('templateNamespace.templateName/instanceName', 'callService', {a: 1})
.then(function(res){
console.log('then:res');
});
scriptUtil User Information
getUserInfo
scriptUtil.getUserInfo(function (res) {
// res is current user information
console.log('res', res);
});
getSessionUserInfo
scriptUtil.getSessionUserInfo();
setAuthority
scriptUtil.setAuthority();