<commit_before>import React from 'react';
import { Icon, message , Button, Input  , Modal ,Spin ,Select , Checkbox  } from 'antd'
import articalDeTailService from '../../../service/back/articalDeTailService';
import _ from 'underscore';
import UEditor from '../component/ueditor';
import moment from 'moment';
function findIndex(arr,id){
	var index=0;
	for(var i=0;i<arr.length;i++){
		if(id===arr[i].id){
			index = i
		}
	}
	return index;
}
var editArtical=React.createClass({
	getInitialState(){
		return {
			loading:false,
			menus:[],
			currentMenu:"",
			category:[],
			currentCategory:"",
			createAt:undefined,
			updateAt:undefined,
			id:undefined,
			articalName:'',
			title:'新增文章',
			notifyFans:true
		}
	},
	componentDidMount(){
		let id=this.props.params.id;
		var ctx=this;
		if(id){
			this.setState({
				id:id,
				title:'编辑文章'
			})
			
		}
		articalDeTailService.getCategory().then((res)=>{
			if(res.status===0){
				this.setState({
					menus:res.data.menus
				},function(){
					if(id){
						articalDeTailService.getArticalDetail(id).then((res)=>{
							if(res.status===0){
								var menuIndex=findIndex(this.state.menus,res.data.menuId);
								this.setState({
									articalName:res.data.articalName,
									createAt:res.data.createAt,
									updateAt:res.data.updateAt,
								})
								//模拟切换菜单
								this.selectMenu(res.data.menuId,{props:{index:menuIndex}});
								this.selectCategory(res.data.categoryId);
								setTimeout(function(){
									ctx.refs.editor.setContent(res.data.articalContent,false)
								},0)
								
							}
						})
					}
				})
			}
			
		})

	},
	selectMenu(value,option){
		var menus=this.state.menus;
		var index=option.props.index;
		this.setState({
			currentMenu:""+value,
			category:menus[index].children,
			currentCategory:""
		})
	},
	selectCategory(value,option){
		this.setState({
				currentCategory:""+value
			})
	},
	changeName(e){
		this.setState({
			articalName:e.target.value
		})
	},
	changeNotify(e){
		this.setState({
			notifyFans:e.target.checked
		})
	},
	editArtical(){
		if(this.state.currentCategory===""){
			message.error("必须选择文章分类")
		}
		else if(this.state.articalName===""){
			message.error("文章标题不能为空！")
		}else{
			var articalContent=this.refs.editor.getContent()
			articalDeTailService.setArticalDetail({
				id:this.state.id,
				categoryId:this.state.currentCategory,
				articalName:this.state.articalName,
				notifyFans:this.state.notifyFans,
				articalContent:articalContent
			}).then((res)=>{
				if(res.status===0){
					this.setState({
						updateAt:res.data.updateAt<commit_msg>upper case bug Signed-off-by: wade <<EMAIL>><commit_after>import React from 'react';
import { Icon, message , Button, Input  , Modal ,Spin ,Select , Checkbox  } from 'antd'
import articalDetailService from '../../../service/back/articalDetailService';
import _ from 'underscore';
import UEditor from '../component/ueditor';
import moment from 'moment';
function findIndex(arr,id){
	var index=0;
	for(var i=0;i<arr.length;i++){
		if(id===arr[i].id){
			index = i
		}
	}
	return index;
}
var editArtical=React.createClass({
	getInitialState(){
		return {
			loading:false,
			menus:[],
			currentMenu:"",
			category:[],
			currentCategory:"",
			createAt:undefined,
			updateAt:undefined,
			id:undefined,
			articalName:'',
			title:'新增文章',
			notifyFans:true
		}
	},
	componentDidMount(){
		let id=this.props.params.id;
		var ctx=this;
		if(id){
			this.setState({
				id:id,
				title:'编辑文章'
			})
			
		}
		articalDetailService.getCategory().then((res)=>{
			if(res.status===0){
				this.setState({
					menus:res.data.menus
				},function(){
					if(id){
						articalDetailService.getArticalDetail(id).then((res)=>{
							if(res.status===0){
								var menuIndex=findIndex(this.state.menus,res.data.menuId);
								this.setState({
									articalName:res.data.articalName,
									createAt:res.data.createAt,
									updateAt:res.data.updateAt,
								})
								//模拟切换菜单
								this.selectMenu(res.data.menuId,{props:{index:menuIndex}});
								this.selectCategory(res.data.categoryId);
								setTimeout(function(){
									ctx.refs.editor.setContent(res.data.articalContent,false)
								},0)
								
							}
						})
					}
				})
			}
			
		})

	},
	selectMenu(value,option){
		var menus=this.state.menus;
		var index=option.props.index;
		this.setState({
			currentMenu:""+value,
			category:menus[index].children,
			currentCategory:""
		})
	},
	selectCategory(value,option){
		this.setState({
				currentCategory:""+value
			})
	},
	changeName(e){
		this.setState({
			articalName:e.target.value
		})
	},
	changeNotify(e){
		this.setState({
			notifyFans:e.target.checked
		})
	},
	editArtical(){
		if(this.state.currentCategory===""){
			message.error("必须选择文章分类")
		}
		else if(this.state.articalName===""){
			message.error("文章标题不能为空！")
		}else{
			var articalContent=this.refs.editor.getContent()
			articalDetailService.setArticalDetail({
				id:this.state.id,
				categoryId:this.state.currentCategory,
				articalName:this.state.articalName,
				notifyFans:this.state.notifyFans,
				articalContent:articalContent
			}).then((res)=>{
				if(res.status===0){
					this.setState({
						updateAt:res.data.updateAt
{'fraction_non_alphanumeric': 0.16149895377591783, 'fraction_numerical': 0.002282670724747955, 'mean_word_length': 3.295751633986928, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4938273', 'n_tokens_mistral': 2396, 'n_tokens_neox': 1901, 'n_words': 248}