Browse Source

Re-reference a valid EventBus component

pull/81/head
cKey 5 years ago
parent
commit
f851b0bf1c
  1. 1
      aspnet-core/services/cleanup-logs.bat
  2. 2
      aspnet-core/services/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/AbpIdentityServerAdminHttpApiHostModule.cs
  3. 2
      aspnet-core/services/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/LINGYUN.Abp.IdentityServer4.HttpApi.Host.csproj
  4. 6
      vueJs/package-lock.json
  5. 1
      vueJs/package.json
  6. 21
      vueJs/src/components/EventBus/events.d.ts
  7. 10
      vueJs/src/components/EventBus/index.d.ts
  8. 83
      vueJs/src/components/EventBus/index.js
  9. 7
      vueJs/src/components/EventBus/vue.d.ts
  10. 9
      vueJs/src/components/Notification/index.vue
  11. 2
      vueJs/src/main.ts
  12. 8
      vueJs/src/mixins/DataListMiXin.ts
  13. 59
      vueJs/src/mixins/EventBusMiXin.ts
  14. 40
      vueJs/src/utils/request.ts

1
aspnet-core/services/cleanup-logs.bat

@ -8,6 +8,7 @@ del .\platform\LINGYUN.Platform.HttpApi.Host\Logs /Q
del .\apigateway\LINGYUN.ApiGateway.Host\Logs /Q del .\apigateway\LINGYUN.ApiGateway.Host\Logs /Q
del .\apigateway\LINGYUN.ApiGateway.HttpApi.Host\Logs /Q del .\apigateway\LINGYUN.ApiGateway.HttpApi.Host\Logs /Q
del .\account\AuthServer.Host\Logs /Q del .\account\AuthServer.Host\Logs /Q
del .\identity-server\LINGYUN.Abp.IdentityServer4.HttpApi.Host\Logs /Q
del .\messages\LINGYUN.Abp.MessageService.HttpApi.Host\Logs /Q del .\messages\LINGYUN.Abp.MessageService.HttpApi.Host\Logs /Q
del .\admin\LINGYUN.Abp.BackendAdmin.HttpApi.Host\Logs /Q del .\admin\LINGYUN.Abp.BackendAdmin.HttpApi.Host\Logs /Q

2
aspnet-core/services/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/AbpIdentityServerAdminHttpApiHostModule.cs

@ -1,4 +1,4 @@
using DotNetCore.CAP; using DotNetCore.CAP;
using IdentityModel; using IdentityModel;
using LINGYUN.Abp.EventBus.CAP; using LINGYUN.Abp.EventBus.CAP;
using LINGYUN.Abp.ExceptionHandling; using LINGYUN.Abp.ExceptionHandling;

2
aspnet-core/services/identity-server/LINGYUN.Abp.IdentityServer4.HttpApi.Host/LINGYUN.Abp.IdentityServer4.HttpApi.Host.csproj

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework> <TargetFramework>netcoreapp3.1</TargetFramework>

6
vueJs/package-lock.json

@ -21314,12 +21314,6 @@
} }
} }
}, },
"vue-events": {
"version": "3.1.0",
"resolved": "https://registry.npm.taobao.org/vue-events/download/vue-events-3.1.0.tgz",
"integrity": "sha1-jiMSHDRbT/Mu4FT5eVmV8+NEsn0=",
"dev": true
},
"vue-hot-reload-api": { "vue-hot-reload-api": {
"version": "2.3.4", "version": "2.3.4",
"resolved": "https://registry.npm.taobao.org/vue-hot-reload-api/download/vue-hot-reload-api-2.3.4.tgz", "resolved": "https://registry.npm.taobao.org/vue-hot-reload-api/download/vue-hot-reload-api-2.3.4.tgz",

1
vueJs/package.json

@ -117,7 +117,6 @@
"typescript": "^3.8.3", "typescript": "^3.8.3",
"vue-cli-plugin-element": "^1.0.1", "vue-cli-plugin-element": "^1.0.1",
"vue-cli-plugin-style-resources-loader": "^0.1.4", "vue-cli-plugin-style-resources-loader": "^0.1.4",
"vue-events": "^3.1.0",
"vue-template-compiler": "^2.6.11", "vue-template-compiler": "^2.6.11",
"vue-virtual-scroll-list": "^2.1.8", "vue-virtual-scroll-list": "^2.1.8",
"webpack": "^4.42.1" "webpack": "^4.42.1"

21
vueJs/src/components/EventBus/events.d.ts

@ -0,0 +1,21 @@
import { PluginFunction } from 'vue'
export declare class VueEvents {
static install: PluginFunction<never>
emit(event: string, ...args: any[]): void
fire(event: string, ...args: any[]): void
on(event: string, callback: (eventData: any) => void): void
listen(event: string, callback: (eventData: any) => void): void
once(event: string, callback: (eventData: any) => void): void
off(event:string, callback?: (eventData: any) => void): void
unlisten (event:string, callback?: (eventData: any) => void): void
removeAll(): void
}

10
vueJs/src/components/EventBus/index.d.ts

@ -0,0 +1,10 @@
import './vue';
import * as E from './events'
declare namespace VueEvents {
export type VueEvents = E.VueEvents;
}
declare class VueEvents extends E.VueEvents {}
export default VueEvents

83
vueJs/src/components/EventBus/index.js

@ -0,0 +1,83 @@
/**
* vue-event-handler typescript adapter
* src: https://github.com/sandeepk01/vue-event-handler
* reference: https://github.com/cklmercer/vue-events
*/
function plugin(Vue) {
if (plugin.installed) {
return
}
const evmap = {}
const events = new Vue({
methods: {
fire(name, data = null) {
this.emit(name, data)
},
emit(name, data = null) {
this.$emit(name, data)
},
listen(name, cb) {
this.on(name, cb)
},
listenOnce(name, cb) {
this.once(name, cb)
},
on(name, cb) {
evmap[name] = cb
this.$on(name, cb)
},
once(name, cb) {
evmap[name] = cb
this.$once(name, cb)
},
off(name, cb) {
if (!cb) {
cb = evmap[name]
}
this.$off(name, cb)
},
unlisten(name, cb) {
this.off(name, cb)
},
removeAll() {
this.$off()
}
}
})
Vue.mixin({
beforeCreate() {
if (typeof this.$options.events !== 'object') return
let eventMap = {}
for (const key in this.$options.events) {
eventMap[key] = this.$options.events[key].bind(this)
}
this.$once('hook:beforeMount', () => {
for (const key in eventMap) {
events.$on(key, eventMap[key])
}
})
this.$once('hook:beforeDestroy', () => {
for (const key in eventMap) {
events.$off(key, eventMap[key])
}
eventMap = null
})
}
})
Vue.events = events
Object.defineProperty(Vue.prototype, '$events', {
get() {
return events
}
})
}
if (typeof window !== 'undefined' && window.Vue) {
window.Vue.use(plugin)
}
export default plugin

7
vueJs/src/components/EventBus/vue.d.ts

@ -0,0 +1,7 @@
import VueEvents from './index';
declare module 'vue/types/vue' {
interface Vue {
$events: VueEvents
}
}

9
vueJs/src/components/Notification/index.vue

@ -33,7 +33,8 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { Component, Vue } from 'vue-property-decorator' import Component, { mixins } from 'vue-class-component'
import EventBusMiXin from '@/mixins/EventBusMiXin'
import UserNofitications from './components/UserNofitications.vue' import UserNofitications from './components/UserNofitications.vue'
@Component({ @Component({
@ -42,14 +43,14 @@ import UserNofitications from './components/UserNofitications.vue'
UserNofitications UserNofitications
} }
}) })
export default class extends Vue { export default class extends mixins(EventBusMiXin) {
private notificationCount = 0 private notificationCount = 0
created() { created() {
this.$events.on('onNotificationReceived', () => { this.subscribe('onNotificationReceived', () => {
this.notificationCount += 1 this.notificationCount += 1
}) })
this.$events.on('onNotificationReadChanged', () => { this.subscribe('onNotificationReadChanged', () => {
this.notificationCount -= 1 this.notificationCount -= 1
}) })
} }

2
vueJs/src/main.ts

@ -7,7 +7,7 @@ import SvgIcon from 'vue-svgicon'
import uploader from 'vue-simple-uploader' import uploader from 'vue-simple-uploader'
import contextMenu from 'vue-contextmenujs' import contextMenu from 'vue-contextmenujs'
import VueEvents from 'vue-events' import VueEvents from '@/components/EventBus'
import '@/styles/element-variables.scss' import '@/styles/element-variables.scss'
import 'view-design/dist/styles/iview.css' import 'view-design/dist/styles/iview.css'

8
vueJs/src/mixins/DataListMiXin.ts

@ -37,6 +37,8 @@ export default class DataListMiXin extends Vue {
*/ */
protected refreshPagedData() { protected refreshPagedData() {
this.dataLoading = true this.dataLoading = true
// 这里还可以处理对于过滤器的变动
// 例如 abp 框架的skipCount区别于常见的pageNumber
this.getPagedList(this.dataFilter) this.getPagedList(this.dataFilter)
.then(res => { .then(res => {
this.dataList = res.items this.dataList = res.items
@ -52,9 +54,7 @@ export default class DataListMiXin extends Vue {
*/ */
protected getList(filter: any): Promise<ListResultDto<any>> { protected getList(filter: any): Promise<ListResultDto<any>> {
console.log(filter) console.log(filter)
return new Promise<ListResultDto<any>>((resolve) => { return this.getEmptyList()
return resolve(new ListResultDto<any>())
})
} }
/** 获取空数据 */ /** 获取空数据 */
@ -96,4 +96,6 @@ export default class DataListMiXin extends Vue {
protected l(name: string, values?: any[] | { [key: string]: any }) { protected l(name: string, values?: any[] | { [key: string]: any }) {
return this.$t(name, values).toString() return this.$t(name, values).toString()
} }
/** 还可以添加 eventbus 的通用处理器 */
} }

59
vueJs/src/mixins/EventBusMiXin.ts

@ -0,0 +1,59 @@
import { Component, Vue } from 'vue-property-decorator'
/**
*
*
*/
@Component
export default class EventBusMiXin extends Vue {
protected eventMap = new Array<string>()
/**
*
*
*/
destroyed() {
this.$events.removeAll()
this.eventMap.length = 0
}
/**
*
* @param name
* @param callback
*/
protected subscribe(name: string, callback: (eventData: any) => void) {
if (this.eventMap.includes(name)) {
return
}
this.eventMap.push(name)
this.$events.on(name, callback)
}
/**
*
* @param name
* @param callback
*/
protected subscribeOne(name: string, callback: (eventData: any) => void) {
this.$events.once(name, callback)
}
/**
*
* @param name
* @param callback
*/
protected unSubscribe(name: string, callback: (eventData: any) => void | undefined) {
this.$events.off(name, callback)
}
/**
*
* @param name
* @param args
*/
protected trigger(name: string, ...args: any[]) {
this.$events.emit(name, args)
}
}

40
vueJs/src/utils/request.ts

@ -18,20 +18,21 @@ service.interceptors.request.use(
if (tenantId) { if (tenantId) {
config.headers.__tenant = tenantId config.headers.__tenant = tenantId
} }
if (config.url === '/connect/token') {
return config
}
// Add X-Access-Token header to every request, you can add other custom headers here
if (UserModule.token) {
config.headers.Authorization = UserModule.token
}
// abp官方类库用的 zh-Hans 的简体中文包 这里直接粗暴一点 // abp官方类库用的 zh-Hans 的简体中文包 这里直接粗暴一点
// 顺序调整到token之前
const language = getLanguage() const language = getLanguage()
if (language?.indexOf('zh') !== -1) { if (language?.indexOf('zh') !== -1) {
config.headers['Accept-Language'] = 'zh-Hans' config.headers['Accept-Language'] = 'zh-Hans'
} else { } else {
config.headers['Accept-Language'] = language config.headers['Accept-Language'] = language
} }
if (config.url === '/connect/token') {
return config
}
// Add X-Access-Token header to every request, you can add other custom headers here
if (UserModule.token) {
config.headers.Authorization = UserModule.token
}
return config return config
}, },
(error) => { (error) => {
@ -43,21 +44,21 @@ function l(name: string) {
return i18n.tc(name) return i18n.tc(name)
} }
function showError(error: any, status: number) { function showError(response: any) {
let message = '' let message = ''
let title = '' let title = ''
if (error && error.error) { if (response.data && response.data.error) {
if (error.error.details) { if (response.data.error.details) {
message = error.error.details message = response.data.error.details
title = error.error.message title = response.data.error.message
} else if (error.error.message) { } else if (response.data.error.message) {
message = error.error.message message = response.data.error.message
} }
} else { } else {
switch (status) { switch (response.status) {
case 400: case 400:
title = error.error title = response.data.error
message = error.error_description message = response.data.error_description
break break
case 401: case 401:
title = l('AbpUi.DefaultErrorMessage401') title = l('AbpUi.DefaultErrorMessage401')
@ -79,6 +80,9 @@ function showError(error: any, status: number) {
message = l('AbpUi.InternalServerErrorMessage') message = l('AbpUi.InternalServerErrorMessage')
break break
default: default:
// 从响应中返回原始状态说明
title = response.statusText
message = response.status + ' ' + response.statusText
break break
} }
} }
@ -116,7 +120,7 @@ service.interceptors.response.use(
}) })
}) })
} else { } else {
showError(error.response.data, error.response.status) showError(error.response)
} }
return Promise.reject(error) return Promise.reject(error)
} }

Loading…
Cancel
Save