feat: 优化 懒加载事件 ,添加router的path显示

This commit is contained in:
zhangyu
2021-12-21 19:19:35 +08:00
parent 08a177c9ed
commit c1c5b9541b
11 changed files with 71 additions and 19 deletions

View File

@@ -0,0 +1,31 @@
import lodash from 'lodash'
export default {
methods: {
// 解析请求参数,初始化 searchLabel
initQueryFromPath () {
const q = this.$route.query
const searchKeys = {
// key: path 键
// value: vue set 参数
pageNo: { target: this.pageObj, propertyName: 'pageNo', type: 'number' },
pageSize: { target: this.pageObj, propertyName: 'pageSize', type: 'number' },
orderBy: { target: this.$data, propertyName: 'orderBy', type: 'string' },
id: { target: this.searchLabel, propertyName: 'id', type: 'number' },
severityIds: { target: this.searchLabel, propertyName: 'severityIds', type: 'string' },
type: { target: this.searchLabel, propertyName: 'type', type: 'number' },
name: { target: this.searchLabel, propertyName: 'name', type: 'string' }
}
lodash.forIn(searchKeys, (val, key) => {
let qv = lodash.get(q, key)
if (qv && val.type == 'number') {
qv = lodash.toNumber(qv)
}
qv && this.$set(val.target, val.propertyName, qv)
})
},
// 更新path包含请求参数
updatePath (param) {
this.$router.replace({ path: this.fromRoute.alertRule, query: param }).catch(err => {})
}
}
}