fix: bug#10979

This commit is contained in:
xieyonghong 2023-03-26 00:05:03 +08:00
parent 3dd39c5279
commit b9e332447e
11 changed files with 66 additions and 23 deletions

View File

@ -39,10 +39,7 @@ type MenuStateType = {
} }
} }
siderMenus: MenuItem[] siderMenus: MenuItem[]
params: { params: Record<string, any>
key: string
params: Record<string, any>
}
} }
@ -50,10 +47,7 @@ export const useMenuStore = defineStore({
id: 'menu', id: 'menu',
state: (): MenuStateType => ({ state: (): MenuStateType => ({
menus: {}, menus: {},
params: { params: {},
key: '',
params: {}
},
siderMenus: [] siderMenus: []
}), }),
getters: { getters: {
@ -85,6 +79,7 @@ export const useMenuStore = defineStore({
jumpPage(name: string, params?: Record<string, any>, query?: Record<string, any>) { jumpPage(name: string, params?: Record<string, any>, query?: Record<string, any>) {
const path = this.hasMenu(name) const path = this.hasMenu(name)
if (path) { if (path) {
this.params = { [name]: params || {}}
router.push({ router.push({
name, params, query, state: { params } name, params, query, state: { params }
}) })

View File

@ -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
}
}

View File

@ -119,10 +119,12 @@ import { message } from 'jetlinks-ui-components';
import { getImage } from '@/utils/comm'; import { getImage } from '@/utils/comm';
import { getWebSocket } from '@/utils/websocket'; import { getWebSocket } from '@/utils/websocket';
import { useMenuStore } from '@/store/menu'; import { useMenuStore } from '@/store/menu';
import {useRouterParams} from "@/utils/hooks/useParams";
const menuStory = useMenuStore(); const menuStory = useMenuStore();
const route = useRoute(); const route = useRoute();
const routerParams = useRouterParams()
const instanceStore = useInstanceStore(); const instanceStore = useInstanceStore();
const statusMap = new Map(); const statusMap = new Map();
@ -267,15 +269,14 @@ const getDetailFn = async () => {
await instanceStore.refresh(String(_id)); await instanceStore.refresh(String(_id));
getStatus(String(_id)); getStatus(String(_id));
list.value = [...initList]; list.value = [...initList];
console.log('watch', route.params?.id)
getDetail(); getDetail();
instanceStore.tabActiveKey = history.state?.params?.tab || 'Info'; instanceStore.tabActiveKey = routerParams.params.value.tab || 'Info';
} }
} }
onMounted(() => { onMounted(() => {
getDetailFn() getDetailFn()
instanceStore.tabActiveKey = history.state?.params?.tab || 'Info'; instanceStore.tabActiveKey = routerParams.params.value.tab || 'Info';
}); });
const onBack = () => { const onBack = () => {

View File

@ -308,6 +308,7 @@ import dayjs from 'dayjs';
import BadgeStatus from '@/components/BadgeStatus/index.vue'; import BadgeStatus from '@/components/BadgeStatus/index.vue';
import BatchDropdown from '@/components/BatchDropdown/index.vue'; import BatchDropdown from '@/components/BatchDropdown/index.vue';
import { BatchActionsType } from '@/components/BatchDropdown/types'; import { BatchActionsType } from '@/components/BatchDropdown/types';
import {useRouterParams} from "@/utils/hooks/useParams";
const instanceRef = ref<Record<string, any>>({}); const instanceRef = ref<Record<string, any>>({});
const params = ref<Record<string, any>>({}); const params = ref<Record<string, any>>({});
@ -320,7 +321,7 @@ const operationVisible = ref<boolean>(false);
const api = ref<string>(''); const api = ref<string>('');
const type = ref<string>(''); const type = ref<string>('');
const isCheck = ref<boolean>(false); const isCheck = ref<boolean>(false);
const routerParams = useRouterParams()
const menuStory = useMenuStore(); const menuStory = useMenuStore();
const columns = [ const columns = [
@ -546,7 +547,7 @@ const paramsFormat = (
}; };
onMounted(() => { onMounted(() => {
if (history.state?.params?.type === 'add') { if (routerParams.params.value.type === 'add') {
handleAdd(); handleAdd();
} }
}); });

View File

@ -114,11 +114,13 @@ import { message } from 'jetlinks-ui-components';
import { getImage, handleParamsToString } from '@/utils/comm' import { getImage, handleParamsToString } from '@/utils/comm'
import encodeQuery from '@/utils/encodeQuery'; import encodeQuery from '@/utils/encodeQuery';
import { useMenuStore } from '@/store/menu'; import { useMenuStore } from '@/store/menu';
import {useRouterParams} from "@/utils/hooks/useParams";
const menuStory = useMenuStore(); const menuStory = useMenuStore();
const route = useRoute(); const route = useRoute();
const checked = ref<boolean>(true); const checked = ref<boolean>(true);
const productStore = useProductStore(); const productStore = useProductStore();
const routerParams = useRouterParams()
const searchParams = ref({ const searchParams = ref({
terms1: [ terms1: [
{ {
@ -291,8 +293,8 @@ const jumpDevice = () => {
); );
}; };
onMounted(() => { onMounted(() => {
if (history.state?.params?.tab) { if (routerParams.params?.value.tab) {
productStore.tabActiveKey = history.state?.params?.tab; productStore.tabActiveKey = routerParams.params?.value.tab;
} }
}); });
</script> </script>

View File

@ -181,6 +181,7 @@ import { typeOptions } from '@/components/Search/util';
import Save from './Save/index.vue'; import Save from './Save/index.vue';
import { useMenuStore } from 'store/menu'; import { useMenuStore } from 'store/menu';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import {useRouterParams} from "@/utils/hooks/useParams";
/** /**
* 表格数据 * 表格数据
*/ */
@ -616,9 +617,9 @@ const saveRef = ref();
const handleSearch = (e: any) => { const handleSearch = (e: any) => {
params.value = e; params.value = e;
}; };
const route = useRoute(); const routerParams = useRouterParams()
onMounted(() => { onMounted(() => {
if(history.state?.params?.save){ if(routerParams.params?.value.save){
add(); add();
} }
}); });

View File

@ -8,12 +8,13 @@
<script setup lang="ts"> <script setup lang="ts">
import { _control, _stopControl } from '@/api/edge/device'; import { _control, _stopControl } from '@/api/edge/device';
import {useRouterParams} from "@/utils/hooks/useParams";
const url = ref<string>(''); const url = ref<string>('');
const deviceId = ref<string>(''); const deviceId = ref<string>('');
const { params } = useRouterParams()
watch( watch(
() => history.state?.params?.id, () => params.value.id,
(newId) => { (newId) => {
if (newId) { if (newId) {
deviceId.value = newId as string; deviceId.value = newId as string;

View File

@ -421,6 +421,8 @@ import { useMenuStore } from 'store/menu';
import BadgeStatus from '@/components/BadgeStatus/index.vue'; import BadgeStatus from '@/components/BadgeStatus/index.vue';
import BatchDropdown from '@/components/BatchDropdown/index.vue'; import BatchDropdown from '@/components/BatchDropdown/index.vue';
import { BatchActionsType } from '@/components/BatchDropdown/types'; import { BatchActionsType } from '@/components/BatchDropdown/types';
import {usePermissionStore} from "store/permission";
import {useRouterParams} from "@/utils/hooks/useParams";
const router = useRouter(); const router = useRouter();
const menuStory = useMenuStore(); const menuStory = useMenuStore();
@ -588,12 +590,15 @@ const columns = [
scopedSlots: true, scopedSlots: true,
}, },
]; ];
const btnHasPermission = usePermissionStore().hasPermission;
const paltformPermission = btnHasPermission(`iot-card/Platform:add`);
const importSave = () => { const importSave = () => {
cardManageRef.value?.reload() cardManageRef.value?.reload()
importVisible.value = false importVisible.value = false
} }
const routerParams = useRouterParams()
const getActions = ( const getActions = (
data: Partial<Record<string, any>>, data: Partial<Record<string, any>>,
type: 'card' | 'table', type: 'card' | 'table',
@ -989,6 +994,12 @@ const batchActions: BatchActionsType[] = [
}, },
}, },
]; ];
onMounted(() => {
if (routerParams.params.value.type === 'add' && paltformPermission) {
handleAdd()
}
})
</script> </script>
<style scoped lang="less"> <style scoped lang="less">

View File

@ -179,7 +179,6 @@ const pieChartData = ref<any[]>([
]); ]);
const jumpPage = (data: GuideItemProps) => { const jumpPage = (data: GuideItemProps) => {
console.log(data.auth)
if (!data.auth){ if (!data.auth){
message.warning('暂无权限,请联系管理员'); message.warning('暂无权限,请联系管理员');
return return
@ -187,7 +186,11 @@ const jumpPage = (data: GuideItemProps) => {
if (data.key === 'EQUIPMENT') { if (data.key === 'EQUIPMENT') {
menuStory.jumpPage(data.url, { id: ':id'}); menuStory.jumpPage(data.url, { id: ':id'});
} else { } else {
menuStory.jumpPage(data.url); let params: any = undefined
if (data.key === 'SCREEN') {
params = { type: 'add'}
}
menuStory.jumpPage(data.url, params);
} }
}; };

View File

@ -53,8 +53,10 @@ import { message } from 'jetlinks-ui-components';
import { useAlarmStore } from '@/store/alarm'; import { useAlarmStore } from '@/store/alarm';
import Info from './info.vue'; import Info from './info.vue';
import { storeToRefs } from 'pinia'; import { storeToRefs } from 'pinia';
import {useRouterParams} from "@/utils/hooks/useParams";
const route = useRoute(); const route = useRoute();
const id = route.params?.id; const id = route.params?.id;
const { params: routerParams } = useRouterParams()
let visiable = ref(false); let visiable = ref(false);
const columns = [ const columns = [
{ {
@ -181,7 +183,7 @@ const close = () => {
watchEffect(()=>{ watchEffect(()=>{
current.value = details.value; current.value = details.value;
if(history.state?.params.detail && details.value){ if(routerParams.value.detail && details.value){
visiable.value = true; visiable.value = true;
} }
}) })

View File

@ -151,9 +151,11 @@ import { getImage } from '@/utils/comm';
import { message } from 'jetlinks-ui-components'; import { message } from 'jetlinks-ui-components';
import Save from './Save/index.vue'; import Save from './Save/index.vue';
import { SystemConst } from '@/utils/consts'; import { SystemConst } from '@/utils/consts';
import {useRouterParams} from "@/utils/hooks/useParams";
const params = ref<Record<string, any>>({}); const params = ref<Record<string, any>>({});
let visiable = ref(false); let visiable = ref(false);
const tableRef = ref<Record<string, any>>({}); const tableRef = ref<Record<string, any>>({});
const { params: routeParams } = useRouterParams()
const query = { const query = {
columns: [ columns: [
{ {