mirror of
http://112.124.100.131/GFRS/ebiz-h5.git
synced 2025-12-22 19:56:43 +08:00
feat(underwriting): 新增路由跳转工具函数并优化跳转逻辑
- 引入 jump 工具函数并调整其内部路由调用方式 - 新增 navigateRouter 函数用于统一管理路由跳转 - 替换原有 add 方法为 navigateDataCollection 并使用新跳转逻辑 - 移除旧有的手动清理 localStorage 的逻辑 - 优化路由查找逻辑,支持多层级 children 路由匹配 - 添加 URL 参数处理函数 processJson 以适配查询字符串拼接
This commit is contained in:
@@ -1,13 +1,17 @@
|
|||||||
/* eslint-disable no-undef */
|
/* eslint-disable no-undef */
|
||||||
|
import router from '@/router'
|
||||||
|
|
||||||
export default function jump(options) {
|
export default function jump(options) {
|
||||||
// eslint-disable
|
// eslint-disable
|
||||||
if (window.WebViewJavascriptBridge && options.flag) {
|
if (window.WebViewJavascriptBridge && options.flag) {
|
||||||
if (options.flag == 'h5' ||
|
if (
|
||||||
|
options.flag == 'h5' ||
|
||||||
options.flag == 'service' ||
|
options.flag == 'service' ||
|
||||||
options.flag == 'home' ||
|
options.flag == 'home' ||
|
||||||
options.flag == 'mine' ||
|
options.flag == 'mine' ||
|
||||||
options.flag == 'message' ||
|
options.flag == 'message' ||
|
||||||
options.flag == 'setting' ) {
|
options.flag == 'setting'
|
||||||
|
) {
|
||||||
EWebBridge.webCallAppInJs('bridge', {
|
EWebBridge.webCallAppInJs('bridge', {
|
||||||
flag: options.flag,
|
flag: options.flag,
|
||||||
extra: options.extra
|
extra: options.extra
|
||||||
@@ -23,11 +27,11 @@ export default function jump(options) {
|
|||||||
} else {
|
} else {
|
||||||
// 1:replace 2:go 默认为push
|
// 1:replace 2:go 默认为push
|
||||||
if (options.routerInfo && options.routerInfo.type == '1') {
|
if (options.routerInfo && options.routerInfo.type == '1') {
|
||||||
this.$router.replace(options.routerInfo)
|
router.replace(options.routerInfo)
|
||||||
} else if (options.routerInfo && options.routerInfo.type == '2') {
|
} else if (options.routerInfo && options.routerInfo.type == '2') {
|
||||||
this.$router.go(options.routerInfo.index || -1)
|
router.go(options.routerInfo.index || -1)
|
||||||
} else if (options.routerInfo) {
|
} else if (options.routerInfo) {
|
||||||
this.$router.push(options.routerInfo)
|
router.push(options.routerInfo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,13 +20,14 @@
|
|||||||
>
|
>
|
||||||
</van-list>
|
</van-list>
|
||||||
|
|
||||||
<Button v-no-more-click="1000" class="bottom-btn" type="danger" @click="add">点我新增</Button>
|
<Button v-no-more-click="1000" class="bottom-btn" type="danger" @click="navigateDataCollection">点我新增</Button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { navigateRouter } from '@/views/ebiz/underwriting/js/navigate'
|
||||||
import { Search, Tabs, Tab, List, Sticky, Button } from 'vant'
|
import { Search, Tabs, Tab, List, Sticky, Button } from 'vant'
|
||||||
import { orderList, getBankCardSignState } from '@/api/ebiz/sale/sale'
|
import { orderList } from '@/api/ebiz/sale/sale'
|
||||||
import { formatRiskList } from '@/assets/js/utils/formatRiskList.js'
|
import { formatRiskList } from '@/assets/js/utils/formatRiskList.js'
|
||||||
import dataDictionary from '@/assets/js/utils/data-dictionary' //根据数据字典找到用户等级
|
import dataDictionary from '@/assets/js/utils/data-dictionary' //根据数据字典找到用户等级
|
||||||
|
|
||||||
@@ -142,26 +143,9 @@ export default {
|
|||||||
async goDetail() {},
|
async goDetail() {},
|
||||||
|
|
||||||
//新增
|
//新增
|
||||||
add() {
|
navigateDataCollection() {
|
||||||
let thisToken = this.$CacheUtils.getLocItem('token')
|
navigateRouter({
|
||||||
let thisbranchType = ''
|
name: 'UnderwritingDataCollection'
|
||||||
if (this.$CacheUtils.getLocItem('branchType') == '13') {
|
|
||||||
thisbranchType = this.$CacheUtils.getLocItem('branchType')
|
|
||||||
}
|
|
||||||
window.localStorage.clear()
|
|
||||||
this.$CacheUtils.setLocItem('token', thisToken)
|
|
||||||
if (thisbranchType) {
|
|
||||||
this.$CacheUtils.setLocItem('branchType', thisbranchType)
|
|
||||||
}
|
|
||||||
|
|
||||||
localStorage.orderNo = ''
|
|
||||||
localStorage.chooseProductCodes = '' //置空所选险种
|
|
||||||
this.$jump({
|
|
||||||
flag: 'h5',
|
|
||||||
extra: {
|
|
||||||
url: location.origin + '/#/sale/insuredInfo'
|
|
||||||
},
|
|
||||||
routerInfo: { path: '/sale/insuredInfo' }
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
82
src/views/ebiz/underwriting/js/navigate.js
Normal file
82
src/views/ebiz/underwriting/js/navigate.js
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
import jump from '@/assets/js/utils/jump'
|
||||||
|
import router from '@/router'
|
||||||
|
/**
|
||||||
|
* 路由跳转函数
|
||||||
|
* @param path { String}路径
|
||||||
|
* @param name
|
||||||
|
* @param title {String} 标题内容
|
||||||
|
* @param params { Object}参数
|
||||||
|
*/
|
||||||
|
export function navigateRouter({ path = '', name = '', title = '', params = {} } = {}) {
|
||||||
|
const routes = router.options.routes
|
||||||
|
|
||||||
|
let options = {
|
||||||
|
flag: 'h5',
|
||||||
|
extra: {
|
||||||
|
title,
|
||||||
|
// forbidSwipeBack: 1, //当前页面禁止右滑返回
|
||||||
|
url: ''
|
||||||
|
},
|
||||||
|
routerInfo: { query: params }
|
||||||
|
}
|
||||||
|
if (path) {
|
||||||
|
const route = routes.find(item => {
|
||||||
|
if (item.children) {
|
||||||
|
// 可能后面 children 存在多个,目前暂时先判定一层。 待优化
|
||||||
|
return item.children.find(childItem => `${item.path}/${childItem.path}` === path)
|
||||||
|
}
|
||||||
|
return item.path === path
|
||||||
|
})
|
||||||
|
if (!route) {
|
||||||
|
console.error('在 routers 中无法找到该路径,请检查路径是否正确')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
options.extra = {
|
||||||
|
title: route.meta && route.meta.title ? route.meta.title : '',
|
||||||
|
url: location.origin + '/#' + path + '?' + processJson(params)
|
||||||
|
}
|
||||||
|
options.routerInfo = { path }
|
||||||
|
} else if (name) {
|
||||||
|
const route = routes.find(item => {
|
||||||
|
if (item.children) {
|
||||||
|
// 可能后面 children 存在多个,目前暂时先判定一层。 待优化
|
||||||
|
return item.children.find(childItem => childItem.name === name)
|
||||||
|
}
|
||||||
|
return item.name === name
|
||||||
|
})
|
||||||
|
if (!route) {
|
||||||
|
console.error('在 routers 中无法找到该路径,请检查路径是否正确')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 如何存在子元素, 需要重新更改 path 地址
|
||||||
|
if (route.children) {
|
||||||
|
route.path = `${route.path}/${route.children.find(childItem => childItem.name === name).path}`
|
||||||
|
}
|
||||||
|
console.log(route)
|
||||||
|
options.extra = {
|
||||||
|
title: route.meta && route.meta.title ? route.meta.title : '',
|
||||||
|
url: location.origin + '/#' + route.path + '?' + processJson(params)
|
||||||
|
}
|
||||||
|
|
||||||
|
options.routerInfo = { name }
|
||||||
|
}
|
||||||
|
|
||||||
|
jump(options)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理 json 键值对,到 url 中
|
||||||
|
*/
|
||||||
|
function processJson(json) {
|
||||||
|
if (typeof json !== 'object') return
|
||||||
|
if (window.URLSearchParams) return new URLSearchParams(json).toString()
|
||||||
|
|
||||||
|
let url = ''
|
||||||
|
for (const key in json) {
|
||||||
|
if (json.hasOwnProperty(key)) {
|
||||||
|
url += key + '=' + json[key] + '&'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return url.substring(0, url.length - 1)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user