提交 5a8214ba authored 作者: 钟是志's avatar 钟是志

判断是不是字符串的bug

上级 aac8e489
import { import {
EditorState, convertFromRaw, convertToRaw, CompositeDecorator, EditorState, convertFromRaw, convertToRaw, CompositeDecorator,
} from 'draft-js'; } from 'draft-js';
import { message } from 'antd' import {message} from 'antd'
import { stateToHTML } from 'draft-js-export-html'; import {stateToHTML} from 'draft-js-export-html';
import moment from 'moment'; import moment from 'moment';
import {isJSON} from "@/webPublic/one_stop_public/copy";
function findLinkEntities(contentBlock, callback, contentState) { function findLinkEntities(contentBlock, callback, contentState) {
contentBlock.findEntityRanges( contentBlock.findEntityRanges(
...@@ -19,13 +19,12 @@ function findLinkEntities(contentBlock, callback, contentState) { ...@@ -19,13 +19,12 @@ function findLinkEntities(contentBlock, callback, contentState) {
console.log(arguments); console.log(arguments);
callback(...arguments); callback(...arguments);
} }
); );
} }
const Link = (props) => { const Link = (props) => {
const { url } = props.contentState.getEntity(props.entityKey).getData(); const {url} = props.contentState.getEntity(props.entityKey).getData();
return ( return (
<a href={url} target="_blank"> <a href={url} target="_blank">
...@@ -40,29 +39,30 @@ const decorator = new CompositeDecorator([ ...@@ -40,29 +39,30 @@ const decorator = new CompositeDecorator([
component: Link component: Link
} }
]); ]);
export function changeHtml(msg) { export function changeHtml(msg) {
var msg = msg.replace(/<\/?[^>]*>/g, ''); //去除HTML Tag var msg = msg.replace(/<\/?[^>]*>/g, ''); //去除HTML Tag
msg = msg.replace(/[|]*\n/, '') //去除行尾空格 msg = msg.replace(/[|]*\n/, '') //去除行尾空格
msg = msg.replace(/&npsp;/ig, ''); //去掉npsp msg = msg.replace(/&npsp;/ig, ''); //去掉npsp
return msg; return msg;
} }
export function changeToDraftState(blocks) {
export function changeToDraftState(blocks) {
if (blocks == null || blocks == "") { if (blocks == null || blocks == "") {
return EditorState.createEmpty(decorator) return EditorState.createEmpty(decorator)
} }
let x; let x;
if(blocks instanceof String){ if (typeof blocks === 'string' && blocks) {
try{ try {
x = JSON.parse(blocks) x = JSON.parse(blocks)
}catch(e){ } catch (e) {
return EditorState.createEmpty(decorator) return EditorState.createEmpty(decorator)
} }
}else{ } else {
x=blocks x = blocks
} }
if(!x.blocks){ if (!x.blocks) {
return EditorState.createEmpty(decorator) return EditorState.createEmpty(decorator)
} }
...@@ -71,32 +71,36 @@ export function changeToDraftState(blocks) { ...@@ -71,32 +71,36 @@ export function changeToDraftState(blocks) {
const b = convertFromRaw(x); const b = convertFromRaw(x);
return EditorState.createWithContent(b, decorator) return EditorState.createWithContent(b, decorator)
} }
export function changeFromDraftState(editorState) { export function changeFromDraftState(editorState) {
const x = editorState.getCurrentContent() const x = editorState.getCurrentContent()
const blocks = JSON.stringify(convertToRaw(x)) const blocks = JSON.stringify(convertToRaw(x))
const content = stateToHTML(x) const content = stateToHTML(x)
return { content, blocks } return {content, blocks}
} }
export function changeToDraftState2(blocks) { export function changeToDraftState2(blocks) {
const b = convertFromRaw(blocks); const b = convertFromRaw(blocks);
return EditorState.createWithContent(b, decorator) return EditorState.createWithContent(b, decorator)
} }
export function changeFromDraftState2(editorState) { export function changeFromDraftState2(editorState) {
if(editorState==null) return; if (editorState == null) return;
const x = editorState.getCurrentContent() const x = editorState.getCurrentContent()
const blocks = convertToRaw(x) const blocks = convertToRaw(x)
return blocks return blocks
} }
export function preHandle(values) { export function preHandle(values) {
for (var key in values) { for (var key in values) {
if(!values[key]) continue; if (!values[key]) continue;
if (key.indexOf("$") > -1) { if (key.indexOf("$") > -1) {
var xx = key.split("$") var xx = key.split("$")
for (var i = 0; i < xx.length; i++) { for (var i = 0; i < xx.length; i++) {
...@@ -107,27 +111,27 @@ export function preHandle(values) { ...@@ -107,27 +111,27 @@ export function preHandle(values) {
} }
} }
delete values[key] delete values[key]
} else { } else {
if (values[key] != null) { if (values[key] != null) {
if (values[key] instanceof moment) { if (values[key] instanceof moment) {
values[key] = values[key].valueOf() values[key] = values[key].valueOf()
}else if (values[key] instanceof Date) { } else if (values[key] instanceof Date) {
values[key] = values[key].valueOf() values[key] = values[key].valueOf()
} else if (values[key] instanceof Boolean) { } else if (values[key] instanceof Boolean) {
values[key] = values[key] ? 0 : 1 values[key] = values[key] ? 0 : 1
}else if(values[key] instanceof Object&&key!='defaultValues'){ } else if (values[key] instanceof Object && key != 'defaultValues') {
//处理子表单中的日期值 //处理子表单中的日期值
let objValues = values[key]; let objValues = values[key];
for(let k in objValues){ for (let k in objValues) {
if(k!=''&&objValues[k] instanceof Object){ if (k != '' && objValues[k] instanceof Object) {
let childObj = objValues[k]; let childObj = objValues[k];
for(let j in childObj){ for (let j in childObj) {
if(childObj[j]!=null){ if (childObj[j] != null) {
if (childObj[j] instanceof moment) { if (childObj[j] instanceof moment) {
values[key][k][j] = values[key][k][j].valueOf() values[key][k][j] = values[key][k][j].valueOf()
}else if (childObj[j] instanceof Date) { } else if (childObj[j] instanceof Date) {
values[key][k][j] = values[key][k][j].valueOf() values[key][k][j] = values[key][k][j].valueOf()
} else if (childObj[j] instanceof Boolean) { } else if (childObj[j] instanceof Boolean) {
values[key][k][j] = values[key][k][j] ? 0 : 1 values[key][k][j] = values[key][k][j] ? 0 : 1
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论