InfoUtil.js 4.9 KB

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