代码提交

f
dev_zt
wangqiujuan0808 2023-10-30 18:14:54 +08:00
parent a2aacfcd5a
commit d4b085b054
6 changed files with 35 additions and 17 deletions

View File

@ -2,7 +2,7 @@
<div class="header"> <div class="header">
<div class="left" @click="back" style="cursor: pointer"> <div class="left" @click="back" style="cursor: pointer">
<i v-if="hasBack" class="el-icon-back" ></i> <i v-if="hasBack" class="el-icon-back" ></i>
<span style="font-size: 20px">{{ name }}</span> <span style="font-size: 20px">{{ modelName }}</span>
</div> </div>
<div class="right"> <div class="right">
<el-popover <el-popover
@ -33,14 +33,17 @@ import { onMounted, reactive, toRefs } from 'vue'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
import { localRemove, pathMap } from '@/utils' import { localRemove, pathMap } from '@/utils'
import myApi from '@/api/myApi.js' import myApi from '@/api/myApi.js'
import {useStore} from 'vuex';
export default { export default {
name: 'Header', name: 'Header',
setup() { setup() {
const router = useRouter() const router = useRouter()
const store = useStore();
const state = reactive({ const state = reactive({
name: 'dashboard', name: 'dashboard',
userInfo: null, userInfo: null,
hasBack: false hasBack: false,
modelName: ''
}) })
onMounted(() => { onMounted(() => {
const pathname = window.location.hash.split('/')[1] || '' const pathname = window.location.hash.split('/')[1] || ''
@ -63,7 +66,8 @@ export default {
router.afterEach((to) => { router.afterEach((to) => {
console.log('to', to) console.log('to', to)
const { id } = to.query const { id } = to.query
state.name = pathMap[to.name] state.name = pathMap[to.name];
state.modelName = store.state.modelName;
// state.hasBack = ['level2', 'level3', 'order_detail'].includes(to.name) // state.hasBack = ['level2', 'level3', 'order_detail'].includes(to.name)
}) })
return { return {

View File

@ -1,6 +1,13 @@
<template> <template>
<ul> <ul>
<li v-for="(item,i) in menus" :class="activeI === i? 'active-menu' : ''" @click="activeI = i, go(i)"> {{ item.name }} </li> <li
v-for="(item, i) in menus"
:class="activeI === i ? 'active-menu' : ''"
:key="i"
@click="(activeI = i), go(i)"
>
{{ item.name }}
</li>
</ul> </ul>
</template> </template>
@ -10,25 +17,25 @@ import { useRouter } from "vue-router";
export default { export default {
name: "Header", name: "Header",
props: ["pactiveI", "menus"], props: ["pactiveI", "menus"],
setup(props, ctx) { setup(props, ctx) {
const router = useRouter(); const router = useRouter();
const state = reactive({ const state = reactive({
activeI: 0, activeI: 0,
menus: [] menus: [],
}); });
onMounted(() => { onMounted(() => {
if (props.pactiveI) { if (props.pactiveI) {
state.activeI = props.pactiveI; state.activeI = props.pactiveI;
state.menus = props.menus state.menus = props.menus;
} }
}); });
const go = (i) => { const go = (i) => {
ctx.emit("changeIndex", i); ctx.emit("changeIndex", i);
}; };
return { return {
...toRefs(state), ...toRefs(state),
go go,
}; };
}, },
}; };
@ -45,7 +52,7 @@ ul {
flex-direction: column; flex-direction: column;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
li { li {
width: 100%; width: 100%;
text-align: center; text-align: center;
@ -54,11 +61,11 @@ ul {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
box-shadow: 0 0 8px #99ACB0 inset; box-shadow: 0 0 8px #99acb0 inset;
border-radius: 5px; border-radius: 5px;
&.active-menu font-size: 24px;
{ &.active-menu {
background:#A7DCF5; background: #a7dcf5;
} }
} }
} }

View File

@ -7,7 +7,8 @@ const store = createStore({
currentPath: '', currentPath: '',
userInfo: {}, userInfo: {},
selectDate: 0, selectDate: 0,
selectTab: 'old' selectTab: 'old',
modelName: ''
}, },
mutations: { mutations: {
updateCurrentPath(state, path) { updateCurrentPath(state, path) {
@ -22,6 +23,9 @@ const store = createStore({
changeSelectTab(state, data) { changeSelectTab(state, data) {
state.selectTab = data; state.selectTab = data;
}, },
setModelName(state, data) {
state.modelName = data;
}
}, },
actions: { actions: {
updateCurrentPath({ commit }, path) { updateCurrentPath({ commit }, path) {

View File

@ -42,7 +42,7 @@ export default {
name: '数据分析', name: '数据分析',
}, },
{ {
name: '历史数据', name: '数据记录',
} }
], ],
}) })

View File

@ -16,10 +16,12 @@
<script> <script>
import { onMounted, reactive, ref, toRefs, nextTick } from "vue"; import { onMounted, reactive, ref, toRefs, nextTick } from "vue";
import { useRouter } from "vue-router"; import { useRouter } from "vue-router";
import {useStore} from 'vuex';
export default { export default {
name: 'home', name: 'home',
setup() { setup() {
const router = useRouter(); const router = useRouter();
const store = useStore();
const state = reactive({ const state = reactive({
menus: [{ menus: [{
name: '处理&回用系统', name: '处理&回用系统',
@ -42,6 +44,7 @@ export default {
}] }]
}) })
const go = (item) => { const go = (item) => {
store.commit("setModelName", item.name);
router.push(item.url); router.push(item.url);
} }
return { return {

View File

@ -42,7 +42,7 @@ export default {
name: '数据分析', name: '数据分析',
}, },
{ {
name: '历史数据', name: '数据记录',
} }
], ],
}) })