Commit 786c75b2 by Jaxon

chron: 路由结构调整

1 parent 7151765d
@import "./normalize.scss"; @import "./normalize.scss";
@import "./sprite.scss"; @import "./sprite.scss";
html, html,
body .app { body #app {
color: #333333; color: #333333;
font-family: Arial, Helvetica, "STHeiti STXihei", "Microsoft YaHei", Tohoma, sans-serif; font-family: Arial, Helvetica, "STHeiti STXihei", "Microsoft YaHei", Tohoma, sans-serif;
background-color: #fff; background-color: #fff;
......
.sprite-icon { .sprite-icon { background-image: url(../images/sprite.png);background-size: 80px 80px;}
background-image: url(../images/sprite.png); .icon-logo { width: 80px; height: 80px; background-position: 0px 0px;}
background-size: 80px 80px;
}
.icon-logo {
width: 80px;
height: 80px;
background-position: 0px 0px;
}
\ No newline at end of file \ No newline at end of file
...@@ -30,7 +30,7 @@ export default { ...@@ -30,7 +30,7 @@ export default {
}, },
{ {
title: "业绩概览", title: "业绩概览",
to: "/performance/overview", to: { path: "/performance/index" },
activeIcon: baseUrl + "tab-view-active.png", activeIcon: baseUrl + "tab-view-active.png",
inactiveIcon: baseUrl + "tab-view.png", inactiveIcon: baseUrl + "tab-view.png",
}, },
...@@ -51,6 +51,7 @@ export default { ...@@ -51,6 +51,7 @@ export default {
:deep(.van-tabbar-item__icon img) { :deep(.van-tabbar-item__icon img) {
height: 24px; height: 24px;
} }
.tab-icon { .tab-icon {
height: 20px; height: 20px;
width: 20px; width: 20px;
......
<template>
<router-view />
</template>
<script>
export default {
name: "RouteOutlet",
};
</script>
import router from "./router"; import router from "./router";
import { keeps } from "./routes";
export const keepAlives = keeps;
export default router; export default router;
import { mineRoutes } from "./mine";
import { getFirstNavigablePath } from "./shared";
import { teamWorkRoutes } from "./teamWork";
import { viewRoutes } from "./view";
export { mineRoutes } from "./mine";
export { routeOutlet } from "./shared";
export { teamWorkRoutes } from "./teamWork";
export { viewRoutes } from "./view";
const moduleRoutes = [
...teamWorkRoutes,
...viewRoutes,
...mineRoutes,
];
const defaultRedirect = getFirstNavigablePath(moduleRoutes) || "/";
export default [
{
path: "/",
redirect: defaultRedirect, // 默认重定向到首个移动端页面
},
...moduleRoutes,
];
import { routeOutlet } from "./shared";
export const mineRoutes = [
{
path: "/mine",
redirect: "/mine/tasks",
component: routeOutlet,
children: [
{
path: "tasks",
name: "mine/tasks",
component: () => import("@/views/mine/mine/tasks.vue"),
meta: {
title: "我的任务",
showTabBar: true,
},
},
],
},
];
export const routeOutlet = () => import("@/layouts/RouteOutlet.vue");
function trimSlashes(path) {
return (path || "").replace(/^\/+|\/+$/g, "");
}
function joinPaths(parentPath, childPath) {
const normalizedChild = childPath || "";
if (normalizedChild.startsWith("/"))
return normalizedChild;
const segments = [parentPath, normalizedChild]
.map(trimSlashes)
.filter(Boolean);
return segments.length ? `/${segments.join("/")}` : "/";
}
export function getFirstNavigablePath(routes, parentPath = "") {
for (const route of routes) {
const currentPath = joinPaths(parentPath, route.path);
if (route.children && route.children.length) {
const childPath = getFirstNavigablePath(route.children, currentPath);
if (childPath)
return childPath;
}
if (route.name)
return currentPath;
}
return "";
}
export const mobilePages = { import { routeOutlet } from "./shared";
teamWork: [
export const teamWorkRoutes = [
{ {
path: "/teamWork",
redirect: "/teamWork/teamList",
component: routeOutlet,
children: [
{
path: "teamList",
name: "teamWork/teamList", name: "teamWork/teamList",
path: "/teamWork/teamList", component: () => import("@/views/teamWork/teamWork/teamList.vue"),
meta: { meta: {
title: "团队工作台", title: "团队工作台",
showTabBar: true, showTabBar: true,
}, },
}, },
{ {
path: "reportDetail",
name: "teamWork/reportDetail", name: "teamWork/reportDetail",
path: "/teamWork/reportDetail", component: () => import("@/views/teamWork/teamWork/reportDetail.vue"),
meta: { meta: {
title: "督导日报", title: "督导日报",
}, },
}, },
{ {
path: "specialTaskList",
name: "teamWork/specialTaskList", name: "teamWork/specialTaskList",
path: "/teamWork/specialTaskList", component: () => import("@/views/teamWork/teamWork/specialTaskList.vue"),
meta: { meta: {
title: "专项任务列表", title: "专项任务列表",
}, },
}, },
{ {
path: "specialTaskDetail",
name: "teamWork/specialTaskDetail", name: "teamWork/specialTaskDetail",
path: "/teamWork/specialTaskDetail", component: () => import("@/views/teamWork/teamWork/specialTaskDetail.vue"),
meta: { meta: {
title: "专项任务详情", title: "专项任务详情",
}, },
}, },
], ],
performance: [
{
name: "performance/overview",
path: "/performance/overview",
meta: {
title: "业绩概览",
showTabBar: true,
},
},
],
mine: [
{
name: "mine/tasks",
path: "/mine/tasks",
meta: {
title: "我的任务",
showTabBar: true,
},
}, },
], ];
};
import { routeOutlet } from "./shared";
export const viewRoutes = [
{
path: "/performance",
redirect: "/performance/index",
component: routeOutlet,
children: [
{
path: "index",
name: "performance",
component: () => import("@/views/performance/view/index.vue"),
meta: {
title: "业绩概览",
showTabBar: true,
},
},
],
},
];
import Vue from "vue"; import Vue from "vue";
import Router from "vue-router"; import Router from "vue-router";
import store from "@/store"; import store from "@/store";
import routes from "./routes"; import routes from "./modules";
// hack router push callback // hack router push callback
const originalPush = Router.prototype.push; const originalPush = Router.prototype.push;
Router.prototype.push = function push(location, onResolve, onReject) { Router.prototype.push = function push(location, onResolve, onReject) {
...@@ -13,6 +13,7 @@ Router.prototype.push = function push(location, onResolve, onReject) { ...@@ -13,6 +13,7 @@ Router.prototype.push = function push(location, onResolve, onReject) {
Vue.use(Router); Vue.use(Router);
const router = createRouter(); const router = createRouter();
function createRouter() { function createRouter() {
return new Router({ return new Router({
// mode: 'history', // 如果是 history模式 需要配置vue.config.js publicPath // mode: 'history', // 如果是 history模式 需要配置vue.config.js publicPath
...@@ -23,6 +24,7 @@ function createRouter() { ...@@ -23,6 +24,7 @@ function createRouter() {
routes, routes,
}); });
} }
// http://scrm.dev.glsx.com.cn/dj-scrm-wx-work-main/ // http://scrm.dev.glsx.com.cn/dj-scrm-wx-work-main/
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
store.commit("SET_LAST_PATH", to.name); store.commit("SET_LAST_PATH", to.name);
...@@ -37,6 +39,7 @@ router.beforeEach((to, from, next) => { ...@@ -37,6 +39,7 @@ router.beforeEach((to, from, next) => {
} }
next(); next();
}); });
// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465 // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() { export function resetRouter() {
const newRouter = createRouter(); const newRouter = createRouter();
......
import { mobilePages } from "./mobile";
const keepAlives = [];
// 合并所有页面配置
const pages = { ...mobilePages };
const routes = [
{
path: "/",
redirect: "/teamWork/teamList", // 默认重定向到 mobile,或者根据需求改为其他
},
];
Object.keys(pages).map((parent) => {
pages[parent].map((val) => {
const childrenPath = `${parent}/${val.name}`;
console.log(childrenPath);
const { meta } = val;
const path = val.path || `/${val.name == "index" ? parent : childrenPath}`;
const name = val.name == "index" ? parent : val.name;
if (meta && meta.keepAlive)
keepAlives.push(name);
const route = {
component: resolve => require([`@/views/${childrenPath}.vue`], resolve),
path,
name,
meta,
};
routes.push(route);
});
});
export const keeps = keepAlives;
export default routes;
<template>
<div ref="wrapper" class="tabs-wrapper">
<div ref="tabsInner" class="tabs-inner">
<div class="tabs-bg" />
<div v-if="normalizedList.length"
class="slider"
:style="sliderStyle" />
<div v-for="(item, index) in normalizedList"
:key="item.key"
:ref="`tab-${index}`"
class="tab-item"
:class="{ 'is-active': activeKey === item.key }"
@click="onTap(item, index)">
<img v-if="item.icon && (!item.showIconOnActiveOnly || activeKey === item.key)"
class="icon"
:alt="item.label"
:src="item.icon" />
<span class="label">{{ item.label }}</span>
</div>
</div>
</div>
</template>
<script>
export default {
name: "TypeTabs",
props: {
list: {
type: Array,
default() {
return [];
},
},
value: {
type: [String, Number],
default: null,
},
},
data() {
return {
activeKey: null,
activeIndex: 0,
sliderX: 0,
sliderWidth: 0,
resizeObserver: null,
};
},
computed: {
normalizedList() {
return this.normalizeList(this.list);
},
sliderStyle() {
return {
width: this.sliderWidth + "px",
transform: "translate3d(" + this.sliderX + "px, 0, 0)",
};
},
},
watch: {
list: {
immediate: true,
deep: true,
handler() {
this.syncFromProps();
},
},
value: {
immediate: true,
handler() {
this.syncFromProps();
},
},
},
mounted() {
this.bindResizeObserver();
window.addEventListener("resize", this.updateSlider, { passive: true });
this.$nextTick(this.updateSlider);
},
beforeDestroy() {
window.removeEventListener("resize", this.updateSlider);
this.unbindResizeObserver();
},
methods: {
syncFromProps() {
let nextActiveKey = this.getValidActiveKey({
normalizedList: this.normalizedList,
value: this.value,
prevActiveKey: this.activeKey,
});
let nextActiveIndex = this.getIndexByKey(this.normalizedList, nextActiveKey);
this.activeKey = nextActiveKey;
this.activeIndex = nextActiveIndex;
this.$nextTick(function () {
this.updateSlider();
this.scrollActiveIntoView();
});
},
normalizeList(list) {
if (!Array.isArray(list)) {
return [];
}
return list
.map((raw) => {
let item = raw || {};
let labelObject = item.label && typeof item.label === "object" ? item.label : null;
let key
= item.key != null ? item.key : item.value != null ? item.value : item.id != null ? item.id : labelObject ? (labelObject.key != null ? labelObject.key : labelObject.value) : undefined;
let label = labelObject
? labelObject.text != null
? labelObject.text
: labelObject.name != null
? labelObject.name
: labelObject.label != null
? labelObject.label
: labelObject.value != null
? labelObject.value
: labelObject.key
: item.label != null
? item.label
: item.text != null
? item.text
: item.name != null
? item.name
: "";
return {
icon: item.icon || "",
key,
label: label == null ? "" : String(label),
showIconOnActiveOnly: Boolean(item.showIconOnActiveOnly),
};
})
.filter((item) => {
return item.key !== undefined && item.key !== null;
})
.map((item) => {
return {
icon: item.icon,
key: String(item.key),
label: item.label,
showIconOnActiveOnly: item.showIconOnActiveOnly,
};
});
},
getValidActiveKey(options) {
let normalizedList = options.normalizedList || [];
let value = options.value;
let prevActiveKey = options.prevActiveKey;
let keys = normalizedList.map((item) => {
return item.key;
});
let nextValue = value === undefined || value === null ? null : String(value);
let prevValue = prevActiveKey === undefined || prevActiveKey === null ? null : String(prevActiveKey);
if (nextValue !== null && keys.includes(nextValue)) {
return nextValue;
}
if (prevValue !== null && keys.includes(prevValue)) {
return prevValue;
}
return normalizedList[0] ? normalizedList[0].key : null;
},
getIndexByKey(normalizedList, key) {
if (!normalizedList.length || key == null) {
return 0;
}
let targetKey = String(key);
for (let i = 0; i < normalizedList.length; i += 1) {
if (normalizedList[i].key === targetKey) {
return i;
}
}
return 0;
},
onTap(item, index) {
let nextKey = item && item.key != null ? String(item.key) : null;
if (!nextKey || nextKey === this.activeKey) {
return;
}
this.activeKey = nextKey;
this.activeIndex = index;
this.$nextTick(function () {
this.updateSlider();
this.scrollActiveIntoView();
});
this.$emit("input", nextKey);
this.$emit("change", {
key: nextKey,
index,
item,
});
},
updateSlider() {
if (!this.normalizedList.length) {
this.sliderX = 0;
this.sliderWidth = 0;
return;
}
let tabEl = this.getTabElement(this.activeIndex);
if (!tabEl) {
return;
}
this.sliderX = tabEl.offsetLeft;
this.sliderWidth = tabEl.offsetWidth;
},
scrollActiveIntoView() {
if (this.normalizedList.length <= 2) {
return;
}
let wrapperEl = this.$refs.wrapper;
let tabEl = this.getTabElement(this.activeIndex);
if (!wrapperEl || !tabEl) {
return;
}
let targetScrollLeft = tabEl.offsetLeft - (wrapperEl.clientWidth - tabEl.offsetWidth) / 2;
let maxScrollLeft = Math.max(wrapperEl.scrollWidth - wrapperEl.clientWidth, 0);
let nextScrollLeft = Math.max(0, Math.min(targetScrollLeft, maxScrollLeft));
wrapperEl.scrollTo({
left: nextScrollLeft,
behavior: "smooth",
});
},
getTabElement(index) {
let ref = this.$refs["tab-" + index];
return Array.isArray(ref) ? ref[0] : ref;
},
bindResizeObserver() {
if (typeof ResizeObserver === "undefined") {
return;
}
let tabsInner = this.$refs.tabsInner;
if (!tabsInner) {
return;
}
this.resizeObserver = new ResizeObserver(this.updateSlider);
this.resizeObserver.observe(tabsInner);
},
unbindResizeObserver() {
if (this.resizeObserver) {
this.resizeObserver.disconnect();
this.resizeObserver = null;
}
},
},
};
</script>
<style scoped lang="scss">
.tabs-wrapper {
width: 100%;
box-sizing: border-box;
overflow-x: auto;
overflow-y: hidden;
-webkit-overflow-scrolling: touch;
scrollbar-width: none;
}
.tabs-wrapper::-webkit-scrollbar {
display: none;
}
.tabs-inner {
position: relative;
display: inline-flex;
align-items: center;
min-width: 100%;
width: max-content;
padding: var(--fontSize6, 6px);
box-sizing: border-box;
border-radius: var(--fontSize48, 48px);
overflow: hidden;
}
.tabs-bg {
position: absolute;
inset: 0;
border-radius: var(--fontSize48, 48px);
pointer-events: none;
}
.slider {
position: absolute;
top: var(--fontSize6, 6px);
bottom: var(--fontSize6, 6px);
left: 0;
z-index: 1;
border-radius: var(--fontSize48, 48px);
background-color: var(--primary-color, #1677ff);
transition:
transform 250ms cubic-bezier(0.2, 0.8, 0.2, 1),
width 250ms cubic-bezier(0.2, 0.8, 0.2, 1);
will-change: transform, width;
pointer-events: none;
}
.tab-item {
position: relative;
z-index: 2;
display: inline-flex;
align-items: center;
justify-content: center;
padding: var(--fontSize12, 12px) var(--fontSize28, 28px);
border-radius: var(--fontSize48, 48px);
white-space: nowrap;
color: #222222;
background: rgba(243, 243, 244, 1);
cursor: pointer;
user-select: none;
transition: color 250ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.tab-item.is-active {
color: #ffffff;
}
.tab-item + .tab-item {
margin-left: var(--fontSize12, 12px);
}
.icon {
position: relative;
z-index: 2;
width: var(--fontSize32, 32px);
height: var(--fontSize32, 32px);
margin-right: var(--fontSize12, 12px);
flex-shrink: 0;
object-fit: contain;
}
.label {
position: relative;
z-index: 2;
line-height: var(--fontSize40, 40px);
font-size: var(--fontSize26, 26px);
transition: color 250ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
</style>
<template>
<div class="page-container">
<van-empty description="业绩概览开发中..." />
</div>
</template>
<script>
export default {
name: "PerformanceOverview",
};
</script>
<style lang="scss" scoped>
.page-container {
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: #f2f3f7;
box-sizing: border-box;
padding-bottom: calc(50px + env(safe-area-inset-bottom));
}
</style>
<template>
<div class="page-container" :style="{ backgroundImage: `url(${pageBgUrl})` }">
<van-tabs>
<van-tab title="督导业绩" />
<van-tab title="门店业绩" />
</van-tabs>
<div class="filter-wrapper">
</div>
</div>
</template>
<script>
export default {
name: "PerformanceOverview",
data() {
return {
pageBgUrl: "https://img02.glsx.com.cn/weapp/resource/supervise-wecom/page-bg.png",
};
},
};
</script>
<style lang="scss" scoped>
.page-container {
background-position: 0 0;
background-size: 100% 240px;
background-repeat: no-repeat;
height: 100%;
::v-deep .van-tabs {
.van-tab {
flex: none;
font-weight: 500;
line-height: 20px;
margin-left: 16px;
&:first-child {
margin-left: 0;
}
&__text {
}
&--active {
color: var(--themeColor);
}
}
&__wrap {
background-color: transparent;
padding: 0 12px;
}
&__nav {
background-color: transparent;
}
&__line {
bottom: 18px;
width: 18px;
}
}
}
</style>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!