浏览代码

自动导入plugin中的插件方法

yujinwen 3 月之前
父节点
当前提交
fe08d7eec5

+ 67 - 0
src/auto-imports.d.ts

@@ -0,0 +1,67 @@
+/* eslint-disable */
+/* prettier-ignore */
+// @ts-nocheck
+// noinspection JSUnusedGlobalSymbols
+// Generated by unplugin-auto-import
+export {}
+declare global {
+  const $confirmDialog: typeof import('./plugin/dialog.jsx')['$confirmDialog']
+  const EffectScope: typeof import('vue')['EffectScope']
+  const computed: typeof import('vue')['computed']
+  const createApp: typeof import('vue')['createApp']
+  const customRef: typeof import('vue')['customRef']
+  const defineAsyncComponent: typeof import('vue')['defineAsyncComponent']
+  const defineComponent: typeof import('vue')['defineComponent']
+  const effectScope: typeof import('vue')['effectScope']
+  const getCurrentInstance: typeof import('vue')['getCurrentInstance']
+  const getCurrentScope: typeof import('vue')['getCurrentScope']
+  const h: typeof import('vue')['h']
+  const inject: typeof import('vue')['inject']
+  const isProxy: typeof import('vue')['isProxy']
+  const isReactive: typeof import('vue')['isReactive']
+  const isReadonly: typeof import('vue')['isReadonly']
+  const isRef: typeof import('vue')['isRef']
+  const markRaw: typeof import('vue')['markRaw']
+  const nextTick: typeof import('vue')['nextTick']
+  const onActivated: typeof import('vue')['onActivated']
+  const onBeforeMount: typeof import('vue')['onBeforeMount']
+  const onBeforeUnmount: typeof import('vue')['onBeforeUnmount']
+  const onBeforeUpdate: typeof import('vue')['onBeforeUpdate']
+  const onDeactivated: typeof import('vue')['onDeactivated']
+  const onErrorCaptured: typeof import('vue')['onErrorCaptured']
+  const onMounted: typeof import('vue')['onMounted']
+  const onRenderTracked: typeof import('vue')['onRenderTracked']
+  const onRenderTriggered: typeof import('vue')['onRenderTriggered']
+  const onScopeDispose: typeof import('vue')['onScopeDispose']
+  const onServerPrefetch: typeof import('vue')['onServerPrefetch']
+  const onUnmounted: typeof import('vue')['onUnmounted']
+  const onUpdated: typeof import('vue')['onUpdated']
+  const provide: typeof import('vue')['provide']
+  const reactive: typeof import('vue')['reactive']
+  const readonly: typeof import('vue')['readonly']
+  const ref: typeof import('vue')['ref']
+  const resolveComponent: typeof import('vue')['resolveComponent']
+  const shallowReactive: typeof import('vue')['shallowReactive']
+  const shallowReadonly: typeof import('vue')['shallowReadonly']
+  const shallowRef: typeof import('vue')['shallowRef']
+  const toRaw: typeof import('vue')['toRaw']
+  const toRef: typeof import('vue')['toRef']
+  const toRefs: typeof import('vue')['toRefs']
+  const toValue: typeof import('vue')['toValue']
+  const triggerRef: typeof import('vue')['triggerRef']
+  const unref: typeof import('vue')['unref']
+  const useAttrs: typeof import('vue')['useAttrs']
+  const useCssModule: typeof import('vue')['useCssModule']
+  const useCssVars: typeof import('vue')['useCssVars']
+  const useSlots: typeof import('vue')['useSlots']
+  const watch: typeof import('vue')['watch']
+  const watchEffect: typeof import('vue')['watchEffect']
+  const watchPostEffect: typeof import('vue')['watchPostEffect']
+  const watchSyncEffect: typeof import('vue')['watchSyncEffect']
+}
+// for type re-export
+declare global {
+  // @ts-ignore
+  export type { Component, ComponentPublicInstance, ComputedRef, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, VNode, WritableComputedRef } from 'vue'
+  import('vue')
+}

+ 1 - 3
src/layout/Index.vue

@@ -1,9 +1,7 @@
 <script setup>
-import {confirmDialog} from '@/plugin/dialog.jsx'
-
 
 async function handleLoginOut(){
-	await confirmDialog({
+	await $confirmDialog({
     header:'提示',
     body: '是否确认退出当前账号',
 		confirmBtn:'确认退出'

+ 1 - 1
src/plugin/dialog.jsx

@@ -2,7 +2,7 @@
 // 根据dialog-confirm-pop 类名改样式吧
 import { DialogPlugin } from 'tdesign-vue-next';
 import warningIcon from '@/assets/icons/warning.png'
-export function confirmDialog(props){
+export function $confirmDialog(props){
   const headerHtml=()=><div style="display:flex;align-items:center">
     <img src={warningIcon} style="width:20px" />
     <span>{props.header}</span>

+ 1 - 2
src/views/user/favorite/components/ClassifyWrap.vue

@@ -3,7 +3,6 @@ import {apiETAChartUser} from '@/api/etaChart'
 import { useTemplateRef, watch } from "vue";
 import EditClassify from './EditClassify.vue'
 import MoveChart from './MoveChart.vue'
-import {confirmDialog} from '@/plugin/dialog.jsx'
 import { MessagePlugin } from 'tdesign-vue-next';
 
 const emits=defineEmits(['change'])
@@ -74,7 +73,7 @@ async function handleSortEnd({node}){
 
 // 删除分类
 async function handleDeleteClassify(node){
-  await confirmDialog({
+  await $confirmDialog({
     header:'提示',
     body: '若删除该分类,则分类下关联的所有图表将被全部删除,是否继续?',
   });

+ 1 - 1
src/views/user/favorite/components/CollectChart.vue

@@ -48,7 +48,7 @@ async function handleSave(){
   if(res.Ret!==200) return
   show.value=false
   if(res.Msg==='已收藏,可选择在ETA社区-我的收藏/ETA-我的图库中-ETA社区图库查看'){
-    await confirmDialog({
+    await $confirmDialog({
       header:'提示',
       body: res.Msg,
       closeBtn:false,

+ 2 - 0
vite.config.js

@@ -20,11 +20,13 @@ export default defineConfig(({ mode }) => {
       AutoImport({
         // 自动导入 Vue 相关函数,如:ref, reactive, toRef 等
         imports: ["vue"],
+        dirs: ["./src/plugin"], // 自动扫描并导入 `src/plugin` 下的方法
         resolvers: [
           TDesignResolver({
             library: "vue-next",
           }),
         ],
+        dts: "src/auto-imports.d.ts", // 自动生成类型声明文件
       }),
       Components({
         resolvers: [