Commit 1ea73e42 authored by zhanglw's avatar zhanglw

路由控制

parent 14a7192f
...@@ -4,637 +4,20 @@ import qs from 'qs' ...@@ -4,637 +4,20 @@ import qs from 'qs'
export const HttpReq = { export const HttpReq = {
// 后台管理接口列表 // 后台管理接口列表
backstageApi: { backstageApi: {
// 上传营业执照图片 // 获取所有软件工具
uploadBusinessLicense: function(data) { getApp: function(data) {
return request({ return request({
url: '/api/bsw/users/uploadBusinessLicense', url: '/apps/getApp',
method: 'post', method: 'post',
data: data data: data
}).then((res) => { }).then((res) => {
return res return res
}) })
}, },
deleteBusinessLicense: function(data) { api: null
return request({
url: '/api/bsw/users/deleteBusinessLicense',
method: 'delete',
data: data
}).then((res) => {
return res
})
},
deletePicture: function(data) {
return request({
url: '/api/bsw/common/deletePicture',
method: 'delete',
data: data
}).then((res) => {
return res
})
},
// 获取行政区划
findAreaByCodeAndType: function(params) {
return request({
url: '/api/bsw/users/findAreaByCodeAndType?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 添加客户信息
addCustomer: function(data) {
return request({
url: '/api/bsw/users/addCustomer',
method: 'post',
data: data
}).then((res) => {
return res
})
},
// 修改客户信息
updateCustomerDetail: function(data) {
return request({
url: '/api/bsw/users/updateCustomerDetail',
method: 'put',
data: data
}).then((res) => {
return res
})
},
// 获取客户列表
queryCustomer: function(params) {
return request({
url: '/api/bsw/users/queryCustomer?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 客户信息详情
queryCustomerDetail: function(params) {
return request({
url: '/api/bsw/users/queryCustomerDetail?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 查询当前登录用户在进行新增客户的页面展示信息
queryCustomerTemporary: function(params) {
return request({
url: '/api/bsw/users/queryCustomerTemporary?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 新增当前登录用户在进行新增客户的页面展示信息
insertCustomerTemporary: function(data) {
return request({
url: '/api/bsw/users/insertCustomerTemporary',
method: 'post',
data: data
}).then((res) => {
return res
})
},
// 批量禁用启用客户
userEnableDisable: function(data) {
return request({
url: '/api/bsw/users/enableDisable',
method: 'put',
data: data
}).then((res) => {
return res
})
},
// 客户信息审核
reviewCustomer: function(data) {
return request({
url: '/api/bsw/users/reviewCustomer',
method: 'put',
data: data
}).then((res) => {
return res
})
},
// 上传产品图片
uploadProductPic: function(data) {
return request({
url: '/api/bsw/product/uploadProductPic',
method: 'post',
data: data
}).then((res) => {
return res
})
},
deleteProductPic: function(data) {
return request({
url: '/api/bsw/product/deleteProductPic',
method: 'delete',
data: data
}).then((res) => {
return res
})
},
// 联想查询供应商名称
associateQueryEnterpriseName: function(params) {
return request({
url: '/api/bsw/product/associateQueryEnterpriseName?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
checkEnterpriseName: function(params) {
return request({
url: '/api/bsw/product/checkEnterpriseName?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 添加产品详情
addProduct: function(data) {
return request({
url: '/api/bsw/product/addProduct',
method: 'post',
data: data
}).then((res) => {
return res
})
},
// 更新产品详情
updateProductDetail: function(data) {
return request({
url: '/api/bsw/product/updateProductDetail',
method: 'put',
data: data
}).then((res) => {
return res
})
},
// 查询产品列表
queryProduct: function(params) {
return request({
url: '/api/bsw/product/queryProduct?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 查询产品详情
queryProductDetail: function(params) {
return request({
url: '/api/bsw/product/queryProductDetail?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 客户信息审核
reviewProduct: function(data) {
return request({
url: '/api/bsw/product/reviewProduct',
method: 'put',
data: data
}).then((res) => {
return res
})
},
// 批量上下架产品
batchReleaseAndRecovery: function(data) {
return request({
url: '/api/bsw/product/batchReleaseAndRecovery',
method: 'put',
data: data
}).then((res) => {
return res
})
},
// 查询咨询信息列表
queryInformation: function(params) {
return request({
url: '/api/bsw/information/queryInformation?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 查询咨询信息详情
queryInformationDetail: function(params) {
return request({
url: '/api/bsw/information/queryInformationDetail?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 批量处理咨询
batchInformationProcessing: function(data) {
return request({
url: '/api/bsw/information/batchInformationProcessing',
method: 'put',
data: data
}).then((res) => {
return res
})
},
// 内容管理-新增供应商列表页面
addSupplierListPage: function(data) {
return request({
url: '/api/bsw/supplierListPage/addSupplierListPage',
method: 'post',
data: data
}).then((res) => {
return res
})
},
// 内容管理-修改供应商列表页中供应商详情(排序、展示产品)
updateSupplierListPage: function(data) {
return request({
url: '/api/bsw/supplierListPage/updateSupplierListPage',
method: 'put',
data: data
}).then((res) => {
return res
})
},
// 内容管理-供应商列表批量发布
releaseSupplierListPage: function(data) {
return request({
url: '/api/bsw/supplierListPage/releaseSupplierListPage',
method: 'put',
data: data
}).then((res) => {
return res
})
},
// 内容管理-查询单个供应商列表页
querySupplierListPageById: function(params) {
return request({
url: '/api/bsw/supplierListPage/querySupplierListPageById?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 内容管理-供应商列表查询
querySupplierListPage: function(params) {
return request({
url: '/api/bsw/supplierListPage/querySupplierListPage?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 内容管理-查询产品列表页
queryProductListPage: function(params) {
return request({
url: '/api/bsw/productListPage/queryProductListPage?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 内容管理-查询单个产品列表页
queryProductListPageById: function(params) {
return request({
url: '/api/bsw/productListPage/queryProductListPageById?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 内容管理-修改产品列表
updateProductListPage: function(data) {
return request({
url: '/api/bsw/productListPage/updateProductListPage',
method: 'put',
data: data
}).then((res) => {
return res
})
},
// 内容管理-产品列表批量发布
releaseProductListPage: function(data) {
return request({
url: '/api/bsw/productListPage/releaseProductListPage',
method: 'put',
data: data
}).then((res) => {
return res
})
},
// 内容管理-查询首页内容列表页
queryHomePage: function(params) {
return request({
url: '/api/bsw/homePage/queryHomePage?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 内容管理-查询单个首页内容列表页
queryHomePageById: function(params) {
return request({
url: '/api/bsw/homePage/queryHomePageById?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 内容管理-新增首页内容
addHomePage: function(data) {
return request({
url: '/api/bsw/homePage/addHomePage',
method: 'post',
data: data
}).then((res) => {
return res
})
},
// 内容管理-修改首页内容
updateHomePage: function(data) {
return request({
url: '/api/bsw/homePage/updateHomePage',
method: 'put',
data: data
}).then((res) => {
return res
})
},
// 内容管理-首页管理批量发布
releaseHomePage: function(data) {
return request({
url: '/api/bsw/homePage/releaseHomePage',
method: 'put',
data: data
}).then((res) => {
return res
})
},
// 内容管理-首页管理批量删除
hpBatchDelete: function(data) {
return request({
url: '/api/bsw/homePage/batchDelete',
method: 'delete',
data: data
}).then((res) => {
return res
})
},
// 内容管理-查询资讯页内容
queryNewsPage: function(params) {
return request({
url: '/api/bsw/newsPage/queryNewsPage?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 内容管理-查询单个资讯页内容
queryNewsPageById: function(params) {
return request({
url: '/api/bsw/newsPage/queryNewsPageById?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 内容管理-资讯发布
releaseNewsPage: function(data) {
return request({
url: '/api/bsw/newsPage/releaseNewsPage',
method: 'put',
data: data
}).then((res) => {
return res
})
},
// 内容管理-修改资讯
updateNewsPage: function(data) {
return request({
url: '/api/bsw/newsPage/updateNewsPage',
method: 'put',
data: data
}).then((res) => {
return res
})
},
// 内容管理-新增资讯
addNewsPage: function(data) {
return request({
url: '/api/bsw/newsPage/addNewsPage',
method: 'post',
data: data
}).then((res) => {
return res
})
},
// 内容管理-删除资讯
newsBatchDelete: function(data) {
return request({
url: '/api/bsw/newsPage/batchDelete',
method: 'delete',
data: data
}).then((res) => {
return res
})
}
}, },
// web端接口列表 // web端接口列表
webClientApi: { webClientApi: {
// 首页-头部文件
homePageGetHeader: function(params) {
return request({
url: '/api/bsw/bigScreen/index/header?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 首页-搜索推荐
homePageGetSearch: function(params) {
return request({
url: '/api/bsw/bigScreen/index/search?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 首页-热门排行
homePageGetRank: function(params) {
return request({
url: '/api/bsw/bigScreen/index/rank?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 首页-合作伙伴
homePageGetPartners: function(params) {
return request({
url: '/api/bsw/bigScreen/index/partners?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 首页-底部导航
homePageGetBottomNavigation: function(params) {
return request({
url: '/api/bsw/bigScreen/index/bottomNavigationBar?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 首页-供应商板块
homePageGetSupplier: function(params) {
return request({
url: '/api/bsw/bigScreen/index/supplier?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 首页-产品板块
homePageGetProduct: function(params) {
return request({
url: '/api/bsw/bigScreen/index/product?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 产品-硬件查询列表
productGetHardwareList: function(params) {
return request({
url: '/api/bsw/bigScreen/highQualityProducts?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 产品-方案概述、软件系统、专业培训
productGetPlanSystemAndTraining: function(params) {
return request({
url: '/api/bsw/bigScreen/highQualityProducts/planSystemAndTraining?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 底部文件-查询单个首页内容列表页
queryHomePageById: function(params) {
return request({
url: '/api/bsw/bigScreen/index/queryHomePageById?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 优质供应商-查询列表
supplierGetSupplierList: function(params) {
return request({
url: '/api/bsw/bigScreen/highQualitySuppliers?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 解决方案-查询列表
projectGetSolutionsAndServices: function(params) {
return request({
url: '/api/bsw/bigScreen/solutionsAndServices?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 软件系统-查询列表
softWareSystem: function(params) {
return request({
url: '/api/bsw/bigScreen/softWareSystem?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 专业培训-查询列表
professionalTraining: function(params) {
return request({
url: '/api/bsw/bigScreen/professionalTraining?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 行业资讯查询
industryInformation: function(params) {
return request({
url: '/api/bsw/bigScreen/industryInformation?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 行业资讯查询-详情
findDetailIndustryInformationById: function(params) {
return request({
url: '/api/bsw/bigScreen/industryInformation/findDetailIndustryInformationById?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 个人中心-个人详情
personalCenterInfo: function(params) {
return request({
url: '/api/bsw/bigScreen/personalCenter?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 个人中心-产品管理
productManagement: function(params) {
return request({
url: '/api/bsw/bigScreen/personalCenter/productManagement?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 个人中心-收藏的产品
collectProduct: function(params) {
return request({
url: '/api/bsw/bigScreen/personalCenter/collectProduct?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 个人中心-收藏的供应商
collectSupplier: function(params) {
return request({
url: '/api/bsw/bigScreen/personalCenter/collectSupplier?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 个人中心-被询价记录
inquiryRecord: function(params) {
return request({
url: '/api/bsw/bigScreen/personalCenter/inquiryRecord?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 个人中心-主动询价记录
translateInquiryRecord: function(params) {
return request({
url: '/api/bsw/bigScreen/personalCenter/translateInquiryRecord?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 收藏产品-供应商
collectProductOrSupplier: function(data) {
return request({
url: '/api/bsw/bigScreen/index/collectProductOrSupplier',
method: 'post',
data: data
}).then((res) => {
return res
})
},
// 供应商详细信息
supplierDetails: function(params) {
return request({
url: '/api/bsw/bigScreen/index/supplierDetails?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 产品详细信息
productDetails: function(params) {
return request({
url: '/api/bsw/bigScreen/index/productDetails?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
// 咨询
consultationInformation: function(data) {
return request({
url: '/api/bsw/bigScreen/index/consultationInformation',
method: 'post',
data: data
}).then((res) => {
return res
})
},
// 请求短信验证
sendSmsCode: function(data) {
return request({
url: '/api/bsw/bigScreen/personalCenter/sendSmsCode',
method: 'post',
data: data
}).then((res) => {
return res
})
},
// 短信注册
smsRegistration: function(data) {
return request({
url: '/api/bsw/bigScreen/personalCenter/smsRegistration',
method: 'post',
data: data
}).then((res) => {
return res
})
},
// 填写注册信息--注册成为供应商
supplierRegister: function(data) {
return request({
url: '/api/bsw/bigScreen/personalCenter/supplierRegister',
method: 'post',
data: data
}).then((res) => {
return res
})
},
// 完善供应商信息--根据当前登录用户查询供应商的详细信息
improveSupplierInformation: function(params) {
return request({
url: '/api/bsw/bigScreen/personalCenter/improveSupplierInformation?' + qs.stringify(params, { indices: false }),
method: 'get'
})
},
id: null
} }
} }
...@@ -19,6 +19,9 @@ const install = function(Vue) { ...@@ -19,6 +19,9 @@ const install = function(Vue) {
new Dict(this.dict).init(this.$options.dicts, () => { new Dict(this.dict).init(this.$options.dicts, () => {
this.$nextTick(() => { this.$nextTick(() => {
this.$emit('dictReady') this.$emit('dictReady')
if (this.$options.methods && this.$options.methods.onDictReady instanceof Function) {
this.$options.methods.onDictReady.call(this, this.dict)
}
}) })
}) })
} }
......
...@@ -9,7 +9,8 @@ import { filterAsyncRouter } from '@/store/modules/permission' ...@@ -9,7 +9,8 @@ import { filterAsyncRouter } from '@/store/modules/permission'
NProgress.configure({ showSpinner: false })// NProgress Configuration NProgress.configure({ showSpinner: false })// NProgress Configuration
const whiteList = ['/login']// no redirect whitelist const whiteList = ['/login', '/backlogin', '/home']// 免登录路由白名单
const backUrlList = ['/dashboard', '/system', '/monitor', '/sys-tools', '/backstage']// 后台路由
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
if (to.meta.title) { if (to.meta.title) {
...@@ -17,9 +18,14 @@ router.beforeEach((to, from, next) => { ...@@ -17,9 +18,14 @@ router.beforeEach((to, from, next) => {
} }
NProgress.start() NProgress.start()
if (getToken()) { if (getToken()) {
// 已登录且要跳转的页面是登录页 if (to.path === '/') { // 根路由重定向到前台home页
if (to.path === '/login') { next('/home')
next({ path: '/' }) NProgress.done()
} else if (to.path === '/login') { // 已登录且要跳转的页面是登录页
next({ path: '/home' })
NProgress.done()
} else if (to.path === '/backlogin') { // 已登录且要跳转的页面是后台登录页
next({ path: '/backstage/dashboard' })
NProgress.done() NProgress.done()
} else { } else {
if (store.getters.roles.length === 0) { // 判断当前用户是否已拉取完user_info信息 if (store.getters.roles.length === 0) { // 判断当前用户是否已拉取完user_info信息
...@@ -41,9 +47,23 @@ router.beforeEach((to, from, next) => { ...@@ -41,9 +47,23 @@ router.beforeEach((to, from, next) => {
} }
} }
} else { } else {
const findUrl = (urlList, path) => {
let flag = false
urlList.forEach(url => {
if (path.indexOf(url) !== -1) {
flag = true
}
})
return flag
}
/* has no token*/ /* has no token*/
if (whiteList.indexOf(to.path) !== -1) { // 在免登录白名单,直接进入 if (to.path === '/') { // 根路由重定向到前台home页
next('/home')
} else if (findUrl(whiteList, to.path)) { // 在免登录白名单,直接进入
next() next()
} else if (findUrl(backUrlList, to.path)) { // 后台路由重定向到后台登录
next(`/backlogin?redirect=${to.fullPath}`)
NProgress.done()
} else { } else {
next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页 next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
NProgress.done() NProgress.done()
......
...@@ -7,6 +7,11 @@ Vue.use(Router) ...@@ -7,6 +7,11 @@ Vue.use(Router)
export const constantRouterMap = [ export const constantRouterMap = [
{ path: '/login', { path: '/login',
meta: { title: '登录', noCache: true }, meta: { title: '登录', noCache: true },
component: (resolve) => require(['@/views/homepage/login'], resolve),
hidden: true
},
{ path: '/backlogin',
meta: { title: '后台登录', noCache: true },
component: (resolve) => require(['@/views/login'], resolve), component: (resolve) => require(['@/views/login'], resolve),
hidden: true hidden: true
}, },
...@@ -32,7 +37,15 @@ export const constantRouterMap = [ ...@@ -32,7 +37,15 @@ export const constantRouterMap = [
] ]
}, },
{ {
path: '/', path: '/home',
meta: { title: '首页', noCache: true },
component: (resolve) => {
return require(['@/views/homepage/index'], resolve)
},
hidden: true
},
{
path: '/backstage',
component: Layout, component: Layout,
redirect: '/dashboard', redirect: '/dashboard',
children: [ children: [
......
...@@ -45,6 +45,11 @@ ...@@ -45,6 +45,11 @@
<el-input v-model="formData.contentAbstract" type="textarea" placeholder="请输入文本" maxlength="300" :autosize="{ minRows: 4, maxRows: 4}" show-word-limit resize="none" class="cell-input" /> <el-input v-model="formData.contentAbstract" type="textarea" placeholder="请输入文本" maxlength="300" :autosize="{ minRows: 4, maxRows: 4}" show-word-limit resize="none" class="cell-input" />
</div> </div>
</el-form-item> </el-form-item>
<el-form-item label="web页面地址:" class="form-cell" prop="title">
<div class="cell-box">
<el-input v-model="formData.title" placeholder="单行输入" class="cell-input" />
</div>
</el-form-item>
<el-form-item label="上传软件工具:" class="form-cell"> <el-form-item label="上传软件工具:" class="form-cell">
<div class="cell-box"> <div class="cell-box">
<el-upload <el-upload
......
...@@ -91,13 +91,13 @@ export default { ...@@ -91,13 +91,13 @@ export default {
Object.keys(this.query).length !== 0 && Object.keys(this.query).forEach(item => { Object.keys(this.query).length !== 0 && Object.keys(this.query).forEach(item => {
if (this.query[item] === null || this.query[item] === '') this.query[item] = undefined if (this.query[item] === null || this.query[item] === '') this.query[item] = undefined
}) })
HttpReq.backstageApi.queryProduct({ HttpReq.backstageApi.getApp({
page: this.page - 1, page: this.page - 1,
pageSize: this.pageSize, pageSize: this.pageSize,
...this.query ...this.query
}).then((res) => { }).then((res) => {
this.tableData = res.data.data // this.tableData = res.data.data
this.total = res.data.total // this.total = res.data.total
}) })
}, },
batchOperate(type, row) { batchOperate(type, row) {
......
<template>
<div class="page-body">前台-首页-占位</div>
</template>
<script>
export default {
components: { },
dicts: [],
data() {
return {
imgSrcStart: process.env.VUE_APP_BASE_API,
query: {},
throttle: null, // 节流器
throttleTime: 300
}
},
mounted() {
this.$nextTick(() => {
})
},
methods: {
onDictReady(dict) {
}
}
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.touch {
cursor:pointer;
}
.clear {
clear: both
}
</style>
<template>
<div class="login" :style="'background-image:url('+ Background +');'">
<el-form ref="loginForm" :model="loginForm" :rules="loginRules" label-position="left" label-width="0px" class="login-form">
<h3 class="title">
矿山之星后台管理系统
</h3>
<el-form-item prop="username">
<el-input v-model="loginForm.username" type="text" auto-complete="off" placeholder="账号">
<svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
</el-input>
</el-form-item>
<el-form-item prop="password">
<el-input v-model="loginForm.password" type="password" auto-complete="off" placeholder="密码" @keyup.enter.native="handleLogin">
<svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
</el-input>
</el-form-item>
<el-form-item prop="code">
<el-input v-model="loginForm.code" auto-complete="off" placeholder="验证码" style="width: 63%" @keyup.enter.native="handleLogin">
<svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
</el-input>
<div class="login-code">
<img :src="codeUrl" @click="getCode">
</div>
</el-form-item>
<el-checkbox v-model="loginForm.rememberMe" style="margin:0 0 25px 0;">
记住我
</el-checkbox>
<el-form-item style="width:100%;">
<el-button :loading="loading" size="medium" type="primary" style="width:100%;" @click.native.prevent="handleLogin">
<span v-if="!loading">登 录</span>
<span v-else>登 录 中...</span>
</el-button>
</el-form-item>
</el-form>
<!-- 底部 -->
<div v-if="$store.state.settings.showFooter" id="el-login-footer">
<span v-html="$store.state.settings.footerTxt" />
<span v-if="$store.state.settings.caseNumber"></span>
<a href="https://beian.miit.gov.cn/#/Integrated/index" target="_blank">{{ $store.state.settings.caseNumber }}</a>
</div>
</div>
</template>
<script>
import { encrypt } from '@/utils/rsaEncrypt'
import Config from '@/settings'
import { getCodeImg } from '@/api/login'
import Cookies from 'js-cookie'
import qs from 'qs'
import Background from '@/assets/images/background.webp'
export default {
name: 'Login',
data() {
return {
Background: Background,
codeUrl: '',
cookiePass: '',
loginForm: {
username: 'admin',
password: '123456',
rememberMe: false,
code: '',
uuid: ''
},
loginRules: {
username: [{ required: true, trigger: 'blur', message: '用户名不能为空' }],
password: [{ required: true, trigger: 'blur', message: '密码不能为空' }],
code: [{ required: true, trigger: 'change', message: '验证码不能为空' }]
},
loading: false,
redirect: undefined
}
},
watch: {
$route: {
handler: function(route) {
const data = route.query
if (data && data.redirect) {
this.redirect = data.redirect
delete data.redirect
if (JSON.stringify(data) !== '{}') {
this.redirect = this.redirect + '&' + qs.stringify(data, { indices: false })
}
}
},
immediate: true
}
},
created() {
// 获取验证码
this.getCode()
// 获取用户名密码等Cookie
this.getCookie()
// token 过期提示
this.point()
},
methods: {
getCode() {
getCodeImg().then(res => {
this.codeUrl = res.img
this.loginForm.uuid = res.uuid
})
},
getCookie() {
const username = Cookies.get('username')
let password = Cookies.get('password')
const rememberMe = Cookies.get('rememberMe')
// 保存cookie里面的加密后的密码
this.cookiePass = password === undefined ? '' : password
password = password === undefined ? this.loginForm.password : password
this.loginForm = {
username: username === undefined ? this.loginForm.username : username,
password: password,
rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
code: ''
}
},
handleLogin() {
this.$refs.loginForm.validate(valid => {
const user = {
username: this.loginForm.username,
password: this.loginForm.password,
rememberMe: this.loginForm.rememberMe,
code: this.loginForm.code,
uuid: this.loginForm.uuid
}
if (user.password !== this.cookiePass) {
user.password = encrypt(user.password)
}
if (valid) {
this.loading = true
if (user.rememberMe) {
Cookies.set('username', user.username, { expires: Config.passCookieExpires })
Cookies.set('password', user.password, { expires: Config.passCookieExpires })
Cookies.set('rememberMe', user.rememberMe, { expires: Config.passCookieExpires })
} else {
Cookies.remove('username')
Cookies.remove('password')
Cookies.remove('rememberMe')
}
this.$store.dispatch('Login', user).then(() => {
this.loading = false
this.$router.push({ path: this.redirect || '/' })
}).catch(() => {
this.loading = false
this.getCode()
})
} else {
console.log('error submit!!')
return false
}
})
},
point() {
const point = Cookies.get('point') !== undefined
if (point) {
this.$notify({
title: '提示',
message: '当前登录状态已过期,请重新登录!',
type: 'warning',
duration: 5000
})
Cookies.remove('point')
}
}
}
}
</script>
<style rel="stylesheet/scss" lang="scss">
.login {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
background-size: cover;
}
.title {
margin: 0 auto 30px auto;
text-align: center;
color: #707070;
}
.login-form {
border-radius: 6px;
background: #ffffff;
width: 385px;
padding: 25px 25px 5px 25px;
.el-input {
height: 38px;
input {
height: 38px;
}
}
.input-icon{
height: 39px;width: 14px;margin-left: 2px;
}
}
.login-tip {
font-size: 13px;
text-align: center;
color: #bfbfbf;
}
.login-code {
width: 33%;
display: inline-block;
height: 38px;
float: right;
img{
cursor: pointer;
vertical-align:middle
}
}
</style>
...@@ -14,14 +14,14 @@ ...@@ -14,14 +14,14 @@
<svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" /> <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
</el-input> </el-input>
</el-form-item> </el-form-item>
<el-form-item prop="code"> <!-- <el-form-item prop="code">-->
<el-input v-model="loginForm.code" auto-complete="off" placeholder="验证码" style="width: 63%" @keyup.enter.native="handleLogin"> <!-- <el-input v-model="loginForm.code" auto-complete="off" placeholder="验证码" style="width: 63%" @keyup.enter.native="handleLogin">-->
<svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" /> <!-- <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />-->
</el-input> <!-- </el-input>-->
<div class="login-code"> <!-- <div class="login-code">-->
<img :src="codeUrl" @click="getCode"> <!-- <img :src="codeUrl" @click="getCode">-->
</div> <!-- </div>-->
</el-form-item> <!-- </el-form-item>-->
<el-checkbox v-model="loginForm.rememberMe" style="margin:0 0 25px 0;"> <el-checkbox v-model="loginForm.rememberMe" style="margin:0 0 25px 0;">
记住我 记住我
</el-checkbox> </el-checkbox>
...@@ -56,7 +56,7 @@ export default { ...@@ -56,7 +56,7 @@ export default {
codeUrl: '', codeUrl: '',
cookiePass: '', cookiePass: '',
loginForm: { loginForm: {
username: 'admin', username: '18888888888',
password: '123456', password: '123456',
rememberMe: false, rememberMe: false,
code: '', code: '',
...@@ -64,8 +64,7 @@ export default { ...@@ -64,8 +64,7 @@ export default {
}, },
loginRules: { loginRules: {
username: [{ required: true, trigger: 'blur', message: '用户名不能为空' }], username: [{ required: true, trigger: 'blur', message: '用户名不能为空' }],
password: [{ required: true, trigger: 'blur', message: '密码不能为空' }], password: [{ required: true, trigger: 'blur', message: '密码不能为空' }]
code: [{ required: true, trigger: 'change', message: '验证码不能为空' }]
}, },
loading: false, loading: false,
redirect: undefined redirect: undefined
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment