plm前端
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.

81 lines
2.4 KiB

1 year ago
7 months ago
1 year ago
  1. export default {
  2. bind(el) {
  3. // 获取所有子元素中的 input 和 el-select
  4. const inputs = el.querySelectorAll('input');
  5. const selects = el.querySelectorAll('.el-select');
  6. const textareas = el.querySelectorAll('textarea');
  7. // function applyHighlight(inputEl) {
  8. // const isModified = inputEl.value !== null && inputEl.value.trim() !== '';
  9. // if (isModified) {
  10. // inputEl.classList.add('highlight');
  11. // } else {
  12. // inputEl.classList.remove('highlight');
  13. // }
  14. // }
  15. //
  16. // inputs.forEach(inputEl => {
  17. // // 初始检查
  18. // applyHighlight(inputEl);
  19. //
  20. // // 监听输入变化
  21. // inputEl.addEventListener('input', function() {
  22. // applyHighlight(inputEl);
  23. // });
  24. // });
  25. // 处理所有的 input 元素
  26. inputs.forEach(inputEl => {
  27. inputEl.dataset.originalValue = inputEl.value;
  28. inputEl.addEventListener('input', function() {
  29. const isModified = inputEl.value !== inputEl.dataset.originalValue;
  30. if (isModified) {
  31. inputEl.classList.add('highlight');
  32. } else {
  33. inputEl.classList.remove('highlight');
  34. }
  35. });
  36. });
  37. // 处理所有的 textarea 元素
  38. textareas.forEach(textareaEl => {
  39. textareaEl.dataset.originalValue = textareaEl.value;
  40. // 监听 input 事件
  41. textareaEl.addEventListener('input', function() {
  42. const isModified = textareaEl.value !== textareaEl.dataset.originalValue;
  43. if (isModified) {
  44. textareaEl.classList.add('highlight');
  45. } else {
  46. textareaEl.classList.remove('highlight');
  47. }
  48. });
  49. });
  50. // 处理所有的 el-select 元素
  51. selects.forEach(selectEl => {
  52. const selectComponent = selectEl.__vue__;
  53. if (!selectComponent) {
  54. console.warn('Element does not have a Vue instance attached.');
  55. return;
  56. }
  57. selectEl.dataset.originalValue = selectComponent.value;
  58. selectComponent.$on('change', function(value) {
  59. const selectInputEl = selectEl.querySelector('.el-input__inner');
  60. if (selectInputEl) {
  61. const isModified = value !== selectEl.dataset.originalValue;
  62. if (isModified) {
  63. selectInputEl.classList.add('highlight');
  64. } else {
  65. selectInputEl.classList.remove('highlight');
  66. }
  67. }
  68. });
  69. });
  70. }
  71. };