From 1a6c5f3a2fd35484d533f79782adf2006bcb209d Mon Sep 17 00:00:00 2001 From: mjh <741600436@qq.com> Date: Sun, 1 May 2022 01:44:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4vite-plugin-monaco-editor-nls?= =?UTF-8?q?,=E4=BF=AE=E5=A4=8D=E5=B7=B2=E7=9F=A5bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.production | 4 +-- build/vite/monaco/index.ts | 27 ------------------- package.json | 1 - src/components/Custom/MonacoEditor/index.vue | 6 ++--- .../Custom/MonacoEditor/langs/tpl.ts | 16 +++++++++++ src/components/registerGlobComp.ts | 9 +------ src/views/tool/gen/edit/BaseInfo.vue | 10 ++++--- src/views/tool/gen/edit/index.vue | 4 +-- src/views/tool/gen/modal/preview/index.vue | 2 +- src/views/tool/tpl/modal/diff/index.vue | 3 ++- src/views/tool/tpl/modal/editor/index.vue | 4 +-- vite.config.ts | 5 +--- 12 files changed, 36 insertions(+), 55 deletions(-) delete mode 100644 build/vite/monaco/index.ts diff --git a/.env.production b/.env.production index 48b63e7..a976772 100644 --- a/.env.production +++ b/.env.production @@ -1,7 +1,7 @@ # 是否开启mock VITE_USE_MOCK=true # 接口地址 可以由nginx做转发或者直接写实际地址 -VITE_GLOB_API_URL=/api +VITE_GLOB_API_URL=/basic-api # 文件上传地址 可以由nginx做转发或者直接写实际地址 VITE_GLOB_UPLOAD_URL=/upload # 接口地址前缀,有些系统所有接口地址都有前缀,可以在这里统一加,方便切换 @@ -13,7 +13,7 @@ VITE_PUBLIC_PATH=/ # 打包是否输出gz|br文件 # 可选: gzip | brotli | none # 也可以有多个, 例如 ‘gzip’|'brotli',这样会同时生成 .gz和.br文件 -VITE_BUILD_COMPRESS='gzip' +VITE_BUILD_COMPRESS='none' # 打包是否压缩图片 VITE_USE_IMAGEMIN=false # 打包是否开启pwa功能 diff --git a/build/vite/monaco/index.ts b/build/vite/monaco/index.ts deleted file mode 100644 index 89af179..0000000 --- a/build/vite/monaco/index.ts +++ /dev/null @@ -1,27 +0,0 @@ -/* - * @version: - * @Company: - * @Description: - * @FilePath: \build\vite\monaco\index.ts - */ -import MonacoEditorNlsPlugin, { - esbuildPluginMonacoEditorNls, - Languages, -} from 'vite-plugin-monaco-editor-nls'; - -const prefix = `monaco-editor/esm/vs`; - -export default { - optimizeDeps: { - include: [`${prefix}/language/typescript/ts.worker`, `${prefix}/editor/editor.worker`], - /** vite 版本需要大于等于2.3.0 */ - esbuildOptions: { - plugins: [ - esbuildPluginMonacoEditorNls({ - locale: Languages.zh_hans, - }), - ], - }, - }, - plugins: [MonacoEditorNlsPlugin({ locale: Languages.zh_hans })], -}; diff --git a/package.json b/package.json index b7b5a4d..e464065 100644 --- a/package.json +++ b/package.json @@ -141,7 +141,6 @@ "vite-plugin-imagemin": "^0.6.1", "vite-plugin-mkcert": "^1.6.0", "vite-plugin-mock": "^2.9.6", - "vite-plugin-monaco-editor-nls": "^1.0.8", "vite-plugin-purge-icons": "^0.8.1", "vite-plugin-pwa": "^0.11.13", "vite-plugin-style-import": "^2.0.0", diff --git a/src/components/Custom/MonacoEditor/index.vue b/src/components/Custom/MonacoEditor/index.vue index 4e54f5a..59443ac 100644 --- a/src/components/Custom/MonacoEditor/index.vue +++ b/src/components/Custom/MonacoEditor/index.vue @@ -44,7 +44,7 @@ }, }, setup(props, { emit }) { - let editor, + let editor: any = ref(null), __prevent_trigger_change_event = false; let diffEditor: any = ref(null); const monacoEditor: any = ref(null); @@ -53,9 +53,7 @@ watch( () => props.modelValue, (newValue) => { - // newValue && editor.setValue(newValue); const model = editor.getModel(); - console.log('new', newValue !== model.getValue()); if (newValue !== model.getValue()) { editor.pushUndoStop(); __prevent_trigger_change_event = true; @@ -144,7 +142,7 @@ * 格式化代码 */ editor?.getAction('editor.action.formatDocument').run(); - },200); + }, 200); (window as any).MonacoEnvironment = { getWorker(_, label) { if (label === 'json') { diff --git a/src/components/Custom/MonacoEditor/langs/tpl.ts b/src/components/Custom/MonacoEditor/langs/tpl.ts index 19dc3c8..1b46612 100644 --- a/src/components/Custom/MonacoEditor/langs/tpl.ts +++ b/src/components/Custom/MonacoEditor/langs/tpl.ts @@ -169,6 +169,14 @@ const keywords = (range) => label: 'GoField', detail: 'GO字段名', }, + { + label: 'TsType', + detail: 'TypeScript类型', + }, + { + label: 'TsField', + detail: 'TypeScript字段名', + }, { label: 'IsPk', detail: '是否主键(1是)', @@ -389,6 +397,14 @@ const keywords = (range) => label: 'GoField', detail: 'GO字段名', }, + { + label: 'TsType', + detail: 'TypeScript类型', + }, + { + label: 'TsField', + detail: 'TypeScript字段名', + }, { label: 'IsPk', detail: '是否主键(1是)', diff --git a/src/components/registerGlobComp.ts b/src/components/registerGlobComp.ts index a673970..1c52ee3 100644 --- a/src/components/registerGlobComp.ts +++ b/src/components/registerGlobComp.ts @@ -17,12 +17,5 @@ export function registerGlobComp(app: App) { table: {}, }; VXETable.use(VXETablePluginAntd); - app - .use(Input) - .use(Button) - .use(Select) - .use(Switch) - .use(Layout) - .use(hljsVuePlugin) - .use(VXETable, VXETableSettings); + app.use(Input).use(Button).use(Select).use(Switch).use(Layout).use(VXETable, VXETableSettings).use(hljsVuePlugin); } diff --git a/src/views/tool/gen/edit/BaseInfo.vue b/src/views/tool/gen/edit/BaseInfo.vue index fa610e8..4e60142 100644 --- a/src/views/tool/gen/edit/BaseInfo.vue +++ b/src/views/tool/gen/edit/BaseInfo.vue @@ -6,7 +6,7 @@ - + @@ -46,7 +46,7 @@ showActionButtonGroup: false, }); //基础信息 - const [editorRegister, editorMethods] = useForm({ + const [paramsRegister, { validate: paramsValidate, getFieldsValue: getParamsValue, setFieldsValue: setParams }] = useForm({ labelWidth: 100, baseColProps: { span: 10, @@ -94,6 +94,7 @@ tableInfo.value = props.tableInfo; await setBaseInfo(props.tableInfo.info); await setGenInfo(props.tableInfo.info); + await setParams(props.tableInfo.info); } }; @@ -104,7 +105,10 @@ setBaseInfo, genRegister, genValidate, - editorRegister, + paramsRegister, + setParams, + paramsValidate, + getParamsValue, updateGenSchema, removeGenSchema, appendGenSchema, diff --git a/src/views/tool/gen/edit/index.vue b/src/views/tool/gen/edit/index.vue index 5156f78..bc85a33 100644 --- a/src/views/tool/gen/edit/index.vue +++ b/src/views/tool/gen/edit/index.vue @@ -41,7 +41,7 @@ }, setup() { const tableRef = ref<{ getData: () => any } | null>(null); - const baseInfoRef = ref<{ baseValidate: () => any; genValidate: () => any } | null>(null); + const baseInfoRef = ref<{ baseValidate: () => any; genValidate: () => any; paramsValidate: () => any; getParamsValue: () => any } | null>(null); const tableInfo = ref({}); let { closeCurrent } = useTabs(); @@ -65,7 +65,7 @@ }; if (baseInfoRef.value) { const [values, taskValues] = await Promise.all([baseInfoRef.value.baseValidate(), baseInfoRef.value.genValidate()]); - tableResult = { ...tableResult, ...values, ...taskValues }; + tableResult = { ...tableResult, ...values, ...taskValues, ...baseInfoRef.value.getParamsValue() }; } if (tableRef.value) { tableResult.columns = tableRef.value.getData(); diff --git a/src/views/tool/gen/modal/preview/index.vue b/src/views/tool/gen/modal/preview/index.vue index e3b32f3..35bc1d8 100644 --- a/src/views/tool/gen/modal/preview/index.vue +++ b/src/views/tool/gen/modal/preview/index.vue @@ -40,7 +40,7 @@ import { Tabs } from 'ant-design-vue'; import { BasicModal, useModalInner } from '/@/components/Modal'; import * as _API from '../../api'; - import { PreviewParams, PreviewResultModel } from '../../edit/model'; + import { PreviewParams, PreviewResultModel } from '../../api/model'; import { useMessage } from '/@/hooks/web/useMessage'; export default defineComponent({ diff --git a/src/views/tool/tpl/modal/diff/index.vue b/src/views/tool/tpl/modal/diff/index.vue index 37e0779..3f0949b 100644 --- a/src/views/tool/tpl/modal/diff/index.vue +++ b/src/views/tool/tpl/modal/diff/index.vue @@ -5,7 +5,7 @@ * @FilePath: \src\views\tool\tpl\modal\diff\index.vue --> @@ -29,6 +29,7 @@ setModalProps({ confirmLoading: false }); }); const handleSubmit = () => { + nextTick(() => (visible.value = false)); closeModal(); emit('success'); }; diff --git a/src/views/tool/tpl/modal/editor/index.vue b/src/views/tool/tpl/modal/editor/index.vue index 6245203..f0c5d0e 100644 --- a/src/views/tool/tpl/modal/editor/index.vue +++ b/src/views/tool/tpl/modal/editor/index.vue @@ -21,7 +21,7 @@ import { getFormConfig } from './config'; import monacoEditor from '/@/components/Custom/MonacoEditor/index.vue'; import * as _API from '../../api'; - import { message, Modal } from 'ant-design-vue'; + import { Modal } from 'ant-design-vue'; import diffModal from '../diff/index.vue'; export default defineComponent({ name: 'tplForm', @@ -77,7 +77,7 @@ title: '提示', content: '是否需要进行代码对比?', okText: '确认', - cancelText: '取消', + cancelText: '取消并保存', onOk: () => { diffModalMethods.openModal(true, { diffValue: form.value.content, modelValue: monacoEditor.value.getVal() || getFieldsValue()?.content }); }, diff --git a/vite.config.ts b/vite.config.ts index c479974..8f5f444 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -7,7 +7,6 @@ import { generateModifyVars } from './build/generate/generateModifyVars'; import { createProxy } from './build/vite/proxy'; import { wrapperEnv } from './build/utils'; import { createVitePlugins } from './build/vite/plugin'; -import monacoVite from './build/vite/monaco'; import { OUTPUT_DIR } from './build/constant'; function pathResolve(dir: string) { @@ -100,7 +99,7 @@ export default ({ command, mode }: ConfigEnv): UserConfig => { }, // The vite plugin used by the project. The quantity is large, so it is separately extracted and managed - plugins: createVitePlugins(viteEnv, isBuild).concat(monacoVite.plugins), + plugins: createVitePlugins(viteEnv, isBuild), optimizeDeps: { // @iconify/iconify: The dependency is dynamically and virtually loaded by @purge-icons/generated, so it needs to be specified explicitly @@ -110,9 +109,7 @@ export default ({ command, mode }: ConfigEnv): UserConfig => { '@iconify/iconify', 'ant-design-vue/es/locale/zh_CN', 'ant-design-vue/es/locale/en_US', - ...monacoVite.optimizeDeps.include, ], - esbuildOptions: monacoVite.optimizeDeps.esbuildOptions, }, }; }; -- Gitee