This commit is contained in:
MTrun
2021-12-10 14:11:49 +08:00
commit 535104447b
72 changed files with 5576 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
import { Component, DefineComponent } from "vue";
import { App, Plugin, getCurrentInstance } from "vue";
interface Registed {
[key: string]: boolean;
}
let registed: Registed = {};
interface Comp {
displayName?: string;
name?: string;
}
type RegisteComp = (comp: Comp & Plugin) => void;
const registeComp: RegisteComp = comp => {
const name = comp.displayName || comp.name;
if (name && !registed[name]) {
const instance = getCurrentInstance();
const app = instance?.appContext.app;
if (app) {
app.use(comp);
registed[name] = true;
}
}
};
const regComp: (comp: any) => void = comp => {
const instance = getCurrentInstance();
const app = instance?.appContext.app;
app?.component(comp?.name, comp);
};
export { registeComp, regComp };
+43
View File
@@ -0,0 +1,43 @@
import { h, unref } from 'vue';
import { NIcon, NTag } from 'naive-ui';
import type { App, Plugin } from 'vue';
/**
* 生成一个用不重复的ID
* @param { Number } randomLength
*/
function getUUID(randomLength: number) {
return Number(
Math.random()
.toString()
.substr(2, randomLength) + Date.now()
).toString(36);
}
/**
* render new Tag
* */
const newTagColors = { color: '#f90', textColor: '#fff', borderColor: '#f90' };
export function renderNew(type = 'warning', text = 'New', color: object = newTagColors) {
return () =>
h(
NTag as any,
{
type,
round: true,
size: 'small',
color,
},
{ default: () => text }
);
}
/**
* render 图标
* */
export function renderIcon(icon: any) {
return () => h(NIcon, null, { default: () => h(icon) });
}
export { getUUID };