|
@@ -1,136 +1,166 @@
|
|
|
import Vue from "vue";
|
|
|
|
|
|
-// const ignoreComponents = [undefined, "transition", "router-link", "Bar"];
|
|
|
-
|
|
|
-// const ignoreComponentsNameRegexArray = [/^El[A-Z].*/, /^fa-.*/];
|
|
|
-
|
|
|
-// const groupCollapsed = true;
|
|
|
-
|
|
|
-// const RENDER_DURATION = 1 * 1000;
|
|
|
-
|
|
|
-export default function({
|
|
|
- ignoreComponents = [undefined, "transition", "router-link", "Bar"],
|
|
|
- ignoreComponentsNameRegexArray = [/^El[A-Z].*/, /^fa-.*/],
|
|
|
- groupCollapsed = true,
|
|
|
- RENDER_DURATION = 1 * 1000
|
|
|
-}) {
|
|
|
- function getParentNumber(that) {
|
|
|
- let parentNumber = 0;
|
|
|
- while (that) {
|
|
|
- if (that.$parent) {
|
|
|
- parentNumber++;
|
|
|
- that = that.$parent;
|
|
|
- } else {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- return parentNumber;
|
|
|
- }
|
|
|
-
|
|
|
- function componentNameMatch(name) {
|
|
|
- if (ignoreComponents.includes(name)) {
|
|
|
- return true;
|
|
|
+const ignoreComponents = [
|
|
|
+ undefined,
|
|
|
+ "transition",
|
|
|
+ "RemainTime",
|
|
|
+ "router-link",
|
|
|
+ "Affix",
|
|
|
+ "Alert",
|
|
|
+ "Anchor",
|
|
|
+ "AnchorLink",
|
|
|
+ "AutoComplete",
|
|
|
+ "Avatar",
|
|
|
+ "BackTop",
|
|
|
+ "Badge",
|
|
|
+ "Breadcrumb",
|
|
|
+ "BreadcrumbItem",
|
|
|
+ "Button",
|
|
|
+ "ButtonGroup",
|
|
|
+ "Card",
|
|
|
+ "Carousel",
|
|
|
+ "CarouselItem",
|
|
|
+ "Cascader",
|
|
|
+ "Cell",
|
|
|
+ "CellGroup",
|
|
|
+ "Checkbox",
|
|
|
+ "CheckboxGroup",
|
|
|
+ "i-circle",
|
|
|
+ "Col",
|
|
|
+ "Collapse",
|
|
|
+ "ColorPicker",
|
|
|
+ "Content",
|
|
|
+ "Divider",
|
|
|
+ "DatePicker",
|
|
|
+ "Drawer",
|
|
|
+ "Dropdown",
|
|
|
+ "DropdownItem",
|
|
|
+ "DropdownMenu",
|
|
|
+ "Footer",
|
|
|
+ "Form",
|
|
|
+ "iForm",
|
|
|
+ "FormItem",
|
|
|
+ "Header",
|
|
|
+ "Icon",
|
|
|
+ "Input",
|
|
|
+ "InputNumber",
|
|
|
+ "Layout",
|
|
|
+ "Menu",
|
|
|
+ "MenuGroup",
|
|
|
+ "MenuItem",
|
|
|
+ "Sider",
|
|
|
+ "Submenu",
|
|
|
+ "Modal",
|
|
|
+ "Option",
|
|
|
+ "OptionGroup",
|
|
|
+ "Page",
|
|
|
+ "Panel",
|
|
|
+ "Poptip",
|
|
|
+ "Progress",
|
|
|
+ "Radio",
|
|
|
+ "RadioGroup",
|
|
|
+ "Rate",
|
|
|
+ "Row",
|
|
|
+ "Select",
|
|
|
+ "Slider",
|
|
|
+ "Spin",
|
|
|
+ "Split",
|
|
|
+ "Step",
|
|
|
+ "Steps",
|
|
|
+ "i-switch",
|
|
|
+ "Table",
|
|
|
+ "Tabs",
|
|
|
+ "TabPane",
|
|
|
+ "Tag",
|
|
|
+ "Time",
|
|
|
+ "Timeline",
|
|
|
+ "TimelineItem",
|
|
|
+ "TimePicker",
|
|
|
+ "Tooltip",
|
|
|
+ "Transfer",
|
|
|
+ "Tree",
|
|
|
+ "Upload"
|
|
|
+];
|
|
|
+
|
|
|
+setInterval(
|
|
|
+ () => console.log("----------------------Vue lifecyle logs----------------"),
|
|
|
+ 10 * 1000
|
|
|
+);
|
|
|
+
|
|
|
+function getParentNumber(that) {
|
|
|
+ let parentNumber = 0;
|
|
|
+ while (that) {
|
|
|
+ if (that.$parent) {
|
|
|
+ parentNumber++;
|
|
|
+ that = that.$parent;
|
|
|
} else {
|
|
|
- let match = false;
|
|
|
- for (const regex of ignoreComponentsNameRegexArray) {
|
|
|
- if (regex.test(name)) {
|
|
|
- match = true;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- return match;
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- const injectMethods = [
|
|
|
- { name: "beforeCreate", style: "color: green" },
|
|
|
- { name: "created", style: "color: green" },
|
|
|
- { name: "beforeMount", style: "color: green" },
|
|
|
- { name: "mounted", style: "color: green" },
|
|
|
- { name: "beforeUpdate", style: "color: #0000aa" },
|
|
|
- { name: "updated", style: "color: #0000aa" },
|
|
|
- { name: "beforeDestroy", style: "color: red; font-weight: bold" },
|
|
|
- { name: "destroyed", style: "color: red; font-weight: bold" }
|
|
|
- ];
|
|
|
-
|
|
|
- const injectRouterMethods = [
|
|
|
- {
|
|
|
- name: "beforeRouteEnter",
|
|
|
- style: ["background: #aaa", "color: #0000aa;"]
|
|
|
- },
|
|
|
- {
|
|
|
- name: "beforeRouteUpdate",
|
|
|
- style: ["background: #aaa", "color: #0000aa;"]
|
|
|
- },
|
|
|
- { name: "beforeRouteLeave", style: ["background: #aaa", "color: #0000aa;"] }
|
|
|
- ];
|
|
|
-
|
|
|
- let lifeCycleMixins = {};
|
|
|
-
|
|
|
- let startLogging = false;
|
|
|
- let loggingTime = Date.now();
|
|
|
-
|
|
|
- for (const m of injectMethods) {
|
|
|
- lifeCycleMixins[m.name] = function() {
|
|
|
- const parentNumber = getParentNumber(this);
|
|
|
- if (!componentNameMatch(this.$options.name)) {
|
|
|
- if (!startLogging) {
|
|
|
- startLogging = true;
|
|
|
- if (groupCollapsed) {
|
|
|
- console.groupCollapsed("Vue lifecyle logs");
|
|
|
- } else {
|
|
|
- console.group("Vue lifecyle logs");
|
|
|
- }
|
|
|
-
|
|
|
- loggingTime = Date.now();
|
|
|
- }
|
|
|
- console.log(
|
|
|
- "--".repeat(parentNumber) + `${this.$options.name} %c ${m.name}`,
|
|
|
- m.style
|
|
|
- );
|
|
|
- }
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- for (const m of injectRouterMethods) {
|
|
|
- lifeCycleMixins[m.name] = function(to, from, next) {
|
|
|
- if (!startLogging) {
|
|
|
- startLogging = true;
|
|
|
- if (groupCollapsed) {
|
|
|
- console.groupCollapsed("Vue lifecyle logs");
|
|
|
- } else {
|
|
|
- console.group("Vue lifecyle logs");
|
|
|
- }
|
|
|
-
|
|
|
- loggingTime = Date.now();
|
|
|
- }
|
|
|
-
|
|
|
+ return parentNumber;
|
|
|
+}
|
|
|
+Vue.mixin({
|
|
|
+ created() {
|
|
|
+ const parentNumber = getParentNumber(this);
|
|
|
+ if (!ignoreComponents.includes(this.$options.name))
|
|
|
console.log(
|
|
|
- "%c " +
|
|
|
- from.fullPath +
|
|
|
- " --> " +
|
|
|
- to.fullPath +
|
|
|
- (this ? ` (${this.$options.name}) ` : " ") +
|
|
|
- `%c ${m.name}`,
|
|
|
- ...m.style
|
|
|
+ "--".repeat(parentNumber) + `${this.$options.name} %c created`,
|
|
|
+ "color: green"
|
|
|
+ );
|
|
|
+ },
|
|
|
+ mounted() {
|
|
|
+ const parentNumber = getParentNumber(this);
|
|
|
+ if (!ignoreComponents.includes(this.$options.name))
|
|
|
+ console.log(
|
|
|
+ "--".repeat(parentNumber) + `${this.$options.name} %c mounted`,
|
|
|
+ "color: green"
|
|
|
+ );
|
|
|
+ },
|
|
|
+ updated() {
|
|
|
+ const parentNumber = getParentNumber(this);
|
|
|
+ if (!ignoreComponents.includes(this.$options.name))
|
|
|
+ console.log(
|
|
|
+ "--".repeat(parentNumber) + `${this.$options.name} %c updated`,
|
|
|
+ "color: #0000aa"
|
|
|
+ );
|
|
|
+ },
|
|
|
+ beforeRouteEnter(to, from, next) {
|
|
|
+ console.log(
|
|
|
+ "%c " + from.fullPath + " --> " + to.fullPath + " %c beforeRouteEnter",
|
|
|
+ "background: #aaa",
|
|
|
+ "color: #0000aa"
|
|
|
+ );
|
|
|
+
|
|
|
+ next();
|
|
|
+ },
|
|
|
+ beforeRouteUpdate(to, from, next) {
|
|
|
+ const parentNumber = getParentNumber(this);
|
|
|
+ console.log(
|
|
|
+ "%c " +
|
|
|
+ "--".repeat(parentNumber) +
|
|
|
+ `${this.$options.name} %c beforeRouteUpdate`,
|
|
|
+ "background: #aaa",
|
|
|
+ "color: #0000aa"
|
|
|
+ );
|
|
|
+ next();
|
|
|
+ },
|
|
|
+ beforeRouteLeave(to, from, next) {
|
|
|
+ const parentNumber = getParentNumber(this);
|
|
|
+ console.log(
|
|
|
+ "%c " +
|
|
|
+ "--".repeat(parentNumber) +
|
|
|
+ `${this.$options.name} %c beforeRouteLeave`,
|
|
|
+ "background: #aaa",
|
|
|
+ "color: #0000aa"
|
|
|
+ );
|
|
|
+ next();
|
|
|
+ },
|
|
|
+ beforeDestroy() {
|
|
|
+ const parentNumber = getParentNumber(this);
|
|
|
+ if (!ignoreComponents.includes(this.$options.name))
|
|
|
+ console.log(
|
|
|
+ "--".repeat(parentNumber) + `${this.$options.name} %c beforeDestroy`,
|
|
|
+ "color: red; font-weight: bold"
|
|
|
);
|
|
|
-
|
|
|
- next();
|
|
|
- };
|
|
|
}
|
|
|
-
|
|
|
- // setInterval(
|
|
|
- // () => console.log("----------------------Vue lifecyle logs----------------"),
|
|
|
- // 10 * 1000
|
|
|
- // );
|
|
|
- setInterval(() => {
|
|
|
- if (startLogging && Date.now() - loggingTime > RENDER_DURATION) {
|
|
|
- console.groupEnd();
|
|
|
- startLogging = false;
|
|
|
- }
|
|
|
- }, 1 * 100);
|
|
|
-
|
|
|
- Vue.mixin({
|
|
|
- ...lifeCycleMixins
|
|
|
- });
|
|
|
-}
|
|
|
+});
|