xuqm 1 年之前
父節點
當前提交
a091e51f7e

+ 38 - 0
im-admin/.eslintrc.json

@@ -0,0 +1,38 @@
+{
+    "env": {
+        "browser": true,
+        "es2021": true
+    },
+    "extends": [
+        "eslint:recommended",
+        "plugin:@typescript-eslint/recommended",
+        "plugin:vue/vue3-essential"
+    ],
+    "parserOptions": {
+        "ecmaVersion": "latest",
+        "parser": "@typescript-eslint/parser",
+        "sourceType": "module"
+    },
+    "plugins": [
+        "@typescript-eslint",
+        "vue"
+    ],
+    "rules": {
+        "indent": [
+            "error",
+            "tab"
+        ],
+        "linebreak-style": [
+            "error",
+            "windows"
+        ],
+        "quotes": [
+            "error",
+            "double"
+        ],
+        "semi": [
+            "error",
+            "always"
+        ]
+    }
+}

File diff suppressed because it is too large
+ 564 - 328
im-admin/package-lock.json


+ 5 - 0
im-admin/package.json

@@ -11,12 +11,17 @@
   "dependencies": {
     "element-plus": "^2.3.9",
     "pinia": "^2.1.6",
+    "pinia-plugin-persist": "^1.0.0",
     "vue": "^3.3.4",
     "vue-router": "^4.0.13"
   },
   "devDependencies": {
     "@types/node": "^20.5.0",
+    "@typescript-eslint/eslint-plugin": "^6.4.0",
+    "@typescript-eslint/parser": "^6.4.0",
     "@vitejs/plugin-vue": "^4.2.3",
+    "eslint": "^8.47.0",
+    "eslint-plugin-vue": "^9.17.0",
     "typescript": "^5.0.2",
     "vite": "^4.4.5",
     "vue-tsc": "^1.8.5"

+ 24 - 14
im-admin/src/main.ts

@@ -1,14 +1,24 @@
-import { createApp } from 'vue'
-import { createPinia } from 'pinia'
-import ElementPlus from 'element-plus'
-import 'element-plus/dist/index.css'
-import App from './App.vue'
-import router from './router'
-
-const app = createApp(App)
-const pinia = createPinia()
-
-app.use(ElementPlus)
-app.use(pinia)
-app.use(router)
-app.mount('#app')
+import {createApp} from "vue";
+import {createPinia} from "pinia";
+import ElementPlus from "element-plus";
+import "element-plus/dist/index.css";
+import App from "./App.vue";
+import router from "./router";
+import piniaPersist from "pinia-plugin-persist";
+import { useTenantStore } from "./store/useTenantStore";
+
+const app = createApp(App);
+const pinia = createPinia();
+pinia.use(piniaPersist);
+
+
+router.beforeEach((to) => {
+	const tenant = useTenantStore(pinia);
+  
+	if (to.meta.requiresAuth && !tenant.isLogin) return "/login";
+});
+
+app.use(ElementPlus);
+app.use(pinia);
+app.use(router);
+app.mount("#app");

+ 19 - 11
im-admin/src/router/index.ts

@@ -1,16 +1,24 @@
-import {createRouter, createWebHistory, RouteRecordRaw} from 'vue-router'
-import Home from '@/views/Home.vue'
+import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";
+import Home from "@/views/HomeView.vue";
+import Login from "@/views/LoginView.vue";
 
 const routes: Array<RouteRecordRaw> = [
-    {
-        path: '/',
-        component: Home
-    },
-]
+	{
+		path: "/",
+		component: Home,
+		meta: {
+			requiresAuth: true
+		}
+	},
+	{
+		path: "/login",
+		component: Login
+	},
+];
 
 const router = createRouter({
-    history: createWebHistory(),
-    routes
-})
+	history: createWebHistory(),
+	routes
+});
 
-export default router
+export default router;

+ 28 - 0
im-admin/src/store/useTenantStore.ts

@@ -0,0 +1,28 @@
+import {defineStore} from "pinia";
+
+export const useTenantStore = defineStore("tenant", {
+	state: () => ({
+		tenantNo: "",
+		tenantName: "",
+		updateTime: new Date()
+	}),
+	getters: {
+		isLogin: (state) => state.tenantNo !== "" && state.tenantName !== ""
+	},
+	persist: {
+		enabled: true
+	},
+	actions: {
+		login() {
+			this.tenantNo = "123456";
+			this.tenantName = "123456";
+			this.updateTime = new Date();
+		},
+		logout() {
+			this.tenantNo = "";
+			this.tenantName = "";
+			this.updateTime = new Date();
+			console.log("--------------");
+		}
+	},
+});

+ 1 - 0
im-admin/src/types/pinia-plugin-persist.d.ts

@@ -0,0 +1 @@
+declare module "@/types/pinia-plugin-persist";

+ 0 - 13
im-admin/src/views/Home.vue

@@ -1,13 +0,0 @@
-<script setup lang="ts">
-
-</script>
-
-<template>
-  <div>
-    <el-button>中文</el-button>
-  </div>
-</template>
-
-<style scoped>
-
-</style>

+ 18 - 0
im-admin/src/views/HomeView.vue

@@ -0,0 +1,18 @@
+<script setup lang="ts">
+import { useTenantStore } from "@/store/useTenantStore.js";
+
+const tenant = useTenantStore();
+
+</script>
+
+<template>
+  <div>
+    <el-button
+      @click="tenant.logout"
+      >注销</el-button
+    >
+  </div>
+</template>
+
+<style scoped>
+</style>

+ 15 - 0
im-admin/src/views/LoginView.vue

@@ -0,0 +1,15 @@
+<template>
+  <div>
+    <el-button @click="tenant.login">登录</el-button>
+    <div>{{ tenant.tenantName }}</div>
+  </div>
+</template>
+
+<script setup lang="ts">
+import { useTenantStore } from "@/store/useTenantStore.js";
+
+const tenant = useTenantStore();
+
+</script>
+
+<style scoped></style>

+ 27 - 10
im-admin/tsconfig.json

@@ -3,9 +3,12 @@
     "target": "ES2020",
     "useDefineForClassFields": true,
     "module": "ESNext",
-    "lib": ["ES2020", "DOM", "DOM.Iterable"],
+    "lib": [
+      "ES2020",
+      "DOM",
+      "DOM.Iterable"
+    ],
     "skipLibCheck": true,
-
     /* Bundler mode */
     "moduleResolution": "bundler",
     "allowImportingTsExtensions": true,
@@ -13,20 +16,34 @@
     "isolatedModules": true,
     "noEmit": true,
     "jsx": "preserve",
-
     "baseUrl": ".",
     "paths": {
-      "@/*": ["src/*"],
-//      "/@build/*": ["build/*"],
-//      "/#/*": ["types/*"],
-//      "_pinia/*": ["src/pinia/*"]
+      "@/*": [
+        "src/*"
+      ]
+      //      "/@build/*": ["build/*"],
+      //      "/#/*": ["types/*"],
+      //      "_pinia/*": ["src/pinia/*"]
     },
     /* Linting */
     "strict": true,
     "noUnusedLocals": true,
     "noUnusedParameters": true,
-    "noFallthroughCasesInSwitch": true
+    "noFallthroughCasesInSwitch": true,
+    "typeRoots": [
+      "./node_modules/@types",
+      "./src/types"
+    ]
   },
-  "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
-  "references": [{ "path": "./tsconfig.node.json" }]
+  "include": [
+    "src/**/*.ts",
+    "src/**/*.d.ts",
+    "src/**/*.tsx",
+    "src/**/*.vue"
+  ],
+  "references": [
+    {
+      "path": "./tsconfig.node.json"
+    }
+  ]
 }

+ 3 - 1
im-admin/tsconfig.node.json

@@ -6,5 +6,7 @@
     "moduleResolution": "bundler",
     "allowSyntheticDefaultImports": true
   },
-  "include": ["vite.config.ts"]
+  "include": [
+    "vite.config.ts"
+  ]
 }

Some files were not shown because too many files changed in this diff