学校端代码提交

This commit is contained in:
jiangzhe 2024-04-11 17:02:17 +08:00
parent d23b8af9cd
commit b81ad87f95
12 changed files with 193 additions and 316 deletions

View File

@ -16,7 +16,6 @@
"axios": "^1.6.3",
"dayjs": "^1.11.10",
"element-plus": "^2.6.2",
"pinia": "^2.1.7",
"vue": "^3.3.11",
"vue-router": "^4.2.5"
},

View File

@ -20,9 +20,6 @@ dependencies:
element-plus:
specifier: ^2.6.2
version: 2.6.2(vue@3.4.15)
pinia:
specifier: ^2.1.7
version: 2.1.7(vue@3.4.15)
vue:
specifier: ^3.3.11
version: 3.4.15
@ -1756,23 +1753,6 @@ packages:
engines: {node: '>=8.6'}
dev: true
/pinia@2.1.7(vue@3.4.15):
resolution: {integrity: sha512-+C2AHFtcFqjPih0zpYuvof37SFxMQ7OEG2zV9jRI12i9BOy3YQVAHwdKtyyc8pDcDyIc33WCIsZaCFWU7WWxGQ==}
peerDependencies:
'@vue/composition-api': ^1.4.0
typescript: '>=4.4.4'
vue: ^2.6.14 || ^3.3.0
peerDependenciesMeta:
'@vue/composition-api':
optional: true
typescript:
optional: true
dependencies:
'@vue/devtools-api': 6.5.1
vue: 3.4.15
vue-demi: 0.14.6(vue@3.4.15)
dev: false
/pkg-types@1.0.3:
resolution: {integrity: sha512-nN7pYi0AQqJnoLPC9eHFQ8AcyaixBUOwvqc5TDnIKCMEE6I0y8P7OKA7fPexsXGCGxQDl/cmrLAp26LhcwxZ4A==}
dependencies:

View File

@ -1,23 +1,26 @@
// 封装所有和用户相关的接口函数
import request from '@/utils/http'
export const loginAPI = ({ account, password }) => {
export const getAuthCodeAPI = () => {
return request({
url: '/login',
method: 'POST',
data: {
account,
password
}
url: '/auth/code'
})
}
export const getLikeListAPI = ({ limit = 4 }) => {
export const loginAPI = (loginBody) => {
return request({
url: '/goods/relevant',
params: {
limit
}
url: '/auth/passwordLogin',
method: 'POST',
headers: {
isToken: false,
isEncrypt: false
},
data: loginBody
})
}
export const getPublishAPI = () => {
return request({
url: '/web/scale/publish'
})
}

View File

@ -1,5 +1,4 @@
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import * as Elicons from '@element-plus/icons-vue'
//引入Elmessage和Elloading的css样式文件
import 'element-plus/theme-chalk/el-loading.css'
@ -15,7 +14,6 @@ import { lazyPlugin } from '@/directives'
const app = createApp(App)
app.use(createPinia())
app.use(router)
app.use(lazyPlugin)

View File

@ -2,6 +2,7 @@ import { createRouter, createWebHistory } from 'vue-router'
import Login from '@/views/Login/index.vue'
import Exam from '@/views/Exam/index.vue'
import ScaleList from '@/views/ScaleList/index.vue'
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
@ -12,8 +13,12 @@ const router = createRouter({
},
{
path: '/',
component: ScaleList
},
{
path: '/exam/:scaleId',
component: Exam
}
}
],
// 路由滚动行为定制
scrollBehavior() {
@ -23,4 +28,18 @@ const router = createRouter({
}
})
router.beforeEach((to, from, next) => {
const token = localStorage.getItem('token')
if (to.path === '/login') {
next()
} else {
if (token) {
next()
} else {
next('/login')
}
}
}
)
export default router

View File

@ -1,31 +0,0 @@
// 管理用户数据相关
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { loginAPI } from '@/apis/user'
export const useUserStore = defineStore(
'user',
() => {
// 1. 定义管理用户数据的state
const userInfo = ref({})
// 2. 定义获取接口数据的action函数
const getUserInfo = async ({ account, password }) => {
const res = await loginAPI({ account, password })
userInfo.value = res.result
}
// 退出时清除用户信息
const clearUserInfo = () => {
userInfo.value = {}
}
// 3. 以对象的格式把state和action return
return {
userInfo,
getUserInfo,
clearUserInfo
}
},
{
persist: true
}
)

View File

@ -1,6 +1,6 @@
/* 只需要重写你需要的即可 */
@forward 'element-plus/theme-chalk/src/common/var.scss' with ($colors: ('primary': ( // 主色
'base': #129AFE,
'base': #1CC19A,
),
'success': ( // 成功色
'base': #1dc779,

View File

@ -1,4 +1,4 @@
$xtxColor: #129AFE;
$xtxColor: #1CC19A;
$helpColor: #e26237;
$sucColor: #1dc779;
$warnColor: #ffb302;

View File

@ -1,12 +1,19 @@
import axios from 'axios'
const http = axios.create({
baseURL: 'http://pcapi-xiaotuxian-front-devtest.itheima.net',
timeout: 5000
baseURL: '/api',
timeout: 50000
})
// axios请求拦截器
http.interceptors.request.use(config => {
const isToken = config.headers.isToken === false
if(!isToken && localStorage.getItem('token')){
config.headers.Authorization = `Bearer ${localStorage.getItem('token')}`
}
config.headers.clientId = 'e5cd7e4891bf95d1d19206ce24a7b32e'
return config
}, e => Promise.reject(e))

View File

@ -1,33 +1,18 @@
<template>
<el-container class="container-exam">
<el-header class="header">
SCL-90症状自评量表_专业焦虑与抑郁测试
<img src="@/assets/images/fenxiang.png" alt="">
<span class="desc">本平台提供专业的自评量表请仔细地阅读每一条根据近期内您的实际感受点击适合您的选项请注意不要漏题答题完成后您将获得一份专业的分析报告</span>
</el-header>
<el-main class="main">
<el-card class="card">
<template #header>
<div class="card-header">
<p>症状自评量表-SCL90是世界上最著名的心理健康测试量表之一是当前使用最为广泛的精神障碍和心理疾病门诊检查量表SCL90协助我们从十个方面来了解自己的心理健康程度</p>
<p>症状自评量表Self-reporting
Inventory)又名90项症状清单SCL-90时也叫做Hopkin's症状清单HSCL编制年代早于SCL-90作者为同一人HCSL最早版编于1954年于1975年编制其作者是德若伽提斯L.R.Derogatis)该量表共有90个项目包含有较广泛的精神病症状学内容从感觉情感思维意识行为直至生活习惯人际关系饮食睡眠等均有涉及并采用10个因子分别反映10个方面的心理症状情况
</p>
SCL-90症状自评量表_专业焦虑与抑郁测试
</div>
</template>
<div class="subject-btn">
<el-button-group>
<el-button type="primary" size="large" @click="previous" :disabled="preDisable">
<el-icon class="el-icon--left">
<ArrowLeft />
</el-icon>
</el-button>
<el-button type="primary" size="large" @click="next" :disabled="nextDisable">
下一题<el-icon class="el-icon--right">
<ArrowRight />
</el-icon>
</el-button>
</el-button-group>
</div>
<el-progress :percentage="10" :format="format" />
<div class="subject-content">
<div class="subject-title">{{ questionNum + 1 + '、' + currentQuestion.question }}</div>
@ -38,12 +23,25 @@
</el-radio-group>
</div>
<template #footer v-if="nextDisable">
<div class="submit-footer">
<el-button class="submit-btn" type="primary" size="large">提交</el-button>
</div>
</template>
<div class="subject-btn">
<el-button-group>
<el-button type="primary" size="large" @click="previous" :disabled="preDisable">
<el-icon class="el-icon--left">
<ArrowLeft />
</el-icon>
</el-button>
<el-button v-if="nextDisable" type="primary" size="large" @click="next">
提交<el-icon class="el-icon--right">
<ArrowRight />
</el-icon>
</el-button>
<el-button v-else type="primary" size="large" @click="next">
下一题<el-icon class="el-icon--right">
<ArrowRight />
</el-icon>
</el-button>
</el-button-group>
</div>
</el-card>
</el-main>
</el-container>
@ -51,6 +49,12 @@
<script setup>
import { ref, computed } from 'vue'
import {useRoute} from 'vue-router'
const route = useRoute()
console.log(route)
const format = (percentage) => (percentage === 100 ? '90题' : `10/90题`)
const questionList = ref([
{
@ -126,11 +130,15 @@ function next() {
.header {
height: 60px;
color: #CDCDCD;
background-color: #333333;
color: #41515C;
background-color: #FFF;
text-align: center;
font-size: 20px;
font-size: 18px;
padding-top: 15px;
.desc {
margin-left: 20px;
}
}
.main {
@ -142,9 +150,10 @@ function next() {
height: 100%;
.card-header {
text-indent: 2em;
font-size: 14px;
line-height: 28px;
text-align: center;
font-size: 30px;
font-weight: bold;
line-height: 60px;
}
.subject-btn {
@ -161,7 +170,7 @@ function next() {
.subject-content {
margin-left: 50px;
margin-top: 10px;
margin-top: 30px;
height: 400px;
::v-deep .el-radio-group {
@ -174,7 +183,7 @@ function next() {
}
.subject-title {
color: #0F9AE0;
color: #FF5A72;
font-size: 18px;
font-weight: bold;
}

View File

@ -1,245 +1,129 @@
<template>
<div class="login-container">
<div class="logo" />
<div class="form">
<h1 style="color: #A2A2A3;">云舒 心理健康平台</h1>
<el-card shadow="never" class="login-card">
<el-form ref="formRef" :model="loginForm" :rules="loginRules">
<el-form-item prop="username">
<el-input :prefix-icon="User" v-model="loginForm.username" placeholder="请输入学号" />
</el-form-item>
<el-form-item prop="password">
<el-input :prefix-icon="Lock" v-model="loginForm.password" show-password placeholder="请输入密码" />
</el-form-item>
<el-form-item>
<el-button style="width:350px" type="primary" @click="login">登录</el-button>
</el-form-item>
</el-form>
</el-card>
</div>
</div>
</template>
<script setup>
// +
import { ref } from 'vue'
import { ElMessage } from 'element-plus'
import 'element-plus/theme-chalk/el-message.css'
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { loginAPI } from '@/apis/user'
import { User, Lock } from '@element-plus/icons-vue'
import { useUserStore } from '@/stores/userStore'
const router = useRouter();
const userStore = useUserStore()
// 1.
const form = ref({
account: '18610848230',
password: '123456',
const loginForm = ref({
username: '',
password: '',
clientId: 'e5cd7e4891bf95d1d19206ce24a7b32e',
grantType: 'password'
})
// 2.
const rules = {
account: [
{ required: true, message: '用户名不能为空', trigger: 'blur' }
const loginRules = ref({
username: [
{ required: true, message: '请输入学号', trigger: 'blur' },
],
password: [
{ required: true, message: '密码不能为空', trigger: 'blur' },
{ min: 6, max: 14, message: '密码长度为6-14个字符', trigger: 'blur' },
{ required: true, message: '请输入密码', trigger: 'blur' },
]
}
})
// 3. form
const formRef = ref(null)
const router = useRouter()
const doLogin = () => {
const { account, password } = form.value
//
async function login() {
formRef.value.validate(async (valid) => {
// valid: true
console.log(valid)
// valid
if (valid) {
// TODO LOGIN
await userStore.getUserInfo({ account, password })
// 1.
ElMessage({ type: 'success', message: '登录成功' })
// 2.
router.replace({ path: '/' })
const res = await loginAPI(loginForm.value)
if (res.code == 200) {
localStorage.setItem('token', res.data.access_token)
router.push('/')
} else {
ElMessage.error(res.msg)
}
}
})
}
// 1. -
// 2. validator:(rule,value,callback)=>{}
// 3. form validate -> true
onMounted(() => {
})
</script>
<template>
<div>
<section class="login-section">
<div class="wrapper">
<nav>
<a href="javascript:;">账户登录</a>
</nav>
<div class="account-box">
<div class="form">
<el-form ref="formRef" :model="form" :rules="rules" label-position="right" label-width="60px" status-icon>
<el-form-item prop="account" label="学号">
<el-input v-model="form.account" />
</el-form-item>
<el-form-item prop="password" label="密码">
<el-input v-model="form.password" />
</el-form-item>
<el-button size="large" class="subBtn" @click="doLogin">点击登录</el-button>
</el-form>
</div>
</div>
</div>
</section>
</div>
</template>
<style scoped lang='scss'>
.login-section {
background: url('@/assets/images/login-bg.jpg') no-repeat center / cover;
height: 100vh;
<style lang="scss" scoped>
.login-container {
display: flex;
justify-content: center;
align-items: center;
align-items: stretch;
height: 100vh;
background-color: #fff;
.wrapper {
width: 450px;
height: 250px;
background: #fff;
transform: translate3d(100px, 0, 0);
box-shadow: 0 0 10px rgba(0, 0, 0, 0.15);
border-radius: 30px 30px 30px 30px;
.logo {
flex: 3;
background: rgba(38, 72, 176) url(../../assets/images/login_back.png) no-repeat center / cover;
border-top-right-radius: 60px;
display: flex;
flex-direction: column;
align-items: flex-end;
justify-content: center;
padding: 0 100px;
nav {
font-size: 14px;
height: 55px;
margin-bottom: 20px;
border-bottom: 1px solid #f5f5f5;
display: flex;
padding: 0 40px;
text-align: right;
align-items: center;
a {
flex: 1;
line-height: 1;
display: inline-block;
font-size: 20px;
position: relative;
text-align: center;
}
.icon {
background: url(../../assets/images/logo.png) no-repeat 70px center / contain;
width: 300px;
height: 50px;
margin-bottom: 50px;
}
}
}
.account-box {
.toggle {
padding: 15px 40px;
text-align: right;
a {
color: $xtxColor;
i {
font-size: 14px;
}
p {
color: #fff;
font-size: 18px;
margin-top: 20px;
width: 300px;
text-align: center;
}
}
.form {
padding: 0 20px 20px 20px;
&-item {
margin-bottom: 28px;
.input {
position: relative;
height: 36px;
>i {
width: 34px;
height: 34px;
background: #cfcdcd;
color: #fff;
position: absolute;
left: 1px;
top: 1px;
text-align: center;
line-height: 34px;
font-size: 18px;
}
input {
padding-left: 44px;
border: 1px solid #cfcdcd;
height: 36px;
line-height: 36px;
width: 100%;
&.error {
border-color: $priceColor;
}
&.active,
&:focus {
border-color: $xtxColor;
}
}
.code {
position: absolute;
right: 1px;
top: 1px;
text-align: center;
line-height: 34px;
font-size: 14px;
background: #f5f5f5;
color: #666;
width: 90px;
height: 34px;
cursor: pointer;
}
}
>.error {
position: absolute;
font-size: 12px;
line-height: 28px;
color: $priceColor;
i {
font-size: 14px;
margin-right: 2px;
}
}
}
.agree {
a {
color: #069;
}
}
.btn {
display: block;
width: 100%;
height: 40px;
color: #fff;
text-align: center;
line-height: 40px;
background: $xtxColor;
&.disabled {
background: #cfcdcd;
}
}
}
.action {
padding: 20px 40px;
flex: 2;
display: flex;
justify-content: space-between;
align-items: center;
flex-direction: column;
justify-content: center;
padding-left: 176px;
background-color: #fff;
.url {
a {
color: #999;
margin-left: 10px;
.el-card {
border: none;
padding: 0;
}
h1 {
padding-left: 20px;
font-size: 24px;
}
.el-input {
width: 350px;
height: 44px;
.el-input__inner {
background: #f4f5fb;
}
}
}
}
.subBtn {
background: $xtxColor;
margin-left: 40px;
width: 90%;
color: #fff;
}
</style>
</style>

View File

@ -56,5 +56,14 @@ export default defineConfig({
`
}
}
},
server: {
proxy: {
'/api': {
target: 'http://localhost:8080/',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, '')
}
}
}
})