index.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. export function isEmptyObject(value) {
  2. if (JSON.stringify(value) == "{}") {
  3. return true
  4. } else {
  5. return false
  6. }
  7. }
  8. export function getDeepValue(key, valueData, type = '') {
  9. if (key.includes('.')) {
  10. const keyList = key.split('.')
  11. if (valueData[keyList[0]]) {
  12. if (type && valueData[keyList[0]]) {
  13. return valueData[keyList[0]][keyList[1]][type]
  14. } else {
  15. return valueData[keyList[0]][keyList[1]]
  16. }
  17. } else {
  18. return undefined
  19. }
  20. }
  21. if (type && valueData[key]) {
  22. return valueData[key][type] || undefined
  23. } else {
  24. return valueData[key] || undefined
  25. }
  26. }
  27. export function isChildOf(child, parent) {
  28. let parentNode;
  29. if (child && parent) {
  30. parentNode = child.parentNode;
  31. while (parentNode) {
  32. if (parent === parentNode) {
  33. return true;
  34. }
  35. parentNode = parentNode.parentNode;
  36. }
  37. }
  38. return false;
  39. }
  40. export function uploadImg(imgData) {
  41. return new Promise((resolve, reject) => {
  42. const HTTP = axios.create({
  43. baseURL: '/apis', // 这是基础url
  44. headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
  45. transformRequest: [(data) => {
  46. // Do whatever you want to transform the data
  47. let ret = ''
  48. for (const it in data) {
  49. ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
  50. }
  51. return ret
  52. }]
  53. })
  54. HTTP.post('//star.xiaojukeji.com/upload/img.node', {
  55. 'imgData': imgData,
  56. 'innerPublic': true
  57. }).then((res) => {
  58. resolve(res.data.url)
  59. })
  60. })
  61. }
  62. export function keepLastIndex(obj, window) {
  63. if (window.getSelection) { // ie11 10 9 ff safari
  64. obj.focus() // 解决ff不获取焦点无法定位问题
  65. const range = window.getSelection() // 创建range
  66. range.selectAllChildren(obj) // range 选择obj下所有子内容
  67. range.collapseToEnd() // 光标移至最后
  68. } else if (document.selection) { // ie10 9 8 7 6 5
  69. const range = document.selection.createRange() // 创建选择对象
  70. range.moveToElementText(obj) // range定位到obj
  71. range.collapse(false) // 光标移至最后
  72. range.select()
  73. }
  74. }