mirror of
https://gitee.com/dromara/go-view.git
synced 2026-04-23 00:00:12 +08:00
init
This commit is contained in:
@@ -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 };
|
||||
@@ -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 };
|
||||
Reference in New Issue
Block a user