| 12345678910111213141516171819202122232425262728293031323334 |
- /** 语句:log 打印信息(仅 console/UI,不写 log.txt) */
- const types = ['log']
- function parse(action, parseContext) {
- const { extractVarName } = parseContext
- const parsed = { type: 'log' }
- if (action.inVars && Array.isArray(action.inVars)) {
- parsed.inVars = action.inVars.map(v => extractVarName(v))
- } else parsed.inVars = []
- if (action.value) parsed.value = action.value
- return Object.assign({}, action, parsed)
- }
- async function execute(action, ctx) {
- const { variableContext, extractVarName, replaceVariablesInString } = ctx
- let message = ''
- if (action.inVars && action.inVars.length > 0) {
- const messages = action.inVars.map(varWithBraces => {
- const varName = extractVarName(varWithBraces)
- const v = variableContext[varName]
- return v !== undefined ? String(v) : varWithBraces
- })
- message = messages.join(' ')
- } else if (action.value) {
- message = replaceVariablesInString(action.value, variableContext)
- }
- if (typeof console !== 'undefined') console.log(message)
- if (typeof window !== 'undefined') {
- window.dispatchEvent(new CustomEvent('log-message', { detail: { message } }))
- }
- return { success: true }
- }
- module.exports = { types, parse, execute }
|