mirror of
https://github.com/cool-team-official/cool-admin-vue.git
synced 2025-12-17 00:52:51 +00:00
46 lines
969 B
TypeScript
46 lines
969 B
TypeScript
import { isObject } from "../utils";
|
|
|
|
export function Permission(value: string) {
|
|
return function (target: any, key: any, descriptor: any) {
|
|
if (!target.permission) {
|
|
target.permission = {};
|
|
}
|
|
|
|
setTimeout(() => {
|
|
target.permission[key] = (
|
|
(target.namespace ? target.namespace + "/" : "") + value
|
|
).replace(/\//g, ":");
|
|
}, 0);
|
|
|
|
return descriptor;
|
|
};
|
|
}
|
|
|
|
export function Service(value: any) {
|
|
return function (target: any) {
|
|
// 命名
|
|
if (typeof value == "string") {
|
|
target.prototype.namespace = value;
|
|
}
|
|
|
|
// 复杂项
|
|
if (isObject(value)) {
|
|
const { proxy, namespace, url, mock } = value;
|
|
// @ts-ignore
|
|
const item: any = null;
|
|
|
|
if (proxy && !item) {
|
|
console.error(`${proxy} 指向的地址不存在!`);
|
|
}
|
|
|
|
target.prototype.namespace = namespace;
|
|
target.prototype.mock = mock;
|
|
|
|
if (proxy) {
|
|
target.prototype.proxy = proxy;
|
|
target.prototype.url = url || item ? item.target : null;
|
|
}
|
|
}
|
|
};
|
|
}
|