Browse Source

接口对接,登录

admin_zwk
zhaowenkang 5 months ago
parent
commit
7fdb04a5ea
  1. 12
      work/src/api/LoginApi.js
  2. 2
      work/src/api/UpdateWorkApi.js
  3. 42
      work/src/views/AddWork.vue
  4. 26
      work/src/views/HomeWork.vue
  5. 47
      work/src/views/Login.vue
  6. 31
      work/src/views/UpdateWork.vue
  7. 42
      work/src/views/WorkDetail.vue
  8. 2
      work/vite.config.js

12
work/src/api/LoginApi.js

@ -0,0 +1,12 @@
import service from ".";
const LoginApi={
//登录
login(username,password){
return service.post("/api/login",username,password)
},
//退出登录
logout(token){
return service.post("/api/logout",token)
}
}
export default LoginApi;

2
work/src/api/UpdateWorkApi.js

@ -14,7 +14,7 @@ const UpdateWorkApi={
},
//数据导出
excelexport(data){
return service.post("/api/homework_manage/excelexport",data)
return service.post("/api/homework_manage/exceleexport",data)
}
}
export default UpdateWorkApi;

42
work/src/views/AddWork.vue

@ -3,7 +3,7 @@
<el-container>
<el-header class="header">
<el-text class="header-text">抢点班作业后台管理</el-text>
<el-button class="header-button" type="primary" text style="float: right;">退出登录</el-button>
<el-button class="header-button" type="primary" text style="float: right;" @click="logout">退出登录</el-button>
</el-header>
<el-main class="main">
<div class="main-title">
@ -92,6 +92,11 @@ import AddWorkApi from '../api/AddWorkApi';
import _ from 'lodash';
import dayjs from 'dayjs';
import { ElMessage } from 'element-plus'
import LoginApi from '../api/LoginApi';
import axios from 'axios';
import { useRouter } from 'vue-router';
const router = useRouter();
const options = ref([
{ id: 1, name: '牧民俱乐部' },
@ -232,20 +237,31 @@ const addBlank = () => {
});
};
// const addOption = (questionIndex) => {
// const currentQuestion = questions.value[questionIndex];
// const currentContent = JSON.parse(currentQuestion.content);
// currentContent.push({ "id": "", "text": "" });
// currentQuestion.content = JSON.stringify(currentContent);
// };
// const removeOption = (questionIndex, optionIndex) => {
// const currentQuestion = questions.value[questionIndex];
// const currentContent = JSON.parse(currentQuestion.content);
// currentContent.splice(optionIndex, 1);
// currentQuestion.content = JSON.stringify(currentContent);
// };
const addOption = (questionIndex) => {
const currentQuestion = questions.value[questionIndex];
const currentContent = JSON.parse(currentQuestion.content);
currentContent.push({ "id": "", "text": "" });
currentQuestion.content = JSON.stringify(currentContent);
// content
if (!currentQuestion.content) {
currentQuestion.content = [];
}
currentQuestion.content.push({ id: "", text: "" });
};
const removeOption = (questionIndex, optionIndex) => {
const currentQuestion = questions.value[questionIndex];
const currentContent = JSON.parse(currentQuestion.content);
currentContent.splice(optionIndex, 1);
currentQuestion.content = JSON.stringify(currentContent);
currentQuestion.content.splice(optionIndex, 1);
};
const removeQuestion = (questionIndex) => {
questions.value.splice(questionIndex, 1);
};
@ -271,6 +287,14 @@ const handleMouseLeave = (index) => {
onMounted(() => {
isHovered.value = Array(questions.value.length).fill(false);
});
//退
const logout = () => {
LoginApi.logout().then(res => {
console.log(res)
})
router.push('/')
}
</script>
<style scoped>

26
work/src/views/HomeWork.vue

@ -3,7 +3,7 @@
<el-container>
<el-header class="header">
<el-text class="header-text">抢点班作业后台管理</el-text>
<el-button class="header-button" type="primary" text style="float: right;">退出登录</el-button>
<el-button class="header-button" type="primary" text style="float: right;" @click="logout">退出登录</el-button>
</el-header>
<el-main class="main">
<div class="main-title">
@ -87,9 +87,10 @@
import { ref, onMounted } from 'vue';
import { ElMessage } from 'element-plus';
import ClassListApi from '../api/ClassListApi';
import axios from 'axios';
import { useRouter } from 'vue-router';
import LoginApi from '../api/LoginApi';
const router = useRouter();
const assignments = ref([]);
@ -143,10 +144,9 @@ const viewDetails = async(row) => {
} catch (error) {
console.log('获取数据出错:', error)
}
};
const router = useRouter();
//
const editAssignment = async (row) => {
try {
@ -159,6 +159,22 @@ const editAssignment = async (row) => {
console.log('获取数据出错:', error)
}
};
// 退
const logout = () => {
LoginApi.logout().then(res => {
console.log(res);
// axiostoken
axios.interceptors.request.eject(axios.interceptors.request.handlers.find(
handler => handler.fulfilled && handler.fulfilled.toString().includes('Authorization')
));
}).catch(err => {
// 退
ElMessage.error('退出登录失败,请稍后重试');
}).finally(() => {
//
router.push('/');
});
}
</script>
<style scoped>

47
work/src/views/Login.vue

@ -24,16 +24,53 @@
<script setup>
import { ref } from 'vue';
import LoginApi from '../api/LoginApi';
import { ElMessage } from 'element-plus';
import { useRouter } from 'vue-router';
import axios from 'axios';
// 使ref
const username = ref('');
const password = ref('');
// token
const token = ref('');
const router = useRouter();
//
const login = () => {
// API
console.log('用户名:', username.value);
console.log('密码:', password.value);
const login = async() => {
if (!username.value ||!password.value) {
ElMessage.error('账号和密码不能为空,请输入完整信息');
return;
}
try {
// LoginApi
const response = await LoginApi.login({
username: username.value,
password: password.value
});
if (response.code === 200) {
// token
token.value = response.data.token;
// axiostoken
axios.interceptors.request.use(config => {
config.headers.Authorization = `${token.value}`;
return config;
});
console.log(token.value);
//
ElMessage.success('登录成功');
//
router.push('/list');
} else {
//
ElMessage.error(response.message || '登录失败,请稍后重试');
}
} catch (error) {
//
ElMessage.error('网络异常,请检查网络连接后重试');
console.error(error);
}
};
</script>

31
work/src/views/UpdateWork.vue

@ -33,7 +33,7 @@
@select="handleSelectArticle" clearable/>
</el-form-item>
<el-form-item label="关联直播">
<el-select v-model="form.LiveId" placeholder="请选择" style="width: 100%" clearable>
<el-select v-model="form.LiveId" placeholder="请选择" style="width: 100%" clearable @change="handleLiveChange">
<el-option v-for="item in live" :key="item.id" :label="item.name" :value="item.id"/>
</el-select>
</el-form-item>
@ -184,7 +184,7 @@ onMounted(async () => {
if (homeworkData.value.article && homeworkData.value.article.title) {
articleTitle.value = homeworkData.value.article.title;
} else if (homeworkData.value.live && homeworkData.value.live.name) {
form.value.LiveId = homeworkData.value.live.name;
form.value.LiveId = homeworkData.value.live.id;
}
form.value.ClubType = homeworkData.value.clubType;
const processFormData = () => {
@ -261,6 +261,12 @@ const back = () => {
const articleSearchResults = ref([]);
//
const queryArticleList = async (queryString: string) => {
if (form.value.LiveId) {
ElMessage.warning('您已关联直播,暂无法关联文章');
articleTitle.value = ''; //
form.value.LiveId = '';
return [];
}
try {
const response = await AddWorkApi.getArticleList(queryString);
const formattedResults = response.data.map(article => ({
@ -274,6 +280,14 @@ const queryArticleList = async (queryString: string) => {
return [];
}
};
const handleLiveChange = () => {
if (form.value.ArticleId) {
ElMessage.warning('您已关联文章,暂无法关联直播');
form.value.LiveId = ''; //
form.value.ArticleId = '';
articleTitle.value = '';
}
};
//
const handleSelectArticle = (article: { label: string }) => {
// idarticle.label使
@ -339,16 +353,15 @@ const addBlank = () => {
const addOption = (questionIndex) => {
const currentQuestion = questions.value[questionIndex];
const currentContent = JSON.parse(currentQuestion.content);
currentContent.push({ "id": "", "text": "" });
currentQuestion.content = JSON.stringify(currentContent);
// content
if (!currentQuestion.content) {
currentQuestion.content = [];
}
currentQuestion.content.push({ id: "", text: "" });
};
const removeOption = (questionIndex, optionIndex) => {
const currentQuestion = questions.value[questionIndex];
const currentContent = JSON.parse(currentQuestion.content);
currentContent.splice(optionIndex, 1);
currentQuestion.content = JSON.stringify(currentContent);
currentQuestion.content.splice(optionIndex, 1);
};
const removeQuestion = (questionIndex) => {

42
work/src/views/WorkDetail.vue

@ -50,14 +50,16 @@
</el-table-column>
<el-table-column label="作业详情">
<template v-slot="{ $index }">
<el-popover placement="bottom" title="详情" :width="600" trigger="click"
:content="`${getContent($index).formTitle}${getContent($index).contentTitle}${getContent($index).content}`">
<el-popover placement="bottom" title="详情" :width="500" trigger="click">
<template #reference>
<el-button link type="primary">查看</el-button>
</template>
<div>{{ getContent($index).formTitle }}</div>
<div>{{ getContent($index).contentTitle }}</div>
<div>{{ getContent($index).content }}</div>
<div v-for="(r, subIndex) in getContent($index).replies" :key="subIndex">
<div>{{ r.formTitle }}</div>
<div>{{ r.contentTitle }}</div>
<div>{{ r.content }}</div>
<div style="margin-bottom: 10px;"></div>
</div>
</el-popover>
</template>
</el-table-column>
@ -173,31 +175,45 @@ const id = ref(route.params.id)
console.log(id.value + '============')
const workdetailData = ref([]);
// onMounted(async () => {
// try {
// const response = await ClassListApi.getWorkDetail(id.value, PageNo.value, PageSize.value);
// workdetailData.value = response.data;
// console.log(workdetailData.value);
// } catch (error) {
// console.error(':', error);
// }
// });
onMounted(async ()=>{
const refdata = {
id: id.value,
pageNo:PageNo.value,
pageSize:PageSize.value
}
try {
const response = await ClassListApi.getWorkDetail(id.value, PageNo.value, PageSize.value);
const response = await UpdateWorkApi.getrecordbycondition(refdata);
workdetailData.value = response.data;
console.log(workdetailData.value);
} catch (error) {
console.error('接口请求出现错误:', error);
}
});
})
const getContent = (index) => {
if (workdetailData.value && workdetailData.value[index] && workdetailData.value[index].Reply) {
const reply = workdetailData.value[index].Reply[0];
const replies = workdetailData.value[index].Reply;
return {
// reply
replies: replies.map((reply) => ({
formTitle: reply.formTitle,
contentTitle: reply.contentTitle,
content: reply.content
}))
};
}
return {
formTitle: '',
contentTitle: '',
content: ''
replies: []
};
};
}
</script>
<style scoped>

2
work/vite.config.js

@ -16,7 +16,7 @@ export default defineConfig({
server: {
proxy: {
'/api': {
target: 'http://192.168.9.19:8080',
target: 'http://192.168.8.191:8080',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, '')
},

Loading…
Cancel
Save