File.vue。文件管理
- 使用了带选择的el-table,自定义el-table-column
- 使用了el-分页
<template>
<div>
<div>
<el-input style="width: 200px" placeholder="请输入名称" suffix-icon="el-icon-search" v-model="name"></el-input>
<el-button class="ml-5" type="primary" @click="load">搜索</el-button>
<el-button type="warning" @click="reset">重置</el-button>
</div>
<div style="margin-top: 10px">
<el-upload
style="display: inline-block"
:action="'http://' + serverIp + ':9090/file/upload'"
:on-success="handleFileUploadSuccess"
>
<el-button type="primary">上传文件 <i class="el-icon-top"></i></el-button>
</el-upload>
<el-popconfirm
class="ml-10"
confirm-button-text='好的'
cancel-button-text='不用了'
icon="el-icon-info"
icon-color="red"
title="这是一段内容确定删除吗?"
@confirm="delBatch"
>
<el-button slot="reference">批量删除 <i class="el-icon-remove-outline"></i></el-button>
</el-popconfirm>
</div>
<el-table
ref="multipleTable"
:data="tableData"
border stripe
:header-cell-class-name="'headerBg'"
tooltip-effect="dark"
style="width: 100%; margin-top: 10px"
@selection-change="handleSelectionChange">
<el-table-column
type="selection"
width="55">
</el-table-column>
<el-table-column
prop="id"
label="ID"
width="120">
</el-table-column>
<el-table-column prop="name" label="文件名称"></el-table-column>
<el-table-column prop="type" label="文件类型"></el-table-column>
<el-table-column prop="size" label="文件大小(kb)"></el-table-column>
<el-table-column label="预览">
<template slot-scope="scope">
<el-button type="primary" @click="preview(scope.row.url)">预览</el-button>
</template>
</el-table-column>
<el-table-column label="下载">
<template slot-scope="scope">
<el-button type="primary" @click="download(scope.row.url)">下载</el-button>
</template>
</el-table-column>
<el-table-column label="启用">
<template slot-scope="scope">
<el-switch
v-model="scope.row.enable"
active-color="#13ce66"
inactive-color="#ff4949"
@change="changeEnable(scope.row)"
>
</el-switch>
</template>
</el-table-column>
<el-table-column>
<template slot-scope="scope">
<el-popconfirm
confirm-button-text='确定'
cancel-button-text='我再想想'
icon="el-icon-info"
icon-color="red"
title="您确定删除吗?"
@confirm="del(scope.row.id)"
>
<el-button type="danger" slot="reference">删除 <i class="el-icon-remove-outline"></i></el-button>
</el-popconfirm>
</template>
</el-table-column>
</el-table>
<div class="block">
<el-pagination
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="pageNum"
:page-sizes="[2, 5, 10, 20]"
:page-size="pageSize"
layout="total, sizes, prev, pager, next, jumper"
:total="total">
</el-pagination>
</div>
</div>
</template>
<script>
export default {
name: "File",
data() {
return {
multipleSelection: [],
tableData: [],
serverIp: 'localhost',
pageNum: 1,
pageSize: 10,
total: 0,
name: '',
}
},
created() {
this.load()
},
methods: {
del(id) {
this.request.delete("/file/" + id).then(res => {
if (res.code === '200') {
this.$message.success("删除成功")
this.load()
} else {
this.$message.error("删除失败")
}
})
},
download(url) {
window.open(url)
},
preview(url) {
window.open('https://file.keking.cn/onlinePreview?url=' + encodeURIComponent(window.btoa((url))))
},
changeEnable(row) {
this.request.post("/file/update", row).then(res => {
if (res.code === '200') {
this.$message.success("操作成功")
}
})
},
handleSizeChange(pageSize) {
console.log(pageSize)
this.pageSize = pageSize
this.load()
},
handleCurrentChange(pageNum) {
console.log(pageNum)
this.pageNum = pageNum
this.load()
},
handleSelectionChange(val) {
console.log(val)
this.multipleSelection = val
},
reset() {
this.name = ""
this.load()
},
load() {
this.request.get("/file/page", {
params: {
pageNum: this.pageNum,
pageSize: this.pageSize,
name: this.name,
}
}).then(res => {
this.tableData = res.data.records
this.total = res.data.total
})
},
}
}
</script>
<style scoped>
</style>
使用高德地图。 在public/index.html中添加 <script type="text/javascript" src="https://webapi.amap.com/maps?v=2.0&key=你申请的key"></script> Map.vue
<template>
<div>
<div id="container" style="width: 100%; height: calc(100vh - 100px)"></div>
<div id="info"></div>
</div>
</template>
<script>
var content = [
"<div style='font-size: 14px; color: red; width: 200px; height: 50px'>这是信息窗口</div>"
];
export default {
name: "Map",
data() {
return {}
},
created() {
},
mounted() {
var map = new AMap.Map("container", {
zoom: 12,
resizeEnable: true
})
var infoWindow = new AMap.InfoWindow({
anchor: 'top-right',
content: content.join("<br>")
});
var clickHandler = function(e) {
console.log('您在[ '+e.lnglat.getLng()+','+e.lnglat.getLat()+' ]的位置点击了地图!');
infoWindow.open(map, [116.396901,39.919544]);
};
var marker = new AMap.Marker({
position: new AMap.LngLat(116.396901,39.919544),
title: '北京故宫',
icon: '//vdata.amap.com/icons/b18/1/2.png',
})
marker.on('click', clickHandler);
map.add(marker);
var path = []
path.push([116.303843, 39.983412])
path.push([116.321354, 39.896436])
path.push([116.407012, 39.992093])
map.plugin('AMap.DragRoute', function () {
var route = new AMap.DragRoute(map, path, AMap.DrivingPolicy.LEAST_FEE)
route.search()
})
var polyLine = new AMap.Polyline({
path: path,
strokeWeight: 5,
borderWeight: 5,
strokeStyle: "solid",
strokeColor: '#DC143C',
lineJoin: 'round'
})
map.add(polyLine)
map.plugin('AMap.Geolocation', function() {
var geolocation = new AMap.Geolocation({
enableHighAccuracy: true,
timeout: 10000,
offset: [10, 20],
zoomToAccuracy: true,
position: 'RB'
})
geolocation.getCurrentPosition(function(status,result){
if(status=='complete'){
onComplete(result)
}else{
onError(result)
}
});
function onComplete (data) {
console.log(data)
}
function onError (data) {
console.error(data)
}
})
},
methods: {}
}
</script>
<style>
</style>
Article.vue。文章管理
- 使用了带选择的el-table,
- 使用了el-分页
- 使用了el-dialog
- 使用mavon-editor,md编辑器
<template>
<div>
<div style="margin: 10px 0">
<el-input style="width: 200px" placeholder="请输入名称" suffix-icon="el-icon-search" v-model="name"></el-input>
<el-button class="ml-5" type="primary" @click="load">搜索</el-button>
<el-button type="warning" @click="reset">重置</el-button>
</div>
<div style="margin: 10px 0">
<el-button type="primary" @click="handleAdd" v-if="user.role === 'ROLE_ADMIN'">新增 <i class="el-icon-circle-plus-outline"></i></el-button>
<el-popconfirm
class="ml-5"
confirm-button-text='确定'
cancel-button-text='我再想想'
icon="el-icon-info"
icon-color="red"
title="您确定批量删除这些数据吗?"
@confirm="delBatch"
>
<el-button type="danger" slot="reference">批量删除 <i class="el-icon-remove-outline"></i></el-button>
</el-popconfirm>
</div>
<el-table :data="tableData" border stripe :header-cell-class-name="'headerBg'"
@selection-change="handleSelectionChange">
<el-table-column type="selection" width="55"></el-table-column>
<el-table-column prop="id" label="ID" width="80"></el-table-column>
<el-table-column prop="name" label="文章标题"></el-table-column>
<el-table-column prop="content" label="文章内容">
<template slot-scope="scope">
<el-button @click="view(scope.row.content)" type="primary">查看内容</el-button>
</template>
</el-table-column>
<el-table-column prop="user" label="发布人"></el-table-column>
<el-table-column prop="time" label="发布时间"></el-table-column>
<el-table-column label="操作" width="280" align="center">
<template slot-scope="scope">
<el-button type="success" @click="handleEdit(scope.row)" v-if="user.role === 'ROLE_ADMIN'">编辑 <i class="el-icon-edit"></i></el-button>
<el-popconfirm
class="ml-5"
confirm-button-text='确定'
cancel-button-text='我再想想'
icon="el-icon-info"
icon-color="red"
title="您确定删除吗?"
@confirm="del(scope.row.id)"
>
<el-button type="danger" slot="reference" v-if="user.role === 'ROLE_ADMIN'">删除 <i class="el-icon-remove-outline"></i></el-button>
</el-popconfirm>
</template>
</el-table-column>
</el-table>
<div style="padding: 10px 0">
<el-pagination
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="pageNum"
:page-sizes="[2, 5, 10, 20]"
:page-size="pageSize"
layout="total, sizes, prev, pager, next, jumper"
:total="total">
</el-pagination>
</div>
<el-dialog title="文章信息" :visible.sync="viewDialogVis" width="60%" >
<el-card>
<div>
<mavon-editor
class="md"
:value="content"
:subfield="false"
:defaultOpen="'preview'"
:toolbarsFlag="false"
:editable="false"
:scrollStyle="true"
:ishljs="true"
/>
</div>
</el-card>
</el-dialog>
<el-dialog title="文章信息" :visible.sync="dialogFormVisible" width="60%" >
<el-form label-width="80px" size="small">
<el-form-item label="文章标题">
<el-input v-model="form.name" autocomplete="off"></el-input>
</el-form-item>
<el-form-item label="文章内容">
<mavon-editor ref="md" v-model="form.content" :ishljs="true" @imgAdd="imgAdd"/>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogFormVisible = false">取 消</el-button>
<el-button type="primary" @click="save">确 定</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
export default {
name: "Article",
data() {
return {
form: {},
content: '',
tableData: [],
name: '',
multipleSelection: [],
pageNum: 1,
pageSize: 10,
total: 0,
user: localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")) : {},
dialogFormVisible: false,
viewDialogVis: false
}
},
created() {
this.load()
},
methods: {
view(content) {
this.content = content
this.viewDialogVis = true
},
load() {
this.request.get("/article/page", {
params: {
pageNum: this.pageNum,
pageSize: this.pageSize,
name: this.name,
}
}).then(res => {
this.tableData = res.data.records
this.total = res.data.total
})
},
handleAdd() {
this.dialogFormVisible = true
this.form = {}
},
handleEdit(row) {
this.form = JSON.parse(JSON.stringify(row))
this.dialogFormVisible = true
},
imgAdd(pos, $file) {
let $vm = this.$refs.md
const formData = new FormData();
formData.append('file', $file);
axios({
url: 'http://localhost:9090/file/upload',
method: 'post',
data: formData,
headers: {'Content-Type': 'multipart/form-data'},
}).then((res) => {
$vm.$img2Url(pos, res.data);
})
},
del(id) {
this.request.delete("/article/" + id).then(res => {
if (res.code === '200') {
this.$message.success("删除成功")
this.load()
} else {
this.$message.error("删除失败")
}
})
},
handleSelectionChange(val) {
console.log(val)
this.multipleSelection = val
},
delBatch() {
let ids = this.multipleSelection.map(v => v.id)
this.request.post("/article/del/batch", ids).then(res => {
if (res.code === '200') {
this.$message.success("批量删除成功")
this.load()
} else {
this.$message.error("批量删除失败")
}
})
},
save() {
this.request.post("/article", this.form).then(res => {
if (res.code === '200') {
this.$message.success("保存成功")
this.dialogFormVisible = false
this.load()
} else {
this.$message.error("保存失败")
}
})
},
reset() {
this.name = ""
this.load()
},
handleSizeChange(pageSize) {
console.log(pageSize)
this.pageSize = pageSize
this.load()
},
handleCurrentChange(pageNum) {
console.log(pageNum)
this.pageNum = pageNum
this.load()
},
download(url) {
window.open(url)
},
}
}
</script>
<style scoped>
</style>
router/index.js
- 定义routes
- 创建VueRouter实例
- 提供重置router,用于用户下线
- 设置routes的方法,用于动态路由
- 一个全局前置导航守卫,拦截未定义路径,未登录跳转到login
import Vue from 'vue'
import VueRouter from 'vue-router'
import store from "@/store";
Vue.use(VueRouter)
const routes = [
{
path: '/login',
name: 'Login',
component: () => import('../views/login/Login.vue')
},
{
path: '/register',
name: 'Register',
component: () => import('../views/Register.vue')
},
{
path: '/404',
name: '404',
component: () => import('../views/404.vue')
},
{
path: '/front',
name: 'Front',
component: () => import('../views/front/Front'),
children: [
{
path: 'home',
name: 'FrontHome',
component: () => import('../views/front/Home.vue')
},
{
path: 'item1',
name: 'Item1',
component: () => import('../views/front/Item1.vue')
},
{
path: 'person',
name: 'FrontPerson',
component: () => import('../views/front/Person')
},
{
path: 'password',
name: 'FrontPassword',
component: () => import('../views/front/Password')
},
{
path: 'video',
name: 'Video',
component: () => import('../views/front/Video')
},
{
path: 'videoDetail',
name: 'VideoDetail',
component: () => import('../views/front/VideoDetail')
},
{
path: 'article',
name: 'FrontArticle',
component: () => import('../views/front/Article')
},
{
path: 'articleDetail',
name: 'ArticleDetail',
component: () => import('../views/front/ArticleDetail')
},
]
},
]
const router = new VueRouter({
mode: 'history',
base: process.env.BASE_URL,
routes
})
export const resetRouter = () => {
router.matcher = new VueRouter({
mode: 'history',
base: process.env.BASE_URL,
routes
})
}
export const setRoutes = () => {
const storeMenus = localStorage.getItem("menus");
if (storeMenus) {
const currentRouteNames = router.getRoutes().map(v => v.name)
if (!currentRouteNames.includes('Manage')) {
const manageRoute = { path: '/', name: 'Manage', component: () => import('../views/Manage.vue'), redirect: "/home", children: [
{ path: 'person', name: '个人信息', component: () => import('../views/Person.vue')},
{ path: 'password', name: '修改密码', component: () => import('../views/Password.vue')}
] }
const menus = JSON.parse(storeMenus)
console.log(menus);
menus.forEach(item => {
if (item.path) {
let itemMenu = { path: item.path.replace("/", ""), name: item.name, component: () => import('../views/' + item.pagePath + '.vue')}
manageRoute.children.push(itemMenu)
} else if(item.children.length) {
item.children.forEach(item => {
if (item.path) {
let itemMenu = { path: item.path.replace("/", ""), name: item.name, component: () => import('../views/' + item.pagePath + '.vue')}
manageRoute.children.push(itemMenu)
}
})
}
})
console.log(manageRoute);
router.addRoute(manageRoute)
}
}
}
setRoutes();
router.beforeEach((to, from, next) => {
localStorage.setItem("currentPathName", to.name)
store.commit("setPath")
if (!to.matched.length) {
const storeMenus = localStorage.getItem("menus")
if (storeMenus) {
next("/404")
} else {
next("/login")
}
}
next()
})
export default router;
Person.vue .个人信息
- 使用了el-upload,使用了text-align在让子元素居中
- 使用了el-from
<template>
<div>
<el-card style="width: 500px;" >
<el-upload
class="avatar-uploader"
:action="'http://' + serverIp +':9090/file/upload'"
:show-file-list="false"
:on-success="handleAvatarSuccess"
>
<img v-if="form.avatarUrl" :src="form.avatarUrl" class="avatar">
<i v-else class="el-icon-plus avatar-uploader-icon"></i>
</el-upload>
<el-form label-width="80px" size="small" :model="form">
<el-form-item label="用户名">
<el-input v-model="form.username" disabled autocomplete="off"></el-input>
</el-form-item>
<el-form-item label="昵称">
<el-input v-model="form.nickname" autocomplete="off"></el-input>
</el-form-item>
<el-form-item label="邮箱">
<el-input v-model="form.email" autocomplete="off"></el-input>
</el-form-item>
<el-form-item label="电话">
<el-input v-model="form.phone" autocomplete="off"></el-input>
</el-form-item>
<el-form-item label="地址">
<el-input type="textarea" v-model="form.address" autocomplete="off"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="save">确 定</el-button>
</el-form-item>
</el-form>
</el-card>
</div>
</template>
<script>
export default {
name: "Person",
data() {
return {
form: {},
user: localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")) : {},
serverIp: 'localhost',
}
},
created() {
this.getUser().then(res => {
console.log(res)
this.form = res
})
},
methods: {
save() {
this.request.post("/user", this.form).then(res => {
if (res.code === '200') {
this.$message.success("保存成功")
this.$emit("refreshUser")
this.getUser().then(res => {
res.token = JSON.parse(localStorage.getItem("user")).token
localStorage.setItem("user", JSON.stringify(res))
})
} else {
this.$message.error("保存失败")
}
})
},
handleAvatarSuccess(res) {
this.form.avatarUrl = res
},
async getUser() {
return (await this.request.get("/user/username/" + this.user.username)).data
},
}
}
</script>
<style scoped>
.avatar-uploader {
text-align: center;
padding: 10px;
}
.avatar-uploader .el-upload {
border: 1px dashed #d9d9d9;
border-radius: 6px;
cursor: pointer;
}
.avatar-uploader-icon {
font-size: 28px;
color: #8c939d;
width: 138px;
height: 138px;
line-height: 138px;
text-align: center;
}
.avatar {
width: 138px;
height: 138px;
display: block;
}
</style>
font/Front.vue 。学生页面总体。
- 使用了flex,对于文字使用了line-height来使文字居中对齐,使用了align-items来居中对齐图片文字
- 使用了el-menu、使用了el-dropdown-menu下拉菜单
<template>
<div>
<div style="display: flex; height: 60px; line-height: 60px;">
<div style="display: flex; align-items: center;width: 300px;">
<img src="../../assets/logo1.png" alt=""
style="width: 3em; height: 3em; margin-left: 20px;"
>
<span style="margin-left: 10px;">欢迎来到xx系统</span>
</div>
<div style="flex: 1">
<el-menu :default-active="'1'" class="el-menu-demo" mode="horizontal" router>
<el-menu-item index="/front/home">首页</el-menu-item>
<el-menu-item index="/front/video">视频播放</el-menu-item>
<el-menu-item index="/front/article">文章列表</el-menu-item>
<el-submenu index="2">
<template slot="title">我的工作台</template>
<el-menu-item index="/front/item1">选项1</el-menu-item>
<el-menu-item index="2-2">选项2</el-menu-item>
<el-menu-item index="2-3">选项3</el-menu-item>
<el-submenu index="2-4">
<template slot="title">选项4</template>
<el-menu-item index="2-4-1">选项1</el-menu-item>
<el-menu-item index="2-4-2">选项2</el-menu-item>
<el-menu-item index="2-4-3">选项3</el-menu-item>
</el-submenu>
</el-submenu>
<el-menu-item index="3" disabled>消息中心</el-menu-item>
<el-menu-item index="4"><a href="https://www.ele.me" target="_blank">订单管理</a></el-menu-item>
</el-menu>
</div>
<div style="width: 200px">
<div v-if="!user.username">
<el-button @click="$router.push('/login')">登录</el-button>
<el-button @click="$router.push('/register')">注册</el-button>
</div>
<div v-else>
<el-dropdown>
<div>
<img :src="user.avatarUrl">
<span>{{ user.nickname }}</span><i class="el-icon-arrow-down"></i>
</div>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item>
<router-link to="/front/password">修改密码</router-link>
</el-dropdown-item>
<el-dropdown-item>
<span @click="$router.replace('/front/person')">个人信息</span>
</el-dropdown-item>
<el-dropdown-item>
<span @click="logout">退出</span>
</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</div>
</div>
</div>
<div style="width: 1000px; margin: 0 auto">
<router-view />
</div>
</div>
</template>
<script>
export default {
name: "Front",
data() {
return {
user: localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")) : {}
}
},
created() {
},
methods: {
logout() {
this.$store.commit("logout")
this.$message.success("退出成功")
}
}
}
</script>
<style>
</style>
front/Home.vue。首页
<template>
<div>
<el-carousel height="450px">
<el-carousel-item v-for="item in imgs" :key="item">
<img :src="item" alt="" >
</el-carousel-item>
</el-carousel>
</div>
</template>
<script>
export default {
name: "FrontHome",
data() {
return {
imgs: [
'https://img30.360buyimg.com/babel/s1580x830_jfs/t1/109361/24/22897/74054/621ede58E099d37e3/f12730c81df6046a.jpg!cc_1580x830.webp',
'https://img13.360buyimg.com/babel/s1580x830_jfs/t1/96398/30/23715/70228/6221e9d0Ec1b9fe65/f66e2ad76314d6cd.jpg!cc_1580x830.webp'
],
files: []
}
},
methods: {
}
}
</script>
<style>
</style>
|