history.js
1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* @Descripttion:
* @version: 1.0.0
* @Author: limin
* @Date: 2021-08-25 14:52:15
* @LastEditors: limin
* @LastEditTime: 2021-10-13 11:22:37
* @FilePath: \scrm\scrm-base\src\global\history.js
*/
import store from '@/store'
import { utils } from 'glsx-common'
/**
* 跨应用路由跳转
* @param {String} href url地址
* @param {Object} stateObj 状态参数 可以通过history.state读取
* @param {String} title 标题 暂时没有用
*/
function push(menu) {
let stateObj, title, url, id
function val(to) {
if (to) {
stateObj = to.stateObj
title = to.title
id = to.id
url = to.path
if (id) {
store.dispatch('app/setCurrentPage', to)
}
}
}
if (typeof menu === 'string') {
url = menu
} else {
val(menu)
}
if (!url) {
throw new Error('history.push:必须传入URL')
}
const to = store.getters.app.flatten.find(mod => url === mod.path || '/' + url === mod.path)
to && val(to)
if (!url) {
throw new Error('跳转页面失败,请检查页面参数是否正确')
}
if (!utils.isEmptyObject(menu.params)) {
url = url + '?' + utils.genUrlParams(menu.params)
}
window.history.pushState(stateObj, title, url)
}
export {
push // 跨应用路由跳转
}