Ver Fonte

feature: 整合vue 用于写doc

后羿 há 1 ano atrás
pai
commit
8443dda1c0
24 ficheiros alterados com 1437 adições e 202 exclusões
  1. 4 0
      .browserslistrc
  2. 8 4
      .eslintrc.js
  3. 24 1
      .gitignore
  4. 1 0
      .prettierignore
  5. 3 0
      babel.config.js
  6. 19 0
      jsconfig.json
  7. 4 4
      lib/queue.js
  8. 20 4
      package.json
  9. BIN
      public/favicon.ico
  10. 17 0
      public/index.html
  11. 39 39
      sdk/async.ts
  12. 3 3
      sdk/index.ts
  13. 94 94
      sdk/queue.ts
  14. 52 52
      sdk/storage.ts
  15. 29 0
      src/App.vue
  16. BIN
      src/assets/logo.png
  17. 22 0
      src/components/navBar.vue
  18. 12 0
      src/main.js
  19. 17 0
      src/router/index.js
  20. 9 0
      src/store/index.js
  21. 3 0
      src/views/queue.vue
  22. 1 1
      tsconfig.json
  23. 31 0
      vue.config.js
  24. 1025 0
      yarn.lock

+ 4 - 0
.browserslistrc

@@ -0,0 +1,4 @@
+> 1%
+last 2 versions
+not dead
+not ie 11

+ 8 - 4
.eslintrc.js

@@ -7,8 +7,9 @@ const config = {
     browser: true,
     node: true,
   },
-  parser: "@typescript-eslint/parser",
+  parser: "vue-eslint-parser",
   extends: [
+    "plugin:vue/vue3-essential",
     "eslint:recommended",
     "plugin:@typescript-eslint/eslint-recommended",
     "plugin:@typescript-eslint/recommended",
@@ -16,12 +17,15 @@ const config = {
   ],
   plugins: ["@typescript-eslint"],
   parserOptions: {
-    ecmaVersion: 2020,
+    parser: "@babel/eslint-parser",
   },
   rules: {
-    "no-console": "off",
-    "no-debugger": "off",
+    "no-console": process.env.NODE_ENV === "production" ? "warn" : "off",
+    "no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off",
     "@typescript-eslint/no-explicit-any": "off",
+    "@typescript-eslint/no-var-requires": "off",
+    "vue/multi-word-component-names": "off",
+    "@typescript-eslint/no-empty-function": "off",
   },
 };
 

+ 24 - 1
.gitignore

@@ -1 +1,24 @@
-/node_modules
+.DS_Store
+node_modules
+/dist
+
+
+# local env files
+.env.local
+.env.*.local
+
+# Log files
+npm-debug.log*
+yarn-debug.log*
+yarn-error.log*
+pnpm-debug.log*
+
+# Editor directories and files
+.idea
+.vscode
+*.suo
+*.ntvs*
+*.njsproj
+*.sln
+*.sw?
+

+ 1 - 0
.prettierignore

@@ -0,0 +1 @@
+/lib

+ 3 - 0
babel.config.js

@@ -0,0 +1,3 @@
+module.exports = {
+  presets: ["@vue/cli-plugin-babel/preset"],
+};

+ 19 - 0
jsconfig.json

@@ -0,0 +1,19 @@
+{
+  "compilerOptions": {
+    "target": "es5",
+    "module": "esnext",
+    "baseUrl": "./",
+    "moduleResolution": "node",
+    "paths": {
+      "@/*": [
+        "src/*"
+      ]
+    },
+    "lib": [
+      "esnext",
+      "dom",
+      "dom.iterable",
+      "scripthost"
+    ]
+  }
+}

+ 4 - 4
lib/queue.js

@@ -71,13 +71,13 @@ class Node {
     }
     destroy() {
         if (this.prev) {
-            this.prev.setNext(null);
+            this.prev.setNext(undefined);
         }
         if (this.next) {
-            this.next.setPrev(null);
+            this.next.setPrev(undefined);
         }
-        this.prev = null;
-        this.next = null;
+        this.prev = undefined;
+        this.next = undefined;
         this.self = undefined;
     }
 }

+ 20 - 4
package.json

@@ -15,19 +15,35 @@
   "author": "shawn",
   "license": "ISC",
   "dependencies": {
+    "amfe-flexible": "^2.2.1",
     "core-js": "^3.8.3",
+    "reset-css": "^5.0.1",
     "vue": "^3.2.13",
     "vue-router": "^4.0.3",
     "vuex": "^4.0.0"
   },
   "devDependencies": {
+    "@babel/core": "^7.12.16",
+    "@babel/eslint-parser": "^7.12.16",
     "@typescript-eslint/eslint-plugin": "^5.60.0",
     "@typescript-eslint/parser": "^5.60.0",
-    "eslint": "^8.43.0",
-    "eslint-config-prettier": "^8.8.0",
-    "eslint-plugin-prettier": "^4.2.1",
+    "@vue/cli-plugin-babel": "~5.0.0",
+    "@vue/cli-plugin-eslint": "~5.0.0",
+    "@vue/cli-plugin-router": "~5.0.0",
+    "@vue/cli-plugin-vuex": "~5.0.0",
+    "@vue/cli-service": "~5.0.0",
+    "autoprefixer": "^10.4.14",
+    "eslint": "^7.32.0",
+    "eslint-config-prettier": "^8.3.0",
+    "eslint-plugin-prettier": "^4.0.0",
+    "eslint-plugin-vue": "^8.0.3",
+    "less": "^4.0.0",
+    "less-loader": "^8.0.0",
+    "postcss": "^8.4.24",
+    "postcss-pxtorem": "^6.0.0",
     "prettier": "^2.8.8",
     "tslib": "^2.5.3",
-    "typescript": "^5.1.3"
+    "typescript": "^5.1.3",
+    "vue-eslint-parser": "^9.3.1"
   }
 }

BIN
public/favicon.ico


+ 17 - 0
public/index.html

@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html lang="">
+  <head>
+    <meta charset="utf-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <meta name="viewport" content="width=device-width,initial-scale=1.0">
+    <link rel="icon" href="<%= BASE_URL %>favicon.ico">
+    <title><%= htmlWebpackPlugin.options.title %></title>
+  </head>
+  <body>
+    <noscript>
+      <strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
+    </noscript>
+    <div id="app"></div>
+    <!-- built files will be auto injected -->
+  </body>
+</html>

+ 39 - 39
src/async.ts → sdk/async.ts

@@ -1,39 +1,39 @@
-export async function asyncWhile(
-  checker: (index: number) => boolean | Promise<boolean>,
-  callback: (index: number) => void | Promise<void>
-) {
-  let index = 0;
-  const newCallback = async () => {
-    const checkRes = await checker(index);
-    if (checkRes) {
-      await callback(index);
-      index++;
-      await newCallback();
-    }
-  };
-  return await newCallback();
-}
-
-export async function asyncForEach<T = any>(
-  array: T[],
-  callback: (item: T, index: number) => boolean | Promise<boolean>
-) {
-  let index = 0;
-  const newCallback = async () => {
-    const item = array[index];
-    const res = await callback(item, index);
-    if (index < array.length - 1 && res !== false) {
-      index++;
-      await newCallback();
-    }
-  };
-  return await newCallback();
-}
-
-export function nextTick(time = 0) {
-  return new Promise((resolve) => {
-    setTimeout(() => {
-      resolve(true);
-    }, time);
-  });
-}
+export async function asyncWhile(
+  checker: (index: number) => boolean | Promise<boolean>,
+  callback: (index: number) => void | Promise<void>
+) {
+  let index = 0;
+  const newCallback = async () => {
+    const checkRes = await checker(index);
+    if (checkRes) {
+      await callback(index);
+      index++;
+      await newCallback();
+    }
+  };
+  return await newCallback();
+}
+
+export async function asyncForEach<T = any>(
+  array: T[],
+  callback: (item: T, index: number) => boolean | Promise<boolean>
+) {
+  let index = 0;
+  const newCallback = async () => {
+    const item = array[index];
+    const res = await callback(item, index);
+    if (index < array.length - 1 && res !== false) {
+      index++;
+      await newCallback();
+    }
+  };
+  return await newCallback();
+}
+
+export function nextTick(time = 0) {
+  return new Promise((resolve) => {
+    setTimeout(() => {
+      resolve(true);
+    }, time);
+  });
+}

+ 3 - 3
src/index.ts → sdk/index.ts

@@ -1,3 +1,3 @@
-export * from "./queue";
-export * from "./async";
-export * from "./storage";
+export * from "./queue";
+export * from "./async";
+export * from "./storage";

+ 94 - 94
src/queue.ts → sdk/queue.ts

@@ -1,94 +1,94 @@
-class Queue<T extends { run: () => Promise<any> }> {
-  private current?: Node<T>;
-  private end?: Node<T>;
-  private status: "waiting" | "running" = "waiting";
-
-  append(item: T, autoRun = true) {
-    const node = new Node(item);
-    if (!this.current || !this.end) {
-      this.current = this.end = node;
-    } else {
-      this.end.setNext(node);
-      this.end = node;
-    }
-
-    if (autoRun) {
-      this.startRun();
-    }
-  }
-
-  startRun() {
-    if (this.status === "waiting") {
-      this.run();
-    }
-  }
-
-  async run() {
-    if (this.current) {
-      this.status = "running";
-      const current = this.current;
-      const self = current.getSelf();
-      this.current = this.current.getNext();
-      const res = await self.run();
-      current.destroy();
-      if (res === false) {
-        this.status = "waiting";
-      } else {
-        this.run();
-      }
-    } else {
-      this.end = undefined;
-      this.status = "waiting";
-    }
-  }
-}
-
-class Node<T = any> {
-  private prev?: Node<T>;
-  private next?: Node<T>;
-  private self: T;
-
-  constructor(self: T) {
-    this.self = self;
-  }
-
-  getSelf() {
-    return this.self;
-  }
-
-  setPrev(prev?: Node<T>) {
-    this.prev = prev;
-    if (prev) {
-      prev.next = this;
-    }
-  }
-
-  setNext(next?: Node<T>) {
-    this.next = next;
-    if (next) {
-      next.prev = this;
-    }
-  }
-
-  getPrev() {
-    return this.prev;
-  }
-
-  getNext() {
-    return this.next;
-  }
-
-  destroy() {
-    if (this.prev) {
-      this.prev.setNext(undefined);
-    }
-    if (this.next) {
-      this.next.setPrev(undefined);
-    }
-    this.prev = undefined;
-    this.next = undefined;
-    this.self = undefined;
-  }
-}
-
-export { Queue };
+class Queue<T extends { run: () => Promise<any> }> {
+  private current?: Node<T>;
+  private end?: Node<T>;
+  private status: "waiting" | "running" = "waiting";
+
+  append(item: T, autoRun = true) {
+    const node = new Node(item);
+    if (!this.current || !this.end) {
+      this.current = this.end = node;
+    } else {
+      this.end.setNext(node);
+      this.end = node;
+    }
+
+    if (autoRun) {
+      this.startRun();
+    }
+  }
+
+  startRun() {
+    if (this.status === "waiting") {
+      this.run();
+    }
+  }
+
+  async run() {
+    if (this.current) {
+      this.status = "running";
+      const current = this.current;
+      const self = current.getSelf();
+      this.current = this.current.getNext();
+      const res = await self.run();
+      current.destroy();
+      if (res === false) {
+        this.status = "waiting";
+      } else {
+        this.run();
+      }
+    } else {
+      this.end = undefined;
+      this.status = "waiting";
+    }
+  }
+}
+
+class Node<T = any> {
+  private prev?: Node<T>;
+  private next?: Node<T>;
+  private self: T;
+
+  constructor(self: T) {
+    this.self = self;
+  }
+
+  getSelf() {
+    return this.self;
+  }
+
+  setPrev(prev?: Node<T>) {
+    this.prev = prev;
+    if (prev) {
+      prev.next = this;
+    }
+  }
+
+  setNext(next?: Node<T>) {
+    this.next = next;
+    if (next) {
+      next.prev = this;
+    }
+  }
+
+  getPrev() {
+    return this.prev;
+  }
+
+  getNext() {
+    return this.next;
+  }
+
+  destroy() {
+    if (this.prev) {
+      this.prev.setNext(undefined);
+    }
+    if (this.next) {
+      this.next.setPrev(undefined);
+    }
+    this.prev = undefined;
+    this.next = undefined;
+    this.self = undefined;
+  }
+}
+
+export { Queue };

+ 52 - 52
src/storage.ts → sdk/storage.ts

@@ -1,52 +1,52 @@
-class StorageAdapter {
-  static session = new StorageAdapter("session");
-  static local = new StorageAdapter("local");
-
-  private storage: Storage;
-
-  constructor(type: "session" | "local") {
-    if (type === "session") {
-      this.storage = window.sessionStorage;
-    } else if (type === "local") {
-      this.storage = window.localStorage;
-    }
-  }
-
-  setItem(key: string, value: string | number | Record<string, any>) {
-    return this.storage.setItem(key, JSON.stringify(value));
-  }
-
-  getItem(key: string) {
-    const item = this.storage.getItem(key);
-    if (item) {
-      try {
-        return JSON.parse(item);
-      } catch (error) {
-        return item;
-      }
-    }
-    return null;
-  }
-
-  removeItem(key: string) {
-    return this.storage.removeItem(key);
-  }
-
-  getStorage() {
-    return this.storage;
-  }
-
-  get length() {
-    return this.storage.length;
-  }
-
-  clear() {
-    return this.storage.clear();
-  }
-
-  key(index: number) {
-    return this.storage.key(index);
-  }
-}
-
-export { StorageAdapter };
+class StorageAdapter {
+  static session = new StorageAdapter("session");
+  static local = new StorageAdapter("local");
+
+  private storage: Storage;
+
+  constructor(type: "session" | "local") {
+    if (type === "session") {
+      this.storage = window.sessionStorage;
+    } else if (type === "local") {
+      this.storage = window.localStorage;
+    }
+  }
+
+  setItem(key: string, value: string | number | Record<string, any>) {
+    return this.storage.setItem(key, JSON.stringify(value));
+  }
+
+  getItem(key: string) {
+    const item = this.storage.getItem(key);
+    if (item) {
+      try {
+        return JSON.parse(item);
+      } catch (error) {
+        return item;
+      }
+    }
+    return null;
+  }
+
+  removeItem(key: string) {
+    return this.storage.removeItem(key);
+  }
+
+  getStorage() {
+    return this.storage;
+  }
+
+  get length() {
+    return this.storage.length;
+  }
+
+  clear() {
+    return this.storage.clear();
+  }
+
+  key(index: number) {
+    return this.storage.key(index);
+  }
+}
+
+export { StorageAdapter };

+ 29 - 0
src/App.vue

@@ -0,0 +1,29 @@
+<template>
+  <div id="app">
+    <nav-bar />
+    <div>
+      <div></div>
+      <div><router-view /></div>
+    </div>
+  </div>
+</template>
+
+<script>
+import NavBar from "@/components/navBar.vue";
+export default {
+  components: { NavBar },
+  setup() {},
+};
+</script>
+
+<style lang="less">
+html,
+body {
+  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
+    Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
+  -webkit-font-smoothing: antialiased;
+  -moz-osx-font-smoothing: grayscale;
+  text-align: center;
+  color: #2c3e50;
+}
+</style>

BIN
src/assets/logo.png


+ 22 - 0
src/components/navBar.vue

@@ -0,0 +1,22 @@
+<template>
+  <div class="nav-bar">
+    <div class="logo">
+      <h1>Ludash</h1>
+      <p>一些常用的SDK</p>
+    </div>
+    <div></div>
+  </div>
+</template>
+
+<style lang="less" scoped>
+.nav-bar {
+  height: 60px;
+  border-bottom: 1px solid #ccc;
+  display: flex;
+  align-items: center;
+  padding: 0 20px;
+  .logo {
+    display: flex;
+  }
+}
+</style>

+ 12 - 0
src/main.js

@@ -0,0 +1,12 @@
+import { createApp } from "vue";
+import App from "./App.vue";
+import router from "./router";
+import store from "./store";
+import "amfe-flexible";
+import "reset-css";
+
+import { Queue } from "../lib";
+
+console.log(Queue);
+
+createApp(App).use(store).use(router).mount("#app");

+ 17 - 0
src/router/index.js

@@ -0,0 +1,17 @@
+import { createRouter, createWebHistory } from "vue-router";
+
+const routes = [
+  {
+    path: "/",
+    name: "home",
+    component: () =>
+      import(/* webpackChunkName: "about" */ "../views/queue.vue"),
+  },
+];
+
+const router = createRouter({
+  history: createWebHistory(process.env.BASE_URL),
+  routes,
+});
+
+export default router;

+ 9 - 0
src/store/index.js

@@ -0,0 +1,9 @@
+import { createStore } from "vuex";
+
+export default createStore({
+  state: {},
+  getters: {},
+  mutations: {},
+  actions: {},
+  modules: {},
+});

+ 3 - 0
src/views/queue.vue

@@ -0,0 +1,3 @@
+<template>
+  <div>this is queue</div>
+</template>

+ 1 - 1
tsconfig.json

@@ -15,6 +15,6 @@
       "tslib" : ["node_modules/tslib/tslib.d.ts"]
     }
   },
-  "include": ["./src/**/*.ts"],
+  "include": ["sdk/**/*.ts"],
   "exclude": ["node_modules"]
 }

+ 31 - 0
vue.config.js

@@ -1,4 +1,35 @@
 const { defineConfig } = require("@vue/cli-service");
+
 module.exports = defineConfig({
   transpileDependencies: true,
+  css: {
+    loaderOptions: {
+      postcss: {
+        postcssOptions: {
+          plugins: [
+            require("autoprefixer")({
+              overrideBrowserslist: [
+                "Android 4.1",
+                "iOS 7.1",
+                "Chrome > 31",
+                "ff > 31",
+                "ie >= 8",
+                "last 10 versions", // 所有主流浏览器最近10版本用
+              ],
+              grid: true,
+            }),
+            require("postcss-pxtorem")({
+              rootValue: 192, //设计稿宽度%10 比如 1920
+              exclude: /(node_module)/, //默认false,可以(reg)利用正则表达式排除某些文件夹的方法,例如/(node_module|src)/
+              propList: ["*"], //是一个存储哪些将被转换的属性列表,这里设置为["*"]全部,假设需要仅对边框进行设置,可以写]['*','!border*']
+              //selectorBlackList :['.box'],//,那例如fs-xl类名,里面有关px的样式将不被转换,这里也支持正则写法。
+              replace: true, //替换包含rems的规则。
+              mediaQuery: false, //(布尔值)允许在媒体查询中转换px。
+              minPixelValue: 0, //设置要替换的最小像素值(3px会被转rem)。 默认 0
+            }),
+          ],
+        },
+      },
+    },
+  },
 });

Diff do ficheiro suprimidas por serem muito extensas
+ 1025 - 0
yarn.lock


Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff