初始化询价智能体新仓:同步本地工程并排除密钥与 .env。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
import { withInstall } from '/@/utils/index';
|
||||
import tinymce from './src/Editor.vue';
|
||||
|
||||
export const Tinymce = withInstall(tinymce);
|
||||
@@ -0,0 +1,361 @@
|
||||
<template>
|
||||
<div :class="prefixCls" :style="{ width: containerWidth }">
|
||||
<ImgUpload
|
||||
:fullscreen="fullscreen"
|
||||
@uploading="handleImageUploading"
|
||||
@done="handleDone"
|
||||
v-if="showImageUpload"
|
||||
v-show="editorRef"
|
||||
:disabled="disabled"
|
||||
/>
|
||||
<textarea :id="tinymceId" ref="elRef" :style="{ visibility: 'hidden' }" v-if="!initOptions.inline"></textarea>
|
||||
<slot v-else></slot>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import type { Editor, RawEditorSettings } from 'tinymce';
|
||||
// 必须先经 tinymce-global 挂到 window,再 import 插件;否则 Vite 下会 tinymce is not defined 卡死启动页
|
||||
import tinymce from './tinymce-global';
|
||||
import 'tinymce/themes/silver';
|
||||
import 'tinymce/icons/default/icons';
|
||||
import 'tinymce/plugins/advlist';
|
||||
import 'tinymce/plugins/anchor';
|
||||
import 'tinymce/plugins/autolink';
|
||||
import 'tinymce/plugins/autosave';
|
||||
import 'tinymce/plugins/code';
|
||||
import 'tinymce/plugins/codesample';
|
||||
import 'tinymce/plugins/directionality';
|
||||
import 'tinymce/plugins/fullscreen';
|
||||
import 'tinymce/plugins/hr';
|
||||
import 'tinymce/plugins/insertdatetime';
|
||||
import 'tinymce/plugins/link';
|
||||
import 'tinymce/plugins/lists';
|
||||
import 'tinymce/plugins/media';
|
||||
import 'tinymce/plugins/nonbreaking';
|
||||
import 'tinymce/plugins/noneditable';
|
||||
import 'tinymce/plugins/pagebreak';
|
||||
import 'tinymce/plugins/paste';
|
||||
import 'tinymce/plugins/preview';
|
||||
import 'tinymce/plugins/print';
|
||||
import 'tinymce/plugins/save';
|
||||
import 'tinymce/plugins/searchreplace';
|
||||
import 'tinymce/plugins/spellchecker';
|
||||
import 'tinymce/plugins/tabfocus';
|
||||
// import 'tinymce/plugins/table';
|
||||
import 'tinymce/plugins/template';
|
||||
import 'tinymce/plugins/textpattern';
|
||||
import 'tinymce/plugins/visualblocks';
|
||||
import 'tinymce/plugins/visualchars';
|
||||
import 'tinymce/plugins/wordcount';
|
||||
import 'tinymce/plugins/image';
|
||||
import 'tinymce/plugins/table';
|
||||
import 'tinymce/plugins/textcolor';
|
||||
import 'tinymce/plugins/contextmenu';
|
||||
import { defineComponent, computed, nextTick, ref, unref, watch, onDeactivated, onBeforeUnmount } from 'vue';
|
||||
import ImgUpload from './ImgUpload.vue';
|
||||
import { toolbar, plugins, simplePlugins, simpleToolbar, menubar } from './tinymce';
|
||||
import { buildShortUUID } from '/@/utils/uuid';
|
||||
import { bindHandlers } from './helper';
|
||||
import { onMountedOrActivated } from '/@/hooks/core/onMountedOrActivated';
|
||||
import { useDesign } from '/@/hooks/web/useDesign';
|
||||
import { isNumber } from '/@/utils/is';
|
||||
import { useLocale } from '/@/locales/useLocale';
|
||||
import { useAppStore } from '/@/store/modules/app';
|
||||
import { uploadFile } from '/@/api/common/api';
|
||||
import { getFileAccessHttpUrl } from '/@/utils/common/compUtils';
|
||||
const tinymceProps = {
|
||||
options: {
|
||||
type: Object as PropType<Partial<RawEditorSettings>>,
|
||||
default: {},
|
||||
},
|
||||
value: {
|
||||
type: String,
|
||||
},
|
||||
|
||||
toolbar: {
|
||||
type: [Array as PropType<string[]>, String],
|
||||
default: toolbar,
|
||||
},
|
||||
plugins: {
|
||||
type: Array as PropType<string[]>,
|
||||
default: plugins,
|
||||
},
|
||||
menubar: {
|
||||
type: [Object, String],
|
||||
default: menubar,
|
||||
},
|
||||
modelValue: {
|
||||
type: String,
|
||||
},
|
||||
height: {
|
||||
type: [Number, String] as PropType<string | number>,
|
||||
required: false,
|
||||
default: 400,
|
||||
},
|
||||
width: {
|
||||
type: [Number, String] as PropType<string | number>,
|
||||
required: false,
|
||||
default: 'auto',
|
||||
},
|
||||
showImageUpload: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
};
|
||||
|
||||
export default defineComponent({
|
||||
name: 'Tinymce',
|
||||
components: { ImgUpload },
|
||||
inheritAttrs: false,
|
||||
props: tinymceProps,
|
||||
emits: ['change', 'update:modelValue', 'inited', 'init-error'],
|
||||
setup(props, { emit, attrs }) {
|
||||
const editorRef = ref<Nullable<Editor>>(null);
|
||||
const fullscreen = ref(false);
|
||||
const tinymceId = ref<string>(buildShortUUID('tiny-vue'));
|
||||
const elRef = ref<Nullable<HTMLElement>>(null);
|
||||
|
||||
const { prefixCls } = useDesign('tinymce-container');
|
||||
|
||||
const appStore = useAppStore();
|
||||
|
||||
const tinymceContent = computed(() => props.modelValue);
|
||||
|
||||
const containerWidth = computed(() => {
|
||||
const width = props.width;
|
||||
if (isNumber(width)) {
|
||||
return `${width}px`;
|
||||
}
|
||||
return width;
|
||||
});
|
||||
|
||||
const skinName = computed(() => {
|
||||
return appStore.getDarkMode === 'light' ? 'jeecg' : 'oxide-dark';
|
||||
});
|
||||
|
||||
const langName = computed(() => {
|
||||
const lang = useLocale().getLocale.value;
|
||||
return ['zh_CN', 'en'].includes(lang) ? lang : 'zh_CN';
|
||||
});
|
||||
|
||||
const initOptions = computed((): RawEditorSettings => {
|
||||
const { height, options, toolbar, plugins, menubar } = props;
|
||||
const publicPath = import.meta.env.VITE_PUBLIC_PATH || '/';
|
||||
return {
|
||||
selector: `#${unref(tinymceId)}`,
|
||||
height,
|
||||
toolbar,
|
||||
menubar: menubar,
|
||||
plugins,
|
||||
language_url: publicPath + 'resource/tinymce/langs/' + langName.value + '.js',
|
||||
language: langName.value,
|
||||
branding: false,
|
||||
default_link_target: '_blank',
|
||||
link_title: false,
|
||||
object_resizing: true,
|
||||
toolbar_mode: 'sliding',
|
||||
auto_focus: true,
|
||||
toolbar_groups: true,
|
||||
skin: skinName.value,
|
||||
skin_url: publicPath + 'resource/tinymce/skins/ui/' + skinName.value,
|
||||
images_upload_handler: (blobInfo, success) => {
|
||||
let params = {
|
||||
file: blobInfo.blob(),
|
||||
filename: blobInfo.filename(),
|
||||
data: { biz: 'jeditor', jeditor: '1' },
|
||||
};
|
||||
const uploadSuccess = (res) => {
|
||||
if (res.success) {
|
||||
if (res.message == 'local') {
|
||||
const img = 'data:image/jpeg;base64,' + blobInfo.base64();
|
||||
success(img);
|
||||
} else {
|
||||
let img = getFileAccessHttpUrl(res.message);
|
||||
success(img);
|
||||
}
|
||||
}
|
||||
};
|
||||
uploadFile(params, uploadSuccess);
|
||||
},
|
||||
content_css: publicPath + 'resource/tinymce/skins/ui/' + skinName.value + '/content.min.css',
|
||||
...options,
|
||||
setup: (editor: Editor) => {
|
||||
editorRef.value = editor;
|
||||
editor.on('init', (e) => initSetup(e));
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
const disabled = computed(() => {
|
||||
const { options } = props;
|
||||
const getdDisabled = options && Reflect.get(options, 'readonly');
|
||||
const editor = unref(editorRef);
|
||||
// update-begin-author:taoyan date:20220407 for: 设置disabled,图片上传没有被禁用
|
||||
if (editor) {
|
||||
editor.setMode(getdDisabled || attrs.disabled === true ? 'readonly' : 'design');
|
||||
}
|
||||
if (attrs.disabled === true) {
|
||||
return true;
|
||||
}
|
||||
// update-end-author:taoyan date:20220407 for: 设置disabled,图片上传没有被禁用
|
||||
return getdDisabled ?? false;
|
||||
});
|
||||
|
||||
watch(
|
||||
() => attrs.disabled,
|
||||
() => {
|
||||
const editor = unref(editorRef);
|
||||
if (!editor) {
|
||||
return;
|
||||
}
|
||||
editor.setMode(attrs.disabled ? 'readonly' : 'design');
|
||||
}
|
||||
);
|
||||
|
||||
onMountedOrActivated(() => {
|
||||
if (!initOptions.value.inline) {
|
||||
tinymceId.value = buildShortUUID('tiny-vue');
|
||||
}
|
||||
nextTick(() => {
|
||||
setTimeout(() => {
|
||||
initEditor();
|
||||
}, 30);
|
||||
});
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
destory();
|
||||
});
|
||||
|
||||
onDeactivated(() => {
|
||||
destory();
|
||||
});
|
||||
|
||||
function destory() {
|
||||
if (tinymce !== null) {
|
||||
tinymce?.remove?.(unref(initOptions).selector!);
|
||||
}
|
||||
}
|
||||
|
||||
function initEditor() {
|
||||
const el = unref(elRef);
|
||||
if (el) {
|
||||
el.style.visibility = '';
|
||||
}
|
||||
tinymce
|
||||
.init(unref(initOptions))
|
||||
.then((editor) => {
|
||||
emit('inited', editor);
|
||||
})
|
||||
.catch((err) => {
|
||||
emit('init-error', err);
|
||||
});
|
||||
}
|
||||
|
||||
function initSetup(e) {
|
||||
const editor = unref(editorRef);
|
||||
if (!editor) {
|
||||
return;
|
||||
}
|
||||
const value = props.modelValue || '';
|
||||
|
||||
editor.setContent(value);
|
||||
bindModelHandlers(editor);
|
||||
bindHandlers(e, attrs, unref(editorRef));
|
||||
}
|
||||
|
||||
function setValue(editor: Recordable, val: string, prevVal?: string) {
|
||||
if (editor && typeof val === 'string' && val !== prevVal && val !== editor.getContent({ format: attrs.outputFormat })) {
|
||||
editor.setContent(val);
|
||||
}
|
||||
}
|
||||
|
||||
function bindModelHandlers(editor: any) {
|
||||
const modelEvents = attrs.modelEvents ? attrs.modelEvents : null;
|
||||
const normalizedEvents = Array.isArray(modelEvents) ? modelEvents.join(' ') : modelEvents;
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(val: string, prevVal: string) => {
|
||||
setValue(editor, val, prevVal);
|
||||
}
|
||||
);
|
||||
|
||||
watch(
|
||||
() => props.value,
|
||||
(val: string, prevVal: string) => {
|
||||
setValue(editor, val, prevVal);
|
||||
},
|
||||
{
|
||||
immediate: true,
|
||||
}
|
||||
);
|
||||
|
||||
editor.on(normalizedEvents ? normalizedEvents : 'change keyup undo redo', () => {
|
||||
const content = editor.getContent({ format: attrs.outputFormat });
|
||||
emit('update:modelValue', content);
|
||||
emit('change', content);
|
||||
});
|
||||
|
||||
editor.on('FullscreenStateChanged', (e) => {
|
||||
fullscreen.value = e.state;
|
||||
});
|
||||
}
|
||||
|
||||
function handleImageUploading(name: string) {
|
||||
const editor = unref(editorRef);
|
||||
if (!editor) {
|
||||
return;
|
||||
}
|
||||
editor.execCommand('mceInsertContent', false, getUploadingImgName(name));
|
||||
const content = editor?.getContent() ?? '';
|
||||
setValue(editor, content);
|
||||
}
|
||||
|
||||
function handleDone(name: string, url: string) {
|
||||
const editor = unref(editorRef);
|
||||
if (!editor) {
|
||||
return;
|
||||
}
|
||||
const content = editor?.getContent() ?? '';
|
||||
const val = content?.replace(getUploadingImgName(name), `<img src="${url}"/>`) ?? '';
|
||||
setValue(editor, val);
|
||||
}
|
||||
|
||||
function getUploadingImgName(name: string) {
|
||||
return `[uploading:${name}]`;
|
||||
}
|
||||
|
||||
return {
|
||||
prefixCls,
|
||||
containerWidth,
|
||||
initOptions,
|
||||
tinymceContent,
|
||||
elRef,
|
||||
tinymceId,
|
||||
handleImageUploading,
|
||||
handleDone,
|
||||
editorRef,
|
||||
fullscreen,
|
||||
disabled,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped></style>
|
||||
|
||||
<style lang="less">
|
||||
@prefix-cls: ~'@{namespace}-tinymce-container';
|
||||
|
||||
.@{prefix-cls} {
|
||||
position: relative;
|
||||
line-height: normal;
|
||||
|
||||
textarea {
|
||||
z-index: -1;
|
||||
visibility: hidden;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,118 @@
|
||||
<template>
|
||||
<div :class="[prefixCls, { fullscreen }]">
|
||||
<Upload
|
||||
name="file"
|
||||
multiple
|
||||
@change="handleChange"
|
||||
:action="uploadUrl"
|
||||
:showUploadList="false"
|
||||
:data="getBizData()"
|
||||
:headers="getheader()"
|
||||
accept=".jpg,.jpeg,.gif,.png,.webp"
|
||||
>
|
||||
<a-button type="primary" v-bind="{ ...getButtonProps }">
|
||||
{{ t('component.upload.imgUpload') }}
|
||||
</a-button>
|
||||
</Upload>
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { defineComponent, computed } from 'vue';
|
||||
|
||||
import { Upload } from 'ant-design-vue';
|
||||
import { useDesign } from '/@/hooks/web/useDesign';
|
||||
import { useGlobSetting } from '/@/hooks/setting';
|
||||
import { useI18n } from '/@/hooks/web/useI18n';
|
||||
import { getToken } from '/@/utils/auth';
|
||||
import { getFileAccessHttpUrl } from '/@/utils/common/compUtils';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'TinymceImageUpload',
|
||||
components: { Upload },
|
||||
props: {
|
||||
fullscreen: {
|
||||
type: Boolean,
|
||||
},
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
},
|
||||
emits: ['uploading', 'done', 'error'],
|
||||
setup(props, { emit }) {
|
||||
let uploading = false;
|
||||
|
||||
//update-begin-author:taoyan date:2022-5-13 for: 富文本上传图片不支持
|
||||
function getheader() {
|
||||
return { 'X-Access-Token': getToken() };
|
||||
}
|
||||
|
||||
function getBizData() {
|
||||
return {
|
||||
biz: 'jeditor',
|
||||
jeditor: '1',
|
||||
};
|
||||
}
|
||||
const { domainUrl } = useGlobSetting();
|
||||
const uploadUrl = domainUrl + '/sys/common/upload';
|
||||
//update-end-author:taoyan date:2022-5-13 for: 富文本上传图片不支持
|
||||
const { t } = useI18n();
|
||||
const { prefixCls } = useDesign('tinymce-img-upload');
|
||||
|
||||
const getButtonProps = computed(() => {
|
||||
const { disabled } = props;
|
||||
return {
|
||||
disabled,
|
||||
};
|
||||
});
|
||||
|
||||
function handleChange(info: Recordable) {
|
||||
const file = info.file;
|
||||
const status = file?.status;
|
||||
//const url = file?.response?.url;
|
||||
const name = file?.name;
|
||||
|
||||
if (status === 'uploading') {
|
||||
if (!uploading) {
|
||||
emit('uploading', name);
|
||||
uploading = true;
|
||||
}
|
||||
} else if (status === 'done') {
|
||||
//update-begin-author:taoyan date:2022-5-13 for: 富文本上传图片不支持
|
||||
let realUrl = getFileAccessHttpUrl(file.response.message);
|
||||
emit('done', name, realUrl);
|
||||
//update-end-author:taoyan date:2022-5-13 for: 富文本上传图片不支持
|
||||
uploading = false;
|
||||
} else if (status === 'error') {
|
||||
emit('error');
|
||||
uploading = false;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
prefixCls,
|
||||
handleChange,
|
||||
uploadUrl,
|
||||
getheader,
|
||||
getBizData,
|
||||
t,
|
||||
getButtonProps,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
<style lang="less" scoped>
|
||||
@prefix-cls: ~'@{namespace}-tinymce-img-upload';
|
||||
|
||||
.@{prefix-cls} {
|
||||
position: absolute;
|
||||
top: 4px;
|
||||
right: 10px;
|
||||
z-index: 20;
|
||||
|
||||
&.fullscreen {
|
||||
position: fixed;
|
||||
z-index: 10000;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,81 @@
|
||||
const validEvents = [
|
||||
'onActivate',
|
||||
'onAddUndo',
|
||||
'onBeforeAddUndo',
|
||||
'onBeforeExecCommand',
|
||||
'onBeforeGetContent',
|
||||
'onBeforeRenderUI',
|
||||
'onBeforeSetContent',
|
||||
'onBeforePaste',
|
||||
'onBlur',
|
||||
'onChange',
|
||||
'onClearUndos',
|
||||
'onClick',
|
||||
'onContextMenu',
|
||||
'onCopy',
|
||||
'onCut',
|
||||
'onDblclick',
|
||||
'onDeactivate',
|
||||
'onDirty',
|
||||
'onDrag',
|
||||
'onDragDrop',
|
||||
'onDragEnd',
|
||||
'onDragGesture',
|
||||
'onDragOver',
|
||||
'onDrop',
|
||||
'onExecCommand',
|
||||
'onFocus',
|
||||
'onFocusIn',
|
||||
'onFocusOut',
|
||||
'onGetContent',
|
||||
'onHide',
|
||||
'onInit',
|
||||
'onKeyDown',
|
||||
'onKeyPress',
|
||||
'onKeyUp',
|
||||
'onLoadContent',
|
||||
'onMouseDown',
|
||||
'onMouseEnter',
|
||||
'onMouseLeave',
|
||||
'onMouseMove',
|
||||
'onMouseOut',
|
||||
'onMouseOver',
|
||||
'onMouseUp',
|
||||
'onNodeChange',
|
||||
'onObjectResizeStart',
|
||||
'onObjectResized',
|
||||
'onObjectSelected',
|
||||
'onPaste',
|
||||
'onPostProcess',
|
||||
'onPostRender',
|
||||
'onPreProcess',
|
||||
'onProgressState',
|
||||
'onRedo',
|
||||
'onRemove',
|
||||
'onReset',
|
||||
'onSaveContent',
|
||||
'onSelectionChange',
|
||||
'onSetAttrib',
|
||||
'onSetContent',
|
||||
'onShow',
|
||||
'onSubmit',
|
||||
'onUndo',
|
||||
'onVisualAid',
|
||||
];
|
||||
|
||||
const isValidKey = (key: string) => validEvents.indexOf(key) !== -1;
|
||||
|
||||
export const bindHandlers = (initEvent: Event, listeners: any, editor: any): void => {
|
||||
Object.keys(listeners)
|
||||
.filter(isValidKey)
|
||||
.forEach((key: string) => {
|
||||
const handler = listeners[key];
|
||||
if (typeof handler === 'function') {
|
||||
if (key === 'onInit') {
|
||||
handler(initEvent, editor);
|
||||
} else {
|
||||
editor.on(key.substring(2), (e: any) => handler(e, editor));
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* TinyMCE 全局挂载(Vite ESM 必需)。
|
||||
*
|
||||
* 背景:tinymce 各插件脚本用裸标识符 `tinymce.PluginManager...`,依赖浏览器全局。
|
||||
* Vite 会把同一文件里的 import 全部提前执行,若在 Editor.vue 里写
|
||||
* `import tinymce from 'tinymce/tinymce'; window.tinymce = tinymce; import 'tinymce/plugins/...'`
|
||||
* 赋值语句赶不上插件执行,启动就会 Uncaught ReferenceError: tinymce is not defined,页面一直转圈。
|
||||
*
|
||||
* 做法:单独模块先加载核心并挂到 window,再由 Editor.vue 按顺序 import 本模块、主题、插件。
|
||||
*/
|
||||
import tinymce from 'tinymce/tinymce';
|
||||
|
||||
(window as any).tinymce = tinymce;
|
||||
|
||||
export default tinymce;
|
||||
@@ -0,0 +1,20 @@
|
||||
// Any plugins you want to setting has to be imported
|
||||
// Detail plugins list see https://www.tinymce.com/docs/plugins/
|
||||
// Custom builds see https://www.tinymce.com/download/custom-builds/
|
||||
// colorpicker/contextmenu/textcolor plugin is now built in to the core editor, please remove it from your editor configuration
|
||||
|
||||
export const plugins = [
|
||||
'advlist anchor autolink autosave code codesample directionality fullscreen hr insertdatetime link lists media nonbreaking noneditable pagebreak paste preview print save searchreplace spellchecker tabfocus template textpattern visualblocks visualchars wordcount image',
|
||||
];
|
||||
|
||||
export const toolbar =
|
||||
'fullscreen code preview | undo redo | bold italic underline strikethrough | fontselect fontsizeselect formatselect | alignleft aligncenter alignright alignjustify | outdent indent lineheight|subscript superscript blockquote| numlist bullist checklist | forecolor backcolor casechange permanentpen formatpainter removeformat | pagebreak | charmap emoticons | insertfile image media pageembed link anchor codesample insertdatetime hr| a11ycheck ltr rtl';
|
||||
|
||||
export const simplePlugins = ['lists image link media table textcolor wordcount contextmenu fullscreen'];
|
||||
|
||||
export const simpleToolbar = [
|
||||
'undo redo formatselect bold italic alignleft aligncenter alignright alignjustify bullist numlist outdent indent',
|
||||
'lists link unlink image media table removeformat fullscreen',
|
||||
];
|
||||
|
||||
export const menubar = 'file edit insert view format table';
|
||||
Reference in New Issue
Block a user