Skip to content

Commit

Permalink
fead:Added global property notifications and updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
yanghang committed Nov 7, 2023
1 parent 8cfc1dd commit ddfc509
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 10 deletions.
10 changes: 10 additions & 0 deletions docs/guide/conf.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ... // 通知
```

Binary file modified scan.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 5 additions & 3 deletions src/app/admin/main.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 2 additions & 0 deletions src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ declare global {
AES_IV: any;
AES_KEY: any;
publicKey: any;
$message:any;
$notification:any
}
}
1 change: 1 addition & 0 deletions src/packages/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import logo from "@/packages/assets/logo-min.png"
export default {
whiteList: ["/login"],
resetPath: "/login",
httpCode:[1],
menus: [],
// 通过注入函数,让框架获取外部文件
getViews: () => {
Expand Down
13 changes: 12 additions & 1 deletion src/packages/http/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion src/packages/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> = mitt()

function customizer(objValue, srcValue) {
Expand Down
11 changes: 9 additions & 2 deletions src/packages/install.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
<n-config-provider :theme="darkTheme" :theme-overrides="themeOverrides" :locale="locale"
:date-locale="dateLocale">
<n-notification-provider>
<NotificationApi/>
<n-message-provider>
<MessageApi/>
<router-view></router-view>
</n-message-provider>
</n-notification-provider>
Expand All @@ -20,15 +22,15 @@ 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"
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<any> = mitt()
function customizer(objValue, srcValue) {
Expand All @@ -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()
Expand All @@ -55,6 +58,10 @@ export {
}
export default defineComponent({
components:{
MessageApi:Message,
NotificationApi:Notification
},
setup() {
const app = appStore()
const themeOverrides: GlobalThemeOverrides = reactive({
Expand Down
7 changes: 7 additions & 0 deletions src/packages/layout/components/Message.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<template>
<div></div>
</template>
<script lang="ts" setup>
import { useMessage } from "naive-ui"
window.$message = useMessage()
</script>
7 changes: 7 additions & 0 deletions src/packages/layout/components/Notification.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<template>
<div></div>
</template>
<script lang="ts" setup>
import { useNotification } from "naive-ui"
window.$notification = useNotification()
</script>
8 changes: 8 additions & 0 deletions src/packages/layout/components/UserSet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ export default defineComponent({
const formRef = ref<FormInst | null>(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},
Expand Down Expand Up @@ -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
},
Expand Down
2 changes: 0 additions & 2 deletions src/packages/layout/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/packages/view/login/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
</div>
</div>
</n-card>
<DigitalClock></DigitalClock>
<!-- <DigitalClock></DigitalClock>-->
</template>
<script lang="ts">
import {defineComponent, ref,reactive,CSSProperties,computed} from "vue"
Expand Down

0 comments on commit ddfc509

Please sign in to comment.