From 682e5eec556bbddb4419047246abcba17b19dfcb Mon Sep 17 00:00:00 2001 From: xiechong1 Date: Fri, 10 Dec 2021 11:34:13 +0800 Subject: [PATCH 1/5] =?UTF-8?q?fixed:=E4=BF=AE=E5=A4=8D=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E8=AF=AD=E5=8F=A5=E5=85=A5=E5=8F=82=E4=B8=BA?= =?UTF-8?q?underfind=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/util/condition.ts | 98 ++++++++++++++++--------------------------- 1 file changed, 37 insertions(+), 61 deletions(-) diff --git a/src/util/condition.ts b/src/util/condition.ts index 7d7542b..4cf13eb 100644 --- a/src/util/condition.ts +++ b/src/util/condition.ts @@ -23,12 +23,16 @@ export interface ConditionConfig { } export default function ConditionHelper(condition: ConditionConfig | undefined, datas: { record?: object, data: object[], step: number }): boolean { + // 条件语句模版 + let conditionTemplate = ''; + // 条件语句模版入参 + let statementParams = {}; + if (condition === undefined || ((condition.statement === undefined || condition.statement === '') && (condition.template === undefined || condition.template === ''))) { return true } else { if (condition.template) { - const statementTemplate = template(condition.template) - let statementParams = {} + conditionTemplate = condition.template; if (condition.params) { condition.params.forEach((param) => { if (param.field !== undefined && param.data !== undefined) { @@ -41,46 +45,15 @@ export default function ConditionHelper(condition: ConditionConfig | undefined, } }) } - - try { - const statement = statementTemplate(statementParams) - try { - const result = eval(statement) - if (result) { - if (condition.debug) { - console.info('CCMS debug: condition - `' + statement + '` => true') - } - return true - } else { - if (condition.debug) { - console.info('CCMS debug: condition - `' + statement + '` => false') - } - return false - } - } catch (e) { - if (condition.debug) { - console.info('CCMS debug: condition - `' + condition.template + '` => `' + statement + '` => error') - } - console.error('表单项展示条件语句执行错误。', condition.template, statement) - return false - } - } catch (e) { - if (condition.debug) { - console.info('CCMS debug: condition - `' + condition.template + '` => error') - } - console.error('表单项展示条件语句执行错误。', condition.template) - return false - } } else { // 用于兼容旧版本中的通配符 // V2新增逻辑段 - 开始 // const statementTemplate = template(condition.statement) // V2新增逻辑段 - 结束 // V2移除逻辑段 - 开始 - const statementPolyfill = condition.statement?.replace(/([^\$])\{/g, '$1${') - const statementTemplate = template(statementPolyfill) + conditionTemplate = condition.statement?.replace(/([^\$])\{/g, '$1${') || ''; // V2移除逻辑段 - 结束 - let statementParams = {} + if (condition.params) { condition.params.forEach((param) => { if (param.field !== undefined && param.data !== undefined) { @@ -92,36 +65,39 @@ export default function ConditionHelper(condition: ConditionConfig | undefined, } }) } - + } + + return execConditionHandler(condition, conditionTemplate, statementParams); + } +} + +// 执行条件语句,返回结果 +const execConditionHandler = (condition: ConditionConfig | undefined, conditionTemplate: string, statementParams: object): boolean => { + try { + if (Object.values(statementParams).some((param) => param === undefined)) { + if (condition?.debug) { + console.info(`CCMS debug: condition ${conditionTemplate} => false`); + } + return false + } else { + const statement = template(conditionTemplate)(statementParams); + try { - const statement = statementTemplate(statementParams) - try { - const result = eval(statement) - if (result) { - if (condition.debug) { - console.info('CCMS debug: condition - `' + statement + '` => true') - } - return true - } else { - if (condition.debug) { - console.info('CCMS debug: condition - `' + statement + '` => false') - } - return false - } - } catch (e) { - if (condition.debug) { - console.info('CCMS debug: condition - `' + condition.statement + '` => `' + statement + '` => error') - } - console.error('表单项展示条件语句执行错误。', condition.statement, statement) - return false + const result = eval(statement); + if (condition?.debug) { + console.info(`CCMS debug: condition ${statement} => ${result}`); } + return result; } catch (e) { - if (condition.debug) { - console.info('CCMS debug: condition - `' + condition.statement + '` => error') - } - console.error('表单项展示条件语句执行错误。', condition.statement) + console.error('表单项展示条件语句执行错误。', conditionTemplate, statement); return false } } + } catch (e) { + if (condition?.debug) { + console.info('CCMS debug: condition - `' + conditionTemplate + '` => error'); + } + console.error('表单项展示条件语句执行错误。', conditionTemplate); + return false; } -} \ No newline at end of file +} \ No newline at end of file -- Gitee From c3cd84dd5d112d1f546dbfe25ea8ab0a38c52ce4 Mon Sep 17 00:00:00 2001 From: xiechong1 Date: Mon, 20 Dec 2021 16:54:39 +0800 Subject: [PATCH 2/5] =?UTF-8?q?change:=E6=A0=BC=E5=BC=8F=E6=A0=87=E5=87=86?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/util/condition.ts | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/util/condition.ts b/src/util/condition.ts index 4cf13eb..a8358a6 100644 --- a/src/util/condition.ts +++ b/src/util/condition.ts @@ -1,6 +1,6 @@ -import { set, cloneDeep, template } from "lodash" -import { ParamConfig } from "../interface"; -import ParamHelper from "./param"; +import { set, cloneDeep, template } from 'lodash' +import { ParamConfig } from '../interface' +import ParamHelper from './param' export interface ConditionConfig { /** @@ -22,17 +22,17 @@ export interface ConditionConfig { debug?: boolean } -export default function ConditionHelper(condition: ConditionConfig | undefined, datas: { record?: object, data: object[], step: number }): boolean { +export default function ConditionHelper (condition: ConditionConfig | undefined, datas: { record?: object, data: object[], step: number }): boolean { // 条件语句模版 - let conditionTemplate = ''; + let conditionTemplate = '' // 条件语句模版入参 - let statementParams = {}; - + let statementParams = {} + if (condition === undefined || ((condition.statement === undefined || condition.statement === '') && (condition.template === undefined || condition.template === ''))) { return true } else { if (condition.template) { - conditionTemplate = condition.template; + conditionTemplate = condition.template if (condition.params) { condition.params.forEach((param) => { if (param.field !== undefined && param.data !== undefined) { @@ -51,7 +51,7 @@ export default function ConditionHelper(condition: ConditionConfig | undefined, // const statementTemplate = template(condition.statement) // V2新增逻辑段 - 结束 // V2移除逻辑段 - 开始 - conditionTemplate = condition.statement?.replace(/([^\$])\{/g, '$1${') || ''; + conditionTemplate = condition.statement?.replace(/([^\$])\{/g, '$1${') || '' // V2移除逻辑段 - 结束 if (condition.params) { @@ -67,7 +67,7 @@ export default function ConditionHelper(condition: ConditionConfig | undefined, } } - return execConditionHandler(condition, conditionTemplate, statementParams); + return execConditionHandler(condition, conditionTemplate, statementParams) } } @@ -76,28 +76,28 @@ const execConditionHandler = (condition: ConditionConfig | undefined, conditionT try { if (Object.values(statementParams).some((param) => param === undefined)) { if (condition?.debug) { - console.info(`CCMS debug: condition ${conditionTemplate} => false`); + console.info(`CCMS debug: condition ${conditionTemplate} => false`) } return false } else { - const statement = template(conditionTemplate)(statementParams); + const statement = template(conditionTemplate)(statementParams) try { - const result = eval(statement); + const result = eval(statement) if (condition?.debug) { - console.info(`CCMS debug: condition ${statement} => ${result}`); + console.info(`CCMS debug: condition ${statement} => ${result}`) } - return result; + return result } catch (e) { - console.error('表单项展示条件语句执行错误。', conditionTemplate, statement); + console.error('表单项展示条件语句执行错误。', conditionTemplate, statement) return false } } } catch (e) { if (condition?.debug) { - console.info('CCMS debug: condition - `' + conditionTemplate + '` => error'); + console.info('CCMS debug: condition - `' + conditionTemplate + '` => error') } - console.error('表单项展示条件语句执行错误。', conditionTemplate); - return false; + console.error('表单项展示条件语句执行错误。', conditionTemplate) + return false } -} \ No newline at end of file +} -- Gitee From 404f4c01f499b649955624457046fa423b3c8e51 Mon Sep 17 00:00:00 2001 From: xiechong1 Date: Thu, 20 Jan 2022 22:13:02 +0800 Subject: [PATCH 3/5] =?UTF-8?q?feat:=E5=A2=9E=E5=8A=A0=E8=A1=A8=E6=A0=BC?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E6=8C=89=E9=92=AE=E8=B7=B3=E8=BD=AC=E7=AC=AC?= =?UTF-8?q?=E4=B8=89=E6=96=B9=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/steps/table/index.tsx | 47 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index 72111dc..b50eefa 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -54,7 +54,7 @@ export interface TableOperationConfig { level?: 'normal' | 'primary' | 'danger' check?: { enable: false } | TableOperationCheckConfig confirm?: { enable: false } | TableOperationConfirmConfig - handle: TableCCMSOperationConfig + handle: TableCCMSOperationConfig | TableLinkOperationConfig condition?: ConditionConfig } @@ -69,6 +69,15 @@ export interface TableCCMSOperationConfig { debug?: boolean } +export interface TableLinkOperationConfig { + type: 'link' + target: '_blank' | '_self' + targetURL: string + params?: { field: string, data: ParamConfig }[] + callback?: boolean + debug?: boolean +} + interface TableOperationCheckConfig { enable: true interface: InterfaceConfig @@ -338,6 +347,42 @@ export default class TableStep extends Step { window.open(`${targetURL}${targetKey}`) } } + + // 当按钮的响应类型是第三方链接时 + if (operation.handle.type === 'link') { + const params = {} + if (operation.handle.params !== undefined) { + for (const { field, data: dataConfig } of operation.handle.params) { + const value = getParam(dataConfig, { record, data, step }) + set(params, field, value) + } + + if (operation.handle.debug) { + console.log('CCMS debug: operation - operation.handle.type === link', params) + } + + // 提取跳转URL地址,合并URL参数拼接 + const targetURL = operation.handle.targetURL || '' + const { url, query, fragmentIdentifier } = queryString.parseUrl(targetURL, { arrayFormat: 'bracket', parseFragmentIdentifier: true }) + const jumpUrl = queryString.stringifyUrl({ url, query: { ...query, ...params }, fragmentIdentifier: fragmentIdentifier?.replace('/', '') }, { arrayFormat: 'bracket' }) || '' + + this.urlJumpHandler(jumpUrl, operation.handle.target) + } + } + } + + /** + * 链接跳转处理方法 + * @param url 跳转地址 + * @param target 跳转方式 + */ + urlJumpHandler = (url: string, target: string) => { + const a = document.createElement('a') + document.body.appendChild(a) + a.href = url + a.target = target + a.click() + document.body.removeChild(a) } /** -- Gitee From 7c0be189f76f9bb31bfba0d488f61075f982548e Mon Sep 17 00:00:00 2001 From: xiechong1 Date: Fri, 21 Jan 2022 20:09:41 +0800 Subject: [PATCH 4/5] =?UTF-8?q?fixed:=E5=A2=9E=E5=BC=BA=E4=BA=86=E8=A1=A8?= =?UTF-8?q?=E6=A0=BC=E6=93=8D=E4=BD=9C=E6=8C=89=E9=92=AE=E7=AC=AC=E4=B8=89?= =?UTF-8?q?=E6=96=B9=E8=BF=9E=E6=8E=A5=E7=9A=84=E5=85=BC=E5=AE=B9=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/steps/table/index.tsx | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index b50eefa..ac82304 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -363,14 +363,34 @@ export default class TableStep extends Step { // 提取跳转URL地址,合并URL参数拼接 const targetURL = operation.handle.targetURL || '' - const { url, query, fragmentIdentifier } = queryString.parseUrl(targetURL, { arrayFormat: 'bracket', parseFragmentIdentifier: true }) - const jumpUrl = queryString.stringifyUrl({ url, query: { ...query, ...params }, fragmentIdentifier: fragmentIdentifier?.replace('/', '') }, { arrayFormat: 'bracket' }) || '' + const urlParams = this.queryUrlParams(targetURL) + const query = urlParams.paramsResult + const hash = urlParams.hashResult.hash?.replace('#/', '') + const url = targetURL?.split('#')[0]?.split('?')[0] + // const { url, query, fragmentIdentifier } = queryString.parseUrl(targetURL, { arrayFormat: 'bracket', parseFragmentIdentifier: true }) + const jumpUrl = queryString.stringifyUrl({ url, query: { ...query, ...params }, fragmentIdentifier: hash }, { arrayFormat: 'bracket' }) || '' this.urlJumpHandler(jumpUrl, operation.handle.target) } } } + /** + * 获取URL中的路由和参数 + * @param url url地址 + */ + queryUrlParams = (url: string) => { + const paramsResult: any = {} + const hashResult: any = {} + const paramReg = /([^?=&#]+)=([^?=&#]+)/g + const hashReg = /#[^?=&#]+/g + // eslint-disable-next-line no-return-assign + url.replace(paramReg, (n, x, y) => paramsResult[x] = y) + // eslint-disable-next-line no-return-assign + url.replace(hashReg, (n) => hashResult.hash = n) + return { paramsResult, hashResult } + } + /** * 链接跳转处理方法 * @param url 跳转地址 -- Gitee From 81266e86e464e12b1cb4bc3c39e032d97703ce51 Mon Sep 17 00:00:00 2001 From: xiechong1 Date: Wed, 23 Feb 2022 12:43:07 +0800 Subject: [PATCH 5/5] =?UTF-8?q?fixed:=E4=BF=AE=E5=A4=8D=E8=B7=B3=E8=BD=AC?= =?UTF-8?q?=E7=AC=AC=E4=B8=89=E6=96=B9=E9=93=BE=E6=8E=A5=E7=9A=84=E6=8B=BC?= =?UTF-8?q?=E6=8E=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/steps/table/index.tsx | 49 +++++++-------------------------------- 1 file changed, 9 insertions(+), 40 deletions(-) diff --git a/src/steps/table/index.tsx b/src/steps/table/index.tsx index ac82304..a3a5dbd 100644 --- a/src/steps/table/index.tsx +++ b/src/steps/table/index.tsx @@ -361,50 +361,19 @@ export default class TableStep extends Step { console.log('CCMS debug: operation - operation.handle.type === link', params) } - // 提取跳转URL地址,合并URL参数拼接 - const targetURL = operation.handle.targetURL || '' - const urlParams = this.queryUrlParams(targetURL) - const query = urlParams.paramsResult - const hash = urlParams.hashResult.hash?.replace('#/', '') - const url = targetURL?.split('#')[0]?.split('?')[0] - // const { url, query, fragmentIdentifier } = queryString.parseUrl(targetURL, { arrayFormat: 'bracket', parseFragmentIdentifier: true }) - const jumpUrl = queryString.stringifyUrl({ url, query: { ...query, ...params }, fragmentIdentifier: hash }, { arrayFormat: 'bracket' }) || '' - - this.urlJumpHandler(jumpUrl, operation.handle.target) + const targetURL = operation.handle.targetURL + const { query } = queryString.parseUrl(targetURL, { arrayFormat: 'bracket' }) + const targetKey = queryString.stringifyUrl({ url: '', query: { ...query, ...params } }, { arrayFormat: 'bracket' }) || '' + const jumpUrl = `${targetURL}${targetKey}` + if (operation.handle.target === '_blank') { + window.open(jumpUrl) + } else { + window.location.href = jumpUrl + } } } } - /** - * 获取URL中的路由和参数 - * @param url url地址 - */ - queryUrlParams = (url: string) => { - const paramsResult: any = {} - const hashResult: any = {} - const paramReg = /([^?=&#]+)=([^?=&#]+)/g - const hashReg = /#[^?=&#]+/g - // eslint-disable-next-line no-return-assign - url.replace(paramReg, (n, x, y) => paramsResult[x] = y) - // eslint-disable-next-line no-return-assign - url.replace(hashReg, (n) => hashResult.hash = n) - return { paramsResult, hashResult } - } - - /** - * 链接跳转处理方法 - * @param url 跳转地址 - * @param target 跳转方式 - */ - urlJumpHandler = (url: string, target: string) => { - const a = document.createElement('a') - document.body.appendChild(a) - a.href = url - a.target = target - a.click() - document.body.removeChild(a) - } - /** * 渲染 操作二次确认弹窗 * @param props -- Gitee