整理

上级 57cce4a8
...@@ -144,11 +144,12 @@ export default { ...@@ -144,11 +144,12 @@ export default {
this.interviewPage() this.interviewPage()
}, },
mounted() { mounted() {
// 在页面加载时从localStorage中获取currentPage的值 this.currentPage = 1
const storedPage = localStorage.getItem('poetryLastPage') // // 在页面加载时从localStorage中获取currentPage的值
if (storedPage) { // const storedPage = localStorage.getItem('poetryLastPage')
this.currentPage = parseInt(storedPage) // if (storedPage) {
} // this.currentPage = parseInt(storedPage)
// }
}, },
methods: { methods: {
prepareAdd() { prepareAdd() {
...@@ -203,6 +204,8 @@ export default { ...@@ -203,6 +204,8 @@ export default {
}) })
if (res.code === 200) { if (res.code === 200) {
this.form.poetryText = '' this.form.poetryText = ''
this.currentPage=1
this.interviewPage()
} else { } else {
console.error('Received non-200 status code', res) console.error('Received non-200 status code', res)
this.errorMsg(res.message) this.errorMsg(res.message)
......
...@@ -105,330 +105,332 @@ ...@@ -105,330 +105,332 @@
<script> <script>
import axios from 'axios' import axios from 'axios'
export default { export default {
name: 'MyInterview', name: 'MyInterview',
data() { data() {
return { return {
// 用户列表数据 // 用户列表数据
userlist: [], userlist: [],
loading: false, loading: false,
elementui_page_component_key: 0, elementui_page_component_key: 0,
currentPage: Number(localStorage.getItem('interviewLastPage')) || 1, currentPage: Number(localStorage.getItem('interviewLastPage')) || 1,
pageSize: 9, pageSize: 9,
total: 0, total: 0,
formInline: { formInline: {
question: '', question: '',
}, },
options: [], options: [],
questionType: 0, questionType: 0,
// 新增的内容 // 新增的内容
dialogFormVisible: false, dialogFormVisible: false,
dialogMutiFormVisible: false, dialogMutiFormVisible: false,
form: { form: {
question: '', question: '',
questionType: 0, questionType: 0,
}, },
formLabelWidth: '120px', formLabelWidth: '120px',
dialogVisible: false, dialogVisible: false,
editVisible: false, editVisible: false,
currentRowId: null, currentRowId: null,
colorMap: {}, // 创建一个空的颜色映射关系对象 colorMap: {}, // 创建一个空的颜色映射关系对象
} }
}, },
watch: { watch: {
'formInline.question'(newVal) { 'formInline.question'(newVal) {
if (newVal === '') { if (newVal === '') {
this.currentPage = 1 this.currentPage = 1
localStorage.setItem('interviewLastPage', this.currentPage) localStorage.setItem('interviewLastPage', this.currentPage)
this.getQuestionType() this.getQuestionType()
} }
}, },
// 监听currentPage的变化,将新值保存到localStorage中 // 监听currentPage的变化,将新值保存到localStorage中
currentPage(newPage) { currentPage(newPage) {
localStorage.setItem('interviewLastPage', newPage.toString()) localStorage.setItem('interviewLastPage', newPage.toString())
}, },
}, },
created() { created() {
//获取问题列表 //获取问题列表
this.getQuestionType() this.getQuestionType()
}, },
mounted() { mounted() {
// 在页面加载时从localStorage中获取currentPage的值 this.currentPage = 1
const storedPage = localStorage.getItem('interviewLastPage') // // 在页面加载时从localStorage中获取currentPage的值
if (storedPage) { // const storedPage = localStorage.getItem('interviewLastPage')
this.currentPage = parseInt(storedPage) // if (storedPage) {
} // this.currentPage = parseInt(storedPage)
}, // }
methods: { },
prepareAdd() { methods: {
this.form.question = '' prepareAdd() {
this.form.questionType = 0 this.form.question = ''
this.dialogFormVisible = true this.form.questionType = 0
}, this.dialogFormVisible = true
prepareMutiAdd() { },
this.form.question = '' prepareMutiAdd() {
this.form.questionType = 0 this.form.question = ''
this.dialogMutiFormVisible = true this.form.questionType = 0
}, this.dialogMutiFormVisible = true
},
prepareDelete(id) { prepareDelete(id) {
this.currentRowId = id this.currentRowId = id
this.dialogVisible = true this.dialogVisible = true
}, },
preEdit(id, question, questionTypeName) { preEdit(id, question, questionTypeName) {
this.form.question = question this.form.question = question
// 定义一个映射(map)来存储 questionType 到 name 的转换 // 定义一个映射(map)来存储 questionType 到 name 的转换
const questionTypeToNameMap = {} const questionTypeToNameMap = {}
this.options.forEach((option) => { this.options.forEach((option) => {
questionTypeToNameMap[option.name] = option.questionType questionTypeToNameMap[option.name] = option.questionType
}) })
this.form.questionType = questionTypeToNameMap[questionTypeName] this.form.questionType = questionTypeToNameMap[questionTypeName]
this.currentRowId = id this.currentRowId = id
this.editVisible = true this.editVisible = true
}, },
handleClose(done) { handleClose(done) {
this.$confirm('确认关闭?') this.$confirm('确认关闭?')
.then((_) => { .then((_) => {
done() done()
}) })
.catch((_) => {}) .catch((_) => {})
}, },
handleConfirm(addType) { handleConfirm(addType) {
this.dialogFormVisible = false // 关闭对话框 this.dialogFormVisible = false // 关闭对话框
this.dialogMutiFormVisible = false this.dialogMutiFormVisible = false
this.addQuestion(addType) // 发送请求 this.addQuestion(addType) // 发送请求
}, },
async addQuestion(addType) { async addQuestion(addType) {
try { try {
this.loading = true this.loading = true
const { data: res } = await axios.post('http://120.79.36.53:8888/interviewQuestion/add', { const { data: res } = await axios.post('http://120.79.36.53:8888/interviewQuestion/add', {
addType: addType, addType: addType,
question: this.form.question, question: this.form.question,
questionType: this.form.questionType, questionType: this.form.questionType,
}) })
if (res.code === 200) { if (res.code === 200) {
this.form.question = '' this.currentPage = 1
this.form.questionType = 0 this.form.question = ''
this.getQuestionType() // 确保这个方法是有效的 this.form.questionType = 0
} else { this.getQuestionType() // 确保这个方法是有效的
console.error('Received non-200 status code', res) } else {
this.errorMsg(res.message) console.error('Received non-200 status code', res)
} this.errorMsg(res.message)
} catch (error) { }
console.error('An error occurred while adding the question:', error) } catch (error) {
// 异常处理逻辑 console.error('An error occurred while adding the question:', error)
} finally { // 异常处理逻辑
this.loading = false } finally {
} this.loading = false
}, }
errorMsg(msg) { },
this.$message({ errorMsg(msg) {
showClose: true, this.$message({
message: msg, showClose: true,
type: 'error', message: msg,
}) type: 'error',
}, })
async editConfirm() { },
try { async editConfirm() {
this.loading = true try {
this.loading = true
const { data: res } = await axios.post('http://120.79.36.53:8888/interviewQuestion/update', { const { data: res } = await axios.post('http://120.79.36.53:8888/interviewQuestion/update', {
id: this.currentRowId, id: this.currentRowId,
question: this.form.question, question: this.form.question,
questionType: this.form.questionType, questionType: this.form.questionType,
}) })
if (res.code === 200) { if (res.code === 200) {
this.form.question = '' this.form.question = ''
this.form.questionType = 0 this.form.questionType = 0
this.editVisible = false this.editVisible = false
currentRowId: null currentRowId: null
this.getQuestionType() // 确保这个方法是有效的 this.getQuestionType() // 确保这个方法是有效的
} else { } else {
console.error('Received non-200 status code', res) console.error('Received non-200 status code', res)
} }
} catch (error) { } catch (error) {
console.error('An error occurred while adding the question:', error) console.error('An error occurred while adding the question:', error)
// 异常处理逻辑 // 异常处理逻辑
} finally { } finally {
this.loading = false this.loading = false
} }
}, },
async onDelete(id) { async onDelete(id) {
this.dialogVisible = false this.dialogVisible = false
this.loading = true this.loading = true
const { data: res } = await axios.get('http://120.79.36.53:8888/interviewQuestion/delete', { const { data: res } = await axios.get('http://120.79.36.53:8888/interviewQuestion/delete', {
params: { params: {
id: id, id: id,
}, },
}) })
this.getQuestionType() this.getQuestionType()
this.loading = false this.loading = false
}, },
refreshPage() { refreshPage() {
//获取问题类型的枚举 //获取问题类型的枚举
this.getQuestionType() this.getQuestionType()
location.reload() location.reload()
}, },
async getQuestionType() { async getQuestionType() {
const { data: res } = await axios.get('http://120.79.36.53:8888/interviewQuestion/questionType', { params: {} }) const { data: res } = await axios.get('http://120.79.36.53:8888/interviewQuestion/questionType', { params: {} })
if (res.code === 200) { if (res.code === 200) {
this.options = res.result this.options = res.result
this.interviewPage() this.interviewPage()
} }
}, },
async interviewPage() { async interviewPage() {
this.loading = true this.loading = true
const { data: res } = await axios.get('http://120.79.36.53:8888/interviewQuestion/page', { const { data: res } = await axios.get('http://120.79.36.53:8888/interviewQuestion/page', {
params: { params: {
page: this.currentPage, page: this.currentPage,
pageSize: this.pageSize, pageSize: this.pageSize,
question: this.formInline.question, question: this.formInline.question,
questionType: this.questionType, questionType: this.questionType,
}, },
}) })
if (res.code === 200) { if (res.code === 200) {
this.total = res.result.totalElements this.total = res.result.totalElements
// 定义一个映射(map)来存储 questionType 到 name 的转换 // 定义一个映射(map)来存储 questionType 到 name 的转换
const questionTypeToNameMap = {} const questionTypeToNameMap = {}
this.options.forEach((option) => { this.options.forEach((option) => {
questionTypeToNameMap[option.questionType] = option.name questionTypeToNameMap[option.questionType] = option.name
}) })
// 修改 userlist 中的每一个元素,将 questionType 转换为 name // 修改 userlist 中的每一个元素,将 questionType 转换为 name
res.result.content.forEach((user) => { res.result.content.forEach((user) => {
user.questionTypeName = questionTypeToNameMap[user.questionType] || 'Unknown' user.questionTypeName = questionTypeToNameMap[user.questionType] || 'Unknown'
}) })
this.userlist = res.result.content this.userlist = res.result.content
} }
this.loading = false this.loading = false
}, },
handleCurrentChange(currentPage) { handleCurrentChange(currentPage) {
this.currentPage = currentPage this.currentPage = currentPage
this.getQuestionType() this.getQuestionType()
}, },
getColorForValue(value) { getColorForValue(value) {
// 检查颜色映射关系中是否已经有该值对应的颜色 // 检查颜色映射关系中是否已经有该值对应的颜色
if (!this.colorMap[value]) { if (!this.colorMap[value]) {
// 如果没有,随机生成一个颜色并将其关联到该值 // 如果没有,随机生成一个颜色并将其关联到该值
this.colorMap[value] = this.getRandomColor() this.colorMap[value] = this.getRandomColor()
} }
// 返回值对应的颜色 // 返回值对应的颜色
return this.colorMap[value] return this.colorMap[value]
}, },
getRandomColor() { getRandomColor() {
// 从颜色数组中随机选取一个颜色 // 从颜色数组中随机选取一个颜色
const colorArray = [ const colorArray = [
'red', 'red',
'blue', 'blue',
'green', 'green',
'yellow', 'yellow',
'purple', 'purple',
'orange', 'orange',
'pink', 'pink',
'brown', 'brown',
'cyan', 'cyan',
'magenta', 'magenta',
'maroon', 'maroon',
'navy', 'navy',
'olive', 'olive',
'teal', 'teal',
'lime', 'lime',
'aqua', 'aqua',
'silver', 'silver',
'gray', 'gray',
'white', 'white',
'indigo', 'indigo',
'violet', 'violet',
'lavender', 'lavender',
'coral', 'coral',
'gold', 'gold',
'salmon', 'salmon',
'turquoise', 'turquoise',
'orchid', 'orchid',
'khaki', 'khaki',
'slategray', 'slategray',
'thistle', 'thistle',
'burlywood', 'burlywood',
'cadetblue', 'cadetblue',
'chartreuse', 'chartreuse',
'chocolate', 'chocolate',
'crimson', 'crimson',
'darkblue', 'darkblue',
'darkcyan', 'darkcyan',
'darkgoldenrod', 'darkgoldenrod',
'darkgray', 'darkgray',
'darkgreen', 'darkgreen',
'darkkhaki', 'darkkhaki',
'darkmagenta', 'darkmagenta',
'darkolivegreen', 'darkolivegreen',
'darkorange', 'darkorange',
'darkorchid', 'darkorchid',
'darkred', 'darkred',
'darksalmon', 'darksalmon',
'darkseagreen', 'darkseagreen',
'darkslateblue', 'darkslateblue',
'darkslategray', 'darkslategray',
'darkturquoise', 'darkturquoise',
'darkviolet', 'darkviolet',
'deeppink', 'deeppink',
'deepskyblue', 'deepskyblue',
'dodgerblue', 'dodgerblue',
'firebrick', 'firebrick',
'forestgreen', 'forestgreen',
'fuchsia', 'fuchsia',
'gold', 'gold',
'greenyellow', 'greenyellow',
'hotpink', 'hotpink',
'indianred', 'indianred',
'lawngreen', 'lawngreen',
'lightcoral', 'lightcoral',
'lightgreen', 'lightgreen',
'lightpink', 'lightpink',
'lightsalmon', 'lightsalmon',
'lightseagreen', 'lightseagreen',
'lightskyblue', 'lightskyblue',
'lightslategray', 'lightslategray',
'lightsteelblue', 'lightsteelblue',
'mediumaquamarine', 'mediumaquamarine',
'mediumblue', 'mediumblue',
'mediumorchid', 'mediumorchid',
'mediumpurple', 'mediumpurple',
'mediumseagreen', 'mediumseagreen',
'mediumslateblue', 'mediumslateblue',
'mediumspringgreen', 'mediumspringgreen',
'mediumturquoise', 'mediumturquoise',
'mediumvioletred', 'mediumvioletred',
'midnightblue', 'midnightblue',
'orangered', 'orangered',
'palegoldenrod', 'palegoldenrod',
'palegreen', 'palegreen',
'paleturquoise', 'paleturquoise',
'palevioletred', 'palevioletred',
'peru', 'peru',
'powderblue', 'powderblue',
'rosybrown', 'rosybrown',
'saddlebrown', 'saddlebrown',
'seagreen', 'seagreen',
'sienna', 'sienna',
'skyblue', 'skyblue',
'slateblue', 'slateblue',
'springgreen', 'springgreen',
'tan', 'tan',
'thistle', 'thistle',
'tomato', 'tomato',
'turquoise', 'turquoise',
'violet', 'violet',
] ]
const randomIndex = Math.floor(Math.random() * colorArray.length) const randomIndex = Math.floor(Math.random() * colorArray.length)
return colorArray[randomIndex] return colorArray[randomIndex]
}, },
}, },
} }
</script> </script>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册