InfoUtil.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. import UserStorageResource from '../../common/UserStorageResource.js';
  2. import Common from '../../common/Common.js';
  3. export default {
  4. cloneField: function (field) {
  5. var fieldClone = {
  6. 'fieldName': field.fieldName,
  7. 'name': field.name,
  8. 'nameEng': field.nameEng,
  9. 'isShow': field.isShow,
  10. 'mandatory': field.mandatory,
  11. 'sortNo':field.sortNo,
  12. 'width':field.width,
  13. };
  14. return fieldClone;
  15. },
  16. // 获取InfoFilterField的Key
  17. getInfoFilterFieldKey: function(infoFilterFieldItem){
  18. if(infoFilterFieldItem == undefined){
  19. return undefined;
  20. }
  21. return '#InfoFilterFieldItem_' + infoFilterFieldItem.id + '_' + infoFilterFieldItem.fieldName + '_' + infoFilterFieldItem.rowNumber;
  22. },
  23. saveInfoFilterFields: function (infoWindowNo, filterFields) {
  24. var key = 'InfoFilterFields_' + infoWindowNo;
  25. var userStorageDtos = [
  26. {
  27. key: key,
  28. value: JSON.stringify(filterFields),
  29. },
  30. ];
  31. return new Promise(function (resolve, reject) {
  32. UserStorageResource.uploadUserStorage(userStorageDtos).then(successData => {
  33. resolve();
  34. }, errorData => {
  35. Common.processException(errorData);
  36. reject();
  37. });
  38. });
  39. },
  40. saveInfoGridFields: function (infoWindowNo, filterGrids) {
  41. var key = 'InfoGridFields_' + infoWindowNo;
  42. var userStorageDtos = [
  43. {
  44. key: key,
  45. value: JSON.stringify(filterGrids),
  46. },
  47. ];
  48. return new Promise(function (resolve, reject) {
  49. UserStorageResource.uploadUserStorage(userStorageDtos).then(successData => {
  50. resolve();
  51. }, errorData => {
  52. Common.processException(errorData);
  53. reject();
  54. });
  55. });
  56. },
  57. restoreInfoFilterFields: function (infoWindowNo, localInfoFilterFields) {
  58. var key = 'InfoFilterFields_' + infoWindowNo;
  59. if (localInfoFilterFields != null) {
  60. UserStorageResource.uniqueByKey(key).then(successData => {
  61. // if(successData.errorCode != 0) {
  62. // Notify.error('提示', successData.errorMessage, false);
  63. // return;
  64. // }
  65. var remoteInfoFilterFields = null;
  66. if (successData.data != null) {
  67. remoteInfoFilterFields = JSON.parse(successData.data);
  68. }else{
  69. remoteInfoFilterFields = null;
  70. }
  71. if (remoteInfoFilterFields != null) {
  72. localInfoFilterFields.forEach(localInfoFilterField => {
  73. remoteInfoFilterFields.forEach(remoteInfoFilterField => {
  74. if (remoteInfoFilterField != null && localInfoFilterField != null &&
  75. localInfoFilterField.fieldName == remoteInfoFilterField.fieldName) {
  76. localInfoFilterField.isShow = remoteInfoFilterField.isShow;
  77. localInfoFilterField.sortNo = remoteInfoFilterField.sortNo == null ? 0 : remoteInfoFilterField.sortNo;
  78. }
  79. });
  80. });
  81. localInfoFilterFields.sort(function(item1, item2){
  82. return item1.sortNo - item2.sortNo;
  83. });
  84. }else{
  85. localInfoFilterFields.forEach(localInfoFilterField => {
  86. if(localInfoFilterField.sortNo == undefined){
  87. localInfoFilterField.sortNo = 10;
  88. }
  89. });
  90. localInfoFilterFields.sort(function(item1, item2){
  91. return item1.sortNo - item2.sortNo;
  92. });
  93. }
  94. }, errorData => {
  95. Common.processException(errorData);
  96. });
  97. }
  98. },
  99. restoreInfoGridFields: function (infoWindowNo, localInfoGridFields) {
  100. var key = 'InfoGridFields_' + infoWindowNo;
  101. if (localInfoGridFields != null) {
  102. UserStorageResource.uniqueByKey(key).then(successData => {
  103. // if(successData.errorCode != 0) {
  104. // Notify.error('提示', successData.errorMessage, false);
  105. // return;
  106. // }
  107. var remoteInfoGridFields = null;
  108. if (successData.data != null) {
  109. remoteInfoGridFields = JSON.parse(successData.data);
  110. }else{
  111. remoteInfoGridFields = null;
  112. }
  113. if (remoteInfoGridFields != null && remoteInfoGridFields != undefined) {
  114. localInfoGridFields.forEach(localInfoGridField => {
  115. remoteInfoGridFields.forEach(remoteInfoGridField => {
  116. if (remoteInfoGridField != null && localInfoGridField != null &&
  117. localInfoGridField.fieldName == remoteInfoGridField.fieldName) {
  118. localInfoGridField.isShow = remoteInfoGridField.isShow;
  119. localInfoGridField.sortNo = remoteInfoGridField.sortNo == null ? 0 : remoteInfoGridField.sortNo;
  120. localInfoGridField.width = remoteInfoGridField.width;
  121. }
  122. });
  123. });
  124. localInfoGridFields.sort(function(item1, item2){
  125. return item1.sortNo - item2.sortNo;
  126. });
  127. }else{
  128. localInfoGridFields.forEach(localInfoGridField => {
  129. if(localInfoGridField.sortNo == undefined){
  130. localInfoGridField.sortNo = 10;
  131. }
  132. });
  133. localInfoGridFields.sort(function(item1, item2){
  134. return item1.sortNo - item2.sortNo;
  135. });
  136. }
  137. }, errorData => {
  138. Common.processException(errorData);
  139. });
  140. }
  141. },
  142. };