diff --git a/docs/guide/conf.md b/docs/guide/conf.md index f1d12f4d..76ca0003 100644 --- a/docs/guide/conf.md +++ b/docs/guide/conf.md @@ -63,3 +63,13 @@ createApp(App).use(install, { getViews: () => import.meta.glob("@/view/**/*.vue", {eager: true}) }).use(router).mount("#app") ``` + +## 全局变量 +已内置,可在组件外部使用 +[官方-message](https://www.naiveui.com/zh-CN/os-theme/components/message), +[官方-notification](https://www.naiveui.com/zh-CN/os-theme/components/notification) +```javascript +window.$message['success'] ... // 信息 +window.$notification['warning'] ... // 通知 +``` + diff --git a/scan.jpg b/scan.jpg index 0e6f985f..191dc550 100644 Binary files a/scan.jpg and b/scan.jpg differ diff --git a/src/app/admin/main.ts b/src/app/admin/main.ts index e1608c59..e8d48bca 100644 --- a/src/app/admin/main.ts +++ b/src/app/admin/main.ts @@ -1,7 +1,9 @@ import {createApp, shallowRef} from "vue" -import App from "./App.vue" -import install from "@/packages/install.ts" -import router from "@/app/admin/router" +// @ts-ignore +import App, { install,router } from "@/packages/install.vue" +// import App from "./App.vue" +// import install from "@/packages/install.ts" +// import router from "@/app/admin/router" import headerUserSet from "@/app/admin/components/headerUserSet.vue" import {setupProdMockServer} from "__ROOT__/mock/mockProdServer.ts" diff --git a/src/global.d.ts b/src/global.d.ts index 6a7b2f06..db5a079a 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -4,5 +4,7 @@ declare global { AES_IV: any; AES_KEY: any; publicKey: any; + $message:any; + $notification:any } } diff --git a/src/packages/config/index.ts b/src/packages/config/index.ts index 1f5dfc50..8ffcf258 100644 --- a/src/packages/config/index.ts +++ b/src/packages/config/index.ts @@ -3,6 +3,7 @@ import logo from "@/packages/assets/logo-min.png" export default { whiteList: ["/login"], resetPath: "/login", + httpCode:[1], menus: [], // 通过注入函数,让框架获取外部文件 getViews: () => { diff --git a/src/packages/http/request.ts b/src/packages/http/request.ts index 00980acb..85a52823 100644 --- a/src/packages/http/request.ts +++ b/src/packages/http/request.ts @@ -18,10 +18,21 @@ http.interceptors.request.use((config: InternalAxiosRequestConfig) => { }) http.interceptors.response.use((response: AxiosResponse) => { - const {code} = response.data + const {code,msg} = response.data if (code === 1) { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + if(response.config.hint && msg){ + window.$message.success(msg) + } return response.data } + + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + if(response.config.hint && msg){ + window.$notification.warning({content: "异常提示",meta: msg,duration: 2500,keepAliveOnHover: true}) + } return response }, (error: AxiosError) => { return Promise.reject(error) diff --git a/src/packages/install.ts b/src/packages/install.ts index 846d2399..2b3e6f8e 100644 --- a/src/packages/install.ts +++ b/src/packages/install.ts @@ -13,7 +13,6 @@ import setupIcons from "@/packages/config/icon.ts" import {axios} from "@/packages/http/request.ts" import router from "@/packages/router" import setupComponents from "@/packages/components" - const emitter: Emitter = mitt() function customizer(objValue, srcValue) { diff --git a/src/packages/install.vue b/src/packages/install.vue index e7ef584e..b20a39cc 100644 --- a/src/packages/install.vue +++ b/src/packages/install.vue @@ -2,7 +2,9 @@ + + @@ -20,7 +22,6 @@ import mergeWith from "lodash/mergeWith.js" import cloneDeep from "lodash/mergeWith.js" import isArray from "lodash/isArray.js" import "@/packages/style/style.less" - import setupGlobal from "@/packages/global" import setupPinia from "@/packages/pinia" import config from "@/packages/config" @@ -28,7 +29,8 @@ import setupIcons from "@/packages/config/icon.ts" import {axios} from "@/packages/http/request.ts" import router from "@/packages/router" import setupComponents from "@/packages/components" - +import Message from "@/packages/layout/components/Message.vue" +import Notification from "@/packages/layout/components/Notification.vue" const emitter: Emitter = mitt() function customizer(objValue, srcValue) { @@ -42,6 +44,7 @@ const install = (app: App, options?: any) => { app.config.globalProperties["configOptions"] = configOptions app.provide("configOptions", readonly(configOptions)) app.provide("$mitt", emitter) + axios.configOptions = configOptions setupPinia(app) setupIcons(app) setupGlobal() @@ -55,6 +58,10 @@ export { } export default defineComponent({ + components:{ + MessageApi:Message, + NotificationApi:Notification + }, setup() { const app = appStore() const themeOverrides: GlobalThemeOverrides = reactive({ diff --git a/src/packages/layout/components/Message.vue b/src/packages/layout/components/Message.vue new file mode 100644 index 00000000..220a3696 --- /dev/null +++ b/src/packages/layout/components/Message.vue @@ -0,0 +1,7 @@ + + diff --git a/src/packages/layout/components/Notification.vue b/src/packages/layout/components/Notification.vue new file mode 100644 index 00000000..ed07492d --- /dev/null +++ b/src/packages/layout/components/Notification.vue @@ -0,0 +1,7 @@ + + diff --git a/src/packages/layout/components/UserSet.vue b/src/packages/layout/components/UserSet.vue index c2c24693..b94e9b15 100644 --- a/src/packages/layout/components/UserSet.vue +++ b/src/packages/layout/components/UserSet.vue @@ -236,6 +236,8 @@ export default defineComponent({ const formRef = ref(null) const userIcon = ref( [ + {size: 20, color: "0e7a0d", name: "GithubOutlined", show: true}, + {size: 18, color: "0e7a0d", name: "HomeOutline", show: true}, {size: 18, color: "0e7a0d", name: "SearchOutline", show: computed(() => !app.browser.xs)}, {size: 18, color: "0e7a0d", name: "NotificationsOutline", show: true}, {size: 18, color: "0e7a0d", name: "HappyOutline", show: true}, @@ -269,6 +271,12 @@ export default defineComponent({ ScanOutline() { toggle() }, + GithubOutlined(){ + window.open("https://github.com/hangjob/vue-bag-admin") + }, + HomeOutline(){ + window.location.href = "/" + }, SearchOutline() { compData.searchModel = true }, diff --git a/src/packages/layout/index.vue b/src/packages/layout/index.vue index d107b0b7..476adf83 100644 --- a/src/packages/layout/index.vue +++ b/src/packages/layout/index.vue @@ -39,8 +39,6 @@ import Navbar from "@/packages/layout/navbar/index.vue" import Tabs from "@/packages/layout/tabs/index.vue" import BagMain from "@/packages/layout/main/index.vue" import appStore from "@/packages/pinia/app.ts" - - export default defineComponent({ components: { Breadcrumb, diff --git a/src/packages/view/login/index.vue b/src/packages/view/login/index.vue index 5a8aa134..a3330bb5 100644 --- a/src/packages/view/login/index.vue +++ b/src/packages/view/login/index.vue @@ -91,7 +91,7 @@ - +