vue.js——“微商城”后台管理系统

news2024/9/27 16:43:10

1. 需求背景:

先创建运行环境,“微商城”后台管理系统是一种后台管理系统平台,旨在提供一个便捷、安全和高效的管 理和操作各类数据的平台。系统将涵盖用户登录、商品管理、分类管理、新增分类和个人中 心等功能,以满足用户高效数据管理的各种需求。通过 Web 前端开发框架(VUE)的技术实现该项目。

首先,配置该环境

示例如图

在此文件中可检验引用是否成功

main.js中配置环境,添加以下代码

import { createApp } from 'vue'
import App from './App.vue'
import router from './router.js'
// import './style.css'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import AntDesignVue from 'ant-design-vue'
import 'ant-design-vue/dist/antd.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'


const app=createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}
app.use(AntDesignVue)
app.use(ElementPlus)
app.use(router)
app.mount('#app')
// createApp(App).mount('#app')

router.js中创建路由链接

import { RouterView, createRouter, createWebHashHistory } from 'vue-router'
import { h } from 'vue'

const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    { path: '/', redirect:'/login' },
    { path: '/login', component: () => import ('./components/Login.vue') },
    { 
      path: '/home', 
      component: () => import ('./components/Home.vue'),
      redirect:'/home/user',
      children: [
        { 
          path: 'user', 
          component: { render: () => h(RouterView) },
          children: [
          ]
        },
		{
			path: '/aside',
			component: () => import('./components/subcomponents/MyAside.vue')
		},
        { 
          path: '/rights', 
          component: () => import ('./components/subcomponents/MyRights.vue') 
        },
        { 
          path: '/goods', 
          component: () => import ('./components/subcomponents/MyGoods.vue') 
        },
        { 
          path: '/orders', 
          component: () => import ('./components/subcomponents/MyOrders.vue') 
        },
        { 
          path: '/settings', 
          component: () => import ('./components/subcomponents/MySettings.vue') 
        },
        { 
          path: '/menu', 
          component: () => import ('./components/subcomponents/MyMenu.vue') 
        },
      ] 
    }
  ]
})



router.beforeEach((to, from, next) => {
  // 如果访问的是登录页面,直接执行下一个钩子函数
  if(to.path === '/login'){
	return next()
  }
  // 获取Token值
  const token = localStorage.getItem('token')
  console.log(token)
  if (!token) {
    // Tok/en值不存在,强制跳转到登录页面
    return next('/login')
  }
  // 存在Token值,直接执行下一个钩子函数
  next()
})
export default router

index.html中编写导航栏

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <link rel="icon" href="/favicon.ico" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>"微商城"后台管理系统--沈茗萱</title>
  </head>
  <body>
    <div id="app"></div>
    <script type="module" src="/src/main.js"></script>
  </body>
</html>

任务一: 登录页面的制作

style.css中编写样式

:root {
  font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 24px;
  font-weight: 400;

  color-scheme: light dark;
  color: rgba(255, 255, 255, 0.87);
  background-color: #242424;

  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
}

a {
  font-weight: 500;
  color: #646cff;
  text-decoration: inherit;
}
a:hover {
  color: #535bf2;
}

a {
  font-weight: 500;
  color: #646cff;
  text-decoration: inherit;
}
a:hover {
  color: #535bf2;
}

/* body {
  margin: 0;
  display: flex;
  place-items: center;
  min-width: 320px;
  min-height: 100vh;
} */

body {
  margin: 0;
  display: flex;
  place-items: center;
  height: 100%;
}
html{
  height: 100%;
}

h1 {
  font-size: 3.2em;
  line-height: 1.1;
}

button {
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0.6em 1.2em;
  font-size: 1em;
  font-weight: 500;
  font-family: inherit;
  background-color: #1a1a1a;
  cursor: pointer;
  transition: border-color 0.25s;
}
button:hover {
  border-color: #646cff;
}
button:focus,
button:focus-visible {
  outline: 4px auto -webkit-focus-ring-color;
}

.card {
  padding: 2em;
}

/* #app {
  width: 1280px;
  margin: 0 auto;
  padding: 2rem;
  text-align: center;
} */

#app {
  width: 100%;
  margin: 0 auto;
  text-align: center;
  height: 100%;
}
@media (prefers-color-scheme: light) {
  :root {
    color: #213547;
    background-color: #ffffff;
  }
  a:hover {
    color: #747bff;
  }
  button {
    background-color: #f9f9f9;
  }
}

(1)登录项目的验证:

  • a) 用户名和密码是必须输入项目。
  • b) 用户名和密码的检查:
  • 用户名: '用户名长度为 3~12 个字符'
  • 密码: '密码长度为 6~24 个字符'

(2)登录按钮的功能的实现:

  • 点击【登录】按钮,跳转到后台管理系统的首页
  • 点击【重置】按钮,清空用户名和密码的输入内容

(3)使用导航守卫实现登录页面的功能:

  • 访问后台主页时,需要用户处于登录状态,如果没有登录就跳转到登录页面。
  • 用户在登录页面进行登录操作,若登录成功,则跳转到后台主页;若登录失败,则返回 登录页面

Login.vue中输入以下代码:

<template>
	<!-- 登录表单模板 -->
	<el-card class="box-form">
		<template #header>
			<!--标题 -->
			<div class="card-header">
				<h3>"微商城"后台管理系统</h3>
			</div>
		</template>
		<el-form :model="loginForm" :rules="FormRules" ref="ruleFormRef" label-width="120px" class="demo-ruleForm">
			<!-- 表单部分,包含用户名和密码输入字段 -->
			<el-form-item label="用户名" prop="username">
				<!-- 用户名-->
				<el-input type="text" placeholder="请输入用户名" v-model="loginForm.username" />
			</el-form-item>
			<el-form-item label="密&nbsp;&nbsp;&nbsp;码" prop="password">
				<!-- 密码-->
				<el-input v-model="loginForm.password" placeholder="请输入密码" type="password" />
			</el-form-item>
			<el-form-item>
				<!-- 登录和重置按钮 -->
				<el-button type="primary" @click="submitForm">登录</el-button>
				<el-button @click="resetForm" type="info">重置</el-button>
			</el-form-item>
		</el-form>
	</el-card>
</template>

<script setup>
	import {
		ElMessage
	} from 'element-plus';
	import {
		ref
	} from 'vue';
	import {
		useRouter
	} from 'vue-router';

	// 定义响应式变量,包括登录表单、表单引用和路由
	const loginForm = ref({
		username: '',
		password: ''
	});
	const ruleFormRef = ref();
	const router = useRouter();

	// 提交表单的函数
	const submitForm = () => {
		ruleFormRef.value.validate((valid) => {
			if (valid) {
				// 验证用户名和密码,然后登录或显示错误消息
				if (loginForm.value.username === '沈茗萱' && loginForm.value.password === '123456') {
					localStorage.setItem('token', 'Bearer xxx');
					ElMessage.success('登录成功');
					router.push('/home');
				} else {
					ElMessage.error('用户名或密码输入错误');
					localStorage.removeItem('token');
				}
			} else {
				ElMessage.error('请正确输入用户名和密码');
				return false;
			}
		});
	};

	// 重置表单的函数
	const resetForm = () => {
		ruleFormRef.value.resetFields();
	};

	// 定义表单验证规则
	const FormRules = {
		username: [{
				required: true,
				message: '请输入用户名',
				trigger: 'blur'
			},
			{
				min: 3,
				max: 12,
				message: '用户名长度为 3~12 个字符',
				trigger: 'blur'
			}
		],
		password: [{
				required: true,
				message: '请输入密码',
				trigger: 'blur'
			},
			{
				min: 6,
				max: 24,
				message: '密码长度为 6~24 个字符',
				trigger: 'blur'
			}
		]
	};
</script>

<style scoped>
	/* 表单容器样式 */
	.box-form {
		width: 600px;
		margin: 200px auto;
		padding: 20px;/* 内边距*/
		background-color: #fff;
		border: 1px solid #fff;/* 边框宽度*/
		border-radius: 5px;	/* 边框圆角半径*/
		box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1); /* 盒子阴影效果 */
	}

	/* 头部标题样式 */
	h3 {
		color: darkred;
		text-align: center;
	}

	/* 按钮样式 */
	.el-button {
		margin: 0 auto;
	}
</style>

其示例结果为

MyUserDetail.vue中添加以下代码,用于登录失败返回登录页面

<template>
  <button @click="goBack">后退</button>
  <h4>用户{{ id }}的详情页面</h4>
</template>

<script setup>
import { useRouter } from 'vue-router'
const props = defineProps({
  id: String
})
const router = useRouter()
const goBack = () => {
  router.push('/login')
}
</script>

<style scoped>
 button{
  background-color: #8FF0EE;
  color: #fff;
 }
</style>

任务二: 后台首页的制作

(1)头部区域:

  • a) 头部区域分别是导航栏标题和用户信息
  • b)点击【退出】按钮,跳转到登录页面

MyHeader.vue中输入以下代码,用于退出至登录页面

<template>
	<div class="layout-header-container">
		<div class="layout-header-left">  
			<h4 class="layout-header-left-title ml-3">"微商城"后台管理系统</h4>  
		</div>
		<div class="layout-header-right">
			<button type="button" class="btn btn-light" @click="onLogout">退出</button>  
		</div>  
	</div>  
</template>

<script setup>  
 import { reactive,ref } from 'vue';
	import {  
		useRouter  
	} from 'vue-router'  
	import router from '../../router';
  
	//获取路由实例  
	const router = useRouter()  
  
	// 定义退出方法  
	const onLogout = () => {
		// 重定向
		router.push('/login')  
	}  
</script>  
  
<style scoped>  
	/* 头部容器样式 */  
	.layout-header-container {  
		height: 60px;
		border-bottom: 1px solid #D9D9D9; /* 底部边框 */  
		display: flex; 
		justify-content: space-between; /* 子元素在主轴上的排列方式,左右分布 */  
		align-items: center; /* 子元素在交叉轴上的对齐方式,居中对齐 */  
		padding: 0 0.5rem; /* 内边距 */  
		background-color: #8DC4C4; 
		/* 左侧容器样式 */ 
		.layout-header-left {
			display: flex; /* 使用 flex 布局 */  
			align-items: center;
			color: #fff;
		}
	}
   
	.layout-header-right {  
		/* 按钮样式 */  
		.btn {  
			background-color: #8DC4C4;
			color: #fff; 
		}  
  
		/* 按钮点击时的样式 */  
		.btn:hover {  
			color: #999; 
			opacity: 0.5; /* 透明度 */  
			background-color: #fff;
		}  
	}  
</style>

(2)主体区域:

  • a) 主体区域分别是左侧导航栏和右侧内容区域

MyAside.vue中输入以下代码:

<template>
	<!-- 设置列间距 -->
	<el-row :gutter="24">
		<!-- 设置 span 属性为 6,占据 1/4 的栅格系统宽度 -->
		<el-col :span="6">
			<el-card class="box-card">
				<!-- 具名插槽 -->
				<template #header>
					<div class="card-header">
						<!-- 形状方形 -->
						<el-avatar shape="square">
						</el-avatar>
						<span style="font-size: 20px;float: right;">沈茗萱</span>
					</div>
				</template>
				<div class="info">
					<p>登录时间:2024-06-04</p>
					<p>登录地点:江西省南昌市区</p>
				</div>
			</el-card>
		</el-col>

		<el-col :span="18">
			<!-- 占格 -->
			<el-card class="box-card">
				<template #header>
					6月统计信息
				</template>
				<div class="info">
					<el-row :gutter="24" justify="end">
						<el-col :span="8" class="san">
							<div class="el-col-div1"></div>
							<span class="right1">500</span>
							<p class="right2">商品数量(个)</p>
						</el-col>

						<el-col :span="8" class="san">
							<!-- 商品分类数量 -->
							<div class="el-col-div2"></div>
							<p class="right1">20</p>
							<p class="right2">商品分类数量(个)</p>
						</el-col>

						<el-col :span="8" class="san">
							<!-- 用户访问数量 -->
							<div class="el-col-div3"></div>
							<div>
								<p class="right1">121</p>
								<p class="right2">用户访问数量(次)</p>
							</div>
						</el-col>
					</el-row>
				</div>
			</el-card>
		</el-col>
	</el-row>
</template>

<script>
</script>
<style>
	.card-header {
		height: 50px;
	}

	.san {
		height: 100px;
		border: 1px solid #bababa;/* 边框*/
	}

	.right1 {
		text-align: center;
		margin-right: 5px;/* 右外边距 */
	}

	.el-col-div1 {
		width: 90px;
		height: 90px;
		background: #d5d68b;
		float: left;/* 浮动*/
		position: relative;/* 相对定位 */
		top: 3px;
		left: -10px;
	}

	.el-col-div2 {
		width: 90px;
		height: 90px;
		background: #d5b5d6;
		float: left;
		position: relative;
		top: 3px;
		left: -10px;
	}

	.el-col-div3 {
		width: 90px;
		height: 90px;
		background: #9fcccc;
		float: left;
		position: relative;/* 相对定位 */
		top: 3px;
		left: -10px;
	}
</style>

任务三: 新增分类页面和分类管理页面的制作

(1)新增分类页面

  • 页面中是新增分类的页面,页面中包含分类名称、分类级别(一级分类和二级分类)、 产品大类、供货方式、备注信息和及时生效等项目。页面中有提交按钮和重置按钮。

MyRights.vue中添加以下代码,

<template>
	<!-- 新增分类标题 -->
	<div class="head">
		<h2>新增分类</h2>
	</div>
	<!-- 表单 -->
	<el-form ref="ruleFormRef" style="max-width:600px" :model="ruleForm" :rules="rules" label-width="auto"
		class="demo-ruleForm" :size="formSize" status-icon>
		<!-- 分类名称 -->
		<el-form-item label="分类名称" prop="name">
			<el-input v-model="ruleForm.name" />
		</el-form-item>
		<!-- 分类级别 -->
		<el-form-item label="分类级别" prop="region">
			<el-select v-model="ruleForm.region" placeholder="请选择分类级别">
				<el-option label="简单" />
				<el-option label="中等" />
				<el-option label="困难" />
			</el-select>
		</el-form-item>
		<!-- 产品大类 -->
		<el-form-item label="产品大类" prop="type">
			<el-checkbox-group v-model="ruleForm.type">
				<el-checkbox name="type" label="潮流服饰">
				</el-checkbox>
				<el-checkbox value="Promotion activities" name="type" label="食品">
				</el-checkbox>
				<el-checkbox value="Offline activities" name="type" label="珠宝配饰">
				</el-checkbox>
				<el-checkbox value="Simple brand exposure" name="type" label="日用百货">	
				</el-checkbox>
			</el-checkbox-group>
		</el-form-item>
		<!-- 供货方式 -->
		<el-form-item label="供货方式" prop="resource">
			<el-radio-group v-model="ruleForm.resource">
				<el-radio value="Sponsorship" label="线上供货"></el-radio>
				<el-radio value="Venue" label="线下供货"></el-radio>
			</el-radio-group>
		</el-form-item>
		<!-- 备注信息 -->
		<el-form-item label="备注信息" prop="desc">
			<el-input v-model="ruleForm.desc" type="textarea" />
		</el-form-item>
		<!-- 即时生效 -->
		<el-form-item label="即时生效" prop="delivery">
			<el-switch v-model="ruleForm.delivery" />
		</el-form-item>
		<!-- 提交和重置按钮 -->
		<el-form-item>
			<el-button type="primary" @click="submitForm(ruleFormRef)">提交</el-button>
			<el-button @click="resetForm(ruleFormRef)">重置</el-button>
		</el-form-item>
	</el-form>
</template>

<script lang="ts" setup>
	import { reactive, ref } from 'vue'
	import type { ComponentSize, FormInstance, FormRules } from 'element-plus'

	// 表单数据接口
	interface RuleForm {
		name : string
		region : string
		count : string
		delivery : boolean
		type : string[]
		resource : string
		desc : string
	}

	// 表单尺寸
	const formSize = ref<ComponentSize>('default')
	// 表单实例引用
	const ruleFormRef = ref<FormInstance>()
	// 表单数据
	const ruleForm = reactive<RuleForm>({
		name: '',
		region: '',
		count: '',
		delivery: false,
		type: [],
		resource: '',
		desc: '',
	})

	// 表单验证规则
	const rules = reactive<FormRules>({
		name: [
			{ required: true, message: 'Please input Activity name', trigger: 'blur' },
			{ min: 3, max: 5, message: 'Length should be 3 to 5', trigger: 'blur' },
		],
		region: [
			{
				required: true,
				message: 'Please select Activity zone',
				trigger: 'change',
			},
		],
		count: [
			{
				required: true,
				message: 'Please select Activity count',
				trigger: 'change',
			},
		],
		type: [
			{
				type: 'array',
				required: true,
				message: 'Please select at least one activity type',
				trigger: 'change',
			},
		],
		resource: [
			{
				required: true,
				message: 'Please select activity resource',
				trigger: 'change',
			},
		],
		desc: [
			{ required: true, message: 'Please input activity form', trigger: 'blur' },
		],
	})

	// 提交表单
	const submitForm = async (formEl : FormInstance | undefined) => {
		if (!formEl) return
		await formEl.validate((valid, fields) => {
			if (valid) {
				console.log('submit!')
			} else {
				console.log('error submit!', fields)
			}
		})
	}

	// 重置表单
	const resetForm = (formEl : FormInstance | undefined) => {
		if (!formEl) return
		formEl.resetFields()
	}
</script>

<style scoped>
	.head{
		text-align: center;
	}
	.el-button {
		/* 按钮样式 */
		margin: 0 auto;
	}
</style>

(2)分类管理页面

  • a) 页面采用表单布局的方式,页面中展示关于分类的相关信息,包含分类名称、分类级 别(一级分类和二级分类)、产品大类、供货方式、备注信息等项目。
  • b) 单击页面中的【新增分类】按钮,可以新增分类信息,跳转到新增分类页面。

MyGoods.vue中添加以下代码

<template>
	<div class="but">
		<!--类型为 primary,主要按钮蓝色-->
		<el-button type="primary" @click="MyRights">新增分类</el-button>
	</div>
	<div>
		<!--表格组件 -->
		<el-table :data="goodsList" stripe border style="width: 100%">
			<!-- 表格列-->
			<el-table-column sortable prop="id" label="分类名称">
			</el-table-column>
			<el-table-column prop="goods_name" label="分类级别">
			</el-table-column>
			<el-table-column prop="goods_desp" label="供货方式">
			</el-table-column>
			<el-table-column prop="goods_price" label="备注信息">
			</el-table-column>
			<el-table-column prop="goods_cz" label="操作">
			</el-table-column>
		</el-table>
	</div>
</template>

<script setup>
	import {
		reactive
	} from 'vue'
	// 导入 Vue Router 实例  
	import router from '../../router';

	// 定义MyRights,按钮点击事件  
	const MyRights = () => {
		// 跳转到 '/rights' 路由  
		router.push('/rights')
	}
</script>

<style scoped>
	.but {
		height: 80px;
		text-align: center;
		line-height: 60px;
	}
</style>

任务四:商品管理页面的制作

  • (1)商品管理页面中展示关于商品的相关信息,包含商品编号、商品名称、商品价格、 商品分类、商品库存、商品简介和商品图片等项目。
  • (2)单击“后退”按钮,跳转到后台管理系统首页页面。
  • (3)【选做项目】:点击“详情”按钮,跳转到商品详情信息页面。

MyOrders.vue中输入代码

<template>
  <el-card class="box-form">
	  <template #header>
	  	<!--标题 -->
	  	<div class="card-header">
			<el-button type="primary" @click="orders">后退</el-button>
	  		<h2>商品管理平台详情</h2>
	  	</div>
	  </template>
  </el-card>
</template>

<script setup>
	import {
		reactive
	} from 'vue';
	import router from '../../router';
	const orders = () => {
		router.push('/settings')
	}
</script>
<style>
	.box-form {
		/* 表单容器 */
		width: 100%;
		margin: 0 auto;
		background-color: #fff;
		border: 1px solid #fff;
		border-radius: 5px;
		box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
	}
	.card-header{
		text-align: center;
	}
	.el-button{
		float: right;
	}
</style>

MySettings.vue中输入以下代码,展示商品相关信息

<template>
	<div class="but">
		<el-button type="primary" @click="MySettings">后退</el-button>
	</div>
	<el-table :data="goodsList" border style="width: 100%">
		<el-table-column prop="id" label="商品编号" width="120px">
		</el-table-column>
		<el-table-column prop="name" label="商品名称" width="120px">
		</el-table-column>
		<el-table-column prop="price" label="商品价格" width="120px">
		</el-table-column>
		<el-table-column prop="desp" label="商品库存" width="120px">
		</el-table-column>
		<el-table-column prop="jian" label="商品简介" width="500px">
		</el-table-column>
		<el-table-column prop="pic" label="商品图片">
			<template #default="{ row }">
				<el-image v-if="row.pic != ''" :src="row.pic" fit="contain"
					style="display: flex; align-items: center; height: 65px;"></el-image>
			</template>
		</el-table-column>
		<el-table-column prop="czuo" label="操作" width="100px">
			<template #default="{ row }">
				<el-button type="warning" class="caozuo" @click="MyOrders">详情</el-button>
			</template>
		</el-table-column>
	</el-table>
</template>

<script setup>
	import {
		reactive
	} from 'vue';
	import router from '../../router';
	const MySettings = () => {
		router.push('/aside')
	}
	const MyOrders = () =>{
		router.push('/orders')
	}
	const goodsList = reactive([{
			id: 1,
			name: '葡萄柚',
			price: '10.00',
			desp: '10',
			jian: '葡萄柚含有丰富的蛋白质、维生素、叶酸、无机盐、纤维素等等',
			pic: 'src/assets/grapefruit.png',
		},
		{
			id: 2,
			name: '葡萄',
			price: '10.00',
			desp: '20',
			jian: '葡萄含有大量的维生素C,丰富的矿物质,日常食用,可以抗氧化、起到美容养颜的作用,并且还能提高机体抵抗力、辅助降血压、降血糖、预防心脑血管疾病。',
			pic: 'src/assets/grape.png',
		},
		{
			id: 3,
			name: '西红柿',
			price: '3.00',
			desp: '10',
			jian: '西红柿属于常见的水果,不仅美味,还营养丰富,具有美容养颜、保护视力等功效。',
			pic: 'src/assets/tomatoes.png',
		},
		{
			id: 4,
			name: '生菜',
			price: '6.00',
			desp: '50',
			jian: '生菜可生食,脆嫩爽口,略甜,具有改善睡眠、减肥瘦身、保护视力等功效。',
			pic: 'src/assets/spinach.png',
		},
		{
			id: 5,
			name: '葡萄柚',
			price: '10.00',
			desp: '10',
			jian: '葡萄柚含有丰富的蛋白质、维生素、叶酸、无机盐、纤维素等等。',
			pic: 'src/assets/grapefruit.png',
		},
		{
			id: 6,
			name: '葡萄柚',
			price: '10.00',
			desp: '10',
			jian: '葡萄柚含有丰富的蛋白质、维生素、叶酸、无机盐、纤维素等等。',
			pic: 'src/assets/grapefruit.png',
		},
		{
			id: 7,
			name: '葡萄柚',
			price: '10.00',
			desp: '10',
			jian: '葡萄柚含有丰富的蛋白质、维生素、叶酸、无机盐、纤维素等等。',
			pic: 'src/assets/grapefruit.png',
		}
	])
</script>

<style>
	th,
	td {
		line-height: 30px;
		background-color: #fff;
		padding: 10px;
	}

	.but {
		height: 80px;
		text-align: center;
		line-height: 60px;
	}

	.czuo {
		background: #e6a23d;
		color: #fff;
	}
</style>

Home.vue中输入以下代码,跳转到后台管理系统首页页面

<template>
	<el-container>
		<el-header>"微商城"后台管理系统</el-header>
		<!--点击后调用 tuichu 方法 -->
		<el-button type="primary" @click="tuichu">退出</el-button>
		<!-- 嵌套侧边栏和主要内容 -->
		<el-container>
			<!-- 侧边栏组件 -->
			<el-aside width="200px">
				<!-- 菜单组件 -->
				<el-menu :default-active="activeIndex" class="el-menu-demo" mode="vertical" background-color="#fff"
					text-color="#000" active-text-color="#A4D1BE">
					<!-- 路由链接,点击后不同的页面 -->
					<router-link to="/aside"><el-menu-item index="1"><el-icon>
								<HomeFilled />
							</el-icon>首页</el-menu-item></router-link>
					<router-link to="/rights"><el-menu-item index="2"><el-icon>
								<Menu />
							</el-icon>新增分类</el-menu-item></router-link>
					<router-link to="/goods"><el-menu-item index="3"><el-icon>
								<Menu />
							</el-icon>分类管理</el-menu-item></router-link>
					<router-link to="/settings"><el-menu-item index="4"><el-icon>
								<Menu />
							</el-icon>商品管理</el-menu-item></router-link>
					<router-link to="/menu"><el-menu-item index="5"><el-icon>
								<User />
							</el-icon>个人中心</el-menu-item></router-link>
				</el-menu>
			</el-aside>
			<!-- 容器组件,嵌套主要内容区域 -->
			<el-container>
				<!-- 主要内容区域,当前路由对应的组件 -->
				<el-main><router-view></router-view></el-main>
			</el-container>
		</el-container>
	</el-container>
</template>

<script setup>
	import {
		reactive,
		ref
	} from 'vue'
import { useRouter } from 'vue-router';
	const router=useRouter()
const tuichu = () => {
	router.push('/login')
	localStorage.removeItem('token');
}

</script>

<style scoped>
	/* 头部*/
	.el-header {
		background-color: #7FBAA7;
		color: #ffffff;
		text-align: left;
		line-height: 60px;
	}

	/* 退出按钮 */
	.el-button {
		position: absolute;
		top: 15px;
		right: 50px;
	}
	/* 侧边栏 */
	.el-aside {
		background-color: #fff;
		color: #333;
	}

	/* 主要内容区域*/
	.el-main {
		background-color: #F7F7F7;
		color: #333;
	}

	/* 移除下划线 */
	.el-menu a {
		text-decoration: none;
	}

	/* 演示样式*/
	.el-menu-demo {
		height: 680px;
	}

	body>.el-container {
		margin-bottom: 40px;
	}

	.el-container:nth-child(5) .el-aside,
	.el-container:nth-child(6) .el-aside {
		line-height: 260px;
	}

	.el-container:nth-child(7) .el-aside {
		line-height: 320px;
	}
</style>

任务五:个人中心页面的制作

        个人中心页面是对个人账户信息进行修改,可以对用户名和密码进行修改,单击【提交】 按钮,可以完成对用户名和密码的修改,单击页面中的【重置】按钮,可以清空页面中需要 修改的用户名和密码。

MyMenu.vue中添加以下代码,编写个人中心页面

<template>
	<!-- 登录表单模板 -->
	<el-card class="box-form">
		<template #header>
			<!--标题 -->
			<div class="card-header">
				<h3>个人账户</h3>
			</div>
		</template>
		<el-form :model="FormData" ref="ruleFormRef" label-width="120px" class="demo-ruleForm">
			<!-- 表单部分,包含用户名和密码输入字段 -->
			<el-form-item class="yhm" label="用户名: &nbsp;&nbsp;&nbsp;&nbsp;沈茗萱" prop="name">
			</el-form-item>
			<el-form-item label="原密码" prop="input">
				<el-input v-model="FormData.input" show-password />
			</el-form-item>
			<el-form-item label="新密码" prop="menuFrom">
				<el-input v-model="FormData.menuFrom" show-password />
			</el-form-item>
			<el-form-item label="再次输入新密码" prop="newpassword">
				<el-input v-model="FormData.newpassword" show-password />
			</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="submitForm">提交</el-button>
				<el-button @click="resetForm">重置</el-button>
			</el-form-item>
		</el-form>
	</el-card>
</template>

<script setup>
	import {
		ElMessage
	} from 'element-plus';
	import {
		ref
	} from 'vue';
	import {
		useRouter
	} from 'vue-router';
	const router = useRouter()
	const ruleFormRef = ref()
	const FormData = ref({
		input: '',
		menuFrom: '',
		newpassword: ''
	})

	//提交
	const submitForm = () => {
		// 验证用户名和密码,然后登录或显示错误消息

		if (FormData.input !=''&& FormData.menuFrom!='' && FormData.newpassword!='') {
			if (FormData.menuFrom === FormData.newpassword) {
				ElMessage.success('提交成功')
				router.push('/aside')
			} else {
				ElMessage.error('两次输入的密码不同')
			}
		} else{
			ElMessage.error('密码不为空')
		}
	}

	// 重置
	const resetForm = () => {
		ruleFormRef.value.resetFields();
	}
</script>

<style scoped>
	.box-form {
		/* 表单容器 */
		width: 800px;
		margin: 0 auto;
		background-color: #fff;
		border: 1px solid #fff;
		border-radius: 5px;
		box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
	}

	h3 {
		/* 头部标题 */
		color: darkred;
		text-align: center;
	}

	.el-button {
		/* 按钮 */
		margin: 0 auto;
	}

	.yhm {
		margin-left: 60px;
	}
</style>

自此,微商城完成

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2170485.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Vue2项目中vuex如何简化程序代码,提升代码质量和开发效率

Vuex为Vue中提供了集中式存储 库&#xff0c;其主要分为state、getter、mutation、action四个模块&#xff0c;它们每个担任了不同角色&#xff0c;分工不同&#xff1b;Vuex允许所有的组件共享状态抽取出来&#xff0c;以一个全局单例模式管理&#xff0c;状态集中存储在同一…

安装软件及apt install -f修复均报错

UOS统信安装软件过程及修复依赖过程&#xff0c;可排查deepin-installer和dpkg问题 文章目录 一、问题现象二、问题原因三、解决方案 一、问题现象 执行apt install -f 都会出现该报错&#xff0c;如图所示&#xff1a; 二、问题原因 造成这种情况的原因在于/var/lib/dpkg/…

视频生成模型哪家强?豆包可灵通义海螺全面评测【AI评测】

比较贴切的表述是&#xff0c;豆包的视频模型这次的升级&#xff0c;已然将国内AI视频的美学境界拔高了一个档次&#xff0c;让AI视频也开始变得更加实用了。 作者|斗斗 出品|产业家 国内的文生视频领域&#xff0c;也是吃上“细糠”了。 最近&#xff0c;火山引擎宣布豆…

必收藏,售后客服日常回复必备的话术 (精华版)

在售后客服工作中&#xff0c;使用恰当的话术对客户进行回复至关重要。本文精选了售后客服日常工作中必备的精华话术&#xff0c;旨在帮助客服人员提升回复效率和服务质量。其中包括客户投诉处理、问题解决、礼貌用语等多个方面的话术内容。 前言 在售后客服工作中&#xff0c…

Flux【lora模型】【禅意插画】:画风清新唯美,充满禅意韵味的插画模型:Zenpainting l 禅意插画

大家好我是安琪&#xff01;&#xff01;&#xff01; 今天和大家推荐一款基于Flux训练的禅意插画风格的lora模型:Zenpainting l 禅意插画**。**此Lora模型可生成富禅意韵味的艺术插画&#xff0c;画风清新唯美&#xff0c;充满艺术意境。 提示词&#xff1a;Zen painting il…

URI和URL的区别

1: 将 URI 转换为 URL import java.net.URI; import java.net.URL;public class UriToUrlExample {public static void main(String[] args) {// 创建一个 URI 对象URI uri = new URI("http://example.com/path/to/resource");// 将 URI 转换为 URLtry {URL url = u…

C++:模板(1)

目录 实现泛型的交换函数 函数模板 1.概念 2.格式 3.原理 4.函数模板实例化 5.函数模板参数的匹配原则 类模板 1.定义格式 2.实例化 3.声明与定义问题 实现泛型的交换函数 我们实现一个对所有类型都通用的交换函数&#xff0c;可以用函数重载来实现。 void Swap(in…

Map和Set,TreeMap和TreeSet,HashMap和HashSet

文章目录 TreeSet和TreeMap二叉搜索树模拟TreeMAp定义 基本操作插入查找删除(难点)遍历性能分析应用场景 Map&&Set模型 HashMap常用方法 HashSet常用方法HashMap和HashSet区别数据结构不同元素类型不同方法不同使用场景不同 TreeSet和TreeMap 定义&#xff1a; TreeSe…

个人健康档案管理系统

基于springbootvue实现的个人健康档案管理系统&#xff08;源码L文ppt&#xff09;4-076 4.1 系统功能结构设计 根据对个人健康档案管理系统的具体需求分析&#xff0c;把系统可以划分为几个不同的功能模块&#xff1a;管理员可以对系统首页、用户管理、健康体检管理、疫…

智能密码、指纹锁语音芯片ic方案 可存放40s语音内容 NVD语音芯片

随着科技的飞速发展&#xff0c;智能家居安全领域迎来了前所未有的变革。智能密码与指纹锁作为现代家庭安全防护的重要一环&#xff0c;其背后的语音芯片IC开发更是这一变革中的关键技术突破。 智能密码、指纹锁语音芯片ic方案 选型与简介&#xff1a; NVD语音芯片是一款低成…

基于JAVA+SpringBoot+Vue的疫苗发布和接种预约系统

基于JAVASpringBootVue的疫苗发布和接种预约系统 前言 ✌全网粉丝20W,csdn特邀作者、博客专家、CSDN[新星计划]导师、java领域优质创作者,博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java技术领域和毕业项目实战✌ &#x1f345;文末附源码下载链接&#x1f3…

AlmaLinux 安裝JDK8

在 AlmaLinux 上安装 JDK 8 可以通过包管理器 dnf 来完成。AlmaLinux 是基于 RHEL 的一个开源发行版&#xff0c;因此其包管理系统和 RHEL 类似。以下是详细的步骤来安装 OpenJDK 8 1. 更新系统包列表 sudo dnf update -y 2. 安装 OpenJDK 8 使用 dnf 安装 OpenJDK 8。你可…

【Python-tkinter】实现简单的文本编辑器(附带教程源码)

如果你也是刚入门的小伙伴呢&#xff0c;小编为你们准备了入门Python学习籽料和Python入门实践&#xff0c;点击领取&#xff08;无偿获得&#xff09; 利用tkinter实现简单的文本编辑器。创建一个简单的文本编辑器。可以用读文件的方式在一个文本域里显示一些文字供用户编辑…

大模型分布式训练并行技术(七)-自动并行

近年来&#xff0c;随着Transformer、MOE架构的提出&#xff0c;使得深度学习模型轻松突破上万亿规模参数&#xff0c;传统的单机单卡模式已经无法满足超大模型进行训练的要求。因此&#xff0c;我们需要基于单机多卡、甚至是多机多卡进行分布式大模型的训练。 而利用AI集群&a…

5--苍穹外卖-SpringBoot项目中菜品管理 详解(一)

目录 公共字段自动填充 问题分析 实现思路 代码开发 步骤一 步骤二 功能测试 新增菜品 需求分析和设计 代码开发 文件上传接口 功能测试 1--苍穹外卖-SpringBoot项目介绍及环境搭建 详解-CSDN博客 2--苍穹外卖-SpringBoot项目中员工管理 详解&#xff08;一&#…

医疗器械库存管理软件 符合gsp要求

软件介绍&#xff1a; 盘谷医疗器械进销存管理软件契合医疗器械行业特点&#xff0c;符合gsp要求&#xff0c;专为一二三类医疗器械经营企业开发的医疗器械进销存、质量验收、GSP管理、UDI扫码识别、财务管理一体化经营管理系统&#xff0c;符合药监新版医疗器械经营质量管理规…

C++在线开发环境搭建(WEBIDE)

C在线开发环境搭建 一、环境说明1.1 系统基础环境说明1.1 docker-ce社区版安装 二、codeserver构建2.1 构建codeserver环境的docker容器2.2 构建docker镜像2.3 运行docker2.4 运行展示 三、构建codeserver中的c开发环境3.1 插件下载3.2 插件安装 四、其他知识4.2 code-server配…

vue仿chatGpt的AI聊天功能--大模型通义千问(阿里云)

vue仿chatGpt的AI聊天功能–大模型通义千问&#xff08;阿里云&#xff09; 通义千问是由阿里云自主研发的大语言模型&#xff0c;用于理解和分析用户输入的自然语言。 1. 创建API-KEY并配置环境变量 打开通义千问网站进行登录&#xff0c;登陆之后创建api-key&#xff0c;右…

20个数字经济创新发展试验区建设案例【2024年发布】

数据简介&#xff1a;国家数字经济创新发展试验区的建设是一项重要的国家战略&#xff0c;旨在推动数字经济与实体经济的深度融合&#xff0c;促进经济高质量发展。自2019年10月启动以来&#xff0c;包括河北省&#xff08;雄安新区&#xff09;、浙江省、福建省、广东省、重庆…

【java】前端RSA加密后端解密

目录 1. 说明2. 前端示例3. 后端示例3.1 pom依赖3.2 后端结构图3.3 DecryptHttpInputMessage3.4 ApiCryptoProperties3.5 TestController3.6 ApiCryptoUtil3.7 ApiDecryptParamResolver3.8 ApiDecryptRequestBodyAdvice3.9 ApiDecryptRsa3.10 ApiCryptoProperties3.11 KeyPair3…