From 6d2db98549c98ac3c729352087457e8b87ce032b Mon Sep 17 00:00:00 2001 From: chenjianglong Date: Sun, 21 Jan 2024 17:57:39 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9AComponentInternalInstance=20?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintrc-auto-import.json | 1 + src/auto-import.d.ts | 2 +- src/env.d.ts | 13 +++++++++++++ .../dashboard/workplace/components/announcement.vue | 2 +- src/views/login/components/account-login.vue | 2 +- src/views/login/components/email-login.vue | 8 ++++---- src/views/login/components/phone-login.vue | 2 +- src/views/login/social/index.vue | 6 +++--- src/views/monitor/log/login/index.vue | 6 +++--- src/views/monitor/log/operation/index.vue | 4 ++-- src/views/monitor/log/system/index.vue | 6 +++--- src/views/monitor/online/index.vue | 2 +- src/views/system/announcement/index.vue | 6 +++--- .../system/config/components/basic-setting.vue | 2 +- src/views/system/dept/index.vue | 8 ++++---- src/views/system/dict/index.vue | 2 +- src/views/system/dict/item.vue | 2 +- .../file/components/FileRenameModal/index.vue | 2 +- src/views/system/file/main/FileMain/index.vue | 2 +- src/views/system/menu/index.vue | 2 +- src/views/system/message/index.vue | 2 +- src/views/system/role/index.vue | 2 +- .../system/user/center/components/basic-info.vue | 6 +++--- .../components/security-settings/bind-social.vue | 12 ++++++------ .../components/security-settings/update-email.vue | 2 +- .../components/security-settings/update-phone.vue | 2 +- .../components/security-settings/update-pwd.vue | 2 +- .../system/user/center/components/user-panel.vue | 2 +- src/views/system/user/index.vue | 2 +- src/views/tool/generator/index.vue | 2 +- 30 files changed, 64 insertions(+), 50 deletions(-) diff --git a/.eslintrc-auto-import.json b/.eslintrc-auto-import.json index dcf85eb..94a5782 100644 --- a/.eslintrc-auto-import.json +++ b/.eslintrc-auto-import.json @@ -2,6 +2,7 @@ "globals": { "Component": true, "ComponentPublicInstance": true, + "ComponentInternalInstance": true, "ComputedRef": true, "EffectScope": true, "ExtractDefaultPropTypes": true, diff --git a/src/auto-import.d.ts b/src/auto-import.d.ts index 65b02fd..aed7193 100644 --- a/src/auto-import.d.ts +++ b/src/auto-import.d.ts @@ -66,6 +66,6 @@ declare global { // for type re-export declare global { // @ts-ignore - export type { Component, ComponentPublicInstance, ComputedRef, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, VNode, WritableComputedRef } from 'vue' + export type { Component, ComponentPublicInstance, ComponentInternalInstance, ComputedRef, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, VNode, WritableComputedRef } from 'vue' import('vue') } diff --git a/src/env.d.ts b/src/env.d.ts index 487190e..90aff9b 100644 --- a/src/env.d.ts +++ b/src/env.d.ts @@ -1,4 +1,6 @@ /// +import type download from '@/components/crud/index'; +import type useDict from '@/utils/dict'; declare module '*.vue' { import { DefineComponent } from 'vue'; @@ -6,6 +8,16 @@ declare module '*.vue' { const component: DefineComponent<{}, {}, any>; export default component; } + +export {}; +declare module 'vue' { + interface ComponentCustomProperties { + // 调整成你要使用到的属性,在这里进行注册 + download: typeof download; + useDict: typeof useDict; + } +} + interface ImportMetaEnv { readonly VITE_API_BASE_URL: string; } @@ -25,6 +37,7 @@ declare global { export type { Component, ComponentPublicInstance, + ComponentInternalInstance, ComputedRef, InjectionKey, PropType, diff --git a/src/views/dashboard/workplace/components/announcement.vue b/src/views/dashboard/workplace/components/announcement.vue index 7be56c7..818e42f 100644 --- a/src/views/dashboard/workplace/components/announcement.vue +++ b/src/views/dashboard/workplace/components/announcement.vue @@ -5,7 +5,7 @@ } from '@/api/common/dashboard'; import { DataRecord, get } from '@/api/system/announcement'; - const { proxy } = getCurrentInstance() as any; + const { proxy } = getCurrentInstance() as ComponentInternalInstance; const { announcement_type } = proxy.useDict('announcement_type'); const dataList = ref([]); diff --git a/src/views/login/components/account-login.vue b/src/views/login/components/account-login.vue index 6cc8ae5..6b43680 100644 --- a/src/views/login/components/account-login.vue +++ b/src/views/login/components/account-login.vue @@ -7,7 +7,7 @@ import { encryptByRsa } from '@/utils/encrypt'; import { useRouter } from 'vue-router'; - const { proxy } = getCurrentInstance() as any; + const { proxy } = getCurrentInstance() as ComponentInternalInstance; const { t } = useI18n(); const router = useRouter(); const userStore = useUserStore(); diff --git a/src/views/login/components/email-login.vue b/src/views/login/components/email-login.vue index 022673c..3abde4a 100644 --- a/src/views/login/components/email-login.vue +++ b/src/views/login/components/email-login.vue @@ -5,7 +5,7 @@ import { EmailLoginReq } from '@/api/auth'; import { getMailCaptcha } from '@/api/common/captcha'; - const { proxy } = getCurrentInstance() as any; + const { proxy } = getCurrentInstance() as ComponentInternalInstance; const { t } = useI18n(); const router = useRouter(); const userStore = useUserStore(); @@ -47,7 +47,7 @@ */ const handleSendCaptcha = () => { if (captchaLoading.value) return; - proxy.$refs.formRef.validateField('email', (valid: any) => { + proxy!.$refs.formRef.validateField('email', (valid: any) => { if (!valid) { captchaLoading.value = true; captchaBtnNameKey.value = 'login.captcha.ing'; @@ -67,7 +67,7 @@ resetCaptcha(); } }, 1000); - proxy.$message.success(res.msg); + proxy!.$message.success(res.msg); }) .catch(() => { resetCaptcha(); @@ -106,7 +106,7 @@ ...othersQuery, }, }); - proxy.$notification.success(t('login.success')); + proxy!.$notification.success(t('login.success')); }) .catch(() => { form.value.captcha = ''; diff --git a/src/views/login/components/phone-login.vue b/src/views/login/components/phone-login.vue index 614f9c3..839f0cb 100644 --- a/src/views/login/components/phone-login.vue +++ b/src/views/login/components/phone-login.vue @@ -5,7 +5,7 @@ import { PhoneLoginReq } from '@/api/auth'; import { BehaviorCaptchaReq, getSmsCaptcha } from '@/api/common/captcha'; - const { proxy } = getCurrentInstance() as any; + const { proxy } = getCurrentInstance() as ComponentInternalInstance; const { t } = useI18n(); const router = useRouter(); const userStore = useUserStore(); diff --git a/src/views/login/social/index.vue b/src/views/login/social/index.vue index 0ca388d..dabe717 100644 --- a/src/views/login/social/index.vue +++ b/src/views/login/social/index.vue @@ -4,7 +4,7 @@ import { isLogin } from '@/utils/auth'; import { bindSocial } from '@/api/system/user-center'; - const { proxy } = getCurrentInstance() as any; + const { proxy } = getCurrentInstance() as ComponentInternalInstance; const { t } = useI18n(); const route = useRoute(); const router = useRouter(); @@ -25,7 +25,7 @@ router.push({ name: (redirect as string) || 'Workplace', }); - proxy.$notification.success(t('login.success')); + proxy!.$notification.success(t('login.success')); }) .catch(() => { router.push({ @@ -55,7 +55,7 @@ tab: 'security-setting', }, }); - proxy.$message.success(res.msg); + proxy!.$message.success(res.msg); }) .catch(() => { router.push({ diff --git a/src/views/monitor/log/login/index.vue b/src/views/monitor/log/login/index.vue index 6346895..dadbc05 100644 --- a/src/views/monitor/log/login/index.vue +++ b/src/views/monitor/log/login/index.vue @@ -5,8 +5,8 @@ listLoginLog, } from '@/api/monitor/log'; - const { proxy } = getCurrentInstance() as any; - const { success_failure_status_enum } = proxy.useDict( + const { proxy } = getCurrentInstance() as ComponentInternalInstance; + const { success_failure_status_enum } = proxy!.useDict( 'success_failure_status_enum', ); @@ -55,7 +55,7 @@ * 重置 */ const resetQuery = () => { - proxy.$refs.queryRef.resetFields(); + proxy!.$refs.queryRef.resetFields(); handleQuery(); }; diff --git a/src/views/monitor/log/operation/index.vue b/src/views/monitor/log/operation/index.vue index 250d74c..5080cbe 100644 --- a/src/views/monitor/log/operation/index.vue +++ b/src/views/monitor/log/operation/index.vue @@ -5,9 +5,9 @@ listOperationLog, } from '@/api/monitor/log'; - const { proxy } = getCurrentInstance() as any; + const { proxy } = getCurrentInstance() as ComponentInternalInstance; const { success_failure_status_enum } = proxy.useDict( - 'success_failure_status_enum' + 'success_failure_status_enum', ); const operationLogList = ref([]); diff --git a/src/views/monitor/log/system/index.vue b/src/views/monitor/log/system/index.vue index 672addd..0f7f2fb 100644 --- a/src/views/monitor/log/system/index.vue +++ b/src/views/monitor/log/system/index.vue @@ -10,7 +10,7 @@ import VueJsonPretty from 'vue-json-pretty'; import 'vue-json-pretty/lib/styles.css'; - const { proxy } = getCurrentInstance() as any; + const { proxy } = getCurrentInstance() as ComponentInternalInstance; const { copy, copied } = useClipboard(); const systemLogList = ref([]); const systemLog = ref({ @@ -95,7 +95,7 @@ }; watch(copied, () => { if (copied.value) { - proxy.$message.success('复制成功'); + proxy!.$message.success('复制成功'); } }); @@ -110,7 +110,7 @@ * 重置 */ const resetQuery = () => { - proxy.$refs.queryRef.resetFields(); + proxy!.$refs.queryRef.resetFields(); handleQuery(); }; diff --git a/src/views/monitor/online/index.vue b/src/views/monitor/online/index.vue index e051c28..d4aaf7e 100644 --- a/src/views/monitor/online/index.vue +++ b/src/views/monitor/online/index.vue @@ -3,7 +3,7 @@ import { getToken } from '@/utils/auth'; import checkPermission from '@/utils/permission'; - const { proxy } = getCurrentInstance() as any; + const { proxy } = getCurrentInstance() as ComponentInternalInstance; const dataList = ref([]); const total = ref(0); diff --git a/src/views/system/announcement/index.vue b/src/views/system/announcement/index.vue index 4c1d52f..ece279c 100644 --- a/src/views/system/announcement/index.vue +++ b/src/views/system/announcement/index.vue @@ -10,8 +10,8 @@ } from '@/api/system/announcement'; import checkPermission from '@/utils/permission'; - const { proxy } = getCurrentInstance() as any; - const { announcement_type, announcement_status_enum } = proxy.useDict( + const { proxy } = getCurrentInstance() as ComponentInternalInstance; + const { announcement_type, announcement_status_enum } = proxy!.useDict( 'announcement_type', 'announcement_status_enum', ); @@ -97,7 +97,7 @@ */ const reset = () => { form.value = {}; - proxy.$refs.formRef?.resetFields(); + proxy.$refs.formRef.resetFields(); }; /** diff --git a/src/views/system/config/components/basic-setting.vue b/src/views/system/config/components/basic-setting.vue index 1f1e160..0e1b919 100644 --- a/src/views/system/config/components/basic-setting.vue +++ b/src/views/system/config/components/basic-setting.vue @@ -11,7 +11,7 @@ import { upload } from '@/api/common'; import { useAppStore } from '@/store'; - const { proxy } = getCurrentInstance() as any; + const { proxy } = getCurrentInstance() as ComponentInternalInstance; const dataList = ref([]); const isEdit = ref(false); const logoFile = ref({ uid: '-1' }); diff --git a/src/views/system/dept/index.vue b/src/views/system/dept/index.vue index 3b35679..97e37ba 100644 --- a/src/views/system/dept/index.vue +++ b/src/views/system/dept/index.vue @@ -1,5 +1,5 @@ diff --git a/src/views/system/user/center/components/security-settings/bind-social.vue b/src/views/system/user/center/components/security-settings/bind-social.vue index 40cae52..711f915 100644 --- a/src/views/system/user/center/components/security-settings/bind-social.vue +++ b/src/views/system/user/center/components/security-settings/bind-social.vue @@ -6,7 +6,7 @@ } from '@/api/system/user-center'; import { socialAuth } from '@/api/auth'; - const { proxy } = getCurrentInstance() as any; + const { proxy } = getCurrentInstance() as ComponentInternalInstance; const socialBinds = ref([]); const giteeSocial = ref(); const githubSocial = ref(); @@ -18,10 +18,10 @@ listSocial().then((res) => { socialBinds.value = res.data; giteeSocial.value = socialBinds.value.find( - (item) => item.source === 'GITEE' + (item) => item.source === 'GITEE', ); githubSocial.value = socialBinds.value.find( - (item) => item.source === 'GITHUB' + (item) => item.source === 'GITHUB', ); }); }; @@ -36,7 +36,7 @@ const handleBind = (source: string, sourceDescription: string) => { const isBind = socialBinds.value.some((item) => item.source === source); if (isBind) { - proxy.$modal.warning({ + proxy!.$modal.warning({ title: `确认解除和${sourceDescription}平台的三方账号绑定吗?`, titleAlign: 'start', content: '解除绑定后,将无法使用该第三方账户登录到此账号', @@ -44,13 +44,13 @@ onOk: () => { unbindSocial(source).then((res) => { list(); - proxy.$message.success(res.msg); + proxy!.$message.success(res.msg); }); }, }); return; } - proxy.$modal.info({ + proxy!.$modal.info({ title: '提示', titleAlign: 'start', content: `确认和${sourceDescription}平台的三方账号绑定吗?`, diff --git a/src/views/system/user/center/components/security-settings/update-email.vue b/src/views/system/user/center/components/security-settings/update-email.vue index 152acbb..329c645 100644 --- a/src/views/system/user/center/components/security-settings/update-email.vue +++ b/src/views/system/user/center/components/security-settings/update-email.vue @@ -6,7 +6,7 @@ import { useUserStore } from '@/store'; import { encryptByRsa } from '@/utils/encrypt'; - const { proxy } = getCurrentInstance() as any; + const { proxy } = getCurrentInstance() as ComponentInternalInstance; const { t } = useI18n(); const userStore = useUserStore(); const captchaTime = ref(60); diff --git a/src/views/system/user/center/components/security-settings/update-phone.vue b/src/views/system/user/center/components/security-settings/update-phone.vue index 2108ec3..e9c2b79 100644 --- a/src/views/system/user/center/components/security-settings/update-phone.vue +++ b/src/views/system/user/center/components/security-settings/update-phone.vue @@ -6,7 +6,7 @@ import { useUserStore } from '@/store'; import { encryptByRsa } from '@/utils/encrypt'; - const { proxy } = getCurrentInstance() as any; + const { proxy } = getCurrentInstance() as ComponentInternalInstance; const { t } = useI18n(); const userStore = useUserStore(); const captchaTime = ref(60); diff --git a/src/views/system/user/center/components/security-settings/update-pwd.vue b/src/views/system/user/center/components/security-settings/update-pwd.vue index fe503e7..11230d3 100644 --- a/src/views/system/user/center/components/security-settings/update-pwd.vue +++ b/src/views/system/user/center/components/security-settings/update-pwd.vue @@ -5,7 +5,7 @@ import { useUserStore } from '@/store'; import { encryptByRsa } from '@/utils/encrypt'; - const { proxy } = getCurrentInstance() as any; + const { proxy } = getCurrentInstance() as ComponentInternalInstance; const { t } = useI18n(); const userStore = useUserStore(); diff --git a/src/views/system/user/center/components/user-panel.vue b/src/views/system/user/center/components/user-panel.vue index eb0285b..9d29f95 100644 --- a/src/views/system/user/center/components/user-panel.vue +++ b/src/views/system/user/center/components/user-panel.vue @@ -6,7 +6,7 @@ import { VueCropper } from 'vue-cropper'; import 'vue-cropper/dist/index.css'; - const { proxy } = getCurrentInstance() as any; + const { proxy } = getCurrentInstance() as ComponentInternalInstance; const userStore = useUserStore(); const cropperRef = ref(); const visible = ref(false); diff --git a/src/views/system/user/index.vue b/src/views/system/user/index.vue index b366367..6637bcf 100644 --- a/src/views/system/user/index.vue +++ b/src/views/system/user/index.vue @@ -16,7 +16,7 @@ import getAvatar from '@/utils/avatar'; import checkPermission from '@/utils/permission'; - const { proxy } = getCurrentInstance() as any; + const { proxy } = getCurrentInstance() as ComponentInternalInstance; const { dis_enable_status_enum } = proxy.useDict('dis_enable_status_enum'); const dataList = ref([]); diff --git a/src/views/tool/generator/index.vue b/src/views/tool/generator/index.vue index 5664c14..ef664e9 100644 --- a/src/views/tool/generator/index.vue +++ b/src/views/tool/generator/index.vue @@ -19,7 +19,7 @@ generate, } from '@/api/tool/generator'; - const { proxy } = getCurrentInstance() as any; + const { proxy } = getCurrentInstance() as ComponentInternalInstance; const { form_type_enum, query_type_enum } = proxy.useDict( 'form_type_enum', 'query_type_enum', -- 2.49.1