Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<link rel="shortcut icon" href="assets/favicon2.ico">
<title>Search</title>
<meta name="description" content="">
<meta name="keywords" content="">
<link href="" rel="stylesheet">
<script src="js/vue.js"></script>
<script src="js/vue-resource.js"></script>
<script src="js/element.js"></script>
<script src="js/sweet-alert.js"></script>
<script src="js/jquery-3.3.1.js"></script>
<script src="js/highlight.pack.js"></script>
<script src="js/quill.js"></script>
<script src="js/image-resize.min.js"></script>
<link rel="stylesheet" href="css/atom-one-dark.css">
<link rel="stylesheet" href="css/quill.snow.css">
<link rel="stylesheet" href="css/element.css">
<link rel="stylesheet" href="css/sweet-alert.css">
<link rel="stylesheet" href="css/index.css">
<style>
.el-collapse-item__header {
font-size: 16px;
}
.ql-editor {
min-height: 400px;
}
</style>
</head>
<body>
<div id="app">
<div class="index-nav">
<a @click="dialogloginVisible=true" v-if="user.username==''"
style="float: right;position: relative;right: 30px;top: 25px;text-decoration: none;cursor: pointer;">
Sign in
</a>
<a href="#" v-if="user.username!=''" @click='signout'
style="float: right;position: relative;right: 30px;top: 25px;text-decoration: none; margin-left: 30px;">
Sign out
</a>
<a href="#" v-if="user.username!=''"
style="float: right;position: relative;right: 30px;top: 25px;text-decoration: none;">
{{user.username}}
</a>
<div style="float: right;position: relative;top: 10px;right: 50px;">
<img v-if="user.username!=''" :src="user.avatar" style="width: 50px;height: 50px;border-radius: 50%;" alt="">
</div>
<div class="logo-container" onclick="window.location.href='/index.html'">
<img class="logo" src="assets/logo2.jpg">
<div style="align-self: center;font-size: 25px;font-family: xingshu;">Intelligent Q&A System</div>
<el-link class="nav-link" type="primary" href="index.html">Search</el-link>
<el-link class="nav-link" href="playground.html">Q & A platform</el-link>
<el-link v-if="user.user_type=='teacher'" class="nav-link" href="manager.html">Manage</el-link>
</div>
</div>
<div id="question-container">
<div>
<el-input placeholder="Input question" prefix-icon="el-icon-search" v-model="question_query" >
<el-button slot="append" icon="el-icon-search" @click="submit"></el-button>
</el-input>
</div>
<div id="answer-list">
<el-collapse v-model="show_Questions" v-if="question_list.length>0">
<el-collapse-item v-for="(question, index) in question_list" :name="index">
<template slot="title">
{{question.content}}
</template>
<div class="answer" v-for="answer in question.answer_list" v-html="answer.content">
</div>
</el-collapse-item>
</el-collapse>
<div v-if="question_list.length==0 && showNone">
<p>Sorry,No answers</p>
</div>
</div>
<el-switch v-model="needhelp" active-text="No solved" inactive-text="Solved">
</el-switch>
<div v-show="needhelp" style="margin-top: 20px;" v-loading="loading" element-loading-text="loading"
element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.8)">
<el-input placeholder="Enter question content" prefix-icon="el-icon-search" v-model="question_query"
style="margin: 20px 0 20px 0;">
</el-input>
<div id="editor">
</div>
<div style="text-align: right;margin: 20px;">
<el-button type="primary" @click.prevent="submitQuestion">Submit question</el-button>
</div>
</div>
</div>
<el-dialog title="Sign in" :visible.sync="dialogloginVisible" @keyup.enter.native="login">
<el-form>
<el-form-item label="Username">
<el-input v-model="username" autocomplete="off"></el-input>
</el-form-item>
<el-form-item label="Student NO">
<el-input v-model="user_no" autocomplete="off"></el-input>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogloginVisible = false">Cancel</el-button>
<el-button type="primary" @click="login">Login</el-button>
</div>
</el-dialog>
</el-pagination>
</div>
<script>
var vm = new Vue({
el: "#app",
data: {
needhelp: false,
question_query: "",
user: {
username: "",
user_type: "",
id: 0
},
dialogloginVisible: false,
user_no: "",
username:"",
show_Questions: [0],
question_list: [],
loading: false,
currentPage:1,
showNone:false,
},
beforeCreate() {
$.ajax({
url: "http://47.102.143.222:8088/",
method: 'get',
xhrFields: {
withCredentials: true
},
success: (response) => {
if (response["id"] == "-1")
this.user["id"] = -1;
else
this.user = response;
}
});
},
methods: {
pageChange(){
console.log(this.currentPage)
},
validateUser(new_value){
if(new_value && this.user.username==""){
this.dialogloginVisible = true;
this.needhelp = false;
}
},
submit() {
if (this.question_query == "" || this.question_query.trim()=="") {
this.$notify({
title: "∑( 口 ||Question?",
message: "You should input question content",
type: 'warning'
});
return;
}
//加载loading效果
var search_loading = this.$loading({
lock: true,
text: 'Searching~~~',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)'
});
//发送请求
this.$http.post("http://47.102.143.222:8088/searchQuestion/", {
question: this.question_query
}, {
emulateJSON: true
}).then(
response => {
console.log(response.body);
this.question_list = response.body["question_list"];
this.question_list.sort((question1, question2) => {
if (question1.score >= question2.score) {
return -1;
} else {
return 1;
}
});
this.showNone = true;
search_loading.close();
}
)
},
signout() {
var cookies = document.cookie.split(";");
var new_cookie = [];
for(let cookie of cookies){
document.cookie = cookie.split("=")[0] + "=; ";
}
swal({
title:"Sign out successfully",
text:"Hope next login",
type:"success",
},
()=>{
location.reload();
}
);
},
login() {
if(this.username =="" || this.user_no==""){
this.dialogloginVisible = false;
swal("Please input username or password", "Check it again", "warning");
return;
}
$.ajax({
url: "http://47.102.143.222:8088/login/",
method: 'post',
xhrFields: {
withCredentials: true
},
data: {
user_no: this.user_no,
username: this.username
},
success: (response) => {
if (response["id"] == "-1"){
this.user["id"] = -1;
swal("Wrong", "incorrect username or password", "error");
}
else{
swal("Sign in successfully", "Welcome Back", "success");
this.user = response;
}
this.dialogloginVisible = false;
}
});
},
submitQuestion() {
if (this.user.id == 0 || this.user.id==null || this.user.id==-1) {
//如果没有登陆则跳转
alert("Please Sign in first.");
return;
}
if (this.question_query=="") {
alert("Question content should not empty");
return;
}
content = document.getElementsByClassName("ql-editor");
if (content[0].innerText == "\n") {
alert("Question content should not empty");
return;
}
this.loading = true;
imgs = content[0].getElementsByTagName('img');
if (imgs.length > 0) {
for (let i = 0; i < imgs.length; i++) {
img_data = {
img: imgs[i].src,
index: i,
question_id: 0
};
this.$http.post('http://47.102.143.222:8088/img_src_change/', img_data, {
emulateJSON: true
}).then(response => {
if (response.status == 200) {
console.log("图片src修改成功 " + response.body['img_src']);
imgs[i].src = response.body["img_src"];
if (i == imgs.length - 1) {
this.save_question(response.body['question_id']);
}
} else {
alert("图片src更改失败");
this.loading = false;
}
});
}
} else {
this.save_question();
}
},
save_question(question_id) {
var content = document.getElementsByClassName("ql-editor");
console.log(content[0].innerHTML);
var reply_data = {
user_id: this.user.id,
question_id: question_id ? question_id : 0,
user_type: this.user.user_type,
detail_content: content[0].innerHTML,
content: this.question_query
};
this.$http.post('http://47.102.143.222:8088/addQuestion/',
reply_data, {
emulateJSON: true
}).then(response => {
if (response.status == 200) {
if (response.body['result'] == '0') {
content.innerText = "\n";
swal("Add it successfully", "Wait for answer yoooooo~", "success");
content[0].innerHTML = "";
this.question_query = "";
} else {
swal("Add it unsuccessfully", "there may something wrong", "warning");
}
} else {
swal("Add it unsuccessfully", "server does not work", "error");
}
this.loading = false;
})
},
}
});
var toolbarOptions = [
['bold', 'italic', 'underline', 'strike'], // 切换按钮
['blockquote', 'image', 'code-block'],
[{
'header': 1
}, {
'header': 2
}], // 用户自定义按钮值
[{
'list': 'ordered'
}, {
'list': 'bullet'
}],
[{
'script': 'sub'
}, {
'script': 'super'
}], // 上标/下标
[{
'indent': '-1'
}, {
'indent': '+1'
}], // 减少缩进/缩进
[{
'direction': 'rtl'
}], // 文本下划线
[{
'size': ['small', false, 'large', 'huge']
}], // 用户自定义下拉
[{
'header': [1, 2, 3, 4, 5, 6, false]
}],
[{
'color': []
}, {
'background': []
}], // 主题默认下拉,使用主题提供的值
[{
'font': []
}],
[{
'align': []
}],
['clean'] // 清除格式
];
var quill = new Quill('#editor', {
modules: {
toolbar: toolbarOptions,
imageResize: {}
},
theme: 'snow',
placeholder: 'Input question content'
});
document.getElementsByClassName('ql-code-block')[0].addEventListener("click", event => {
console.log("sss");
for (let element of document.getElementsByTagName("pre")) {
hljs.highlightBlock(element);
}
});
</script>
</body>
</html>