mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
refactor(projects): 请求构造函数适配不同后端接口的数据结构
This commit is contained in:
25
src/directives/network.ts
Normal file
25
src/directives/network.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import type { App, Directive } from 'vue';
|
||||
import { NETWORK_ERROR_MSG } from '@/config';
|
||||
|
||||
export default function setupNetworkDirective(app: App) {
|
||||
function listenerHandler(event: MouseEvent) {
|
||||
const hasNetwork = window.navigator.onLine;
|
||||
if (!hasNetwork) {
|
||||
window.$message?.error(NETWORK_ERROR_MSG);
|
||||
event.stopPropagation();
|
||||
}
|
||||
}
|
||||
|
||||
const networkDirective: Directive<HTMLElement, boolean | undefined> = {
|
||||
mounted(el: HTMLElement, binding) {
|
||||
if (binding.value === false) return;
|
||||
el.addEventListener('click', listenerHandler, { capture: true });
|
||||
},
|
||||
unmounted(el: HTMLElement, binding) {
|
||||
if (binding.value === false) return;
|
||||
el.removeEventListener('click', listenerHandler);
|
||||
}
|
||||
};
|
||||
|
||||
app.directive('network', networkDirective);
|
||||
}
|
Reference in New Issue
Block a user