fix: 解决冲突

This commit is contained in:
zwjamnsss 2017-08-07 20:04:47 +08:00
commit 15f5315c0c
8 changed files with 408 additions and 37 deletions

12
.tags
View File

@ -230,12 +230,6 @@ constructor /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/Login/Reg.js
state.confirmDirty /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/Login/Reg.js /^ this.state = {$/;" property line:30
static.form /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/Login/Reg.js /^ static propTypes = {$/;" property line:35
render /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/Login/Reg.js /^ render() {$/;" function line:80
constructor /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/News/News.js /^ constructor(props) {$/;" function line:23
from.state.loading /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/News/News.js /^ this.state = {$/;" property line:25
static.newsData /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/News/News.js /^ static propTypes = {$/;" property line:29
setLoading /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/News/News.js /^ setLoading(bool){$/;" function line:34
componentWillMount /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/News/News.js /^ componentWillMount(){$/;" function line:39
render /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/News/News.js /^ render () {$/;" function line:45
@connect.fetchNewsData /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/News/NewsList/NewsList.js /^ static propTypes = {$/;" property line:34
constructor /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/News/NewsList/NewsList.js /^ constructor(props) {$/;" function line:40
constructor.state.selectedKeys /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/News/NewsList/NewsList.js /^ this.state = {$/;" property line:42
@ -284,3 +278,9 @@ state.login /Users/qitmac000445/Desktop/YAPI/yapi/client/Application.js /^ th
static.checkLoginState /Users/qitmac000445/Desktop/YAPI/yapi/client/Application.js /^ static propTypes = {$/;" property line:34
componentDidMount /Users/qitmac000445/Desktop/YAPI/yapi/client/Application.js /^ componentDidMount() {$/;" function line:39
render /Users/qitmac000445/Desktop/YAPI/yapi/client/Application.js /^ render() {$/;" function line:72
constructor /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/News/News.js /^ constructor(props) {$/;" function line:23
from.state.loading /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/News/News.js /^ this.state = {$/;" property line:25
static.newsData /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/News/News.js /^ static propTypes = {$/;" property line:29
setLoading /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/News/News.js /^ setLoading(bool){$/;" function line:34
componentWillMount /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/News/News.js /^ componentWillMount(){$/;" function line:39
render /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/News/News.js /^ render () {$/;" function line:45

6
.tags1
View File

@ -4,3 +4,9 @@
!_TAG_PROGRAM_NAME Exuberant Ctags //
!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
!_TAG_PROGRAM_VERSION 5.8 //
constructor /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/News/News.js /^ constructor(props) {$/;" function line:23
from.state.loading /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/News/News.js /^ this.state = {$/;" property line:25
static.newsData /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/News/News.js /^ static propTypes = {$/;" property line:29
setLoading /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/News/News.js /^ setLoading(bool){$/;" function line:34
componentWillMount /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/News/News.js /^ componentWillMount(){$/;" function line:39
render /Users/qitmac000445/Desktop/YAPI/yapi/client/containers/News/News.js /^ render () {$/;" function line:45

View File

@ -1,34 +1,11 @@
import moment from 'moment'
import regex_parse from './parseCommon.js';
exports.formatTime = (timestamp) => {
return moment.unix(timestamp).format("YYYY-MM-DD HH:mm:ss")
}
exports.regexp_parse = regexp_parse;
function regexp_parse(p,c) {//遍历json中的regexp字符串并将其转为RegExp对象。其中p为被转换的jsonc为存储对象。
c = c || {};
for (var i in p) {
if(! p.hasOwnProperty(i)){
continue;
}
if (typeof p[i] === 'object') {
c[i] = (p[i].constructor === Array) ? [] : {};
regexp_parse(p[i], c[i]);
} else {
if(/^\/.+\/$/.test(p[i])){
var regexpStr = p[i].substring(1,p[i].length-1);
try{
c[i] = new RegExp(regexpStr);
}
catch(e)
{
c[i] = p[i];
}
}else{
c[i] = p[i];
}
}
}
return c;
}
console.log(regex_parse)

View File

@ -0,0 +1,244 @@
import './MockDoc.scss'
import React, { Component } from 'react'
import PropTypes from 'prop-types'
// 组件用法 <MockDoc mock= mockData doc= docData />
// mockData: mock数据 格式为json
// docDatadocData数据 格式为array
class MockDoc extends Component {
constructor(props) {
super(props);
this.state = {
release: []
};
}
static propTypes = {
mock: PropTypes.object,
doc: PropTypes.array
}
// btnCol(start,col){
// return function(){
// console.log(start,col);
// }
// }
render() {
let htmlData = mockToArr(this.props.mock);
htmlData = arrToHtml(htmlData,this.props.doc);
return (
<div className='MockDoc'>
{
htmlData.map(function(item,i){
{/*//类型Object 必有字段 备注qwqwqw*/}
if(item.mes){
var mes = [];
item.mes.type?mes.push(<span key = {i} className="keymes"> / /{item.mes.type}</span>):"";
item.mes.required?mes.push(<span key = {i+1} className="keymes">必有字段</span>):"";
item.mes.desc?mes.push(<span key = {i+2} className="keymes">备注{item.mes.desc}</span>):"";
}
return (
<div className="jsonItem" key = {i}>
{<span className="jsonitemNum">{i+1}.</span>}{
produceSpace(item.space)
}{setStrToHtml(item.str)}
{mes}
</div>
)
})
}
</div>
)
}
}
MockDoc.defaultProps = {
mock: {
"ersrcode": "@integer",
"data|9-19": [
"123",
{
"name": "@name",
"name1": [{
"name3":"1"
}]
}],
"data1": "123",
"data3": {
"err": "errCode",
"arr": [1,2]
}
},
doc: [
{ type: "strisng", key: "ersrcode", required: true, desc: "错误编码" },
{ type: "number", key: "data[]", required: true, desc: "返回数据" },
{ type: "object", key: "data[].name", required: true, desc: "数据名" },
{ type: "object", key: "data[].name1[].name3", required: true, desc: "数据名1" },
{ type: "object", key: "data1", required: true, desc: "数据名1" },
{ type: "object", key: "data3.err", required: true, desc: "数据名1" },
{ type: "object", key: "data3", required: true, desc: "数据名1" },
{ type: "object", key: "data3.arr[]", required: true, desc: "数据名1" }
]
}
function produceSpace(count){
var space = [];
for(var i = 0; i< count; i++){
space.push(<span key = {i} className="spaces"></span>);
}
return space;
}
function setStrToHtml(str){
return <span dangerouslySetInnerHTML={{__html: `${str}`}} />
}
function arrToHtml(mockArr,mock){
for(var i in mockArr){
for(var item in mock){
// if(mockArr[i].key){
// console.log(mockArr[i].key,mock[item].key)
// }
if(mockArr[i].key && mockArr[i].key === mock[item].key){
mockArr[i].mes = mock[item];
}
}
}
return mockArr;
}
function mockToArr(mock,html,space,key) {
html = html || [];
space = space || 0;
key = key || [];
if(typeof mock === 'object' && space===0){
if (mock.constructor === Array) {
html.push({
space: space,
str: "["
})
space++;
}else{
html.push({
space: space,
str: "{"
})
space++;
}
}
for (var i in mock) {
if (!mock.hasOwnProperty(i)) {
continue;
}
var index = i;
if(/^\w+(\|\w+)?/.test(i)){
index = i.split("|")[0];
}
if (typeof mock[i] === 'object') {
if(mock[i].constructor === Array){
// shuzu
if(mock.constructor != Array){
if(key.length){
key.push("."+ index + "[]");
}else{
key.push(index + "[]");
}
}else{
key.push("[]");
}
html.push({
space: space,
str: index + " : [",
key: key.join("")
})
}else{
// object
if(mock.constructor != Array){
if(key.length){
key.push('.'+index);
}else{
key.push(index);
}
html.push({
space: space,
str: index + " : {"
})
}else{
html.push({
space: space,
str: "{"
})
}
}
space++;
mockToArr(mock[i],html,space,key);
key.pop();
space--;
} else {
if(mock.constructor === Array){
// html.push(produceSpace(space) + mock[i]+ ",");
html.push({
space: space,
str: `<span class = "valueLight">${mock[i]}</span>`+ ","
})
}else{
// html.push(produceSpace(space) + index + ":" + mock[i] + ",");
if(mock.constructor != Array){
if(key.length){
// doc.push(key+"."+index);
html.push({
space: space,
str: index + " : " + `<span class = "valueLight">${mock[i]}</span>` + ",",
key: key.join("")+"."+index
})
}else{
// doc.push(key + index);
html.push({
space: space,
str: index + " : " + `<span class = "valueLight">${mock[i]}</span>` + ",",
key: key.join("") + index
})
}
}else{
html.push({
space: space,
str: index + " : " + `<span class = "valueLight">${mock[i]}</span>` + ",",
key: key.join("")
})
}
}
}
}
if(typeof mock === 'object'){
html[html.length-1].str = html[html.length-1].str.substr(0,html[html.length-1].str.length-1);
if (mock.constructor === Array) {
space--;
// html.push(produceSpace(space)+"]");
html.push({
space: space,
str: "]"
})
}else{
space--;
// html.push(produceSpace(space)+"}");
html.push({
space: space,
str: "}"
})
}
}
if(space != 0){
html[html.length-1].str = html[html.length-1].str + ",";
}
return html;
}
export default MockDoc;

View File

@ -0,0 +1,31 @@
.MockDoc{
background-color: #F6F6F6;
// padding: 16px;
border:16px solid #F6F6F6;
overflow: auto;
width: 500px;
height: 500px;
word-break:keep-all; /* 不换行 */
white-space:nowrap;
.jsonItem{
font-size: 14px;
width: auto;
}
.jsonitemNum{
margin-right: 16px;
display: inline-block;
width: 25px;
border-right: 1px solid gray;
}
.valueLight{
color: #108ee9;
}
}
.spaces{
display: inline-block;
width: 30px;
}
.keymes{
margin-left: 20px;
}

View File

@ -3,8 +3,7 @@ import { Card } from 'antd'
import { connect } from 'react-redux'
import PropTypes from 'prop-types'
import Mock from 'mockjs'
import common from '../../../common';
import parseCommon from '../../../parseCommon';
@connect(
state => {
return {
@ -30,7 +29,7 @@ class Result extends Component {
let json, j;
try{
json = JSON.parse(resParams);
json = common.regexp_parse(json);
json = parseCommon.regexp_parse(json);
}catch(e){
json = false;
}

View File

@ -46,6 +46,7 @@ class News extends Component {
const data = this.props.newsData
return (
<section className="news-box">
{/*<MockDoc />*/}
<NewsList loading={this.state.loading} setLoading={this.setLoading.bind(this)} />
<NewsTimeline loading={this.state.loading} setLoading={this.setLoading.bind(this)} newsData = {data} />
</section>

113
client/parseCommon.js Normal file
View File

@ -0,0 +1,113 @@
function regexp_parse(p, c) {//遍历json中的regexp字符串并将其转为RegExp对象。其中p为被转换的jsonc为存储对象。 "kry|regexp/i|":"<(.*)>(.*)<\/(.*)>|<(.*)\/>"
c = c || {};
for (var i in p) {
if (!p.hasOwnProperty(i)) {
continue;
}
if (typeof p[i] === 'object') {
c[i] = (p[i].constructor === Array) ? [] : {};
regexp_parse(p[i], c[i]);
} else {
if (/^\w+\s*\|\s*(regexp){1}\s*(\/\s*[img])?/.test(i)) {
var regexpStr = i.split("|");
var regex = regexpStr[1].split("/");
if (regex[0]) {
try {
if (regex[1]) {
c[i.replace(/\|regexp\s*(\/[img]*)?\s*/, "")] = new RegExp(p[i], regex[1]);
} else {
c[i.replace(/\|regexp\s*(\/[img]*)?\s*/, "")] = new RegExp(p[i]);
}
}
catch (e) {
c[i] = p[i];
}
}
} else {
c[i] = p[i];
}
}
}
return c;
}
function mockToDocModel(mock,doc,key) {
doc = doc || [];
key = key || [];
for (var i in mock) {
if (!mock.hasOwnProperty(i)) {
continue;
}
var index = i;
if(/^\w+(\|\w+)?/.test(i)){
index = i.split("|")[0];
}
if (typeof mock[i] === 'object') {
if (mock[i].constructor === Array) {
//为数组时
if(mock.constructor != Array){
if(key.length){
key.push("."+ index + "[]");
}else{
key.push(index + "[]");
}
}else{
key.push("[]");
}
doc.push(key.join(""));
} else {
// 为object时
if(mock.constructor != Array){
if(key.length){
key.push('.'+index);
}else{
key.push(index);
}
doc.push(key.join());
}
}
mockToDocModel(mock[i],doc,key);
key.pop();
} else {
if(mock.constructor != Array){
if(key.length){
doc.push(key.join("")+"."+index);
}else{
doc.push(index);
}
}
}
}
return doc;
}
mockToDocModel({
"errcode": "@integer",
"data|9-19": [
"123",
{
"name": "@name",
"name1": [{
"name3":"1"
}]
}],
"data4": [1,2],
"data1": "123",
"data3": {
"err": "errCode",
"arr": [1,2]
}
})
module.exports = {
mockToDocModel: mockToDocModel,
regexp_parse: regexp_parse
};