Skip to main content

Frontend

Provides unified global components, public modules, utility functions, and Web Workers support for frontend development.

globals.Calc is an official built-in public module Type element that provides mathematical, logical, text, and date/time calculation functions. The globals.Calc element hierarchical structure is Meta (globals.Meta) → Type (globals.Calc), and developers can use app.getElement("globals.Calc") to get and use it directly.

modules.xxx series are official instance elements providing frontend data processing, user interface feedback, files and tools, message communication, and other functions. The element hierarchical structure is Meta (modules.Meta) → Type (modules.FrontType) → Instance, and developers can use app.getElement("modules.xxx") to get and use them directly.

Of course, developers can also create their own public modules and modules.xxx series elements, or modify the official elements provided by JitAi in their own App to implement their own encapsulation.

Calculation Components

globals.Calc

Global calculation component providing mathematical, logical, text, and date/time calculation functions.

Basic Usage

Basic Usage of Calculation Components
import { app } from 'jit';

// Get calculation component
const CALC = await app.getElement('globals.Calc');

// Use calculation functions
const result = CALC.SUM(10, 20, 30);
const text = CALC.CONCAT("Hello", "World");
const now = CALC.NOW();

Mathematical Calculation Functions

Function NameParametersReturn ValueFunction Description
SUM(...numbers: number[])numberSum multiple numbers
AVG(...numbers: number[])numberCalculate average
MAX(...numbers: number[])numberGet maximum value
MIN(...numbers: number[])numberGet minimum value
ABS(number: number)numberGet absolute value
ROUND(number: number, digits: number)numberRound to specified decimal places
TRUNCATE(number: number, digits: number)numberTruncate decimal places without rounding
POWER(base: number, exponent: number)numberPower operation base^exponent
MOD(dividend: number, divisor: number)numberModulo operation
RANDOM(min: number, max: number, decimal: number)numberGenerate random number in specified range and decimal places
CHINESEUPPER(number: number)stringConvert number to Chinese uppercase amount
ENGLISHUPPER(number: number)stringConvert number to English uppercase amount
TOSTRING(value: any)string | nullConvert to string, return null on failure
TONUMBER(value: any)number | nullConvert to number, return null on failure

Text Processing Functions

Function NameParametersReturn ValueFunction Description
CONCAT(...texts: any[])stringConcatenate multiple values to text
LEN(text: string)numberGet text length
LEFT(text: string, length: number)stringExtract specified length text from left
RIGHT(text: string, length: number)stringExtract specified length text from right
MID(text: string, start: number, length: number)stringExtract specified length text from specified position
TRIM(text: string)stringRemove leading and trailing spaces
REPLACE(text: string, oldText: string, newText: string)stringGlobal text replacement
INSERT(sourceText: string, start: number, length: number, replaceText: string)stringReplace text at specified position
LOCATE(searchText: string, sourceText: string)booleanCheck if contains specified text
IDCARDSEX(idCard: string)stringGet gender from ID card number ('男'/'女'/''')
IDCARDBIRTHDAY(idCard: string)stringGet birthday from ID card number (YYYY-MM-DD format)

Date and Time Functions

Function NameParametersReturn ValueFunction Description
NOW()stringGet current time (YYYY-MM-DD HH:mm:ss format)
TODAY()stringGet today's date (YYYY-MM-DD format)
DATEADD(date: string, number: number, unit?: string)string | nullDate addition/subtraction, unit optional: 'Y'/'y' (year), 'M'/'m' (month), 'D'/'d' (day), 'H'/'h' (hour), 'I'/'i' (minute), 'S'/'s' (second), default is day
DATEDELTA(date1: string, date2: string, unit?: string)number | nullCalculate date difference, unit same as DATEADD, returns date1-date2 difference
EXTRACT(date: string, unit?: string)number | nullExtract date part, unit optional: 'Y'/'y' (year), 'M'/'m' (month), 'D'/'d' (day), 'H'/'h' (hour), 'I'/'i' (minute), 'S'/'s' (second), 'Q'/'q' (quarter), default returns year
TIMESTAMPFORMAT(timestamp: number)stringConvert timestamp to date time string
DATESTR(date: string)stringConvert date to YYYYMMDD format string
DATE(year: number, month: number, day: number)stringConstruct date string (YYYY-MM-DD format)
MONTHDAYS(date: string)number | nullGet number of days in month for specified date
DAYOFYEAR(date: string)number | nullGet day of year for specified date
WEEKOFYEAR(date: string)numberGet week of year for specified date
WEEKDAYNUM(date: string)number | nullGet weekday number (1-7, Monday to Sunday)
WEEKDAYSTR(date: string)stringGet weekday text (Monday to Sunday)
MONTHSTART(date: string)string | nullGet first day of month for specified date
MONTHEND(date: string)string | nullGet last day of month for specified date
NETWORKDAYS(startDate: string, endDate: string)number | nullCalculate working days between two dates (excluding weekends and holidays)
WORKDAY(date: string, days: number, holidays?: any[])stringCalculate date after specified working days from specified date

Logical Judgment Functions

Function NameParametersReturn ValueFunction Description
IF(condition: any, trueValue: any, falseValue: any)anyConditional judgment, return trueValue if condition is true, otherwise return falseValue
IFS(...args: any[])anyMultiple conditional judgment, judge in order of condition-value pairs, return first satisfied value, last parameter as default value
AND(...conditions: any[])booleanLogical AND operation, return true only if all conditions are true
OR(...conditions: any[])booleanLogical OR operation, return true if any condition is true
ISEMPTY(value: any)booleanCheck if value is empty (null, undefined, empty string, empty array, empty object)
ISNOTEMPTY(value: any)booleanCheck if value is not empty
EMPTY()nullReturn empty value null
EMPTYSTR()stringReturn empty string ""
DEFAULTVALUE(value: T, defaultValue: T)TReturn defaultValue if value is empty, otherwise return value

Common Examples

Common Examples of Calculation Functions
const CALC = await app.getElement('globals.Calc');

// Mathematical calculations
const total = CALC.SUM(10, 20, 30); // 60
const avg = CALC.AVG(1, 2, 3, 4, 5); // 3
const rounded = CALC.ROUND(3.14159, 2); // 3.14
const random = CALC.RANDOM(1, 100, 0); // Random integer 1-100

// Text processing
const fullName = CALC.CONCAT("张", "三"); // "张三"
const length = CALC.LEN("Hello World"); // 11
const left3 = CALC.LEFT("Hello", 3); // "Hel"
const gender = CALC.IDCARDSEX("110101199001011234"); // "男"

// Date and time
const now = CALC.NOW(); // "2024-01-15 14:30:25"
const today = CALC.TODAY(); // "2024-01-15"
const nextWeek = CALC.DATEADD(today, 7, "D"); // "2024-01-22"
const year = CALC.EXTRACT(today, "Y"); // 2024

// Logical judgment
const result = CALC.IF(total > 50, "及格", "不及格"); // "及格"
const isEmpty = CALC.ISEMPTY(""); // true
const defaultName = CALC.DEFAULTVALUE(null, "匿名"); // "匿名"

Variable Management

globals.AppVar

Application variable configuration component providing frontend application-level variable configuration framework.

Basic Usage

Basic Usage of Application Variables
import { app } from 'jit';

// Get application variable configuration
const appVar = await app.getElement('globals.AppVar');

// Application variable configuration is a JSON object
console.log(appVar); // Output variable configuration

Component Features

FeatureDescription
Configuration FormatJSON object format variable configuration
ScopeFrontend application level
PurposeProvide variable definition framework and configuration foundation

globals.GlobalVar

Global variable component providing predefined time-related variables and user information.

Basic Usage

Basic Usage of Global Variables
import { app } from 'jit';

const globalVar = await app.getElement('globals.GlobalVar');

// Use time variables
const now = globalVar.currentTime;
const today = globalVar.today;
const currentUser = globalVar.currentUser;
Variable NameTypeFunction Description
currentTimeDatetimeCurrent time
todayDateRangeToday time range
yesterdayDateRangeYesterday time range
tomorrowDateRangeTomorrow time range
thisWeekDateRangeThis week time range
lastWeekDateRangeLast week time range
nextWeekDateRangeNext week time range
thisMonthDateRangeThis month time range
lastMonthDateRangeLast month time range
nextMonthDateRangeNext month time range
thisQuarterDateRangeThis quarter time range
lastQuarterDateRangeLast quarter time range
nextQuarterDateRangeNext quarter time range
thisYearDateRangeThis year time range
lastYearDateRangeLast year time range
nextYearDateRangeNext year time range

Dynamic Day Range Variables

Variable NameTypeFunction Description
last24HoursDateRangeLast 24 hours
last2DaysDateRangeLast 2 days
last3DaysDateRangeLast 3 days
last7DaysDateRangeLast 7 days
last15DaysDateRangeLast 15 days
last30DaysDateRangeLast 30 days
last60DaysDateRangeLast 60 days
last90DaysDateRangeLast 90 days
Variable NameTypeFunction Description
currentUserMemberCurrent logged-in user information

Data Processing

modules.DataHandler

Data processing module providing data conversion, filter conversion, and other functions.

Basic Usage

Basic Usage of Data Processing
import { app } from 'jit';

const { convertRowData, convertRowList, convertFilter, tableSet } = await app.getElement('modules.DataHandler');

// Use data conversion
const rowData = convertRowData(mappingDict, sourceVal, targetModelName, sourceModelName);
const filter = convertFilter(mappingDict, sourceVal);
const table = tableSet(tqlConfig);

Available Methods

Method NameParametersReturn ValueFunction Description
convertRowData(mappingDict: Record<string, any>, sourceVal: any, targetModelName: string, sourceModelName: string)Record<string, any> | undefinedConvert single row data format
convertRowList(mappingDict: Record<string, any>, sourceVal: any, targetModelName: string, sourceModelName: string)Record<string, any>[] | undefinedConvert multiple row data format
convertFilter(mappingDict: Record<string, any>, sourceVal?: string)string | nullConvert filter conditions
tableSet(tqlConfig: ITqlInitConfig)TableSetCreate table dataset object

User Interface Feedback

modules.FeedBack

Feedback component module providing message prompts, confirmation dialogs, loading states, and other UI feedback.

Basic Usage

Basic Usage of Feedback Components
import { app } from 'jit';

const { globalMessage, globalConfirm, openLoading, closeLoading } = await app.getElement('modules.FeedBack');

// Use feedback functions
globalMessage('success', 'Operation successful!');
const confirmed = await globalConfirm('Are you sure to delete?');
const loadingId = openLoading('Processing...');

Message Prompt Methods

Method NameParametersReturn ValueFunction Description
globalMessage(type: string, content: string | object)voidShow message prompt, type optional: 'success', 'error', 'warn', 'info'

Dialog Methods

Method NameParametersReturn ValueFunction Description
globalConfirm(content: string | Record<string, any>)Promise<string>Show confirmation dialog, return Promise<'true'|'false'>

Loading State Methods

Method NameParametersReturn ValueFunction Description
openLoading(text?: string)stringShow loading state, return unique loadingId
closeLoading(loadingId: string)voidClose specified ID loading state

Files and Tools

modules.Util

Utility module providing file processing, export, printing, and other common functions.

Basic Usage

Basic Usage of Utility Module
import { app } from 'jit';

const { exportExcel, uploadFile, printQrCode, generateJitList } = await app.getElement('modules.Util');

// Use utility functions
await exportExcel(exportConfig);
await uploadFile(file);
await printQrCode(qrConfig);

// Generate number list
const numberList = await generateJitList(5); // Generate JitList of [1,2,3,4,5]

File Processing Methods

Method NameParametersReturn ValueFunction Description
uploadFile(file: Record<string, any>, ...args: any[])Promise<any>Upload file to default storage
generateFile()FileGenerate file data type instance
fileTmpls.download(templateId: string)Promise<any>Download file template

Data Generation Methods

Method NameParametersReturn ValueFunction Description
generateJitList(len: number)Promise<JitList>Generate consecutive number array list based on input length, return JitList type data from 1 to len

Export Function Methods

Method NameParametersReturn ValueFunction Description
exportExcel(exportExcelConfig: ExportConfig)Promise<void>Export Excel file
exportExcelType(data: any, type: string)voidExport Excel by specified type
Method NameParametersReturn ValueFunction Description
printQrCode(data: QrCodeConfig)Promise<void>Print QR code
printAttachmentsInBulk(tmplName: Record<string, any>)Promise<void>Bulk print attachments

Page Operation Methods

Method NameParametersReturn ValueFunction Description
openPage(data: OpenPageConfig)voidOpen new page
log(type: 'log' | 'warn' | 'error', content: string)voidConsole log recording

Message Communication

modules.MessageHandler

Message processing module providing SMS sending and message notification functions.

Basic Usage

Basic Usage of Message Processing
import { app } from 'jit';

const { sendMsg, sendSms } = await app.getElement('modules.MessageHandler');

// Use message functions
await sendSms(smsFullName, smsConfig, receiver, params);
await sendMsg(receiver, msgData);

Available Methods

Method NameParametersReturn ValueFunction Description
sendSms(smsFullName: string, smsConfig: Record<string, any>, receiver: {receiverDict: ReceiverDict}, params: Record<string, any>)Promise<void>Send SMS notification
sendMsg(receiver: {receiverDict: ReceiverDict}, msgData: {msg: MsgData})Promise<void>Send message notification

Approval Processing

modules.ApproveHandle

Approval processing module providing approval task related functions.

Basic Usage

Basic Usage of Approval Processing
import { app } from 'jit';

const { applyTask } = await app.getElement('modules.ApproveHandle');

// Use approval functions
await applyTask(approveDict, workflowName, rowDataDict, modelName);

Available Methods

Method NameParametersReturn ValueFunction Description
applyTask(approveDict: Record<string, any>, workflowName: string, rowDataDict: Record<string, any>, modelName: string)Promise<void>Initiate approval process

External Integration

modules.ExternalApiHandle

External API call module providing unified external API access interface.

Basic Usage

Basic Usage of External API
import { app } from 'jit';

const { callExternalApi } = await app.getElement('modules.ExternalApiHandle');

// Use external API
await callExternalApi(fullName, apiName, headers, params, body);

Available Methods

Method NameParametersReturn ValueFunction Description
callExternalApi(fullName: string, apiName: string, headers: Record<string, any>, params: Record<string, any>, body: Record<string, any>)Promise<void>Call external API interface

Public Tools

modules.common

Public utility module providing common utility functions and components.

Basic Usage

Basic Usage of Public Tools
import { app } from 'jit';

const { downloadFile, FilePreviewer } = await app.getElement('modules.common');

// Use public tools
downloadFile(url);
FilePreviewer({ file: { url: 'fileUrl', type: 'application/pdf' } });

Utility Functions

Function NameParametersReturn ValueFunction Description
downloadFile(url: string)voidDownload file from specified URL

Available Components

Component NameParametersReturn ValueFunction Description
FilePreviewer({file: PreviewFile, fileList?: PreviewFile[], mode?: PLATFORM})voidFile preview function (direct call, no component return)

Exception Handling

modules.ExceptionHandler

Exception handling module providing unified error prompts and console output functions.

Basic Usage

Basic Usage of Exception Handling
import { app } from 'jit';

const { promptError, promptWarn, promptInfo, consoleError } = await app.getElement('modules.ExceptionHandler');

// Use exception handling
promptError('Operation failed');
promptWarn('Warning information');
consoleError('Error information');

Available Methods

Method NameParametersReturn ValueFunction Description
promptError(message: string)voidShow error prompt
promptWarn(message: string)voidShow warning prompt
promptInfo(message: string)voidShow information prompt
consoleError(message: string, responseData?: Record<string, any>)voidConsole error output

Multi-threading Support

workers.WebWorker

Web Worker support module providing basic encapsulation for multi-threaded computing capabilities.

Basic Usage

Basic Usage of WebWorker
import { app } from 'jit';

// Get WebWorker configuration
const webWorkerConfig = await app.getElement('workers.WebWorker');

// Use native Web Worker API
const worker = new Worker('/workers/calculation.js');
worker.postMessage(data);
worker.terminate();

Native API Usage

APIParametersReturn ValueFunction Description
new Worker(scriptURL)(scriptURL: string)WorkerCreate Web Worker instance
worker.postMessage(data)(data: any)voidSend message to Worker
worker.onmessage= (event: MessageEvent) => void-Event handler for listening to Worker return messages
worker.onerror= (event: ErrorEvent) => void-Event handler for listening to Worker errors
worker.terminate()()voidTerminate Worker execution
JitAI AssistantBeta
Powered by JitAI