diff --git a/app/controllers/admins/base_controller.rb b/app/controllers/admins/base_controller.rb index e2e3babae..ad56afbf7 100644 --- a/app/controllers/admins/base_controller.rb +++ b/app/controllers/admins/base_controller.rb @@ -6,6 +6,7 @@ class Admins::BaseController < ApplicationController layout 'admin' skip_before_action :verify_authenticity_token + skip_before_action :setup_laboratory before_action :require_login, :require_admin! diff --git a/app/controllers/admins/competition_prize_users_controller.rb b/app/controllers/admins/competition_prize_users_controller.rb index 50d11e211..34dbc1f76 100644 --- a/app/controllers/admins/competition_prize_users_controller.rb +++ b/app/controllers/admins/competition_prize_users_controller.rb @@ -6,6 +6,16 @@ class Admins::CompetitionPrizeUsersController < Admins::BaseController include_class = [:competition_team, :competition_prize, :approver, user: [:process_real_name_apply, :process_professional_apply, user_extension: :school]] @prize_users = paginate(prize_users.preload(include_class)) + + respond_to do |format| + format.js + format.html + format.xlsx do + @all_prize_users = prize_users + filename = "#{@competition.name}竞赛获奖人信息列表_#{Time.current.strftime('%Y%m%d%H%M%S')}.xlsx" + render xlsx: 'index', filename: filename + end + end end def create diff --git a/app/controllers/admins/enroll_lists_controller.rb b/app/controllers/admins/enroll_lists_controller.rb index fb7cec9b0..f9fac9316 100644 --- a/app/controllers/admins/enroll_lists_controller.rb +++ b/app/controllers/admins/enroll_lists_controller.rb @@ -12,10 +12,6 @@ class Admins::EnrollListsController < Admins::BaseController respond_to do |format| format.js format.html - format.xls{ - filename = "#{@competition.name}竞赛报名列表_#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}.xls" - send_data(shixun_list_xls(shixuns), :type => 'application/octet-stream', :filename => filename_for_content_disposition(filename)) - } end end diff --git a/app/controllers/admins/laboratories_controller.rb b/app/controllers/admins/laboratories_controller.rb index 3bc9383cc..d75b2e11f 100644 --- a/app/controllers/admins/laboratories_controller.rb +++ b/app/controllers/admins/laboratories_controller.rb @@ -1,7 +1,6 @@ class Admins::LaboratoriesController < Admins::BaseController def index - params[:sort_by] = params[:sort_by].presence || 'id' - params[:sort_direction] = params[:sort_direction].presence || 'desc' + default_sort('id', 'desc') laboratories = Admins::LaboratoryQuery.call(params) @laboratories = paginate laboratories.preload(:school, :laboratory_users) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 488289815..5dd001f5a 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -288,11 +288,11 @@ class CoursesController < ApplicationController inform = @course.informs.find_by(id: params[:inform_id]) next_inform = inform.next_inform ActiveRecord::Base.transaction do - if next_inform + if next_inform.blank? render_error('已经到达最顶部') else - inform.update_attribute(:position, (position + 1)) - next_inform.update_attribute(:position, last_inform.position - 1) + inform.update_attribute(:position, (inform.position + 1)) + next_inform.update_attribute(:position, inform.position - 1) render_ok end end @@ -302,11 +302,11 @@ class CoursesController < ApplicationController inform = @course.informs.find_by(id: params[:inform_id]) last_inform = inform.last_inform ActiveRecord::Base.transaction do - if last_inform + if last_inform.blank? render_error('已经到达最底部') else - inform.update_attribute(:position, (position - 1)) - last_inform.update_attribute(:position, last_inform.position + 1) + inform.update_attribute(:position, (inform.position - 1)) + last_inform.update_attribute(:position, inform.position + 1) render_ok end end @@ -317,7 +317,7 @@ class CoursesController < ApplicationController inform = Inform.new(container: @course) inform.name = params[:name] inform.description = params[:description] - inform.position = @course.informs.maximum(:position) + 1 + inform.position = @course.informs.maximum(:position).to_i + 1 inform.save! normal_status("创建成功") end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 48c942e65..ba07d42c9 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -26,12 +26,27 @@ class HomeController < ApplicationController @rep_list << {rep_id: rep.id, rep_name: rep.name, sub_rep_list: sub_rep_list} end - @shixuns = Shixun.where(homepage_show: 1).includes(:tag_repertoires, :challenges).limit(8) + shixuns = current_laboratory.shixuns + subjects = current_laboratory.subjects + + if current_laboratory.main_site? + shixuns = shixuns.where(homepage_show: true) + subjects = subjects.where(homepage_show: true) + else + shixuns = shixuns.where(laboratory_shixuns: { homepage: true }) + subjects = subjects.where(laboratory_subjects: { homepage: true }) + end + + @shixuns = shixuns.includes(:tag_repertoires, :challenges).limit(8) + @subjects = subjects.includes(:repertoire, :shixuns).limit(8) - @subjects = Subject.where(homepage_show: 1).includes(:shixuns, :repertoire).limit(8) + @main_shixuns = Shixun.where(homepage_show: true).includes(:tag_repertoires, :challenges).limit(8) + @main_subjects = Subject.where(homepage_show: true).includes(:shixuns, :repertoire).limit(8) - @tea_users = User.where(homepage_teacher: 1).includes(:user_extension).limit(10).order("experience desc") - @stu_users = User.where(is_test: 0).includes(:user_extension).where(user_extensions: {identity: 1}).limit(10).order("experience desc") + if current_laboratory.main_site? + @tea_users = User.where(homepage_teacher: 1).includes(:user_extension).limit(10).order("experience desc") + @stu_users = User.where(is_test: 0).includes(:user_extension).where(user_extensions: {identity: 1}).limit(10).order("experience desc") + end end def search diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index c1e08d440..3a8a25133 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -103,11 +103,14 @@ class MessagesController < ApplicationController return normal_status(403, "您没有权限进行该操作") if current_user != @message.author && !current_user.teacher_of_course?(@message.board.course) begin - h = {is_md: true} + email_notify = @message.email_notify ? 1 : @board.course.email_notify && params[:email_notify] + send_email = !@message.email_notify && email_notify + h = {is_md: true, email_notify: email_notify} m_params = message_params.merge(h) @message.update_attributes(m_params) Attachment.associate_container(params[:attachment_ids], @message.id, @message.class.name) @message.update_content(params[:content]) + notify_course_students(@message, @board.course) if send_email rescue Exception => e uid_logger_error(e.message) tip_exception("修改失败") @@ -123,6 +126,7 @@ class MessagesController < ApplicationController @message.author = current_user @message.board_id = params[:select_board_id] @message.message_detail_attributes = {content: params[:content]} + @message.email_notify = @board.course.email_notify && params[:email_notify] ? 1 : 0 @message.save! Attachment.associate_container(params[:attachment_ids], @message.id, @message.class.name) if @board.course.email_notify && params[:email_notify] @@ -189,7 +193,7 @@ class MessagesController < ApplicationController private def validate_sort_type - normal_status(2, "参数sort_tyope暂时只支持 'time', 'hot'两种") if params.has_key?(:sort_type) && !SORT_TYPE.include?(params[:sort_type].strip) + normal_status(2, "参数sort_type暂时只支持 'time', 'hot'两种") if params.has_key?(:sort_type) && !SORT_TYPE.include?(params[:sort_type].strip) end def find_message @@ -207,7 +211,7 @@ class MessagesController < ApplicationController def notify_course_students message, course course.students.includes(:user).each do |student| - UserMailer.course_message_email(student&.user&.mail, message.id).deliver_now if student&.user&.mail + UserMailer.course_message_email(student&.user&.mail, message.id).deliver_later if student&.user&.mail end end end diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index e2b78ee4b..cfe6141ee 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -33,7 +33,12 @@ class ShixunsController < ApplicationController current_user.my_shixuns else Shixun.unhidden - end + end + + ## 云上实验室过滤 + unless current_laboratory.main_site? + @shixuns = @shixuns.joins(:laboratory_shixuns).where(laboratory_shixuns: { laboratory_id: current_laboratory.id }) + end ## 方向 if params[:tag_level].present? && params[:tag_id].present? diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index 9c6980b69..b76db8a20 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -23,16 +23,17 @@ class SubjectsController < ApplicationController # 最热排序 if reorder == "myshixun_count" + laboratory_join = current_laboratory.main_site? ? '' : " JOIN laboratory_subjects ls ON ls.subject_id = subjects.id AND ls.laboratory_id = #{current_laboratory.id} " if select @subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, subjects.shixuns_count, subjects.excellent, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns - on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id where + on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id #{laboratory_join} where subjects.hidden = 0 AND subjects.status = 2 AND subjects.name like '%#{search}%' AND subjects.repertoire_id = #{select} GROUP BY subjects.id ORDER BY myshixun_member_count DESC") else @subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, subjects.shixuns_count, subjects.excellent, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns - on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id where + on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id #{laboratory_join} where subjects.hidden = 0 AND subjects.status = 2 AND subjects.name like '%#{search}%' GROUP BY subjects.id ORDER BY myshixun_member_count DESC") end @@ -52,6 +53,11 @@ class SubjectsController < ApplicationController @subjects = Subject.visible.unhidden end + # 云上实验室过滤 + unless current_laboratory.main_site? + @subjects = @subjects.joins(:laboratory_subjects).where(laboratory_subjects: { laboratory_id: current_laboratory.id }) + end + # 类型 if select @subjects = @subjects.where(repertoire_id: select) diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index 5cd9d787c..6e957b4df 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -12,6 +12,6 @@ class UserMailer < ApplicationMailer def course_message_email(mail, message_id) @message = Message.find_by(id: message_id) @course = @message&.board&.course - mail(to: mail, subject: '课堂通知') if @message.present? && @course.present? + mail(to: mail, subject: '课堂发布了新的帖子') if @message.present? && @course.present? end end diff --git a/app/models/inform.rb b/app/models/inform.rb index 93b7d5337..dc979ef32 100644 --- a/app/models/inform.rb +++ b/app/models/inform.rb @@ -7,11 +7,11 @@ class Inform < ApplicationRecord has_many :attachments, as: :container, dependent: :destroy def next_inform - Inform.where(position: self.position+1, container_id: self.container_id, container_type: self.container_type) + Inform.find_by(position: self.position+1, container_id: self.container_id, container_type: self.container_type) end def last_inform - Inform.where(position: self.position-1, container_id: self.container_id, container_type: self.container_type) + Inform.find_by(position: self.position-1, container_id: self.container_id, container_type: self.container_type) end end diff --git a/app/models/laboratory.rb b/app/models/laboratory.rb index ff8f89c5e..672294b63 100644 --- a/app/models/laboratory.rb +++ b/app/models/laboratory.rb @@ -38,4 +38,17 @@ class Laboratory < ApplicationRecord def self.current Thread.current[:current_laboratory] ||= Laboratory.find(1) end + + def shixuns + main_site? ? Shixun.all : Shixun.joins(:laboratory_shixuns).where(laboratory_shixuns: { laboratory_id: id }) + end + + def subjects + main_site? ? Subject.all : Subject.joins(:laboratory_subjects).where(laboratory_subjects: { laboratory_id: id }) + end + + # 是否为主站 + def main_site? + id == 1 + end end \ No newline at end of file diff --git a/app/models/user.rb b/app/models/user.rb index 85b9ef551..5d9ccd0ba 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -235,6 +235,28 @@ class User < ApplicationRecord end end + # 实名认证状态 + def auth_status + status = if authentication + "已认证" + elsif process_real_name_apply.present? + "待审核" + else + "未认证" + end + end + + # 职业认证状态 + def pro_status + status = if professional_certification + "已认证" + elsif process_professional_apply.present? + "待审核" + else + "未认证" + end + end + # 判断当前用户是否通过职业认证 def pro_certification? professional_certification diff --git a/app/services/duplicate_course_service.rb b/app/services/duplicate_course_service.rb index acff0a726..fa57a8901 100644 --- a/app/services/duplicate_course_service.rb +++ b/app/services/duplicate_course_service.rb @@ -94,8 +94,8 @@ class DuplicateCourseService < ApplicationService exercise = course.exercises.create!(attrs.merge(user_id: user.id)) origin_exercise.exercise_questions.find_each do |origin_question| - question_attrs = origin_question.as_json(only: %i[question_title question_type question_number question_score]) - question_attrs[:question_type] ||= 1 + question_attrs = origin_question.as_json(only: %i[question_title question_type question_number question_score shixun_name shixun_id is_ordered level]) + # question_attrs[:question_type] ||= 1 question = exercise.exercise_questions.create!(question_attrs) exercise_choice_map = {} @@ -103,15 +103,20 @@ class DuplicateCourseService < ApplicationService choice_attrs = { choice_position: index + 1, choice_text: origin_choice.choice_text } choice = question.exercise_choices.create!(choice_attrs) - exercise_choice_map[origin_choice.id] = choice.id + # exercise_choice_map[origin_choice.id] = choice.id 标准答案中存的是choice_position, 直接取原题的exercise_choice_id就行 end origin_question.exercise_standard_answers.find_each do |origin_answer| question.exercise_standard_answers.create!( - exercise_choice_id: exercise_choice_map[origin_answer.exercise_choice_id], + exercise_choice_id: origin_answer.exercise_choice_id, answer_text: origin_answer.answer_text ) end + + origin_question.exercise_shixun_challenges.each_with_index do |sc, index| + question.exercise_shixun_challenges.create!({position: index+1, challenge_id: sc.challenge_id, + shixun_id: sc.shixun_id, question_score: sc.question_score}) + end end origin_exercise.exercise_bank.increment!(:quotes) if exercise.exercise_bank diff --git a/app/views/admins/competition_prize_users/index.html.erb b/app/views/admins/competition_prize_users/index.html.erb index dbb86d066..735d94d2e 100644 --- a/app/views/admins/competition_prize_users/index.html.erb +++ b/app/views/admins/competition_prize_users/index.html.erb @@ -50,6 +50,12 @@ <%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %> <%= link_to '清除', admins_competition_competition_prize_users_path(@competition), class: "btn btn-default",'data-disable-with': '清除中...' %> <% end %> + +
+ <%= link_to '导出', admins_competition_competition_prize_users_path(competition_id: @competition.id, format: :xlsx), class: 'btn btn-primary' %> + <%#= javascript_void_link '导出', class: 'btn btn-primary', 'data-url': admins_competition_competition_prize_users_path(competition_id: @competition.id, format: :xlsx) %> +
+ diff --git a/app/views/admins/competition_prize_users/index.xlsx.axlsx b/app/views/admins/competition_prize_users/index.xlsx.axlsx new file mode 100644 index 000000000..63e23a214 --- /dev/null +++ b/app/views/admins/competition_prize_users/index.xlsx.axlsx @@ -0,0 +1,33 @@ +wb = xlsx_package.workbook + +wb.styles do |s| + blue_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:height => 25,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center} + wb.add_worksheet(name: "#{@competition.name}证书审批列表") do |sheet| + sheet.add_row %w(序号 排名 奖项 战队ID 战队名称 姓名 职业 学号 学校名称 学院名称 地区 实名认证 职业认证 手机号码 队长 签领/开户行及银行卡号 审批时间 审批人), :height => 25,:style => blue_cell + + @all_prize_users.each_with_index do |prize_user, index| + user = prize_user.user + data = [ + index + 1, + prize_user.rank, + prize_user.competition_prize.name, + prize_user.competition_team_id, + prize_user.competition_team.name, + user.real_name, + user.identity, + user.student_id, + user.school_name, + user.department_name, + user.location, + user.auth_status, + user.pro_status, + user.phone, + prize_user.leader? ? "是" : "-", + [prize_user.extra&.[]('bank'), prize_user.extra&.[]('second_bank'), prize_user.extra&.[]('card_no')].compact.join('/'), + prize_user.approved_at&.strftime('%Y-%m-%d %H:%M'), + prize_user.approver&.real_name + ] + sheet.add_row(data) + end + end +end diff --git a/app/views/home/index.json.jbuilder b/app/views/home/index.json.jbuilder index aa29ae7ff..5bbd1b799 100644 --- a/app/views/home/index.json.jbuilder +++ b/app/views/home/index.json.jbuilder @@ -3,17 +3,19 @@ json.images_url @images_url json.reps @rep_list json.shixuns do - json.partial! 'shixuns/shixun', locals: {shixuns: @shixuns} + json.partial! 'shixuns/shixun', locals: {shixuns: @shixuns.present? ? @shixuns : @main_shixuns} end json.subjects do - json.partial! 'subjects/subject', locals: {subjects: @subjects} + json.partial! 'subjects/subject', locals: {subjects: @subjects.present? ? @subjects : @main_subjects} end -json.teachers do - json.partial! 'users/user_small', users: @tea_users -end +if current_laboratory.main_site? + json.teachers do + json.partial! 'users/user_small', users: @tea_users + end -json.students do - json.partial! 'users/user_small', users: @stu_users + json.students do + json.partial! 'users/user_small', users: @stu_users + end end diff --git a/app/views/messages/_message.json.jbuilder b/app/views/messages/_message.json.jbuilder index c3ab6c6e3..17e2c39a8 100644 --- a/app/views/messages/_message.json.jbuilder +++ b/app/views/messages/_message.json.jbuilder @@ -1,2 +1,2 @@ json.extract! message, :id, :parent_id, :subject, :created_on, :total_replies_count, :total_praises_count, - :is_md, :praises_count, :visits, :sticky, :is_hidden, :is_public + :is_md, :praises_count, :visits, :sticky, :is_hidden, :is_public, :email_notify diff --git a/app/views/user_mailer/course_message_email.html.erb b/app/views/user_mailer/course_message_email.html.erb index 66c75414b..b3e57b5a2 100644 --- a/app/views/user_mailer/course_message_email.html.erb +++ b/app/views/user_mailer/course_message_email.html.erb @@ -1,7 +1,7 @@ - <%= @course.name %>通知 + <%= @course.name %> 发布了新的帖子 + } - + {hackathonedit===true?"":} -

+ {hackathonedit===true?"":

{data&&data.hackathon.description===null?"":

} -

+

} + + {hackathonedit===true?this.getosshackathonlist()} + hidehackathonedit={()=>this.hidehackathonedit()} + {...this.props} + {...this.state} + />:""} + {this.state.Osshackathonmodeltype===true?this.getosshackathonlist()} + hideeditSignupentry={()=>this.hideeditSignupentry()} + {...this.props} + {...this.state} + />:""} + {this.props.user&&this.props.user.admin===true? + + + + :""} + {/*学生身份*/} { - data&&data.hacks.length==0?"":data&&data.hacks.map((item,key)=>{ + this.props.user&&this.props.user.admin===false?data&&data.hacks.length==0?"":data&&data.hacks.map((item,key)=>{ return( - + + + + {item.name} + + + + {item.entry_info===true?:} + + +

{item.description}

+
) - }) + }):"" } - {/*学生身份*/} - - - - - 大赛介绍 - - - - - - - -

Card content

-

Card content

-
+ + {/*教师身份*/} + {this.props.user&&this.props.user.admin===true?:""} + { + this.props.user&&this.props.user.admin===true?data&&data.hacks.length==0?"":data&&data.hacks.map((item,key)=>{ + return( + + + + {item.name} + + + + this.editSignupentry(item.id,item.name,item.description)}>编辑 + this.delSignupentry(item.id)}>删除 + + + - - - - 大赛介绍 - - - - - - -

Card content

-

Card content

-
+ + +
+ + +
{item.hack_users_count}
+ +
+ + + +
报名数
+ +
+
+ + + {item.description} + +
+ + +
+ )}):"" + } + {data&&data.hacks_count>10?data&&data.hacks.length===0?"":
+ +
:""} + diff --git a/public/react/src/modules/osshackathon/Osshackathonmd.js b/public/react/src/modules/osshackathon/Osshackathonmd.js new file mode 100644 index 000000000..e9a888ab1 --- /dev/null +++ b/public/react/src/modules/osshackathon/Osshackathonmd.js @@ -0,0 +1,111 @@ +import React, { Component } from 'react'; +import {Button, Card, Row, Col ,Upload,Icon,message,Tabs,Form,Input} from 'antd'; +import axios from 'axios'; +import {getImageUrl,getUrl} from 'educoder'; +import TPMMDEditor from '../tpm/challengesnew/TPMMDEditor'; +class Osshackathonmd extends Component{ + constructor(props) { + super(props) + this.contentMdRef = React.createRef(); + this.state={ + title_num: 0, + title_value: undefined + } + } + componentDidUpdate =(prevState)=>{ + // if(prevState!=this.props){ + // let url=`/osshackathon/edit_hackathon.json`; + // axios.get(url).then((result)=>{ + // if(result.status==200){ + // this.setState({ + // title_value:result.data.name + // }) + // this.contentMdRef.current.setValue(result.data.description); + // } + // }) + // } + } + componentDidMount(){ + let url=`/osshackathon/edit_hackathon.json`; + axios.get(url).then((result)=>{ + if(result.status==200){ + this.setState({ + title_value:result.data.name + }) + this.contentMdRef.current.setValue(result.data.description); + } + }) + } + + + // 输入title + changeTitle = (e) => { + // title_num: 60 - parseInt(e.target.value.length), + this.setState({ + title_num: e.target.value.length, + title_value: e.target.value + }) + + } + handleSubmit = () => { + let {title_value}=this.state; + const mdContnet = this.contentMdRef.current.getValue().trim(); + // if(mdContnet.length>10000){ + // this.props.showNotification("内容超过10000个字"); + // return + // } + + let url=`/osshackathon/update_hackathon.json`; + axios.post(url,{ + name:title_value, + description:mdContnet, + } + ).then((response) => { + if(response.data.status===0){ + this.props.getosshackathon() + this.props.hidehackathonedit() + this.props.showNotification(`提交成功`); + } + }).catch((error) => { + console.log(error) + }) + + } + render() { + + + // console.log(this.props.tabkey) + // console.log(chart_rules) + + return ( +
+
+ + + + + + + +
+ + + + +
+ + ) + } +} +export default Osshackathonmd; \ No newline at end of file diff --git a/public/react/src/modules/osshackathon/Osshackathonmodel.js b/public/react/src/modules/osshackathon/Osshackathonmodel.js new file mode 100644 index 000000000..296847510 --- /dev/null +++ b/public/react/src/modules/osshackathon/Osshackathonmodel.js @@ -0,0 +1,217 @@ +import React, { Component } from 'react'; +import {Button, Card, Row, Col ,Upload,Icon,message,Tabs,Form,Input,Modal} from 'antd'; +import axios from 'axios'; +import {getImageUrl,getUrl,WordNumberTextarea} from 'educoder'; + +class Osshackathonmodel extends Component{ + constructor(props) { + super(props) + this.state={ + title_num: 0, + title_value: undefined, + Textarea_comment:undefined + } + } + componentDidUpdate =(prevState)=>{ + // if(prevState!=this.props){ + // let name=this.props&&this.props.modelname; + // let mdvalue=this.props&&this.props.modeldescription; + // this.setState({ + // title_value:name, + // Textarea_comment:mdvalue + // }) + // } + } + componentDidMount(){ + if(this.props.modelid===undefined){ + this.setState({ + title_value:undefined, + Textarea_comment:undefined + }) + }else{ + let url=`/osshackathon/${this.props.modelid}/edit.json`; + axios.get(url).then((result)=>{ + if(result.status==200){ + this.setState({ + title_value:result.data.name, + Textarea_comment:result.data.description + }) + } + }) + } + } + + handleSubmit = () => { + let {title_value,Textarea_comment}=this.state; + // if(mdContnet.length>10000){ + // this.props.showNotification("内容超过10000个字"); + // return + // } + // + + if(this.props.modelid===undefined){ + let url=`/osshackathon.json`; + axios.post(url,{ + name:title_value, + description:Textarea_comment, + } + ).then((response) => { + if(response.data.status===0){ + + this.props.getosshackathon() + this.props.hideeditSignupentry() + this.props.showNotification(`提交成功`); + } + }).catch((error) => { + console.log(error) + }) + }else{ + let url=`/osshackathon/${this.props.modelid}.json` + axios.put(url,{ + name:title_value, + description:Textarea_comment, + } + ).then((response) => { + if(response.data.status===0){ + + this.props.getosshackathon() + this.props.hideeditSignupentry() + this.props.showNotification(`提交成功`); + } + }).catch((error) => { + console.log(error) + }) + } + + } + + changeTitle=(e)=>{ + this.setState({ + title_value:e.target.value, + title_num:e.target.value.length, + }) + } + + Textarea_comment=(e)=>{ + this.setState({ + Textarea_comment:e.target.value, + }) + } + render() { + let {textareavaltype}=this.state; + // console.log(this.props.tabkey) + console.log(this.props.Osshackathonmodeltype) + + return ( +
+ + + + +
+ +
+

+ 名称 +

+ + this.changeTitle(e)} + className={"Osshackathonmodelinput"} + style={{"width": "100%"}} maxLength="60" + addonAfter={String(this.state.title_value===undefined?0:this.state.title_value.length)+"/60"} + /> + +

+ 描述 +

+ + this.Textarea_comment(e)} + value={this.state.Textarea_comment} + maxlength={500} + /> + +
  • 评阅内容至少有一个不为空
  • +
    + +
    +
    + +
    + + ) + } +} +export default Osshackathonmodel; \ No newline at end of file