fix: bug#10979
This commit is contained in:
parent
3dd39c5279
commit
b9e332447e
|
@ -39,10 +39,7 @@ type MenuStateType = {
|
|||
}
|
||||
}
|
||||
siderMenus: MenuItem[]
|
||||
params: {
|
||||
key: string
|
||||
params: Record<string, any>
|
||||
}
|
||||
params: Record<string, any>
|
||||
}
|
||||
|
||||
|
||||
|
@ -50,10 +47,7 @@ export const useMenuStore = defineStore({
|
|||
id: 'menu',
|
||||
state: (): MenuStateType => ({
|
||||
menus: {},
|
||||
params: {
|
||||
key: '',
|
||||
params: {}
|
||||
},
|
||||
params: {},
|
||||
siderMenus: []
|
||||
}),
|
||||
getters: {
|
||||
|
@ -85,6 +79,7 @@ export const useMenuStore = defineStore({
|
|||
jumpPage(name: string, params?: Record<string, any>, query?: Record<string, any>) {
|
||||
const path = this.hasMenu(name)
|
||||
if (path) {
|
||||
this.params = { [name]: params || {}}
|
||||
router.push({
|
||||
name, params, query, state: { params }
|
||||
})
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
import {useMenuStore} from "store/menu";
|
||||
import { onBeforeUnmount } from 'vue'
|
||||
|
||||
export const useRouterParams = () => {
|
||||
const params = ref<Record<string, any>>({})
|
||||
const menu = useMenuStore();
|
||||
|
||||
const router = useRouter();
|
||||
const routeName = router.currentRoute.value.name as string
|
||||
|
||||
watchEffect(() => {
|
||||
params.value = routeName && menu.params[routeName] ? menu.params[routeName] : {}
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
if (routeName && menu.params[routeName]) { // 如果当前路由params参数,离开页面清除掉
|
||||
menu.params = {}
|
||||
}
|
||||
})
|
||||
|
||||
return {
|
||||
params
|
||||
}
|
||||
}
|
|
@ -119,10 +119,12 @@ import { message } from 'jetlinks-ui-components';
|
|||
import { getImage } from '@/utils/comm';
|
||||
import { getWebSocket } from '@/utils/websocket';
|
||||
import { useMenuStore } from '@/store/menu';
|
||||
import {useRouterParams} from "@/utils/hooks/useParams";
|
||||
|
||||
const menuStory = useMenuStore();
|
||||
|
||||
const route = useRoute();
|
||||
const routerParams = useRouterParams()
|
||||
const instanceStore = useInstanceStore();
|
||||
|
||||
const statusMap = new Map();
|
||||
|
@ -267,15 +269,14 @@ const getDetailFn = async () => {
|
|||
await instanceStore.refresh(String(_id));
|
||||
getStatus(String(_id));
|
||||
list.value = [...initList];
|
||||
console.log('watch', route.params?.id)
|
||||
getDetail();
|
||||
instanceStore.tabActiveKey = history.state?.params?.tab || 'Info';
|
||||
instanceStore.tabActiveKey = routerParams.params.value.tab || 'Info';
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
getDetailFn()
|
||||
instanceStore.tabActiveKey = history.state?.params?.tab || 'Info';
|
||||
instanceStore.tabActiveKey = routerParams.params.value.tab || 'Info';
|
||||
});
|
||||
|
||||
const onBack = () => {
|
||||
|
|
|
@ -308,6 +308,7 @@ import dayjs from 'dayjs';
|
|||
import BadgeStatus from '@/components/BadgeStatus/index.vue';
|
||||
import BatchDropdown from '@/components/BatchDropdown/index.vue';
|
||||
import { BatchActionsType } from '@/components/BatchDropdown/types';
|
||||
import {useRouterParams} from "@/utils/hooks/useParams";
|
||||
|
||||
const instanceRef = ref<Record<string, any>>({});
|
||||
const params = ref<Record<string, any>>({});
|
||||
|
@ -320,7 +321,7 @@ const operationVisible = ref<boolean>(false);
|
|||
const api = ref<string>('');
|
||||
const type = ref<string>('');
|
||||
const isCheck = ref<boolean>(false);
|
||||
|
||||
const routerParams = useRouterParams()
|
||||
const menuStory = useMenuStore();
|
||||
|
||||
const columns = [
|
||||
|
@ -546,7 +547,7 @@ const paramsFormat = (
|
|||
};
|
||||
|
||||
onMounted(() => {
|
||||
if (history.state?.params?.type === 'add') {
|
||||
if (routerParams.params.value.type === 'add') {
|
||||
handleAdd();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -114,11 +114,13 @@ import { message } from 'jetlinks-ui-components';
|
|||
import { getImage, handleParamsToString } from '@/utils/comm'
|
||||
import encodeQuery from '@/utils/encodeQuery';
|
||||
import { useMenuStore } from '@/store/menu';
|
||||
import {useRouterParams} from "@/utils/hooks/useParams";
|
||||
|
||||
const menuStory = useMenuStore();
|
||||
const route = useRoute();
|
||||
const checked = ref<boolean>(true);
|
||||
const productStore = useProductStore();
|
||||
const routerParams = useRouterParams()
|
||||
const searchParams = ref({
|
||||
terms1: [
|
||||
{
|
||||
|
@ -291,8 +293,8 @@ const jumpDevice = () => {
|
|||
);
|
||||
};
|
||||
onMounted(() => {
|
||||
if (history.state?.params?.tab) {
|
||||
productStore.tabActiveKey = history.state?.params?.tab;
|
||||
if (routerParams.params?.value.tab) {
|
||||
productStore.tabActiveKey = routerParams.params?.value.tab;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
|
|
@ -181,6 +181,7 @@ import { typeOptions } from '@/components/Search/util';
|
|||
import Save from './Save/index.vue';
|
||||
import { useMenuStore } from 'store/menu';
|
||||
import { useRoute } from 'vue-router';
|
||||
import {useRouterParams} from "@/utils/hooks/useParams";
|
||||
/**
|
||||
* 表格数据
|
||||
*/
|
||||
|
@ -616,9 +617,9 @@ const saveRef = ref();
|
|||
const handleSearch = (e: any) => {
|
||||
params.value = e;
|
||||
};
|
||||
const route = useRoute();
|
||||
const routerParams = useRouterParams()
|
||||
onMounted(() => {
|
||||
if(history.state?.params?.save){
|
||||
if(routerParams.params?.value.save){
|
||||
add();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -8,12 +8,13 @@
|
|||
|
||||
<script setup lang="ts">
|
||||
import { _control, _stopControl } from '@/api/edge/device';
|
||||
import {useRouterParams} from "@/utils/hooks/useParams";
|
||||
|
||||
const url = ref<string>('');
|
||||
const deviceId = ref<string>('');
|
||||
|
||||
const { params } = useRouterParams()
|
||||
watch(
|
||||
() => history.state?.params?.id,
|
||||
() => params.value.id,
|
||||
(newId) => {
|
||||
if (newId) {
|
||||
deviceId.value = newId as string;
|
||||
|
|
|
@ -421,6 +421,8 @@ import { useMenuStore } from 'store/menu';
|
|||
import BadgeStatus from '@/components/BadgeStatus/index.vue';
|
||||
import BatchDropdown from '@/components/BatchDropdown/index.vue';
|
||||
import { BatchActionsType } from '@/components/BatchDropdown/types';
|
||||
import {usePermissionStore} from "store/permission";
|
||||
import {useRouterParams} from "@/utils/hooks/useParams";
|
||||
|
||||
const router = useRouter();
|
||||
const menuStory = useMenuStore();
|
||||
|
@ -588,12 +590,15 @@ const columns = [
|
|||
scopedSlots: true,
|
||||
},
|
||||
];
|
||||
|
||||
const btnHasPermission = usePermissionStore().hasPermission;
|
||||
const paltformPermission = btnHasPermission(`iot-card/Platform:add`);
|
||||
const importSave = () => {
|
||||
cardManageRef.value?.reload()
|
||||
importVisible.value = false
|
||||
}
|
||||
|
||||
const routerParams = useRouterParams()
|
||||
|
||||
const getActions = (
|
||||
data: Partial<Record<string, any>>,
|
||||
type: 'card' | 'table',
|
||||
|
@ -989,6 +994,12 @@ const batchActions: BatchActionsType[] = [
|
|||
},
|
||||
},
|
||||
];
|
||||
|
||||
onMounted(() => {
|
||||
if (routerParams.params.value.type === 'add' && paltformPermission) {
|
||||
handleAdd()
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
|
|
|
@ -179,7 +179,6 @@ const pieChartData = ref<any[]>([
|
|||
]);
|
||||
|
||||
const jumpPage = (data: GuideItemProps) => {
|
||||
console.log(data.auth)
|
||||
if (!data.auth){
|
||||
message.warning('暂无权限,请联系管理员');
|
||||
return
|
||||
|
@ -187,7 +186,11 @@ const jumpPage = (data: GuideItemProps) => {
|
|||
if (data.key === 'EQUIPMENT') {
|
||||
menuStory.jumpPage(data.url, { id: ':id'});
|
||||
} else {
|
||||
menuStory.jumpPage(data.url);
|
||||
let params: any = undefined
|
||||
if (data.key === 'SCREEN') {
|
||||
params = { type: 'add'}
|
||||
}
|
||||
menuStory.jumpPage(data.url, params);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -53,8 +53,10 @@ import { message } from 'jetlinks-ui-components';
|
|||
import { useAlarmStore } from '@/store/alarm';
|
||||
import Info from './info.vue';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import {useRouterParams} from "@/utils/hooks/useParams";
|
||||
const route = useRoute();
|
||||
const id = route.params?.id;
|
||||
const { params: routerParams } = useRouterParams()
|
||||
let visiable = ref(false);
|
||||
const columns = [
|
||||
{
|
||||
|
@ -181,7 +183,7 @@ const close = () => {
|
|||
|
||||
watchEffect(()=>{
|
||||
current.value = details.value;
|
||||
if(history.state?.params.detail && details.value){
|
||||
if(routerParams.value.detail && details.value){
|
||||
visiable.value = true;
|
||||
}
|
||||
})
|
||||
|
|
|
@ -151,9 +151,11 @@ import { getImage } from '@/utils/comm';
|
|||
import { message } from 'jetlinks-ui-components';
|
||||
import Save from './Save/index.vue';
|
||||
import { SystemConst } from '@/utils/consts';
|
||||
import {useRouterParams} from "@/utils/hooks/useParams";
|
||||
const params = ref<Record<string, any>>({});
|
||||
let visiable = ref(false);
|
||||
const tableRef = ref<Record<string, any>>({});
|
||||
const { params: routeParams } = useRouterParams()
|
||||
const query = {
|
||||
columns: [
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue