feat: useRender 添加注释

pull/5/MERGE
xingyu 2023-04-25 10:40:07 +08:00
parent 3669f90629
commit 48ccd91ad3
1 changed files with 60 additions and 2 deletions

View File

@ -1,11 +1,15 @@
import { DictTag } from '@/components/DictTag'
import Icon from '@/components/Icon'
import { Image, Tag } from 'ant-design-vue'
import { Button, Image, Tag } from 'ant-design-vue'
import dayjs from 'dayjs'
import { h } from 'vue'
export const useRender = {
// 渲染图片
/**
*
* @param text
* @returns image
*/
renderImg: (text) => {
if (text) {
return h(Image, {
@ -16,6 +20,31 @@ export const useRender = {
}
return ''
},
/**
*
* @param url
* @param text
* @returns link
*/
renderLink: (url, text?) => {
if (url) {
return h(
Button,
{
type: 'link',
href: text
},
() => text || ''
)
}
return ''
},
/**
* textval
* @param text 1
* @param val 2
* @returns 1 + 2
*/
renderText: (text, val) => {
if (text) {
return text + ' ' + val
@ -23,6 +52,12 @@ export const useRender = {
return ''
}
},
/**
*
* @param text
* @param color
* @returns
*/
renderTag: (text, color?) => {
if (!color) {
return h(Tag, { color }, () => text)
@ -30,6 +65,11 @@ export const useRender = {
return h('span', text)
}
},
/**
*
* @param texts
* @returns
*/
renderTags: (texts: string[]) => {
if (texts) {
return h('div', null, [
@ -40,6 +80,12 @@ export const useRender = {
}
return ''
},
/**
*
* @param text
* @param format
* @returns
*/
renderDate: (text, format?) => {
if (!text) {
return ''
@ -50,6 +96,13 @@ export const useRender = {
return dayjs(text).format(format)
}
},
/**
*
* @param text
* @param type
* @param dictType number | string | boolean
* @returns
*/
renderDict: (text, type, dictType?) => {
if (type) {
return h(DictTag, {
@ -60,6 +113,11 @@ export const useRender = {
}
return ''
},
/**
* icon
* @param text icon
* @returns icon
*/
renderIcon: (text) => {
if (text) {
return h(Icon, { icon: text })