export default {
  data() {
    let that = this;
    return {
			editor: null,
      froalaConfig: {
				toolbarButtons: [
					'insertImage',
					'insertVideo',
					'embedly',
					'insertFile',
					'textColor',
					'bold',
					'italic',
					'underline',
					'strikeThrough',
					'subscript',
					'superscript',
					'fontFamily',
					'fontSize',
					'color',
					'inlineClass',
					'inlineStyle',
					'paragraphStyle',
					'lineHeight',
					'paragraphFormat',
					'align',
					'formatOL',
					'formatUL',
					'outdent',
					'indent',
					'quote',
					'insertTable',
					'emoticons',
					'fontAwesome',
					'specialCharacters',
					'insertHR',
					'selectAll',
					'clearFormatting',
					'html',
					'undo',
					'redo',
				],
				height: 800,
				fontSize: [
					'12',
					'14',
					'16',
					'18',
					'20',
					'24',
					'28',
					'32',
					'36',
					'40',
				],
				fontSizeDefaultSelection: '16',
				theme: 'dark', //主题
				placeholderText: '请输入内容',
				language: 'zh_cn', //国际化
				imageUploadURL: process.env.API_ROOT + '/report/uploadImg', //上传url
				videoUploadURL: process.env.API_ROOT + '/report/uploadImg', //上传url
				fileUploadURL: process.env.API_ROOT + '/report/uploadImg', //上传url 更多上传介绍 请访问https://www.froala.com/wysiwyg-editor/docs/options
				imageDefaultWidth: false,
				quickInsertButtons: ['image', 'table', 'ul', 'ol', 'hr'], //快速插入项
				toolbarVisibleWithoutSelection: true, //是否开启 不选中模式
				// disableRightClick:true,//是否屏蔽右击
				// colorsHEXInput:false,//关闭16进制色值
				toolbarSticky: false, //操作栏是否自动吸顶
				// zIndex:99999,
				saveInterval: 0,
				/* 				saveParam: 'content',
			saveURL: process.env.API_ROOT+'/report/saveReportContent',
			saveMethod: 'POST',
			saveParams: {}, */
				events: {
					// 'froalaEditor.initialized':function(){
					//   console.log('initialized', this);
					// },
					//this.editor 定义在vue data 中
					initialized: function () {
						// this.editor = editor;
						that.editor = this;
						// that.editor.html.set(that.value);
						// that.setHtml()
					},
					keyup: function (e, editor) {
						//添加事件，在每次按键按下时，都记录一下最后停留位置
						that.$nextTick(function () {
							that.lastEditRange = getSelection().getRangeAt(0);
						});
					},
					click: function (e, editor) {
						//添加事件，在每次鼠标点击时，都记录一下最后停留位置
						that.$nextTick(function () {
							that.lastEditRange = getSelection().getRangeAt(0);
						});
					},
					//内容改变事件
					contentChanged: function () {
						that.ischange = true;
						that.lastEditRange = getSelection().getRangeAt(0) || 0;
					},
				},
				charCounterCount: false,
				reportloadding: false,
				lastsavetime: '',
				isAddEnter: false, //是否已经添加过
				timer: null,
				ischange: false,
				isPublishloading: false,
			},
    }
  },
  methods: {
    insertHtml(item) {
			if(item.Disabled) return this.$message.warning('内部图表，不允许插入报告') 
			
			//设置编辑器获取焦点
			this.editor.events.focus();
			// 获取选定对象
			const selection = getSelection();
			// 判断是否有最后光标对象存在
			if (this.lastEditRange) {
				// 存在最后光标对象，选定对象清除所有光标并添加最后光标还原之前的状态
				selection.removeAllRanges();
				selection.addRange(this.lastEditRange);

			}
			//插入内容
			const LINK_CHART_URL = process.env.NODE_ENV === "production" ? 'https://chartlib.hzinsights.com/chartshow' : 'https://charttest.hzinsights.com/chartshow';
			this.$nextTick(() => {
					this.editor.html.insert(
					`<p style='text-align:left; margin-top:10px;'>
						<iframe src='${LINK_CHART_URL}?code=${item.UniqueCode}' width='100%' height='350' style='border-width:0px; min-height:350px;'></iframe>
					</p>`)
			})

			this.lastEditRange = selection.getRangeAt(0);
		},
  },
}