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