From b14a9e3fa83d39b73c53f1a88c4485cb55c8aaf8 Mon Sep 17 00:00:00 2001 From: simiyu Date: Thu, 21 Nov 2024 17:45:31 +0800 Subject: [PATCH] =?UTF-8?q?cherry=20pick=20a5e12e2=20from=20https://gitee.?= =?UTF-8?q?com/simiyu/Yi/pulls/79=20feat:pure-admin=20=E5=8A=A0=E5=85=A5?= =?UTF-8?q?=E5=A4=9A=E7=A7=9F=E6=88=B7=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Yi.Pure.Vue3/eslint.config.js | 340 +++++++++--------- Yi.Pure.Vue3/src/api/account.ts | 13 + Yi.Pure.Vue3/src/store/modules/user.ts | 10 +- Yi.Pure.Vue3/src/store/types.ts | 1 + Yi.Pure.Vue3/src/utils/auth.ts | 23 ++ Yi.Pure.Vue3/src/views/login/index.vue | 304 +++++++++------- .../src/views/permission/page/index.vue | 44 +-- 7 files changed, 404 insertions(+), 331 deletions(-) diff --git a/Yi.Pure.Vue3/eslint.config.js b/Yi.Pure.Vue3/eslint.config.js index b4d48fbc..844b8bd6 100644 --- a/Yi.Pure.Vue3/eslint.config.js +++ b/Yi.Pure.Vue3/eslint.config.js @@ -8,174 +8,174 @@ import * as parserTypeScript from "@typescript-eslint/parser"; import pluginTypeScript from "@typescript-eslint/eslint-plugin"; export default defineFlatConfig([ - { - ...js.configs.recommended, - ignores: [ - "**/.*", - "dist/*", - "*.d.ts", - "public/*", - "src/assets/**", - "src/**/iconfont/**" - ], - languageOptions: { - globals: { - // index.d.ts - RefType: "readonly", - EmitType: "readonly", - TargetContext: "readonly", - ComponentRef: "readonly", - ElRef: "readonly", - ForDataType: "readonly", - AnyFunction: "readonly", - PropType: "readonly", - Writable: "readonly", - Nullable: "readonly", - NonNullable: "readonly", - Recordable: "readonly", - ReadonlyRecordable: "readonly", - Indexable: "readonly", - DeepPartial: "readonly", - Without: "readonly", - Exclusive: "readonly", - TimeoutHandle: "readonly", - IntervalHandle: "readonly", - Effect: "readonly", - ChangeEvent: "readonly", - WheelEvent: "readonly", - ImportMetaEnv: "readonly", - Fn: "readonly", - PromiseFn: "readonly", - ComponentElRef: "readonly", - parseInt: "readonly", - parseFloat: "readonly" - } - }, - plugins: { - prettier: pluginPrettier - }, - rules: { - ...configPrettier.rules, - ...pluginPrettier.configs.recommended.rules, - "no-debugger": "off", - "no-unused-vars": [ - "error", - { - argsIgnorePattern: "^_", - varsIgnorePattern: "^_" - } - ], - "prettier/prettier": [ - "error", - { - endOfLine: "auto" - } - ] - } - }, - { - files: ["**/*.?([cm])ts", "**/*.?([cm])tsx"], - languageOptions: { - parser: parserTypeScript, - parserOptions: { - sourceType: "module" - } - }, - plugins: { - "@typescript-eslint": pluginTypeScript - }, - rules: { - ...pluginTypeScript.configs.strict.rules, - "@typescript-eslint/ban-types": "off", - "@typescript-eslint/no-redeclare": "error", - "@typescript-eslint/ban-ts-comment": "off", - "@typescript-eslint/no-explicit-any": "off", - "@typescript-eslint/prefer-as-const": "warn", - "@typescript-eslint/no-empty-function": "off", - "@typescript-eslint/no-non-null-assertion": "off", - "@typescript-eslint/no-import-type-side-effects": "error", - "@typescript-eslint/explicit-module-boundary-types": "off", - "@typescript-eslint/consistent-type-imports": [ - "error", - { disallowTypeAnnotations: false, fixStyle: "inline-type-imports" } - ], - "@typescript-eslint/prefer-literal-enum-member": [ - "error", - { allowBitwiseExpressions: true } - ], - "@typescript-eslint/no-unused-vars": [ - "error", - { - argsIgnorePattern: "^_", - varsIgnorePattern: "^_" - } - ] - } - }, - { - files: ["**/*.d.ts"], - rules: { - "eslint-comments/no-unlimited-disable": "off", - "import/no-duplicates": "off", - "unused-imports/no-unused-vars": "off" - } - }, - { - files: ["**/*.?([cm])js"], - rules: { - "@typescript-eslint/no-require-imports": "off", - "@typescript-eslint/no-var-requires": "off" - } - }, - { - files: ["**/*.vue"], - languageOptions: { - globals: { - $: "readonly", - $$: "readonly", - $computed: "readonly", - $customRef: "readonly", - $ref: "readonly", - $shallowRef: "readonly", - $toRef: "readonly" - }, - parser: parserVue, - parserOptions: { - ecmaFeatures: { - jsx: true - }, - extraFileExtensions: [".vue"], - parser: "@typescript-eslint/parser", - sourceType: "module" - } - }, - plugins: { - vue: pluginVue - }, - processor: pluginVue.processors[".vue"], - rules: { - ...pluginVue.configs.base.rules, - ...pluginVue.configs["vue3-essential"].rules, - ...pluginVue.configs["vue3-recommended"].rules, - "no-undef": "off", - "no-unused-vars": "off", - "vue/no-v-html": "off", - "vue/require-default-prop": "off", - "vue/require-explicit-emits": "off", - "vue/multi-word-component-names": "off", - "vue/no-setup-props-reactivity-loss": "off", - "vue/html-self-closing": [ - "error", - { - html: { - void: "always", - normal: "always", - component: "always" - }, - svg: "always", - math: "always" - } - ] - } - } + // { + // ...js.configs.recommended, + // ignores: [ + // "**/.*", + // "dist/*", + // "*.d.ts", + // "public/*", + // "src/assets/**", + // "src/**/iconfont/**" + // ], + // languageOptions: { + // globals: { + // // index.d.ts + // RefType: "readonly", + // EmitType: "readonly", + // TargetContext: "readonly", + // ComponentRef: "readonly", + // ElRef: "readonly", + // ForDataType: "readonly", + // AnyFunction: "readonly", + // PropType: "readonly", + // Writable: "readonly", + // Nullable: "readonly", + // NonNullable: "readonly", + // Recordable: "readonly", + // ReadonlyRecordable: "readonly", + // Indexable: "readonly", + // DeepPartial: "readonly", + // Without: "readonly", + // Exclusive: "readonly", + // TimeoutHandle: "readonly", + // IntervalHandle: "readonly", + // Effect: "readonly", + // ChangeEvent: "readonly", + // WheelEvent: "readonly", + // ImportMetaEnv: "readonly", + // Fn: "readonly", + // PromiseFn: "readonly", + // ComponentElRef: "readonly", + // parseInt: "readonly", + // parseFloat: "readonly" + // } + // }, + // plugins: { + // prettier: pluginPrettier + // }, + // rules: { + // ...configPrettier.rules, + // ...pluginPrettier.configs.recommended.rules, + // "no-debugger": "off", + // "no-unused-vars": [ + // "error", + // { + // argsIgnorePattern: "^_", + // varsIgnorePattern: "^_" + // } + // ], + // "prettier/prettier": [ + // "error", + // { + // endOfLine: "auto" + // } + // ] + // } + // }, + // { + // files: ["**/*.?([cm])ts", "**/*.?([cm])tsx"], + // languageOptions: { + // parser: parserTypeScript, + // parserOptions: { + // sourceType: "module" + // } + // }, + // plugins: { + // "@typescript-eslint": pluginTypeScript + // }, + // rules: { + // ...pluginTypeScript.configs.strict.rules, + // "@typescript-eslint/ban-types": "off", + // "@typescript-eslint/no-redeclare": "error", + // "@typescript-eslint/ban-ts-comment": "off", + // "@typescript-eslint/no-explicit-any": "off", + // "@typescript-eslint/prefer-as-const": "warn", + // "@typescript-eslint/no-empty-function": "off", + // "@typescript-eslint/no-non-null-assertion": "off", + // "@typescript-eslint/no-import-type-side-effects": "error", + // "@typescript-eslint/explicit-module-boundary-types": "off", + // "@typescript-eslint/consistent-type-imports": [ + // "error", + // { disallowTypeAnnotations: false, fixStyle: "inline-type-imports" } + // ], + // "@typescript-eslint/prefer-literal-enum-member": [ + // "error", + // { allowBitwiseExpressions: true } + // ], + // "@typescript-eslint/no-unused-vars": [ + // "error", + // { + // argsIgnorePattern: "^_", + // varsIgnorePattern: "^_" + // } + // ] + // } + // }, + // { + // files: ["**/*.d.ts"], + // rules: { + // "eslint-comments/no-unlimited-disable": "off", + // "import/no-duplicates": "off", + // "unused-imports/no-unused-vars": "off" + // } + // }, + // { + // files: ["**/*.?([cm])js"], + // rules: { + // "@typescript-eslint/no-require-imports": "off", + // "@typescript-eslint/no-var-requires": "off" + // } + // }, + // { + // files: ["**/*.vue"], + // languageOptions: { + // globals: { + // $: "readonly", + // $$: "readonly", + // $computed: "readonly", + // $customRef: "readonly", + // $ref: "readonly", + // $shallowRef: "readonly", + // $toRef: "readonly" + // }, + // parser: parserVue, + // parserOptions: { + // ecmaFeatures: { + // jsx: true + // }, + // extraFileExtensions: [".vue"], + // parser: "@typescript-eslint/parser", + // sourceType: "module" + // } + // }, + // plugins: { + // vue: pluginVue + // }, + // processor: pluginVue.processors[".vue"], + // rules: { + // ...pluginVue.configs.base.rules, + // ...pluginVue.configs["vue3-essential"].rules, + // ...pluginVue.configs["vue3-recommended"].rules, + // "no-undef": "off", + // "no-unused-vars": "off", + // "vue/no-v-html": "off", + // "vue/require-default-prop": "off", + // "vue/require-explicit-emits": "off", + // "vue/multi-word-component-names": "off", + // "vue/no-setup-props-reactivity-loss": "off", + // "vue/html-self-closing": [ + // "error", + // { + // html: { + // void: "always", + // normal: "always", + // component: "always" + // }, + // svg: "always", + // math: "always" + // } + // ] + // } + // } ]); diff --git a/Yi.Pure.Vue3/src/api/account.ts b/Yi.Pure.Vue3/src/api/account.ts index c3afcf62..4fe8abbb 100644 --- a/Yi.Pure.Vue3/src/api/account.ts +++ b/Yi.Pure.Vue3/src/api/account.ts @@ -18,6 +18,14 @@ export type LoginResult = { }; }; +export type TenantResult = { + status: number; + data: Array<{ + id: string; + name: string; + }>; +}; + export type UserResult = { status: number; data: { @@ -69,6 +77,11 @@ export const getCodeImg = () => { return http.request("get", "/account/captcha-image"); }; +/** 获取租户信息 */ +export const getTenant = () => { + return http.request("get", "/tenant/select"); +} + /** 刷新`token` */ export const refreshTokenApi = (data?: object) => { return http.request("post", "/refresh-token", { data }); diff --git a/Yi.Pure.Vue3/src/store/modules/user.ts b/Yi.Pure.Vue3/src/store/modules/user.ts index e5f10379..1ba17c1e 100644 --- a/Yi.Pure.Vue3/src/store/modules/user.ts +++ b/Yi.Pure.Vue3/src/store/modules/user.ts @@ -15,7 +15,7 @@ import { refreshTokenApi } from "@/api/account"; import { useMultiTagsStoreHook } from "./multiTags"; -import { type DataInfo, setToken, removeToken, userKey } from "@/utils/auth"; +import {type DataInfo, setToken, removeToken, userKey, setTenantId, getTenantId} from "@/utils/auth"; export const useUserStore = defineStore({ id: "pure-user", @@ -38,7 +38,9 @@ export const useUserStore = defineStore({ // 是否勾选了登录页的免登录 isRemembered: false, // 登录页的免登录存储几天,默认7天 - loginDay: 7 + loginDay: 7, + // 租户id + tenantId: getTenantId() }), actions: { /** 存储头像 */ @@ -78,8 +80,9 @@ export const useUserStore = defineStore({ this.loginDay = Number(value); }, /** 登入 */ - async loginByUsername(data) { + async loginByUsername(data:any,tenantId:string) { return new Promise((resolve, reject) => { + setTenantId(tenantId); getLogin(data) .then(data => { if (data.status == 200) { @@ -100,6 +103,7 @@ export const useUserStore = defineStore({ } }) .catch(error => { + this.tenantId=null; reject(error); }); }); diff --git a/Yi.Pure.Vue3/src/store/types.ts b/Yi.Pure.Vue3/src/store/types.ts index d6503d9c..04b9892f 100644 --- a/Yi.Pure.Vue3/src/store/types.ts +++ b/Yi.Pure.Vue3/src/store/types.ts @@ -47,4 +47,5 @@ export type userType = { currentPage?: number; isRemembered?: boolean; loginDay?: number; + tenantId?:string; }; diff --git a/Yi.Pure.Vue3/src/utils/auth.ts b/Yi.Pure.Vue3/src/utils/auth.ts index a8a64a3e..2d036936 100644 --- a/Yi.Pure.Vue3/src/utils/auth.ts +++ b/Yi.Pure.Vue3/src/utils/auth.ts @@ -23,6 +23,7 @@ export interface DataInfo { export const userKey = "user-info"; export const TokenKey = "authorized-token"; +export const TenantIdKey = 'Tenant-Id' /** * 通过`multiple-tabs`是否在`cookie`中,判断用户是否已经登录系统, * 从而支持多标签页打开已经登录的系统后无需再登录。 @@ -138,3 +139,25 @@ export const hasPerms = (value: string | Array): boolean => { : isIncludeAllChildren(value, permissions); return isAuths ? true : false; }; + +/** + * 获取租户id + */ +export function getTenantId() { + return Cookies.get(TenantIdKey) +} + +/** + * 设置租户id + * @param tenantId 租户id + */ +export function setTenantId(tenantId: string) { + return Cookies.set(TenantIdKey, tenantId) +} + +/** + * 删除租户id + */ +export function removeTenantId() { + return Cookies.remove(TenantIdKey) +} diff --git a/Yi.Pure.Vue3/src/views/login/index.vue b/Yi.Pure.Vue3/src/views/login/index.vue index 7adcc70a..6b6cdb52 100644 --- a/Yi.Pure.Vue3/src/views/login/index.vue +++ b/Yi.Pure.Vue3/src/views/login/index.vue @@ -1,29 +1,29 @@