Commit bceaff99 authored by 王玉鑫's avatar 王玉鑫

fix: 首页切换区域,选中项与url参数不同步修正

parent 87b68d29
...@@ -144,6 +144,7 @@ import { useRoute } from 'vue-router'; ...@@ -144,6 +144,7 @@ import { useRoute } from 'vue-router';
// import cookie from 'js-cookie'; // import cookie from 'js-cookie';
import { useCity } from '@/composable/useCity.ts'; import { useCity } from '@/composable/useCity.ts';
import type { DropdownInstance } from 'element-plus'; import type { DropdownInstance } from 'element-plus';
import type { RouteLocationRaw } from 'vue-router';
const props = withDefaults( const props = withDefaults(
defineProps<{ defineProps<{
...@@ -248,12 +249,15 @@ const changeCityStatus = (status: number) => { ...@@ -248,12 +249,15 @@ const changeCityStatus = (status: number) => {
const handleCityClick = (cityName: string) => { const handleCityClick = (cityName: string) => {
currentCity.value = cityName; currentCity.value = cityName;
// cookie.set('city', cityName);
const cityInFilter = provinceList.filter((item) => { const cityInFilter = provinceList.filter((item) => {
return item.name.replace(/\s+/g, '').indexOf(cityName) > -1; return item.name.replace(/\s+/g, '').indexOf(cityName) > -1;
}); });
const jump = (params: RouteLocationRaw) => {
openPage(params);
router.replace(params);
};
if (cityInFilter.length) { if (cityInFilter.length) {
openPage({ jump({
name: route.name!, name: route.name!,
query: { query: {
city: cityInFilter[0].name, city: cityInFilter[0].name,
...@@ -261,7 +265,7 @@ const handleCityClick = (cityName: string) => { ...@@ -261,7 +265,7 @@ const handleCityClick = (cityName: string) => {
}, },
}); });
} else { } else {
openPage({ jump({
name: route.name!, name: route.name!,
query: {}, query: {},
}); });
...@@ -275,7 +279,7 @@ const handleLogin = (type: 'loginByPhone' | 'register') => { ...@@ -275,7 +279,7 @@ const handleLogin = (type: 'loginByPhone' | 'register') => {
}; };
const toUserCenter = () => { const toUserCenter = () => {
dropdown.value.handleClose(); dropdown.value!.handleClose();
if (!(route.name as string).includes(RouteName.userCenter)) { if (!(route.name as string).includes(RouteName.userCenter)) {
router.push(RouteName.userCenter); router.push(RouteName.userCenter);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment