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

判断是不是字符串的bug

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