tools.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { getArrValue } from 'js-fast-way'
  2. import { getDictionary } from '~api/other'
  3. //效验是否为数字或小数的数字
  4. export const isNumberReg = (text) => {
  5. let pattern = /^[0-9]+([.]{1}[0-9]+){0,1}$/
  6. return pattern.test(text)
  7. }
  8. //获取字典数据
  9. export const getDictionaryData = async (code) => {
  10. const { data } = await getDictionary({
  11. code: code,
  12. })
  13. //处理数据
  14. let newArr = []
  15. const newData = getArrValue(data)
  16. for (let i = 0; i < newData.length; i++) {
  17. newArr.push({
  18. label: newData[i]['dictValue'],
  19. value: Number(newData[i]['dictKey']),
  20. })
  21. }
  22. return newArr
  23. }
  24. //删除提醒
  25. export const delMessage = (cbk) => {
  26. window?.$messageBox?.alert('请谨慎考虑后,确认是否需要删除?', '删除提醒', {
  27. showCancelButton: true,
  28. confirmButtonText: '确认删除',
  29. cancelButtonText: '取消',
  30. type: 'warning',
  31. callback: (action) => {
  32. if (action === 'confirm') {
  33. cbk()
  34. }
  35. },
  36. })
  37. }
  38. //动态加载线上js文件
  39. export const addDocumentsJs = () => {
  40. return new Promise((resolve) => {
  41. const script = document.createElement('script')
  42. script.src = 'http://47.110.251.215:6831/web-apps/apps/api/documents/api.js'
  43. script.type = 'text/javascript'
  44. document.head.appendChild(script)
  45. script.onload = () => {
  46. resolve()
  47. }
  48. })
  49. }
  50. //判断是否为网址
  51. export const isPathUrl = (path) => {
  52. return /^(https?:|mailto:|tel:)/.test(path)
  53. }
  54. //获取当前域名
  55. export const getTopUrl = () => {
  56. return window.location.href.split('/#/')[0]
  57. }
  58. //设置系统名称
  59. export const setAppName = (name) => {
  60. const title = window.document.title
  61. window.document.title = `${title}${name ? ' - ' + name : ''}`
  62. }