From 8348691e283723d65ff0d3bcd35e4d367efb3d0e Mon Sep 17 00:00:00 2001 From: qianlishi Date: Mon, 9 Jan 2023 10:08:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/MonacoEditor/index.vue | 132 ++++++++++++++++++ .../util/javascript-completion.js | 38 +++++ .../MonacoEditor/util/log-language.js | 58 ++++++++ .../MonacoEditor/util/sql-completion.js | 82 +++++++++++ .../designer/components/dynamicForm.vue | 81 +++++++---- .../bigscreenDesigner/designer/index.vue | 12 ++ .../configure/barCharts/widget-barchart.js | 73 ++++++---- 7 files changed, 422 insertions(+), 54 deletions(-) create mode 100644 report-ui/src/components/MonacoEditor/index.vue create mode 100644 report-ui/src/components/MonacoEditor/util/javascript-completion.js create mode 100644 report-ui/src/components/MonacoEditor/util/log-language.js create mode 100644 report-ui/src/components/MonacoEditor/util/sql-completion.js diff --git a/report-ui/src/components/MonacoEditor/index.vue b/report-ui/src/components/MonacoEditor/index.vue new file mode 100644 index 00000000..8f5325b1 --- /dev/null +++ b/report-ui/src/components/MonacoEditor/index.vue @@ -0,0 +1,132 @@ + + + + + diff --git a/report-ui/src/components/MonacoEditor/util/javascript-completion.js b/report-ui/src/components/MonacoEditor/util/javascript-completion.js new file mode 100644 index 00000000..3999cc29 --- /dev/null +++ b/report-ui/src/components/MonacoEditor/util/javascript-completion.js @@ -0,0 +1,38 @@ +import * as monaco from 'monaco-editor' +// js 有内置提示 +function createCompleter(getExtraHints) { + const createSuggestions = function (model, textUntilPosition) { + let text = model.getValue(); + textUntilPosition = textUntilPosition.replace(/[\*\[\]@\$\(\)]/g, "").replace(/(\s+|\.)/g, " "); + let arr = textUntilPosition.split(/[\s;]/); + let activeStr = arr[arr.length - 1]; + let len = activeStr.length; + let rexp = new RegExp("([^\\w]|^)" + activeStr + "\\w*", "gim"); + let match = text.match(rexp); + let mergeHints = Array.from(new Set([...getExtraHints(model)])) + .sort() + .filter(ele => { + let rexp = new RegExp(ele.substr(0, len), "gim"); + return (match && match.length === 1 && ele === activeStr) || + ele.length === 1 ? false : activeStr.match(rexp); + }); + return mergeHints.map(ele => ({ + label: ele, + kind: monaco.languages.CompletionItemKind.Text, + documentation: ele, + insertText: ele + })); + }; + return { + provideCompletionItems(model, position) { + let textUntilPosition = model.getValueInRange({ + startLineNumber: position.lineNumber, + startColumn: 1, + endLineNumber: position.lineNumber, + endColumn: position.column + }); + return { suggestions: createSuggestions(model, textUntilPosition) }; + } + } +} +export default createCompleter; \ No newline at end of file diff --git a/report-ui/src/components/MonacoEditor/util/log-language.js b/report-ui/src/components/MonacoEditor/util/log-language.js new file mode 100644 index 00000000..a3db9c6b --- /dev/null +++ b/report-ui/src/components/MonacoEditor/util/log-language.js @@ -0,0 +1,58 @@ +function registerLanguage(monaco) { + monaco.languages.register({ + id: "log" + }); + monaco.languages.setMonarchTokensProvider("log", { + tokenizer: { + root: [ + [/(^[=a-zA-Z].*|\d\s.*)/, "log-normal"], + [/\sERROR\s.*/, "log-error"], + [/\sWARN\s.*/, "log-warn"], + [/\sINFO\s.*/, "log-info"], + [ + /^([0-9]{4}||[0-9]{2})-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}(.[0-9]{3})?/, + "log-date", + ], + [ + /^[0-9]{2}\/[0-9]{2}\/[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}(.[0-9]{3})?/, + "log-date", + ], + [/(^\*\*Waiting queue:.*)/, "log-info"], + [/(^\*\*result tips:.*)/, "log-info"], + ], + }, + }); + monaco.editor.defineTheme("log", { + base: "vs", + inherit: true, + rules: [{ + token: "log-info", + foreground: "4b71ca" + }, + { + token: "log-error", + foreground: "ff0000", + fontStyle: "bold" + }, + { + token: "log-warn", + foreground: "FFA500" + }, + { + token: "log-date", + foreground: "008800" + }, + { + token: "log-normal", + foreground: "808080" + }, + ], + colors: { + "editor.lineHighlightBackground": "#ffffff", + "editorGutter.background": "#f7f7f7", + }, + }); + + } + + export default registerLanguage; \ No newline at end of file diff --git a/report-ui/src/components/MonacoEditor/util/sql-completion.js b/report-ui/src/components/MonacoEditor/util/sql-completion.js new file mode 100644 index 00000000..9ebcc029 --- /dev/null +++ b/report-ui/src/components/MonacoEditor/util/sql-completion.js @@ -0,0 +1,82 @@ +import * as monaco from 'monaco-editor' +const hints = [ + "SELECT", + "INSERT", + "DELETE", + "UPDATE", + "CREATE TABLE", + "DROP TABLE", + "ALTER TABLE", + "CREATE VIEW", + "DROP VIEW", + "CREATE INDEX", + "DROP INDEX", + "CREATE PROCEDURE", + "DROP PROCEDURE", + "CREATE TRIGGER", + "DROP TRIGGER", + "CREATE SCHEMA", + "DROP SCHEMA", + "CREATE DOMAIN", + "ALTER DOMAIN", + "DROP DOMAIN", + "GRANT", + "DENY", + "REVOKE", + "COMMIT", + "ROLLBACK", + "SET TRANSACTION", + "DECLARE", + "EXPLAN", + "OPEN", + "FETCH", + "CLOSE", + "PREPARE", + "EXECUTE", + "DESCRIBE", + "FROM", + "ORDER BY"] +function createCompleter(getExtraHints) { + const createSuggestions = function (model, textUntilPosition) { + let text = model.getValue(); + textUntilPosition = textUntilPosition.replace(/[\*\[\]@\$\(\)]/g, "").replace(/(\s+|\.)/g, " "); + let arr = textUntilPosition.split(/[\s;]/); + let activeStr = arr[arr.length - 1]; + let len = activeStr.length; + let rexp = new RegExp("([^\\w]|^)" + activeStr + "\\w*", "gim"); + let match = text.match(rexp); + let textHints = !match ? [] : + match.map(ele => { + let rexp = new RegExp(activeStr, "gim"); + let search = ele.search(rexp); + return ele.substr(search); + }); + let mergeHints = Array.from(new Set([...hints, ...textHints, ...getExtraHints(model)])) + .sort() + .filter(ele => { + let rexp = new RegExp(ele.substr(0, len), "gim"); + return (match && match.length === 1 && ele === activeStr) || + ele.length === 1 ? false : activeStr.match(rexp); + }); + return mergeHints.map(ele => ({ + label: ele, + kind: hints.indexOf(ele) > -1 ? + monaco.languages.CompletionItemKind.Keyword : + monaco.languages.CompletionItemKind.Text, + documentation: ele, + insertText: ele + })); + }; + return { + provideCompletionItems(model, position) { + let textUntilPosition = model.getValueInRange({ + startLineNumber: position.lineNumber, + startColumn: 1, + endLineNumber: position.lineNumber, + endColumn: position.column + }); + return { suggestions: createSuggestions(model, textUntilPosition) }; + } + } +} +export default createCompleter; diff --git a/report-ui/src/views/bigscreenDesigner/designer/components/dynamicForm.vue b/report-ui/src/views/bigscreenDesigner/designer/components/dynamicForm.vue index 587cf649..ca74cb6d 100644 --- a/report-ui/src/views/bigscreenDesigner/designer/components/dynamicForm.vue +++ b/report-ui/src/views/bigscreenDesigner/designer/components/dynamicForm.vue @@ -12,8 +12,8 @@ 编辑 + 添加事件 + 确 定 + + + + + 取 消 + 确 定 + + + @change="changed($event, item.name)" + />
@@ -169,7 +195,7 @@ {} - } + default: () => {}, + }, }, data() { return { formData: {}, inputShow: {}, // 控制表单是否显示 dialogVisibleStaticData: false, + methodsVisible: false, validationRules: "", optionsJavascript: { mode: "text/javascript", @@ -318,9 +347,9 @@ export default { styleActiveLine: true, // 高亮选中行 hintOptions: { - completeSingle: true // 当匹配只有一项的时候是否自动补全 - } - } + completeSingle: true, // 当匹配只有一项的时候是否自动补全 + }, + }, }; }, watch: { @@ -330,7 +359,7 @@ export default { options(val) { this.setDefaultValue(); this.isShowData(); - } + }, }, created() { this.isShowData(); @@ -365,6 +394,7 @@ export default { saveData() { this.$emit("onChanged", this.formData); this.dialogVisibleStaticData = false; + this.methodsVisible = false; }, // 静态数据 addStaticData() { @@ -372,6 +402,7 @@ export default { }, handleClose() { this.dialogVisibleStaticData = false; + this.methodsVisible = false; }, // 组件属性 数据是否展示动态还是静态数据 isShowData() { @@ -386,7 +417,7 @@ export default { data.push(this.options[i]); } } - data.forEach(el => { + data.forEach((el) => { if (el.relactiveDomValue != currentData.value) { this.inputShow[el.name] = false; } @@ -404,7 +435,7 @@ export default { } else if (Object.prototype.toString.call(obj) == "[object Array]") { for (let j = 0; j < obj.length; j++) { const list = obj[j].list; - list.forEach(el => { + list.forEach((el) => { this.formData[el.name] = el.value; }); } @@ -416,8 +447,8 @@ export default { // 是否显示 那种格式 isShowForm(val, type) { return Object.prototype.toString.call(val) == type; - } - } + }, + }, }; diff --git a/report-ui/src/views/bigscreenDesigner/designer/index.vue b/report-ui/src/views/bigscreenDesigner/designer/index.vue index 124df5eb..ab0e65f2 100644 --- a/report-ui/src/views/bigscreenDesigner/designer/index.vue +++ b/report-ui/src/views/bigscreenDesigner/designer/index.vue @@ -270,6 +270,17 @@ @onChanged="(val) => widgetValueChanged('position', val)" /> + + +
@@ -360,6 +371,7 @@ export default { top: 0, zIndex: 0, }, + methods: {}, }, // options属性是从工具栏中拿到的tools中拿到 options: [], diff --git a/report-ui/src/views/bigscreenDesigner/designer/tools/configure/barCharts/widget-barchart.js b/report-ui/src/views/bigscreenDesigner/designer/tools/configure/barCharts/widget-barchart.js index 673d26f6..5ff6c9d4 100644 --- a/report-ui/src/views/bigscreenDesigner/designer/tools/configure/barCharts/widget-barchart.js +++ b/report-ui/src/views/bigscreenDesigner/designer/tools/configure/barCharts/widget-barchart.js @@ -3,8 +3,8 @@ * @version: * @Author: qianlishi * @Date: 2021-08-29 07:21:45 - * @LastEditors: qianlishi - * @LastEditTime: 2021-09-28 14:08:29 + * @LastEditors: qianlishi qianlishi@anji-plus.com + * @LastEditTime: 2023-01-09 09:53:31 */ export const widgetBarchart = { code: 'widget-barchart', @@ -111,10 +111,10 @@ export const widgetBarchart = { required: false, placeholder: '', selectOptions: [ - {code: 'normal', name: '正常'}, - {code: 'bold', name: '粗体'}, - {code: 'bolder', name: '特粗体'}, - {code: 'lighter', name: '细体'} + { code: 'normal', name: '正常' }, + { code: 'bold', name: '粗体' }, + { code: 'bolder', name: '特粗体' }, + { code: 'lighter', name: '细体' } ], value: 'normal' }, @@ -125,9 +125,9 @@ export const widgetBarchart = { required: false, placeholder: '', selectOptions: [ - {code: 'normal', name: '正常'}, - {code: 'italic', name: 'italic斜体'}, - {code: 'oblique', name: 'oblique斜体'}, + { code: 'normal', name: '正常' }, + { code: 'italic', name: 'italic斜体' }, + { code: 'oblique', name: 'oblique斜体' }, ], value: 'normal' }, @@ -138,9 +138,9 @@ export const widgetBarchart = { required: false, placeholder: '', selectOptions: [ - {code: 'center', name: '居中'}, - {code: 'left', name: '左对齐'}, - {code: 'right', name: '右对齐'}, + { code: 'center', name: '居中' }, + { code: 'left', name: '左对齐' }, + { code: 'right', name: '右对齐' }, ], value: 'center' }, @@ -175,10 +175,10 @@ export const widgetBarchart = { required: false, placeholder: '', selectOptions: [ - {code: 'normal', name: '正常'}, - {code: 'bold', name: '粗体'}, - {code: 'bolder', name: '特粗体'}, - {code: 'lighter', name: '细体'} + { code: 'normal', name: '正常' }, + { code: 'bold', name: '粗体' }, + { code: 'bolder', name: '特粗体' }, + { code: 'lighter', name: '细体' } ], value: 'normal' }, @@ -189,9 +189,9 @@ export const widgetBarchart = { required: false, placeholder: '', selectOptions: [ - {code: 'normal', name: '正常'}, - {code: 'italic', name: 'italic斜体'}, - {code: 'oblique', name: 'oblique斜体'}, + { code: 'normal', name: '正常' }, + { code: 'italic', name: 'italic斜体' }, + { code: 'oblique', name: 'oblique斜体' }, ], value: 'normal' }, @@ -481,10 +481,10 @@ export const widgetBarchart = { required: false, placeholder: '', selectOptions: [ - {code: 'normal', name: '正常'}, - {code: 'bold', name: '粗体'}, - {code: 'bolder', name: '特粗体'}, - {code: 'lighter', name: '细体'} + { code: 'normal', name: '正常' }, + { code: 'bold', name: '粗体' }, + { code: 'bolder', name: '特粗体' }, + { code: 'lighter', name: '细体' } ], value: 'normal' }, @@ -553,7 +553,7 @@ export const widgetBarchart = { label: '', name: 'customColor', required: false, - value: [{color: '#ff7f50'}, {color: '#87cefa'}, {color: '#da70d6'}, {color: '#32cd32'}, {color: '#6495ed'}], + value: [{ color: '#ff7f50' }, { color: '#87cefa' }, { color: '#da70d6' }, { color: '#32cd32' }, { color: '#6495ed' }], }, ], }, @@ -597,11 +597,11 @@ export const widgetBarchart = { relactiveDom: 'dataType', relactiveDomValue: 'staticData', value: [ - {"axis": "苹果", "data": 1000}, - {"axis": "三星", "data": 2229}, - {"axis": "小米", "data": 3879}, - {"axis": "oppo", "data": 2379}, - {"axis": "vivo", "data": 4079}, + { "axis": "苹果", "data": 1000 }, + { "axis": "三星", "data": 2229 }, + { "axis": "小米", "data": 3879 }, + { "axis": "oppo", "data": 2379 }, + { "axis": "vivo", "data": 4079 }, ], }, { @@ -652,5 +652,20 @@ export const widgetBarchart = { value: 200, }, ], + // 事件 + methods: [ + { + type: 'methods', + label: '前置钩子', + name: 'beforeMethods', + value: 'function beforeMethods(data){\n\t//自定义脚本内容1\n\treturn data;\n}', + }, + { + type: 'methods', + label: '后置钩子', + name: 'afterMethods', + value: 'function afterMethods(data){\n\t//自定义脚本内容2\n\treturn data;\n}', + }, + ] } }