format.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { formatTimeToStr } from '@/utils/date'
  2. import { getDict } from '@/utils/dictionary'
  3. export const formatBoolean = (bool) => {
  4. if (bool !== null) {
  5. return bool ? '是' : '否'
  6. } else {
  7. return ''
  8. }
  9. }
  10. export const formatDate = (time) => {
  11. if (time !== null && time !== '') {
  12. var date = new Date(time)
  13. return formatTimeToStr(date, 'yyyy-MM-dd hh:mm:ss')
  14. } else {
  15. return ''
  16. }
  17. }
  18. export const filterDict = (value, options) => {
  19. const rowLabel = options && options.filter(item => item.value === value)
  20. return rowLabel && rowLabel[0] && rowLabel[0].label
  21. }
  22. export const getDictFunc = async(type) => {
  23. const dicts = await getDict(type)
  24. return dicts
  25. }
  26. const path = import.meta.env.VITE_BASE_PATH + ':' + import.meta.env.VITE_SERVER_PORT + '/'
  27. export const ReturnArrImg = (arr) => {
  28. const imgArr = []
  29. if (arr instanceof Array) { // 如果是数组类型
  30. for (const arrKey in arr) {
  31. if (arr[arrKey].slice(0, 4) !== 'http') {
  32. imgArr.push(path + arr[arrKey])
  33. } else {
  34. imgArr.push(arr[arrKey])
  35. }
  36. }
  37. } else { // 如果不是数组类型
  38. if (arr.slice(0, 4) !== 'http') {
  39. imgArr.push(path + arr)
  40. } else {
  41. imgArr.push(arr)
  42. }
  43. }
  44. return imgArr
  45. }
  46. export const onDownloadFile = (url) => {
  47. window.open(path + url)
  48. }