提交 49ba11fb authored 作者: 王鹏飞's avatar 王鹏飞

updates

上级 8167becc
差异被折叠。
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
"version": "0.0.0", "version": "0.0.0",
"scripts": { "scripts": {
"dev": "vite --mode dev", "dev": "vite --mode dev",
"build": "cross-env BUILD_ENV=prod vite build && cross-env BUILD_ENV=prod npm run deploy", "build": "vite build --mode prod && npm run deploy",
"build:pre": "vite build", "build:pre": "vite build --mode pre",
"build:test": "vite build --mode test", "build:test": "vite build --mode test",
"preview": "vite preview", "preview": "vite preview",
"deploy": "node ./deploy.js", "deploy": "node ./deploy.js",
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
"vuex": "^3.6.2" "vuex": "^3.6.2"
}, },
"devDependencies": { "devDependencies": {
"@rollup/plugin-eslint": "^8.0.1",
"ali-oss": "^6.17.1", "ali-oss": "^6.17.1",
"chalk": "^5.0.0", "chalk": "^5.0.0",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
......
...@@ -27,7 +27,8 @@ export function uploadFile(data) { ...@@ -27,7 +27,8 @@ export function uploadFile(data) {
headers: { 'Content-Type': 'multipart/form-data' } headers: { 'Content-Type': 'multipart/form-data' }
}) })
} }
// 获取可访问的所有项目 // 获取可访问的所有项目
export function getPermissionProject() { export function getAllProjects() {
return httpRequest.get('/api/qbs/admin/v1/projects') return httpRequest.get('/api/qbs/admin/v1/projects')
} }
...@@ -27,7 +27,7 @@ export default { ...@@ -27,7 +27,7 @@ export default {
{ {
name: '试题中心', name: '试题中心',
path: '/question', path: '/question',
icon: 'el-icon-document', icon: 'el-icon-collection',
children: [ children: [
{ name: '新建试题', path: '/question/create' }, { name: '新建试题', path: '/question/create' },
{ name: '我的题库', path: '/question/list' }, { name: '我的题库', path: '/question/list' },
...@@ -37,13 +37,13 @@ export default { ...@@ -37,13 +37,13 @@ export default {
{ {
name: '试卷中心', name: '试卷中心',
path: '/paper', path: '/paper',
icon: 'el-icon-document', icon: 'el-icon-toilet-paper',
children: [{ name: '我的试卷库', path: '/paper/list' }] children: [{ name: '我的试卷库', path: '/paper/list' }]
}, },
{ {
name: '考试中心', name: '考试中心',
path: '/exam', path: '/exam',
icon: 'el-icon-document', icon: 'el-icon-folder-opened',
children: [{ name: '我的考试', path: '/exam/list' }] children: [{ name: '我的考试', path: '/exam/list' }]
} }
] ]
......
...@@ -60,6 +60,7 @@ export default { ...@@ -60,6 +60,7 @@ export default {
height: 64px; height: 64px;
background-color: #fff; background-color: #fff;
color: #c01c40; color: #c01c40;
box-shadow: 0 1px 3px rgb(18 18 18 / 10%);
.logo { .logo {
width: 120px; width: 120px;
} }
......
const routes = [
{
path: '/401',
component: () => import('./views/401.vue')
},
{
name: 'browser',
path: '/browser',
component: () => import('./views/browser.vue')
},
{
path: '/choose',
component: () => import('@/components/layout/Index.vue'),
props: { sidebar: false },
children: [{ path: '', component: () => import('./views/Choose.vue'), meta: { requireProjectTag: false } }]
}
]
export { routes }
差异被折叠。
<template>
<div class="choose-list">
<el-card class="choose-item" v-for="item in projects" :key="item.id" @click.native="handleClick(item)">
<h2>{{ item.name }}</h2>
</el-card>
</div>
</template>
<script>
export default {
computed: {
projects() {
return this.$store.state.projects || []
}
},
methods: {
handleClick(item) {
this.$store.commit('setActiveProjedct', item)
this.$router.push({ path: '/', query: { project_tag: item.tag } })
}
}
}
</script>
<style lang="scss" scoped>
.choose-list {
display: flex;
flex-wrap: wrap;
}
.choose-item {
margin: 10px;
cursor: pointer;
}
</style>
<template>
<div class="container">
<div class="box">
<h1 class="tips">你的浏览器版本较低,请升级你的浏览器。</h1>
<div class="list">
<ul>
<li v-for="item in browserList" :key="item.name">
<a :href="item.href" target="_blank">
<img :src="item.logoUrl" />
<p class="t1">{{ item.name }}</p>
<p class="t2">{{ item.company }}</p>
</a>
</li>
</ul>
</div>
</div>
<p class="ua">{{ UA }}</p>
</div>
</template>
<script>
export default {
data() {
const UA = window.navigator.userAgent
const isIe = window.ActiveXObject || 'ActiveXObject' in window
return {
UA,
isIe,
browserList: [
{
name: 'Chrome',
company: 'Google',
href: 'https://www.google.cn/chrome',
logoUrl: 'https://webapp-pub.ezijing.com/website/base/images/chrome.png'
},
{
name: 'Edge',
company: 'Microsoft',
href: 'https://www.microsoft.com/edge',
logoUrl: 'https://webapp-pub.ezijing.com/website/base/images/edge.png'
},
{
name: 'Firefox',
company: 'Mozilla Foundation',
href: 'https://download.mozilla.org',
logoUrl: 'https://webapp-pub.ezijing.com/website/base/images/firefox.png'
}
]
}
},
beforeMount() {
!this.isIe && this.$router.replace('/')
}
}
</script>
<style lang="scss" scoped>
.container {
height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.box {
width: 700px;
background-color: #f4f5f7;
border-radius: 10px;
}
.tips {
margin: 30px;
font-size: 24px;
color: #172b4d;
text-align: center;
}
ul {
margin: 0;
padding: 0;
display: flex;
list-style: none;
li {
flex: 1;
padding: 40px;
text-align: center;
}
img {
width: 100px;
}
p {
margin: 0;
text-align: center;
}
.t1 {
color: #e25600;
}
.t2 {
color: #aaa;
text-decoration: none;
}
a {
text-decoration: none;
}
}
.ua {
font-size: 12px;
margin: 20px;
}
</style>
import Vue from 'vue' import Vue from 'vue'
import Vuex from 'vuex' import Vuex from 'vuex'
import { getUser, logout, getPermissionProject } from '@/api/base' import { getUser, logout, getAllProjects } from '@/api/base'
Vue.use(Vuex) Vue.use(Vuex)
const store = new Vuex.Store({ const store = new Vuex.Store({
state: { state: {
user: {}, user: {},
projects: [] projects: [], // 项目列表
activeProject: {} // 当前激活的项目
}, },
mutations: { mutations: {
setUser(state, user) { setUser(state, user) {
...@@ -15,9 +16,30 @@ const store = new Vuex.Store({ ...@@ -15,9 +16,30 @@ const store = new Vuex.Store({
}, },
setProject(state, projects) { setProject(state, projects) {
state.projects = projects state.projects = projects
},
setProjects(state, projects) {
state.projects = projects
},
setActiveProjedct(state, project = {}) {
state.activeProject = project
localStorage.setItem('project_tag', project.tag || '')
} }
}, },
actions: { actions: {
// 获取所有项目列表
getAllProjects({ commit }) {
getAllProjects().then(res => {
const projects = res.data
const localProjectTag = localStorage.getItem('project_tag')
// 当前激活的项目
if (localProjectTag) {
const activeProject = projects.find(item => item.tag === localProjectTag) || {}
commit('setActiveProjedct', activeProject)
}
// 所有项目列表
commit('setProjects', projects)
})
},
// 获取用户信息 // 获取用户信息
getUser({ commit }) { getUser({ commit }) {
getUser().then(response => { getUser().then(response => {
...@@ -47,16 +69,17 @@ const store = new Vuex.Store({ ...@@ -47,16 +69,17 @@ const store = new Vuex.Store({
return false return false
}) })
return isLogin return isLogin
},
getPermissionProject({ commit }) {
getPermissionProject().then(response => {
const { projects = [] } = response.data
commit('setProject', projects)
return response.data
})
} }
} }
}) })
store.dispatch('getPermissionProject')
const localProjectTag = localStorage.getItem('project_tag')
// 当前激活的项目
if (localProjectTag) {
store.commit('setActiveProjedct', { tag: localProjectTag })
}
// 初始化获取项目列表
store.dispatch('getAllProjects')
export default store export default store
...@@ -2,6 +2,8 @@ import axios from 'axios' ...@@ -2,6 +2,8 @@ import axios from 'axios'
import queryString from 'query-string' import queryString from 'query-string'
import { Message } from 'element-ui' import { Message } from 'element-ui'
import router from '../router' import router from '../router'
import store from '../store'
const httpRequest = axios.create({ const httpRequest = axios.create({
timeout: 60000, timeout: 60000,
withCredentials: true withCredentials: true
...@@ -11,6 +13,11 @@ const httpRequest = axios.create({ ...@@ -11,6 +13,11 @@ const httpRequest = axios.create({
// 请求拦截 // 请求拦截
httpRequest.interceptors.request.use( httpRequest.interceptors.request.use(
function (config) { function (config) {
// 设置项目
config.headers.tenant = store.state.activeProject?.tag
config.params = Object.assign({ project_prefix: store.state.activeProject?.tag }, config.params)
config.data = Object.assign({ project_prefix: store.state.activeProject?.tag }, config.data)
// 默认参数 // 默认参数
const defaultHeaders = { const defaultHeaders = {
timestamp: parseInt(Date.now() / 1000), timestamp: parseInt(Date.now() / 1000),
......
...@@ -12,6 +12,12 @@ export default async function (to, from, next) { ...@@ -12,6 +12,12 @@ export default async function (to, from, next) {
window.location.href = `${import.meta.env.VITE_LOGIN_URL}?rd=${encodeURIComponent(window.location.href)}` window.location.href = `${import.meta.env.VITE_LOGIN_URL}?rd=${encodeURIComponent(window.location.href)}`
return return
} }
// 选择项目
const hasProjectTag = !!store.state.activeProject.tag
if ((!Object.hasOwnProperty.call(to.meta, 'requireProjectTag') || to.meta.requireProjectTag) && !hasProjectTag) {
next('/choose')
return
}
next() next()
} }
...@@ -3,8 +3,10 @@ import path from 'path' ...@@ -3,8 +3,10 @@ import path from 'path'
import { defineConfig } from 'vite' import { defineConfig } from 'vite'
import { createVuePlugin } from 'vite-plugin-vue2' import { createVuePlugin } from 'vite-plugin-vue2'
import checker from 'vite-plugin-checker' import checker from 'vite-plugin-checker'
export default defineConfig({
base: process.env.BUILD_ENV === 'prod' ? 'https://webapp-pub.ezijing.com/website/prod/qbs/' : '/', export default defineConfig(({ mode }) => {
return {
base: mode === 'prod' ? 'https://webapp-pub.ezijing.com/website/prod/qbs/' : '/',
plugins: [ plugins: [
checker({ checker({
eslint: { eslint: {
...@@ -46,4 +48,5 @@ export default defineConfig({ ...@@ -46,4 +48,5 @@ export default defineConfig({
// 禁用SASS警告提醒 // 禁用SASS警告提醒
preprocessorOptions: { scss: { quietDeps: true, charset: false } } preprocessorOptions: { scss: { quietDeps: true, charset: false } }
} }
}
}) })
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论