提交 0aa8f812 authored 作者: 刘旭's avatar 刘旭

添加lic控制权限

上级 1927fdf2
......@@ -61,7 +61,7 @@ router.beforeEach(async (to, from, next) => {
}
} else {
//判断是否在白名单中
if (whiteList.indexOf(to.path) !== -1) { //存在白名单,放行
if (whiteList.indexOf(to.path) !== -1 || to.path === '/import/lic') { //存在白名单,放行
next();
} else { //不存在,登录
next({ path: '/login' })
......
......@@ -38,6 +38,11 @@ const routes: Array<RouteRecordRaw> = [
component: () => import("@/views/login/login.vue"),
},
{
path: "/import/lic",
name: "importLic",
component: () => import("@/views/importLic/index.vue"),
},
{
path: "/404",
name: "404",
component: () => import("@/views/exception/404.vue"),
......
import axios, { AxiosInstance } from 'axios'
import { ElMessage } from 'element-plus'
import router from '@/router/index'
// api路径
const API_URL: string = import.meta.env.VITE_APP_BASE_URL
......@@ -33,7 +32,6 @@ service.interceptors.response.use(
error => {
// 数据请求失败后的相应操作
const response = error.response;
// 根据返回的code值来做不同的处理(和后端约定)
switch (response.status) {
case 401:
......@@ -41,6 +39,9 @@ service.interceptors.response.use(
window.location.href = "/#/login";
sessionStorage.clear()
return ElMessage.error('请重新登录')
} else if (response.data.code === 913) {
window.location.href = '/#/import/lic'
return ElMessage.error('请重新导入lic文件')
}
ElMessage.error('错误请求')
break;
......
......@@ -19,3 +19,21 @@ export function toLogin(
// method: 'get',
// })
// }
// 获取mac地址
export function getMacAddress() {
return request({
url: '/api/lic/info/mac',
method: 'post'
})
}
// 导入文件
export function importFile(data: any) {
return request({
url: "/api/lic/info/file/import",
method: 'post',
headers: { 'Content-Type': 'multipart/form-data' },
data
})
}
<template>
<el-alert title="lic已失效,请通过mac地址,重新导入lic文件" type="warning" :closable='false' center />
<div class='app-container'>
mac地址:{{ macAddress }}
<el-button type="primary" style="width: 100px; margin-top: 20px;" @click="handleSelected">导入lic文件</el-button>
<input ref="uploadInput" type="file" style="display: none;" accept=".tmp" @change="submitUpload" />
</div>
</template>
<script setup lang='ts'>
import { ref } from 'vue'
import { getMacAddress, importFile } from '@/services/api/login/login'
import { ElMessage } from 'element-plus'
const macAddress = ref()
const uploadInput = ref()
const handleSelected = () => uploadInput.value.click()
// //选好文件之后点击打开按钮
const submitUpload = (e: any) => {
const files = e.target.files
const rawFile = files[0]
console.log(rawFile);
if (!rawFile) return
upload(rawFile)
}
//上传
const upload = (rawFile: any) => {
uploadInput.value = null
uploadSectionFile(rawFile)
}
const uploadSectionFile = (file: any, params?: any) => {
// let data = params
let fromData = new FormData()// FormData 对象
let fileObj = file// 相当于input里取得的files
fromData.append('file', fileObj)// 文件对象
importFile(fromData).then((res: any) => {
//调用上传接口
if (res.code === 200) {
sessionStorage.clear()
ElMessage({ type: 'success', message: '导入成功!' })
}
})
}
getMacAddress().then((res: any) => {
if (res.code === 200) {
macAddress.value = res.data.macAddress
}
})
</script>
<style lang = "scss" scoped>
.app-container {
display: flex;
flex-direction: column;
margin: 10% auto;
justify-content: center;
align-items: center;
}
</style>
\ No newline at end of file
......@@ -89,11 +89,11 @@ export default ({ command, mode }) => {
// '/foo': '',
// 选项写法
"/admin": {
target: "http://192.168.0.60:82/",
target: "http://192.168.0.9:8089/",
// rewrite: (path) => path.replace(/^\/api/, '') http://192.168.0.9:8089/
},
"/wx": {
target: "http://192.168.0.60:82/",
target: "http://192.168.0.9:8089/",
// rewrite: (path) => path.replace(/^\/api/, '')
},
// 正则表达式写法
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论