请根据文档内容,提供给我完整的web前端项目VSCode代码,需要实现有首页,登录注册页,医生列表至少三个页面。首页按照文档内要求制作
时间: 2024-12-13 09:24:05 浏览: 13
好的,以下是根据文档内容提供的完整Web前端项目的VSCode代码结构,包含了首页、登录注册页和医生列表页。项目使用了Vue.js、ElementUI、Vue Router 和 Vuex。
### 项目结构
```
project-name/
├── src/
│ ├── assets/
│ │ └── images/
│ │ └── doctor1.jpg
│ │ └── doctor2.jpg
│ │ └── ...
│ ├── components/
│ │ ├── AppointmentForm.vue
│ │ ├── AppointmentList.vue
│ │ ├── DoctorCard.vue
│ │ ├── DoctorList.vue
│ │ ├── Header.vue
│ │ ├── Footer.vue
│ │ ├── Login.vue
│ │ ├── Register.vue
│ ├── router/
│ │ └── index.js
│ ├── store/
│ │ └── index.js
│ ├── App.vue
│ └── main.js
├── public/
│ └── index.html
├── package.json
└── README.md
```
### 代码文件
#### `public/index.html`
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>预约挂号系统</title>
</head>
<body>
<div id="app"></div>
</body>
</html>
```
#### `src/main.js`
```javascript
import Vue from 'vue';
import App from './App.vue';
import router from './router';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import store from './store';
Vue.config.productionTip = false;
Vue.use(ElementUI);
new Vue({
el: '#app',
router,
store,
render: h => h(App)
});
```
#### `src/App.vue`
```vue
<template>
<div id="app">
<Header />
<router-view />
<Footer />
</div>
</template>
<script>
import Header from '@/components/Header.vue';
import Footer from '@/components/Footer.vue';
export default {
name: 'App',
components: {
Header,
Footer
}
};
</script>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
body {
margin: 0;
font-family: Arial, sans-serif;
}
</style>
```
#### `src/router/index.js`
```javascript
import Vue from 'vue';
import Router from 'vue-router';
import Login from '../components/Login.vue';
import Register from '../components/Register.vue';
import DoctorList from '../components/DoctorList.vue';
import AppointmentForm from '../components/AppointmentForm.vue';
import AppointmentList from '../components/AppointmentList.vue';
Vue.use(Router);
export default new Router({
routes: [
{ path: '/', redirect: '/login' },
{ path: '/login', component: Login },
{ path: '/register', component: Register },
{ path: '/doctors', component: DoctorList },
{ path: '/appointment/:doctorId', component: AppointmentForm },
{ path: '/appointments', component: AppointmentList }
]
});
```
#### `src/store/index.js`
```javascript
import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);
export default new Vuex.Store({
state: {
user: null,
appointments: []
},
mutations: {
setUser(state, user) {
state.user = user;
},
addAppointment(state, appointment) {
state.appointments.push(appointment);
}
},
actions: {
login({ commit }, user) {
commit('setUser', user);
},
register({ commit }, user) {
commit('setUser', user);
},
createAppointment({ commit }, appointment) {
commit('addAppointment', appointment);
}
}
});
```
#### `src/components/Header.vue`
```vue
<template>
<el-header>
<div class="header-container">
<div class="logo">预约挂号</div>
<el-menu mode="horizontal">
<el-menu-item>
<router-link to="/login">用户登录</router-link>
</el-menu-item>
<el-menu-item>
<router-link to="/register">注册</router-link>
</el-menu-item>
<el-menu-item>
<router-link to="/appointment">预约挂号</router-link>
</el-menu-item>
<el-menu-item>
<router-link to="/doctors">医生列表</router-link>
</el-menu-item>
</el-menu>
</div>
</el-header>
</template>
<script>
export default {
name: 'Header'
};
</script>
<style scoped>
.header-container {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 20px;
}
.logo {
font-size: 24px;
font-weight: bold;
}
</style>
```
#### `src/components/Footer.vue`
```vue
<template>
<el-footer>
<div class="footer-container">
<div class="address">地址:x市南泉路</div>
<div class="contact">联系电话:123456780</div>
<div class="clock">{{ currentTime }}</div>
</div>
</el-footer>
</template>
<script>
export default {
data() {
return {
currentTime: ''
};
},
created() {
this.updateTime();
setInterval(this.updateTime, 1000);
},
methods: {
updateTime() {
const now = new Date();
this.currentTime = now.toLocaleString();
}
}
};
</script>
<style scoped>
.footer-container {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 20px;
}
</style>
```
#### `src/components/Login.vue`
```vue
<template>
<div class="login-container">
<el-card class="box-card">
<h2>登录</h2>
<el-form @submit.native.prevent="handleLogin">
<el-form-item label="用户名">
<el-input v-model="username"></el-input>
</el-form-item>
<el-form-item label="密码">
<el-input type="password" v-model="password"></el-input>
</el-form-item>
<el-button type="primary" native-type="submit">登录</el-button>
</el-form>
</el-card>
</div>
</template>
<script>
export default {
data() {
return {
username: '',
password: ''
};
},
methods: {
handleLogin() {
const user = { username: this.username, password: this.password };
this.$store.dispatch('login', user);
this.$router.push('/doctors');
}
}
};
</script>
<style scoped>
.login-container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.box-card {
width: 400px;
}
</style>
```
#### `src/components/Register.vue`
```vue
<template>
<div class="register-container">
<el-card class="box-card">
<h2>注册</h2>
<el-form @submit.native.prevent="handleRegister">
<el-form-item label="用户名">
<el-input v-model="username"></el-input>
</el-form-item>
<el-form-item label="密码">
<el-input type="password" v-model="password"></el-input>
</el-form-item>
<el-button type="primary" native-type="submit">注册</el-button>
</el-form>
</el-card>
</div>
</template>
<script>
export default {
data() {
return {
username: '',
password: ''
};
},
methods: {
handleRegister() {
const user = { username: this.username, password: this.password };
this.$store.dispatch('register', user);
this.$router.push('/login');
}
}
};
</script>
<style scoped>
.register-container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.box-card {
width: 400px;
}
</style>
```
#### `src/components/DoctorList.vue`
```vue
<template>
<div class="doctor-list-container">
<h2>医生列表</h2>
<el-row :gutter="20">
<el-col :span="8" v-for="doctor in doctors" :key="doctor.id">
<DoctorCard :doctor="doctor" />
</el-col>
</el-row>
</div>
</template>
<script>
import DoctorCard from './DoctorCard.vue';
export default {
components: {
DoctorCard
},
data() {
return {
doctors: [
{ id: 1001, name: '刘梓豪', specialty: '心血管科', expertise: '高血压', schedule: ['周一上午', '周三上午'] },
{ id: 1002, name: '杨人杰', specialty: '精神科', expertise: '儿童青少年心理', schedule: ['周二下午', '周四上午'] },
{ id: 1003, name: '杨晓逸', specialty: '营养科', expertise: '临床营养', schedule: ['周二上午', '周五下午'] },
{ id: 1004, name: '郑豪', specialty: '肝脏内科', expertise: '肾脏内科', schedule: ['周三下午', '周四下午'] },
{ id: 1005, name: '张洋', specialty: '呼吸内科', expertise: '戒烟', schedule: ['周一上午', '周二上午'] },
{ id: 1006, name: '左咏梅', specialty: '皮肤科', expertise: '皮肤管理', schedule: ['周三下午', '周五上午'] },
{ id: 1007, name: '刘帅', specialty: '神经外科', expertise: '脊椎病', schedule: ['周二下午', '周四上午'] },
{ id: 1008, name: '李斌', specialty: '耳鼻喉科', expertise: '耳鼻喉', schedule: ['周三上午', '周五上午'] }
]
};
}
};
</script>
<style scoped>
.doctor-list-container {
padding: 20px;
}
</style>
```
#### `src/components/DoctorCard.vue`
```vue
<template>
<el-card class="box-card">
<div slot="header" class="clearfix">
<span>{{ doctor.name }}</span>
<el-button style="float: right; padding: 3px 0" type="text" @click="viewDetails">查看详情</el-button>
</div>
<img :src="getDoctorImage(doctor.id)" alt="医生照片" style="width: 100%; max-height: 200px; object-fit: cover;">
<p><strong>科室:</strong>{{ doctor.specialty }}</p>
<p><strong>擅长:</strong>{{ doctor.expertise }}</p>
<p><strong>排班:</strong>{{ doctor.schedule.join(', ') }}</p>
</el-card>
</template>
<script>
export default {
props: {
doctor: Object
},
methods: {
viewDetails() {
this.$router.push(`/appointment/${this.doctor.id}`);
},
getDoctorImage(id) {
return require(`@/assets/images/doctor${id}.jpg`);
}
}
};
</script>
<style scoped>
.box-card {
margin-bottom: 20px;
}
</style>
```
#### `src/components/AppointmentForm.vue`
```vue
<template>
<div class="appointment-form-container">
<h2>预约挂号</h2>
<el-form @submit.native.prevent="handleSubmit">
<el-form-item label="姓名">
<el-input v-model="form.name"></el-input>
</el-form-item>
<el-form-item label="性别">
<el-select v-model="form.gender" placeholder="请选择性别">
<el-option label="男" value="male"></el-option>
<el-option label="女" value="female"></el-option>
</el-select>
</el-form-item>
<el-form-item label="年龄">
<el-input v-model.number="form.age"></el-input>
</el-form-item>
<el-form-item label="联系电话">
<el-input v-model="form.phone"></el-input>
</el-form-item>
<el-form-item label="预约时间">
<el-date-picker v-model="form.date" type="datetime" placeholder="选择日期时间"></el-date-picker>
</el-form-item>
<el-button type="primary" native-type="submit">提交</el-button>
</el-form>
</div>
</template>
<script>
export default {
data() {
return {
form: {
name: '',
gender: '',
age: '',
phone: '',
date: ''
}
};
},
methods: {
handleSubmit() {
const appointment = { ...this.form, doctorId: this.$route.params.doctorId };
this.$store.dispatch('createAppointment', appointment);
this.$router.push('/appointments');
}
}
};
</script>
<style scoped>
.appointment-form-container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.box-card {
width: 400px;
}
</style>
```
#### `src/components/AppointmentList.vue`
```vue
<template>
<div class="appointment-list-container">
<h2>我的预约记录</h2>
<el-table :data="appointments" stripe>
<el-table-column prop="name" label="姓名"></el-table-column>
<el-table-column prop="gender" label="性别"></el-table-column>
<el-table-column prop="age" label="年龄"></el-table-column>
<el-table-column prop="phone" label="联系电话"></el-table-column>
<el-table-column prop="date" label="预约时间"></el-table-column>
<el-table-column prop="doctorId" label="医生证号"></el-table-column>
</el-table>
</div>
</template>
<script>
export default {
computed: {
appointments() {
return this.$store.state.appointments;
}
}
};
</script>
<style scoped>
.appointment-list-container {
padding: 20px;
}
</style>
```
### 运行项目
1. 安装依赖:
```sh
npm install
```
2. 启动开发服务器:
```sh
npm run serve
```
希望这些代码能够帮助你完成项目!如果有任何问题,请随时联系我。
阅读全文