You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

137 lines
2.9 KiB

2 years ago
import { h } from 'vue'
import dayjs from 'dayjs'
import { Button, Tag } from 'ant-design-vue'
2 years ago
import { isArray, isString } from '@/utils/is'
import { DictTag } from '@/components/DictTag'
import { Icon } from '@/components/Icon'
import TableImg from '../components/TableImg.vue'
import { JsonPreview } from '@/components/CodeEditor'
2 years ago
export const useRender = {
/**
*
* @param text
* @returns image标签
*/
2 years ago
renderImg: (text) => {
if (text) {
if (isArray(text)) {
return h(TableImg, { imgList: text })
2 years ago
} else if (isString(text)) {
2 years ago
return h(TableImg, { imgList: [text] })
}
2 years ago
}
2 years ago
return ''
2 years ago
},
/**
*
* @param url
* @param text
* @returns link
*/
renderLink: (url, text?) => {
if (url) {
2 years ago
return h(Button, { type: 'link', href: url, target: '_blank' }, () => text || '')
}
return ''
},
/**
* text与val
* @param text 1
* @param val 2
* @returns 1 + 2
*/
2 years ago
renderText: (text, val) => {
if (text) {
return text + ' ' + val
2 years ago
} else {
return ''
2 years ago
}
},
/**
*
* @param text
* @param color
* @returns
*/
2 years ago
renderTag: (text, color?) => {
2 years ago
if (color) {
2 years ago
return h(Tag, { color }, () => text)
} else {
2 years ago
return h(Tag, {}, () => text)
2 years ago
}
},
/**
*
* @param texts
* @returns
*/
renderTags: (texts: string[]) => {
if (texts) {
return h('div', null, [
texts.map((text) => {
return h(Tag, null, () => text)
})
])
}
2 years ago
return ''
},
/**
*
* @param text
* @param format
* @returns
*/
2 years ago
renderDate: (text, format?) => {
2 years ago
if (!text) {
return ''
}
2 years ago
if (!format) {
return dayjs(text).format('YYYY-MM-DD HH:mm:ss')
} else {
return dayjs(text).format(format)
}
},
/**
*
* @param text
* @param dictType
* @returns
*/
renderDict: (text, dictType) => {
if (dictType) {
return h(DictTag, { type: dictType, value: text })
2 years ago
}
2 years ago
return ''
},
/**
* icon
* @param text icon
* @returns icon
*/
renderIcon: (text) => {
if (text) {
return h(Icon, { icon: text })
}
},
/**
* 使JsonPreview组件 便JSON
* @param json json字符串/obj
* @returns json返回JsonPreview
*/
renderJsonPreview: (json: any) => {
if (!json) return ''
if (typeof json === 'object') {
return h(JsonPreview, { data: json })
}
if (typeof json === 'string') {
try {
const data = JSON.parse(json)
return h(JsonPreview, { data })
} catch (e) {
return json
}
}
2 years ago
}
}